ParkingInfoPushJob.java
8.16 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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.HubParkingInfoBO;
import com.zteits.park.mapper.HubEnterpriseInfoMapper;
import com.zteits.park.mapper.smapper.HubParkingInfoSMapper;
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.util.List;
/**
* 停车场数据推送JOB
* @since 2025-08-17
*/
@Component
public class ParkingInfoPushJob {
private static final Logger logger = LoggerFactory.getLogger(ParkingInfoPushJob.class);
@Autowired
private HubParkingInfoSMapper hubParkingInfoSMapper;
@Autowired
private HubEnterpriseInfoMapper hubEnterpriseInfoMapper;
@Autowired
private HubConfig hubConfig;
@Autowired
private TokenService tokenService;
@XxlJob("ParkingInfoPushJob")
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() {
List<HubParkingInfoBO> hubParkingInfoList = hubParkingInfoSMapper.selectList(null);
if (CollectionUtils.isEmpty(hubParkingInfoList)) {
log("没有需要推送的停车场信息");
}
// 查询运营单位信息
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);
for (HubParkingInfoBO hubParkingInfo : hubParkingInfoList) {
//发送停车场信息
hubParkingInfo.setBizId(hubEnterpriseInfo.getBizId());
hubParkingInfo.setOpenParkPlaceNum(hubParkingInfo.getBerths());
// Integer类型字段如果为空则赋值为0
convert(hubParkingInfo);
// 发送停车场信息
int code = ParkInfoUtil.getSingleInstance().sendParkInfo(hubConfig.getUrlPrefix(), tokenService.getToken(false), hubParkingInfo);
if (code == 401) {
// 重新刷新token,再次尝试发送
ParkInfoUtil.getSingleInstance().sendParkInfo(hubConfig.getUrlPrefix(), tokenService.getToken(true), hubParkingInfo);
}
}
}
private static void convert(HubParkingInfoBO hubParkingInfo) {
if (hubParkingInfo.getBerths() == null) hubParkingInfo.setBerths(0);
if (hubParkingInfo.getOpenParkPlaceNum() == null) hubParkingInfo.setOpenParkPlaceNum(0);
if (hubParkingInfo.getChargeNum() == null) hubParkingInfo.setChargeNum(0);
if (hubParkingInfo.getEntranceNum() == null) hubParkingInfo.setEntranceNum(0);
if (hubParkingInfo.getExitNum() == null) hubParkingInfo.setExitNum(0);
if (hubParkingInfo.getSharedParkPlaceNum() == null) hubParkingInfo.setSharedParkPlaceNum(0);
if (hubParkingInfo.getFreeNum() == null) hubParkingInfo.setFreeNum(0);
if (hubParkingInfo.getLargeVehicleNum() == null) hubParkingInfo.setLargeVehicleNum(0);
if (hubParkingInfo.getLightVehicleNum() == null) hubParkingInfo.setLightVehicleNum(0);
if (hubParkingInfo.getParkPlaceNum01() == null) hubParkingInfo.setParkPlaceNum01(0);
if (hubParkingInfo.getParkPlaceNum02() == null) hubParkingInfo.setParkPlaceNum02(0);
if (hubParkingInfo.getParkPlaceNum03() == null) hubParkingInfo.setParkPlaceNum03(0);
if (hubParkingInfo.getParkPlaceNum04() == null) hubParkingInfo.setParkPlaceNum04(0);
if (hubParkingInfo.getParkPlaceNum05() == null) hubParkingInfo.setParkPlaceNum05(0);
if (hubParkingInfo.getParkPlaceNum06() == null) hubParkingInfo.setParkPlaceNum06(0);
if (hubParkingInfo.getWorkerNum() == null) hubParkingInfo.setWorkerNum(0);
if (hubParkingInfo.getDaySmallCarChrononMinsFirstHour() == null) hubParkingInfo.setDaySmallCarChrononMinsFirstHour(0);
if (hubParkingInfo.getDaySmallCarChrononMins() == null) hubParkingInfo.setDaySmallCarChrononMins(0);
if (hubParkingInfo.getNightSmallCarChrononMins() == null) hubParkingInfo.setNightSmallCarChrononMins(0);
if (hubParkingInfo.getDayBigCarChrononMinsFirstHour() == null) hubParkingInfo.setDayBigCarChrononMinsFirstHour(0);
if (hubParkingInfo.getDayBigCarChrononMins() == null) hubParkingInfo.setDayBigCarChrononMins(0);
if (hubParkingInfo.getNightBigCarChrononMins() == null) hubParkingInfo.setNightBigCarChrononMins(0);
if (hubParkingInfo.getChargingStandardLeaseSmallCar() == null) hubParkingInfo.setChargingStandardLeaseSmallCar(0);
if (hubParkingInfo.getChargingStandardLeaseBigCar() == null) hubParkingInfo.setChargingStandardLeaseBigCar(0);
if (hubParkingInfo.getDataStatus() == null) hubParkingInfo.setDataStatus(0);
// Float类型字段如果为空则赋值为0,不为空则保留2位小数
if (hubParkingInfo.getChargingStandardTempSmallCarDayFirstHour() == null) {
hubParkingInfo.setChargingStandardTempSmallCarDayFirstHour(0.0f);
} else {
hubParkingInfo.setChargingStandardTempSmallCarDayFirstHour(Math.round(hubParkingInfo.getChargingStandardTempSmallCarDayFirstHour() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getChargingStandardTempSmallCarDay() == null) {
hubParkingInfo.setChargingStandardTempSmallCarDay(0.0f);
} else {
hubParkingInfo.setChargingStandardTempSmallCarDay(Math.round(hubParkingInfo.getChargingStandardTempSmallCarDay() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getChargingStandardTempSmallCarNight() == null) {
hubParkingInfo.setChargingStandardTempSmallCarNight(0.0f);
} else {
hubParkingInfo.setChargingStandardTempSmallCarNight(Math.round(hubParkingInfo.getChargingStandardTempSmallCarNight() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getChargingStandardTempBigCarDayFirstHour() == null) {
hubParkingInfo.setChargingStandardTempBigCarDayFirstHour(0.0f);
} else {
hubParkingInfo.setChargingStandardTempBigCarDayFirstHour(Math.round(hubParkingInfo.getChargingStandardTempBigCarDayFirstHour() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getChargingStandardTempBigCarDay() == null) {
hubParkingInfo.setChargingStandardTempBigCarDay(0.0f);
} else {
hubParkingInfo.setChargingStandardTempBigCarDay(Math.round(hubParkingInfo.getChargingStandardTempBigCarDay() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getChargingStandardTempBigCarNight() == null) {
hubParkingInfo.setChargingStandardTempBigCarNight(0.0f);
} else {
hubParkingInfo.setChargingStandardTempBigCarNight(Math.round(hubParkingInfo.getChargingStandardTempBigCarNight() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getTsaaFee() == null) {
hubParkingInfo.setTsaaFee(0.0f);
} else {
hubParkingInfo.setTsaaFee(Math.round(hubParkingInfo.getTsaaFee() * 100.0f) / 100.0f);
}
if (hubParkingInfo.getTbaaFee() == null) {
hubParkingInfo.setTbaaFee(0.0f);
} else {
hubParkingInfo.setTbaaFee(Math.round(hubParkingInfo.getTbaaFee() * 100.0f) / 100.0f);
}
}
private void log(String msg){
XxlJobHelper.log(msg);
logger.info(msg);
}
}