| @@ -37,6 +37,8 @@ public class MqBaseConsumer { | |||
| @Autowired | |||
| private AfterCarInOutMsgServiceImpl afterCarInOutMsgService; | |||
| @Autowired | |||
| private AfterBusinessCreditMsgServiceImpl afterBusinessCreditMsgService; | |||
| @Autowired | |||
| private SyncMemberCardMsgServiceImpl syncMemberCardMsgService; | |||
| @Autowired | |||
| private FmInsideOrderSuccessMsgServiceImpl fmInsideOrderSuccessMsgService; | |||
| @@ -134,6 +136,11 @@ public class MqBaseConsumer { | |||
| AfterCarInOutMsg msg = (AfterCarInOutMsg)JsonUtil.readValue(message,AfterCarInOutMsg.class); | |||
| afterCarInOutMsgService.send(msg); | |||
| } | |||
| else if(EnumMsgRecordType.AFTER_BUSINESS_CREDIT.getCode().equals(baseMsg.getMsgType())) { | |||
| //商圈积分后 | |||
| AfterBusinessCreditMsg msg = (AfterBusinessCreditMsg)JsonUtil.readValue(message,AfterBusinessCreditMsg.class); | |||
| afterBusinessCreditMsgService.send(msg); | |||
| } | |||
| else if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 下订单成功 | |||
| FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg)JsonUtil.readValue(message,FmInsideOrderSuccessMsg.class); | |||
| @@ -104,7 +104,7 @@ public class BusinessCircleBase extends TenantEntity { | |||
| private Integer increasedPoints; | |||
| @Excel(name = "积分更新时间", width = 20, orderNum = "15", format = "yyyy-MM-dd HH:mm:ss") | |||
| @io.swagger.annotations.ApiModelProperty(value="积分更新时间(新增)",name="increasedPoints") | |||
| @io.swagger.annotations.ApiModelProperty(value="积分更新时间(新增)",name="pointsUpdateTime") | |||
| private Date pointsUpdateTime; | |||
| @Excel(name = "是否退款", width = 20, orderNum = "6", replace = {"退款订单_1", "付款订单_0"}) | |||
| @@ -0,0 +1,20 @@ | |||
| package com.iformall.domain.po.msg; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| /** | |||
| * | |||
| */ | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class AfterBusinessCreditMsg extends BaseMsg { | |||
| private static final long serialVersionUID = -1l; | |||
| @io.swagger.annotations.ApiModelProperty(value="商圈订单ID",name="businessCircleOrderId") | |||
| private Long businessCircleOrderId; | |||
| } | |||
| @@ -18,6 +18,7 @@ public enum EnumMsgRecordType { | |||
| AFTER_ADD_CREDIT(11,"积分变更后"), | |||
| AFTER_ADD_SCORE(12,"成长值变更后"), | |||
| AFTER_CAR_IN_OR_OUT(13,"车辆入场,出场后"), | |||
| AFTER_BUSINESS_CREDIT(14,"商圈积分后"), | |||
| INSIDE_ORDER_SUCCESS(100, "下订单成功"), | |||
| INSIDE_COUPON_VERIFY(101, "券核销"), | |||
| @@ -51,10 +51,17 @@ public interface WxBusinessCircleOrderService { | |||
| */ | |||
| void updatePoints(WxBusinessCircleOrder record); | |||
| /** | |||
| * 同步积分状态 | |||
| * @param record | |||
| */ | |||
| void notifyPoints(WxBusinessCircleOrder record); | |||
| /** | |||
| * 积分同步状态修改 | |||
| */ | |||
| void updateIsPointsNotify(WxBusinessCircleOrder record); | |||
| void sendsyncNotifyPointsMsg(TenantEntity tenantEntity, Long businessCircleOrderId); | |||
| void exportData(WxBusinessCircleOrder circleOrder, HttpServletRequest request, HttpServletResponse response); | |||
| @@ -1,16 +0,0 @@ | |||
| package com.iformall.service; | |||
| import com.iformall.domain.po.WxBusinessCircleOrder; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| public interface WxCallBackService { | |||
| /** | |||
| * | |||
| * @param record | |||
| */ | |||
| @Async | |||
| void notifyPoints(WxBusinessCircleOrder record); | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.service.impl; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.MemberCardAuthorizeResult; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.ParkingNotifyRequest; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PointsCommitStatusResult; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PointsNotifyRequest; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.pagehelper.PageHelper; | |||
| @@ -13,6 +14,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.AfterAddCreditMsg; | |||
| import com.iformall.domain.po.msg.AfterBusinessCreditMsg; | |||
| import com.iformall.domain.po.msg.AfterCarInOutMsg; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -33,8 +35,10 @@ import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.math.BigDecimal; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Locale; | |||
| @Service | |||
| public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderService { | |||
| @@ -64,9 +68,6 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| @Autowired | |||
| WxCreditHistoryService creditHistoryService; | |||
| @Autowired | |||
| WxCallBackService wxCallBackService; | |||
| @Autowired | |||
| WxCouponSendService wxCouponSendService; | |||
| @@ -146,8 +147,11 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| WxBusinessCircleOrder byTransactionId = this.getOrderByTransactionId(record.getTransactionId(),record.getTenantId()); | |||
| if(byTransactionId != null){ | |||
| logger.error("--Wx商圈付款--订单消息已存在---byTransactionId="+byTransactionId.getTransactionId()); | |||
| //同步积分状态 | |||
| this.sendsyncNotifyPointsMsg(record,record.getId()); | |||
| redisLock.unlock(lockKey, timeStr); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); | |||
| return new ResultData(); | |||
| // throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); | |||
| }else { | |||
| Date now = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -235,10 +239,8 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| record.setPointsUpdateTime(creditHistory.getCreateDate()); | |||
| this.updatePoints(record); | |||
| if(StringUtils.isNotBlank(record.getNoticeId())){ | |||
| //同步积分 | |||
| wxCallBackService.notifyPoints(record); | |||
| } | |||
| //同步积分 | |||
| this.sendsyncNotifyPointsMsg(record,record.getId()); | |||
| } | |||
| redisLock.unlock(lockKey, timeStr); | |||
| return new ResultData(creditNum); | |||
| @@ -388,6 +390,52 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| wxBusinessCircleOrderMapper.updatePoints(record); | |||
| } | |||
| @Override | |||
| public void notifyPoints(WxBusinessCircleOrder record){ | |||
| if(EnumYesOrNo.YES.getCode().equals(record.getIsPointsNotify())){ | |||
| logger.info("该商圈订单已同步积分"+record.getId()); | |||
| return; | |||
| } | |||
| WxPayService wxPayService = wxPayAccountService.getWxPayService(record.getTenantId()); | |||
| PointsNotifyRequest request = new PointsNotifyRequest(); | |||
| request.setSubMchid(wxPayService.getConfig().getSubMchId()); | |||
| request.setTransactionId(record.getTransactionId()); | |||
| request.setAppid(wxPayService.getConfig().getAppId()); | |||
| request.setOpenid(record.getOpenid()); | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+'mm:ss", Locale.CHINA); | |||
| if(record.getIncreasedPoints() != null && record.getIncreasedPoints() > 0 ){ | |||
| request.setEarnPoints(true); | |||
| request.setIncreasedPoints(record.getIncreasedPoints()); | |||
| request.setPointsUpdateTime(sdf.format(record.getPointsUpdateTime())); | |||
| }else{ | |||
| request.setEarnPoints(false); | |||
| request.setIncreasedPoints(0); | |||
| request.setPointsUpdateTime(sdf.format(new Date())); | |||
| request.setNoPointsRemarks("该订单不参与积分活动"); | |||
| } | |||
| try { | |||
| String result = wxPayService.getBusinessCircleService().notifyPoints(request); | |||
| logger.info("微信商圈同步积分请求结果----"+result); | |||
| record.setUpdateTime(new Date()); | |||
| this.updateIsPointsNotify(record); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| @Override | |||
| public void sendsyncNotifyPointsMsg(TenantEntity tenantEntity, Long businessCircleOrderId) { | |||
| AfterBusinessCreditMsg msg = new AfterBusinessCreditMsg(); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| msg.setMsgType(EnumMsgRecordType.AFTER_BUSINESS_CREDIT.getCode()); | |||
| msg.setBusinessCircleOrderId(businessCircleOrderId); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| @Override | |||
| public void updateIsPointsNotify(WxBusinessCircleOrder record) { | |||
| record.setUpdateTime(new Date()); | |||
| @@ -1,58 +0,0 @@ | |||
| package com.iformall.service.impl; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PointsNotifyRequest; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.iformall.domain.po.WxBusinessCircleOrder; | |||
| import com.iformall.mapper.WxBusinessCircleOrderMapper; | |||
| import com.iformall.service.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import java.util.Locale; | |||
| @Service | |||
| public class WxCallBackServiceImpl implements WxCallBackService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+'mm:ss", Locale.CHINA); | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| WxBusinessCircleOrderMapper wxBusinessCircleOrderMapper; | |||
| /** | |||
| * | |||
| * @param record | |||
| */ | |||
| public void notifyPoints(WxBusinessCircleOrder record){ | |||
| WxPayService wxPayService = wxPayAccountService.getWxPayService(record.getTenantId()); | |||
| PointsNotifyRequest request = new PointsNotifyRequest(); | |||
| request.setSubMchid(wxPayService.getConfig().getSubMchId()); | |||
| request.setTransactionId(record.getTransactionId()); | |||
| request.setAppid(wxPayService.getConfig().getAppId()); | |||
| request.setOpenid(record.getOpenid()); | |||
| request.setEarnPoints(true); | |||
| request.setIncreasedPoints(record.getIncreasedPoints()); | |||
| request.setPointsUpdateTime(sdf.format(new Date())); | |||
| try { | |||
| String result = wxPayService.getBusinessCircleService().notifyPoints(request); | |||
| logger.info("微信商圈同步积分请求结果----"+result); | |||
| record.setUpdateTime(new Date()); | |||
| wxBusinessCircleOrderMapper.updateIsPointsNotify(record); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,58 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.AfterBusinessCreditMsg; | |||
| import com.iformall.domain.po.msg.AfterCarInOutMsg; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.enums.EnumAppPlat; | |||
| import com.iformall.enums.EnumBusinessType; | |||
| import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.mapper.WxCarCmdLogMapper; | |||
| import com.iformall.pay.WxPayConstant; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxBusinessCircleOrderService; | |||
| import com.iformall.service.WxCUserCarService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| /** | |||
| * | |||
| */ | |||
| @Service | |||
| public class AfterBusinessCreditMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxBusinessCircleOrderService wxBusinessCircleOrderService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception{ | |||
| AfterBusinessCreditMsg msg = (AfterBusinessCreditMsg)baseMsg; | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(msg.getTenantId()); | |||
| tenantEntity.setParentTenantId(msg.getParentTenantId()); | |||
| try { | |||
| Thread.currentThread().sleep(3000); | |||
| } catch (Exception e) { | |||
| logger.error("sleep error: " + e.getMessage()); | |||
| } | |||
| WxBusinessCircleOrder circleOrder = wxBusinessCircleOrderService.getById(msg.getBusinessCircleOrderId(), tenantEntity.getTenantId()); | |||
| if(circleOrder != null){ | |||
| wxBusinessCircleOrderService.notifyPoints(circleOrder); | |||
| } | |||
| } | |||
| } | |||