missMyLove 3 éve
szülő
commit
48dd266cee

+ 4 - 0
src/main/java/com/comtika/safe/core/task/WarnHandleTask.java

@@ -12,6 +12,7 @@ import javax.annotation.PreDestroy;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -73,11 +74,14 @@ public class WarnHandleTask {
             if (v.getTime() + timeout_warn < startTime) {
                 // 这里要删除数据
                 WarnRecord record = v.getRecord();
+                boolean isFendMsg = record.getStatus() != null && record.getStatus() == 0;
                 record.setWarnStatus(1);
+                record.setStatus(null);// 这个状态不修改
                 record.setUpdateTime(System.currentTimeMillis());
                 iWarnRecordDao.updateTemplateById(record);
                 delList.add(k);
                 // todo 后期这里需要告警推送
+
             }
         });
         delList.forEach(s->{

+ 13 - 2
src/main/java/com/comtika/safe/core/weChat/WxChatUtil.java

@@ -8,6 +8,7 @@ import com.comtika.safe.common.utils.StringUtil;
 import com.comtika.safe.common.utils.http.HttpUtil;
 import com.comtika.safe.config.WeChatProperties;
 import com.comtika.safe.entity.warn.help.WarnMessageHelp;
+import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -20,6 +21,7 @@ import java.util.List;
  * @DESC: todo 这个是发送消息方法,后期需要处理
  **/
 @Component
+@Log4j2
 public class WxChatUtil {
     @Autowired
     private WeChatProperties weChatProperties;
@@ -28,12 +30,17 @@ public class WxChatUtil {
     private static final String WX_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
     // 发生公众号消息方法
     public JSONObject sendTemplateMsg(String accessToken, String json) {
+        if(StringUtil.isEmpty(accessToken)) {
+            log.error("token 为空~~");
+            return null;
+        }
         String requestUrl = AC_PUSH_URL.replace(TOKEN_KEY, accessToken);
         return JSONObject.parseObject(HttpUtil.doPost(requestUrl, json));
     }
     private static boolean isText = false;
 
 
+
     // 获取程序的openid
     public JSONObject findWeChatAuth2Data(String code, boolean isSmall) {
         String url = null;
@@ -81,7 +88,7 @@ public class WxChatUtil {
             token = getTocken(false);
         // 下面发生消息
         JSONObject jsonObject = sendTemplateMsg(token, json);
-        System.out.println("发生结果为:" + jsonObject.toJSONString());
+        log.info("发生结果为:{}" , jsonObject.toJSONString());
         return RespWrapper.makeSuccessResp(true);
     }
     public RespWrapper<Boolean> sendMessageToVisit(boolean isSuccess,String remark,String acOpenId,String token){
@@ -94,7 +101,7 @@ public class WxChatUtil {
             token = getTocken(false);
         // 下面发生消息
         JSONObject jsonObject = sendTemplateMsg(token, json);
-        System.out.println("发生结果为:" + jsonObject.toJSONString());
+       log.info("发生结果为:{}" , jsonObject.toJSONString());
         return RespWrapper.makeSuccessResp(true);
     }
     public RespWrapper<Boolean> sendWarnMessageToUser(WarnMessageHelp help, List<String> acOpenIdList, String token){
@@ -107,6 +114,10 @@ public class WxChatUtil {
         for(String acOpenId:acOpenIdList){
             if(!isText){
                 token = getTocken(false);
+                if(StringUtil.isEmpty(token)){
+                    log.error("获取token 失败,检查公众号是否配置");
+                    return RespWrapper.makeFailResp("获取token 失败,检查公众号是否配置");
+                }
             }
             //回调地址
             String json = MessageDataHandle.toJsonPN(false,null, acOpenId, AcTemplateMessage.WARN.templateId, vm.getData());

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

@@ -15,6 +15,8 @@ public interface IRepService {
     void handleWarnData(WarnDataHelp dataHelp);
     TerminalSafeInfo findTerminalBaseInfo(String terminalNo);
 
+    void updateWarnCacheStatus(String serialNo, int type,Integer status);
+
 
     void sendOffLineTerminalMessage(String terminalNo);
 }

+ 8 - 4
src/main/java/com/comtika/safe/service/safe/impl/RepServiceImpl.java

@@ -30,10 +30,7 @@ import lombok.extern.log4j.Log4j2;
 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.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
@@ -291,6 +288,13 @@ public class RepServiceImpl implements IRepService {
         String key = String.format(WARN_KEY,serialNo,type);
         return warnHandleTask.findWarnCache(key);
     }
+    @Override
+    public void updateWarnCacheStatus(String serialNo, int type,Integer status){
+        // 修改缓存状态
+        Optional.ofNullable(findWarnCache(serialNo, type)).ifPresent(k->{
+            k.setStatus(status);
+        });
+    }
     private void updateWarnCache(String serialNo,int type,WarnRecord record){
         String key = String.format(WARN_KEY,serialNo,type);
         warnHandleTask.updateWarnCache(key,record);

+ 5 - 0
src/main/java/com/comtika/safe/service/warn/impl/WarnServiceImpl.java

@@ -22,6 +22,7 @@ import com.comtika.safe.entity.warn.help.WarnHelp;
 import com.comtika.safe.entity.warn.help.WarnHomeHelp;
 import com.comtika.safe.entity.warn.help.WarnMonthHelp;
 import com.comtika.safe.service.protocol.impl.ProtocolSeriveImpl;
+import com.comtika.safe.service.safe.IRepService;
 import com.comtika.safe.service.warn.IWarnService;
 import lombok.extern.log4j.Log4j2;
 import org.apache.lucene.search.*;
@@ -47,6 +48,8 @@ public class WarnServiceImpl implements IWarnService {
     @Autowired
     private IExcelFieldDao iExcelFieldDao;
     public static final int excelMaxNum = 50000;
+    @Autowired
+    private IRepService iRepService;
 
     // 这里处理数据
     @Override
@@ -171,6 +174,8 @@ public class WarnServiceImpl implements IWarnService {
             single.setStatus(1);
         }else single.setStatus(0);*/
         single.setStatus(status);
+        // todo 需要修改缓存状态
+        iRepService.updateWarnCacheStatus(single.getSerialNo(),single.getWarnType(),status);
         iWarnRecordDao.updateTemplateById(single);
         return RespWrapper.makeSuccessResp(true);
     }