package com.weaver.seconddev.interfaces.workflow.controller;

import com.google.common.collect.Maps;
import com.weaver.common.authority.annotation.WeaPermission;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.common.distribution.genid.IdGenerator;
import com.weaver.common.distribution.lock.DistributionLockInterface;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.custom.configcenter.htsysjcmtConfig;
import com.weaver.ecode.api.dto.FolderDto;
import com.weaver.ecode.api.rpc.EcodeService;
import com.weaver.framework.client.annotation.WeaverConfigCenter;
import com.weaver.framework.rpc.annotation.RpcReference;
import com.weaver.framework.rpc.context.impl.TenantRpcContext;
import com.weaver.teams.domain.user.SimpleEmployee;
import com.weaver.teams.security.context.UserContext;
import com.weaver.teams.security.user.User;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.workflow.common.entity.list.api.publicapi.RequestListInfoPAEntity;
import com.weaver.workflow.list.api.rest.publicapi.WflRequestListRest;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping({"/papi/secondev/workflow/demo" })
//@WeaPermission
public class ApiController {

    // api 需要用户会话，e10入口地址访问
    // papi 任何人都可以直接访问 public api，e10入口地址访问
    // sapi 服务内部通信的接口路由前缀 /sapi/secondev，e10入口地址访问不了
    // 二开服务新接口：/api/secondev，/papi/secondev

    @RpcReference(timeout = 10000)
    EcodeService ecodeService;
    @RpcReference(timeout = 2000, group = "workflow")
    WflRequestListRest wflRequestListRest;
    @Autowired
    private DistributionLockInterface distributionLock;

    @Autowired
    private htsysjcmtConfig htsysjcmtConfig;
//    @Value("${srmbacklisturl}")
//    private String srmbacklisturl;
//
    @Value("${weaver.swagger.basePackage}")
    private String basePackage;

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ApiController.class);
    @GetMapping("/hello")
    //@PostMapping("/post")
    public WeaResult<String> hello(@RequestParam("key") String key) {
        // todo api

        logger.error("ApiController info :  hello "  );
        logger.error("srmbacklisturl == " +1);
        logger.error("ApiController info :  basePackage "  + basePackage);

        Map<String ,String > map = new HashMap<>();
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String sql = "select *  from  eteams.dbo.employee where id = 100001700000000003";
        TenantRpcContext.setTargetTenantKey("t6kj9c07jr");
        rs.setTenantKey("t6kj9c07jr");
        rs.executeQuery(sql);
        if(rs.next()){
            map.put("username" , rs.getString("username"));
            map.put("id" ,rs.getString("id"));
        }
        logger.error("map == " +map);
//        logger.info("ApiController info :  hello "  );
//        final User currentUser = UserContext.getCurrentUser();
//        //final Tenant currentTenant = TenantContext.getCurrentTenant();
//        final Long employeeId = currentUser.getEmployeeId();//用户
//
//
//        logger.info("ApiController info :  employeeId = " + employeeId );
//        logger.error("ApiController info :  employeeId = " + employeeId );
//        final String tenantKey = currentUser.getTenantKey();//租户
//
//        logger.info("ApiController info : tenantKey= " + tenantKey );
//        logger.error("ApiController info : tenantKey= " + tenantKey );


        return WeaResult.success(map.toString());
    }



}
