|
|
@@ -1,18 +1,28 @@ |
|
|
|
package com.qtzl.alterSales.manager.service; |
|
|
|
|
|
|
|
import cn.com.taiji.common.manager.net.http.ServiceHandleException; |
|
|
|
import cn.com.taiji.common.pub.json.JsonTools; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import com.qtzl.alterSales.dao.entity.primary.AflApPayOrder; |
|
|
|
import com.qtzl.alterSales.dao.entity.primary.AflApPayOrderRel; |
|
|
|
import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay; |
|
|
|
import com.qtzl.alterSales.dao.entity.primary.WechatBillPayApply; |
|
|
|
import com.qtzl.alterSales.dao.entity.second.AflOrderInfo; |
|
|
|
import com.qtzl.alterSales.dao.entity.second.AflSmsConfig; |
|
|
|
import com.qtzl.alterSales.dao.entity.second.AflSmsRecord; |
|
|
|
import com.qtzl.alterSales.dao.entity.second.AflWechatSign; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.primary.AflApPayOrderRelRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.primary.AflApPayOrderRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.primary.WechatBillPayApplyRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.second.AflOrderInfoRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.second.AflSmsConfigRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.second.AflSmsRecordRepo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.second.AflWechatSignRepo; |
|
|
|
import com.qtzl.alterSales.manager.enums.AflApPayOrderStatus; |
|
|
|
import com.qtzl.alterSales.manager.enums.BlacklistOpType; |
|
|
@@ -22,6 +32,7 @@ import com.qtzl.alterSales.manager.model.protocol.UcServiceError; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.ChoiceBillsPayRequest; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.wechat.partnerpayments.JsapiV3Manager; |
|
|
|
import com.qtzl.alterSales.manager.rabbit.RabbitUnifiedProduction; |
|
|
|
import com.qtzl.alterSales.manager.sms.*; |
|
|
|
import com.qtzl.alterSales.manager.tools.RedisUtils; |
|
|
|
import com.qtzl.alterSales.manager.vo.AflMchConfigVo; |
|
|
|
import com.qtzl.alterSales.manager.vo.AflPaccountPushConfigVo; |
|
|
@@ -31,13 +42,18 @@ import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.scheduling.annotation.EnableAsync; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@@ -50,6 +66,7 @@ import java.util.stream.Collectors; |
|
|
|
* {@code @date} 2023/10/16 11:08 |
|
|
|
**/ |
|
|
|
@Service |
|
|
|
@EnableAsync |
|
|
|
public class ChoiceBillsOperationServiceImpl implements ChoiceBillsOperationService { |
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ChoiceBillsOperationServiceImpl.class); |
|
|
@@ -86,6 +103,15 @@ public class ChoiceBillsOperationServiceImpl implements ChoiceBillsOperationServ |
|
|
|
@Resource |
|
|
|
private AflPaccountPushConfigManager paccountPushConfigManager; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AflSmsRecordRepo aflSmsRecordRepo; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AflSmsConfigRepo aflSmsConfigRepo; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AflOrderInfoRepo aflOrderInfoRepo; |
|
|
|
|
|
|
|
@Override |
|
|
|
public ChoiceBillsPayVo choiceBillsPay(ChoiceBillsPayRequest request) throws ServiceHandleException { |
|
|
|
if (StringUtils.isEmpty(request.getOpenId())) { |
|
|
@@ -258,11 +284,163 @@ public class ChoiceBillsOperationServiceImpl implements ChoiceBillsOperationServ |
|
|
|
|
|
|
|
final List<String> orderList = accountPayList.stream().map(FssPaccountPay::getOrderId).toList(); |
|
|
|
final List<String> payIdList = accountPayList.stream().map(FssPaccountPay::getcPayId).toList(); |
|
|
|
blackInfoManager.execute(agreementNum, BlacklistOpType.OUT, "所有流水补扣成功,对该协议返白", String.join("、", |
|
|
|
orderList), String.join("、", payIdList), |
|
|
|
boolean execute = blackInfoManager.execute(agreementNum, BlacklistOpType.OUT, "所有流水补扣成功,对该协议返白", String.join("、", |
|
|
|
orderList), String.join("、", payIdList), |
|
|
|
null, null, null); |
|
|
|
if(execute){ |
|
|
|
sendSmsOut(accountPayList.get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 反白发送短信 |
|
|
|
* @param paccountPay |
|
|
|
*/ |
|
|
|
@Async |
|
|
|
public void sendSmsOut(FssPaccountPay paccountPay) { |
|
|
|
try { |
|
|
|
log.info("反白,发送短信...请求参数:{}", paccountPay); |
|
|
|
AflSmsConfig byAgentId = aflSmsConfigRepo.findByAgentId(paccountPay.getAgentId()); |
|
|
|
//判断是否是比亚迪车辆 才发短信 |
|
|
|
if(canSendSms(paccountPay, byAgentId)){ |
|
|
|
String smsTemplate ="尊敬的ETC客户:您好!您的车辆(****%s)ETC账户状态正常且无欠费记录"; |
|
|
|
String carPlate = paccountPay.getVehicleId().split("_")[0].toString(); |
|
|
|
// 修改部分:将脱敏部分放在前面,保留后三位 |
|
|
|
String smsContent = String.format(smsTemplate, |
|
|
|
carPlate.substring(carPlate.length() - 3)); |
|
|
|
SendSmsReq sendSmsReq= new SendSmsReq(); |
|
|
|
sendSmsReq.setSmsContent(smsContent); |
|
|
|
//查询 车牌 最新手机号 |
|
|
|
List<AflOrderInfo> byVehicleId = aflOrderInfoRepo.findByVehicleId(paccountPay.getVehicleId().split("_")[0],Integer.parseInt(paccountPay.getVehicleId().split("_")[1])); |
|
|
|
if(!byVehicleId.isEmpty()&&byVehicleId.get(0).getMobile()!=null) { |
|
|
|
sendSmsReq.setMobile(byVehicleId.get(0).getMobile()); |
|
|
|
} |
|
|
|
QtztJsonRequest qtztJsonRequest = new QtztJsonRequest(); |
|
|
|
qtztJsonRequest.setData(sendSmsReq); |
|
|
|
qtztJsonRequest.setStaffId("hcETCqz001"); |
|
|
|
qtztJsonRequest.setAgentId("52010106004"); |
|
|
|
qtztJsonRequest.setChannelId("5201010600401140115"); |
|
|
|
qtztJsonRequest.setSign("123213"); |
|
|
|
qtztJsonRequest.setStamp("1563271471061"); |
|
|
|
qtztJsonRequest.setChannelType(2); |
|
|
|
qtztJsonRequest.setTerminalId("999999999999"); |
|
|
|
qtztJsonRequest.setToken("123"); |
|
|
|
qtztJsonRequest.setOrgCode("52010106004"); |
|
|
|
if(!byVehicleId.isEmpty()) { |
|
|
|
//查询mobile payId是否已经发送 防止 短信轰炸 |
|
|
|
List<AflSmsRecord> byMobileandBusinessId = aflSmsRecordRepo.findByMobileandBusinessIdThree(sendSmsReq.getMobile(), paccountPay.getPayId()); |
|
|
|
if(byMobileandBusinessId.isEmpty()&&StringUtils.isNotEmpty(smsTemplate)) { |
|
|
|
QtztJsonResponse qtztJsonResponse = sendQtzt(qtztJsonRequest, SendSmsResponseData.class,paccountPay,sendSmsReq,"3"); |
|
|
|
//存储短信发送记录 |
|
|
|
AflSmsRecord aflSmsRecord = new AflSmsRecord(); |
|
|
|
aflSmsRecord.setBusinessId(paccountPay.getPayId()); |
|
|
|
aflSmsRecord.setSendTime(LocalDateTime.now()); |
|
|
|
aflSmsRecord.setMobile(sendSmsReq.getMobile()); |
|
|
|
aflSmsRecord.setContent(sendSmsReq.getSmsContent()); |
|
|
|
aflSmsRecord.setAgentId(paccountPay.getAgentId()); |
|
|
|
aflSmsRecord.setBusinessType("3"); |
|
|
|
if(null!=qtztJsonResponse&&qtztJsonResponse.getRcode()==0) { |
|
|
|
aflSmsRecord.setStatus("0"); |
|
|
|
}else { |
|
|
|
aflSmsRecord.setStatus("1"); |
|
|
|
aflSmsRecord.setErrorMsg(qtztJsonResponse.getRmsg()); |
|
|
|
} |
|
|
|
aflSmsRecord.setVehicleId(paccountPay.getVehicleId()); |
|
|
|
aflSmsRecordRepo.save(aflSmsRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.info("反白发短信异常"+e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
public boolean canSendSms(FssPaccountPay paccountPay, AflSmsConfig byAgentId) { |
|
|
|
// 判断代理商、短信开关、发送时间等条件 |
|
|
|
if(null==byAgentId){ |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(null!=byAgentId.getVehicleJson()){ |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
try { |
|
|
|
List<String> vehicleIds = objectMapper.readValue(byAgentId.getVehicleJson(), List.class); |
|
|
|
if(vehicleIds.contains(paccountPay.getVehicleId())){ |
|
|
|
return false; |
|
|
|
} |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (byAgentId.getIsEnabled() == 1&&isWithinTimeRange(byAgentId.getSendTimeStart(), byAgentId.getSendTimeEnd())) { |
|
|
|
if (byAgentId.getType() == 1) { |
|
|
|
List<AflSmsRecord> byCountDay = aflSmsRecordRepo.findByCountDay(paccountPay.getVehicleId()); |
|
|
|
if (byCountDay.size() >= byAgentId.getMaxCountPerDay()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (byAgentId.getType() == 2) { |
|
|
|
List<AflSmsRecord> byCountMonth = aflSmsRecordRepo.findByCountMonth(paccountPay.getVehicleId()); |
|
|
|
if (byCountMonth.size() >= byAgentId.getMaxCountPerMonth()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isWithinTimeRange(String startTime, String endTime) { |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); // 调整格式以匹配你的时间字符串 |
|
|
|
|
|
|
|
try { |
|
|
|
LocalTime start = LocalTime.parse(startTime, formatter); |
|
|
|
LocalTime end = LocalTime.parse(endTime, formatter); |
|
|
|
LocalTime now = LocalTime.now(); |
|
|
|
|
|
|
|
return !now.isBefore(start) && now.isBefore(end); |
|
|
|
} catch (Exception e) { |
|
|
|
// 处理异常,例如抛出自定义异常或返回错误标志 |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public QtztJsonResponse sendQtzt(QtztJsonRequest req, Class<? extends QtztJsonResponse> typeClass, FssPaccountPay paccountPay, SendSmsReq sendSmsReq , String businessType ) |
|
|
|
{ |
|
|
|
QtztJsonRequestData reqData = req.getData(); |
|
|
|
req.setCode(reqData.getQtztTransType().getCode()); |
|
|
|
QtztTransType t = reqData.getQtztTransType(); |
|
|
|
String str = req.toJsonWithData(); |
|
|
|
Map<QtztTransType, Class<? extends QtztJsonResponse>> map = Maps.newHashMap(); |
|
|
|
map.put(reqData.getQtztTransType(), typeClass); |
|
|
|
QtztJsonResponse res = null; |
|
|
|
String qtztUrl = "http://192.168.100.148:20801"; |
|
|
|
try { |
|
|
|
|
|
|
|
log.info("请求地址:" + qtztUrl + t.getUrl()); |
|
|
|
String strs = QtztHttpHelper.jsonPost(qtztUrl + t.getUrl(), str, "utf-8").replaceAll("\\\\", "").replaceAll("\"]", "").replace("[\"", ""); |
|
|
|
log.info("响应内容:" + strs + "_" + map.get(t)); |
|
|
|
res = JsonTools.json2Object(strs, map.get(t)); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.info("短信发送请求异常:" + e.getMessage()); |
|
|
|
|
|
|
|
//存储短信发送记录 |
|
|
|
AflSmsRecord aflSmsRecord = new AflSmsRecord(); |
|
|
|
aflSmsRecord.setBusinessId(paccountPay.getPayId()); |
|
|
|
aflSmsRecord.setSendTime(LocalDateTime.now()); |
|
|
|
aflSmsRecord.setMobile(sendSmsReq.getMobile()); |
|
|
|
aflSmsRecord.setContent(sendSmsReq.getSmsContent()); |
|
|
|
aflSmsRecord.setAgentId(paccountPay.getAgentId()); |
|
|
|
aflSmsRecord.setBusinessType(businessType); |
|
|
|
aflSmsRecord.setStatus("1"); |
|
|
|
aflSmsRecord.setErrorMsg("网络连接异常"); |
|
|
|
aflSmsRecord.setVehicleId(paccountPay.getVehicleId()); |
|
|
|
aflSmsRecordRepo.save(aflSmsRecord); |
|
|
|
} |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AflMchConfigVo getMchInfoEnum(String vehicleId) throws ServiceHandleException { |
|
|
|
// |