|
|
|
@@ -0,0 +1,180 @@ |
|
|
|
package com.iformall.schedule; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.domain.po.WxMsgCallback; |
|
|
|
import com.iformall.domain.po.WxMsgConfig; |
|
|
|
import com.iformall.domain.po.WxMsgValidationcode; |
|
|
|
import com.iformall.domain.po.WxMsgValidationcodeModel; |
|
|
|
import com.iformall.enums.EnumMsgSendStatus; |
|
|
|
import com.iformall.enums.EnumVerifyCode; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.utils.WiwideUtil; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author gongbiao |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
public class BillNotificationSchedule { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMsgValidationcodeMapper wxMsgValidationcodeMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMsgConfigMapper wxMsgConfigMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMsgValidationcodeModelMapper wxMsgValidationcodelModelMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxBillAllMapper wxBillAllMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMsgCallbackMapper wxMsgCallbackMapper; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 每天9点执行 |
|
|
|
*/ |
|
|
|
@Scheduled(cron = "0 0 9 * * ?") |
|
|
|
public void sendMsgFromBill() { |
|
|
|
logger.info("账单通知任务启动"); |
|
|
|
sendWaitPayBill(); |
|
|
|
sendOweBill(); |
|
|
|
logger.info("账单通知任务结束"); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendOweBill() { |
|
|
|
logger.info("查询欠缴账单数据"); |
|
|
|
List<Map<String, Object>> oweBillList = wxBillAllMapper.getOWeBill(); |
|
|
|
for (Map<String, Object> bill : oweBillList) { |
|
|
|
logger.info("欠缴账单:" + JSONObject.toJSONString(bill)); |
|
|
|
String tenantId = bill.get("tenantId").toString(); |
|
|
|
BigDecimal owe = (BigDecimal) bill.get("owe"); |
|
|
|
BigDecimal price = owe.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); |
|
|
|
String phone = bill.get("linkPhone").toString(); |
|
|
|
String appname = bill.get("appname").toString(); |
|
|
|
logger.info("欠缴账单检验短信配置信息"); |
|
|
|
WxMsgConfig wxMsgConfig = checkMsgConfig(tenantId); |
|
|
|
if (wxMsgConfig != null) { |
|
|
|
logger.info("欠缴账单获取模板内容"); |
|
|
|
WxMsgValidationcodeModel wxMsgValidationcodeModel = getMsgModel(tenantId, 7); |
|
|
|
if (wxMsgValidationcodeModel != null) { |
|
|
|
String signature = wxMsgValidationcodeModel.getSignature(); |
|
|
|
String msg = wxMsgValidationcodeModel.getContent(). |
|
|
|
replace("{price}", String.valueOf(price.doubleValue())). |
|
|
|
replace("{app}", appname); |
|
|
|
String notifyUrl = wxMsgConfig.getNotifyurl(); |
|
|
|
String secret = wxMsgConfig.getSecret(); |
|
|
|
String bid = wxMsgConfig.getBid(); |
|
|
|
String publickey = wxMsgConfig.getPublickey(); |
|
|
|
sendWaitPayBillMsg(phone, signature, msg, notifyUrl, secret, bid, publickey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void sendWaitPayBill() { |
|
|
|
logger.info("查询待缴账单数据"); |
|
|
|
List<Map<String, Object>> waitBillList = wxBillAllMapper.getWaitPayBill(); |
|
|
|
for (Map<String, Object> bill : waitBillList) { |
|
|
|
logger.info("待缴账单账单:" + JSONObject.toJSONString(bill)); |
|
|
|
String tenantId = bill.get("tenantId").toString(); |
|
|
|
String receiveDate = bill.get("receiveDate").toString(); |
|
|
|
BigDecimal needPay = (BigDecimal) bill.get("needPay"); |
|
|
|
BigDecimal price = needPay.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); |
|
|
|
String phone = bill.get("linkPhone").toString(); |
|
|
|
String appname = bill.get("appname").toString(); |
|
|
|
logger.info("待缴账单检验短信配置信息"); |
|
|
|
WxMsgConfig wxMsgConfig = checkMsgConfig(tenantId); |
|
|
|
if (wxMsgConfig != null) { |
|
|
|
logger.info("待缴账单获取模板内容"); |
|
|
|
WxMsgValidationcodeModel wxMsgValidationcodeModel = getMsgModel(tenantId, 7); |
|
|
|
if (wxMsgValidationcodeModel != null) { |
|
|
|
String signature = wxMsgValidationcodeModel.getSignature(); |
|
|
|
String msg = wxMsgValidationcodeModel.getContent(). |
|
|
|
replace("{price}", String.valueOf(price.doubleValue())). |
|
|
|
replace("{date}", receiveDate). |
|
|
|
replace("{app}", appname); |
|
|
|
String notifyUrl = wxMsgConfig.getNotifyurl(); |
|
|
|
String secret = wxMsgConfig.getSecret(); |
|
|
|
String bid = wxMsgConfig.getBid(); |
|
|
|
String publickey = wxMsgConfig.getPublickey(); |
|
|
|
sendWaitPayBillMsg(phone, signature, msg, notifyUrl, secret, bid, publickey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private WxMsgConfig checkMsgConfig(String tenantId) { |
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
wxMsgConfig.setTenantId(tenantId); |
|
|
|
List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
if (wxMsgConfigs.size() == 0) { |
|
|
|
logger.info("缺少系统短信配置"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
wxMsgConfig = wxMsgConfigs.get(0); |
|
|
|
if (wxMsgConfig.getRemains() == 0) { |
|
|
|
logger.info("短信数量为0"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return wxMsgConfigs.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
private WxMsgValidationcodeModel getMsgModel(String tenantId, Integer type) { |
|
|
|
WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); |
|
|
|
wxMsgValidationcodeModel.setTenantId(tenantId); |
|
|
|
wxMsgValidationcodeModel.setType(type); |
|
|
|
return wxMsgValidationcodelModelMapper.findList(wxMsgValidationcodeModel).get(0); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendWaitPayBillMsg(String phone, String signature, String msg, String notifyUrl, String secret, String bid, String publickey) { |
|
|
|
logger.info("开始调用迈外迪短信接口"); |
|
|
|
String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.YES.getCode().toString(), null); |
|
|
|
logger.info("迈外迪短信接口返回值:" + result); |
|
|
|
JSONObject jsonObjectResult = JSONObject.parseObject(result); |
|
|
|
String ret = jsonObjectResult.get("ret").toString(); |
|
|
|
String batchNo = jsonObjectResult.get("data").toString(); |
|
|
|
if (ret.equals(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode())) { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); |
|
|
|
wxMsgValidationcode.setId(idWorker.nextId()); |
|
|
|
wxMsgValidationcode.setCreatetime(new Date()); |
|
|
|
wxMsgValidationcodeMapper.insertSelective(wxMsgValidationcode); |
|
|
|
addMsgCallback(wxMsgValidationcode, batchNo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo) { |
|
|
|
logger.info("验证码发送时主动添加回调记录开始..."); |
|
|
|
String phone = wxmsg.getPhone(); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
WxMsgCallback wxMsgCallback = new WxMsgCallback(); |
|
|
|
wxMsgCallback.setId(idWorker.nextId()); |
|
|
|
wxMsgCallback.setPhone(phone); |
|
|
|
wxMsgCallback.setTenantId(wxmsg.getTenantId()); |
|
|
|
wxMsgCallback.setBatchNo(batchNo); |
|
|
|
wxMsgCallback.setMsgId(wxmsg.getId()); |
|
|
|
wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SENDING.getCode()); |
|
|
|
wxMsgCallback.setCreatetime(new Date()); |
|
|
|
wxMsgCallbackMapper.insertSelective(wxMsgCallback); |
|
|
|
logger.info("验证码发送时主动添加回调记录结束..."); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |