| @@ -2,225 +2,189 @@ package com.iformall.domain.po; | |||||
| import javax.persistence.Id; | import javax.persistence.Id; | ||||
| import javax.persistence.Table; | import javax.persistence.Table; | ||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @Table(name = "wx_msg_record") | @Table(name = "wx_msg_record") | ||||
| public class WxMsgRecord implements Serializable { | |||||
| public class WxMsgRecord extends BaseMsg { | |||||
| private static final long serialVersionUID = 18957895653478L; | private static final long serialVersionUID = 18957895653478L; | ||||
| @Id | @Id | ||||
| protected Long id; | protected Long id; | ||||
| @Transient | |||||
| protected List<Long> ids; | |||||
| @Transient | |||||
| protected String sortColumns; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getSortColumns() { | |||||
| return sortColumns; | |||||
| } | |||||
| public List<Long> getIds() { | |||||
| return ids; | |||||
| } | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | |||||
| } | |||||
| //uuid | |||||
| private String uuid; | |||||
| //租户id | //租户id | ||||
| private String tenantId; | private String tenantId; | ||||
| //域1sys 2a端 3c端 4b端 | //域1sys 2a端 3c端 4b端 | ||||
| private String group; | |||||
| //type | |||||
| private Integer type; | |||||
| //msg | |||||
| private Integer domain; | |||||
| //msg 消息类型1短信 2回调短信 邮件 3微信小程序模板 4微信公众号模板 5系统通 | |||||
| private String msg; | private String msg; | ||||
| //发送时间 | //发送时间 | ||||
| private String sendTime; | private String sendTime; | ||||
| //model_id | //model_id | ||||
| private Long modelId; | private Long modelId; | ||||
| //from,手机号邮件地址等 | //from,手机号邮件地址等 | ||||
| private String from; | |||||
| private String sender; | |||||
| //发送人id | //发送人id | ||||
| private Long fromUserId; | |||||
| private Long senderUserId; | |||||
| //发送人姓名 | //发送人姓名 | ||||
| private String fromUserName; | |||||
| private String senderUserName; | |||||
| //接收人,手机号邮件地址等 | //接收人,手机号邮件地址等 | ||||
| private String to; | |||||
| private String receiver; | |||||
| //接收人用户id | //接收人用户id | ||||
| private Long toUserId; | |||||
| private Long receiverUserId; | |||||
| //接收人姓名 | //接收人姓名 | ||||
| private String toUserName; | |||||
| //消费结果 | |||||
| private Integer status; | |||||
| //消费结果信息 | |||||
| private String statusMessage; | |||||
| private String receiverUserName; | |||||
| //签名 | //签名 | ||||
| private String signature; | private String signature; | ||||
| //模板类型 | //模板类型 | ||||
| private Integer modelType; | private Integer modelType; | ||||
| //动态内容(map结构的json数据) | |||||
| private String dynamicContent; | |||||
| //消息json | |||||
| private String msgJson; | |||||
| private Date createtime; | private Date createtime; | ||||
| private Date updatetime; | private Date updatetime; | ||||
| public String getDynamicContent() { | |||||
| return dynamicContent; | |||||
| } | |||||
| //动态替换内容 | |||||
| private Map<String,String> dynamicContentMap; | |||||
| private String dynamicContent; | |||||
| public void setDynamicContent(String dynamicContent) { | |||||
| this.dynamicContent = dynamicContent; | |||||
| } | |||||
| public Integer getModelType() { | |||||
| return modelType; | |||||
| public String getMsgJson() { | |||||
| return msgJson; | |||||
| } | } | ||||
| public void setModelType(Integer modelType) { | |||||
| this.modelType = modelType; | |||||
| public void setMsgJson(String msgJson) { | |||||
| this.msgJson = msgJson; | |||||
| } | } | ||||
| public String getSignature() { | |||||
| return signature; | |||||
| public Map<String, String> getDynamicContentMap() { | |||||
| return dynamicContentMap; | |||||
| } | } | ||||
| public void setSignature(String signature) { | |||||
| this.signature = signature; | |||||
| public void setDynamicContentMap(Map<String, String> dynamicContentMap) { | |||||
| this.dynamicContentMap = dynamicContentMap; | |||||
| } | } | ||||
| public String getUuid() { | |||||
| return uuid; | |||||
| public String getDynamicContent() { | |||||
| return dynamicContent; | |||||
| } | } | ||||
| public void setUuid(String uuid) { | |||||
| this.uuid = uuid; | |||||
| public void setDynamicContent(String dynamicContent) { | |||||
| this.dynamicContent = dynamicContent; | |||||
| } | } | ||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | } | ||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | } | ||||
| public String getGroup() { | |||||
| return group; | |||||
| public Integer getDomain() { | |||||
| return domain; | |||||
| } | } | ||||
| public void setGroup(String group) { | |||||
| this.group = group; | |||||
| public void setDomain(Integer domain) { | |||||
| this.domain = domain; | |||||
| } | } | ||||
| public Integer getType() { | |||||
| return type; | |||||
| public String getSender() { | |||||
| return sender; | |||||
| } | } | ||||
| public void setType(Integer type) { | |||||
| this.type = type; | |||||
| public void setSender(String sender) { | |||||
| this.sender = sender; | |||||
| } | } | ||||
| public String getMsg() { | |||||
| return msg; | |||||
| public Long getSenderUserId() { | |||||
| return senderUserId; | |||||
| } | } | ||||
| public void setMsg(String msg) { | |||||
| this.msg = msg; | |||||
| public void setSenderUserId(Long senderUserId) { | |||||
| this.senderUserId = senderUserId; | |||||
| } | } | ||||
| public String getSendTime() { | |||||
| return sendTime; | |||||
| public String getSenderUserName() { | |||||
| return senderUserName; | |||||
| } | } | ||||
| public void setSendTime(String sendTime) { | |||||
| this.sendTime = sendTime; | |||||
| public void setSenderUserName(String senderUserName) { | |||||
| this.senderUserName = senderUserName; | |||||
| } | } | ||||
| public Long getModelId() { | |||||
| return modelId; | |||||
| public String getReceiver() { | |||||
| return receiver; | |||||
| } | } | ||||
| public void setModelId(Long modelId) { | |||||
| this.modelId = modelId; | |||||
| public void setReceiver(String receiver) { | |||||
| this.receiver = receiver; | |||||
| } | } | ||||
| public String getFrom() { | |||||
| return from; | |||||
| public Long getReceiverUserId() { | |||||
| return receiverUserId; | |||||
| } | } | ||||
| public void setFrom(String from) { | |||||
| this.from = from; | |||||
| public void setReceiverUserId(Long receiverUserId) { | |||||
| this.receiverUserId = receiverUserId; | |||||
| } | } | ||||
| public Long getFromUserId() { | |||||
| return fromUserId; | |||||
| public String getReceiverUserName() { | |||||
| return receiverUserName; | |||||
| } | } | ||||
| public void setFromUserId(Long fromUserId) { | |||||
| this.fromUserId = fromUserId; | |||||
| public void setReceiverUserName(String receiverUserName) { | |||||
| this.receiverUserName = receiverUserName; | |||||
| } | } | ||||
| public String getFromUserName() { | |||||
| return fromUserName; | |||||
| public Integer getModelType() { | |||||
| return modelType; | |||||
| } | } | ||||
| public void setFromUserName(String fromUserName) { | |||||
| this.fromUserName = fromUserName; | |||||
| public void setModelType(Integer modelType) { | |||||
| this.modelType = modelType; | |||||
| } | } | ||||
| public String getTo() { | |||||
| return to; | |||||
| public String getSignature() { | |||||
| return signature; | |||||
| } | } | ||||
| public void setTo(String to) { | |||||
| this.to = to; | |||||
| public void setSignature(String signature) { | |||||
| this.signature = signature; | |||||
| } | } | ||||
| public Long getToUserId() { | |||||
| return toUserId; | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | } | ||||
| public void setToUserId(Long toUserId) { | |||||
| this.toUserId = toUserId; | |||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| } | } | ||||
| public String getToUserName() { | |||||
| return toUserName; | |||||
| public String getMsg() { | |||||
| return msg; | |||||
| } | } | ||||
| public void setToUserName(String toUserName) { | |||||
| this.toUserName = toUserName; | |||||
| public void setMsg(String msg) { | |||||
| this.msg = msg; | |||||
| } | } | ||||
| public Integer getStatus() { | |||||
| return status; | |||||
| public String getSendTime() { | |||||
| return sendTime; | |||||
| } | } | ||||
| public void setStatus(Integer status) { | |||||
| this.status = status; | |||||
| public void setSendTime(String sendTime) { | |||||
| this.sendTime = sendTime; | |||||
| } | } | ||||
| public String getStatusMessage() { | |||||
| return statusMessage; | |||||
| public Long getModelId() { | |||||
| return modelId; | |||||
| } | } | ||||
| public void setStatusMessage(String statusMessage) { | |||||
| this.statusMessage = statusMessage; | |||||
| public void setModelId(Long modelId) { | |||||
| this.modelId = modelId; | |||||
| } | } | ||||
| public Date getCreatetime() { | public Date getCreatetime() { | ||||
| @@ -239,62 +203,5 @@ public class WxMsgRecord implements Serializable { | |||||
| this.updatetime = updatetime; | this.updatetime = updatetime; | ||||
| } | } | ||||
| public static enum Field | |||||
| { | |||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||||
| ,Available_ASC("`available` ASC"),Available_DESC("`available` DESC") | |||||
| ,Description_ASC("`description` ASC"),Description_DESC("`description` DESC") | |||||
| ; | |||||
| private String value; | |||||
| Field(String value){ | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| public void setCol(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return this.getValue(); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(WxMsgRecord.Field... fields) | |||||
| { | |||||
| if (fields == null || fields.length == 0) { | |||||
| return; | |||||
| } | |||||
| for (int k = 0; k < fields.length; k++) { | |||||
| if (fields[k] == null) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||||
| for (int k = 1; k < fields.length; k++) { | |||||
| sb.append(","); | |||||
| sb.append(fields[k].toString()); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(String sortColumns) | |||||
| { | |||||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||||
| return; | |||||
| } | |||||
| if (sortColumns.contains(",")) { | |||||
| String[] cols = sortColumns.split(","); | |||||
| List<Field> fList = new java.util.ArrayList(); | |||||
| for (int k = 0; k < cols.length; k++) { | |||||
| fList.add(Field.valueOf(cols[k])); | |||||
| } | |||||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||||
| } else { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,16 +1,12 @@ | |||||
| package com.iformall.mapper; | package com.iformall.mapper; | ||||
| import com.iformall.common.CommonMapper; | import com.iformall.common.CommonMapper; | ||||
| import com.iformall.domain.po.MallRole; | |||||
| import com.iformall.domain.po.BaseMsg; | |||||
| import com.iformall.domain.po.WxMsgRecord; | import com.iformall.domain.po.WxMsgRecord; | ||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| public interface WxMsgRecordMapper extends CommonMapper<WxMsgRecord, String> { | public interface WxMsgRecordMapper extends CommonMapper<WxMsgRecord, String> { | ||||
| void update(WxMsgRecord record); | |||||
| void update(BaseMsg record); | |||||
| @@ -1,75 +0,0 @@ | |||||
| package com.iformall.mq; | |||||
| import com.alibaba.druid.support.json.JSONUtils; | |||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import com.iformall.enums.EnumMsgRecordStatus; | |||||
| import com.iformall.mapper.WxMsgRecordMapper; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.apache.rocketmq.client.producer.DefaultMQProducer; | |||||
| import org.apache.rocketmq.client.producer.SendCallback; | |||||
| import org.apache.rocketmq.client.producer.SendResult; | |||||
| import org.apache.rocketmq.common.message.Message; | |||||
| import org.apache.rocketmq.remoting.common.RemotingHelper; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.stereotype.Service; | |||||
| import javax.annotation.PostConstruct; | |||||
| import java.util.UUID; | |||||
| /** | |||||
| * @Auther: luozukai | |||||
| * @Date: 2019-01-31 | |||||
| * @Description: RocketMQ消息生产者 | |||||
| */ | |||||
| @Service | |||||
| @Slf4j | |||||
| public class MqProducer { | |||||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | |||||
| @Value("${spring.rocketmq.nameServer}") | |||||
| private String namesrvAddr; | |||||
| @Autowired | |||||
| private WxMsgRecordMapper wxMsgRecordMapper; | |||||
| @PostConstruct | |||||
| public void start(){ | |||||
| try { | |||||
| producer.setNamesrvAddr(namesrvAddr); | |||||
| //producer.setRetryTimesWhenSendFailed(5);//重试机制,默认2次 | |||||
| //producer.setSendMsgTimeout(6000); //默认是3000 | |||||
| producer.start(); | |||||
| log.info("Message Producer Start..."); | |||||
| }catch (Exception e){ | |||||
| log.error("Message Producer Start Error!!",e); | |||||
| } | |||||
| } | |||||
| public void sendMessage(WxMsgRecord data, String topic, String tags, String keys) throws Throwable{ | |||||
| try { | |||||
| data.setUuid(UUID.randomUUID().toString()); | |||||
| wxMsgRecordMapper.insert(data); | |||||
| byte[] messageBody = JSONUtils.toJSONString(data).getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| Message mqMsg = new Message(topic, tags, keys, messageBody); | |||||
| producer.send(mqMsg, new SendCallback() { | |||||
| @Override | |||||
| public void onSuccess(SendResult sendResult) { | |||||
| log.info("Message Producer: Send Message Success {}", sendResult); | |||||
| data.setStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | |||||
| wxMsgRecordMapper.update(data); | |||||
| } | |||||
| @Override | |||||
| public void onException(Throwable throwable) { | |||||
| log.error("Message Producer: Send Message Error (onException)", throwable); | |||||
| } | |||||
| }); | |||||
| } catch (Throwable e) { | |||||
| e.printStackTrace(); | |||||
| log.error("Message Producer: Send Message Error (sendMessage)", e); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,9 +1,14 @@ | |||||
| package com.iformall.mq; | |||||
| package com.iformall.mq.impl; | |||||
| import com.alibaba.druid.support.json.JSONUtils; | |||||
| import com.iformall.domain.po.BaseMsg; | |||||
| import com.iformall.domain.po.WxMsg; | |||||
| import com.iformall.domain.po.WxMsgRecord; | import com.iformall.domain.po.WxMsgRecord; | ||||
| import com.iformall.enums.EnumMsgRecordStatus; | import com.iformall.enums.EnumMsgRecordStatus; | ||||
| import com.iformall.mapper.WxMsgRecordMapper; | import com.iformall.mapper.WxMsgRecordMapper; | ||||
| import com.iformall.mq.MQConfig; | |||||
| import com.iformall.mq.MqBaseProducer; | |||||
| import com.iformall.service.WxMsgRecordService; | |||||
| import com.iformall.utils.JsonUtil; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.rocketmq.client.producer.DefaultMQProducer; | import org.apache.rocketmq.client.producer.DefaultMQProducer; | ||||
| import org.apache.rocketmq.client.producer.SendCallback; | import org.apache.rocketmq.client.producer.SendCallback; | ||||
| @@ -14,31 +19,37 @@ import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.context.annotation.Profile; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import javax.annotation.PostConstruct; | import javax.annotation.PostConstruct; | ||||
| import java.util.UUID; | import java.util.UUID; | ||||
| /** | /** | ||||
| * @Auther: luozukai | |||||
| * @Auther: Stormeye | |||||
| * @Date: 2019-01-31 | * @Date: 2019-01-31 | ||||
| * @Description: RocketMQ消息生产者 | * @Description: RocketMQ消息生产者 | ||||
| */ | */ | ||||
| @Service | @Service | ||||
| @Slf4j | @Slf4j | ||||
| public class MqProducer { | |||||
| @Profile(MQConfig.Impl.ROCKET_MQ) | |||||
| public class RocketMqMessageProducer implements MqBaseProducer { | |||||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||||
| private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | |||||
| @Value("${spring.rocketmq.nameServer}") | @Value("${spring.rocketmq.nameServer}") | ||||
| private String namesrvAddr; | private String namesrvAddr; | ||||
| private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | |||||
| @Autowired | @Autowired | ||||
| private WxMsgRecordMapper wxMsgRecordMapper; | private WxMsgRecordMapper wxMsgRecordMapper; | ||||
| @Autowired | |||||
| private WxMsgRecordService wxMsgRecordService; | |||||
| @PostConstruct | @PostConstruct | ||||
| public void start(){ | public void start(){ | ||||
| try { | try { | ||||
| producer.setNamesrvAddr(namesrvAddr); | producer.setNamesrvAddr(namesrvAddr); | ||||
| //producer.setRetryTimesWhenSendFailed(5);//重试机制,默认2次 | |||||
| //producer.setSendMsgTimeout(6000); //默认是3000 | |||||
| producer.start(); | producer.start(); | ||||
| log.info("Message Producer Start..."); | log.info("Message Producer Start..."); | ||||
| }catch (Exception e){ | }catch (Exception e){ | ||||
| @@ -46,30 +57,32 @@ public class MqProducer { | |||||
| } | } | ||||
| } | } | ||||
| public void sendMessage(WxMsgRecord data, String topic, String tags, String keys) throws Throwable{ | |||||
| @Override | |||||
| public void sendMessage(BaseMsg data, String topic, String tags, String keys) { | |||||
| try { | try { | ||||
| data.setUuid(UUID.randomUUID().toString()); | |||||
| wxMsgRecordMapper.insert(data); | |||||
| wxMsgRecordService.save(data); | |||||
| byte[] messageBody = JsonUtil.obj2Json(data).getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| byte[] messageBody = JSONUtils.toJSONString(data).getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| Message mqMsg = new Message(topic, tags, keys, messageBody); | Message mqMsg = new Message(topic, tags, keys, messageBody); | ||||
| producer.send(mqMsg, new SendCallback() { | producer.send(mqMsg, new SendCallback() { | ||||
| @Override | @Override | ||||
| public void onSuccess(SendResult sendResult) { | public void onSuccess(SendResult sendResult) { | ||||
| log.info("Message Producer: Send Message Success {}", sendResult); | log.info("Message Producer: Send Message Success {}", sendResult); | ||||
| data.setStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | |||||
| wxMsgRecordMapper.update(data); | |||||
| // data.setMsgStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | |||||
| // wxMsgRecordMapper.update(data); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void onException(Throwable throwable) { | public void onException(Throwable throwable) { | ||||
| log.error("Message Producer: Send Message Error (onException)", throwable); | |||||
| log.error("Message Producer: Send Message Error ", throwable); | |||||
| } | } | ||||
| }); | }); | ||||
| } catch (Throwable e) { | |||||
| e.printStackTrace(); | |||||
| log.error("Message Producer: Send Message Error (sendMessage)", e); | |||||
| } catch (Exception e) { | |||||
| log.error("Message Producer: Send Message Error ", e); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,12 +1,10 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import com.iformall.domain.po.BaseMsg; | |||||
| /** | |||||
| * 发送消息 | |||||
| */ | |||||
| public interface MsgSendService { | public interface MsgSendService { | ||||
| void send(WxMsgRecord record); | |||||
| void send(BaseMsg baseMsg) throws Exception; | |||||
| } | } | ||||
| @@ -1,8 +1,25 @@ | |||||
| package com.iformall.service.impl; | package com.iformall.service.impl; | ||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumVerifyCode; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxMsgConfigMapper; | |||||
| import com.iformall.mapper.WxMsgValidationcodeMapper; | |||||
| import com.iformall.mapper.WxMsgValidationcodeModelMapper; | |||||
| import com.iformall.service.MsgSendService; | import com.iformall.service.MsgSendService; | ||||
| import com.iformall.service.WxMsgValidationcodeService; | |||||
| import com.iformall.utils.WiwideUtil; | |||||
| import org.apache.commons.collections.CollectionUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * @author luozukai | * @author luozukai | ||||
| @@ -10,9 +27,82 @@ import org.springframework.stereotype.Service; | |||||
| */ | */ | ||||
| @Service | @Service | ||||
| public class SendSmsServiceImpl implements MsgSendService { | public class SendSmsServiceImpl implements MsgSendService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxMsgConfigMapper wxMsgConfigMapper; | |||||
| @Autowired | |||||
| private WxMsgValidationcodeModelMapper wxMsgValidationcodeModelMapper; | |||||
| @Autowired | |||||
| private WxMsgValidationcodeMapper wxMsgValidationcodeMapper; | |||||
| @Autowired | |||||
| private WxMsgValidationcodeService wxMsgValidationcodeService; | |||||
| @Override | @Override | ||||
| public void send(WxMsgRecord record) { | |||||
| public void send(BaseMsg baseMsg) { | |||||
| WxMsgRecord record = (WxMsgRecord)baseMsg; | |||||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
| wxMsgValidationcode.setPhone(record.getReceiver()); | |||||
| wxMsgValidationcode.setTenantId(record.getTenantId()); | |||||
| wxMsgValidationcode.setType(record.getModelType()); | |||||
| //3、从短信配置中查询密钥 bid 等信息 | |||||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||||
| wxMsgConfig.setTenantId(record.getTenantId()); | |||||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||||
| if(CollectionUtils.isEmpty(wxMsgConfigs)){ | |||||
| throw new MallinkException(ErrorCode.MSG_CONFIG_NOT_FOUND); | |||||
| } | |||||
| wxMsgConfig = wxMsgConfigs.get(0); | |||||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); | |||||
| wxMsgValidationcodeModel.setTenantId(record.getTenantId()); | |||||
| wxMsgValidationcodeModel.setType(record.getModelType()); | |||||
| List<WxMsgValidationcodeModel> modelList = wxMsgValidationcodeModelMapper.findList(wxMsgValidationcodeModel); | |||||
| if(CollectionUtils.isEmpty(modelList)){ | |||||
| throw new MallinkException(ErrorCode.MSG_MODEL_NOT_FOUND); | |||||
| } | |||||
| wxMsgValidationcodeModel = wxMsgValidationcodeModelMapper.findList(wxMsgValidationcodeModel).get(0); | |||||
| String secret = wxMsgConfig.getSecret(); | |||||
| String bid = wxMsgConfig.getBid(); | |||||
| String publickey = wxMsgConfig.getPublickey(); | |||||
| String phone = record.getReceiver(); | |||||
| String signature = wxMsgValidationcodeModel.getSignature(); | |||||
| wxMsgValidationcode.setSignature(signature); | |||||
| //替换内容 | |||||
| String msg = wxMsgValidationcodeModel.getContent(); | |||||
| for (Map.Entry<String, String> entry : record.getDynamicContentMap().entrySet()) { | |||||
| msg = msg.replace("{"+entry.getKey()+"}", entry.getValue()); | |||||
| } | |||||
| wxMsgValidationcode.setMsg(msg); | |||||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||||
| Integer modelId = wxMsgValidationcodeModel.getModelId(); | |||||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.YES.getCode().toString(), modelId); | |||||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||||
| String ret = jsonObjectResult.get("ret").toString(); | |||||
| String batchNo = jsonObjectResult.get("data").toString(); | |||||
| if (ret.equals("1")) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| wxMsgValidationcode.setId(idWorker.nextId()); | |||||
| long currentTime = System.currentTimeMillis() ; | |||||
| Date createtime=new Date(currentTime); | |||||
| wxMsgValidationcode.setCreatetime(createtime); | |||||
| Integer minutes = wxMsgValidationcodeModel.getMinutes(); | |||||
| if(minutes >0) { | |||||
| currentTime += minutes * 60 * 1000; | |||||
| Date expiredate = new Date(currentTime); | |||||
| wxMsgValidationcode.setExpiretime(expiredate); | |||||
| } | |||||
| wxMsgValidationcodeMapper.insertSelective(wxMsgValidationcode); | |||||
| wxMsgValidationcodeService.addMsgCallback(wxMsgValidationcode,batchNo); | |||||
| logger.error("短信运营商返回成功,手机号:{}",phone); | |||||
| }else{ | |||||
| logger.error("短信运营商返回失败,手机号:{},返回信息:{}",phone,result); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,65 +0,0 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.MallRoleMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallRole"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||||
| <result column="available" jdbcType="VARCHAR" property="available" /> | |||||
| <result column="description" jdbcType="VARCHAR" property="description" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`name`,`available`,`description` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != name and '' != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | |||||
| <if test=" null != available "> | |||||
| and `available` like concat('%', #{available},'%') | |||||
| </if> | |||||
| <if test=" null != description "> | |||||
| and `description` like concat('%', #{description},'%') | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.MallRole" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from mall_role | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <select id="countByName" resultType="java.lang.Integer" parameterType="java.util.HashMap"> | |||||
| select count(1) from mall_role where name=#{name} | |||||
| <if test="id!=null"> and id !=#{id}</if> | |||||
| </select> | |||||
| </mapper> | |||||
| @@ -4,18 +4,18 @@ | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMsgRecord"> | <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMsgRecord"> | ||||
| <id column="id" property="id" /> | <id column="id" property="id" /> | ||||
| <result column="tenant_id" property="tenantId" /> | <result column="tenant_id" property="tenantId" /> | ||||
| <result column="group" property="group" /> | |||||
| <result column="type" property="type" /> | |||||
| <result column="domain" property="domain" /> | |||||
| <result column="msg_type" property="msgType" /> | |||||
| <result column="msg" property="msg" /> | <result column="msg" property="msg" /> | ||||
| <result column="send_time" property="sendTime" /> | <result column="send_time" property="sendTime" /> | ||||
| <result column="model_id" property="modelId" /> | <result column="model_id" property="modelId" /> | ||||
| <result column="from" property="from" /> | |||||
| <result column="from_user_id" property="fromUserId" /> | |||||
| <result column="from_user_name" property="fromUserName" /> | |||||
| <result column="to" property="to" /> | |||||
| <result column="to_user_id" property="toUserId" /> | |||||
| <result column="to_user_name" property="toUserName" /> | |||||
| <result column="status" property="status" /> | |||||
| <result column="sender" property="from" /> | |||||
| <result column="sender_user_id" property="fromUserId" /> | |||||
| <result column="sender_user_name" property="fromUserName" /> | |||||
| <result column="receiver" property="to" /> | |||||
| <result column="receiver_user_id" property="toUserId" /> | |||||
| <result column="receiver_user_name" property="toUserName" /> | |||||
| <result column="msg_status" property="msgStatus" /> | |||||
| <result column="status_message" property="statusMessage" /> | <result column="status_message" property="statusMessage" /> | ||||
| <result column="createtime" property="createtime" /> | <result column="createtime" property="createtime" /> | ||||
| <result column="updatetime" property="updatetime" /> | <result column="updatetime" property="updatetime" /> | ||||
| @@ -23,14 +23,10 @@ | |||||
| <result column="signature" property="signature" /> | <result column="signature" property="signature" /> | ||||
| <result column="model_type" property="modelType" /> | <result column="model_type" property="modelType" /> | ||||
| <result column="dynamic_content" property="dynamicContent" /> | <result column="dynamic_content" property="dynamicContent" /> | ||||
| <result column="msg_json" property="msgJson" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`group`,`type`,`msg` ,send_time,model_id,from,from_user_id,from_user_name,to,to_user_id,to_user_name | |||||
| ,status,status_message,createtime,updatetime,uuid,signature,model_type,dynamic_content | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| where 1 = 1 | where 1 = 1 | ||||
| @@ -53,10 +49,10 @@ | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | <if test=" null != sortColumns"> order by ${sortColumns} </if> | ||||
| </sql> | </sql> | ||||
| <update id="update" parameterType="com.iformall.domain.po.WxMsgRecord"> | |||||
| <update id="update" parameterType="com.iformall.domain.po.BaseMsg"> | |||||
| update wx_msg_record set updatetime = now() | update wx_msg_record set updatetime = now() | ||||
| <if test=" null != status ">,status = #{status}</if> | |||||
| <if test=" null != message ">,message = #{message}</if> | |||||
| <if test=" null != msgStatus ">,msg_status = #{msgStatus}</if> | |||||
| <if test=" null != statusMessage ">,status_message = #{statusMessage}</if> | |||||
| where uuid = #{uuid} | where uuid = #{uuid} | ||||
| </update> | </update> | ||||