VipCardExpireWarnPushJob.java
15.7 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package com.zteits.pay.job.vipcardpush;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.clouds.common.cache.sys.SysCodeValueCacheUtil;
import com.clouds.common.constants.CodeValKindEnum;
import com.clouds.common.constants.CodeValueEnum;
import com.clouds.common.oss.ali.AliMessageClientUtil;
import com.clouds.common.utils.MsgTemplateUtil;
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.bean.BizResult;
import com.zteits.clouds.api.apibase.constants.MSGTempleteEnum;
import com.zteits.clouds.api.apibase.constants.MSGTypeEnum;
import com.zteits.clouds.api.dto.bill.vipcard.VipCardExpireWarnPushDTO;
import com.zteits.clouds.api.dto.bill.vipcard.param.VipCardExpireWarnPushRequest;
import com.zteits.clouds.api.dto.messgesend.ChinameTelecomDTO;
import com.zteits.clouds.api.dto.messgesend.param.ChinameTelecomSmsReq;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.dto.park.param.QueryParkLotInfoByPkNoRequest;
import com.zteits.clouds.api.dto.pay.TdBWxConfigDTO;
import com.zteits.clouds.api.dto.pay.param.VipCardExpireWarnRequest;
import com.zteits.clouds.api.dto.pay.param.WxConfigQueryByAppIdRequest;
import com.zteits.clouds.api.dto.sys.SysOrgAppIdDTO;
import com.zteits.clouds.api.dto.sys.param.SysOrgAppIdQueryRequest;
import com.zteits.clouds.api.service.bill.vipcard.VipCardCustInfoService;
import com.zteits.clouds.api.service.messgesend.ShortMessageSendService;
import com.zteits.clouds.api.service.order.aliwxconfig.WXOrderConfigService;
import com.zteits.clouds.api.service.park.ParkingLotQueryService;
import com.zteits.clouds.api.service.pay.JPushService;
import com.zteits.clouds.api.service.sys.SysOrgAppIdService;
import com.zteits.pay.dao.TdCCustPersonDao;
import com.zteits.pay.dao.TdCMsgTemplateDao;
import com.zteits.pay.dao.TdCPushMsgDao;
import com.zteits.pay.dao.WXCustBindingDao;
import com.zteits.pay.domain.TdBCustBinding;
import com.zteits.pay.domain.TdCCustPerson;
import com.zteits.pay.domain.TdCMsgTemplate;
import com.zteits.pay.domain.TdCPushMsg;
import com.zteits.pay.util.JPustUtil;
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 org.springframework.util.StringUtils;
import java.util.*;
/**
* 会员卡到期提醒(公众号推送、极光推送)
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: VipCardExpireWarnPushJob.java
* @Description:
* @version: v1.0.0
* @author: wangfs
* @date: 2019-10-10 09:20
* Modification History:
* Date Author Version Description
* ---------------------------------------------------------*
* 2019-10-10 wangfs v1.0.0 创建
*/
@Component
public class VipCardExpireWarnPushJob {
private static final Logger logger = LoggerFactory.getLogger(VipCardExpireWarnPushJob.class);
@Autowired
private JPushService jPushService;
@Autowired
private VipCardCustInfoService vipCardCustInfoService;
@Autowired
private ParkingLotQueryService parkingLotQueryService;
@Autowired
private WXCustBindingDao wXCustBindingDao;
@Autowired
private TdCCustPersonDao tdCCustPersonDao;
@Autowired
private TdCMsgTemplateDao tdCMsgTemplateDao;
@Autowired
private SysOrgAppIdService sysOrgAppIdService;
@Autowired
private WXOrderConfigService wXConfigService;
@Autowired
private TdCPushMsgDao tdCPushMsgDao;
@Autowired
private ShortMessageSendService shortMessageSendService;
/**
* 会员卡到期提醒(公众号推送、极光推送)
* 步骤:
* 1.查询三天后即将到期的所有会员卡信息
* @Auther: wangfs
* @param
* @return
*/
@XxlJob(value = "VipCardExpireWarnPushJob")
public ReturnT<String> execute(String... params) throws Exception {
String param = XxlJobHelper.getJobParam();
if (!StringUtils.isEmpty(param) && params == null) {
params = param.split(",");
}
this.logger("begin会员卡到期提醒(公众号推送、极光推送),入参="+ JSONObject.toJSONString(params));
if (null == params || params.length == 0) {
this.logger("入参不能为空,天数,多个用'逗号'分割");
return new ReturnT<>(ReturnT.FAIL_CODE, "入参不能为空,请传入对应的组织ID,多个用'逗号'分割");
}
//获取组织
List<String> stringList = Arrays.asList(params);
String s = stringList.get(0);
int anInt = Integer.parseInt(s);
int day = 3;
if (anInt > 0) {
day = anInt;
}
//取当前天+2天
Date newDate = DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, day);
String times = DateUtil.format(newDate,"yyyy-MM-dd");
String beginTime = DateUtil.format(new Date(),"yyyy-MM-dd")+" 00:00:00";
String endTime = times+" 23:59:59";
VipCardExpireWarnPushRequest request = new VipCardExpireWarnPushRequest();
request.setSysCode("1001");
request.setBeginTime(beginTime);
request.setEndTime(endTime);
this.logger("本次需要推送,开始时间="+beginTime+"结束时间="+endTime);
BizResult<List<VipCardExpireWarnPushDTO>> listBizResult = vipCardCustInfoService.queryVipCardByExpireDate(request);
this.logger("查询到3天后将要过期的会员卡信息为="+JSONObject.toJSON(listBizResult));
if(listBizResult != null && !CollectionUtils.isEmpty(listBizResult.getData())){
List<VipCardExpireWarnPushDTO> list = listBizResult.getData();
for(VipCardExpireWarnPushDTO vipCardInfo:list){
if(vipCardInfo == null ){
continue;
}
// QueryParkLotInfoByPkNoRequest queryParklot = new QueryParkLotInfoByPkNoRequest();
// queryParklot.setPklNo(vipCardInfo.getPlNo());
// queryParklot.setSysCode("1001");
// BizResult<ParkingLotDTO> parkingLotDTOBizResult = parkingLotQueryService.QueryParkingLotByPkNo(queryParklot);
// this.logger("查询到停车场信息为="+JSONObject.toJSON(parkingLotDTOBizResult));
// if(parkingLotDTOBizResult != null && parkingLotDTOBizResult.getData() != null){
// vipCardInfo.setPlName(parkingLotDTOBizResult.getData().getPlName());
// vipCardInfo.setOrgId(parkingLotDTOBizResult.getData().getOrgId());
// }
/**1.调用公众号推送*/
// this.sendVipCardExpireWarn(vipCardInfo);
/**2.极光推送*/
// this.sendVipCardExpireWarnForJG((vipCardInfo));
/**3.短信提醒-阿里云*/
this.aliyunsendSms(vipCardInfo);
/**4.电信模板短信推送
this.dianxinSendMessage(vipCardInfo);*/
}
}
this.logger("end会员卡到期提醒(公众号推送、极光推送)...");
return ReturnT.SUCCESS ;
}
/**
* 微信公众号推送
* @param vipCardInfo
*/
public void sendVipCardExpireWarn(VipCardExpireWarnPushDTO vipCardInfo) {
logger("begin微信公众号推送,入参="+JSONObject.toJSON(vipCardInfo));
/**1.查询微信公众号绑定信息*/
TdBCustBinding tdBCustBinding =wXCustBindingDao.queryCustBindingByCustId(vipCardInfo.getCustId());
if(tdBCustBinding != null && !StringUtils.isEmpty(tdBCustBinding.getBindingId())) {
VipCardExpireWarnRequest request = new VipCardExpireWarnRequest();
TdBWxConfigDTO tdBWxConfigDTO = new TdBWxConfigDTO();
//无锡微纳园
// if ("10005".equals(vipCardInfo.getOrgId() + "")) {
// tdBWxConfigDTO.setAppid("wx1e9001e5940605b1");
// tdBWxConfigDTO.setAppSecret("TixijEti1k7ZCArXAbl4a9aeRAsHzTLjD8kqwuHlZlQy3Ma1cue7CFbko7yTJb/e");
// }
/**获取微信公众号配置信息.*/
this.queryWxConfigInfo(vipCardInfo.getOrgId(),tdBWxConfigDTO);
request.setTdBWxConfigDTO(tdBWxConfigDTO);
request.setToUserOpenId(tdBCustBinding.getBindingId());
request.setCardNo(vipCardInfo.getCustCardNo());
request.setCarNumber(vipCardInfo.getCarNumber());
request.setPlName(StringUtils.isEmpty(vipCardInfo.getPlName()) ? vipCardInfo.getPlNo():vipCardInfo.getPlName() );
request.setExpDate(vipCardInfo.getExpDate());
request.setColor("#f3173b");
this.logger("发起公众号推送信息为="+JSONObject.toJSON(request));
jPushService.sendVipCardExpireWarn(request);
}else{
this.logger("客户id=【"+vipCardInfo.getCustId()+"】用户未绑定公众号");
}
logger("end微信公众号推送。。。");
}
/**
* 极光推送
* @param vipCardInfo
*/
public void sendVipCardExpireWarnForJG(VipCardExpireWarnPushDTO vipCardInfo) {
logger("begin会员卡到期提醒-激光推送开始");
TdCCustPerson tdCCustPerson =tdCCustPersonDao.queryPersonByCustId(vipCardInfo.getCustId());
//消息模板
String templeteId = MSGTempleteEnum.APP_VIP_EXPDATE_PUSH.value();;
TdCMsgTemplate tdCMsgTemplate = tdCMsgTemplateDao.queryMsgTempleteByTempleteId(templeteId);
if(tdCMsgTemplate==null){
logger.error("消息模板:"+templeteId+",不存在,不发送激光消息");
return;
}
Map<String, String> datas = new HashMap<String, String>();
/** 消息推送模板 */
datas.put("carNumber", vipCardInfo.getCarNumber());
datas.put("plName", StringUtils.isEmpty(vipCardInfo.getPlName()) ? vipCardInfo.getPlNo():vipCardInfo.getPlName());
datas.put("expsrt", vipCardInfo.getExpDate());
String content = MsgTemplateUtil.render(tdCMsgTemplate.getTemplateContent(), datas);
String title = tdCMsgTemplate.getTemplateTitle();
TdCPushMsg record = new TdCPushMsg();
record.setMsgContent(content.toString());
record.setMsgTitle(title);
record.setMsgType(MSGTypeEnum.MSG_TYPE_PRESENT.value());
record.setTempleteId(templeteId);
record.setPushType(MSGTypeEnum.MSG_PUSH_TYPE_ONLY.value());
record.setReturnType(MSGTypeEnum.MSG_RETURN_YES.value());
record.setReadType(MSGTypeEnum.MSG_READ_NO.value());
record.setCustId(vipCardInfo.getCustId());
record.setDataState(1);
record.setCreateDate(new Date());
record.setModfiyDate(new Date());
record.setOutMsgNo(vipCardInfo.getCustCardNo());
tdCPushMsgDao.insertSelective(record);
//激光推送
JPustUtil.sendPush(content, tdCCustPerson.getAlias(), MSGTypeEnum.MSG_TYPE_SYS.value() + "",
tdCCustPerson.getDeivceType());
logger("end支付激光推送结束...");
}
/**
* 阿里云短信提醒
* @param vipCardInfo
*/
private void aliyunsendSms(VipCardExpireWarnPushDTO vipCardInfo){
final String templateCode = SysCodeValueCacheUtil.queryCodeNameByCodeValue(CodeValKindEnum.APP_SMS, CodeValueEnum.SMS_MSG_CODE_VIP_MORE_TIME);
logger("begin会员卡到期提醒-阿里云短信提醒");
TdCCustPerson tdCCustPerson =tdCCustPersonDao.queryPersonByCustId(vipCardInfo.getCustId());
this.logger("阿里云短信提醒,获取到的客户信息="+JSONObject.toJSON(tdCCustPerson));
if(null != tdCCustPerson && !StringUtils.isEmpty(tdCCustPerson.getUserPhone())){
this.logger("begin【短信推送】,会员卡信息="+JSONObject.toJSON(vipCardInfo));
Map<String,String> param = new HashMap<>();
param.put("userName",vipCardInfo.getCarNumber());
param.put("endTime",vipCardInfo.getExpDate());
param.put("dataTime",vipCardInfo.getExpDate());
String content = JSONObject.toJSONString(param);
AliMessageClientUtil.aliyunSendSms(tdCCustPerson.getUserPhone(),templateCode, content);
}else{
this.logger("阿里云短信提醒,没有获取到用户手机号...无法推送");
}
this.logger("end会员卡到期提醒-阿里云短信提醒");
}
/**
* 通过组织 id 获取公众号配置信息 MessageUtil
* @param orgId
* @param tdBWxConfigDTO
*/
private void queryWxConfigInfo(Long orgId,TdBWxConfigDTO tdBWxConfigDTO){
this.logger("begin通过组织 ID"+orgId+"查询微信公众号配置信息...");
SysOrgAppIdQueryRequest request = new SysOrgAppIdQueryRequest();
request.setOrgId(orgId);
request.setPayType(4);
request.setSysCode("1001");
BizResult<SysOrgAppIdDTO> sysOrgAppIdDTOBizResult = sysOrgAppIdService.querySysOrgAppIdByOrgIdAndPayType(request);
if(null != sysOrgAppIdDTOBizResult && sysOrgAppIdDTOBizResult.getData() != null){
SysOrgAppIdDTO sysOrgAppIdDTO = sysOrgAppIdDTOBizResult.getData();
this.logger("通过组织 ID 获取到的信息为="+JSONObject.toJSON(sysOrgAppIdDTO));
if(!StringUtils.isEmpty(sysOrgAppIdDTO.getPayAppId())){
WxConfigQueryByAppIdRequest req = new WxConfigQueryByAppIdRequest();
req.setAppId(sysOrgAppIdDTO.getPayAppId());
req.setSysCode("1001");
BizResult<TdBWxConfigDTO> tdBWxConfigDTOBizResult = wXConfigService.queryWxConfigByAppId(req);
if(null != tdBWxConfigDTOBizResult && tdBWxConfigDTOBizResult.getData() != null){
TdBWxConfigDTO tdBWxConfig = tdBWxConfigDTOBizResult.getData();
this.logger("通过APPID 获取到的微信公众号信息为="+JSONObject.toJSON(tdBWxConfig));
if(null != tdBWxConfig){
tdBWxConfigDTO.setAppSecret(tdBWxConfig.getAppSecret());
tdBWxConfigDTO.setAppid(tdBWxConfig.getAppid());
}
}
}
}
this.logger("end通过组织 ID"+orgId+"查询微信公众号配置信息...");
}
/**
* 电信短信推送-赤峰
*/
private void dianxinSendMessage(VipCardExpireWarnPushDTO vipCardInfo){
TdCCustPerson tdCCustPerson =tdCCustPersonDao.queryPersonByCustId(vipCardInfo.getCustId());
this.logger("阿里云短信提醒,获取到的客户信息="+JSONObject.toJSON(tdCCustPerson));
if(null != tdCCustPerson && !StringUtils.isEmpty(tdCCustPerson.getUserPhone())) {
/**
* 发送短信
*/
String appId = "714457510000265575";
String secret = "258f0b6283f298b133a71a9ab7f156a4";
String sendUrl = "http://api.189.cn/v2/emp/templateSms/sendSms";
Map<String, String> map = new HashMap<>();
map.put("dateTime", vipCardInfo.getExpDate());
map.put("parkName", vipCardInfo.getPlName());
ChinameTelecomSmsReq req = new ChinameTelecomSmsReq();
req.setAppId(appId);
req.setSendUrl(sendUrl);
req.setStecret(secret);
req.setTemplateId("91555857");
req.setUserPhone(tdCCustPerson.getUserPhone());
req.setSysCode("10001");
req.setTemplateParam(map);
BizResult<ChinameTelecomDTO> result1 = shortMessageSendService.sendTemplateSms(req);
}
}
public static void main(String[] args) {
}
private void logger(String msg) {
XxlJobHelper.log(msg);
logger.info(msg);
}
}