fire_point/src/main/java/com/xkrs/utils/FirePointCodeUtils.java

133 lines
5.2 KiB
Java
Raw Normal View History

2022-06-08 09:23:33 +08:00
package com.xkrs.utils;
2022-07-06 15:43:26 +08:00
import com.xkrs.model.entity.AgentOrgEntity;
import com.xkrs.model.entity.RelRoleAuthorityEntity;
import com.xkrs.model.entity.SysUserEntity;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2022-06-08 09:23:33 +08:00
public class FirePointCodeUtils {
private FirePointCodeUtils() {
}
public static String getCodeNotZeroEnd(String code) throws Exception {
String codeNotZeroEnd = code;
while (codeNotZeroEnd.endsWith("0")) {
codeNotZeroEnd = codeNotZeroEnd.substring(0, codeNotZeroEnd.length() - 1);
}
return codeNotZeroEnd;
}
/**
* 过滤短信通知收信人
*
* @param firePointStreetCode 火点的街道编号
* @param sysUserList 系统用户列表
* @param adminList 管理员列表
* @param normalSmsEnable 普通用户能否接收短信通知
* @param vipSmsEnable VIP用户能否接收短信通知
* @return 短信通知收信人列表
*/
public static List<SysUserEntity> filterSmsReceiver(String firePointStreetCode, List<SysUserEntity> sysUserList, List<RelRoleAuthorityEntity> adminList, boolean normalSmsEnable, boolean vipSmsEnable) {
List<SysUserEntity> smsReceiverList = new ArrayList<>();
if (sysUserList == null || sysUserList.isEmpty()) {
return smsReceiverList;
}
for (SysUserEntity sysUser : sysUserList) {
try {
String codeNotZeroEnd = FirePointCodeUtils.getCodeNotZeroEnd(sysUser.getCountyCode());
if (firePointStreetCode.startsWith(codeNotZeroEnd)) {
if (sysUser.getDeleteFlag() != 0) {//被删除的用户不发短信
continue;
}
if (sysUser.getActiveFlag() != 0) {//被禁用的用户不发短信
continue;
}
if (sysUser.getReceiveSms() != 1) {//关掉开关的用户不发短信
continue;
}
LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME);
if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {
if (!normalSmsEnable) {//根据配置信息决定普通用户是否发送短信
continue;
}
} else {
if (!vipSmsEnable) {//根据配置信息决定VIP用户是否发送短信
continue;
}
}
if (isAdmin(adminList, sysUser)) {//管理员用户不发短信
continue;
}
smsReceiverList.add(sysUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return smsReceiverList;
}
/**
* 判断是否是管理员
*/
private static boolean isAdmin(List<RelRoleAuthorityEntity> administratorList, SysUserEntity sysUser) {
if (administratorList == null || administratorList.size() == 0) {
return false;
}
for (RelRoleAuthorityEntity administrator : administratorList) {
if (administrator.getUserId().intValue() == sysUser.getId().intValue()) {
return true;
}
}
return false;
}
/**
* 对短信通知收信人进行分组
*/
2022-07-06 15:43:26 +08:00
public static Map<String, List<SysUserEntity>> groupSmsReceiver(List<SysUserEntity> smsReceiverList, List<AgentOrgEntity> agentOrgList) {
Map<String, List<SysUserEntity>> 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, agentOrgList);
if (groupMap.containsKey(targetAgentOrgName)) {
List<SysUserEntity> groupSmsReceiverList = groupMap.get(targetAgentOrgName);
groupSmsReceiverList.add(smsReceiver);
} else {
List<SysUserEntity> groupSmsReceiverList = new ArrayList<>();
groupSmsReceiverList.add(smsReceiver);
groupMap.put(targetAgentOrgName, groupSmsReceiverList);
}
}
2022-07-06 15:43:26 +08:00
return groupMap;
}
/**
* 获取系统用户的代理组织名称
*/
private static String getTargetAgentOrgName(SysUserEntity smsReceiver, List<AgentOrgEntity> agentOrgList) {
for (AgentOrgEntity agentOrg : agentOrgList) {
try {
if (smsReceiver.getAgentOrgId().longValue() == agentOrg.getId().longValue()) {
return agentOrg.getOrgName();
}
2022-07-06 15:43:26 +08:00
} catch (Exception e) {
e.printStackTrace();
}
}
2022-07-06 15:43:26 +08:00
return "青岛星科瑞升信息科技有限公司";
}
2022-06-08 09:23:33 +08:00
}