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

83 lines
3.3 KiB
Java

package com.xkrs.utils;
import com.xkrs.straw.model.entity.SysUserEntity;
import org.apache.hc.core5.util.TextUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
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<SysUserEntity> filterSmsReceiver(String firePointStreetCode, List<SysUserEntity> sysUserList, boolean normalSmsEnable, boolean vipSmsEnable) {
List<SysUserEntity> 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;
}
}