完成短信/站内信推送
parent
d04a9074b3
commit
73500df19d
|
@ -446,7 +446,7 @@ public class AppSafetyEnvironmentalController extends BaseController {
|
||||||
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
|
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
|
||||||
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
|
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
|
||||||
pd.put("waffle", pd.getString("ARCHIVE_USER_ID"));
|
pd.put("waffle", pd.getString("ARCHIVE_USER_ID"));
|
||||||
pd.put("loginUserId", Jurisdiction.getUSER_ID());
|
pd.put("loginUserId", pd.getString("ARCHIVE_USER_ID"));
|
||||||
page.setPd(pd);
|
page.setPd(pd);
|
||||||
List<PageData> varList = safetyenvironmentalService.checkList(page); //列出SafetyEnvironmental列表
|
List<PageData> varList = safetyenvironmentalService.checkList(page); //列出SafetyEnvironmental列表
|
||||||
/* 针对验收部分特殊处理 */
|
/* 针对验收部分特殊处理 */
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.zcloud.entity.messages;
|
package com.zcloud.entity.messages;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
import org.hibernate.validator.constraints.Range;
|
import org.hibernate.validator.constraints.Range;
|
||||||
|
@ -7,6 +9,7 @@ import org.hibernate.validator.constraints.Range;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class PushRecords implements Serializable {
|
public class PushRecords implements Serializable {
|
||||||
|
@ -22,9 +25,8 @@ public class PushRecords implements Serializable {
|
||||||
@Length(max = 255, message = "消息标题长度不能大于255")
|
@Length(max = 255, message = "消息标题长度不能大于255")
|
||||||
private String messageTitle;
|
private String messageTitle;
|
||||||
|
|
||||||
@NotBlank(message = "消息内容不能为空")
|
@NotNull(message = "消息内容不能为空")
|
||||||
@Length(max = 255, message = "消息内容长度不能大于255")
|
private Map<String,Object> messageContent;
|
||||||
private String messageContent;
|
|
||||||
|
|
||||||
@NotNull(message = "消息类型不能为空")
|
@NotNull(message = "消息类型不能为空")
|
||||||
@Range(min = 1, max = 3, message = "消息类型只能是1或2或3")
|
@Range(min = 1, max = 3, message = "消息类型只能是1或2或3")
|
||||||
|
@ -34,4 +36,18 @@ public class PushRecords implements Serializable {
|
||||||
private String sendTime;
|
private String sendTime;
|
||||||
|
|
||||||
private Integer state;
|
private Integer state;
|
||||||
|
|
||||||
|
@NotBlank(message = "消息模版id不能为空")
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
public String getMessageContent() {
|
||||||
|
if (CollUtil.isEmpty(messageContent)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(messageContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String,Object> getMessageContentMap() {
|
||||||
|
return messageContent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.zcloud.entity.messages.PushRecords;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
public interface MessagesMapper {
|
public interface MessagesMapper {
|
||||||
|
|
||||||
void install(PushRecords pushRecords);
|
void install(PushRecords pushRecords);
|
||||||
|
|
||||||
String findUserIdByPhone(@Param("phone") String phone);
|
String findUserIdByPhone(@Param("phone") String phone);
|
||||||
|
|
|
@ -21,14 +21,14 @@ public class InsideMessagesImpl implements PushMessages {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void push(PushRecords pushRecords, String userId) throws Exception {
|
public void push(PushRecords pushRecords, String userId) throws Exception {
|
||||||
PageData mes = new PageData();
|
PageData mes = new PageData();
|
||||||
mes.put("BIANMA", "PUSH_RECORDS");
|
mes.put("BIANMA", pushRecords.getMessageTitle());
|
||||||
mes.put("SENDER_ID", "九公司应急管理");
|
mes.put("SENDER_ID", "九公司应急管理");
|
||||||
mes.put("SENDER_NAME", "九公司应急管理");
|
mes.put("SENDER_NAME", "九公司应急管理");
|
||||||
mes.put("SYNOPSIS", pushRecords.getMessageTitle());
|
mes.put("SYNOPSIS", pushRecords.getMessageTitle());
|
||||||
mes.put("CORPINFO_ID", "48a8ca9815814c979814ddcf041c5cd5");
|
mes.put("CORPINFO_ID", "48a8ca9815814c979814ddcf041c5cd5");
|
||||||
mes.put("RECEIVER_ID", userId);
|
mes.put("RECEIVER_ID", userId);
|
||||||
PageData content = new PageData();
|
PageData content = new PageData();
|
||||||
content.put("msg", pushRecords.getMessageContent());
|
content.putAll(pushRecords.getMessageContentMap());
|
||||||
mes.put("CONTENT", content);// 站内信内容
|
mes.put("CONTENT", content);// 站内信内容
|
||||||
noticeCorpService.sendNotice(mes);
|
noticeCorpService.sendNotice(mes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,34 @@
|
||||||
package com.zcloud.service.messages.impl;
|
package com.zcloud.service.messages.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.zcloud.entity.PageData;
|
||||||
import com.zcloud.entity.messages.PushRecords;
|
import com.zcloud.entity.messages.PushRecords;
|
||||||
|
import com.zcloud.service.bus.NoticeTemplateService;
|
||||||
import com.zcloud.service.messages.PushMessages;
|
import com.zcloud.service.messages.PushMessages;
|
||||||
import com.zcloud.util.SendSmsUtil;
|
import com.zcloud.util.SendSmsUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送短信
|
* 发送短信
|
||||||
*/
|
*/
|
||||||
@Component("messages1")
|
@Component("messages1")
|
||||||
@AllArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SmsMessagesImpl implements PushMessages {
|
public class SmsMessagesImpl implements PushMessages {
|
||||||
|
|
||||||
|
private final NoticeTemplateService noticeTemplateService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(PushRecords pushRecords, String userId) throws ParseException {
|
public void push(PushRecords pushRecords, String userId) throws ParseException {
|
||||||
JSONObject object = new JSONObject();
|
PageData pageData = noticeTemplateService.findByBianMa(pushRecords.getTemplateId());
|
||||||
object.put("messageContent", pushRecords.getMessageContent());
|
if (CollUtil.isEmpty(pageData)) {
|
||||||
// todo 应该是短信模版tpId 没有 别的OK了
|
throw new RuntimeException("模板未配置");
|
||||||
if (!SendSmsUtil.sendSms(null, object, pushRecords.getSendTime(), pushRecords.getPhone())) {
|
}
|
||||||
|
Map<String, Object> content = pushRecords.getMessageContentMap();
|
||||||
|
if (!SendSmsUtil.customizeSMSSending(pushRecords.getPhone(), pageData.getString("CONTENT"), content)) {
|
||||||
throw new RuntimeException("系统故障:短信发送失败");
|
throw new RuntimeException("系统故障:短信发送失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.zcloud.util;
|
package com.zcloud.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpResponse;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
@ -14,6 +17,8 @@ import org.springframework.http.MediaType;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重点工程发送短信工具类
|
* 重点工程发送短信工具类
|
||||||
|
@ -77,30 +82,29 @@ public class SendSmsUtil {
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// {"msg":"template error","tpId":"null","code":4014,"msgId":"172950016144709288961"}
|
public static boolean customizeSMSSending(String mobile, String template, Map<String, Object> content) {
|
||||||
// {"msg":"success","tpId":"121487","code":200,"msgId":"172950025828957168641","invalidList":[]}
|
String value = SIGNATURE + template;
|
||||||
public static boolean sendSms(String tpId, JSONObject records, String time, String phone) throws ParseException {
|
for (String key : content.keySet()) {
|
||||||
|
value = StrUtil.replace(value, "${" + key + "}", Convert.toStr(content.get(key)));
|
||||||
|
}
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("username", USERNAME);
|
json.put("username", USERNAME);
|
||||||
json.put("tKey", System.currentTimeMillis() / 1000);
|
json.put("tKey", System.currentTimeMillis() / 1000);
|
||||||
json.put("password", MD5.md5(PASSWORD + json.getLong("tKey")));
|
json.put("password", MD5.md5(PASSWORD + json.getLong("tKey")));
|
||||||
json.put("signature", SIGNATURE);
|
json.put("mobile", mobile);
|
||||||
json.put("tpId", tpId);
|
json.put("content", value);
|
||||||
if (StringUtils.isNotBlank(time) && DateUtil.parseDateTime(time).after(new Date())) {
|
HttpRequest request = HttpRequest.post("https://api-bj-shss01-mix2.zthysms.com/v2/sendSms");
|
||||||
json.put("time", time);
|
request.body(json.toJSONString(), MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
}
|
request.timeout(60000);
|
||||||
JSONArray array = new JSONArray();
|
String body;
|
||||||
array.add(getRecords(phone, records));
|
|
||||||
json.put("records", array);
|
|
||||||
HttpRequest request = HttpRequest.post(URL)
|
|
||||||
.timeout(60000)
|
|
||||||
.body(json.toJSONString(), MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
||||||
try (HttpResponse response = request.execute()) {
|
try (HttpResponse response = request.execute()) {
|
||||||
return JSON.parseObject(response.body()).getInteger("code") == 200;
|
body = response.body();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送短信异常", e);
|
log.error("短信发送异常", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
JSONObject object = JSON.parseObject(body);
|
||||||
|
return object == null || object.getInteger("code") == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,12 +133,44 @@ public class SendSmsUtil {
|
||||||
}//d22f8a5d4a35b3761dc9525186e652a0
|
}//d22f8a5d4a35b3761dc9525186e652a0
|
||||||
|
|
||||||
//测试接口
|
//测试接口
|
||||||
// public static void main(String[] args) throws ParseException {
|
public static void main(String[] args) throws ParseException {
|
||||||
|
//定义替换参数
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("acci_date", DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN));
|
||||||
|
map.put("acci_addr", "xx省xx市xxx");
|
||||||
|
map.put("acci_type", "测试类型");
|
||||||
|
map.put("inju_member", "0");
|
||||||
|
map.put("task_post", "测试");
|
||||||
|
String value = SIGNATURE + "安全事故通知:${acci_date},在${acci_addr}发生了${acci_type}的安全事故,有${inju_member}的伤亡人数,您的职责是:${task_post}";
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
value = StrUtil.replace(value, "${" + key + "}", Convert.toStr(map.get(key)));
|
||||||
|
}
|
||||||
|
if (value.length() >= 1000) {
|
||||||
|
throw new RuntimeException("短信内容,最多支持1000个字符");
|
||||||
|
}
|
||||||
|
Long tKey = System.currentTimeMillis() / 1000;
|
||||||
|
String passWord = MD5.md5(PASSWORD + tKey);
|
||||||
|
JSONObject map2 = new JSONObject();
|
||||||
|
map2.put("username", USERNAME);
|
||||||
|
map2.put("tKey", tKey);
|
||||||
|
map2.put("password", passWord);
|
||||||
|
map2.put("mobile", "18630387571");
|
||||||
|
map2.put("content", value);
|
||||||
|
HttpRequest request = HttpRequest.post("https://api-bj-shss01-mix2.zthysms.com/v2/sendSms");
|
||||||
|
request.body(map2.toJSONString(), MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
|
System.out.println(map2.toJSONString());
|
||||||
|
request.timeout(60000);
|
||||||
|
String s = request.execute().body();
|
||||||
|
System.out.println(s);
|
||||||
|
// JSONArray jsonArray = new JSONArray();
|
||||||
|
// //接受返回结果
|
||||||
|
// JSONObject records = new JSONObject();
|
||||||
// //定义替换参数
|
// //定义替换参数
|
||||||
// JSONObject tpContent = new JSONObject();
|
// JSONObject tpContent = new JSONObject();
|
||||||
// tpContent.put("HIDDENDESCR", "卓云企业测试");
|
// tpContent.put("OUTSOURCEDNAME","测试");
|
||||||
// JSONObject object = sendSms("121487", tpContent, DateUtil.formatDateTime(new Date()), "18630387571");
|
// records = SendSmsUtil.getRecords("18630387571",tpContent);
|
||||||
// System.out.println(object.toJSONString());
|
// jsonArray.add(records);
|
||||||
// }
|
// SendSmsUtil.sendSms("121451",jsonArray,null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,6 +311,12 @@
|
||||||
<if test="pd.INSPECTION_CASE != null and pd.INSPECTION_CASE != ''"><!-- 检查发起人 -->
|
<if test="pd.INSPECTION_CASE != null and pd.INSPECTION_CASE != ''"><!-- 检查发起人 -->
|
||||||
and biss.SITUATION LIKE CONCAT('%', #{pd.INSPECTION_CASE},'%')
|
and biss.SITUATION LIKE CONCAT('%', #{pd.INSPECTION_CASE},'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="pd.INSPECTION_USER_NAME != null and pd.INSPECTION_USER_NAME != ''"><!-- 检查人员 -->
|
||||||
|
and siu.NAME LIKE CONCAT('%', #{pd.INSPECTION_USER_NAME},'%')
|
||||||
|
</if>
|
||||||
|
<if test="pd.INSPECTION_USER_PHONE != null and pd.INSPECTION_USER_PHONE != ''"><!-- 检查人手机 -->
|
||||||
|
and siu.PHONE LIKE CONCAT('%', #{pd.INSPECTION_USER_PHONE},'%')
|
||||||
|
</if>
|
||||||
<if test="pd.INSPECTION_TYPE != null and pd.INSPECTION_TYPE != ''"><!-- 检查类型 -->
|
<if test="pd.INSPECTION_TYPE != null and pd.INSPECTION_TYPE != ''"><!-- 检查类型 -->
|
||||||
and f.INSPECTION_TYPE = #{pd.INSPECTION_TYPE}
|
and f.INSPECTION_TYPE = #{pd.INSPECTION_TYPE}
|
||||||
</if>
|
</if>
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
<if test="state != null">
|
<if test="state != null">
|
||||||
STATE,
|
STATE,
|
||||||
</if>
|
</if>
|
||||||
|
<if test="templateId != null and templateId != ''">
|
||||||
|
TEMPLATE_ID,
|
||||||
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
values
|
values
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
@ -50,6 +53,9 @@
|
||||||
<if test="state != null">
|
<if test="state != null">
|
||||||
#{state},
|
#{state},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="templateId != null and templateId != ''">
|
||||||
|
#{templateId},
|
||||||
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -78,6 +84,9 @@
|
||||||
<if test="state != null">
|
<if test="state != null">
|
||||||
STATE = #{state},
|
STATE = #{state},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="templateId != null and templateId != ''">
|
||||||
|
TEMPLATE_ID = #{templateId},
|
||||||
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where ID = #{id}
|
where ID = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
Loading…
Reference in New Issue