| @@ -4,13 +4,19 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxMsg; | |||
| import com.iformall.domain.po.WxMsgConfig; | |||
| import com.iformall.enums.EnumMsgSend; | |||
| import com.iformall.enums.EnumMsgStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxMsgConfigMapper; | |||
| import com.iformall.service.PushLimitService; | |||
| import com.iformall.service.WxCUserTagsService; | |||
| import com.iformall.service.WxMsgService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @@ -25,6 +31,9 @@ import java.io.File; | |||
| import java.io.FileOutputStream; | |||
| import java.util.*; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| @RestController | |||
| @RequestMapping("wxMsg") | |||
| public class WxMsgController extends BaseController { | |||
| @@ -39,6 +48,9 @@ public class WxMsgController extends BaseController { | |||
| @Autowired | |||
| WxCUserTagsService wxCUserTagsService; | |||
| @Autowired | |||
| PushLimitService pushLimitService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -58,34 +70,53 @@ public class WxMsgController extends BaseController { | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxMsg wxMsg) { | |||
| logger.debug("[" + getIpAddr() + "] WxMsgController::add"); | |||
| //不是草稿检验疲劳度 | |||
| if (!wxMsg.getStatus().equals(EnumMsgStatus.MSG_STATUS_DRAFT.getCode())) { | |||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | |||
| try { | |||
| pushLimitService.checkSendTime(getTenantId()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| PushLimit pushLimit = pushLimitService.getPushLimit(getTenantId()); | |||
| String sendtime = wxMsg.getSendtime(); | |||
| Date date = DateUtils.stringToDate(sendtime, "yyyy-MM-dd HH:mm:ss"); | |||
| boolean isInDate = DateUtils.isInDate(date, pushLimit.getTimeStart(), pushLimit.getTimeEnd()); | |||
| if (!isInDate) { | |||
| return new ResultData(ErrorCode.PUSH_LIMIT_NOT_INRANG); | |||
| } | |||
| } | |||
| } | |||
| wxMsg.setTenantId(getTenantId()); | |||
| //1、手机多条以逗号分隔,直接通过实体得到wxmsg.getphones | |||
| //2、通过标签 | |||
| String phones=wxMsg.getPhones(); | |||
| String phones = wxMsg.getPhones(); | |||
| String label = wxMsg.getLabel(); | |||
| if(!phones.equals("") && !label.equals("")){//两种方式只能选其一 | |||
| if (!phones.equals("") && !label.equals("")) {//两种方式只能选其一 | |||
| return new ResultData(ErrorCode.MSG_SEND_WAY_CHOOSE_ERROR); | |||
| } | |||
| if(phones.equals("")){//没有手工输入手机号时解析标签,有,继续流转 | |||
| phones=parselabel(wxMsg.getTenantId(), wxMsg); | |||
| if(phones.equals("")){//解析之后手机号依然不存在时返回 | |||
| if (phones.equals("")) {//没有手工输入手机号时解析标签,有,继续流转 | |||
| phones = parselabel(wxMsg.getTenantId(), wxMsg); | |||
| if (phones.equals("")) {//解析之后手机号依然不存在时返回 | |||
| return new ResultData(ErrorCode.MSG_PHONE_NOT_FOUND); | |||
| } | |||
| } | |||
| //保证手机号惟一 | |||
| String[] phoneSplit = phones.split(","); | |||
| Set<String> phoneSet=new HashSet<>(); | |||
| for(String phone:phoneSplit){ | |||
| Set<String> phoneSet = new HashSet<>(); | |||
| for (String phone : phoneSplit) { | |||
| phoneSet.add(phone); | |||
| } | |||
| wxMsg.setExpectSendNumber(phoneSet.size());//预计发送数量 | |||
| StringBuffer sb=new StringBuffer(); | |||
| for(String phone:phoneSet){ | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (String phone : phoneSet) { | |||
| sb.append(phone).append(","); | |||
| } | |||
| wxMsg.setPhones(sb.deleteCharAt(sb.length()-1).toString()); | |||
| wxMsg.setPhones(sb.deleteCharAt(sb.length() - 1).toString()); | |||
| //从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| @@ -94,16 +125,16 @@ public class WxMsgController extends BaseController { | |||
| if (wxMsgConfigs.size() == 0) return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND, "您还未接入短信运营商,请联系平台管理员"); | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| if(wxMsgConfig.getRemains()==0){ | |||
| if (wxMsgConfig.getRemains() == 0) { | |||
| logger.info("短信数量为0"); | |||
| return new ResultData(ErrorCode.MSG_SUM_ZERO); | |||
| } | |||
| if(wxMsgConfig.getRemains()<wxMsg.getExpectSendNumber()){ | |||
| if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||
| logger.info("短信数量不足"); | |||
| return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); | |||
| } | |||
| wxMsgService.saveOrUpdate(wxMsg,wxMsgConfig); | |||
| wxMsgService.saveOrUpdate(wxMsg, wxMsgConfig); | |||
| return new ResultData(); | |||
| } | |||
| @@ -114,11 +145,11 @@ public class WxMsgController extends BaseController { | |||
| for (int i = 0; i < arys.length; i++) { | |||
| tagids.add(Long.parseLong(arys[i])); | |||
| } | |||
| List<WxCUserBasicInfo> list = wxCUserTagsService.findByTag(tenantId,tagids); | |||
| List<WxCUserBasicInfo> list = wxCUserTagsService.findByTag(tenantId, tagids); | |||
| StringBuilder sb=new StringBuilder(); | |||
| if(list.size()>0){ | |||
| for(WxCUserBasicInfo cUserInfo:list){ | |||
| StringBuilder sb = new StringBuilder(); | |||
| if (list.size() > 0) { | |||
| for (WxCUserBasicInfo cUserInfo : list) { | |||
| sb.append(cUserInfo.getPhone()).append(","); | |||
| } | |||
| return sb.toString(); | |||
| @@ -130,33 +161,54 @@ public class WxMsgController extends BaseController { | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxMsg wxMsg) { | |||
| logger.debug("[" + getIpAddr() + "] WxMsgController::update"); | |||
| //不是草稿检验疲劳度 | |||
| if (!wxMsg.getStatus().equals(EnumMsgStatus.MSG_STATUS_DRAFT.getCode())) { | |||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | |||
| try { | |||
| pushLimitService.checkSendTime(getTenantId()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| } else { | |||
| PushLimit pushLimit = pushLimitService.getPushLimit(getTenantId()); | |||
| String sendtime = wxMsg.getSendtime(); | |||
| Date date = DateUtils.stringToDate(sendtime, "yyyy-MM-dd HH:mm:ss"); | |||
| boolean isInDate = DateUtils.isInDate(date, pushLimit.getTimeStart(), pushLimit.getTimeEnd()); | |||
| if (!isInDate) { | |||
| return new ResultData(ErrorCode.PUSH_LIMIT_NOT_INRANG); | |||
| } | |||
| } | |||
| } | |||
| //1、手机多条以逗号分隔,直接通过实体得到wxmsg.getphones | |||
| //2、通过标签 | |||
| String phones=wxMsg.getPhones(); | |||
| String phones = wxMsg.getPhones(); | |||
| String label = wxMsg.getLabel(); | |||
| if(!phones.equals("") && !label.equals("")){//两种方式只能选其一 | |||
| if (!phones.equals("") && !label.equals("")) {//两种方式只能选其一 | |||
| return new ResultData(ErrorCode.MSG_SEND_WAY_CHOOSE_ERROR); | |||
| } | |||
| if(phones.equals("")){//没有手工输入手机号时解析标签,有,继续流转 | |||
| phones=parselabel(wxMsg.getTenantId(), wxMsg); | |||
| if(phones.equals("")){//解析之后手机号依然不存在时返回 | |||
| if (phones.equals("")) {//没有手工输入手机号时解析标签,有,继续流转 | |||
| phones = parselabel(wxMsg.getTenantId(), wxMsg); | |||
| if (phones.equals("")) {//解析之后手机号依然不存在时返回 | |||
| return new ResultData(ErrorCode.MSG_PHONE_NOT_FOUND); | |||
| } | |||
| } | |||
| //保证手机号惟一 | |||
| String[] phoneSplit = phones.split(","); | |||
| Set<String> phoneSet=new HashSet<>(); | |||
| for(String phone:phoneSplit){ | |||
| Set<String> phoneSet = new HashSet<>(); | |||
| for (String phone : phoneSplit) { | |||
| phoneSet.add(phone); | |||
| } | |||
| wxMsg.setExpectSendNumber(phoneSet.size());//预计发送数量 | |||
| StringBuffer sb=new StringBuffer(); | |||
| for(String phone:phoneSet){ | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (String phone : phoneSet) { | |||
| sb.append(phone).append(","); | |||
| } | |||
| wxMsg.setPhones(sb.deleteCharAt(sb.length()-1).toString()); | |||
| wxMsg.setPhones(sb.deleteCharAt(sb.length() - 1).toString()); | |||
| //从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| @@ -165,12 +217,12 @@ public class WxMsgController extends BaseController { | |||
| if (wxMsgConfigs.size() == 0) return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND, "您还未接入短信运营商,请联系平台管理员"); | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| if(wxMsgConfig.getRemains()==0){ | |||
| if (wxMsgConfig.getRemains() == 0) { | |||
| logger.info("短信数量为0"); | |||
| return new ResultData(ErrorCode.MSG_SUM_ZERO); | |||
| } | |||
| if(wxMsgConfig.getRemains()<wxMsg.getExpectSendNumber()){ | |||
| if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||
| logger.info("短信数量不足"); | |||
| return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); | |||
| } | |||
| @@ -9,298 +9,312 @@ import java.util.List; | |||
| @Table(name = "wx_msg") | |||
| public class WxMsg implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> 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<String> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /*模板id**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="模板id",name="modelId") | |||
| private Long modelId; | |||
| /*内容**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="内容",name="msg") | |||
| private String msg; | |||
| /*发送时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送时间",name="sendtime") | |||
| private String sendtime; | |||
| /*发送时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送时间",name="createtime") | |||
| private Date createtime; | |||
| /*预计发送数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="预计发送数量",name="expectSendNumber") | |||
| private Integer expectSendNumber; | |||
| /*成功数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="成功数量",name="successNumber") | |||
| private Integer successNumber; | |||
| /*错误数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="错误数量",name="errorNumber") | |||
| private Integer errorNumber; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="returnResult") | |||
| private String returnResult; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="phones") | |||
| private String phones; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="signature") | |||
| private String signature; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="isright") | |||
| private Integer isright; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="name") | |||
| private String name; | |||
| /*发送状态0未发送 1已发送 2草稿箱**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="发送状态0失败1成功",name="sendstatus") | |||
| private Integer sendstatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="excelpath",name="excelpath") | |||
| private String excelpath; | |||
| @io.swagger.annotations.ApiModelProperty(value="标签人群",name="label") | |||
| private String label; | |||
| @io.swagger.annotations.ApiModelProperty(value="状态0未发送 1已发送 2草稿箱",name="status") | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value="1标签短信2精准投放",name="way") | |||
| private Integer way; | |||
| @io.swagger.annotations.ApiModelProperty(value="couponInjectId",name="couponInjectId") | |||
| private Long couponInjectId; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String _tenantId) { | |||
| tenantId = _tenantId; | |||
| } | |||
| public Long getModelId() { | |||
| return modelId; | |||
| } | |||
| public void setModelId(Long _modelId) { | |||
| modelId = _modelId; | |||
| } | |||
| public String getMsg() { | |||
| return msg; | |||
| } | |||
| public void setMsg(String _msg) { | |||
| msg = _msg; | |||
| } | |||
| public String getSendtime() { | |||
| return sendtime; | |||
| } | |||
| public void setSendtime(String _sendtime) { | |||
| sendtime = _sendtime; | |||
| } | |||
| public Date getCreatetime() { | |||
| return createtime; | |||
| } | |||
| public void setCreatetime(Date _createtime) { | |||
| createtime = _createtime; | |||
| } | |||
| public Integer getExpectSendNumber() { | |||
| return expectSendNumber; | |||
| } | |||
| public void setExpectSendNumber(Integer _expectSendNumber) { | |||
| expectSendNumber = _expectSendNumber; | |||
| } | |||
| public Integer getSuccessNumber() { | |||
| return successNumber; | |||
| } | |||
| public void setSuccessNumber(Integer _successNumber) { | |||
| successNumber = _successNumber; | |||
| } | |||
| public Integer getErrorNumber() { | |||
| return errorNumber; | |||
| } | |||
| public void setErrorNumber(Integer _errorNumber) { | |||
| errorNumber = _errorNumber; | |||
| } | |||
| public String getReturnResult() { | |||
| return returnResult; | |||
| } | |||
| public void setReturnResult(String _returnResult) { | |||
| returnResult = _returnResult; | |||
| } | |||
| public String getPhones() { | |||
| return phones; | |||
| } | |||
| public void setPhones(String _phones) { | |||
| phones = _phones; | |||
| } | |||
| public String getSignature() { | |||
| return signature; | |||
| } | |||
| public void setSignature(String _signature) { | |||
| signature = _signature; | |||
| } | |||
| public Integer getIsright() { | |||
| return isright; | |||
| } | |||
| public void setIsright(Integer _isright) { | |||
| isright = _isright; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String _name) { | |||
| name = _name; | |||
| } | |||
| public Integer getSendstatus() { | |||
| return sendstatus; | |||
| } | |||
| public void setSendstatus(Integer _sendstatus) { | |||
| sendstatus = _sendstatus; | |||
| } | |||
| public String getExcelpath() { | |||
| return excelpath; | |||
| } | |||
| public void setExcelpath(String excelpath) { | |||
| this.excelpath = excelpath; | |||
| } | |||
| public String getLabel() { | |||
| return label; | |||
| } | |||
| public void setLabel(String label) { | |||
| this.label = label; | |||
| } | |||
| public Integer getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(Integer status) { | |||
| this.status = status; | |||
| } | |||
| public Integer getWay() { | |||
| return way; | |||
| } | |||
| public void setWay(Integer way) { | |||
| this.way = way; | |||
| } | |||
| List<WxTags> tagsList; | |||
| public List<WxTags> getTagsList() { | |||
| return tagsList; | |||
| } | |||
| public void setTagsList(List<WxTags> tagsList) { | |||
| this.tagsList = tagsList; | |||
| } | |||
| public Long getCouponInjectId() { | |||
| return couponInjectId; | |||
| } | |||
| public void setCouponInjectId(Long couponInjectId) { | |||
| this.couponInjectId = couponInjectId; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | |||
| ,ModelId_ASC("`model_id` ASC"),ModelId_DESC("`model_id` DESC") | |||
| ,Msg_ASC("`msg` ASC"),Msg_DESC("`msg` DESC") | |||
| ,Sendtime_ASC("`sendtime` ASC"),Sendtime_DESC("`sendtime` DESC") | |||
| ,Createtime_ASC("`createtime` ASC"),Createtime_DESC("`createtime` DESC") | |||
| ,ExpectSendNumber_ASC("`expect_send_number` ASC"),ExpectSendNumber_DESC("`expect_send_number` DESC") | |||
| ,SuccessNumber_ASC("`success_number` ASC"),SuccessNumber_DESC("`success_number` DESC") | |||
| ,ErrorNumber_ASC("`error_number` ASC"),ErrorNumber_DESC("`error_number` DESC") | |||
| ,ReturnResult_ASC("`return_result` ASC"),ReturnResult_DESC("`return_result` DESC") | |||
| ,Phones_ASC("`phones` ASC"),Phones_DESC("`phones` DESC") | |||
| ,Signature_ASC("`signature` ASC"),Signature_DESC("`signature` DESC") | |||
| ,Isright_ASC("`isright` ASC"),Isright_DESC("`isright` DESC") | |||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||
| ,Sendstatus_ASC("`sendstatus` ASC"),Sendstatus_DESC("`sendstatus` 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(WxMsg.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()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| java.util.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)); | |||
| } | |||
| } | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") | |||
| private String tenantId; | |||
| /*模板id**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "模板id", name = "modelId") | |||
| private Long modelId; | |||
| /*内容**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "内容", name = "msg") | |||
| private String msg; | |||
| /*发送时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "发送时间", name = "sendtime") | |||
| private String sendtime; | |||
| /*发送时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "发送时间", name = "createtime") | |||
| private Date createtime; | |||
| /*预计发送数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "预计发送数量", name = "expectSendNumber") | |||
| private Integer expectSendNumber; | |||
| /*成功数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "成功数量", name = "successNumber") | |||
| private Integer successNumber; | |||
| /*错误数量**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "错误数量", name = "errorNumber") | |||
| private Integer errorNumber; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "returnResult") | |||
| private String returnResult; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "phones") | |||
| private String phones; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "signature") | |||
| private String signature; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "isright") | |||
| private Integer isright; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "name") | |||
| private String name; | |||
| /*发送状态0未发送 1已发送 2草稿箱**/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "发送状态0失败1成功", name = "sendstatus") | |||
| private Integer sendstatus; | |||
| @io.swagger.annotations.ApiModelProperty(value = "excelpath", name = "excelpath") | |||
| private String excelpath; | |||
| @io.swagger.annotations.ApiModelProperty(value = "标签人群", name = "label") | |||
| private String label; | |||
| @io.swagger.annotations.ApiModelProperty(value = "状态0未发送 1已发送 2草稿箱", name = "status") | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value = "1标签短信2精准投放", name = "way") | |||
| private Integer way; | |||
| @io.swagger.annotations.ApiModelProperty(value = "couponInjectId", name = "couponInjectId") | |||
| private Long couponInjectId; | |||
| @Transient | |||
| List<WxTags> tagsList; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String _tenantId) { | |||
| tenantId = _tenantId; | |||
| } | |||
| public Long getModelId() { | |||
| return modelId; | |||
| } | |||
| public void setModelId(Long _modelId) { | |||
| modelId = _modelId; | |||
| } | |||
| public String getMsg() { | |||
| return msg; | |||
| } | |||
| public void setMsg(String _msg) { | |||
| msg = _msg; | |||
| } | |||
| public String getSendtime() { | |||
| return sendtime; | |||
| } | |||
| public void setSendtime(String _sendtime) { | |||
| sendtime = _sendtime; | |||
| } | |||
| public Date getCreatetime() { | |||
| return createtime; | |||
| } | |||
| public void setCreatetime(Date _createtime) { | |||
| createtime = _createtime; | |||
| } | |||
| public Integer getExpectSendNumber() { | |||
| return expectSendNumber; | |||
| } | |||
| public void setExpectSendNumber(Integer _expectSendNumber) { | |||
| expectSendNumber = _expectSendNumber; | |||
| } | |||
| public Integer getSuccessNumber() { | |||
| return successNumber; | |||
| } | |||
| public void setSuccessNumber(Integer _successNumber) { | |||
| successNumber = _successNumber; | |||
| } | |||
| public Integer getErrorNumber() { | |||
| return errorNumber; | |||
| } | |||
| public void setErrorNumber(Integer _errorNumber) { | |||
| errorNumber = _errorNumber; | |||
| } | |||
| public String getReturnResult() { | |||
| return returnResult; | |||
| } | |||
| public void setReturnResult(String _returnResult) { | |||
| returnResult = _returnResult; | |||
| } | |||
| public String getPhones() { | |||
| return phones; | |||
| } | |||
| public void setPhones(String _phones) { | |||
| phones = _phones; | |||
| } | |||
| public String getSignature() { | |||
| return signature; | |||
| } | |||
| public void setSignature(String _signature) { | |||
| signature = _signature; | |||
| } | |||
| public Integer getIsright() { | |||
| return isright; | |||
| } | |||
| public void setIsright(Integer _isright) { | |||
| isright = _isright; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String _name) { | |||
| name = _name; | |||
| } | |||
| public Integer getSendstatus() { | |||
| return sendstatus; | |||
| } | |||
| public void setSendstatus(Integer _sendstatus) { | |||
| sendstatus = _sendstatus; | |||
| } | |||
| public String getExcelpath() { | |||
| return excelpath; | |||
| } | |||
| public void setExcelpath(String excelpath) { | |||
| this.excelpath = excelpath; | |||
| } | |||
| public String getLabel() { | |||
| return label; | |||
| } | |||
| public void setLabel(String label) { | |||
| this.label = label; | |||
| } | |||
| public Integer getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(Integer status) { | |||
| this.status = status; | |||
| } | |||
| public Integer getWay() { | |||
| return way; | |||
| } | |||
| public void setWay(Integer way) { | |||
| this.way = way; | |||
| } | |||
| public List<WxTags> getTagsList() { | |||
| return tagsList; | |||
| } | |||
| public void setTagsList(List<WxTags> tagsList) { | |||
| this.tagsList = tagsList; | |||
| } | |||
| public Long getCouponInjectId() { | |||
| return couponInjectId; | |||
| } | |||
| public void setCouponInjectId(Long couponInjectId) { | |||
| this.couponInjectId = couponInjectId; | |||
| } | |||
| public static enum Field { | |||
| Id_ASC("`id` ASC"), Id_DESC("`id` DESC"), TenantId_ASC("`tenant_id` ASC"), TenantId_DESC("`tenant_id` DESC"), ModelId_ASC("`model_id` ASC"), ModelId_DESC("`model_id` DESC"), Msg_ASC("`msg` ASC"), Msg_DESC("`msg` DESC"), Sendtime_ASC("`sendtime` ASC"), Sendtime_DESC("`sendtime` DESC"), Createtime_ASC("`createtime` ASC"), Createtime_DESC("`createtime` DESC"), ExpectSendNumber_ASC("`expect_send_number` ASC"), ExpectSendNumber_DESC("`expect_send_number` DESC"), SuccessNumber_ASC("`success_number` ASC"), SuccessNumber_DESC("`success_number` DESC"), ErrorNumber_ASC("`error_number` ASC"), ErrorNumber_DESC("`error_number` DESC"), ReturnResult_ASC("`return_result` ASC"), ReturnResult_DESC("`return_result` DESC"), Phones_ASC("`phones` ASC"), Phones_DESC("`phones` DESC"), Signature_ASC("`signature` ASC"), Signature_DESC("`signature` DESC"), Isright_ASC("`isright` ASC"), Isright_DESC("`isright` DESC"), Name_ASC("`name` ASC"), Name_DESC("`name` DESC"), Sendstatus_ASC("`sendstatus` ASC"), Sendstatus_DESC("`sendstatus` 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(WxMsg.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()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| java.util.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)); | |||
| } | |||
| } | |||
| } | |||
| @@ -15,9 +15,10 @@ import com.iformall.enums.EnumMsgSend; | |||
| import com.iformall.enums.EnumMsgSendStatus; | |||
| import com.iformall.enums.EnumMsgStatus; | |||
| import com.iformall.enums.EnumVerifyCode; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.PushLimitService; | |||
| import com.iformall.mapper.WxCUserBasicInfoMapper; | |||
| import com.iformall.mapper.WxMsgCallbackMapper; | |||
| import com.iformall.mapper.WxMsgConfigMapper; | |||
| import com.iformall.mapper.WxMsgMapper; | |||
| import com.iformall.service.WxCUserTagsService; | |||
| import com.iformall.service.WxMsgService; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -54,21 +55,18 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| @Autowired | |||
| WxMsgCallbackMapper wxMsgCallbackMapper; | |||
| @Autowired | |||
| PushLimitService pushLimitService; | |||
| @Override | |||
| public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | |||
| PageHelper.startPage(pageIndex, pageSize); | |||
| List<WxMsg> templist = wxMsgMapper.findList(record); | |||
| for(WxMsg temp:templist){ | |||
| Map<String,String> params=new HashMap<>(); | |||
| params.put("msgId",temp.getId().toString()); | |||
| params.put("status","1"); | |||
| int success=wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| params.put("status","0"); | |||
| int error=wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| for (WxMsg temp : templist) { | |||
| Map<String, String> params = new HashMap<>(); | |||
| params.put("msgId", temp.getId().toString()); | |||
| params.put("status", "1"); | |||
| int success = wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| params.put("status", "0"); | |||
| int error = wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| temp.setSuccessNumber(success); | |||
| temp.setErrorNumber(error); | |||
| } | |||
| @@ -81,12 +79,12 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| public WxMsg getById(Long id) { | |||
| WxMsg wxMsg = wxMsgMapper.selectByPrimaryKey(id); | |||
| Map<String,String> params=new HashMap<>(); | |||
| params.put("msgId",wxMsg.getId().toString()); | |||
| params.put("status","1"); | |||
| int success=wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| params.put("status","0"); | |||
| int error=wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| Map<String, String> params = new HashMap<>(); | |||
| params.put("msgId", wxMsg.getId().toString()); | |||
| params.put("status", "1"); | |||
| int success = wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| params.put("status", "0"); | |||
| int error = wxMsgCallbackMapper.queryMsgSendTotal(params); | |||
| wxMsg.setSuccessNumber(success); | |||
| wxMsg.setErrorNumber(error); | |||
| @@ -112,16 +110,10 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| //是否立即发送 | |||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | |||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | |||
| try { | |||
| pushLimitService.checkSendTime(wxMsg.getTenantId()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(),e.getMessage()); | |||
| } | |||
| if(wxMsg.getExpectSendNumber().intValue()>1000){ | |||
| batchSendMsg(wxMsg,wxMsgConfig,null); | |||
| }else{ | |||
| sendmsg(wxMsg,wxMsgConfig,null); | |||
| if (wxMsg.getExpectSendNumber().intValue() > 1000) { | |||
| batchSendMsg(wxMsg, wxMsgConfig, null); | |||
| } else { | |||
| sendmsg(wxMsg, wxMsgConfig, null); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "短信已发送"); | |||
| } else { | |||
| @@ -131,7 +123,7 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| wxMsg.setId(id); | |||
| wxMsg.setCreatetime(new Date()); | |||
| wxMsgMapper.insertSelective(wxMsg); | |||
| return new ResultData(Result.SUCCESS, "短信会在预设时间发送",id); | |||
| return new ResultData(Result.SUCCESS, "短信会在预设时间发送", id); | |||
| } | |||
| } else { | |||
| @@ -144,16 +136,10 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| //是否立即发送 | |||
| if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { | |||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | |||
| try { | |||
| pushLimitService.checkSendTime(wxMsg.getTenantId()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(),e.getMessage()); | |||
| } | |||
| if(wxMsg.getExpectSendNumber().intValue()>1000){ | |||
| batchSendMsg(wxMsg,wxMsgConfig,null); | |||
| }else{ | |||
| sendmsg(wxMsg,wxMsgConfig,null); | |||
| if (wxMsg.getExpectSendNumber().intValue() > 1000) { | |||
| batchSendMsg(wxMsg, wxMsgConfig, null); | |||
| } else { | |||
| sendmsg(wxMsg, wxMsgConfig, null); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "短信已发送"); | |||
| } else { | |||
| @@ -167,7 +153,6 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxMsgMapper.deleteByPrimaryKey(id); | |||
| @@ -176,37 +161,37 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| @Async | |||
| @Override | |||
| public void sendMsgFromCouponInject(WxMsg wxmsg, WxMsgConfig wxMsgConfig, WxCouponInject couponInject) { | |||
| batchSendMsg(wxmsg,wxMsgConfig,couponInject); | |||
| batchSendMsg(wxmsg, wxMsgConfig, couponInject); | |||
| } | |||
| public void batchSendMsg(WxMsg wxMsg,WxMsgConfig wxMsgConfig,WxCouponInject couponInject){ | |||
| public void batchSendMsg(WxMsg wxMsg, WxMsgConfig wxMsgConfig, WxCouponInject couponInject) { | |||
| String[] split = wxMsg.getPhones().split(","); | |||
| int length=split.length; | |||
| int length = split.length; | |||
| int extra = length % 1000; | |||
| int extracount = extra > 0 ? (length/1000+1) : (length/1000); | |||
| int index=extracount-1; | |||
| for(int i=0;i<extracount;i++){ | |||
| if(extra>0 && i==index){ | |||
| List<String> phoneList= Arrays.asList(split).subList(i* 1000, length); | |||
| int extracount = extra > 0 ? (length / 1000 + 1) : (length / 1000); | |||
| int index = extracount - 1; | |||
| for (int i = 0; i < extracount; i++) { | |||
| if (extra > 0 && i == index) { | |||
| List<String> phoneList = Arrays.asList(split).subList(i * 1000, length); | |||
| String phones = StringUtils.join(phoneList, ","); | |||
| wxMsg.setPhones(phones); | |||
| wxMsg.setExpectSendNumber(extra); | |||
| sendmsg(wxMsg,wxMsgConfig,couponInject); | |||
| }else{ | |||
| List<String> phoneList = Arrays.asList(split).subList(i * 1000, (i+1) * 1000); | |||
| sendmsg(wxMsg, wxMsgConfig, couponInject); | |||
| } else { | |||
| List<String> phoneList = Arrays.asList(split).subList(i * 1000, (i + 1) * 1000); | |||
| String phones = StringUtils.join(phoneList, ","); | |||
| wxMsg.setExpectSendNumber(1000); | |||
| wxMsg.setPhones(phones); | |||
| sendmsg(wxMsg,wxMsgConfig,couponInject); | |||
| sendmsg(wxMsg, wxMsgConfig, couponInject); | |||
| } | |||
| } | |||
| } | |||
| public ResultData sendmsg(WxMsg record,WxMsgConfig wxMsgConfig,WxCouponInject couponInject) { | |||
| public ResultData sendmsg(WxMsg record, WxMsgConfig wxMsgConfig, WxCouponInject couponInject) { | |||
| logger.info("发送短信开始..."); | |||
| logger.info("couponInject:"+couponInject); | |||
| logger.info("couponInject:" + couponInject); | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String publickey = wxMsgConfig.getPublickey(); | |||
| @@ -216,8 +201,8 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| String msg = record.getMsg(); | |||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| logger.info("=============迈外迪API开始调用"); | |||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl,EnumVerifyCode.NO.getCode().toString()); | |||
| logger.info("=============迈外迪API返回结果:"+result); | |||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString()); | |||
| logger.info("=============迈外迪API返回结果:" + result); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret = jsonObjectResult.get("ret").toString(); | |||
| String batchNo = jsonObjectResult.get("data").toString(); | |||
| @@ -247,30 +232,30 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| wxMsg.setId(id); | |||
| String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:mm:ss"); | |||
| wxMsg.setSendtime(systemTime); | |||
| wxMsg.setCreatetime(DateUtils.stringToDate(systemTime,"yyyy-MM-dd HH:mm:ss")); | |||
| wxMsg.setCreatetime(DateUtils.stringToDate(systemTime, "yyyy-MM-dd HH:mm:ss")); | |||
| //精准投放 | |||
| if(couponInject!=null){ | |||
| if (couponInject != null) { | |||
| wxMsg.setCouponInjectId(couponInject.getId()); | |||
| } | |||
| wxMsgMapper.insertSelective(wxMsg); | |||
| logger.info("发送短信结束..."); | |||
| if (ret.equals(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode().toString())) { | |||
| addMsgCallback(wxMsg,batchNo); | |||
| return new ResultData(Result.SUCCESS, "短信发送中,您可在短信明细中查看发送状态",id); | |||
| addMsgCallback(wxMsg, batchNo); | |||
| return new ResultData(Result.SUCCESS, "短信发送中,您可在短信明细中查看发送状态", id); | |||
| } else { | |||
| return new ResultData(ErrorCode.MSG_SEND_INTERFACE_ERROR.getCode(), | |||
| ErrorCode.MSG_SEND_INTERFACE_ERROR.getMessage()+":"+resultMsg); | |||
| ErrorCode.MSG_SEND_INTERFACE_ERROR.getMessage() + ":" + resultMsg); | |||
| } | |||
| } | |||
| public void addMsgCallback(WxMsg wxmsg, String batchNo){ | |||
| public void addMsgCallback(WxMsg wxmsg, String batchNo) { | |||
| logger.info("营销短信发送时主动添加回调记录开始..."); | |||
| String phones = wxmsg.getPhones(); | |||
| String[] split = phones.split(","); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| for(String phone:split){ | |||
| for (String phone : split) { | |||
| WxMsgCallback wxMsgCallback = new WxMsgCallback(); | |||
| wxMsgCallback.setId(idWorker.nextId()); | |||
| wxMsgCallback.setPhone(phone); | |||
| @@ -286,5 +271,4 @@ public class WxMsgServiceImpl implements WxMsgService { | |||
| } | |||
| } | |||