| @@ -1,10 +1,15 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMsgMapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.MsgSendService; | |||
| import com.iformall.service.WxMsgRecordService; | |||
| import com.iformall.service.impl.SendCallBackSmsServiceImpl; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.JsonUtil; | |||
| import io.swagger.annotations.Api; | |||
| import org.slf4j.Logger; | |||
| @@ -24,6 +29,36 @@ public class WxMsgRecordController extends BaseController { | |||
| private WxMsgRecordService wxMsgRecordService; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private WxMsgMapper wxMsgMapper; | |||
| @Autowired | |||
| private SendCallBackSmsServiceImpl msgSendService; | |||
| @GetMapping(value = "/test") | |||
| public ResultData test() throws Exception{ | |||
| // String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); | |||
| // WxMsg wxMsg = new WxMsg(); | |||
| // wxMsg.setIsright(0); | |||
| // wxMsg.setSendtime(systemTime); | |||
| // wxMsg.setId(270060355273621504l); | |||
| // List<WxMsg> list = wxMsgMapper.findList(wxMsg); | |||
| // logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); | |||
| // for (WxMsg msg : list) { | |||
| // //sendmsg(msg); | |||
| // msg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); | |||
| // msg.setReceiver(msg.getPhones()); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(),null); | |||
| // } | |||
| String s = "{\"tenantId\":\"456\",\"uuid\":\"0a410e4e-c0ef-461e-bea8-7bd222e7c7b7\",\"delayTimeLevel\":0,\"id\":270060355273621504,\"modelId\":220401934081720320,\"msg\":\"狂欢双十一:更多礼品等你来领取\",\"sendtime\":\"2019-03-25 16:00:00\",\"createtime\":\"2019-03-25 15:30:16\",\"expectSendNumber\":1,\"phones\":\"18601973448\",\"signature\":\"富茂科技\",\"isright\":0,\"name\":\"狂欢双十一\",\"excelpath\":\"\",\"label\":\"\",\"status\":0,\"way\":1}"; | |||
| WxMsg wxMsg = (WxMsg) JsonUtil.readValue(s,WxMsg.class); | |||
| wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); | |||
| wxMsg.setReceiver("18601973448"); | |||
| wxMsg.setTenantId("456"); | |||
| msgSendService.send(wxMsg); | |||
| return new ResultData(); | |||
| } | |||
| /** | |||
| * 重新发送失败的消息 | |||
| @@ -10,8 +10,6 @@ public class MailMsg extends BaseMsg { | |||
| private static final long serialVersionUID = 923764283760321L; | |||
| // 模板id | |||
| private Integer modelId; | |||
| private String tenantId; | |||
| private String[] to; | |||
| private String from; | |||
| private String msg; | |||
| @@ -29,14 +27,6 @@ public class MailMsg extends BaseMsg { | |||
| //动态替换内容 | |||
| private Map<String,String> dynamicContentMap; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String tenantId) { | |||
| this.tenantId = tenantId; | |||
| } | |||
| public Map<String, String> getDynamicContentMap() { | |||
| return dynamicContentMap; | |||
| } | |||
| @@ -13,7 +13,6 @@ public class SmartAppMsg extends BaseMsg { | |||
| //小程序的appId | |||
| private String appId; | |||
| private String tenantId; | |||
| private String to; | |||
| private String from; | |||
| private Integer templateType; | |||
| @@ -45,14 +44,6 @@ public class SmartAppMsg extends BaseMsg { | |||
| this.gotopage = gotopage; | |||
| } | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String tenantId) { | |||
| this.tenantId = tenantId; | |||
| } | |||
| public String getTo() { | |||
| return to; | |||
| } | |||
| @@ -43,11 +43,12 @@ public class SendCallBackSmsServiceImpl implements MsgSendService { | |||
| private WxMsgService wxMsgService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) { | |||
| public void send(BaseMsg baseMsg) throws Exception{ | |||
| WxMsg record = (WxMsg)baseMsg; | |||
| WxMsgConfig wxMsgConfig = record.getWxMsgConfig(); | |||
| if(wxMsgConfig == null){ | |||
| wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(record.getTenantId()); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0) { | |||
| @@ -38,7 +38,7 @@ public class SendSmsServiceImpl implements MsgSendService { | |||
| private WxMsgValidationcodeService wxMsgValidationcodeService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) { | |||
| public void send(BaseMsg baseMsg) throws Exception{ | |||
| WxMsgRecord record = (WxMsgRecord)baseMsg; | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setPhone(record.getReceiver()); | |||
| @@ -6,11 +6,9 @@ import com.iformall.enums.EnumMsgRecordStatus; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxMsgRecordService; | |||
| import com.iformall.utils.JsonUtil; | |||
| import org.apache.commons.beanutils.PropertyUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.List; | |||
| import java.util.UUID; | |||
| /** | |||
| * @author luozukai | |||
| @@ -23,20 +21,32 @@ public class WxMsgRecordServiceImpl implements WxMsgRecordService { | |||
| @Override | |||
| public void save(BaseMsg data){ | |||
| WxMsgRecord msgRecord = new WxMsgRecord(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| if(data instanceof WxMsgRecord){ | |||
| msgRecord = (WxMsgRecord)data; | |||
| } | |||
| WxMsgRecord msgRecord = new WxMsgRecord(); | |||
| msgRecord.setId(idWorker.nextId()); | |||
| msgRecord.setReceiver(data.getReceiver()); | |||
| msgRecord.setMsgType(data.getMsgType()); | |||
| msgRecord.setUuid(data.getUuid()); | |||
| msgRecord.setMsgJson(JsonUtil.obj2Json(data)); | |||
| msgRecord.setMsgStatus(EnumMsgRecordStatus.DEFAULT.getCode()); | |||
| msgRecord.setTenantId(data.getTenantId()); | |||
| if(data instanceof WxMsgRecord){ | |||
| msgRecord = (WxMsgRecord)data; | |||
| }else if(data instanceof WxMsg){ | |||
| WxMsg wxMsg = (WxMsg)data; | |||
| msgRecord.setTenantId(wxMsg.getTenantId()); | |||
| msgRecord.setMsgType(wxMsg.getMsgType()); | |||
| msgRecord.setReceiver(wxMsg.getPhones()); | |||
| }else if(data instanceof MailMsg){ | |||
| MailMsg wxMsg = (MailMsg)data; | |||
| msgRecord.setTenantId(wxMsg.getTenantId()); | |||
| msgRecord.setMsgType(wxMsg.getMsgType()); | |||
| msgRecord.setReceiver(JsonUtil.obj2Json(wxMsg.getTo())); | |||
| }else if(data instanceof SmartAppMsg){ | |||
| SmartAppMsg wxMsg = (SmartAppMsg)data; | |||
| msgRecord.setTenantId(wxMsg.getTenantId()); | |||
| msgRecord.setMsgType(wxMsg.getMsgType()); | |||
| msgRecord.setReceiver(wxMsg.getTo()); | |||
| } | |||
| wxMsgRecordMapper.save(msgRecord); | |||
| } | |||