diff --git a/mallinkAdmin/src/main/resources/db/migration/V20230323000001_business.sql b/mallinkAdmin/src/main/resources/db/migration/V20230323000001_business.sql index 8f66aac5a..cc5765708 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V20230323000001_business.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V20230323000001_business.sql @@ -1,5 +1,7 @@ alter table wx_tags add column is_del int(1) not null default 0 comment '是否已删除,1-是,0-否'; +delete from wx_tags_type where id in (14,17); + update wx_tags set is_del = 1 where type_id in (14,17); alter table wx_business add column final_tenant_id varchar(5) comment ''; diff --git a/mallinkAdmin/src/main/resources/db/migration/V20230323000001_msg.sql b/mallinkAdmin/src/main/resources/db/migration/V20230323000001_msg.sql new file mode 100644 index 000000000..34b90b60b --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V20230323000001_msg.sql @@ -0,0 +1,5 @@ +alter table wx_msg add column per_count int(3) not null default 1 comment '每条消息发送条数'; +alter table wx_msg add column sms_channel int(3) not null default 11 comment '发送渠道 EnumSMSChannel'; +update wx_msg set sms_channel = 12 where tenant_id in ('1035','1036'); + + diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/WxMsgModelSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/WxMsgModelSchedule.java index e3484125a..f4fec9ca2 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/WxMsgModelSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/WxMsgModelSchedule.java @@ -50,7 +50,7 @@ public class WxMsgModelSchedule { public void querySmsTemplate() { WxMsgModel msgModel = new WxMsgModel(); msgModel.setStatus(EnumMsgModelStatus.AUDITING.getCode()); - List aliYunList = wxMsgModelMapper.findAliYunList(msgModel); + List aliYunList = wxMsgModelMapper.findList(msgModel); if(!aliYunList.isEmpty()){ Map> collect = aliYunList.stream().collect(groupingBy(WxMsgModel::getTenantId)); for (String tenantId:collect.keySet()) { diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxMsgModel.java b/mallinkService/src/main/java/com/iformall/domain/po/WxMsgModel.java index 9612262cf..1d1527cbb 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxMsgModel.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxMsgModel.java @@ -1,5 +1,6 @@ package com.iformall.domain.po; +import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.TenantEntity; import lombok.Data; @@ -30,10 +31,25 @@ public class WxMsgModel extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="reason",name="reason") private String reason; - @io.swagger.annotations.ApiModelProperty(value="templateType",name="templateType") + @io.swagger.annotations.ApiModelProperty(value="EnumMsgModelType",name="templateType") private Integer templateType; @io.swagger.annotations.ApiModelProperty(value="通道模板code",name="modelCode") private String modelCode; + + public Integer calcuteContentSize(int perSize) { + if (StringUtils.isBlank(content) || perSize <= 0 ) { + return 1; + } + if (content.length() <= perSize) { + return 1; + } + int count = content.length() % perSize; + int countSize = count * perSize; + if (countSize < content.length()) { + return count+1; + } + return count; + } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/msg/WxMsg.java b/mallinkService/src/main/java/com/iformall/domain/po/msg/WxMsg.java index fcfb1ad25..9e2a7db97 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/msg/WxMsg.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/msg/WxMsg.java @@ -69,6 +69,11 @@ public class WxMsg extends BaseMsg { @io.swagger.annotations.ApiModelProperty(value = "couponInjectId", name = "couponInjectId") private Long couponInjectId; + + @io.swagger.annotations.ApiModelProperty(value = "发送渠道 EnumSMSChannel", name = "smsChannel") + private Integer smsChannel; + @io.swagger.annotations.ApiModelProperty(value = "每条消息发送条数", name = "perCount") + private Integer perCount; @TableField(exist = false) @io.swagger.annotations.ApiModelProperty(value = "模板消息", name = "wxTemplateMsg") diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxMsgModelMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxMsgModelMapper.java index e55153234..7cab4cad9 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxMsgModelMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxMsgModelMapper.java @@ -8,10 +8,6 @@ public interface WxMsgModelMapper extends CommonMapper { List findList(WxMsgModel wxMsgModel); - List findAliYunList(WxMsgModel msgModel); - - int updateByCode(WxMsgModel wxMsgModel); - - + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java index 791f6462b..a0eea4143 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java @@ -240,6 +240,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { wxmsg.setErrorNumber(0); //1、标签短信2、精准发券 wxmsg.setWay(EnumSendWay.COUPON.getCode()); + wxmsg.setSmsChannel(wxMsgConfig.getSmsChannel()); wxMsgService.sendMsgFromCouponInject(wxmsg,wxMsgConfig,record); return new ResultData(); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMsgServiceImpl.java index 6801df32c..aca8dc8e3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMsgServiceImpl.java @@ -22,6 +22,8 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.mq.MqBaseProducer; import com.iformall.service.*; +import com.iformall.sms.EnumSMSChannel; +import com.iformall.sms.SMSFactory; import com.iformall.utils.DateUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -90,6 +92,10 @@ public class WxMsgServiceImpl implements WxMsgService { @Lazy @Autowired TtCUserService ttCUserService; + + @Lazy + @Autowired + SMSFactory smsFactory; @Override public PageInfo listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { @@ -103,8 +109,8 @@ public class WxMsgServiceImpl implements WxMsgService { int success = wxMsgCallbackMapper.queryMsgSendTotal(params); params.put("status", "0"); int error = wxMsgCallbackMapper.queryMsgSendTotal(params); - temp.setSuccessNumber(success); - temp.setErrorNumber(error); + temp.setSuccessNumber(success*temp.getPerCount()); + temp.setErrorNumber(error*temp.getPerCount()); } PageInfo pageInfo = new PageInfo<>(templist); @@ -121,8 +127,8 @@ public class WxMsgServiceImpl implements WxMsgService { int success = wxMsgCallbackMapper.queryMsgSendTotal(params); params.put("status", "0"); int error = wxMsgCallbackMapper.queryMsgSendTotal(params); - wxMsg.setSuccessNumber(success); - wxMsg.setErrorNumber(error); + wxMsg.setSuccessNumber(success*wxMsg.getPerCount()); + wxMsg.setErrorNumber(error*wxMsg.getPerCount()); if(null != wxMsg.getModelId() && wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ WxTemplateMsg wxTemplateMsg = wxTemplateMsgMapper.selectById(wxMsg.getModelId()); wxMsg.setWxTemplateMsg(wxTemplateMsg); @@ -275,7 +281,6 @@ public class WxMsgServiceImpl implements WxMsgService { } return new ResultData(ErrorCode.MSG_SEND_WAY_CHOOSE_ERROR); } - if (phones.isEmpty()) {//没有手工输入手机号时解析标签,有,继续流转 if(wxMsg.getWay() == EnumSendWay.TAG.getCode()){ List list = @@ -323,6 +328,18 @@ public class WxMsgServiceImpl implements WxMsgService { logger.info("短信数量不足"); return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); } + + EnumSMSChannel smsChannel = EnumSMSChannel.getEnum(wxMsgConfig.getSmsChannel()); + if (null == smsChannel) { + return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND,"短信配置渠道错误"); + } + wxMsg.setSmsChannel(smsChannel.getCode()); + WxMsgModel wxMsgModel = wxMsgModelMapper.selectById(wxMsg.getModelId()); + if (null == wxMsgModel) { + return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND,"短信模版未查询到"); + } + wxMsg.setPerCount(calcuteMsgCount(wxMsgModel,smsChannel)); + wxMsg.setExpectSendNumber(wxMsg.getExpectSendNumber()*wxMsg.getPerCount()); saveOrUpdate(wxMsg, wxMsgConfig); return new ResultData(); }else if(wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ @@ -334,6 +351,12 @@ public class WxMsgServiceImpl implements WxMsgService { } } + private Integer calcuteMsgCount(WxMsgModel wxMsgModel,EnumSMSChannel smsChannel) { + if (null != smsChannel.getPerSize() && smsChannel.getPerSize() > 0 ) { + return wxMsgModel.calcuteContentSize(smsChannel.getPerSize()); + } + return 1; + } @Async @Override @@ -357,6 +380,7 @@ public class WxMsgServiceImpl implements WxMsgService { wxMsg1.setSignature(wxMsg.getSignature()); wxMsg1.setMsg(wxMsg.getMsg()); wxMsg1.setModelId(wxMsg.getModelId()); + wxMsg1.setSmsChannel(wxMsg.getSmsChannel()); if (extra > 0 && i == index) { List phoneList = Arrays.asList(split).subList(i * 1000, length); String phones = StringUtils.join(phoneList, ","); diff --git a/mallinkService/src/main/java/com/iformall/sms/EnumSMSChannel.java b/mallinkService/src/main/java/com/iformall/sms/EnumSMSChannel.java index e49b10ee7..28f98d021 100644 --- a/mallinkService/src/main/java/com/iformall/sms/EnumSMSChannel.java +++ b/mallinkService/src/main/java/com/iformall/sms/EnumSMSChannel.java @@ -6,9 +6,9 @@ package com.iformall.sms; */ public enum EnumSMSChannel { - ALIYUN(11, "ALIYUN"), - ALIYUN_ZDY(12, "ALIYUN_ZDY"), - WIWIDE(0,"WIWIDE"); + ALIYUN(11, "ALIYUN",60), + ALIYUN_ZDY(12, "ALIYUN_ZDY(客户的阿里云短信)",0), + WIWIDE(0,"WIWIDE",0); public static EnumSMSChannel getEnum(Integer code) { for (EnumSMSChannel value : values()) { @@ -21,10 +21,12 @@ public enum EnumSMSChannel { private Integer code; private String message; + private Integer perSize;//每条短信最大字数,0:无限制,都按1条算 - EnumSMSChannel(Integer code, String message) { + EnumSMSChannel(Integer code, String message,Integer perSize) { this.code = code; this.message = message; + this.perSize = perSize; } public Integer getCode() { @@ -34,4 +36,8 @@ public enum EnumSMSChannel { public String getMessage() { return message; } + + public Integer getPerSize() { + return perSize; + } } diff --git a/mallinkService/src/main/resources/mapper/WxMsgCallbackMapper.xml b/mallinkService/src/main/resources/mapper/WxMsgCallbackMapper.xml index c50cf7ef4..4567cb08c 100644 --- a/mallinkService/src/main/resources/mapper/WxMsgCallbackMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMsgCallbackMapper.xml @@ -105,7 +105,7 @@ diff --git a/mallinkService/src/main/resources/mapper/WxMsgMapper.xml b/mallinkService/src/main/resources/mapper/WxMsgMapper.xml index 3ff95d12c..024974354 100644 --- a/mallinkService/src/main/resources/mapper/WxMsgMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMsgMapper.xml @@ -24,10 +24,13 @@ + + - `id`,`tenant_id`,`parent_tenant_id`,`model_id`,`msg`,`sendtime`,`createtime`,`expect_send_number`,`success_number`,`error_number`,`return_result`,`phones`,`signature`,`isright`,`name`,`sendstatus`,`excelpath`,`label`,`tags`,`status`,`way`,`coupon_inject_id` + `id`,`tenant_id`,`parent_tenant_id`,`model_id`,`msg`,`sendtime`,`createtime`,`expect_send_number`,`success_number`,`error_number`,`return_result`, + `phones`,`signature`,`isright`,`name`,`sendstatus`,`excelpath`,`label`,`tags`,`status`,`way`,`coupon_inject_id`,`per_count`,`sms_channel` diff --git a/mallinkService/src/main/resources/mapper/WxMsgModelMapper.xml b/mallinkService/src/main/resources/mapper/WxMsgModelMapper.xml index cd7a952c1..7bb15302c 100644 --- a/mallinkService/src/main/resources/mapper/WxMsgModelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMsgModelMapper.xml @@ -74,16 +74,7 @@ from wx_msg_model - - - - + update wx_msg_model set status=#{status},reason=#{reason} where `model_code` = #{modelCode}