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

80 lines
3.1 KiB
Java
Raw Normal View History

2022-06-08 09:23:33 +08:00
package com.xkrs.utils;
2023-02-03 17:03:47 +08:00
import com.xkrs.straw.model.entity.SysUserEntity;
2023-02-14 16:36:57 +08:00
import com.xkrs.straw.utils.VipTimeRangeUtils;
import org.apache.hc.core5.util.TextUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
2022-06-08 09:23:33 +08:00
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();
2022-06-08 09:23:33 +08:00
}
int length = formatCutCode.length();
if (1 == length || 3 == length || 5 == length || 8 == length) {
return formatCutCode + "0";
}
if (7 == length) {
return length + "00";
}
return formatCutCode;
2022-06-08 09:23:33 +08:00
}
/**
* 过滤短信通知收信人
*
* @param firePointStreetCode 火点的街道编号
* @param sysUserList 系统用户列表
* @param normalSmsEnable 普通用户能否接收短信通知
* @param vipSmsEnable VIP用户能否接收短信通知
* @return 短信通知收信人列表
*/
2023-01-30 14:07:03 +08:00
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.getActiveFlag() != 0) {//被禁用的用户不发短信
continue;
}
if (sysUser.getReceiveSms() != 1) {//关掉开关的用户不发短信
continue;
2023-01-30 14:07:03 +08:00
}
if ("管理员".equals(sysUser.getAccountType())) {//管理员用户不发短信
continue;
}
2023-02-14 16:36:57 +08:00
boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUser.getVipTimeRangeJson());
LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME);
2023-02-14 14:08:50 +08:00
if (sysUserOverDateTime.isBefore(LocalDateTime.now())) {
if (!normalSmsEnable) {//根据配置信息决定普通用户是否发送短信
continue;
}
} else {
if (!vipSmsEnable) {//根据配置信息决定VIP用户是否发送短信
continue;
}
}
smsReceiverList.add(sysUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return smsReceiverList;
}
2022-06-08 09:23:33 +08:00
}