package org.jeecg.modules.dataVue.task;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.aspectj.weaver.loadtime.Aj;
import org.jeecg.modules.dataVue.entity.AFocusjh;
import org.jeecg.modules.dataVue.entity.Ajh;
import org.jeecg.modules.dataVue.service.*;
import org.jeecg.modules.newWarning.dto.AggregatedResultDto;
import org.jeecg.modules.newWarning.dto.WarnLogStatisticsDto;
import org.jeecg.modules.newWarning.params.WarnLogCountParams;
import org.jeecg.modules.newWarning.service.*;
import org.jeecg.modules.warning.entity.Ltd;
import org.jeecg.modules.warning.entity.WellNewTable;
import org.jeecg.modules.warning.service.ILtdService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class jhWarnTimeJob implements Job {

    @Autowired
    ILjrbService iLjrbService;
    @Autowired
    ILtdSourceService iLtdSourceService;
    @Autowired
    IZjyService iZjyService;
    @Autowired
    IAjhService ajhService;
    @Autowired
    IAFocusjhService focusjhService;
    @Autowired
    RealTimeZjService realTimeZjService;
    @Autowired
    IMasterService iLogicService;

    @Autowired
    ILtdService ltdService;

    @Resource
    private WarnLogService warnLogService;

    @Value("${server.port}")
    private String port;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        if (!port.equals("8090")) {
            return;
        }
        log.info(String.format("    时间:" + org.jeecg.common.util.DateUtils.getTimestamp()));
       // warnLogService.updateAjhWarnInfo();;
//        String warningSql = "select count(1) as COUNT,MAX(WARN_TIME) as TIME,JH from WARN_HISTORY where 0=0  GROUP BY JH order by TIME desc";
//        List<Map<String, Object>> warnQuery = iLtdSourceService.querySql(warningSql,null);
       // List<WarnLogStatisticsDto> warnLogCount = getWarnLogCount();
        //updateJhNew(warnQuery);
       // updateAjhWarnTimeAndWanrCount(warnLogCount);
    }


    @Transactional
    public void updateJhNew(List<Map<String, Object>> warnQuery) {

        for (Map<String, Object> map : warnQuery) {
            String jh = map.get("JH").toString();
            String time = map.get("TIME").toString().substring(0, 19);
            int count = Integer.parseInt(map.get("COUNT").toString());
            ajhService.updateAjhWarnByJh(jh, time, count);
        }
    }


}
