|  |  |  | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 报警记录信息表Service实现 | 
|---|
|  |  |  | * @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) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Warning> findList(Warning warning) { | 
|---|
|  |  |  | warning.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | QueryWrapper<Warning> wrapper = new QueryWrapper<>(warning); | 
|---|
|  |  |  | return warningMapper.selectList(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|