| @@ -40,22 +40,32 @@ public class MqBaseConsumer { | |||
| if(EnumMsgRecordType.SMS.getCode().equals(baseMsg.getMsgType())){ | |||
| //短信 | |||
| sendSmsService.send((WxMsgRecord)JsonUtil.readValue(message,WxMsgRecord.class)); | |||
| WxMsgRecord msg = (WxMsgRecord)JsonUtil.readValue(message,WxMsgRecord.class); | |||
| sendSmsService.send(msg); | |||
| } else if(EnumMsgRecordType.SMS_CALLBACK.getCode().equals(baseMsg.getMsgType())){ | |||
| //业务短信 | |||
| sendCallBackSmsService.send((WxMsg)JsonUtil.readValue(message,WxMsg.class)); | |||
| WxMsg msg = (WxMsg)JsonUtil.readValue(message,WxMsg.class); | |||
| sendCallBackSmsService.send(msg); | |||
| } else if(EnumMsgRecordType.EMAIL.getCode().equals(baseMsg.getMsgType())){ | |||
| //邮件 | |||
| sendEmailService.send((MailMsg)JsonUtil.readValue(message,MailMsg.class)); | |||
| MailMsg msg = (MailMsg)JsonUtil.readValue(message,MailMsg.class); | |||
| sendEmailService.send(msg); | |||
| } else if(EnumMsgRecordType.SMART_APP.getCode().equals(baseMsg.getMsgType())){ | |||
| //微信小程序-模板消息 | |||
| sendSmartAppMsgService.send((SmartAppMsg)JsonUtil.readValue(message,SmartAppMsg.class)); | |||
| SmartAppMsg msg = (SmartAppMsg)JsonUtil.readValue(message,SmartAppMsg.class); | |||
| sendSmartAppMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.PUBLIC.getCode().equals(baseMsg.getMsgType())) { | |||
| //公众号-模板消息 | |||
| sendMpMsgService.send((MpAppMsg)JsonUtil.readValue(message,MpAppMsg.class)); | |||
| MpAppMsg msg = (MpAppMsg)JsonUtil.readValue(message,MpAppMsg.class); | |||
| sendMpMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.SMART_APP_UNIFORM.getCode().equals(baseMsg.getMsgType())) { | |||
| //微信小程序-统一消息 | |||
| sendWeappUniformMsgService.send((AppUniformMsg)JsonUtil.readValue(message,AppUniformMsg.class)); | |||
| AppUniformMsg msg = (AppUniformMsg)JsonUtil.readValue(message,AppUniformMsg.class); | |||
| sendWeappUniformMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 下订单成功 | |||
| FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg)JsonUtil.readValue(message,FmInsideOrderSuccessMsg.class); | |||
| } | |||
| baseMsg.setMsgStatus(EnumMsgRecordStatus.CONSUME_SUCC.getCode()); | |||
| wxMsgRecordMapper.update(baseMsg); | |||
| @@ -405,6 +405,8 @@ public enum ErrorCode{ | |||
| MSG_CONFIG_NOT_FOUND(27001, "找不到短信配置"), | |||
| MSG_CONFIG_ACCOUNT(27002, "短信条数剩余不足"), | |||
| MSG_INSIDE_ERROR(271001, "内部消息转发失败"), | |||
| /** | |||
| * 拼团 | |||
| */ | |||
| @@ -0,0 +1,21 @@ | |||
| package com.iformall.domain.po.msg; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class FmInsideOrderSuccessMsg extends BaseMsg{ | |||
| private static final long serialVersionUID = 1L; | |||
| @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") | |||
| private String tenantId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "成功订单ID", name = "orderId") | |||
| private Long orderId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "券ID", name = "couponId") | |||
| private Long couponId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "cUserId") | |||
| private Long cUserId; | |||
| } | |||
| @@ -12,6 +12,7 @@ public enum EnumMsgRecordType { | |||
| SYSTEM(6, "系统通知"), | |||
| SMART_APP_UNIFORM(7, "小程序统一消息"), | |||
| WEBSOCKET_APP(8, "小程序websocket"), | |||
| INSIDE_ORDER_SUCCESS(100, "下订单成功"), | |||
| ; | |||
| public static EnumMsgRecordType getEnum(Integer code) { | |||
| @@ -160,4 +160,12 @@ public interface WxOrderService { | |||
| // 3. 创建有价订单 | |||
| WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | |||
| /** | |||
| * 下订单成功后处理 | |||
| * @param updateOrder | |||
| * @param coupon | |||
| * @param user | |||
| */ | |||
| void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user); | |||
| } | |||
| @@ -7,10 +7,12 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||
| import com.iformall.domain.vo.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.PressUtils; | |||
| @@ -108,6 +110,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Override | |||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | |||
| @@ -600,8 +605,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| wxOrderMapper.insertSelective(record); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| // 库存恢复 | |||
| stockBack(record); | |||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); | |||
| } | |||
| @@ -611,8 +614,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| couponOrder = createCouponOrder(record, user, coupon); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| // 库存恢复 | |||
| stockBack(record); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| @@ -667,18 +668,33 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| // 订单+券包 流程 完成 | |||
| actionAfterCouponOrderSuccess(updateOrder, coupon, user); | |||
| // 下订单完成,发送内部消息 | |||
| try { | |||
| sendInsideOrderSuccessMsg(updateOrder, coupon, user); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| return ret; | |||
| } | |||
| private void sendInsideOrderSuccessMsg(WxOrder updateOrder, WxCoupon coupon, WxCUser user) { | |||
| FmInsideOrderSuccessMsg orderSuccess = new FmInsideOrderSuccessMsg(); | |||
| orderSuccess.setMsgType(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode()); | |||
| orderSuccess.setTenantId(updateOrder.getTenantId()); | |||
| orderSuccess.setOrderId(updateOrder.getId()); | |||
| orderSuccess.setCUserId(user.getId()); | |||
| orderSuccess.setCouponId(coupon.getId()); | |||
| mqBaseProducer.sendMessage(orderSuccess, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| /** | |||
| * 下订单后操作 | |||
| * @param updateOrder | |||
| * @param coupon | |||
| * @param user | |||
| */ | |||
| private void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user) { | |||
| public void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user) { | |||
| // 交易发券 | |||
| try { | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER, updateOrder); | |||
| @@ -1185,8 +1201,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| // 6. 订单+券包 流程 完成 | |||
| actionAfterCouponOrderSuccess(record, coupon, user); | |||
| // 6. 下订单完成,发送内部消息 | |||
| try { | |||
| sendInsideOrderSuccessMsg(record, coupon, user); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| return record; | |||
| } | |||
| @@ -0,0 +1,72 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| /** | |||
| * | |||
| * @author Stormeye Wu | |||
| * @date 2019/5/10 | |||
| */ | |||
| @Service | |||
| public class FmInsideOrderSuccessMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxOrderService orderService; | |||
| @Autowired | |||
| private WxCUserService userService; | |||
| @Autowired | |||
| private WxCouponService couponService; | |||
| @Autowired | |||
| private WxCouponChannelService couponChannelService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception{ | |||
| FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg)baseMsg; | |||
| WxOrder record = orderService.getById(msg.getOrderId()); | |||
| if(record == null) { | |||
| logger.error("订单未找到" + msg.getOrderId()); | |||
| } | |||
| if(record.getcUserId() != msg.getCUserId()) { | |||
| logger.error("订单用户不一致" + msg.getOrderId()); | |||
| } | |||
| WxCouponChannel couponChannel = couponChannelService.getById(record.getCouponChannelId()); | |||
| if(couponChannel == null) { | |||
| logger.error("投放渠道未找到" + record.getCouponChannelId()); | |||
| } | |||
| if(couponChannel.getCouponId() != msg.getCouponId()) { | |||
| logger.error("券ID不一致" + msg.getCouponId()); | |||
| } | |||
| WxCUser user = userService.getById(msg.getCUserId()); | |||
| if(user == null) { | |||
| logger.error("用户未找到" + msg.getCUserId()); | |||
| } | |||
| WxCoupon coupon = couponService.getById(msg.getCouponId()); | |||
| if(coupon == null) { | |||
| logger.error("券未找到" + msg.getCouponId()); | |||
| } | |||
| // 下订单后处理 | |||
| orderService.actionAfterCouponOrderSuccess(record, coupon, user); | |||
| } | |||
| } | |||