/** * 修改短信 * * @return */ @RequestMapping("/user/updateUserMsg") @ResponseBody public Map<String, Object> updateUserMsg(HttpServletRequest request) { try { UserMobileMsg userMobileMsg = new UserMobileMsg(); userMobileMsg.setId(Integer.parseInt(request.getParameter("msgId"))); userMobileMsg.setContent(request.getParameter("content")); DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); userMobileMsg.setSendTime(df.parse(request.getParameter("sendTime"))); userMobileMsgService.updateUserMobileMsg(userMobileMsg); this.setJson(true, "修改成功", null); } catch (Exception e) { logger.error("updateUserMsg", e); this.setJson(false, "修改失败", null); } return json; }
/** * 发送短信 * * @param request * @return */ @RequestMapping("/user/sendMsg") @ResponseBody public Map<String, Object> sendMobileMsg(HttpServletRequest request) { try { List<UserMobileMsg> msgList = new ArrayList<UserMobileMsg>(); String linksman = request.getParameter("linksman"); // 获取联系人 String content = request.getParameter("content"); // 获取内容 Integer type = Integer.parseInt(request.getParameter("sendType")); // 发送方式 Date now = new Date(); Date sendTime = now; if (type == 2) { // 定时发送 if (StringUtils.isEmpty(request.getParameter("sendTime"))) { this.setJson(false, "定时发送时间不能为空", ""); return json; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); sendTime = df.parse(request.getParameter("sendTime")); // 定时发送时间 } if (StringUtils.isNotEmpty(linksman) && StringUtils.isNotEmpty(content)) { // 验证手机 Map<String, Object> returnMap = checkMobile(linksman); // 错误信息 String errorMobile = returnMap.get("errorMobile").toString(); if (Boolean.parseBoolean(returnMap.get("flag").toString()) == false) { this.setJson(false, errorMobile, ""); return json; } else { // 添加发送记录 JsonObject user = SingletonLoginUtils.getSysUser(request); UserMobileMsg userMobileMsg = new UserMobileMsg(); userMobileMsg.setSendTime(sendTime); if (type == 1) { // 正常发送 userMobileMsg.setStatus(1); } else { // 定时发送 userMobileMsg.setStatus(2); } userMobileMsg.setId(0); userMobileMsg.setType(type); userMobileMsg.setContent(content); userMobileMsg.setMobile(returnMap.get("mobileList").toString()); if (ObjectUtils.isNotNull(user)) { userMobileMsg.setUserId(user.get("userId").getAsLong()); } else { userMobileMsg.setUserId(0L); } userMobileMsg.setCreateTime(now); msgList.add(userMobileMsg); // 添加记录 暂不发送 userMobileMsgService.addUserMobileMsg(msgList); if (type == 1) { // 正常发送 userMobileMsgService.batchSendMobileMsg( content, returnMap.get("mobileList").toString().split(","), 3); } errorMobile = "发送成功"; } this.setJson(Boolean.parseBoolean(returnMap.get("flag").toString()), errorMobile, ""); } else { this.setJson(false, "联系人或内容不能为空", null); } } catch (Exception e) { logger.error("sendMobileMsg", e); } return json; }