//package com.scpyun.platform.jilinsscgsdp.task.impl;
//
//import com.scpyun.base.core.exception.CustomException;
//import com.scpyun.base.core.utils.SpringContextHolder;
//import com.scpyun.base.core.utils.StringUtils;
//import com.scpyun.base.core.utils.UnifyLogger;
//import com.scpyun.base.db.service.CommonService;
//import com.scpyun.platform.jilinsscgsdp.bean.vo.ReqFocisAreasNumVo;
//import com.scpyun.platform.jilinsscgsdp.bean.vo.ReqFocisAreasVo;
//import com.scpyun.platform.jilinsscgsdp.bean.vo.ResFocisAreasNumVo;
//import com.scpyun.platform.jilinsscgsdp.bean.vo.ResFocusAreasVo;
//import com.scpyun.platform.jilinsscgsdp.constant.NumberConstant;
//import org.redisson.api.RLock;
//import org.redisson.api.RedissonClient;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
///**
// * @Author liu
// * @Date 2024/10/28 11:29
// * @PackageName:com.scpyun.platform.jilinsscgsdp.task.impl
// * @ClassName: FocusAreasTask
// * @Description: TODO
// * @Version 1.0
// */
//@Component
//public class FocusAreasTask {
//    CommonService commonService = SpringContextHolder.getBean(CommonService.class);
//    RedissonClient redissonClient = SpringContextHolder.getBean(RedissonClient.class);
//    private final String nameSpace = "com.scpyun.platform.standard.jilinsscgsdp.focusareas.";
//
//    /**
//     * 根据矛盾大类查询
//     */
////    @Scheduled(cron = "0 0 1 * * ?")
//    @Scheduled(cron = "0 0/2 * * * ?")
//    public void synchronizationFocisAreasType() {
//        RLock rLock = redissonClient.getLock("jilinexchange:eventTask");
//        //        rLock.lock(NumberConstant.R_LOCK, TimeUnit.SECONDS);
//        try {
//            if (rLock.tryLock(60, TimeUnit.SECONDS)) {
//                //重点类别
//                UnifyLogger.parent("重点类别定时任务启动----------------");
//                ReqFocisAreasVo endVo = new ReqFocisAreasVo();
////        本月
//                List<ResFocusAreasVo> sfaVoMonthList = commonService.findList(nameSpace + "selectFocisAreasTypeByMonthList", null);
//                for (ResFocusAreasVo vo : sfaVoMonthList) {
//                    ReqFocisAreasVo qfaVo = new ReqFocisAreasVo();
//                    qfaVo.setEvent_category_id(vo.getEvent_category_id());
////            上月
//                    ResFocusAreasVo sfaVo = commonService.getObject(nameSpace + "getFocisAreasTypeByMonth", qfaVo);
////            如果没有查询到则不进入触发风险
//                    if (!StringUtils.isEmpty(sfaVo.getOn_num())) {
//                        ReqFocisAreasNumVo qfanVo = new ReqFocisAreasNumVo();
//                        qfanVo.setNum(vo.getNum());//获取本月矛盾数
//                        qfanVo.setOn_num(sfaVo.getOn_num());//获取上月矛盾数
//                        ResFocisAreasNumVo rfanVo = commonService.getObject(nameSpace + "getCount", qfanVo);
//                        if (rfanVo.getLink_relative_ratio().equals("1")) {
//                            endVo.setEvent_category_id(vo.getEvent_category_id());//获取类别id
//                            endVo.setEvent_category_name(vo.getLabel());//获取类别名称
//                            endVo.setOccurrence_time(vo.getOccurrence_time());//添加统计月份
//                            endVo.setYear_num(vo.getNum());//添加年矛盾数
//                            endVo.setLink_relative_ratio(rfanVo.getLink_relative_ratio_num());//添加月环比数
//                            if (commonService.insert(nameSpace + "insertFocusAreasType", endVo) != 1) {
//                                throw new CustomException("月类别风险比对失败！");
//                            }
//                        }
//                    }
//                }
//
////        年比
//                List<ResFocusAreasVo> sfaYearVoList = commonService.findList(nameSpace + "selectFocisAreasTypeByYearList", null);
//                for (ResFocusAreasVo vo : sfaYearVoList) {
//                    ReqFocisAreasVo qfaVo = new ReqFocisAreasVo();
//                    qfaVo.setEvent_category_id(vo.getEvent_category_id());
////            去年
//                    ResFocusAreasVo sfaVo = commonService.getObject(nameSpace + "getFocisAreasTypeByYear", qfaVo);
////            如果没有查询到则不进入触发风险
//                    if (!StringUtils.isEmpty(sfaVo.getYear_num())) {
//                        ReqFocisAreasNumVo qfanVo = new ReqFocisAreasNumVo();
//                        qfanVo.setYear_num(vo.getYear_num());//获取本年矛盾数
//                        qfanVo.setOn_year(sfaVo.getOn_year());//获取去年矛盾数
//                        ResFocisAreasNumVo rfanVo = commonService.getObject(nameSpace + "getCount", qfanVo);
//                        if (rfanVo.getOn_year_type().equals("1")) {
//                            endVo.setEvent_category_id(vo.getEvent_category_id());//获取类别id
//                            endVo.setEvent_category_name(vo.getLabel());//获取类别名称
//                            endVo.setOccurrence_time(vo.getOccurrence_time());//添加统计月份
//                            endVo.setYear_num(vo.getYear_num());//年矛盾数量
//                            endVo.setOn_year(rfanVo.getOn_year_num());//年同比数
//                            if (commonService.insert(nameSpace + "insertFocusAreasType", endVo) != 1) {
//                                throw new CustomException("年类别风险比对失败！");
//                            }
//                        }
//                    }
//                }
//            }
//        } catch (Exception e) {
//            UnifyLogger.parent(UnifyLogger.getTrace(e), UnifyLogger.Level.INFO);
//        } finally {
//            rLock.unlock();
//        }
//    }
//
//    /**
//     * 根据城市查询
//     */
////    @Scheduled(cron = "0 0 2 * * ?")
//    @Scheduled(cron = "0 0/3 * * * ?")
//    public void synchronizationFocisAreasCity() {
//        RLock rLock = redissonClient.getLock("jilinexchange:eventTask");
//        rLock.lock(NumberConstant.R_LOCK, TimeUnit.SECONDS);
//        try {
//            //重点类别
//            UnifyLogger.parent("重点城市定时任务启动----------------");
//            ReqFocisAreasVo endVo = new ReqFocisAreasVo();
////        本月
//            List<ResFocusAreasVo> sfaVoMonthList = commonService.findList(nameSpace + "selectFocisAreasCityByMonthList", null);
//            for (ResFocusAreasVo vo : sfaVoMonthList) {
//                ReqFocisAreasVo qfaVo = new ReqFocisAreasVo();
//                qfaVo.setEvent_category_id(vo.getEvent_category_id());
////            上月
//                ResFocusAreasVo sfaVo = commonService.getObject(nameSpace + "getFocisAreasCityByMonth", qfaVo);
////            如果没有查询到则不进入触发风险
//                if (!StringUtils.isEmpty(sfaVo.getOn_num())) {
//                    ReqFocisAreasNumVo qfanVo = new ReqFocisAreasNumVo();
//                    qfanVo.setNum(vo.getNum());//获取本月矛盾数
//                    qfanVo.setOn_num(sfaVo.getOn_num());//获取上月矛盾数
//                    ResFocisAreasNumVo rfanVo = commonService.getObject(nameSpace + "getCount", qfanVo);
//                    if (rfanVo.getLink_relative_ratio().equals("1")) {
//                        endVo.setCity_id(vo.getCity_id());//获取城市id
//                        endVo.setCity_name(vo.getName());//获取城市名称
//                        endVo.setOccurrence_time(vo.getOccurrence_time());//添加统计月份
//                        endVo.setYear_num(vo.getNum());//添加年矛盾数
//                        endVo.setLink_relative_ratio(rfanVo.getLink_relative_ratio_num());//添加月环比数
//                        if (commonService.insert(nameSpace + "insertFocusAreasCity", endVo) != 1) {
//                            throw new CustomException("月城市风险比对失败！");
//                        }
//                    }
//                }
//            }
//
////        年比
//            List<ResFocusAreasVo> sfaYearVoList = commonService.findList(nameSpace + "selectFocisAreasCityByYearList", null);
//            for (ResFocusAreasVo vo : sfaYearVoList) {
//                ReqFocisAreasVo qfaVo = new ReqFocisAreasVo();
//                qfaVo.setEvent_category_id(vo.getEvent_category_id());
////            去年
//                ResFocusAreasVo sfaVo = commonService.getObject(nameSpace + "getFocisAreasCityByYear", qfaVo);
////            如果没有查询到则不进入触发风险
//                if (!StringUtils.isEmpty(sfaVo.getYear_num())) {
//                    ReqFocisAreasNumVo qfanVo = new ReqFocisAreasNumVo();
//                    qfanVo.setYear_num(vo.getYear_num());//获取本年矛盾数
//                    qfanVo.setOn_year(sfaVo.getOn_year());//获取去年矛盾数
//                    ResFocisAreasNumVo rfanVo = commonService.getObject(nameSpace + "getCount", qfanVo);
//                    if (rfanVo.getOn_year_type().equals("1")) {
//                        endVo.setCity_id(vo.getCity_id());//获取城市id
//                        endVo.setCity_name(vo.getName());//获取城市名称
//                        endVo.setOccurrence_time(vo.getOccurrence_time());//添加统计月份
//                        endVo.setYear_num(vo.getYear_num());//年矛盾数量
//                        endVo.setOn_year(rfanVo.getOn_year_num());//年同比数
//                        if (commonService.insert(nameSpace + "insertFocusAreasCity", endVo) != 1) {
//                            throw new CustomException("年城市风险比对失败！");
//                        }
//                    }
//                }
//            }
//        } catch (Exception e) {
//            UnifyLogger.parent(UnifyLogger.getTrace(e), UnifyLogger.Level.INFO);
//        } finally {
//            rLock.unlock();
//        }
//    }
//
//}
