添加全局配置服务

This commit is contained in:
liuchengqian 2022-06-16 11:27:42 +08:00
parent 18074cf605
commit 1af9c92788
16 changed files with 585 additions and 206 deletions

View File

@ -2,6 +2,7 @@ package com.xkrs.common.account;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.service.ConfigGlobalUserService;
import com.xkrs.service.SysAuthorityService;
import com.xkrs.service.SysRoleService;
import com.xkrs.service.SysUserService;
@ -25,6 +26,7 @@ import static com.xkrs.utils.EncryptDecryptUtil.encry256;
/**
* 自定义认证Provider
*
* @author tajochen
*/
@Component
@ -39,6 +41,9 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
@Resource
private SysAuthorityService sysAuthorityService;
@Resource
private ConfigGlobalUserService configGlobalUserService;
/**
* 初使化时将已静态化的Service实例化
*/
@ -53,10 +58,12 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
customAuthenticationProvider.sysUserService = this.sysUserService;
customAuthenticationProvider.sysRoleService = this.sysRoleService;
customAuthenticationProvider.sysAuthorityService = this.sysAuthorityService;
customAuthenticationProvider.configGlobalUserService = this.configGlobalUserService;
}
/**
* 用户认证授权
*
* @param authentication
* @return
* @throws AuthenticationException
@ -70,23 +77,25 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
SysUserEntity userEntity = customAuthenticationProvider.sysUserService.getSysUserByUserName(userName);
// 检查用户是否存在
if(userEntity == null){
if (userEntity == null) {
throw new BadCredentialsException("账号不存在或错误,请您确认注册");
}
// 检查用户是否激活
if(userEntity.getActiveFlag().intValue() != 0){
if (userEntity.getActiveFlag().intValue() != 0) {
throw new DisabledException("该账号还未激活,请联系管理员");
}
//检查用户状态是否正常
if(userEntity.getStatusCode() != 0){
if (userEntity.getStatusCode() != 0) {
throw new DisabledException("用户状态不正常,请联系管理员");
}
if(userEntity.getDayNum() == 7){
if(DateTimeUtil.dateTimeToString(LocalDateTime.now()).compareTo(userEntity.getOverTime()) > 0){
throw new DisabledException("该账号已过期,请联系管理员");
if (userEntity.getDayNum() == 7) {
if (DateTimeUtil.dateTimeToString(LocalDateTime.now()).compareTo(userEntity.getOverTime()) > 0) {
if (!customAuthenticationProvider.configGlobalUserService.loginAbleWhenExpired()) {
throw new DisabledException("该账号已过期,请联系管理员");
}
}
}
@ -97,22 +106,22 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
List<Integer> integers = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId());
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.findAllByIdIn(integers);
for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
for (SysAuthorityEntity sysAuthorityEntity : permissionList) {
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
}
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1);
customAuthenticationProvider.sysUserService.updateLoginLastTime(userEntity.getId(),DateTimeUtil.dateTimeToString(LocalDateTime.now()));
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(), userEntity.getLoginNum() + 1);
customAuthenticationProvider.sysUserService.updateLoginLastTime(userEntity.getId(), DateTimeUtil.dateTimeToString(LocalDateTime.now()));
// 生成令牌
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
return authToken;
}
else {
} else {
throw new BadCredentialsException("用户密码错误,请重新输入");
}
}
/**
* 是否可以提供输入类型的认证服务
*
* @param authentication
* @return
*/

View File

