|
|
@@ -5,23 +5,24 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.domain.safetyindex.domain.CoreSafeMonthScore;
|
|
|
import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetyDeductData;
|
|
|
import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetyExceptionData;
|
|
|
import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetySourceData;
|
|
|
import com.xunmei.common.core.domain.safetyindex.vo.SafeIndexRuleCountVo;
|
|
|
+import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.core.question.service.IQuestionService;
|
|
|
import com.xunmei.core.resumption.service.ResumptionService;
|
|
|
import com.xunmei.core.retrieval.service.ICoreMonitoringRetrievalTaskService;
|
|
|
import com.xunmei.core.safetyindex.mapper.CoreSafetyExceptionDataMapper;
|
|
|
-import com.xunmei.core.safetyindex.service.ICoreSafetyDeductDataService;
|
|
|
-import com.xunmei.core.safetyindex.service.ICoreSafetyExceptionDataService;
|
|
|
-import com.xunmei.core.safetyindex.service.ICoreSafetyIndexCalculateRuleService;
|
|
|
-import com.xunmei.core.safetyindex.service.ICoreSafetySourceDataService;
|
|
|
+import com.xunmei.core.safetyindex.service.*;
|
|
|
import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -53,6 +54,8 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
public static final String AFTER_POINT_CODE = "10040202";
|
|
|
public static final String UN_CONFIRM_POINT_CODE = "10050101";
|
|
|
public static final String UN_RECTIFY_POINT_CODE = "10050101";
|
|
|
+ public static final String MONITORING_EXCEPTION_NUMS_POINT_CODE = "10060101";
|
|
|
+ public static final String MONITORING_OVERDUE_POINT_CODE = "10060201";
|
|
|
@Autowired
|
|
|
private CoreSafetyExceptionDataMapper coreSafetyExceptionDataMapper;
|
|
|
@Autowired
|
|
|
@@ -67,7 +70,8 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
private ICoreSafetyDeductDataService safetyDeductDataService;
|
|
|
@Autowired
|
|
|
private ICoreSafetySourceDataService sourceDataService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ICoreSafeMonthScoreService safeMonthScoreService;
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void countExceptionData(String date) {
|
|
|
@@ -121,28 +125,83 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
calculateMonitoringData(monitoringIndexList, monitoringExceptionDataList, year, month, orgList);
|
|
|
|
|
|
|
|
|
+ calculateAll(year,month);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void calculateAll(int year, int month) {
|
|
|
+ /*List<CoreSafetyDeductData> list =safetyDeductDataService.list((new QueryWrapper<CoreSafetyDeductData>()).lambda().eq(CoreSafetyDeductData::getDataYear,year).eq(CoreSafetyDeductData::getDataMonth,month));
|
|
|
+ List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ List<SysOrgVO> orgLista = orgList.stream().filter(r->r.getType()!=null).filter(r->ObjectUtil.equal(OrgTypeEnum.YINGYE_WANGDIAN.getCode(),r.getType())).collect(Collectors.toList());
|
|
|
+ List<SafeLevel> levels =safeLevelService.list();
|
|
|
+ Map<Long, List<CoreSafetyDeductData>> safeSourceDataList = list.stream().collect(Collectors.groupingBy(CoreSafetyDeductData::getOrgId));
|
|
|
+ List<CoreSafeMonthScore> listSafeMonthScore = new ArrayList<>();
|
|
|
+ for(SysOrgVO o:orgLista){
|
|
|
+ CoreSafeMonthScore monthScore = new CoreSafeMonthScore();
|
|
|
+ monthScore.setDataMonth(month);
|
|
|
+ monthScore.setDataYear(year);
|
|
|
+ monthScore.setId(IDHelper.id());
|
|
|
+ monthScore.setOrgId(o.getId());
|
|
|
+ monthScore.setReleaseStatus(true);
|
|
|
+ List<CoreSafetyDeductData> listdata = safeSourceDataList.get(o.getId());
|
|
|
+ double deduct = 0;
|
|
|
+ if(listdata!=null){
|
|
|
+ for(CoreSafetyDeductData data:listdata){
|
|
|
+ deduct+=data.getScoreReal();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double orgscore = 100-deduct;
|
|
|
+ List<SafeLevel> levelList = levels.stream().sorted(Comparator.comparing(r->r.getId())).collect(Collectors.toList());
|
|
|
+ if(orgscore>levelList.get(0).getMinValue()){
|
|
|
+ monthScore.setLevelId(Long.valueOf(levelList.get(0).getId()));
|
|
|
+ }else if(orgscore>levelList.get(1).getMinValue()&&orgscore<=levelList.get(1).getMaxValue()){
|
|
|
+ monthScore.setLevelId(Long.valueOf(levelList.get(1).getId()));
|
|
|
+ }else if(orgscore>levelList.get(2).getMinValue()&&orgscore<=levelList.get(2).getMaxValue()){
|
|
|
+ monthScore.setLevelId(Long.valueOf(levelList.get(2).getId()));
|
|
|
+ }else {
|
|
|
+ monthScore.setLevelId(Long.valueOf(levelList.get(3).getId()));
|
|
|
+ }
|
|
|
+ monthScore.setOrgScore(orgscore);
|
|
|
+ listSafeMonthScore.add(monthScore);
|
|
|
+ }
|
|
|
+ *//* QueryWrapper<SafeMonthScore> qw = new QueryWrapper<>();
|
|
|
+ qw.lambda().eq(SafeMonthScore::getDataYear,year);
|
|
|
+ qw.lambda().eq(SafeMonthScore::getDataMonth,month);
|
|
|
+ safeMonthScoreService.remove(qw);*//*
|
|
|
+ //safeMonthScoreService.saveBatch(listSafeMonthScore);
|
|
|
+ // 根据机构id+年+月判断重复 存在则更新 不存在则新增
|
|
|
+ safeMonthScoreService.checkAndSaveBatchData(listSafeMonthScore);*/
|
|
|
}
|
|
|
|
|
|
private void calculateMonitoringData(List<SafeIndexRuleCountVo> monitoringIndexList, List<CoreSafetyExceptionData> dataList, int year, int month, List<SysOrgVO> orgList) {
|
|
|
//将数据按机构分组
|
|
|
Map<Long, List<CoreSafetyExceptionData>> monitoringExceptionDataList = dataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
|
|
|
-
|
|
|
+ for (Long orgId : monitoringExceptionDataList.keySet()) {
|
|
|
+ orgList.stream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
|
|
|
+ //获取机构的指标配置
|
|
|
+ List<SafeIndexRuleCountVo> orgMonitoringIndexList = monitoringIndexList.stream().filter(r -> ObjectUtil.equal(r.getOrgType(), org.getType())).collect(Collectors.toList());
|
|
|
+ if (orgMonitoringIndexList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //逾期的规则
|
|
|
+ List<SafeIndexRuleCountVo> overdueIndexList = orgMonitoringIndexList.stream()
|
|
|
+ .filter(r -> ObjectUtil.equal(MONITORING_OVERDUE_POINT_CODE, r.getPointCode()))
|
|
|
+ .filter(r -> r.getCalculateType().equals(Constants.ONE))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //获取机构的异常数据并计算逾期分数
|
|
|
+ List<CoreSafetyExceptionData> monitoringExceptionDataListByOrg = monitoringExceptionDataList.get(orgId);
|
|
|
+ if (ObjectUtil.isNotEmpty(monitoringIndexList)) {
|
|
|
+ List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(overdueIndexList, monitoringExceptionDataListByOrg, orgId, year, month);
|
|
|
+ saveSourceData(sourceDataList, monitoringIndexList.get(0));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void calculateQuestionData(List<SafeIndexRuleCountVo> questionIndexList, List<CoreSafetyExceptionData> dataList, int year, int month, List<SysOrgVO> orgList) {
|
|
|
//将数据按机构分组
|
|
|
Map<Long, List<CoreSafetyExceptionData>> questionExceptionDataList = dataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
|
|
|
- //未在规定时间内确认
|
|
|
- List<SafeIndexRuleCountVo> unConfirmIndexList = questionIndexList.stream()
|
|
|
- .filter(r -> ObjectUtil.equal(UN_CONFIRM_POINT_CODE, r.getPointCode()))
|
|
|
- .filter(r -> r.getCalculateType().equals(Constants.ONE))
|
|
|
- .collect(Collectors.toList());
|
|
|
- //已确认但未在规定时间内完成整改
|
|
|
- List<SafeIndexRuleCountVo> unRectifyIndexList = questionIndexList.stream()
|
|
|
- .filter(r -> ObjectUtil.equal(UN_RECTIFY_POINT_CODE, r.getPointCode()))
|
|
|
- .filter(r -> r.getCalculateType().equals(Constants.ONE))
|
|
|
- .collect(Collectors.toList());
|
|
|
for (Long orgId : questionExceptionDataList.keySet()) {
|
|
|
orgList.stream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
|
|
|
//获取机构的指标配置
|
|
|
@@ -150,6 +209,18 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
if (orgResumptionIndexList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
+ //未在规定时间内确认
|
|
|
+ List<SafeIndexRuleCountVo> unConfirmIndexList = orgResumptionIndexList.stream()
|
|
|
+ .filter(r -> ObjectUtil.equal(UN_CONFIRM_POINT_CODE, r.getPointCode()))
|
|
|
+ .filter(r -> r.getCalculateType().equals(Constants.ONE))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //已确认但未在规定时间内完成整改
|
|
|
+ List<SafeIndexRuleCountVo> unRectifyIndexList = orgResumptionIndexList.stream()
|
|
|
+ .filter(r -> ObjectUtil.equal(UN_RECTIFY_POINT_CODE, r.getPointCode()))
|
|
|
+ .filter(r -> r.getCalculateType().equals(Constants.ONE))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
List<CoreSafetyExceptionData> safetyExceptionData = questionExceptionDataList.get(orgId);
|
|
|
//未确认的数据
|
|
|
long unConfirmDataCount = safetyExceptionData.stream().filter(data -> ObjectUtil.equal(data.getExtraField2(), 2)).count();
|
|
|
@@ -181,12 +252,6 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
//扩展字段1:计划id 扩展字段2:计划执行时刻 (2,3,4 营业前中后)
|
|
|
//将数据按机构分组
|
|
|
Map<Long, List<CoreSafetyExceptionData>> safetyExceptionDataMapList = resumptionExceptionDataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
|
|
|
- //营业前
|
|
|
- List<SafeIndexRuleCountVo> resumptionBeforeUndoIndexList = getResumptionUndoIndexList(BEFORE_POINT_CODE, resumptionIndexList);
|
|
|
- //营业中
|
|
|
- List<SafeIndexRuleCountVo> resumptionMiddleIndexList = getResumptionUndoIndexList(MIDDLE_POINT_CODE, resumptionIndexList);
|
|
|
- //营业后
|
|
|
- List<SafeIndexRuleCountVo> resumptionAfterUndoIndexList = getResumptionUndoIndexList(AFTER_POINT_CODE, resumptionIndexList);
|
|
|
|
|
|
for (Long orgId : safetyExceptionDataMapList.keySet()) {
|
|
|
orgList.stream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
|
|
|
@@ -195,6 +260,13 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
if (orgResumptionIndexList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
+ //营业前
|
|
|
+ List<SafeIndexRuleCountVo> resumptionBeforeUndoIndexList = getResumptionUndoIndexList(BEFORE_POINT_CODE, orgResumptionIndexList);
|
|
|
+ //营业中
|
|
|
+ List<SafeIndexRuleCountVo> resumptionMiddleIndexList = getResumptionUndoIndexList(MIDDLE_POINT_CODE, orgResumptionIndexList);
|
|
|
+ //营业后
|
|
|
+ List<SafeIndexRuleCountVo> resumptionAfterUndoIndexList = getResumptionUndoIndexList(AFTER_POINT_CODE, orgResumptionIndexList);
|
|
|
+
|
|
|
//获取机构的异常数据
|
|
|
List<CoreSafetyExceptionData> resumptionExceptionDataListByOrg = safetyExceptionDataMapList.get(orgId);
|
|
|
//构建执行时刻的map,用于存储每个时刻的异常数据
|
|
|
@@ -206,7 +278,7 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
}
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(resumptionMiddleIndexList)) {
|
|
|
- List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(resumptionMiddleIndexList, execTimeMap.get(4), orgId, year, month);
|
|
|
+ List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(resumptionMiddleIndexList, execTimeMap.get(3), orgId, year, month);
|
|
|
saveSourceData(sourceDataList, resumptionMiddleIndexList.get(0));
|
|
|
}
|
|
|
|
|
|
@@ -218,6 +290,7 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 计算连续数与累计数
|
|
|
*
|