|
@@ -1,5 +1,6 @@
|
|
|
package com.ims.eval.schedule;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.ims.common.utils.DateUtils;
|
|
|
import com.ims.common.utils.FormulaUtils;
|
|
|
import com.ims.eval.entity.EvaluationDeptBusinessAssessment;
|
|
@@ -41,12 +42,15 @@ public class EvaluationWarningSchedule {
|
|
|
private final String TYPE_JDKP = "JDKP";
|
|
|
//月度考评
|
|
|
private final String TYPE_YDKP = "YDKP";
|
|
|
+ //触发时间属于当前季度的第几个月,1,4,7,10表示每个季度的第一个月,2,5,8,11表示每个季度的第2个月,3,6,9,12表示每个季度的第三个月
|
|
|
+ private final int[][] SEASON = new int[][]{{1,4,7,10},{2,5,8,11},{3,6,9,12}};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 年度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+// @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningRuleResolveNDKP(){
|
|
|
List<EvaluationWarningRule> list = warningRuleService.warningRuleList(null, null, TYPE_NDKP, true);
|
|
|
List<Map<String, Object>> companys = evaluationService.getCompanyWarning(TYPE_NDKP);
|
|
@@ -54,13 +58,14 @@ public class EvaluationWarningSchedule {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- calculate(list, companys);
|
|
|
+ calculate(list, companys, TYPE_NDKP);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 季度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+// @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningRuleResolveJDKP(){
|
|
|
List<EvaluationWarningRule> list = warningRuleService.warningRuleList(null, null, TYPE_JDKP, true);
|
|
|
List<Map<String, Object>> companys = evaluationService.getCompanyWarning(TYPE_JDKP);
|
|
@@ -68,21 +73,22 @@ public class EvaluationWarningSchedule {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- calculate(list, companys);
|
|
|
+ calculate(list, companys, TYPE_JDKP);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 月度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+// @Scheduled(cron = "0 0 23 * * ?") // cron表达式: 每天23点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningRuleResolveYDKP(){
|
|
|
- List<EvaluationWarningRule> list = warningRuleService.warningRuleList(null, null, TYPE_YDKP,true);
|
|
|
+ List<EvaluationWarningRule> list = warningRuleService.warningRuleList(null, null, TYPE_YDKP, true);
|
|
|
List<Map<String, Object>> companys = evaluationService.getCompanyWarning(TYPE_YDKP);
|
|
|
if (list == null || list.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- calculate(list, companys);
|
|
|
+ calculate(list, companys, TYPE_YDKP);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -90,95 +96,112 @@ public class EvaluationWarningSchedule {
|
|
|
/**
|
|
|
* 单位年度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "* * 8 1 4 ? 2023-2050") // cron表达式: 每年4月1号8点触发
|
|
|
+// @Scheduled(cron = "0 0 0 1 4 ?") // cron表达式: 每年4月1号0点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningEvaluationNDKP(){
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
String year = String.valueOf(cal.get(Calendar.YEAR));
|
|
|
List<OrganizationEvaluation> list = evaluationService.list(null, TYPE_NDKP, year, null);
|
|
|
|
|
|
+ String company = "";
|
|
|
String title = "单位年度考评";
|
|
|
String content = "";
|
|
|
if (list == null || list.size() == 0) {
|
|
|
content = "单位年度考评计划未建立";
|
|
|
+ company = "公司本部";
|
|
|
}
|
|
|
Optional<OrganizationEvaluation> optional = list.stream().filter(item -> item.getStage().equals("流程未启动")).findFirst();
|
|
|
content = optional.isPresent() ? "单位年度考评流程未启动" : content;
|
|
|
+ company = optional.isPresent() ? optional.get().getCreateOrgName() : company;
|
|
|
|
|
|
- saveWarningInfo(null, null, title, content, null, 0, 0);
|
|
|
+ saveWarningInfo(null, null, title, content, null, 0, 0, company);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单位季度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 5 20 1 1,4,7,10 ?") // cron表达式: 每个季度的第一个月的20号的5执行一次
|
|
|
+// @Scheduled(cron = "0 5 20 1 1,4,7,10 ?") // cron表达式: 每个季度的第一个月的20号的5执行一次
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningEvaluationJDKP(){
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
String year = String.valueOf(cal.get(Calendar.YEAR));
|
|
|
String season = String.valueOf(DateUtils.getSeason(cal.getTime()));
|
|
|
List<OrganizationEvaluation> list = evaluationService.list(null, TYPE_JDKP, year, season);
|
|
|
|
|
|
+ String company = "";
|
|
|
String title = "单位季度考评";
|
|
|
String content = "";
|
|
|
if (list == null || list.size() == 0) {
|
|
|
content = "单位季度考评计划未建立";
|
|
|
+ company = "公司本部";
|
|
|
}
|
|
|
Optional<OrganizationEvaluation> optional = list.stream().filter(item -> item.getStage().equals("流程未启动")).findFirst();
|
|
|
content = optional.isPresent() ? "单位季度考评流程未启动" : content;
|
|
|
+ company = optional.isPresent() ? optional.get().getCreateOrgName() : company;
|
|
|
|
|
|
- saveWarningInfo(null, null, title, content, null, 0, 0);
|
|
|
+ saveWarningInfo(null, null, title, content, null, 0, 0, company);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单位月度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0 7 5 * ?") // cron表达式: 每月5日上午7点触发
|
|
|
+// @Scheduled(cron = "0 0 7 5 * ?") // cron表达式: 每月5日上午7点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningEvaluationYDKP(){
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
String year = String.valueOf(cal.get(Calendar.YEAR));
|
|
|
String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
|
|
|
List<OrganizationEvaluation> list = evaluationService.list(null, TYPE_YDKP, year, month);
|
|
|
|
|
|
+ String company = "";
|
|
|
String title = "单位月度考评";
|
|
|
String content = "";
|
|
|
if (list == null || list.size() == 0) {
|
|
|
content = "单位月度考评计划未建立";
|
|
|
+ company = "公司本部";
|
|
|
}
|
|
|
Optional<OrganizationEvaluation> optional = list.stream().filter(item -> item.getStage().equals("流程未启动")).findFirst();
|
|
|
content = optional.isPresent() ? "单位月度考评流程未启动" : content;
|
|
|
+ company = optional.isPresent() ? optional.get().getCreateOrgName() : company;
|
|
|
|
|
|
- saveWarningInfo(null, null, title, content, null, 0, 0);
|
|
|
+ saveWarningInfo(null, null, title, content, null, 0, 0, company);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 部门年度考评
|
|
|
*/
|
|
|
- @Scheduled(cron = "* * 8 1 4 ? 2023,2050") // cron表达式: 每年4月1号8点触发
|
|
|
+// @Scheduled(cron = "0 0 0 1 4 ?") // cron表达式: 每年4月1号0点触发
|
|
|
+ @Scheduled(cron="0/50 * * * * ?")
|
|
|
public void warningEvaluationDeptYDKP(){
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
String year = String.valueOf(cal.get(Calendar.YEAR));
|
|
|
List<EvaluationDeptBusinessAssessment> list = assessmentService.list(year);
|
|
|
|
|
|
+ String company = "";
|
|
|
String title = "部门年度考评";
|
|
|
String content = "";
|
|
|
if (list == null || list.size() == 0) {
|
|
|
content = "部门年度考评计划未建立";
|
|
|
+ company = "公司部门";
|
|
|
}
|
|
|
Optional<EvaluationDeptBusinessAssessment> optional = list.stream().filter(item -> item.getStage().equals("流程未启动")).findFirst();
|
|
|
content = optional.isPresent() ? "部门年度考评计划流程未启动" : content;
|
|
|
+ company = optional.isPresent() ? optional.get().getDeptName() : company;
|
|
|
|
|
|
- saveWarningInfo(null, null, title, content, null, 0, 0);
|
|
|
+ saveWarningInfo(null, null, title, content, null, 0, 0, company);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- private void calculate(List<EvaluationWarningRule> rules, List<Map<String, Object>> companys){
|
|
|
+ private void calculate(List<EvaluationWarningRule> rules, List<Map<String, Object>> companys, String type){
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
Map<Object, List<Map<String, Object>>> collect = companys.stream().collect(Collectors.groupingBy(m -> m.get("indicator_id")));
|
|
|
for (EvaluationWarningRule rule : rules){
|
|
|
- if (!cal.getTime().equals(rule.getCronTime())){
|
|
|
+ if (!isFocus(rule, type)){
|
|
|
continue;
|
|
|
}
|
|
|
+ String company = "";
|
|
|
double targetValue = 0;
|
|
|
double completeValue = 0;
|
|
|
String expression = rule.getExpression();
|
|
@@ -190,20 +213,20 @@ public class EvaluationWarningSchedule {
|
|
|
}
|
|
|
targetValue = mp.containsKey("JHZ") ? (double) mp.get("JHZ") : mp.containsKey("DBZ") ? (double) mp.get("DBZ") : 0;
|
|
|
completeValue = mp.containsKey("WCZ") ? (double) mp.get("WCZ") : 0;
|
|
|
+ company = mp.containsKey("organization_short_name") ? String.valueOf(mp.get("organization_short_name")) : company;
|
|
|
}
|
|
|
/**
|
|
|
* 0:未报警 1:报警
|
|
|
*/
|
|
|
double v = FormulaUtils.calculateFormula(expression);
|
|
|
if (v >= 1){
|
|
|
- String title = "指标预警";
|
|
|
- String content = "完成值未达到预定目标值,请及时查看";
|
|
|
- saveWarningInfo(rule.getBinSection(), rule.getIndicatorId(), title, content, rule.getId(), targetValue, completeValue);
|
|
|
+ saveWarningInfo(rule.getBinSection(), rule.getIndicatorId(), rule.getRuleName(), rule.getRuleDes(), rule.getId(), targetValue, completeValue, company);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void saveWarningInfo(String binSection, String indicatorId, String title, String content, String ruleId, double targetValue, double completeValue){
|
|
|
+ private void saveWarningInfo(String binSection, String indicatorId, String title, String content,
|
|
|
+ String ruleId, double targetValue, double completeValue, String company){
|
|
|
EvaluationWarningInfo info = new EvaluationWarningInfo();
|
|
|
info.setBinSection(binSection);
|
|
|
info.setIndicatorId(indicatorId);
|
|
@@ -213,7 +236,49 @@ public class EvaluationWarningSchedule {
|
|
|
info.setRuleId(ruleId);
|
|
|
info.setTargetValue(targetValue);
|
|
|
info.setCompleteValue(completeValue);
|
|
|
+ info.setCompany(company);
|
|
|
warningInfoService.save(info);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private boolean isFocus(EvaluationWarningRule rule, String type){
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int nowMonth = cal.get(Calendar.MONTH) + 1;
|
|
|
+ int nowDay = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
+ cal.setTime(rule.getCronTime());
|
|
|
+ switch (type){
|
|
|
+ case TYPE_NDKP:
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1;
|
|
|
+ int day = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
+ if (nowMonth == month && nowDay == day){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TYPE_JDKP:
|
|
|
+ int day2 = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
+ int season = DateUtils.getSeason(cal.getTime());
|
|
|
+ int index = season % 3;
|
|
|
+ int[] arr = SEASON[index-1];
|
|
|
+ for (int i = 0; i < arr.length; i++){
|
|
|
+ if (nowMonth == arr[i] && nowDay == day2){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TYPE_YDKP:
|
|
|
+ int day3 = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
+ if (nowDay == day3){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args){
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ System.out.println(cal.get(Calendar.YEAR));
|
|
|
+ System.out.println(cal.get(Calendar.MONTH) + 1);
|
|
|
+ System.out.println(cal.get(Calendar.DAY_OF_MONTH));
|
|
|
+ }
|
|
|
}
|