Sfoglia il codice sorgente

电量动态表,消息短信与公众号分开、1设备电量统计bug

missMyLove 3 anni fa
parent
commit
f0d526bcc9

+ 2 - 1
src/main/java/com/comtika/safe/controller/message/MessageController.java

@@ -38,8 +38,9 @@ public class MessageController extends BaseController {
     public RespWrapper<Boolean> fadMessageConfig(@RequestBody FadMessageConf help){
         // 处理一些数据
         if(help.getId() == null) return RespWrapper.makeFailResp("配置唯一id 不能为空");
-        if(help.getMainSwitch() == null) help.setMainSwitch(true);
+        if(help.getMainSwitch() == null) help.setMainSwitch(false);
         if(help.getOfflineSwitch() == null) help.setOfflineSwitch(false);
+        if(help.getWxSwitch() == null) help.setWxSwitch(true);
         return messageService.fadMessageConfig(help);
     }
     @PostMapping("checkPhoneCode/{phoneNo}/{code}")

+ 10 - 0
src/main/java/com/comtika/safe/controller/mobile/MobileController.java

@@ -30,6 +30,7 @@ public class MobileController extends BaseController {
     public RespWrapper<Map<String,Object>> findUserSiteEleTotal(@RequestBody EleTotalQueryHelp help){
         // 这里应该还有时间
         if(help.getStartTime() == null || help.getEndTime() == null) return RespWrapper.makeFailResp("查询时间不能为空");
+
         return iMobileService.findUserSiteEleTotal(help,findUserCache());
     }
     @ApiOperation(value = "查询各设备电量统计")
@@ -40,6 +41,7 @@ public class MobileController extends BaseController {
         if(help.getSiteId() == null) return RespWrapper.makeFailResp("站点id不能为空");
         return iMobileService.findTerminalEleTotal(help,findUserCache());
     }
+
     @ApiOperation(value = "查询各插座电量统计")
     @PostMapping("findSocketEleTotal")
     public RespWrapper<Map<String,Object>> findSocketEleTotal(@RequestBody EleTotalQueryHelp help){
@@ -47,6 +49,14 @@ public class MobileController extends BaseController {
         if(help.getTerminalId() == null) return RespWrapper.makeFailResp("设备id不能为空");
         return iMobileService.findSocketEleTotal(help);
     }
+
+    @ApiOperation(value = "查询设备列表电量统计曲线")
+    @PostMapping("findTerminalTotalList")
+    public RespWrapper findTerminalEleTotalList(@RequestBody EleTotalQueryHelp help){
+        if(help.getStartTime() == null || help.getEndTime() == null) return RespWrapper.makeFailResp("查询时间不能为空");
+        if(help.getTerminalId() == null) return RespWrapper.makeFailResp("设备id不能为空");
+        return iMobileService.findTerminalEleTotalList(help);
+    }
     @GetMapping("findTerminalDataTotal/{terminalNo}")
     public RespWrapper<Map<String,Object>> findTerminalDataTotal(@PathVariable("terminalNo")String terminalNo){
         return iMobileService.findTerminalDataTotal(terminalNo);

+ 3 - 0
src/main/java/com/comtika/safe/dao/message/FadMessageConfDao.java

@@ -35,4 +35,7 @@ public interface FadMessageConfDao extends BaseMapper<FadMessageConf> {
 
     @Sql(value = "select s.id,s.serial_no name from ctk_equip_socket s where s.equip_terminal_id = ?")
     List<CommonHelp> findTerSocketList(Integer terminalId);
+
+    @Sql(value = "select sum(t.start_ele) start_ele,sum(t.end_ele) end_ele,t.create_time from terminal_ele_total t where t.terminal_id = ? and t.create_time >= ? and t.create_time <= ? GROUP BY t.create_time ORDER BY t.create_time")
+    List<EleTotalHelp> findTerminalEleTotalList(Integer terminalId, Long startTime, long endTime);
 }

+ 1 - 0
src/main/java/com/comtika/safe/entity/message/FadMessageConf.java

@@ -13,6 +13,7 @@ public class FadMessageConf {
     private Integer id;
     private Integer siteId;//每一个站点都有消息配置
     private Boolean mainSwitch;//总开关
+    private Boolean wxSwitch;//微信消息推送开关
     private Boolean offlineSwitch;//掉线开关
 
 }

+ 1 - 0
src/main/java/com/comtika/safe/entity/mobile/EleTotalHelp.java

@@ -17,4 +17,5 @@ public class EleTotalHelp {
     private Integer terminalId;
     private String serialNo;
     private Integer socketId;
+    private Long createTime;
 }

+ 2 - 1
src/main/java/com/comtika/safe/service/message/impl/MessageServiceImpl.java

@@ -277,8 +277,9 @@ public class MessageServiceImpl implements IMessageService {
         if (conf == null) {
             conf = new FadMessageConf();
             conf.setSiteId(siteId);
-            conf.setMainSwitch(true);
+            conf.setMainSwitch(false);
             conf.setOfflineSwitch(false);
+            conf.setWxSwitch(true);
             fadMessageConfDao.insert(conf, true);
         }
         return conf;

+ 2 - 0
src/main/java/com/comtika/safe/service/mobile/IMobileService.java

@@ -22,4 +22,6 @@ public interface IMobileService {
     RespWrapper<Map<String, Object>> findTerminalDataTotal(String terminalNo);
 
     RespWrapper<TerminalNewestData> findTerminalNewDataInfo(Integer id);
+
+    RespWrapper findTerminalEleTotalList(EleTotalQueryHelp help);
 }

+ 25 - 8
src/main/java/com/comtika/safe/service/mobile/impl/MobileServiceImpl.java

@@ -13,10 +13,7 @@ import com.comtika.safe.service.mobile.IMobileService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -90,7 +87,7 @@ public class MobileServiceImpl implements IMobileService {
         List<CommonHelp> terList = fadMessageConfDao.findTerminalCommonList(siteId);
         List<Map<String,Object>> siteTotal = new ArrayList<>(terList.size());
         for(CommonHelp ch:terList){
-            Integer integer = terminalTotalMap.get(ch);
+            Integer integer = terminalTotalMap.get(ch.getId());
             int i = integer == null?0:integer;
             totalEle+=i;
             Map<String,Object> arg1 = new HashMap<>();
@@ -104,6 +101,7 @@ public class MobileServiceImpl implements IMobileService {
         return RespWrapper.makeSuccessResp(condition);
     }
 
+
     @Override
     public RespWrapper<Map<String, Object>> findSocketEleTotal(EleTotalQueryHelp help) {
         Map<String,Object> condition = new HashMap<>();
@@ -114,15 +112,15 @@ public class MobileServiceImpl implements IMobileService {
         }
 
         List<EleTotalHelp> sumTotalList = fadMessageConfDao.findSocketEleTotal(condition);
-        Map<Integer,Integer> socketListMap = new HashMap<>(sumTotalList.size());
+        Map<String,Integer> socketListMap = new HashMap<>(sumTotalList.size());
         sumTotalList.forEach(s->{
-            socketListMap.put(s.getSocketId(),calEle(s.getEndEle() , s.getStartEle()));
+            socketListMap.put(s.getSerialNo(),calEle(s.getEndEle() , s.getStartEle()));
         });
         int totalEle = 0;
         List<CommonHelp> socketList = fadMessageConfDao.findTerSocketList(help.getTerminalId());
         List<Map<String,Object>> siteTotal = new ArrayList<>(socketList.size());
         for(CommonHelp ch: socketList){
-            Integer integer = socketListMap.get(ch.getId());
+            Integer integer = socketListMap.get(ch.getName());
             int i = integer == null ? 0: integer;
             totalEle+=i;
             Map<String,Object> arg1 = new HashMap<>();
@@ -162,6 +160,25 @@ public class MobileServiceImpl implements IMobileService {
         return RespWrapper.makeSuccessResp(data);
     }
 
+    @Override
+    public RespWrapper findTerminalEleTotalList(EleTotalQueryHelp help) {
+        // 这里查询数据
+        List<EleTotalHelp> sumTotalList = fadMessageConfDao.findTerminalEleTotalList(help.getTerminalId(),help.getStartTime(),help.getEndTime()+DateTimeUtils.ONE_DAY);
+        Map<String,Integer> res = new HashMap<>();
+        sumTotalList.forEach(s->{
+            // 处理时间
+            if(s.getCreateTime() == null) return;
+            String key = DateTimeUtils.formatDate(new Date(s.getCreateTime()), DateTimeUtils.FORMAT_YMD);
+            int inc = calEle(s.getEndEle(), s.getStartEle());
+            if(res.containsKey(key)){
+                res.put(key,res.get(key)+inc);
+            }else {
+                res.put(key,inc);
+            }
+        });
+        return RespWrapper.makeSuccessResp(res);
+    }
+
     private int calEle(Integer end,Integer start){
         if(end == null) end = 0;
         if(start == null) start = 0;

+ 31 - 21
src/main/java/com/comtika/safe/service/safe/impl/RepServiceImpl.java

@@ -109,6 +109,9 @@ public class RepServiceImpl implements IRepService {
         }
         return base;
     }
+    private boolean isSendMsg(FadMessageConf conf){
+        return conf.getMainSwitch() || conf.getWxSwitch();
+    }
     // 设备断网断电消息推送
     @Override
     public void sendOffLineTerminalMessage(String terminalNo) {
@@ -121,16 +124,18 @@ public class RepServiceImpl implements IRepService {
             FadMessageConf conf = new FadMessageConf();
             conf.setSiteId(base.getSiteId());
             conf = fadMessageConfDao.templateOne(conf);
-            if(conf != null && conf.getMainSwitch() && conf.getOfflineSwitch()){
+            if(conf != null && conf.getMainSwitch() && isSendMsg(conf) && conf.getOfflineSwitch()){
                 long startTime = System.currentTimeMillis();
                 // todo 这里只发送了短信消息~ 后期需要增加公众号消息
                 log.error("发生断点断网告警通知....");
                 List<String> collect = messageList.stream().map(s -> s.getPhoneNo()).distinct().collect(Collectors.toList());
-                collect.forEach(s->{
-                    // 这个告警需要查询数据
-                    MessageUtils.sendSafeMessage(s,base.getSiteName(),terminalNo,startTime,"设备掉电或掉网");
-                });
-                if(!collect.isEmpty()){
+                if(conf.getMainSwitch()){
+                    collect.forEach(s->{
+                        // 这个告警需要查询数据
+                        MessageUtils.sendSafeMessage(s,base.getSiteName(),terminalNo,startTime,"设备掉电或掉网");
+                    });
+                }
+                if(conf.getWxSwitch() && !collect.isEmpty()){
                     // 发生公众号消息
                     Map<String,Object> condition = new HashMap<>(4);
                     condition.put("phoneList",collect);
@@ -259,25 +264,30 @@ public class RepServiceImpl implements IRepService {
         conf.setSiteId(res.getSiteId());
         conf = fadMessageConfDao.templateOne(conf);
         // 有配置文件,并且设置告警消息
-        if(conf != null && conf.getMainSwitch()){
+        if(conf != null && isSendMsg(conf) && conf.getMainSwitch()){
             log.error("推送告警数据....");
             // 这里说明需要发送消息
-            list.forEach(s->{
-                // 这个告警需要查询数据
-                MessageUtils.sendSafeMessage(s,res.getSiteName(),res.getTerminalNo(),res.getCreateTime(),content);
-            });
+            if(conf.getMainSwitch()){
+                list.forEach(s->{
+                    // 这个告警需要查询数据
+                    MessageUtils.sendSafeMessage(s,res.getSiteName(),res.getTerminalNo(),res.getCreateTime(),content);
+                });
+            }
             // 这里需要根据手机号码,查询已经授权的公众号
-            Map<String,Object> condition = new HashMap<>(4);
-            condition.put("phoneList",list);
-            List<String> openList = iNewestDataDao.findOpenList(condition);
-            if (!openList.isEmpty()) {
-                WarnMessageHelp help = new WarnMessageHelp();//这里推送告警消息
-                help.setTerminalNo(res.getTerminalNo());
-                help.setTerminalType(res.getTypeName());
-                help.setSiteName(res.getSiteName());
-                help.setWarnMsg(content);
-                wxChatUtil.sendWarnMessageToUser(help,openList,null);
+            if(conf.getWxSwitch()){
+                Map<String,Object> condition = new HashMap<>(4);
+                condition.put("phoneList",list);
+                List<String> openList = iNewestDataDao.findOpenList(condition);
+                if (!openList.isEmpty()) {
+                    WarnMessageHelp help = new WarnMessageHelp();//这里推送告警消息
+                    help.setTerminalNo(res.getTerminalNo());
+                    help.setTerminalType(res.getTypeName());
+                    help.setSiteName(res.getSiteName());
+                    help.setWarnMsg(content);
+                    wxChatUtil.sendWarnMessageToUser(help,openList,null);
+                }
             }
+
         }
     }