SharedParkingJob.java
6.96 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
162
163
164
165
166
167
package com.zteits.park.job;
import org.apache.commons.lang3.StringUtils;
import com.clouds.common.cache.sys.SysCodeValueCacheUtil;
import com.clouds.common.constants.CodeValKindEnum;
import com.clouds.common.constants.CodeValueEnum;
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.clouds.api.apibase.constants.OrderStateEnum;
import com.zteits.clouds.api.apibase.constants.PsIsOccupyEnum;
import com.zteits.clouds.api.apibase.exception.AppException;
import com.zteits.park.dao.ParkingSharedDao;
import com.zteits.park.domain.TdPParkingShare;
import com.zteits.park.domain.TdPParkingShareExample;
import com.zteits.park.service.sharedparking.oper.SharedParkingJobOperService;
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.Date;
import java.util.List;
/**
* 共享车位预约,进场,出场相关定时
* .<br/>
*
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: SharedParkingJob
* @Description:
* @version: v1.0.0
* @author: zhaowg
* @date: 2018年4月17日 上午10:09:48
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2018年4月17日 zhaowg v1.0.0 创建
*/
@Component
public class SharedParkingJob{
private static final Logger logger = LoggerFactory.getLogger(SharedParkingJob.class);
@Autowired
private ParkingSharedDao parkingSharedDao;
@Autowired
private SharedParkingJobOperService sharedParkingJobOperService;
@XxlJob("sharedParkingJob")
public ReturnT<String> execute(String... params) throws Exception {
String param = XxlJobHelper.getJobParam();
if (StringUtils.isNotEmpty(param) && params == null) {
params = param.split(",");
}
log("预订-15分钟内未支付担保费,取消订单");
this.reservationOrderCancelJob();
log("进场-超过最迟入场时间未入场");
this.inParkingOverTimeJob();
log("出场-有出场费用且15分钟内没有支付的,则视为欠费");
this.outParkingNoPayedJob();
return ReturnT.SUCCESS;
}
/**
* 出场-待支付,且距离出场时间超过15分钟没有支付时,修改订单为欠费
*
* 2018年4月17日 zhaowg
*/
private void outParkingNoPayedJob() {
try{
sharedParkingJobOperService.outParkingNoPayedJob();
}catch (Exception e) {
if(e instanceof AppException){
AppException ex = (AppException)e;
log("修改出场未支付订单失败:"+ex.getErrMsg());
}else{
log("修改出场未支付订单失败:"+e.getMessage());
}
e.printStackTrace();
}
}
/**
* 超过最迟进场时间仍未进场的,修改订单为完成,有担保费的不退,没有担保费的,计费,修改订单为欠费
*
* 2018年4月17日 zhaowg
*/
private void inParkingOverTimeJob() {
log("查询超过最迟进场时间仍未进场的共享车位订单");
String allowLastestInParkDuration = SysCodeValueCacheUtil.queryCodeNameByCodeValue(CodeValKindEnum.SHARED_PARKING_COMMON_SET, CodeValueEnum.ALLOW_LASTEST_INPARK_DURATION,(30*60)+"");
Integer allowLastestInParkDurationInt = Integer.valueOf(allowLastestInParkDuration);
log("距离预约入场时间超过:"+allowLastestInParkDurationInt+"秒仍未入场的关闭订单");
//当前时间往前推指定的分钟
Date allowLastestInParkDate = new Date(new Date().getTime()-allowLastestInParkDurationInt*1000);
TdPParkingShareExample example = new TdPParkingShareExample();
example.createCriteria()
.andPsOrderStateEqualTo(OrderStateEnum.PAYED.value())//已经支付完担保费
.andPsPreInTimeLessThan(allowLastestInParkDate)//超过最迟入场时间
.andPsIsOccupyEqualTo(PsIsOccupyEnum.RENT_NO_CAR.getCode())//未进场
.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());//有效数据
List<TdPParkingShare> parkingShares = parkingSharedDao.selectByExample(example );
if(CollectionUtils.isEmpty(parkingShares)){
log("未查询到超过最迟入场时间的订单");
return;
}
log("一共查询到超过最迟入场时间订单条数:"+parkingShares.size());
for (TdPParkingShare tdPParkingShare : parkingShares) {
log("开始修改超过最迟入场时间的订单:"+tdPParkingShare.getPsOrderId());
try{
sharedParkingJobOperService.inParkingOverTimeJob(tdPParkingShare);
}catch (Exception e) {
if(e instanceof AppException){
AppException ex = (AppException)e;
log("修改超过最迟入场时间的订单:"+tdPParkingShare.getPsOrderId()+"失败:"+ex.getErrMsg());
}else{
log("修改超过最迟入场时间的订单:"+tdPParkingShare.getPsOrderId()+"失败:"+e.getMessage());
}
e.printStackTrace();
}
}
}
/**
* 取消预订订单,配合共享车位预订功能,当有担保费,且距离下单时间超过15分钟没有支付时,后台自动取消该订单
*
* 2018年4月17日 zhaowg
*/
private void reservationOrderCancelJob(){
log("查询允许取消的共享车位订单");
String allowCancelDuration = SysCodeValueCacheUtil.queryCodeNameByCodeValue(CodeValKindEnum.SHARED_PARKING_COMMON_SET, CodeValueEnum.ALLOW_CANCEL_DURATION,(30*60)+"");
Long allowCancelTimeInt = Long.valueOf(allowCancelDuration);
log("距离下单时间未超过:"+allowCancelTimeInt+"秒可以取消订单");
//当前时间往前推指定的分钟
Date allowCancelOrderDate = new Date(new Date().getTime()-allowCancelTimeInt*1000);
TdPParkingShareExample example = new TdPParkingShareExample();
example.createCriteria()
.andPsPreActFeeGreaterThan(0L)//担保费大于0
.andPsOrderStateEqualTo(OrderStateEnum.WAIT_PAY.value())//订单状态为待支付
.andPsPreCreateTimeLessThan(allowCancelOrderDate)//距离下单时间已经超过规定时间
.andPsIsOccupyEqualTo(PsIsOccupyEnum.RENT_NO_CAR.getCode())//预订-未进场
.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());//有效数据
List<TdPParkingShare> parkingShares = parkingSharedDao.selectByExample(example );
if(CollectionUtils.isEmpty(parkingShares)){
log("未查询到允许取消的订单");
return;
}
log("一共查询到允许取消订单条数:"+parkingShares.size());
for (TdPParkingShare tdPParkingShare : parkingShares) {
log("开始取消订单:"+tdPParkingShare.getPsOrderId());
try{
sharedParkingJobOperService.reservationOrderCancelJob(tdPParkingShare);
}catch (Exception e) {
if(e instanceof AppException){
AppException ex = (AppException)e;
log("取消订单:"+tdPParkingShare.getPsOrderId()+"失败:"+ex.getErrMsg());
}else{
log("取消订单:"+tdPParkingShare.getPsOrderId()+"失败:"+e.getMessage());
}
e.printStackTrace();
}
}
}
private void log(String msg){
XxlJobHelper.log(msg);
logger.info(msg);
}
}