| @@ -1,2 +1,6 @@ | |||
| INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (34, 34, '预约通知', '富茂', '您有新的预约订单请及时处理。', '2023-07-20 18:00:26', 1, 0, NULL, 0, 1, 2, ' | |||
| SMS_461970987'); | |||
| INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (34, 34, '预约通知', '富茂', '您有新的预约订单请及时处理。', '2023-07-20 18:00:26', 1, 0, NULL, 0, 1, 2, 'SMS_461970987'); | |||
| INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (35, 35, '分账失败提醒', '富茂', '您有订单分账处理失败,请及时查看。', '2023-07-20 18:00:26', 1, 0, NULL, 0, 1, 1, 'SMS_462021018'); | |||
| INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (36, 36, '分账失败通知', '富茂', '<!DOCTYPE html>\r\n<html>\r\n\r\n<head>\r\n <meta charset=\"utf-8\">\r\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\">\r\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n <meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />\r\n <meta name=\"renderer\" content=\"webkit\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\r\n <title>富茂通知邮件</title>\r\n <title></title>\r\n <style>\r\n *{\r\n margin: 0;\r\n padding: 0;\r\n }\r\n </style>\r\n</head>\r\n\r\n<body>\r\n <div id=\"box\" style=\"padding:80px 20%;background:#E9E7E7;min-height:100vh;\">\r\n <header style=\"height:140px;width:100%;display:flex;background:rgba(31,47,62,1);border-radius:15px 15px 0px 0px;\">\r\n </header>\r\n <content>\r\n <div style=\"background:#fff;\">\r\n <div style=\"font-size:26px;font-family:MicrosoftYaHei-Bold;font-weight:bold;color:rgba(85,85,85,1);line-height: 32px;padding: 56px 55px 0;\">通知<span>({mallName})</span></div>\r\n <div style=\"font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(85,85,85,1);padding: 36px 55px 40px;\"><span>您有分账处理失败的订单,请电脑登录后台查看分账详情</div>\r\n </div>\r\n </content>\r\n </div>\r\n</body>\r\n\r\n</html>', '2023-07-20 18:00:26', 1, NULL, NULL, 0, 2, 1, NULL); | |||
| @@ -1,21 +1,20 @@ | |||
| package com.iformall.schedule; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.WxMall; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderStatus; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.domain.po.msg.MailMsg; | |||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMallMapper; | |||
| import com.iformall.mapper.WxMallNoticeContactMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.mapper.WxProfitSharingOrderMapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.WxProfitSharingOrderService; | |||
| 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; | |||
| @@ -23,7 +22,9 @@ import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.List; | |||
| import java.util.*; | |||
| import java.util.concurrent.atomic.AtomicInteger; | |||
| import java.util.stream.Collectors; | |||
| @Component | |||
| public class SharingOrderRedoSchedule { | |||
| @@ -39,10 +40,18 @@ public class SharingOrderRedoSchedule { | |||
| @Autowired | |||
| WxPayOrderMapper wxPayOrderMapper; | |||
| @Autowired | |||
| WxMallMapper wxMallMapper; | |||
| @Autowired | |||
| WxMallNoticeContactMapper wxMallNoticeContactMapper; | |||
| @Autowired | |||
| MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private String fmExceptionEmails; | |||
| private List<WxMall> getMalls() { | |||
| WxMall wxMall =new WxMall(); | |||
| return wxMallMapper.findList(wxMall); | |||
| @@ -55,6 +64,8 @@ public class SharingOrderRedoSchedule { | |||
| public void sharingOrderRedoSchedule() { | |||
| List<WxMall> malls = getMalls(); | |||
| for (WxMall mall: malls) { | |||
| AtomicInteger errorCount = new AtomicInteger(); | |||
| WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); | |||
| wxProfitSharingOrder.setTenantId(mall.getTenantId()); | |||
| // wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); | |||
| @@ -62,32 +73,48 @@ public class SharingOrderRedoSchedule { | |||
| List<WxProfitSharingOrder> list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); | |||
| if (null != list) { | |||
| list.stream().forEach(sharingOrder->{ | |||
| try { | |||
| int i = DateUtils.daysBetween(sharingOrder.getCreateTime(), new Date()); | |||
| boolean isSuccess = true; | |||
| try { | |||
| // WxPayOrder wxPayOrder = new WxPayOrder(); | |||
| // wxPayOrder.updateTenantInfo(sharingOrder); | |||
| // wxPayOrder.setId(sharingOrder.getOrderId()); | |||
| // wxPayOrder = wxPayOrderMapper.selectOne(new QueryWrapper(wxPayOrder)); | |||
| WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId(),sharingOrder.getTenantId()); | |||
| if (null == wxPayOrder) { | |||
| isSuccess = false; | |||
| logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getMessage() | |||
| + " ID:" +sharingOrder.getId() | |||
| + " RES: wxPayOrder is null." ); | |||
| return; | |||
| } | |||
| ResultData result = wxProfitSharingOrderService.redoSharingOrder(sharingOrder,wxPayOrder); | |||
| if (result.code != ResultData.SUCCESS) { | |||
| isSuccess = false; | |||
| logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getMessage() | |||
| + " ID:" +sharingOrder.getId() | |||
| + " RES:" + result.message); | |||
| } | |||
| } catch (Exception e){ | |||
| isSuccess = false; | |||
| logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getMessage() | |||
| + " ID:" +sharingOrder.getId() | |||
| + " MSG:" + e.getMessage()); | |||
| } | |||
| //分账3天失败给通知 | |||
| if(!isSuccess && i >= 3){ | |||
| errorCount.getAndIncrement(); | |||
| } | |||
| }); | |||
| } | |||
| if(errorCount.get() > 0){ | |||
| try{ | |||
| //分账失败通知 | |||
| sendSharingErrorMsg(mall); | |||
| }catch(Exception e){} | |||
| } | |||
| // wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); | |||
| // wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| @@ -134,6 +161,44 @@ public class SharingOrderRedoSchedule { | |||
| } | |||
| private void sendSharingErrorMsg(WxMall mall){ | |||
| logger.info("分账失败通知start"); | |||
| WxMallNoticeContact noticeContact = wxMallNoticeContactMapper.getByTenantInfo(mall); | |||
| if(noticeContact == null){ | |||
| return; | |||
| } | |||
| if(StringUtils.isNotBlank(noticeContact.getPhone()) && EnumYesOrNo.YES.getCode().equals(noticeContact.getPhoneEnabled())){ | |||
| WxMsgRecord wxMsgRecord = new WxMsgRecord(); | |||
| wxMsgRecord.updateTenantInfo(mall); | |||
| wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); | |||
| wxMsgRecord.setModelType(EnumMsgModel.COUPON_ORDER_SHARING_ERROR.getCode()); | |||
| wxMsgRecord.setReceiver(noticeContact.getPhone()); | |||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| logger.info("分账失败短信通知end"); | |||
| } | |||
| String[] fmEmails = fmExceptionEmails.split(","); | |||
| List<String> mails = new ArrayList<>(Arrays.asList(fmEmails)); | |||
| if(StringUtils.isNotBlank(noticeContact.getEmail()) && EnumYesOrNo.YES.getCode().equals(noticeContact.getEmailEnabled())){ | |||
| mails.add(noticeContact.getEmail()); | |||
| } | |||
| String[] strings = mails.toArray(new String[mails.size()]); | |||
| Map<String, String> map = new HashedMap(); | |||
| map.put("mallName", mall.getName()); | |||
| MailMsg mailMsg = new MailMsg(); | |||
| mailMsg.setSubject("分账失败通知"); | |||
| mailMsg.setHtml(true); | |||
| mailMsg.setMsgType(EnumMsgRecordType.EMAIL.getCode()); | |||
| mailMsg.setModelType(EnumMailMsgModel.MAIL_SHARING_ERROR.getCode()); | |||
| mailMsg.setTo(strings); | |||
| mailMsg.updateTenantInfo(mall); | |||
| mailMsg.setDynamicContentMap(map); | |||
| mqBaseProducer.sendMessage(mailMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| logger.info("分账失败邮件通知end"); | |||
| } | |||
| // @Async | |||
| //// @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨02:00分账重试 | |||
| // @Scheduled(cron = "0 10 */1 * * ?") // 测试 | |||
| @@ -37,7 +37,7 @@ public class WxMsgValidationcodeModel extends BaseEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="发送开关 0开1关",name="open") | |||
| private Integer open; | |||
| @io.swagger.annotations.ApiModelProperty(value="消息类型 0全部 1短信 2邮箱 11阿里云短信(暂未启用)",name="msgType") | |||
| @io.swagger.annotations.ApiModelProperty(value="消息类型 1短信 2邮箱",name="msgType") | |||
| private Integer msgType; | |||
| @io.swagger.annotations.ApiModelProperty(value="0通用1管理员2商户端3消费者",name="roleType") | |||
| @@ -17,6 +17,9 @@ public enum EnumMailMsgModel { | |||
| MAIL_C_APPLY_NODIFY(25, "审批通知"), | |||
| MAIL_C_ASSIGNEE_NODIFY(26, "代办通知"), | |||
| MAIL_C_REJECT_NODIFY(27, "驳回通知"), | |||
| MAIL_SHARING_ERROR(36, "分账失败通知"), | |||
| ; | |||
| public static EnumMailMsgModel getEnum(Integer code) { | |||
| @@ -43,6 +43,7 @@ public enum EnumMsgModel { | |||
| COUPON_ORDER_REFUND(33,"提交退款提醒"), | |||
| COUPON_ORDER_RESERVATION_SUCCESS(34,"预约成功提醒"), | |||
| COUPON_ORDER_SHARING_ERROR(35,"分账失败提醒"), | |||
| ; | |||
| public static EnumMsgModel getEnum(Integer code) { | |||
| @@ -250,16 +250,18 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.updateTenantInfo(sharingOrder); | |||
| updSharingOrder.setId(sharingOrder.getId()); | |||
| updSharingOrder.setUpdateTime(currentDate); | |||
| if(e.getErrorCode() == ErrorCode.PROFIT_SHARING_NO_SUB_LEDGER_AMOUNT.getCode()){ | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_PROCESSING.getCode()); | |||
| updSharingOrder.setErrorMsg(e.getMessage()); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(); | |||
| }else{ | |||
| updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| updSharingOrder.setErrorMsg(e.getMessage()); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),e.getMessage()); | |||
| } | |||
| updSharingOrder.setUpdateTime(currentDate); | |||
| wxProfitSharingOrderMapper.updateById(updSharingOrder); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),e.getMessage()); | |||
| }catch(Exception e){ | |||
| WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); | |||
| updSharingOrder.updateTenantInfo(sharingOrder); | |||
| @@ -48,26 +48,25 @@ public class SendEmailServiceImpl implements MsgSendService { | |||
| TenantEntity tenantEntity = mailMsg.getTenantInfo(); | |||
| //根据模板替换动态内容 | |||
| if(mailMsg.getModelId() != null){ | |||
| WxMsgValidationcodeModel msgModel = new WxMsgValidationcodeModel(); | |||
| msgModel.setType(mailMsg.getModelType()); | |||
| msgModel.setModelCode(String.valueOf(mailMsg.getModelId())); | |||
| msgModel.setOpen(EnumMsgOpen.OPEN.getCode()); | |||
| List<WxMsgValidationcodeModel> modelList = wxMsgValidationcodeModelMapper.findList(msgModel); | |||
| if(CollectionUtils.isEmpty(modelList)){ | |||
| throw new Exception("模板id:"+mailMsg.getModelId()+"不存在"); | |||
| } | |||
| WxMsgValidationcodeModel wxMsgModel = modelList.get(0); | |||
| WxMsgValidationcodeModel msgModel = new WxMsgValidationcodeModel(); | |||
| msgModel.setType(mailMsg.getModelType()); | |||
| msgModel.setMsgType(2); | |||
| // msgModel.setModelCode(String.valueOf(mailMsg.getModelId())); | |||
| msgModel.setOpen(EnumMsgOpen.OPEN.getCode()); | |||
| List<WxMsgValidationcodeModel> modelList = wxMsgValidationcodeModelMapper.findList(msgModel); | |||
| if(CollectionUtils.isEmpty(modelList)){ | |||
| throw new Exception("模板:不存在"); | |||
| } | |||
| WxMsgValidationcodeModel wxMsgModel = modelList.get(0); | |||
| String msg = wxMsgModel.getContent(); | |||
| for (Map.Entry<String, String> entry : mailMsg.getDynamicContentMap().entrySet()) { | |||
| msg = msg.replace("{"+entry.getKey()+"}", entry.getValue()); | |||
| } | |||
| if(StringUtils.isNotBlank(wxMsgModel.getEmailBgImg())){ | |||
| msg = msg.replace("{bg}", wxMsgModel.getEmailBgImg()); | |||
| } | |||
| mailMsg.setMsg(msg); | |||
| String msg = wxMsgModel.getContent(); | |||
| for (Map.Entry<String, String> entry : mailMsg.getDynamicContentMap().entrySet()) { | |||
| msg = msg.replace("{"+entry.getKey()+"}", entry.getValue()); | |||
| } | |||
| if(StringUtils.isNotBlank(wxMsgModel.getEmailBgImg())){ | |||
| msg = msg.replace("{bg}", wxMsgModel.getEmailBgImg()); | |||
| } | |||
| mailMsg.setMsg(msg); | |||
| if(mailMsg.isHtml()){ //html邮件 | |||
| MimeMessage message = sender.createMimeMessage(); | |||
| @@ -61,6 +61,7 @@ public class SendSmsServiceImpl implements MsgSendService { | |||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); | |||
| wxMsgValidationcodeModel.setType(record.getModelType()); | |||
| wxMsgValidationcodeModel.setMsgType(1); | |||
| wxMsgValidationcodeModel.setOpen(EnumMsgOpen.OPEN.getCode()); | |||
| List<WxMsgValidationcodeModel> modelList = wxMsgValidationcodeModelMapper.findList(wxMsgValidationcodeModel); | |||
| if(CollectionUtils.isEmpty(modelList)){ | |||