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

140 lines
5.7 KiB
Java
Raw Normal View History

2022-06-08 09:23:33 +08:00
package com.xkrs.utils;
import com.xkrs.model.entity.AgentCompanyEntity;
import com.xkrs.model.entity.RelRoleAuthorityEntity;
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;
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;
}
/**
* 对短信通知收信人进行分组
*
* @param smsReceiverList 短信通知收信人列表
* @param master 星科瑞升
* @param agentCompanyList 代理公司列表
* @return 分组后的短信通知收信人列表
*/
public static Map<AgentCompanyEntity, List<SysUserEntity>> groupSmsReceiver(List<SysUserEntity> smsReceiverList, AgentCompanyEntity master, List<AgentCompanyEntity> agentCompanyList) {
//数据仓库
Map<AgentCompanyEntity, List<SysUserEntity>> groupMap = new HashMap<>();
//填充代理公司数据
if (agentCompanyList != null && agentCompanyList.size() > 0) {
for (AgentCompanyEntity agentCompany : agentCompanyList) {
try {
if (TextUtils.isEmpty(agentCompany.getCountyCode())) {//区划编码为空的不发短信
continue;
}
String codeNotZeroEnd = FirePointCodeUtils.getCodeNotZeroEnd(agentCompany.getCountyCode());
if (TextUtils.isEmpty(codeNotZeroEnd)) {//区划编码后切完0为空的不发短信
continue;
}
List<SysUserEntity> receiverList = new ArrayList<>();
for (SysUserEntity smsReceiver : smsReceiverList) {
if (smsReceiver.getCountyCode().startsWith(codeNotZeroEnd)) {
receiverList.add(smsReceiver);
}
}
groupMap.put(agentCompany, receiverList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
//填充星科瑞升数据
List<SysUserEntity> masterReceiverList = new ArrayList<>();
for (Map.Entry<AgentCompanyEntity, List<SysUserEntity>> entry : groupMap.entrySet()) {
for (SysUserEntity smsReceiver : entry.getValue()) {
if (!smsReceiverList.contains(smsReceiver)) {
masterReceiverList.add(smsReceiver);
}
}
}
groupMap.put(master, masterReceiverList);
return groupMap;
}
2022-06-08 09:23:33 +08:00
}