| @@ -88,6 +88,12 @@ public class WxMsgController extends BaseController { | |||
| return new ResultData(ErrorCode.PUSH_LIMIT_NOT_INRANG); | |||
| } | |||
| } | |||
| if(wxMsg.getId()!=null){ | |||
| //如果不是草稿必然之前状态是草稿,删除 | |||
| wxMsgService.deleteById(wxMsg.getId()); | |||
| } | |||
| } | |||
| wxMsg.setTenantId(getTenantId()); | |||
| //1、手机多条以逗号分隔,直接通过实体得到wxmsg.getphones | |||
| @@ -157,79 +163,6 @@ public class WxMsgController extends BaseController { | |||
| return ""; | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @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 label = wxMsg.getLabel(); | |||
| 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("")) {//解析之后手机号依然不存在时返回 | |||
| return new ResultData(ErrorCode.MSG_PHONE_NOT_FOUND); | |||
| } | |||
| } | |||
| //保证手机号惟一 | |||
| String[] phoneSplit = phones.split(","); | |||
| Set<String> phoneSet = new HashSet<>(); | |||
| for (String phone : phoneSplit) { | |||
| phoneSet.add(phone); | |||
| } | |||
| wxMsg.setExpectSendNumber(phoneSet.size());//预计发送数量 | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (String phone : phoneSet) { | |||
| sb.append(phone).append(","); | |||
| } | |||
| wxMsg.setPhones(sb.deleteCharAt(sb.length() - 1).toString()); | |||
| //从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(wxMsg.getTenantId()); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0) return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND, "您还未接入短信运营商,请联系平台管理员"); | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| if (wxMsgConfig.getRemains() == 0) { | |||
| logger.info("短信数量为0"); | |||
| return new ResultData(ErrorCode.MSG_SUM_ZERO); | |||
| } | |||
| if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||
| logger.info("短信数量不足"); | |||
| return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); | |||
| } | |||
| wxMsgService.saveOrUpdate(wxMsg, wxMsgConfig); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||