|
@@ -2,15 +2,14 @@ package com.zoniot.ccrc.scheduled;
|
|
|
|
|
|
|
|
|
|
|
|
-import com.zoniot.ccrc.dao.WarningLogMapper;
|
|
|
-import com.zoniot.ccrc.dao.WarningMessageMapper;
|
|
|
-import com.zoniot.ccrc.dao.WarningRuleMapper;
|
|
|
-import com.zoniot.ccrc.entity.WarningLog;
|
|
|
-import com.zoniot.ccrc.entity.WarningMessage;
|
|
|
-import com.zoniot.ccrc.entity.WarningRule;
|
|
|
+import com.zoniot.ccrc.commom.utils.SendWechatPush;
|
|
|
+import com.zoniot.ccrc.dao.*;
|
|
|
+import com.zoniot.ccrc.entity.*;
|
|
|
+import com.zoniot.ccrc.service.AccessTokenService;
|
|
|
import com.zoniot.ccrc.service.MongoMeterReadRecordService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -37,6 +36,20 @@ public class WarningMessageJob {
|
|
|
private WarningMessageMapper warningMessageMapper;
|
|
|
@Autowired
|
|
|
private MongoMeterReadRecordService mongoMeterReadRecordService;
|
|
|
+ @Resource
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
+ @Resource
|
|
|
+ private GridManagementMapper gridManagementMapper;
|
|
|
+ @Autowired
|
|
|
+ private AccessTokenService accessTokenService;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Value("${wechat.oa.appid}")
|
|
|
+ private String oaAppid;
|
|
|
+
|
|
|
+ @Value("${wechat.mp.appid}")
|
|
|
+ private String mpAppid;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -50,7 +63,9 @@ public class WarningMessageJob {
|
|
|
for (WarningRule warningRule : list) {
|
|
|
Boolean flag = mongoMeterReadRecordService.complyWithWarningRules(warningRule.getDeviceId(),warningRule.getWarningType());
|
|
|
if ( flag) {
|
|
|
- addMessageInfo(warningRule,"单日用水量超过2吨");
|
|
|
+ String content = "单日用水量超过2吨";
|
|
|
+ addMessageInfo(warningRule,content);
|
|
|
+ sendWechatMessage(warningRule.getDeviceId(),content);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -83,4 +98,30 @@ public class WarningMessageJob {
|
|
|
warningMessageNew.setDateUpdate(LocalDateTime.now());
|
|
|
warningMessageMapper.insertSelective(warningMessageNew);
|
|
|
}
|
|
|
+
|
|
|
+ private void sendWechatMessage(Long deviceId,String content){
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String url = "https://www.zoniot.com";
|
|
|
+ String pagepath = "pages/index/index";
|
|
|
+ Device device = deviceMapper.findByDeviceId(deviceId);
|
|
|
+
|
|
|
+ String accessToken = accessTokenService.getMpAccessToken();
|
|
|
+
|
|
|
+ List<GridManagement> gridManagementList = gridManagementMapper.getByDeviceId(deviceId);
|
|
|
+ if (gridManagementList != null && gridManagementList.size() > 0) {
|
|
|
+ for (GridManagement gridManagement : gridManagementList) {
|
|
|
+ User user = userMapper.findUserById(gridManagement.getUserId());
|
|
|
+
|
|
|
+ if(user != null && user.getOpenid() !=null && !"".equals(user.getOpenid())){
|
|
|
+
|
|
|
+ String result = SendWechatPush.sendAbnormalNotice(accessToken, oaAppid, user.getOpenid(), url, mpAppid, pagepath, "用户用水异常", "水量预警", content,
|
|
|
+ LocalDateTime.now().format(df), device.getMeterNo()+gridManagement.getCustomerName()+gridManagement.getCustomerPhone()+device.getLocDesc()+"用水量有异常情况,请及时关注用户情况!");
|
|
|
+ log.info("sendWechatMessage :"+result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|