From 4f6565cb9cca05981abdeb85dfc023a28c892e42 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期三, 05 十一月 2025 16:42:45 +0800
Subject: [PATCH] 钥匙柜信息处理

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningServiceImpl.java |  218 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 212 insertions(+), 6 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningServiceImpl.java
index 6b7263d..5758472 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningServiceImpl.java
@@ -1,38 +1,74 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.dingTalk.DingTalk;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.core.haikang.model.param.request.EventSubRequest;
+import com.doumee.core.haikang.service.HKService;
 import com.doumee.core.utils.Constants;
-import com.doumee.dao.business.model.Category;
-import com.doumee.dao.business.model.PlatformGroup;
+import com.doumee.core.utils.DateUtil;
+import com.doumee.core.utils.WeatherUtil;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.dao.MemberMapper;
+import com.doumee.dao.business.model.*;
 import com.doumee.service.business.third.model.LoginUserInfo;
 import com.doumee.service.business.third.model.PageData;
 import com.doumee.service.business.third.model.PageWrap;
 import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.WarningMapper;
-import com.doumee.dao.business.model.Warning;
 import com.doumee.service.business.WarningService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 鎶ヨ璁板綍淇℃伅琛⊿ervice瀹炵幇
  * @author 姹熻箘韫�
  * @date 2025/09/28 09:01
  */
+@Slf4j
 @Service
 public class WarningServiceImpl implements WarningService {
 
     @Autowired
     private WarningMapper warningMapper;
+
+    @Autowired
+    private WarningRuleMapper warningRuleMapper;
+
+    @Autowired
+    private WarningRuleDetailMapper warningRuleDetailMapper;
+
+    @Autowired
+    private WarningPushMapper warningPushMapper;
+
+    @Autowired
+    private WarningEventMapper warningEventMapper;
+
+    @Autowired
+    private DingTalk dingTalk;
+
+    @Autowired
+    private MemberMapper memberMapper;
+
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+
+    @Autowired
+    private DdNoticeConfigMapper ddNoticeConfigMapper;
+
 
     @Override
     public Integer create(Warning warning) {
@@ -41,6 +77,23 @@
                 .eq(Warning::getName,warning.getName()) )>0){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝浜嬩欢绫诲瀷宸插瓨鍦紝璇疯繑鍥炲埛鏂伴〉闈㈡煡鐪嬶紒");
         }
+
+        if(StringUtils.isNotBlank(warning.getCode())&&Constants.equalsInteger(warning.getType(),Constants.ZERO)||Constants.equalsInteger(warning.getType(),Constants.ONE)){
+            EventSubRequest eventParam = new EventSubRequest();
+            String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
+            eventParam.setEventDest(path+"/notice");
+            try {
+                eventParam.setEventTypes(new Integer[]{Integer.valueOf(warning.getCode())});
+            }catch (Exception e){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浜嬩欢缂栫爜閿欒锛�");
+            }
+            HKService.cancelEventSub(eventParam);//鍏堝彇娑�
+            if(Constants.equalsInteger(warning.getStatus(),Constants.ONE)){
+                HKService.eventSub(eventParam);//瀹夐槻浜嬩欢
+            }
+        }
+
+
         warning.setStatus(Constants.formatIntegerNum(warning.getStatus()));
         warning.setIsdeleted(Constants.ZERO);
         warning.setCreator(warning.getLoginUserInfo().getId());
