package com.xkrs.utils; import com.xkrs.model.entity.AgentOrgEntity; import com.xkrs.model.entity.SysUserEntity; import org.apache.hc.core5.util.TextUtils; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class FirePointCodeUtils { private FirePointCodeUtils() { } public static String getFormatCutCode(String code) throws Exception { String formatCutCode = code.trim(); while ((!TextUtils.isEmpty(formatCutCode)) && (formatCutCode.endsWith("0"))) { formatCutCode = formatCutCode.substring(0, formatCutCode.length() - 1).trim(); } int length = formatCutCode.length(); if (1 == length || 3 == length || 5 == length || 8 == length) { return formatCutCode + "0"; } if (7 == length) { return length + "00"; } return formatCutCode; } /** * 过滤短信通知收信人 * * @param firePointStreetCode 火点的街道编号 * @param sysUserList 系统用户列表 * @param normalSmsEnable 普通用户能否接收短信通知 * @param vipSmsEnable VIP用户能否接收短信通知 * @return 短信通知收信人列表 */ public static List filterSmsReceiver(String firePointStreetCode, List sysUserList, boolean normalSmsEnable, boolean vipSmsEnable) { List smsReceiverList = new ArrayList<>(); if (sysUserList == null || sysUserList.isEmpty()) { return smsReceiverList; } for (SysUserEntity sysUser : sysUserList) { try { String formatCutCode = FirePointCodeUtils.getFormatCutCode(sysUser.getCountyCode()); if (firePointStreetCode.startsWith(formatCutCode)) { if (sysUser.getDeleteFlag() != 0) {//被删除的用户不发短信 continue; } if (sysUser.getActiveFlag() != 0) {//被禁用的用户不发短信 continue; } if (sysUser.getReceiveSms() != 1) {//关掉开关的用户不发短信 continue; } if (sysUser.getStatusCode() != 0) {//状态不正常的用户不发短信 continue; } if ("管理员".equals(sysUser.getAccountType())) {//管理员用户不发短信 continue; } LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME); if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) { if (!normalSmsEnable) {//根据配置信息决定普通用户是否发送短信 continue; } } else { if (!vipSmsEnable) {//根据配置信息决定VIP用户是否发送短信 continue; } } smsReceiverList.add(sysUser); } } catch (Exception e) { e.printStackTrace(); } } return smsReceiverList; } /** * 对短信通知收信人进行分组 */ public static Map> groupSmsReceiver(List smsReceiverList, List agentOrgList) { Map> groupMap = new HashMap<>(); if (smsReceiverList == null || smsReceiverList.isEmpty()) { return groupMap; } if (agentOrgList == null || agentOrgList.isEmpty()) { return groupMap; } for (SysUserEntity smsReceiver : smsReceiverList) { String targetAgentOrgName = getTargetAgentOrgName(smsReceiver.getAgentOrgId(), agentOrgList); if (groupMap.containsKey(targetAgentOrgName)) { List groupSmsReceiverList = groupMap.get(targetAgentOrgName); groupSmsReceiverList.add(smsReceiver); } else { List groupSmsReceiverList = new ArrayList<>(); groupSmsReceiverList.add(smsReceiver); groupMap.put(targetAgentOrgName, groupSmsReceiverList); } } return groupMap; } /** * 获取系统用户的代理组织名称 */ public static String getTargetAgentOrgName(Long agentOrgId, List agentOrgList) { for (AgentOrgEntity agentOrg : agentOrgList) { try { if (agentOrgId.longValue() == agentOrg.getId().longValue()) { return agentOrg.getOrgName(); } } catch (Exception e) { e.printStackTrace(); } } return "青岛星科瑞升信息科技有限公司"; } }