@ -2,7 +2,10 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.ConfigGlobalFirePointEntity;
import com.xkrs.model.vo.ConfigVo;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.ConfigGlobalFirePointService;
import com.xkrs.service.SysUserService;
import com.xkrs.utils.IpUtil;
import org.slf4j.Logger;
@ -21,7 +24,6 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.annotation.Resource;
import javax.servlet.FilterChain;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -41,6 +43,9 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
@Resource
private SysUserService sysUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
public JwtLoginFilter(String url, AuthenticationManager authManager) {
super(new AntPathRequestMatcher(url));
setAuthenticationManager(authManager);
@ -48,10 +53,6 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
/**
* 登录时验证
*
* @param req
* @param res
* @return
*/
@Override
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException {
@ -79,13 +80,6 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
/**
* 验证成功后调用
*
* @param req
* @param response
* @param chain
* @param auth
* @throws IOException
* @throws ServletException
*/
@Override
protected void successfulAuthentication(HttpServletRequest req, HttpServletResponse response, FilterChain chain, Authentication auth) {
@ -94,6 +88,12 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
sysUserService = webApplicationContext.getBean(SysUserService.class);
}
if (configGlobalFirePointService == null) {
ServletContext servletContext = req.getServletContext();
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
configGlobalFirePointService = webApplicationContext.getBean(ConfigGlobalFirePointService.class);
}
ConfigVo config = getConfigVo();
//更新用户登录信息
sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req));
SysUserVo userByUserName = sysUserService.getUserByUserName(auth.getName());
@ -101,16 +101,31 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
response.setHeader("Access-Control-Allow-Credentials", "false");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName);
TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, config);
}
/**
* 生成配置信息
*/
private ConfigVo getConfigVo() {
ConfigVo config = new ConfigVo();
ConfigGlobalFirePointEntity firePointGlobalConfig = configGlobalFirePointService.findFirePointGlobalConfig();
if (firePointGlobalConfig == null) {
config.setTodayAbleWhenExpired(1L);
config.setHistoryAbleWhenExpired(0L);
config.setStatisticsAbleWhenExpired(1L);
config.setNavigateAbleWhenExpired(0L);
} else {
config.setTodayAbleWhenExpired(firePointGlobalConfig.getTodayAbleWhenExpired());
config.setHistoryAbleWhenExpired(firePointGlobalConfig.getHistoryAbleWhenExpired());
config.setStatisticsAbleWhenExpired(firePointGlobalConfig.getStatisticsAbleWhenExpired());
config.setNavigateAbleWhenExpired(firePointGlobalConfig.getNavigateAbleWhenExpired());
}
return config;
}
/**
* 验证失败后调用
*
* @param request
* @param response
* @param failed
* @throws IOException
*/
@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {

View File

@ -2,8 +2,8 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.model.vo.ConfigVo;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.utils.DateTimeUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
@ -19,8 +19,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
/**
@ -54,7 +52,7 @@ public class TokenAuthenticationService {
* @param userName
* @param authorities
*/
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity) {
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity, ConfigVo config) {
Locale locale = new Locale("zh", "CN");
Map map = new HashMap(3);
@ -69,43 +67,61 @@ public class TokenAuthenticationService {
} else {
logger.warn(userName + " has no permission!");
}
if (sysUserEntity.getDayNum() == 7) {
// 结束的时间
LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
// 计算距离结束时间的天数作为token
Duration duration = Duration.between(LocalDateTime.now(), overTime);
/**
* 动态设置过期时间
*/
final long EXPIRATIONTIME = 60 * 60 * (duration.toDays() + 1) * 24_000;
// if (sysUserEntity.getDayNum() == 7) {
// // 结束的时间
// LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
// // 计算距离结束时间的天数作为token
// Duration duration = Duration.between(LocalDateTime.now(), overTime);
// /**
// * 动态设置过期时间
// */
// final long EXPIRATIONTIME = 60 * 60 * (duration.toDays() + 1) * 24_000;
//
// // 生成JWT
// String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName)
// // 保存权限
// .claim("auths", authsList)
// // 有效期设置
// .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
// // 签名设置
// .signWith(key).compact();
// map.put("token", jwt);
// map.put("user", sysUserEntity);
// map.put("config", config);
// } else {
// /**
// * 过期时间6小时
// */
// final long EXPIRATIONTIME = 21_600_000;
//
// // 生成JWT
// String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName)
// // 保存权限
// .claim("auths", authsList)
// // 有效期设置
// .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
// // 签名设置
// .signWith(key).compact();
// map.put("token", jwt);
// map.put("user", sysUserEntity);
// map.put("config", config);
// }
/**
* 过期时间6小时
*/
final long EXPIRATIONTIME = 21_600_000;
// 生成JWT
String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName)
// 保存权限
.claim("auths", authsList)
// 有效期设置
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
// 签名设置
.signWith(key).compact();
map.put("token", jwt);
map.put("user", sysUserEntity);
} else {
/**
* 过期时间6小时
*/
final long EXPIRATIONTIME = 21_600_000;
// 生成JWT
String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName)
// 保存权限
.claim("auths", authsList)
// 有效期设置
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
// 签名设置
.signWith(key).compact();
map.put("token", jwt);
map.put("user", sysUserEntity);
}
// 生成JWT
String jwt = Jwts.builder().setSubject(userName).setIssuer("https://www.microservice.com").setAudience(userName)
// 保存权限
.claim("auths", authsList)
// 有效期设置
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
// 签名设置
.signWith(key).compact();
map.put("token", jwt);
map.put("user", sysUserEntity);
map.put("config", config);
// JWT 写入 body
PrintWriter out = null;
try {

View File

@ -1,6 +1,8 @@
package com.xkrs.controller;
import com.xkrs.service.ConfigGlobalService;
import com.xkrs.service.ConfigGlobalFirePointService;
import com.xkrs.service.ConfigGlobalSMSService;
import com.xkrs.service.ConfigGlobalUserService;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -16,30 +18,25 @@ import java.util.Map;
public class ConfigGlobalController {
@Resource
private ConfigGlobalService configGlobalService;
private ConfigGlobalUserService configGlobalUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
@Resource
private ConfigGlobalSMSService configGlobalSMSService;
/**
* 用户全局配置服务
*/
@PostMapping("/configGlobalUser")
public String configGlobalUser(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalService.configGlobalUser(configMap);
return configGlobalUserService.configGlobalUser(configMap);
}
/**
* 火情信息全局配置服务
*/
@PostMapping("/configGlobalFirePoint")
public String configGlobalFirePoint(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalService.configGlobalFirePoint(configMap);
return configGlobalFirePointService.configGlobalFirePoint(configMap);
}
/**
* 短信全局配置服务
*/
@PostMapping("/configGlobalSMS")
public String configGlobalSMS(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalService.configGlobalSMS(configMap);
return configGlobalSMSService.configGlobalSMS(configMap);
}
}

View File

@ -20,21 +20,29 @@ public class ConfigGlobalFirePointEntity implements Serializable {
/**
* 过期后能否获取今日火情信息
* 0不能获取
* 1能够获取
*/
private Long todayAbleWhenExpired;
/**
* 过期后能否获取历史火情信息
* 0不能获取
* 1能够获取
*/
private Long historyAbleWhenExpired;
/**
* 过期后能否获取统计分析数据
* 0不能获取
* 1能够获取
*/
private Long statisticsAbleWhenExpired;
/**
* 过期后能否使用导航功能
* 0不能导航
* 1能够导航
*/
private Long navigateAbleWhenExpired;

View File

@ -27,41 +27,53 @@ public class ConfigGlobalSMSEntity implements Serializable {
/**
* 省过期前能否提前通知
* 0不能通知
* 1能够通知
*/
private Long proAnAbleBeforeExpired;
/**
* 省过期前提前几天短信通知
* 天数
*/
private Long proAnDayBeforeExpired;
/**
* 市过期前能否提前通知
* 0不能通知
* 1能够通知
*/
private Long cityAnAbleBeforeExpired;
/**
* 市过期前提前几天短信通知
* 天数
*/
private Long cityAnDayBeforeExpired;
/**
* 区县过期前能否提前通知
* 0不能通知
* 1能够通知
*/
private Long countyAnAbleBeforeExpired;
/**
* 区县过期前提前几天短信通知
* 天数
*/
private Long countyAnDayBeforeExpired;
/**
* 街道过期前能否提前通知
* 0不能通知
* 1能够通知
*/
private Long streetAnAbleBeforeExpired;
/**
* 街道过期前提前几天短信通知
* 天数
*/
private Long streetAnDayBeforeExpired;

View File

@ -0,0 +1,69 @@
package com.xkrs.model.vo;
import java.io.Serializable;
public class ConfigVo implements Serializable {
/**
* 过期后能否获取今日火情信息
* 0不能获取
* 1能够获取
*/
private Long todayAbleWhenExpired;
/**
* 过期后能否获取历史火情信息
* 0不能获取
* 1能够获取
*/
private Long historyAbleWhenExpired;
/**
* 过期后能否获取统计分析数据
* 0不能获取
* 1能够获取
*/
private Long statisticsAbleWhenExpired;
/**
* 过期后能否使用导航功能
* 0不能导航
* 1能够导航
*/
private Long navigateAbleWhenExpired;
public ConfigVo() {
}
public Long getTodayAbleWhenExpired() {
return todayAbleWhenExpired;
}
public void setTodayAbleWhenExpired(Long todayAbleWhenExpired) {
this.todayAbleWhenExpired = todayAbleWhenExpired;
}
public Long getHistoryAbleWhenExpired() {
return historyAbleWhenExpired;
}
public void setHistoryAbleWhenExpired(Long historyAbleWhenExpired) {
this.historyAbleWhenExpired = historyAbleWhenExpired;
}
public Long getStatisticsAbleWhenExpired() {
return statisticsAbleWhenExpired;
}
public void setStatisticsAbleWhenExpired(Long statisticsAbleWhenExpired) {
this.statisticsAbleWhenExpired = statisticsAbleWhenExpired;
}
public Long getNavigateAbleWhenExpired() {
return navigateAbleWhenExpired;
}
public void setNavigateAbleWhenExpired(Long navigateAbleWhenExpired) {
this.navigateAbleWhenExpired = navigateAbleWhenExpired;
}
}

View File

@ -0,0 +1,24 @@
package com.xkrs.service;
import com.xkrs.model.entity.ConfigGlobalFirePointEntity;
import java.util.Map;
/**
* 火情信息全局配置服务
*/
public interface ConfigGlobalFirePointService {
boolean todayAbleWhenExpired();
boolean historyAbleWhenExpired();
boolean statisticsAbleWhenExpired();
boolean navigateAbleWhenExpired();
ConfigGlobalFirePointEntity findFirePointGlobalConfig();
String configGlobalFirePoint(Map<String, Long> configMap);
}

View File

@ -0,0 +1,30 @@
package com.xkrs.service;
import java.util.Map;
/**
* 短信全局配置服务
*/
public interface ConfigGlobalSMSService {
boolean smsAbleWhenExpired();
boolean proAnAbleBeforeExpired();
long proAnDayBeforeExpired();
boolean cityAnAbleBeforeExpired();
long cityAnDayBeforeExpired();
boolean countyAnAbleBeforeExpired();
long countyAnDayBeforeExpired();
boolean streetAnAbleBeforeExpired();
long streetAnDayBeforeExpired();
String configGlobalSMS(Map<String, Long> configMap);
}

View File

@ -1,25 +0,0 @@
package com.xkrs.service;
import java.util.Map;
/**
* 全局配置服务
*/
public interface ConfigGlobalService {
/**
* 用户全局配置服务
*/
String configGlobalUser(Map<String, Long> configMap);
/**
* 火情信息全局配置服务
*/
String configGlobalFirePoint(Map<String, Long> configMap);
/**
* 短信全局配置服务
*/
String configGlobalSMS(Map<String, Long> configMap);
}

View File

@ -0,0 +1,14 @@
package com.xkrs.service;
import java.util.Map;
/**
* 用户全局配置服务
*/
public interface ConfigGlobalUserService {
boolean loginAbleWhenExpired();
String configGlobalUser(Map<String, Long> configMap);
}

View File

@ -0,0 +1,126 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.ConfigGlobalFirePointDao;
import com.xkrs.model.entity.ConfigGlobalFirePointEntity;
import com.xkrs.service.ConfigGlobalFirePointService;
import com.xkrs.utils.ConfigConstant;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 火情信息全局配置服务
*/
@Service
public class ConfigGlobalFirePointServiceImpl implements ConfigGlobalFirePointService {
private final Locale locale = LocaleContextHolder.getLocale();
/**
* 火情信息全局配置信息
*/
@Resource
private ConfigGlobalFirePointDao configGlobalFirePointDao;
@Override
public boolean todayAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalFirePointDao.findAll().get(0).getTodayAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean historyAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalFirePointDao.findAll().get(0).getHistoryAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean statisticsAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalFirePointDao.findAll().get(0).getStatisticsAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean navigateAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalFirePointDao.findAll().get(0).getNavigateAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public ConfigGlobalFirePointEntity findFirePointGlobalConfig() {
try {
return configGlobalFirePointDao.findAll().get(0);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public String configGlobalFirePoint(Map<String, Long> configMap) {
if (configMap == null) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
}
Long todayAbleWhenExpired = configMap.get("todayAbleWhenExpired");
Long historyAbleWhenExpired = configMap.get("historyAbleWhenExpired");
Long statisticsAbleWhenExpired = configMap.get("statisticsAbleWhenExpired");
Long navigateAbleWhenExpired = configMap.get("navigateAbleWhenExpired");
List<ConfigGlobalFirePointEntity> configGlobalFirePointEntityList = configGlobalFirePointDao.findAll();
if (configGlobalFirePointEntityList.isEmpty()) {
ConfigGlobalFirePointEntity configGlobalFirePointEntity = new ConfigGlobalFirePointEntity();
configGlobalFirePointEntity.setTodayAbleWhenExpired(todayAbleWhenExpired);
configGlobalFirePointEntity.setHistoryAbleWhenExpired(historyAbleWhenExpired);
configGlobalFirePointEntity.setStatisticsAbleWhenExpired(statisticsAbleWhenExpired);
configGlobalFirePointEntity.setNavigateAbleWhenExpired(navigateAbleWhenExpired);
configGlobalFirePointDao.save(configGlobalFirePointEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
ConfigGlobalFirePointEntity configGlobalFirePointEntity = configGlobalFirePointEntityList.get(0);
if (todayAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getTodayAbleWhenExpired() == null || configGlobalFirePointEntity.getTodayAbleWhenExpired().longValue() != todayAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setTodayAbleWhenExpired(todayAbleWhenExpired);
}
}
if (historyAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getHistoryAbleWhenExpired() == null || configGlobalFirePointEntity.getHistoryAbleWhenExpired().longValue() != historyAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setHistoryAbleWhenExpired(historyAbleWhenExpired);
}
}
if (statisticsAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getStatisticsAbleWhenExpired() == null || configGlobalFirePointEntity.getStatisticsAbleWhenExpired().longValue() != statisticsAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setStatisticsAbleWhenExpired(statisticsAbleWhenExpired);
}
}
if (navigateAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getNavigateAbleWhenExpired() == null || configGlobalFirePointEntity.getNavigateAbleWhenExpired().longValue() != navigateAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setNavigateAbleWhenExpired(navigateAbleWhenExpired);
}
}
configGlobalFirePointDao.save(configGlobalFirePointEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
}

View File

@ -1,13 +1,10 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.ConfigGlobalFirePointDao;
import com.xkrs.dao.ConfigGlobalSMSDao;
import com.xkrs.dao.ConfigGlobalUserDao;
import com.xkrs.model.entity.ConfigGlobalFirePointEntity;
import com.xkrs.model.entity.ConfigGlobalSMSEntity;
import com.xkrs.model.entity.ConfigGlobalUserEntity;
import com.xkrs.service.ConfigGlobalService;
import com.xkrs.service.ConfigGlobalSMSService;
import com.xkrs.utils.ConfigConstant;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
@ -19,121 +16,123 @@ import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 全局配置服务
* 短信全局配置服务
*/
@Service
public class ConfigGlobalServiceImpl implements ConfigGlobalService {
public class ConfigGlobalSMSServiceImpl implements ConfigGlobalSMSService {
private final Locale locale = LocaleContextHolder.getLocale();
/**
* 用户全局配置信息
*/
@Resource
private ConfigGlobalUserDao configGlobalUserDao;
/**
* 火情信息全局配置信息
*/
@Resource
private ConfigGlobalFirePointDao configGlobalFirePointDao;
/**
* 短信全局配置信息
*/
@Resource
private ConfigGlobalSMSDao configGlobalSMSDao;
/**
* 用户全局配置服务
*/
@Override
public String configGlobalUser(Map<String, Long> configMap) {
if (configMap == null) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
public boolean smsAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getSmsAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
Long loginAbleWhenExpired = configMap.get("LoginAbleWhenExpired");
List<ConfigGlobalUserEntity> configGlobalUserEntityList = configGlobalUserDao.findAll();
if (configGlobalUserEntityList.isEmpty()) {
ConfigGlobalUserEntity configGlobalUserEntity = new ConfigGlobalUserEntity();
configGlobalUserEntity.setLoginAbleWhenExpired(loginAbleWhenExpired);
configGlobalUserDao.save(configGlobalUserEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
ConfigGlobalUserEntity configGlobalUserEntity = configGlobalUserEntityList.get(0);
if (loginAbleWhenExpired != null) {
if (configGlobalUserEntity.getLoginAbleWhenExpired() == null || configGlobalUserEntity.getLoginAbleWhenExpired().longValue() != loginAbleWhenExpired.longValue()) {
configGlobalUserEntity.setLoginAbleWhenExpired(loginAbleWhenExpired);
}
}
configGlobalUserDao.save(configGlobalUserEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
return false;
}
/**
* 火情信息全局配置服务
*/
@Override
public String configGlobalFirePoint(Map<String, Long> configMap) {
if (configMap == null) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
public boolean proAnAbleBeforeExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getProAnAbleBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
Long todayAbleWhenExpired = configMap.get("TodayAbleWhenExpired");
Long historyAbleWhenExpired = configMap.get("HistoryAbleWhenExpired");
Long statisticsAbleWhenExpired = configMap.get("StatisticsAbleWhenExpired");
Long navigateAbleWhenExpired = configMap.get("NavigateAbleWhenExpired");
List<ConfigGlobalFirePointEntity> configGlobalFirePointEntityList = configGlobalFirePointDao.findAll();
if (configGlobalFirePointEntityList.isEmpty()) {
ConfigGlobalFirePointEntity configGlobalFirePointEntity = new ConfigGlobalFirePointEntity();
configGlobalFirePointEntity.setTodayAbleWhenExpired(todayAbleWhenExpired);
configGlobalFirePointEntity.setHistoryAbleWhenExpired(historyAbleWhenExpired);
configGlobalFirePointEntity.setStatisticsAbleWhenExpired(statisticsAbleWhenExpired);
configGlobalFirePointEntity.setNavigateAbleWhenExpired(navigateAbleWhenExpired);
configGlobalFirePointDao.save(configGlobalFirePointEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
ConfigGlobalFirePointEntity configGlobalFirePointEntity = configGlobalFirePointEntityList.get(0);
if (todayAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getTodayAbleWhenExpired() == null || configGlobalFirePointEntity.getTodayAbleWhenExpired().longValue() != todayAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setTodayAbleWhenExpired(todayAbleWhenExpired);
}
}
if (historyAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getHistoryAbleWhenExpired() == null || configGlobalFirePointEntity.getHistoryAbleWhenExpired().longValue() != historyAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setHistoryAbleWhenExpired(historyAbleWhenExpired);
}
}
if (statisticsAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getStatisticsAbleWhenExpired() == null || configGlobalFirePointEntity.getStatisticsAbleWhenExpired().longValue() != statisticsAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setStatisticsAbleWhenExpired(statisticsAbleWhenExpired);
}
}
if (navigateAbleWhenExpired != null) {
if (configGlobalFirePointEntity.getNavigateAbleWhenExpired() == null || configGlobalFirePointEntity.getNavigateAbleWhenExpired().longValue() != navigateAbleWhenExpired.longValue()) {
configGlobalFirePointEntity.setNavigateAbleWhenExpired(navigateAbleWhenExpired);
}
}
configGlobalFirePointDao.save(configGlobalFirePointEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
return false;
}
@Override
public long proAnDayBeforeExpired() {
try {
return configGlobalSMSDao.findAll().get(0).getProAnDayBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
@Override
public boolean cityAnAbleBeforeExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getCityAnAbleBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public long cityAnDayBeforeExpired() {
try {
return configGlobalSMSDao.findAll().get(0).getCityAnDayBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
@Override
public boolean countyAnAbleBeforeExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getCountyAnAbleBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public long countyAnDayBeforeExpired() {
try {
return configGlobalSMSDao.findAll().get(0).getCountyAnDayBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
@Override
public boolean streetAnAbleBeforeExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getStreetAnAbleBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public long streetAnDayBeforeExpired() {
try {
return configGlobalSMSDao.findAll().get(0).getStreetAnDayBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
/**
* 短信全局配置服务
*/
@Override
public String configGlobalSMS(Map<String, Long> configMap) {
if (configMap == null) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
}
Long smsAbleWhenExpired = configMap.get("SmsAbleWhenExpired");
Long proAnAbleBeforeExpired = configMap.get("ProAnAbleBeforeExpired");
Long proAnDayBeforeExpired = configMap.get("ProAnDayBeforeExpired");
Long cityAnAbleBeforeExpired = configMap.get("CityAnAbleBeforeExpired");
Long cityAnDayBeforeExpired = configMap.get("CityAnDayBeforeExpired");
Long countyAnAbleBeforeExpired = configMap.get("CountyAnAbleBeforeExpired");
Long countyAnDayBeforeExpired = configMap.get("CountyAnDayBeforeExpired");
Long streetAnAbleBeforeExpired = configMap.get("StreetAnAbleBeforeExpired");
Long streetAnDayBeforeExpired = configMap.get("StreetAnDayBeforeExpired");
Long smsAbleWhenExpired = configMap.get("smsAbleWhenExpired");
Long proAnAbleBeforeExpired = configMap.get("proAnAbleBeforeExpired");
Long proAnDayBeforeExpired = configMap.get("proAnDayBeforeExpired");
Long cityAnAbleBeforeExpired = configMap.get("cityAnAbleBeforeExpired");
Long cityAnDayBeforeExpired = configMap.get("cityAnDayBeforeExpired");
Long countyAnAbleBeforeExpired = configMap.get("countyAnAbleBeforeExpired");
Long countyAnDayBeforeExpired = configMap.get("countyAnDayBeforeExpired");
Long streetAnAbleBeforeExpired = configMap.get("streetAnAbleBeforeExpired");
Long streetAnDayBeforeExpired = configMap.get("streetAnDayBeforeExpired");
List<ConfigGlobalSMSEntity> configGlobalSMSEntityList = configGlobalSMSDao.findAll();
if (configGlobalSMSEntityList.isEmpty()) {
ConfigGlobalSMSEntity configGlobalSMSEntity = new ConfigGlobalSMSEntity();

View File

@ -0,0 +1,65 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.ConfigGlobalUserDao;
import com.xkrs.model.entity.ConfigGlobalUserEntity;
import com.xkrs.service.ConfigGlobalUserService;
import com.xkrs.utils.ConfigConstant;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 用户全局配置服务
*/
@Service
public class ConfigGlobalUserServiceImpl implements ConfigGlobalUserService {
private final Locale locale = LocaleContextHolder.getLocale();
/**
* 用户全局配置信息
*/
@Resource
private ConfigGlobalUserDao configGlobalUserDao;
@Override
public boolean loginAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalUserDao.findAll().get(0).getLoginAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public String configGlobalUser(Map<String, Long> configMap) {
if (configMap == null) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
}
Long loginAbleWhenExpired = configMap.get("loginAbleWhenExpired");
List<ConfigGlobalUserEntity> configGlobalUserEntityList = configGlobalUserDao.findAll();
if (configGlobalUserEntityList.isEmpty()) {
ConfigGlobalUserEntity configGlobalUserEntity = new ConfigGlobalUserEntity();
configGlobalUserEntity.setLoginAbleWhenExpired(loginAbleWhenExpired);
configGlobalUserDao.save(configGlobalUserEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
ConfigGlobalUserEntity configGlobalUserEntity = configGlobalUserEntityList.get(0);
if (loginAbleWhenExpired != null) {
if (configGlobalUserEntity.getLoginAbleWhenExpired() == null || configGlobalUserEntity.getLoginAbleWhenExpired().longValue() != loginAbleWhenExpired.longValue()) {
configGlobalUserEntity.setLoginAbleWhenExpired(loginAbleWhenExpired);
}
}
configGlobalUserDao.save(configGlobalUserEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
}

View File

@ -8,6 +8,9 @@ import com.xkrs.model.qo.FirePointQo;
import com.xkrs.model.vo.AppPhotoVo;
import com.xkrs.model.vo.AppTaskBodyVo;
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
import com.xkrs.service.ConfigGlobalFirePointService;
import com.xkrs.service.ConfigGlobalSMSService;
import com.xkrs.service.ConfigGlobalUserService;
import com.xkrs.service.FirePointService;
import com.xkrs.utils.*;
import org.slf4j.Logger;
@ -84,6 +87,13 @@ public class FirePointServiceImpl implements FirePointService {
@Resource
private FirePointQueryHelper firePointQueryHelper;
@Resource
private ConfigGlobalUserService configGlobalUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
@Resource
private ConfigGlobalSMSService configGlobalSMSService;
/**
* 添加火点信息
@ -423,8 +433,11 @@ public class FirePointServiceImpl implements FirePointService {
continue;
}
LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME);
if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {//过期用户不发短信
continue;
if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {//过期用户
//过期用户需要根据配置决定是否发送短信
if (!configGlobalSMSService.smsAbleWhenExpired()) {
continue;
}
}
if (isAdministrator(administratorList, sysUser)) {//管理员用户不发短信
continue;

View File

@ -0,0 +1,7 @@
package com.xkrs.utils;
public interface ConfigConstant {
Long STATE_ACTIVE = 1L;
}