@@ -55,6 +108,23 @@
 
     @Override
     public void deleteById(Integer id, LoginUserInfo user) {
+        Warning warning = warningMapper.selectById(id);
+        if(Objects.isNull(warning)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+
+        if(StringUtils.isNotBlank(warning.getCode())&&Constants.equalsInteger(warning.getType(),Constants.ZERO)||Constants.equalsInteger(warning.getType(),Constants.ONE)){
+            EventSubRequest eventParam = new EventSubRequest();
+            String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
+            eventParam.setEventDest(path+"/notice");
+            try {
+                eventParam.setEventTypes(new Integer[]{Integer.valueOf(warning.getCode())});
+            }catch (Exception e){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浜嬩欢缂栫爜閿欒锛�");
+            }
+            HKService.cancelEventSub(eventParam);//鍏堝彇娑�
+        }
+
         warningMapper.update(null,new UpdateWrapper<Warning>().lambda()
                 .set(Warning::getIsdeleted,Constants.ONE)
                 .set(Warning::getEditor,user.getId())
@@ -90,6 +160,22 @@
                 .eq(Warning::getName,warning.getName()) )>0){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝浜嬩欢绫诲瀷宸插瓨鍦紝璇疯繑鍥炲埛鏂伴〉闈㈡煡鐪嬶紒");
         }
+
+        if(StringUtils.isNotBlank(warning.getCode())&&Constants.equalsInteger(warning.getType(),Constants.ZERO)||Constants.equalsInteger(warning.getType(),Constants.ONE)){
+            EventSubRequest eventParam = new EventSubRequest();
+            String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
+            eventParam.setEventDest(path+"/notice");
+            try {
+                eventParam.setEventTypes(new Integer[]{Integer.valueOf(warning.getCode())});
+            }catch (Exception e){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浜嬩欢缂栫爜閿欒锛�");
+            }
+            HKService.cancelEventSub(eventParam);//鍏堝彇娑�
+            if(Constants.equalsInteger(warning.getStatus(),Constants.ONE)){
+                HKService.eventSub(eventParam);//瀹夐槻浜嬩欢
+            }
+        }
+
         warning.setEditDate(warning.getCreateDate());
         warning.setEditor(warning.getCreator());
         warningMapper.updateById(warning);
@@ -208,9 +294,129 @@
         if(Constants.equalsInteger(model.getStatus(),param.getStatus())){
             return;
         }
+        if(StringUtils.isNotBlank(param.getCode())&&Constants.equalsInteger(model.getType(),Constants.ZERO)||Constants.equalsInteger(model.getType(),Constants.ONE)){
+            EventSubRequest eventParam = new EventSubRequest();
+            String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
+            eventParam.setEventDest(path+"/notice");
+            try {
+                eventParam.setEventTypes(new Integer[]{Integer.valueOf(model.getCode())});
+            }catch (Exception e){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浜嬩欢缂栫爜閿欒锛�");
+            }
+            HKService.cancelEventSub(eventParam);//鍏堝彇娑�
+            if(Constants.equalsInteger(param.getStatus(),Constants.ONE)){
+                HKService.eventSub(eventParam);//瀹夐槻浜嬩欢
+            }
+        }
+
+
         model.setStatus(param.getStatus());
         model.setEditDate(new Date());
         model.setEditor(param.getLoginUserInfo().getId());
         warningMapper.updateById(model);
     }
