//package cn.cecep.talroad.task;
//
//import cn.cecep.talroad.common.core.domain.R;
//import cn.cecep.talroad.common.core.utils.StringUtils;
//import cn.cecep.talroad.common.log.annotation.Log;
//import cn.cecep.talroad.common.log.enums.BusinessType;
//import cn.cecep.talroad.domain.PcLabel;
//import cn.cecep.talroad.domain.PcLabelFactory;
//import cn.cecep.talroad.domain.PcLabelValue;
//import cn.cecep.talroad.service.IBMainThreeSupervisionEnforcService;
//import cn.cecep.talroad.service.IPcLabelFactoryService;
//import cn.cecep.talroad.service.IPcLabelService;
//import cn.cecep.talroad.service.IPcLabelValueService;
////import cn.cecep.talroad.system.api.RemoteTokenService;
////import cn.cecep.talroad.system.api.domain.LoginBody;
//import cn.cecep.talroad.util.DateUtil;
//import com.alibaba.druid.support.json.JSONUtils;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.*;
//import java.util.stream.Collectors;
//import reactor.core.publisher.Flux;
//
//@Slf4j
//@Api(tags = "三监联动数据监控-定时任务")
//@RestController
//@RequestMapping("/sjLabelController")
//public class SjLabelController {
//
//    @Autowired
//    private IPcLabelService iPcLabelService;
//    @Autowired
//    private IBMainThreeSupervisionEnforcService ibMainThreeSupervisionEnforcService;
//    @Autowired
//    private IPcLabelFactoryService iPcLabelFactoryService;
//    @Autowired
//    private IPcLabelValueService iPcLabelValueService;
////    @Autowired
////    private RemoteTokenService remoteTokenService;
//    @Value("${label.username:liyongcun}")
//    private String userName;
//
//    @ApiOperation(value = "定时任务-更新企业监控label信息：每天执行一次")
//    @Log(title = "更新企业监控label信息", businessType = BusinessType.UPDATE)
//    @PostMapping(value = "/markFactoryLabel")
//    /**
//     * labelCode=JG080,JG081,JG083(值取pc_label.label_code,用","拼接)
//     */
//    public void markFactoryLabel() {
//        String labelCode = "JG031,JG032,JG033,JG034,JG036,JG037,JG038,JG039,JG040,JG041,JG042,JG043,JG044,JG045,JG046,JG047,JG048,JG049,JG051,JG056,JG057,JG058,JG059";
//
//        if (StringUtils.isEmpty(labelCode) || userName.isEmpty()) {
//            return;
//        }
////        LoginBody loginBody = new LoginBody();
////        loginBody.setUsername(userName);
////        R<?> tokenRes = remoteTokenService.getJwt(loginBody);
////        if (R.FAIL == tokenRes.getCode()) {
////            log.error("token服务调用失败:{}", tokenRes.getMsg());
////            return;
////        }
////        Map<String, String> data = (Map) tokenRes.getData();
////        String token = data.getOrDefault("access_token", "");
////        if (token.isEmpty()) {
////            log.error("token为空");
////            return;
////        }
//        log.info("开始执行定时任务-更新企业监控label信息");
//        List<String> labelCodeList = Arrays.asList(labelCode.split(","));
//        List<PcLabel> pcLabels = iPcLabelService.getPcLabelListByLabelCodes(labelCodeList);
//        if (pcLabels.isEmpty()) {
//            log.error("没有查到label信息");
//            return;
//        }
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("pageIndex", 1);
//        map.put("pageSize", 10000);
//        map.put("beginDate", DateUtil.getDaysAgo(30));
//        map.put("endDate", DateUtil.getDay());
//
//        for (PcLabel label : pcLabels) {
//            //删除旧数据
//            iPcLabelFactoryService.batchDelete(label.getId());
//            log.info("删除旧数据，labelId:{}", label.getId());
//
//            map.put("keyword", label.getLabelVal());
//            String resStr = ibMainThreeSupervisionEnforcService.xianheGetAllUrl("","post",JSONUtils.toJSONString(map), token).toString();
//
//            Map res = (Map) JSONUtils.parse(resStr);
//
//            if (res.containsKey("count") && res.containsKey("data") && !res.get("count").equals(0)) {
//                List<PcLabelValue> labelValues = iPcLabelValueService.selectListByLabelId(label.getId());
//                List<String> argumentsCodes = labelValues.stream().map(PcLabelValue::getArgumentsCode).collect(Collectors.toList());
//                String argumentsCodeStr = StringUtils.join(argumentsCodes, ",");
//                List<Map<String, String>> dataList = (List) res.get("data");
//                List<String> factoryIds = new ArrayList<>();
//                dataList.forEach(item -> {
//                    factoryIds.add(item.get("enterpriseid"));
//                });
//                log.info("factoryIds:{}", JSONUtils.toJSONString(factoryIds));
//                if (factoryIds.isEmpty()) {
//                    continue;
//                }
//
//                List<PcLabelFactory> pcLabelFactories = new ArrayList<>();
//                for (String factoryId : factoryIds) {
//                    PcLabelFactory pcLabelFactory = new PcLabelFactory();
//                    pcLabelFactory.setId(UUID.randomUUID().toString());
//                    pcLabelFactory.setFactoryId(factoryId);
//                    pcLabelFactory.setLabelId(label.getId());
//                    pcLabelFactory.setLableUseing("0");
//                    pcLabelFactory.setLabelValue(argumentsCodeStr);
//                    pcLabelFactories.add(pcLabelFactory);
//                }
//                iPcLabelFactoryService.saveBatch(pcLabelFactories, pcLabelFactories.size());
//                log.info("新增数据，factoryIds:{}", JSONUtils.toJSONString(factoryIds));
//            }
//        }
//    }
//}
