ParkingEquipmentPushJob.java
4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.zteits.park.job.datahub;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.park.domain.HubEnterpriseInfo;
import com.zteits.park.domain.HubEnterpriseInfoExample;
import com.zteits.park.domain.HubParkingEquipment;
import com.zteits.park.domain.HubParkingEquipmentExample;
import com.zteits.park.mapper.HubEnterpriseInfoMapper;
import com.zteits.park.mapper.HubParkingEquipmentMapper;
import com.zteits.park.util.ParkInfoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 停车场设备信息推送JOB
* @since 2025-08-17
*/
@Component
public class ParkingEquipmentPushJob {
private static final Logger logger = LoggerFactory.getLogger(ParkingEquipmentPushJob.class);
@Autowired
private HubParkingEquipmentMapper hubParkingEquipmentMapper;
@Autowired
private HubConfig hubConfig;
@Autowired
private TokenService tokenService;
@Autowired
private HubEnterpriseInfoMapper hubEnterpriseInfoMapper;
@XxlJob("ParkingEquipmentPushJob")
public ReturnT<String> execute() {
log("开始推送停车场设备信息JOB");
try {
this.pushData();
} catch (Exception e) {
logger.error("推送停车场设备信息JOB异常:" + e.getMessage(), e);
log("推送停车场设备信息JOB异常:" + e.getMessage());
}
return ReturnT.SUCCESS;
}
private void pushData() {
// 查询所有设备信息
HubParkingEquipmentExample example = new HubParkingEquipmentExample();
example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); // 只查询生效的数据
List<HubParkingEquipment> equipmentList = hubParkingEquipmentMapper.selectByExample(example);
if (CollectionUtils.isEmpty(equipmentList)) {
log("没有需要推送的停车场设备信息");
return;
}
// 查询运营单位信息
HubEnterpriseInfoExample enterpriseInfoExample = new HubEnterpriseInfoExample();
enterpriseInfoExample.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<HubEnterpriseInfo> hubEnterpriseInfos = hubEnterpriseInfoMapper.selectByExample(enterpriseInfoExample);
if (CollectionUtils.isEmpty(hubEnterpriseInfos)) {
log("没有需要推送的运营单位信息");
return;
}
HubEnterpriseInfo hubEnterpriseInfo = hubEnterpriseInfos.get(0);
// 按停车场分组
Map<String, List<HubParkingEquipment>> equipmentByPark = equipmentList.stream()
.collect(Collectors.groupingBy(HubParkingEquipment::getParkCode));
// 遍历每个停车场的设备信息
for (Map.Entry<String, List<HubParkingEquipment>> entry : equipmentByPark.entrySet()) {
String parkCode = entry.getKey();
List<HubParkingEquipment> equipments = entry.getValue();
// 构造CollectEquipmentVO列表
List<com.jtjt.upload.client.vo.CollectEquipmentVO> collectEquipmentVOs = new ArrayList<>();
for (HubParkingEquipment equipment : equipments) {
com.jtjt.upload.client.vo.CollectEquipmentVO vo = new com.jtjt.upload.client.vo.CollectEquipmentVO();
vo.setBizId(hubEnterpriseInfo.getBizId());
vo.setParkCode(parkCode);
vo.setName(equipment.getName());
vo.setCode(equipment.getCode());
vo.setType(equipment.getType());
vo.setSentTime(LocalDateTime.now());
collectEquipmentVOs.add(vo);
}
// 发送设备信息
int code = ParkInfoUtil.getSingleInstance().sendCollectEqiupment(hubConfig.getUrlPrefix(), tokenService.getToken(false), collectEquipmentVOs);
if (code == 401) {
// 重新刷新token,再次尝试发送
ParkInfoUtil.getSingleInstance().sendCollectEqiupment(hubConfig.getUrlPrefix(), tokenService.getToken(true), collectEquipmentVOs);
}
}
}
private void log(String msg) {
XxlJobHelper.log(msg);
logger.info(msg);
}
}