Просмотр исходного кода

[账单通知][添加][定时任务]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
dfc897c213
3 измененных файлов: 195 добавлений и 7 удалений
  1. +180
    -0
      mallinkSchedule/src/main/java/com/iformall/schedule/BillNotificationSchedule.java
  2. +4
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java
  3. +11
    -7
      mallinkService/src/main/resources/mapper/WxBillAllMapper.xml

+ 180
- 0
mallinkSchedule/src/main/java/com/iformall/schedule/BillNotificationSchedule.java Просмотреть файл

@@ -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("验证码发送时主动添加回调记录结束...");
}


}

+ 4
- 0
mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java Просмотреть файл

@@ -21,4 +21,8 @@ public interface WxBillAllMapper extends CommonMapper<MallPermission, Long> {

List<Map<String,Object>> listData(WxBillAll wxBillAll);

List<Map<String, Object>> getWaitPayBill();

List<Map<String, Object>> getOWeBill();

}

+ 11
- 7
mallinkService/src/main/resources/mapper/WxBillAllMapper.xml Просмотреть файл

@@ -214,8 +214,9 @@
<select id="getWaitPayBill" resultType="hashmap">
select bill.merchant_id merchantId,bill.receive_date,bill.need_pay needPay,m.link_phone linkPhone from (
select bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
select bill.tenant_id tenantId,bill.merchant_id merchantId,bill.receive_date receiveDate,
bill.need_pay needPay,m.link_phone linkPhone,app.appname from (
select bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
endtime,rent_shop_type from wx_bill_rent
@@ -245,15 +246,16 @@ select bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from
from wx_bill_other
) bill
where DATEDIFF(bill.receive_date,now())=3 and bill.status!=3
group by bill.merchant_id,bill.receive_date) bill
group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
left join wx_merchant m on bill.merchant_id=m.id
left join (select tenant_id,`name` appname from wx_appinfo app where type=2) app on bill.tenant_id=app.tenant_id

</select>
<select id="getOweBill" resultType="hashmap">
select bill.merchant_id merchantId,bill.owe,m.link_phone linkPhone from (
select bill.merchant_id,sum(owe) owe from (
select bill.tenant_id tenantId,bill.merchant_id merchantId,bill.owe,m.link_phone linkPhone,app.appname from (
select bill.tenant_id,bill.merchant_id,sum(owe) owe from (
select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
endtime,rent_shop_type from wx_bill_rent
@@ -283,8 +285,10 @@ select bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from
from wx_bill_other
) bill
where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status!=3
group by bill.merchant_id) bill
group by bill.tenant_id,bill.merchant_id) bill
left join wx_merchant m on bill.merchant_id=m.id
left join (select tenant_id,`name` appname from wx_appinfo app where type=2) app on bill.tenant_id=app.tenant_id

</select>

</mapper>

Загрузка…
Отмена
Сохранить