| @@ -0,0 +1,91 @@ | |||
| package com.iformall.schedule; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.domain.po.WxActivity; | |||
| import com.iformall.domain.po.WxActivityJoin; | |||
| import com.iformall.domain.po.WxCampaign; | |||
| import com.iformall.domain.po.WxCarPayOrder; | |||
| import com.iformall.domain.po.WxMall; | |||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxActivityJoinMapper; | |||
| import com.iformall.mapper.WxActivityMapper; | |||
| import com.iformall.mapper.WxCampaignMapper; | |||
| import com.iformall.mapper.WxCarPayOrderMapper; | |||
| import com.iformall.mapper.WxMallMapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.park.ParkFactory; | |||
| import com.iformall.service.park.entity.ParkNotifyPaid; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.apache.commons.collections.map.HashedMap; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| @Component | |||
| public class CarPaidNotifySchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCarPayOrderMapper wxCarPayOrderMapper; | |||
| @Autowired | |||
| private WxMallMapper wxMallMapper; | |||
| @Autowired | |||
| ParkFactory parkFactory; | |||
| private List<WxMall> getMalls() { | |||
| WxMall wxMall = new WxMall(); | |||
| return wxMallMapper.findList(wxMall); | |||
| } | |||
| /** | |||
| * 5分钟执行一次 | |||
| */ | |||
| @Async | |||
| @Scheduled(cron = "0 */5 * * * ?") | |||
| public void sendMsg() { | |||
| List<WxMall> malls = getMalls(); | |||
| for (WxMall mall : malls) { | |||
| WxCarPayOrder payOrder = new WxCarPayOrder(); | |||
| payOrder.updateTenantInfo(mall); | |||
| payOrder.setNotifyCountLimit(10); | |||
| payOrder.setParkNotify(EnumYesOrNo.NO.getCode()); | |||
| List<WxCarPayOrder> orderList = wxCarPayOrderMapper.findList(payOrder); | |||
| if (null != orderList && orderList.size() > 0 ) { | |||
| for (int i = 0 ; i < orderList.size(); i++) { | |||
| WxCarPayOrder _po = orderList.get(i); | |||
| //通知车场支付成功 | |||
| try { | |||
| parkFactory.getParkService(_po.getCarVendor()).notifyPaid(new ParkNotifyPaid(_po.getTenantId(), _po.getParkOrderNo(), _po.getPayAmount(), _po.getPayTime())); | |||
| payOrder.setParkNotify(EnumYesOrNo.YES.getCode()); | |||
| payOrder.setUpdateTime(new Date()); | |||
| payOrder.setNotifyCount(payOrder.getNotifyCount()+1); | |||
| wxCarPayOrderMapper.updateById(payOrder); | |||
| }catch(Exception e) { | |||
| payOrder.setParkNotify(EnumYesOrNo.NO.getCode()); | |||
| payOrder.setNotifyFailReason(e.getMessage()); | |||
| payOrder.setNotifyCount(payOrder.getNotifyCount()+1); | |||
| payOrder.setUpdateTime(new Date()); | |||
| wxCarPayOrderMapper.updateById(payOrder); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| @@ -39,4 +40,16 @@ public class WxCarPayOrder extends TenantEntity { | |||
| private Long merchantId; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户名称",name="merchantName") | |||
| private String merchantName; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否已通知车场EnumYesOrNo",name="parkNotify") | |||
| private Integer parkNotify; | |||
| @io.swagger.annotations.ApiModelProperty(value="通知失败原因",name="notifyFailReason") | |||
| private String notifyFailReason; | |||
| @io.swagger.annotations.ApiModelProperty(value="通知重试次数",name="notifyCount") | |||
| private Integer notifyCount; | |||
| @io.swagger.annotations.ApiModelProperty(value="车场类型EnumCarVendor",name="carVendor") | |||
| private Integer carVendor; | |||
| @TableField(exist = false) | |||
| private Integer notifyCountLimit; | |||
| } | |||
| @@ -15,6 +15,7 @@ import com.iformall.domain.po.WxRefundOrder; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxCarPayOrderMapper; | |||
| @@ -172,15 +173,20 @@ public class WxParkPayServiceImpl implements WxParkPayService { | |||
| payOrder.setMerchantAccount(merchantAccount); | |||
| payOrder.setMerchantId(merchantId); | |||
| payOrder.setMerchantName(merchantName); | |||
| payOrder.setCarVendor(carVendor); | |||
| wxCarPayOrderMapper.insert(payOrder); | |||
| //通知车场支付成功 | |||
| try { | |||
| parkFactory.getParkService(carVendor).notifyPaid(new ParkNotifyPaid(tenantEntity.getTenantId(), parkOrderNo, fee, paidTime)); | |||
| payOrder.setParkNotify(EnumYesOrNo.YES.getCode()); | |||
| payOrder.setUpdateTime(new Date()); | |||
| wxCarPayOrderMapper.updateById(payOrder); | |||
| }catch(Exception e) { | |||
| //TODO 重试 | |||
| 111111111 | |||
| payOrder.setParkNotify(EnumYesOrNo.NO.getCode()); | |||
| payOrder.setNotifyFailReason(e.getMessage()); | |||
| payOrder.setUpdateTime(new Date()); | |||
| wxCarPayOrderMapper.updateById(payOrder); | |||
| } | |||
| }catch(Exception e) { | |||
| @@ -16,11 +16,16 @@ | |||
| <result column="merchant_account" jdbcType="VARCHAR" property="merchantAccount"/> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/> | |||
| <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/> | |||
| <result column="park_notify" jdbcType="INTEGER" property="parkNotify"/> | |||
| <result column="notify_fail_reason" jdbcType="VARCHAR" property="notifyFailReason"/> | |||
| <result column="notify_count" jdbcType="INTEGER" property="notifyCount"/> | |||
| <result column="car_vendor" jdbcType="INTEGER" property="carVendor"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`c_user_id`,`car_number`,`pay_amount`, | |||
| `pay_time`,`transaction_id`,`park_order_no`,`merchant_account`,`merchant_id`,`merchant_name` | |||
| `pay_time`,`transaction_id`,`park_order_no`,`merchant_account`,`merchant_id`,`merchant_name`,`park_notify`, | |||
| `notify_fail_reason`,`notify_count`,`car_vendor` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -78,6 +83,18 @@ | |||
| and `merchant_name` like concat('%', #{merchantName},'%') | |||
| </if> | |||
| <if test=" null != parkNotify "> | |||
| and `park_notify` = #{parkNotify} | |||
| </if> | |||
| <if test=" null != notifyCountLimit "> | |||
| and `notify_count` <= #{notifyCountLimit} | |||
| </if> | |||
| <if test=" null != carVendor "> | |||
| and `car_vendor` <= #{carVendor} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||