| | |
| | | package cn.gistack.alerts.notice.service.impl; |
| | | |
| | | import cn.com.flaginfo.sdk.cmc.api.sms.send.SMSSendRequest; |
| | | import cn.gistack.alerts.alarmRule.entity.AlarmRecord; |
| | | import cn.gistack.alerts.alarmRule.entity.AlarmRecordDetail; |
| | | import cn.gistack.alerts.alarmRule.entity.AlarmRule; |
| | | import cn.gistack.alerts.alarmRule.entity.AlarmRuleDetail; |
| | | import cn.gistack.alerts.alarmRule.service.AlarmRecordService; |
| | | import cn.gistack.alerts.notice.constant.ZnwhColumnConstant; |
| | | import cn.gistack.alerts.notice.constant.ZtApiUrlConstant; |
| | | import cn.gistack.alerts.notice.constant.ZtConfigConstant; |
| | | import cn.gistack.alerts.notice.enums.PersonEnum; |
| | | import cn.gistack.alerts.notice.util.FormatUtil; |
| | | import cn.gistack.alerts.push.service.IPushService; |
| | | import cn.gistack.alerts.sms.entity.SmsTemplate; |
| | | import cn.gistack.alerts.sms.service.ISmsTemplateService; |
| | | import cn.gistack.alerts.sms.vo.SmsRequestTemplate; |
| | | import cn.gistack.alerts.sse.server.SSEServer; |
| | | import cn.gistack.common.utils.SpringContextUtil; |
| | | import cn.gistack.sm.intelligentCall.feign.OutCallClient; |
| | | import cn.gistack.sm.message.entity.MessageRecord; |
| | | import cn.gistack.sm.message.feign.IMessageClient; |
| | | import cn.gistack.sm.sjztmd.feign.IAttResManagePersonClient; |
| | | import cn.gistack.sm.sjztmd.vo.PersonVO; |
| | | import cn.gistack.system.feign.ISysClient; |
| | | import cn.gistack.system.user.entity.User; |
| | | import cn.gistack.system.user.feign.IUserClient; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class NoticeHandle { |
| | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private IMessageClient messageClient; |
| | | |
| | | @Autowired |
| | | private IUserClient userClient; |
| | | |
| | | @Autowired |
| | | private IPushService pushService; |
| | | |
| | | @Autowired |
| | | private OutCallClient outCallClient; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 短信发送数据组装 |
| | | * |
| | | * @param jsonArray |
| | | * @param templateId |
| | | * @param alarmRule |
| | | * @param jsonArray 告警动态数据 |
| | | * @param alarmRule 告警规则信息 |
| | | * @param alarmRuleDetail 告警规则详情信息 |
| | | * @param columnsList 列名集合信息 |
| | | * @param flag 是否包含日期 |
| | | * @param adCode 行政区编号 |
| | | * @param adCode 行政区编号(是否过滤区县数据) |
| | | * @param uuid 本次执行临时编号 |
| | | * @param isSendStation 是否发送站内信 |
| | | * @return |
| | | */ |
| | | public SmsRequestTemplate getSendSmsTemplate(JSONArray jsonArray, |
| | | String templateId, |
| | | AlarmRule alarmRule, |
| | | AlarmRuleDetail alarmRuleDetail, |
| | | List<String> columnsList, |
| | | Boolean flag, |
| | | String adCode) { |
| | | // 通过模板id 查询模板相关信息 |
| | | SmsTemplate smsTemplate = smsTemplateService.getOne(new QueryWrapper<SmsTemplate>().eq("template_id",templateId).eq("is_deleted",0)); |
| | | String adCode, |
| | | String uuid, |
| | | Boolean isSendStation) { |
| | | // 通过模板id 查询模板相关信息(外呼对应的模板id则为场景id) |
| | | SmsTemplate smsTemplate |
| | | = smsTemplateService.getOne(new QueryWrapper<SmsTemplate>().eq("id",alarmRuleDetail.getTemplateId()).eq("is_deleted",0)); |
| | | if (null != smsTemplate) { |
| | | // 创建消息发送对象 |
| | | SmsRequestTemplate smsRequestTemplate = new SmsRequestTemplate(); |
| | | // 设置是否发送站内信 |
| | | smsRequestTemplate.setIsSendStation(isSendStation); |
| | | // 设置告警信息 |
| | | smsRequestTemplate.setAlarmRule(alarmRule); |
| | | // 设置模板信息 |
| | | smsRequestTemplate.setSmsTemplate(smsTemplate); |
| | | // 解析模板并设置 title |
| | | smsRequestTemplate.setTitle(FormatUtil.composeMessage(smsTemplate.getContent())); |
| | | // 列名数据转换 |
| | | getColumnData(jsonArray, columnsList,smsRequestTemplate,alarmRule,flag,adCode); |
| | | getColumnData(jsonArray, columnsList,smsRequestTemplate,alarmRuleDetail,flag,adCode,uuid); |
| | | //返回 |
| | | return smsRequestTemplate; |
| | | } |
| | |
| | | |
| | | /** |
| | | * 列名数据转换 |
| | | * @param jsonArray |
| | | * @param columnsList |
| | | * @param smsRequestTemplate |
| | | * @param flag |
| | | * @param adCode |
| | | * @param jsonArray 告警动态数据 |
| | | * @param columnsList 告警动态内容 key |
| | | * @param smsRequestTemplate 消息发送对象 |
| | | * @param alarmRuleDetail 告警人员角色ids |
| | | * @param flag 告警内容是否日期 |
| | | * @param adCode 行政区 code ,用于过滤数据 |
| | | * @param uuid 用于过滤数据 |
| | | * @return |
| | | */ |
| | | private void getColumnData(JSONArray jsonArray, |
| | | List<String> columnsList, |
| | | SmsRequestTemplate smsRequestTemplate, |
| | | AlarmRule alarmRule, |
| | | AlarmRuleDetail alarmRuleDetail, |
| | | Boolean flag, |
| | | String adCode) { |
| | | String adCode, |
| | | String uuid) { |
| | | // 告警人员 |
| | | List<PersonVO> personLists = new ArrayList<>(); |
| | | // 告警内容 |
| | | List<List<String>> lists = new ArrayList<>(); |
| | | Set<String> set = new HashSet<>(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | if (null!=adCode){ |
| | | // city_cd,county_cd 过滤数据 |
| | | String county_cd = jsonArray.getJSONObject(i).getString("county_cd"); |
| | | if (county_cd.equals(adCode)) { |
| | | jointData(jsonArray, columnsList, alarmRule, flag, personLists, lists, i); |
| | | if (null!= county_cd && county_cd.equals(adCode)) { |
| | | jointData(jsonArray, columnsList, alarmRuleDetail, flag, personLists, lists, i,uuid,set); |
| | | } |
| | | }else { |
| | | jointData(jsonArray, columnsList, alarmRule, flag, personLists, lists, i); |
| | | jointData(jsonArray, columnsList, alarmRuleDetail, flag, personLists, lists, i,uuid,set); |
| | | } |
| | | } |
| | | // 设置信息 |
| | |
| | | |
| | | /** |
| | | * 拼接列数据设置告警人员信息 |
| | | * @param jsonArray |
| | | * @param columnsList |
| | | * @param alarmRule |
| | | * @param flag |
| | | * @param personLists |
| | | * @param lists |
| | | * @param i |
| | | * @param jsonArray 告警动态数据 |
| | | * @param columnsList 告警动态内容 key |
| | | * @param alarmRuleDetail 告警人角色ids |
| | | * @param flag 告警内容是否日期 |
| | | * @param personLists 告警人 |
| | | * @param lists 告警内容 |
| | | * @param i 第几个 |
| | | * @return |
| | | */ |
| | | private void jointData(JSONArray jsonArray, List<String> columnsList, AlarmRule alarmRule, Boolean flag, List<PersonVO> personLists, List<List<String>> lists, int i) { |
| | | private void jointData(JSONArray jsonArray, |
| | | List<String> columnsList, |
| | | AlarmRuleDetail alarmRuleDetail, |
| | | Boolean flag, |
| | | List<PersonVO> personLists, |
| | | List<List<String>> lists, |
| | | int i, |
| | | String uuid, |
| | | Set<String> set) { |
| | | // 根据水库编号,所在区域查询需要发送的人员手机号及设置 |
| | | String res_cd = jsonArray.getJSONObject(i).getString("res_cd"); |
| | | // 判断时间是否存在 |
| | | String tm = jsonArray.getJSONObject(i).getString("tm"); |
| | | String day = ""; |
| | | String hour = ""; |
| | | String minute = ""; |
| | | if (null != tm && !tm.equals("") && flag) { |
| | | flag = true; |
| | | // 加入天,时,分 |
| | | day = tm.substring(8, 10); |
| | | hour = tm.substring(11, 13); |
| | | minute = tm.substring(14, 16); |
| | | } else { |
| | | flag = false; |
| | | String tempStr = uuid + res_cd; |
| | | // 去重水库操作,如果有重复的水库则不操作 |
| | | if (!set.contains(tempStr)) { |
| | | set.add(tempStr); |
| | | // 取出测站编码 |
| | | String stcd = jsonArray.getJSONObject(i).getString("stcd"); |
| | | // 判断时间是否存在 |
| | | String tm = jsonArray.getJSONObject(i).getString("tm"); |
| | | String day = ""; |
| | | String hour = ""; |
| | | String minute = ""; |
| | | if (null != tm && !tm.equals("") && flag) { |
| | | flag = true; |
| | | // 加入天,时,分 |
| | | day = tm.substring(8, 10); |
| | | hour = tm.substring(11, 13); |
| | | minute = tm.substring(14, 16); |
| | | } else { |
| | | flag = false; |
| | | } |
| | | // 获取告警人员信息 |
| | | getAlarmPersonList(jsonArray, columnsList, alarmRuleDetail, flag, personLists, lists, i, res_cd, day, hour, minute, stcd); |
| | | } |
| | | // 获取告警人员信息 |
| | | getAlarmPersonList(jsonArray, columnsList, alarmRule, flag, personLists, lists, i, res_cd, day, hour, minute); |
| | | } |
| | | |
| | | /** |
| | | * 获取告警人员信息 |
| | | * @param jsonArray |
| | | * @param columnsList |
| | | * @param alarmRule |
| | | * @param flag |
| | | * @param personLists |
| | | * @param lists |
| | | * @param i |
| | | * @param res_cd |
| | | * @param day |
| | | * @param hour |
| | | * @param minute |
| | | * @param jsonArray 接口水库相关数据 |
| | | * @param columnsList 模板对应列key |
| | | * @param alarmRuleDetail 告警人员角色ids |
| | | * @param flag 模板中是否填入时间 |
| | | * @param personLists 告警人员集合 |
| | | * @param lists 告警内容集合 |
| | | * @param i 第 i 个水库 |
| | | * @param res_cd 水库编码 |
| | | * @param day 日期 |
| | | * @param hour 小时 |
| | | * @param minute 分钟 |
| | | * @param stcd 测站编码 |
| | | */ |
| | | private void getAlarmPersonList(JSONArray jsonArray, |
| | | List<String> columnsList, |
| | | AlarmRule alarmRule, |
| | | AlarmRuleDetail alarmRuleDetail, |
| | | Boolean flag, |
| | | List<PersonVO> personLists, |
| | | List<List<String>> lists, |
| | |
| | | String res_cd, |
| | | String day, |
| | | String hour, |
| | | String minute) { |
| | | String minute, |
| | | String stcd) { |
| | | // 查询告警人员信息 |
| | | List<PersonVO> personVOList = getPersonListByResGuid(res_cd, alarmRule); |
| | | List<PersonVO> personVOList = getPersonListByResGuid(res_cd, alarmRuleDetail.getAlarmPerson()); |
| | | if (personVOList.size() > 0) { |
| | | for (PersonVO personVO : personVOList) { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(stcd); |
| | | list.add(res_cd); |
| | | list.add(personVO.getPhone()); |
| | | if (flag) { |
| | | list.add(day); |
| | | list.add(hour); |
| | | list.add(minute); |
| | | // 如果是电话告警,需要把日期拼到一起 |
| | | if (alarmRuleDetail.getAlarmMode().equals("电话")){ |
| | | String tem = day + "日" + hour + "时" + minute + "分"; |
| | | list.add(tem); |
| | | }else { |
| | | list.add(day); |
| | | list.add(hour); |
| | | list.add(minute); |
| | | } |
| | | } |
| | | // 变量将值放入集合中 |
| | | for (String column : columnsList) { |
| | | String[] split = column.split(","); |
| | | String format = ""; |
| | | for (String s : split) { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | // 内容处理 |
| | | format = addAlarmContent(jsonArray, i, split, format); |
| | | // 加入集合 |
| | | list.add(format); |
| | | } |
| | | lists.add(list); |
| | | } |
| | | } |
| | | personLists.addAll(personVOList); |
| | | } |
| | | |
| | | /** |
| | | * 告警内容拼接处理 |
| | | * @param jsonArray 数据 |
| | | * @param i 第几个 |
| | | * @param split key 值 |
| | | * @param format 值结果 |
| | | * @return |
| | | */ |
| | | private String addAlarmContent(JSONArray jsonArray, int i,String[] split, String format) { |
| | | for (String s : split) { |
| | | // 超汛限水位 |
| | | if (s.equals("over_z")) { |
| | | String is_danger_res = "is_danger_res"; |
| | | if (null!= jsonArray.getJSONObject(i).getString(is_danger_res) && jsonArray.getJSONObject(i).getString(is_danger_res).equals("true")) { |
| | | format = format + "控制运用水位" + jsonArray.getJSONObject(i).getString(s); |
| | | } else if (null!= jsonArray.getJSONObject(i).getString(is_danger_res) && jsonArray.getJSONObject(i).getString(is_danger_res).equals("false")) { |
| | | format = format + "汛限水位" + jsonArray.getJSONObject(i).getString(s); |
| | | } else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | } else if (s.equals("rz")) { |
| | | // 水位 |
| | | String rz = "rz"; |
| | | if (null==jsonArray.getJSONObject(i).getString(rz)) { |
| | | format = format + "无数据"; |
| | | } else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s) + "米"; |
| | | } |
| | | } else if (s.equals("alarm_val")) { |
| | | // 小时雨量 |
| | | String alarm_type = "alarm_type"; |
| | | if (null!=jsonArray.getJSONObject(i).getString(alarm_type) && !jsonArray.getJSONObject(i).getString(alarm_type).equals("")) { |
| | | format = format + jsonArray.getJSONObject(i).getString(alarm_type) + "小时坝前点雨量" + jsonArray.getJSONObject(i).getString(s); |
| | | }else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | } else if (s.equals("diff_dam")) { |
| | | String over_chec_fl_stag = "over_chec_fl_stag"; |
| | | // 如果是超校核的需要判断超值 |
| | | if (null!=jsonArray.getJSONObject(i).getString(over_chec_fl_stag) && !jsonArray.getJSONObject(i).getString(over_chec_fl_stag).equals("")) { |
| | | // 校核,是否漫过坝顶(正数代表未漫过坝顶,负数则反之) |
| | | String diff_dam = jsonArray.getJSONObject(i).getString(s); |
| | | double parseDouble = Double.parseDouble(diff_dam); |
| | | if (parseDouble>0) { |
| | | format = format + "距离大坝坝顶仅" + jsonArray.getJSONObject(i).getString(s); |
| | | }else { |
| | | format = format + "已漫过坝顶" + (-parseDouble); |
| | | } |
| | | }else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | } else if (s.equals("ms_flag")) { |
| | | // 水位 |
| | | String ms_flag = "ms_flag"; |
| | | if (null!= jsonArray.getJSONObject(i).getString(ms_flag) && jsonArray.getJSONObject(i).getString(ms_flag).equals("sy")) { |
| | | format = format + "渗压"; |
| | | } else if (null!= jsonArray.getJSONObject(i).getString(ms_flag) && jsonArray.getJSONObject(i).getString(ms_flag).equals("sl")) { |
| | | format = format + "渗流" ; |
| | | } else if (null!= jsonArray.getJSONObject(i).getString(ms_flag) && jsonArray.getJSONObject(i).getString(ms_flag).equals("by")) { |
| | | format = format + "白蚁" ; |
| | | } else if (null!= jsonArray.getJSONObject(i).getString(ms_flag) && jsonArray.getJSONObject(i).getString(ms_flag).equals("bx")) { |
| | | format = format + "变形" ; |
| | | } else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | } else { |
| | | format = format + jsonArray.getJSONObject(i).getString(s); |
| | | } |
| | | } |
| | | // 返回 |
| | | return format; |
| | | } |
| | | |
| | | /** |
| | |
| | | AlarmRecord alarmRecord = alarmRecordService.getOne(new QueryWrapper<AlarmRecord>() |
| | | .eq("temp_code",uuid) |
| | | .eq("alarm_rule_id",alarmRule.getId()) |
| | | .eq("reservoir_number",list.get(0)) |
| | | .eq("reservoir_number",list.get(1)) |
| | | ); |
| | | if (null!=alarmRecord) { |
| | | // 删除测站编号 |
| | | list.remove(0); |
| | | return alarmRecord; |
| | | }else { |
| | | AlarmRecord alarm = new AlarmRecord(); |
| | | // 设置相关信息 |
| | | alarm.setAlarmRuleId(alarmRule.getId().toString()); |
| | | |
| | | alarm.setReservoirNumber(list.get(0)); |
| | | // 分别设置测站编号和水库编码 |
| | | alarm.setAlarmSurveyStationCode(list.get(0)); |
| | | alarm.setReservoirNumber(list.get(1)); |
| | | alarm.setAlarmCondition(alarmRule.getRuleRemark()); |
| | | alarm.setTempCode(uuid); |
| | | // 新增 |
| | | boolean save = alarmRecordService.save(alarm); |
| | | // 删除测站编号 |
| | | list.remove(0); |
| | | if (save) { |
| | | return alarm; |
| | | } |
| | |
| | | /** |
| | | * 查询告警人员信息 |
| | | * @param res_cd 水库 guid |
| | | * @param alarmRule |
| | | * @param roleIds 角色ids |
| | | * @return |
| | | */ |
| | | private List<PersonVO> getPersonListByResGuid(String res_cd,AlarmRule alarmRule) { |
| | | private List<PersonVO> getPersonListByResGuid(String res_cd,String roleIds) { |
| | | // 查询对应的角色信息 |
| | | List<String> roles = sysClient.getRoleNames(alarmRule.getAlarmPerson()).getData(); |
| | | List<String> roles = sysClient.getRoleNames(roleIds).getData(); |
| | | List<String> personList = new ArrayList<>(); |
| | | List<String> areaList = new ArrayList<>(); |
| | | // 遍历 |
| | |
| | | list.addAll(personVOList); |
| | | } |
| | | //2. 根据水库编号及责任人类型查询相关责任人信息 |
| | | List<PersonVO> personVOList1 = attResManagePersonClient.getPersonListByResGuid(res_cd,String.join(",",personList)); |
| | | // 合并人员数据 |
| | | list.addAll(personVOList1); |
| | | if (personList.size() > 0) { |
| | | List<PersonVO> personVOList1 = attResManagePersonClient.getPersonListByResGuid(res_cd, String.join(",", personList)); |
| | | // 合并人员数据 |
| | | list.addAll(personVOList1); |
| | | } |
| | | // 返回数据 |
| | | return list; |
| | | } |
| | |
| | | /** |
| | | * 依次添加巡查责任人,技术责任人信息 |
| | | * @param list |
| | | * @param isPhone 是否保护电话 |
| | | */ |
| | | public void addPatrolTechnologyInfo(List<String> list) { |
| | | public void addPatrolTechnologyInfo(List<String> list,Boolean isPhone) { |
| | | // 查询巡查责任人姓名,技术责任人姓名信息 |
| | | List<PersonVO> personVOList = attResManagePersonClient.getPersonListByResGuid(list.get(0),"4,5"); |
| | | List<PersonVO> personVOList = attResManagePersonClient.getPersonListByResGuid(list.get(1),"4,5"); |
| | | if (personVOList.size()>0) { |
| | | String xczrr = ""; |
| | | String jszrr = ""; |
| | | String xczrr = "-"; |
| | | String jszrr = "-"; |
| | | for (PersonVO personVO : personVOList) { |
| | | if (personVO.getType().equals("5")) { |
| | | xczrr = personVO.getName(); |
| | | xczrr = isPhone?personVO.getName()+":"+personVO.getPhone() : personVO.getName(); |
| | | } |
| | | if (personVO.getType().equals("4")) { |
| | | jszrr = personVO.getName(); |
| | | jszrr = isPhone?personVO.getName()+":"+personVO.getPhone() : personVO.getName(); |
| | | } |
| | | } |
| | | // 巡查责任人姓名 |
| | |
| | | list.add(jszrr); |
| | | }else { |
| | | // 巡查责任人姓名 |
| | | list.add(""); |
| | | list.add("-"); |
| | | // 技术责任人姓名 |
| | | list.add(""); |
| | | list.add("-"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 拼接市县水利部人员姓名及联系方式 |
| | |
| | | */ |
| | | public void addCityCountyBusinessPersonInfo(List<String> list) { |
| | | // 根据水库编号查询市县水利部人员姓名及联系方式 |
| | | List<PersonVO> personVOList = attResManagePersonClient.getCityCountyPersonListByResGuid(list.get(0)); |
| | | List<PersonVO> personVOList = attResManagePersonClient.getCityCountyPersonListByResGuid(list.get(1)); |
| | | if (personVOList.size()>0){ |
| | | // 如果没有找到人员? |
| | | StringBuilder builder = new StringBuilder(); |
| | | for (PersonVO personVO : personVOList) { |
| | | builder.append(personVO.getName()).append(":").append(personVO.getPhone()).append(","); |
| | | builder.append(personVO.getName()).append(":").append(personVO.getPhone()).append(";"); |
| | | } |
| | | // 拼接水利部人员信息 |
| | | list.add(builder.substring(0,builder.length()-1)); |
| | | }else { |
| | | list.add(""); |
| | | list.add("-"); |
| | | } |
| | | } |
| | | |
| | |
| | | public void addWaterMoreDesignPatrolTechnologyInfo(List<String> list,String personTypes) { |
| | | String[] split = personTypes.split(","); |
| | | // 查询巡查责任人姓名,技术责任人姓名信息 |
| | | List<PersonVO> personVOList = attResManagePersonClient.getPersonListByResGuid(list.get(0),personTypes); |
| | | List<PersonVO> personVOList = attResManagePersonClient.getPersonListByResGuid(list.get(1),personTypes); |
| | | if (personVOList.size()>0) { |
| | | String xzzrr = " "; |
| | | String zgzrr = " "; |
| | | String jszrr = " "; |
| | | String xczrr = " "; |
| | | String xzzrr = "-"; |
| | | String zgzrr = "-"; |
| | | String jszrr = "-"; |
| | | String xczrr = "-"; |
| | | for (PersonVO personVO : personVOList) { |
| | | String str = null!=personVO.getPhone() ? ":"+personVO.getPhone():""; |
| | | String str = null!=personVO.getPhone() ? ":"+personVO.getPhone():"-"; |
| | | if (personVO.getType().equals(split[0])) { |
| | | xzzrr = personVO.getName() + str; |
| | | } |
| | |
| | | list.add(xczrr); |
| | | }else { |
| | | for (String type : split) { |
| | | list.add(""); |
| | | list.add("-"); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (activeProfile.equals("prod")){ |
| | | url = ZtApiUrlConstant.url_prefix_prod + url; |
| | | } |
| | | if (activeProfile.equals("test")){ |
| | | url = ZtApiUrlConstant.url_prefix_test + url; |
| | | } |
| | | //设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add(ZtConfigConstant.header_key, ZtConfigConstant.header_value); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 保存站内信记录信息 |
| | | * @param smsRequestTemplate |
| | | * @param alarmRule |
| | | * @return |
| | | */ |
| | | public Map<String, Object> saveInStationInfo(SmsRequestTemplate smsRequestTemplate, AlarmRule alarmRule) { |
| | | // 取出数据 |
| | | SMSSendRequest request = new SMSSendRequest(); |
| | | SmsTemplate smsTemplate = smsRequestTemplate.getSmsTemplate(); |
| | | request.setTemplateId(smsTemplate.getTemplateId()); |
| | | List<List<String>> templateContent = smsRequestTemplate.getTemplateContent(); |
| | | // 先保存结果记录 |
| | | List<AlarmRecordDetail> alarmRecordDetailList = new ArrayList<>(); |
| | | List<MessageRecord> messageRecordList = new ArrayList<>(); |
| | | Set<String> phoneSet = new HashSet<>(); |
| | | // 遍历处理 |
| | | for (List<String> list : templateContent) { |
| | | // 设置站内信记录信息 |
| | | MessageRecord messageRecord = new MessageRecord(); |
| | | messageRecord.setTheme(alarmRule.getRuleName()); |
| | | messageRecord.setSender(AuthUtil.getUserId().toString()); |
| | | messageRecord.setSource("智能告警"); |
| | | messageRecord.setStatus(0); |
| | | |
| | | // 设置告警记录信息 |
| | | AlarmRecordDetail alarmRecordDetail = new AlarmRecordDetail(); |
| | | alarmRecordDetail.setReservoirNumber(list.get(0)); |
| | | alarmRecordDetail.setAlarmRecordId(Long.parseLong(list.get(list.size() - 1))); |
| | | alarmRecordDetail.setAlarmMode("站内信"); |
| | | // 未读 |
| | | alarmRecordDetail.setStatus(1); |
| | | // 删除 最后一个 告警记录id |
| | | list.remove(list.size() - 1); |
| | | // 删除 0 水库编码 |
| | | list.remove(0); |
| | | |
| | | alarmRecordDetail.setPhone(list.get(0)); |
| | | // 设置手机号 |
| | | request.setUserNumber(list.get(0)); |
| | | messageRecord.setRecipient(list.get(0)); |
| | | phoneSet.add(list.get(0)); |
| | | // 内容处理 |
| | | String s = smsTemplate.getContent().replaceAll("\\{.+?\\}", "%s"); |
| | | // 需要删除最前面的手机号 |
| | | list.remove(0); |
| | | // 格式转换 |
| | | String format = String.format(s, list.toArray()); |
| | | // 设置内容 |
| | | request.setMessageContent(format); |
| | | messageRecord.setContent(format); |
| | | // 保存记录 |
| | | alarmRecordDetail.setAlarmContent(format); |
| | | alarmRecordDetail.setCreateTime(new Date()); |
| | | // 放入集合 |
| | | alarmRecordDetailList.add(alarmRecordDetail); |
| | | messageRecordList.add(messageRecord); |
| | | } |
| | | // 保存告警记录详情信息 |
| | | if (smsRequestTemplate.getIsSendStation()) { |
| | | saveMessageRecord(messageRecordList); |
| | | } |
| | | Map<String, Object> map = new HashMap<>(2); |
| | | // 返回 |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 保存站内信记录信息 |
| | | * @param messageRecordList |
| | | */ |
| | | public void saveMessageRecord(List<MessageRecord> messageRecordList) { |
| | | // 遍历,查询对应的用户id |
| | | for (MessageRecord messageRecord : messageRecordList) { |
| | | // 通过手机号获取用户id信息 |
| | | R<List<User>> listR = userClient.userInfoByPhone("000000", messageRecord.getRecipient()); |
| | | if (listR.getData().size()>0) { |
| | | messageRecord.setRecipient(listR.getData().get(0).getId().toString()); |
| | | } |
| | | } |
| | | |
| | | // List<MessageRecord> messageRecordList1 = new ArrayList<>(); |
| | | // addSendMsgTest(messageRecordList1); |
| | | //给app推送消息 |
| | | // pushService.pushMessageList(messageRecordList1); |
| | | pushService.pushMessageList(messageRecordList); |
| | | |
| | | // 保存记录 |
| | | messageClient.saveMessageRecord(messageRecordList); |
| | | // 发起通知 |
| | | // 遍历 |
| | | for (MessageRecord messageRecord : messageRecordList) { |
| | | Map<String, Object> map = new HashMap<>(2); |
| | | // 查询当前用户未读消息个数 |
| | | map.put("count",messageClient.getNotReadNumber(messageRecord.getRecipient())); |
| | | map.put("record",messageRecord); |
| | | SSEServer.sendMessage("web:"+messageRecord.getRecipient(),new JSONObject(map).toJSONString()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增测试信息 |
| | | * @param messageRecordList |
| | | */ |
| | | private void addSendMsgTest(List<MessageRecord> messageRecordList) { |
| | | MessageRecord messageRecord = new MessageRecord(); |
| | | messageRecord.setRecipient("1654164141753593858"); |
| | | messageRecord.setContent("cs12121212=========="); |
| | | messageRecord.setTheme("接近超汛告警"); |
| | | messageRecord.setSender(AuthUtil.getUserId().toString()); |
| | | messageRecord.setSource("智能告警"); |
| | | messageRecord.setStatus(0); |
| | | // 加入集合 |
| | | messageRecordList.add(messageRecord); |
| | | } |
| | | |
| | | /** |
| | | * 创建告警外呼任务 |
| | | * @param smsRequestTemplate |
| | | * @return |
| | | */ |
| | | public List<String> createOutCallTaskByAlarm(SmsRequestTemplate smsRequestTemplate) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | List<Map<String, String>> mapList = new ArrayList<>(); |
| | | // 拼装数据 |
| | | List<String> titles = new ArrayList<>(Arrays.asList(smsRequestTemplate.getTitle().split(","))); |
| | | // 修改手机号码为被叫号码 |
| | | titles.set(0, "被叫号码"); |
| | | titles.add("告警记录id"); |
| | | titles.add(0,"水库编号"); |
| | | map.put("titles",titles); |
| | | // 处理人员及预警相关数据并组装 |
| | | for (List<String> list : smsRequestTemplate.getTemplateContent()) { |
| | | Map<String, String> stringMap = new HashMap<>(); |
| | | for (int i = 0; i < titles.size(); i++) { |
| | | stringMap.put(titles.get(i),list.get(i)); |
| | | } |
| | | mapList.add(stringMap); |
| | | } |
| | | map.put("list",mapList); |
| | | map.put("scenesId",smsRequestTemplate.getSmsTemplate().getTemplateId()); |
| | | String taskName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH:mm:ss")) + smsRequestTemplate.getAlarmRule().getRuleName() + "智能外呼"; |
| | | map.put("taskName",taskName); |
| | | String taskScheduleTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | map.put("taskScheduleTime",taskScheduleTime); |
| | | // 创建外呼任务 |
| | | return outCallClient.createOutCallTaskByAlarm(map); |
| | | } |
| | | } |