xiao547607 5 年之前
父节点
当前提交
a28f638bc0

+ 20 - 5
src/main/java/com/jpsoft/smart/modules/base/controller/AlarmInfoController.java

@@ -6,6 +6,7 @@ import com.jpsoft.smart.modules.base.service.AlarmInfoService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
+import com.jpsoft.smart.modules.common.utils.WechatMessageUtil;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -33,10 +34,14 @@ public class AlarmInfoController {
             alarmInfo.setDelFlag(false);
             //alarmInfo.setCreateBy(subject);
             alarmInfo.setIsRead(false);
+            //2019-12-07 11:04:04.322  INFO 11000 --- [nio-8080-exec-5] c.j.s.m.b.c.AlarmInfoController          : 周界入侵,目标ID:13974,区域范围:(0.327,0.698)(0.674,0.936)(0.67,0.985)(0.352,0.973)
+            int index = message.indexOf("周界入侵");
+            if(index > 0){
+                message = message.substring(index,message.length());
+            }
             alarmInfo.setMessage(message);
             alarmInfo.setType("2");
             alarmInfo.setCreateTime(new Date());
-
             int affectCount = alarmInfoService.insert(alarmInfo);
 
             if (affectCount > 0) {
@@ -239,7 +244,7 @@ public class AlarmInfoController {
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("id_","asc"));
+        sortList.add(new Sort("create_time","desc"));
 
         if (StringUtils.isNotEmpty(id)) {
             searchParams.put("id","%" + id + "%");
@@ -276,9 +281,19 @@ public class AlarmInfoController {
             msgResult.setResult(true);
             msgResult.setData(alarmInfo.getMessage());
 
-            //修改阅读状态
-            alarmInfo.setIsRead(true);
-            alarmInfoService.update(alarmInfo);
+            String content = alarmInfo.getMessage();
+            int index = content.lastIndexOf(":");
+            if(index > 0){
+                content = content.substring(index+1,content.length());
+            }
+            //发送通知
+            String openId = "oHjCawgwCGen5k1-hAsimdEX5lZo";
+            boolean result = WechatMessageUtil.sendAlarmNoticeMessage("周界入侵警报", content, openId, "","8dpP8XM1XaiiIByXiuAeFIZeNjEow1AleG_h8O2xyVA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
+            if(result) {
+                //修改阅读状态
+                alarmInfo.setIsRead(true);
+                alarmInfoService.update(alarmInfo);
+            }
         }
         return msgResult;
     }

+ 94 - 4
src/main/java/com/jpsoft/smart/modules/common/utils/WechatMessageUtil.java

@@ -223,6 +223,95 @@ public class WechatMessageUtil {
 				
 		return ret;
 	}
+
+	/**
+	 * 发送物业管理通知信息
+	 * @param noticeName 通知名称
+	 * @param noticeDetailId 通知详情ID
+	 * @param openId 发送人
+	 * @return
+	 */
+	public static boolean sendPropertyNoticeMessage(String noticeName,String content,String openId,String noticeDetailId,String noticeTemplateId,String appId,String appSecret) {
+
+
+		JSONObject sendData = new JSONObject();
+		String finallyContent = getContent(content);
+		JSONObject first = new JSONObject();
+		first.put("value", "您好,物业管理通知如下:");
+		first.put("color", "#173177");
+
+		JSONObject keyword1 = new JSONObject();
+		keyword1.put("value", noticeName);
+		keyword1.put("color", "#173177");
+
+
+
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+		JSONObject keyword2 = new JSONObject();
+		keyword2.put("value", sdf.format(new Date()));
+		keyword2.put("color", "#173177");
+
+		JSONObject keyword3 = new JSONObject();
+		keyword3.put("value", finallyContent);
+		keyword3.put("color", "#173177");
+
+		JSONObject remark = new JSONObject();
+		remark.put("value", "点击查看详情");
+		remark.put("color", "#173177");
+
+		sendData.put("first", first);
+		sendData.put("keyword1", keyword1);
+		sendData.put("keyword2", keyword2);
+		sendData.put("keyword3", keyword3);
+		sendData.put("remark", remark);
+
+		//noticeDetailId
+		boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, TEMPLATE_REDIRECT_PRE_URL + "/#/noticeInfo/" + noticeDetailId);
+
+		return ret;
+	}
+
+	/**
+	 * 发送警告通知信息
+	 * @param noticeName 通知名称
+	 * @param noticeDetailId 通知详情ID
+	 * @param openId 发送人
+	 * @return
+	 */
+	public static boolean sendAlarmNoticeMessage(String noticeName,String content,String openId,String noticeDetailId,String noticeTemplateId,String appId,String appSecret) {
+
+
+		JSONObject sendData = new JSONObject();
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		String finallyContent = getContent(content);
+		JSONObject first = new JSONObject();
+		first.put("value", "您好,入侵警告通知如下:");
+		first.put("color", "#173177");
+
+		JSONObject keyword1 = new JSONObject();
+		keyword1.put("value", sdf.format(new Date()));
+		keyword1.put("color", "#173177");
+
+
+		JSONObject keyword2 = new JSONObject();
+		keyword2.put("value", finallyContent);
+		keyword2.put("color", "#173177");
+
+		JSONObject remark = new JSONObject();
+		remark.put("value", "请尽快查看");
+		remark.put("color", "#173177");
+
+		sendData.put("first", first);
+		sendData.put("keyword1", keyword1);
+		sendData.put("keyword2", keyword2);
+		//sendData.put("remark", remark);
+
+		//noticeDetailId
+		boolean ret = sendTemplate(sendData,appId,appSecret,noticeTemplateId ,openId, "");
+
+		return ret;
+	}
 	
 	/**
 	 * 微信发送模版
@@ -295,17 +384,18 @@ public class WechatMessageUtil {
 		}*/
 		
 		//orderConfirmMessage("12312321312", 1111, DEFAULT_OPEN_ID);
-		//sendBillInfo("测试", "测试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "1111", new Date());
+		//sendBillInfo("测试", "测sendNoticeMessage试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "1111", new Date());
 		//sendBillPayedMessage("测试", "荆鹏创业", "张三", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
 		//sendScanPayedMessage("测试", "荆鹏创业", "张三11111", new BigDecimal(1), "o64fbt6TTUcqLC_tyVJ60I5kzWVc", "11111", new Date());
-	/*	sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oOlFd1BUR6Fi2ayBWUeou81G8ZD4", "2222","9JKu9t9uTPHL1siIm7WatOJ1KXGolzEPlnmqIbckTUM","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");
-*/
+//sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oHjCawgwCGen5k1-hAsimdEX5lZo", "2222","9JKu9t9uTPHL1siIm7WatOJ1KXGolzEPlnmqIbckTUM","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");
+
 	/*	sendBillInfo("1栋-1单元-101",new BigDecimal("0.01"),"oOlFd1BUR6Fi2ayBWUeou81G8ZD4",
 				"物业费","小鹏物业","测试","9e52c923-2179-4526-a108-32becc9aa1d0","vVraOPl4OyNVWDGz6XYlJqRb7qGjjcyJdnVi5HWmFRI","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");*/
 
 		/*sendBillPayedMessage("1栋-1单元-101","物业费",new Date(),new BigDecimal("0.01"),"oOlFd1BUR6Fi2ayBWUeou81G8ZD4","33e7e5e6-5b38-45f5-9ccf-c7ef21978a5b","kbx5u70nzo7PklTVl4B1xvRffksrUtXxnDll8ggEKlo","wx41ac6791b9dbcf52","3e3d47c5f132d4b47636a536d503fbd4");*/
 
-
+		//sendAlarmNoticeMessage("周界入侵警报", "周界入侵,目标ID:1419,区域范围:(0.327,0.698)(0.674,0.936)(0.67,0.985)(0.352,0.973)", "oHjCawgwCGen5k1-hAsimdEX5lZo", "","8dpP8XM1XaiiIByXiuAeFIZeNjEow1AleG_h8O2xyVA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
+		//sendNoticeMessage("测试", "sdfsdfasfasdfafasdfasdf", "oHjCawgwCGen5k1-hAsimdEX5lZo", "2222","vsw6sb9lMA3bcsE8MdeaGENvI1HSUy2ht9B8hS3jEzA","wx7e70eb62a8459869","909d17e353268da57c4f18cc09798049");
 		getContent("<p>内容</p>");
 
 	}