|
|
@@ -1,34 +1,141 @@
|
|
1
|
1
|
package com.chinaitop.depot.tempWarn.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import com.chinaitop.depot.tempWarn.mapper.StorageThresholdAlarmMapper;
|
|
|
4
|
+import com.chinaitop.depot.tempWarn.mapper.StorageThresholdSetMapper;
|
|
4
|
5
|
import com.chinaitop.depot.tempWarn.model.StorageThresholdAlarm;
|
|
5
|
6
|
import com.chinaitop.depot.tempWarn.model.StorageThresholdAlarmExample;
|
|
|
7
|
+import com.chinaitop.depot.tempWarn.model.StorageThresholdSet;
|
|
|
8
|
+import com.chinaitop.depot.tempWarn.model.StorageThresholdSetExample;
|
|
6
|
9
|
import com.chinaitop.depot.tempWarn.param.StorageThresholdAlarmPageParam;
|
|
7
|
10
|
import com.chinaitop.depot.tempWarn.service.StorageThresholdAlarmService;
|
|
|
11
|
+import com.chinaitop.depot.utils.DateUtil;
|
|
|
12
|
+import lombok.extern.slf4j.Slf4j;
|
|
8
|
13
|
import org.springframework.stereotype.Service;
|
|
|
14
|
+import org.springframework.util.CollectionUtils;
|
|
9
|
15
|
import org.springframework.util.ObjectUtils;
|
|
10
|
16
|
|
|
11
|
17
|
import javax.annotation.Resource;
|
|
|
18
|
+import java.time.LocalDate;
|
|
|
19
|
+import java.time.ZoneId;
|
|
|
20
|
+import java.util.Date;
|
|
12
|
21
|
import java.util.List;
|
|
|
22
|
+import java.util.UUID;
|
|
13
|
23
|
|
|
14
|
24
|
/**
|
|
15
|
25
|
* @author qingsong.han
|
|
16
|
26
|
* @description:
|
|
17
|
27
|
* @create 2024-12-09 17:08
|
|
18
|
28
|
*/
|
|
|
29
|
+@Slf4j
|
|
19
|
30
|
@Service
|
|
20
|
31
|
public class StorageThresholdAlarmServiceImpl implements StorageThresholdAlarmService {
|
|
21
|
32
|
@Resource
|
|
22
|
33
|
private StorageThresholdAlarmMapper thresholdAlarmMapper;
|
|
|
34
|
+ @Resource
|
|
|
35
|
+ private StorageThresholdSetMapper thresholdSetMapper;
|
|
23
|
36
|
|
|
24
|
37
|
@Override
|
|
25
|
38
|
public List<StorageThresholdAlarm> getPageList(StorageThresholdAlarmPageParam pageParam) {
|
|
26
|
39
|
StorageThresholdAlarmExample example = new StorageThresholdAlarmExample();
|
|
27
|
40
|
StorageThresholdAlarmExample.Criteria criteria = example.createCriteria();
|
|
28
|
41
|
criteria.andOrgIdEqualTo(pageParam.getOrgId());
|
|
|
42
|
+ criteria.andDataFlagEqualTo(1);
|
|
29
|
43
|
if (!ObjectUtils.isEmpty(pageParam.getHouseId())) {
|
|
30
|
44
|
criteria.andHouseIdEqualTo(pageParam.getHouseId());
|
|
31
|
45
|
}
|
|
32
|
46
|
return thresholdAlarmMapper.selectByExample(example);
|
|
33
|
47
|
}
|
|
|
48
|
+
|
|
|
49
|
+ @Override
|
|
|
50
|
+ public void saveAgeWaring() {
|
|
|
51
|
+ // 查询库内报警值
|
|
|
52
|
+ List<StorageThresholdSet> storageThresholdSets = thresholdSetMapper.selectAll();
|
|
|
53
|
+ if (!CollectionUtils.isEmpty(storageThresholdSets)) {
|
|
|
54
|
+ // 查询粮情卡数据
|
|
|
55
|
+ List<StorageThresholdAlarm> listCar = thresholdSetMapper.selectGrainCardList();
|
|
|
56
|
+ if (!CollectionUtils.isEmpty(listCar)) {
|
|
|
57
|
+ // 获取当前时间
|
|
|
58
|
+ LocalDate now = LocalDate.now();
|
|
|
59
|
+ String nowStr = now.toString();
|
|
|
60
|
+ log.info("nowStr: {}", nowStr);
|
|
|
61
|
+ // 转换为储存超限时间类型
|
|
|
62
|
+ Date nowDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
63
|
+ // 比对是否超限
|
|
|
64
|
+ storageThresholdSets.forEach(set -> {
|
|
|
65
|
+ // 市平台设置
|
|
|
66
|
+ Integer sptccnx = set.getSptccnx();
|
|
|
67
|
+ // 库内设置
|
|
|
68
|
+ Integer knccnx = set.getKnccnx();
|
|
|
69
|
+ // 任意一个设置都执行过滤报警
|
|
|
70
|
+ if (!ObjectUtils.isEmpty(knccnx) || !ObjectUtils.isEmpty(sptccnx)) {
|
|
|
71
|
+ listCar.forEach(alarm -> {
|
|
|
72
|
+ // 对比品种
|
|
|
73
|
+ if (set.getLypzmc().equals(alarm.getLypzmc())) {
|
|
|
74
|
+ // 生产年份
|
|
|
75
|
+ String scnf = alarm.getScnf();
|
|
|
76
|
+ if (set.getOrgId().equals(alarm.getOrgId())) {
|
|
|
77
|
+ if (!ObjectUtils.isEmpty(scnf)) {
|
|
|
78
|
+ // 市平台报警
|
|
|
79
|
+ if (!ObjectUtils.isEmpty(sptccnx)) {
|
|
|
80
|
+ // 生产年份+设置超限年份=已储年份
|
|
|
81
|
+ int sptccnxPK = Integer.parseInt(scnf) + sptccnx;// 到期
|
|
|
82
|
+ // 计算超期时间
|
|
|
83
|
+ String cccxsjStr = String.format("%s%s", sptccnxPK, "-01-01");
|
|
|
84
|
+ Date cccxsj = DateUtil.stringToData(cccxsjStr, "yyyy-MM-dd");
|
|
|
85
|
+ // 是否超限
|
|
|
86
|
+ log.info("市平台 cccxsjStr: {} nowStr: {}", cccxsjStr, nowStr);
|
|
|
87
|
+ if (nowStr.equals(cccxsjStr)) {
|
|
|
88
|
+ alarm.setId(UUID.randomUUID().toString());
|
|
|
89
|
+ alarm.setDataFlag(0);
|
|
|
90
|
+ alarm.setKnccnx(sptccnx);
|
|
|
91
|
+ alarm.setCccxsj(cccxsj);
|
|
|
92
|
+ alarm.setBjxx("已超过存储期限要求");
|
|
|
93
|
+ alarm.setBjsj(nowDate);
|
|
|
94
|
+ thresholdAlarmMapper.insertSelective(alarm);
|
|
|
95
|
+ }
|
|
|
96
|
+ }
|
|
|
97
|
+ // 库平台报警
|
|
|
98
|
+ if (!ObjectUtils.isEmpty(knccnx)) {
|
|
|
99
|
+ // 是否超限
|
|
|
100
|
+ int knccnxPK = Integer.parseInt(scnf) + knccnx;
|
|
|
101
|
+ String cccxsjStr = String.format("%s%s", knccnxPK, "-01-01");
|
|
|
102
|
+// String cccxsjStr = String.format("%s%s", knccnxPK, "-12-10");// 测试
|
|
|
103
|
+ // 提前3个月报警
|
|
|
104
|
+ String localDate_3 = now.minusMonths(3).toString();
|
|
|
105
|
+ // 提前1个月报警
|
|
|
106
|
+ String localDate_1 = now.minusMonths(1).toString();
|
|
|
107
|
+ // 保存
|
|
|
108
|
+ alarm.setId(UUID.randomUUID().toString());
|
|
|
109
|
+ alarm.setDataFlag(1);
|
|
|
110
|
+ alarm.setKnccnx(knccnx);
|
|
|
111
|
+ alarm.setBjsj(nowDate);
|
|
|
112
|
+ log.info("库平台 cccxsjStr: {} nowStr: {}", cccxsjStr, nowStr);
|
|
|
113
|
+ if (nowStr.equals(cccxsjStr)) {
|
|
|
114
|
+ Date cccxsj = DateUtil.stringToData(cccxsjStr, "yyyy-MM-dd");
|
|
|
115
|
+ alarm.setCccxsj(cccxsj);
|
|
|
116
|
+ alarm.setBjxx("已超过存储期限要求");
|
|
|
117
|
+ thresholdAlarmMapper.insertSelective(alarm);
|
|
|
118
|
+ } else if (localDate_3.equals(cccxsjStr)) {
|
|
|
119
|
+ Date cccxsj = DateUtil.stringToData(localDate_3, "yyyy-MM-dd");
|
|
|
120
|
+ alarm.setCccxsj(cccxsj);
|
|
|
121
|
+ alarm.setBjxx("距离超过储存期限还有3个月");
|
|
|
122
|
+ thresholdAlarmMapper.insertSelective(alarm);
|
|
|
123
|
+ } else if (localDate_1.equals(cccxsjStr)) {
|
|
|
124
|
+ Date cccxsj = DateUtil.stringToData(localDate_1, "yyyy-MM-dd");
|
|
|
125
|
+ alarm.setCccxsj(cccxsj);
|
|
|
126
|
+ alarm.setBjxx("距离超过储存期限还有1个月");
|
|
|
127
|
+ thresholdAlarmMapper.insertSelective(alarm);
|
|
|
128
|
+ }
|
|
|
129
|
+ }
|
|
|
130
|
+ }
|
|
|
131
|
+ }
|
|
|
132
|
+ }
|
|
|
133
|
+ });
|
|
|
134
|
+ }
|
|
|
135
|
+ });
|
|
|
136
|
+ }
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
34
|
141
|
}
|