|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
package com.ruoyi.web.modules.industryservice.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import java.util.ArrayList;
|
|
|
4
|
+import java.util.Date;
|
|
4
|
5
|
import java.util.List;
|
|
5
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
7
|
import org.springframework.stereotype.Service;
|
|
|
@@ -10,14 +11,18 @@ import com.ruoyi.common.core.domain.entity.SysDept;
|
|
10
|
11
|
import com.ruoyi.common.exception.ServiceException;
|
|
11
|
12
|
import com.ruoyi.common.utils.StringUtils;
|
|
12
|
13
|
import com.ruoyi.web.modules.industryservice.domain.BizFarmerHousehold;
|
|
|
14
|
+import com.ruoyi.web.modules.industryservice.domain.BizYakDiseaseWarning;
|
|
13
|
15
|
import com.ruoyi.web.modules.industryservice.domain.vo.FarmerHouseholdImportResultVo;
|
|
14
|
16
|
import com.ruoyi.web.modules.industryservice.mapper.BizFarmerHouseholdMapper;
|
|
|
17
|
+import com.ruoyi.web.modules.industryservice.mapper.BizYakDiseaseWarningMapper;
|
|
15
|
18
|
import com.ruoyi.web.modules.industryservice.service.IBizFarmerHouseholdService;
|
|
|
19
|
+import com.ruoyi.web.modules.industryservice.support.FarmerHouseholdDerivedSupport;
|
|
16
|
20
|
import com.ruoyi.web.modules.industryservice.support.FarmerHouseholdExcelExporter;
|
|
17
|
21
|
import com.ruoyi.web.modules.industryservice.support.FarmerHouseholdExcelParser;
|
|
18
|
22
|
import com.ruoyi.web.modules.industryservice.support.FarmerHouseholdExcelParser.ParsedRow;
|
|
19
|
23
|
import com.ruoyi.web.modules.industryservice.support.FarmerHouseholdValidation;
|
|
20
|
24
|
import com.ruoyi.web.modules.industryservice.support.TownDeptSupport;
|
|
|
25
|
+import com.ruoyi.web.modules.industryservice.support.YakDiseaseWarningRules;
|
|
21
|
26
|
import com.ruoyi.web.modules.industryservice.support.YakHerdInventoryMonthSupport;
|
|
22
|
27
|
import com.ruoyi.web.modules.industryservice.support.YakHerdInventoryYearSupport;
|
|
23
|
28
|
|
|
|
@@ -30,6 +35,9 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
30
|
35
|
@Autowired
|
|
31
|
36
|
private BizFarmerHouseholdMapper bizFarmerHouseholdMapper;
|
|
32
|
37
|
|
|
|
38
|
+ @Autowired
|
|
|
39
|
+ private BizYakDiseaseWarningMapper bizYakDiseaseWarningMapper;
|
|
|
40
|
+
|
|
33
|
41
|
@Autowired
|
|
34
|
42
|
private TownDeptSupport townDeptSupport;
|
|
35
|
43
|
|
|
|
@@ -54,7 +62,9 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
54
|
62
|
{
|
|
55
|
63
|
FarmerHouseholdValidation.validateRowForSave(row, townDeptSupport);
|
|
56
|
64
|
assertUniqueYearMonthVillage(row.getStatYear(), row.getStatMonth(), row.getVillageDeptId(), null);
|
|
57
|
|
- return bizFarmerHouseholdMapper.insertBizFarmerHousehold(row);
|
|
|
65
|
+ int rows = bizFarmerHouseholdMapper.insertBizFarmerHousehold(row);
|
|
|
66
|
+ syncGrassImbalanceWarning(row);
|
|
|
67
|
+ return rows;
|
|
58
|
68
|
}
|
|
59
|
69
|
|
|
60
|
70
|
@Override
|
|
|
@@ -68,7 +78,9 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
68
|
78
|
FarmerHouseholdValidation.validateRowForSave(row, townDeptSupport);
|
|
69
|
79
|
requireExistingRow(row.getId());
|
|
70
|
80
|
assertUniqueYearMonthVillage(row.getStatYear(), row.getStatMonth(), row.getVillageDeptId(), row.getId());
|
|
71
|
|
- return bizFarmerHouseholdMapper.updateBizFarmerHousehold(row);
|
|
|
81
|
+ int rows = bizFarmerHouseholdMapper.updateBizFarmerHousehold(row);
|
|
|
82
|
+ syncGrassImbalanceWarning(row);
|
|
|
83
|
+ return rows;
|
|
72
|
84
|
}
|
|
73
|
85
|
|
|
74
|
86
|
@Override
|
|
|
@@ -91,7 +103,15 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
91
|
103
|
{
|
|
92
|
104
|
return 0;
|
|
93
|
105
|
}
|
|
94
|
|
- return bizFarmerHouseholdMapper.deleteBizFarmerHouseholdByIds(cleaned.toArray(new Long[0]));
|
|
|
106
|
+ Long[] householdIds = cleaned.toArray(new Long[0]);
|
|
|
107
|
+ List<String> deviceNos = new ArrayList<>();
|
|
|
108
|
+ for (Long householdId : householdIds)
|
|
|
109
|
+ {
|
|
|
110
|
+ deviceNos.add(YakDiseaseWarningRules.farmerHouseholdDeviceNo(householdId));
|
|
|
111
|
+ }
|
|
|
112
|
+ bizYakDiseaseWarningMapper.deleteByDataSourceAndDeviceNos(
|
|
|
113
|
+ YakDiseaseWarningRules.DATA_SOURCE_FARMER_HOUSEHOLD, deviceNos);
|
|
|
114
|
+ return bizFarmerHouseholdMapper.deleteBizFarmerHouseholdByIds(householdIds);
|
|
95
|
115
|
}
|
|
96
|
116
|
|
|
97
|
117
|
/**
|
|
|
@@ -195,6 +215,7 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
195
|
215
|
bizFarmerHouseholdMapper.insertBizFarmerHousehold(row);
|
|
196
|
216
|
result.setInsertCount(result.getInsertCount() + 1);
|
|
197
|
217
|
}
|
|
|
218
|
+ syncGrassImbalanceWarning(row);
|
|
198
|
219
|
}
|
|
199
|
220
|
return result;
|
|
200
|
221
|
}
|
|
|
@@ -245,6 +266,90 @@ public class BizFarmerHouseholdServiceImpl implements IBizFarmerHouseholdService
|
|
245
|
266
|
return farmerHouseholdExcelExporter.export(statYear, statMonth, list, fillerName);
|
|
246
|
267
|
}
|
|
247
|
268
|
|
|
|
269
|
+ /**
|
|
|
270
|
+ * 草畜失衡时写入 biz_yak_disease_warning;恢复平衡则删除对应预警。
|
|
|
271
|
+ * 定位键:data_source=farmer_household + device_no=FH-{id}
|
|
|
272
|
+ */
|
|
|
273
|
+ private void syncGrassImbalanceWarning(BizFarmerHousehold row)
|
|
|
274
|
+ {
|
|
|
275
|
+ if (row == null || row.getId() == null)
|
|
|
276
|
+ {
|
|
|
277
|
+ return;
|
|
|
278
|
+ }
|
|
|
279
|
+ String deviceNo = YakDiseaseWarningRules.farmerHouseholdDeviceNo(row.getId());
|
|
|
280
|
+ if (FarmerHouseholdDerivedSupport.isImbalanced(row))
|
|
|
281
|
+ {
|
|
|
282
|
+ Date now = new Date();
|
|
|
283
|
+ BizYakDiseaseWarning existing = bizYakDiseaseWarningMapper.selectByDataSourceAndDeviceNo(
|
|
|
284
|
+ YakDiseaseWarningRules.DATA_SOURCE_FARMER_HOUSEHOLD, deviceNo);
|
|
|
285
|
+ BizYakDiseaseWarning warning = new BizYakDiseaseWarning();
|
|
|
286
|
+ warning.setDeviceNo(deviceNo);
|
|
|
287
|
+ warning.setDataSource(YakDiseaseWarningRules.DATA_SOURCE_FARMER_HOUSEHOLD);
|
|
|
288
|
+ warning.setWarningType(YakDiseaseWarningRules.WARNING_TYPE_GRASS_IMBALANCE);
|
|
|
289
|
+ warning.setPastureId(null);
|
|
|
290
|
+ warning.setPastureName(row.getVillageName());
|
|
|
291
|
+ warning.setYakNo(null);
|
|
|
292
|
+ warning.setAlertTime(now);
|
|
|
293
|
+ warning.setCollectTime(now);
|
|
|
294
|
+ warning.setLastSyncTime(now);
|
|
|
295
|
+ warning.setUpdateTime(now);
|
|
|
296
|
+ warning.setMeasuredValue(row.getYearEndStockSheepUnit() == null ? null
|
|
|
297
|
+ : row.getYearEndStockSheepUnit().stripTrailingZeros().toPlainString());
|
|
|
298
|
+ warning.setReferenceRange(row.getApprovedCarryingCapacity() == null ? null
|
|
|
299
|
+ : row.getApprovedCarryingCapacity().stripTrailingZeros().toPlainString());
|
|
|
300
|
+ warning.setAlertMessage(buildGrassImbalanceMessage(row));
|
|
|
301
|
+ if (existing == null)
|
|
|
302
|
+ {
|
|
|
303
|
+ warning.setCreateTime(now);
|
|
|
304
|
+ bizYakDiseaseWarningMapper.insertBizYakDiseaseWarning(warning);
|
|
|
305
|
+ }
|
|
|
306
|
+ else
|
|
|
307
|
+ {
|
|
|
308
|
+ warning.setId(existing.getId());
|
|
|
309
|
+ bizYakDiseaseWarningMapper.updateAlertContent(warning);
|
|
|
310
|
+ }
|
|
|
311
|
+ }
|
|
|
312
|
+ else
|
|
|
313
|
+ {
|
|
|
314
|
+ bizYakDiseaseWarningMapper.deleteByDataSourceAndDeviceNo(
|
|
|
315
|
+ YakDiseaseWarningRules.DATA_SOURCE_FARMER_HOUSEHOLD, deviceNo);
|
|
|
316
|
+ }
|
|
|
317
|
+ }
|
|
|
318
|
+
|
|
|
319
|
+ private static String buildGrassImbalanceMessage(BizFarmerHousehold row)
|
|
|
320
|
+ {
|
|
|
321
|
+ StringBuilder sb = new StringBuilder();
|
|
|
322
|
+ sb.append("草畜失衡预警:");
|
|
|
323
|
+ if (row.getStatYear() != null)
|
|
|
324
|
+ {
|
|
|
325
|
+ sb.append(row.getStatYear()).append("年");
|
|
|
326
|
+ }
|
|
|
327
|
+ if (row.getStatMonth() != null)
|
|
|
328
|
+ {
|
|
|
329
|
+ sb.append(row.getStatMonth()).append("月");
|
|
|
330
|
+ }
|
|
|
331
|
+ if (StringUtils.isNotEmpty(row.getTownName()) || StringUtils.isNotEmpty(row.getVillageName()))
|
|
|
332
|
+ {
|
|
|
333
|
+ sb.append(" ");
|
|
|
334
|
+ if (StringUtils.isNotEmpty(row.getTownName()))
|
|
|
335
|
+ {
|
|
|
336
|
+ sb.append(row.getTownName());
|
|
|
337
|
+ }
|
|
|
338
|
+ if (StringUtils.isNotEmpty(row.getVillageName()))
|
|
|
339
|
+ {
|
|
|
340
|
+ sb.append(row.getVillageName());
|
|
|
341
|
+ }
|
|
|
342
|
+ }
|
|
|
343
|
+ sb.append(":核定年末草畜平衡载畜量(")
|
|
|
344
|
+ .append(row.getApprovedCarryingCapacity() == null ? "-"
|
|
|
345
|
+ : row.getApprovedCarryingCapacity().stripTrailingZeros().toPlainString())
|
|
|
346
|
+ .append(")小于年底牲畜存栏绵羊单位(")
|
|
|
347
|
+ .append(row.getYearEndStockSheepUnit() == null ? "-"
|
|
|
348
|
+ : row.getYearEndStockSheepUnit().stripTrailingZeros().toPlainString())
|
|
|
349
|
+ .append(")");
|
|
|
350
|
+ return sb.toString();
|
|
|
351
|
+ }
|
|
|
352
|
+
|
|
248
|
353
|
private void assertUniqueYearMonthVillage(Integer statYear, Integer statMonth, Long villageDeptId, Long excludeId)
|
|
249
|
354
|
{
|
|
250
|
355
|
if (bizFarmerHouseholdMapper.countByYearMonthAndVillageExcludeId(statYear, statMonth, villageDeptId,
|