+
+
+    /**
+     * 瀹氭椂鑾峰彇澶╂皵淇℃伅鎵ц
+     */
+    @Override
+    public void getWeatherInfo(){
+        try{
+            String response = WeatherUtil.getWeatherWarningInfo(systemDictDataBiz.queryByCode(Constants.WEATHER_CONFIG,Constants.REQUEST_URL).getCode(),
+                    systemDictDataBiz.queryByCode(Constants.WEATHER_CONFIG,Constants.API_KEY).getCode(),
+                    systemDictDataBiz.queryByCode(Constants.WEATHER_CONFIG,Constants.LOCATION).getCode());
+            if(StringUtils.isBlank(response)){
+                log.error("鏃犺繑鍥炴暟鎹�");
+            }
+            JSONObject jsonObject = JSONObject.parseObject(response);
+            if(jsonObject.getString("code").equals("200")){
+                if(jsonObject.containsKey("warning")){
+                    Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda()
+                            .eq(Warning::getType,Constants.FOUR).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 1"));
+                    if(Objects.isNull(warning)){
+                        return;
+                    }
+                    //鏌ヨ閫氱煡浜哄憳
+                    List<WarningRule> warningRuleList = warningRuleMapper.selectList(new QueryWrapper<WarningRule>().lambda()
+                            .eq(WarningRule::getIsdeleted,Constants.ZERO)
+                            .apply(" id in ( select w.RULE_ID from warning_rule_detail w where w.WARNING_ID = '"+warning.getId()+"' and w.ISDELETED = 0  ) ")
+                    );
+                    List<Member> memberList = new ArrayList<>();
+                    if(org.apache.commons.collections.CollectionUtils.isNotEmpty(warningRuleList)){
+                        List<String> memberIdStr =  warningRuleList.stream().map(i->i.getMemberIds()).collect(Collectors.toList());
+                        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(memberIdStr)){
+                            List<String> memberIdList = new ArrayList<>();
+                            for (String s:memberIdStr) {
+                                memberIdList.addAll(
+                                        Arrays.asList(s.split(","))
+                                );
+                            }
+                            memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getIsdeleted,Constants.ZERO)
+                                    .notIn(Member::getErpId)
+                                    .in(Member::getId,memberIdList)
+                            );
+                        }
+                    }
+                    JSONArray jsonArray = jsonObject.getJSONArray("warning");
+                    for (int i = 0; i < jsonArray.size(); i++) {
+                        List<WarningPush> warningPushList = new ArrayList<>();
+                        JSONObject  weatherInfo = jsonArray.getJSONObject(i);
+                        String code = weatherInfo.getString("id");
+                        String title = weatherInfo.getString("title");
+                        String text = weatherInfo.getString("text");
+                        //瀛樺湪棰勮 鍒欏瓨鍌ㄩ璀︿俊鎭�
+                        if(warningEventMapper.selectCount(new QueryWrapper<WarningEvent>()
+                                .lambda()
+                                .eq(WarningEvent::getEventId,code)
+                        )>Constants.ZERO){
+                            continue;
+                        }
+
+                        WarningEvent warningEvent = new WarningEvent();
+                        warningEvent.setCreateDate(new Date());
+                        warningEvent.setIsdeleted(Constants.ZERO);
+                        warningEvent.setWarningId(warning.getId());
+                        warningEvent.setTitle(title);
+                        warningEvent.setContent(text);
+                        warningEvent.setEventId(code);
+                        warningEvent.setHappenTime(DateUtil.getCurrDateTime());
+                        warningEvent.setJsonContent(weatherInfo.toJSONString());
+                        warningEventMapper.insert(warningEvent);
+                        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(memberList)&&memberList.size()>Constants.ZERO){
+                            List<String> ddUserIdList = memberList.stream().map(j->j.getErpId()).collect(Collectors.toList());
+                            //鍙戦�佹帹閫侀拤閽夋秷鎭�
+
+                            Boolean isSuccess = dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()),
+                                    String.join(",",ddUserIdList),
+                                    ddNoticeConfigMapper.selectCount(new QueryWrapper<DdNoticeConfig>().lambda()
+                                            .eq(DdNoticeConfig::getIsdeleted,Constants.ZERO).eq(DdNoticeConfig::getStatus,Constants.ZERO)
+                                            .eq(DdNoticeConfig::getObjType,13))>Constants.ZERO?
+                                    dingTalk.getWeatherNoticeMsg(title,text):null);
+                            for (Member member:memberList) {
+                                WarningPush warningPush = new WarningPush();
+                                warningPush.setCreateDate(new Date());
+                                warningPush.setWarningId(warning.getId());
+                                warningPush.setTitle(warningEvent.getTitle());
+                                warningPush.setContent(warningEvent.getContent());
+                                warningPush.setStatus(isSuccess?Constants.ONE:Constants.TWO);
+                                warningPush.setPushType(Constants.ZERO);
+                                warningPush.setMemberId(member.getId());
+                                warningPushList.add(warningPush);
+                            }
+                        }
+                        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(warningPushList)){
+                            warningPushMapper.insert(warningPushList);
+                        }
+                    }
+                }
+            }
+        }catch (Exception e){
+
+        }
+
+    }
+
+
+
 }

--
Gitblit v1.9.3