From 1af9c9278837df1a98cac66934ee7c4c6b17e1c7 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 16 Jun 2022 11:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/CustomAuthenticationProvider.java | 31 ++- .../xkrs/common/account/JwtLoginFilter.java | 51 +++-- .../account/TokenAuthenticationService.java | 96 +++++---- .../controller/ConfigGlobalController.java | 25 +-- .../entity/ConfigGlobalFirePointEntity.java | 8 + .../model/entity/ConfigGlobalSMSEntity.java | 12 ++ src/main/java/com/xkrs/model/vo/ConfigVo.java | 69 +++++++ .../service/ConfigGlobalFirePointService.java | 24 +++ .../xkrs/service/ConfigGlobalSMSService.java | 30 +++ .../com/xkrs/service/ConfigGlobalService.java | 25 --- .../xkrs/service/ConfigGlobalUserService.java | 14 ++ .../ConfigGlobalFirePointServiceImpl.java | 126 ++++++++++++ ...l.java => ConfigGlobalSMSServiceImpl.java} | 191 +++++++++--------- .../impl/ConfigGlobalUserServiceImpl.java | 65 ++++++ .../service/impl/FirePointServiceImpl.java | 17 +- .../java/com/xkrs/utils/ConfigConstant.java | 7 + 16 files changed, 585 insertions(+), 206 deletions(-) create mode 100644 src/main/java/com/xkrs/model/vo/ConfigVo.java create mode 100644 src/main/java/com/xkrs/service/ConfigGlobalFirePointService.java create mode 100644 src/main/java/com/xkrs/service/ConfigGlobalSMSService.java delete mode 100644 src/main/java/com/xkrs/service/ConfigGlobalService.java create mode 100644 src/main/java/com/xkrs/service/ConfigGlobalUserService.java create mode 100644 src/main/java/com/xkrs/service/impl/ConfigGlobalFirePointServiceImpl.java rename src/main/java/com/xkrs/service/impl/{ConfigGlobalServiceImpl.java => ConfigGlobalSMSServiceImpl.java} (50%) create mode 100644 src/main/java/com/xkrs/service/impl/ConfigGlobalUserServiceImpl.java create mode 100644 src/main/java/com/xkrs/utils/ConfigConstant.java diff --git a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java index ca5130e..554f360 100644 --- a/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java +++ b/src/main/java/com/xkrs/common/account/CustomAuthenticationProvider.java @@ -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 permissions = new ArrayList<>(); List integers = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId()); List 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 */ diff --git a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java index 431b352..9c2a7b4 100644 --- a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java +++ b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java @@ -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 { diff --git a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java index f0bc1a7..ca50a22 100644 --- a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java +++ b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java @@ -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 authorities, SysUserVo sysUserEntity) { + static void addAuthentication(HttpServletResponse response, String userName, Collection 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 { diff --git a/src/main/java/com/xkrs/controller/ConfigGlobalController.java b/src/main/java/com/xkrs/controller/ConfigGlobalController.java index fdd091b..12ac50b 100644 --- a/src/main/java/com/xkrs/controller/ConfigGlobalController.java +++ b/src/main/java/com/xkrs/controller/ConfigGlobalController.java @@ -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 configMap) { - return configGlobalService.configGlobalUser(configMap); + return configGlobalUserService.configGlobalUser(configMap); } - /** - * 火情信息全局配置服务 - */ @PostMapping("/configGlobalFirePoint") public String configGlobalFirePoint(@Nullable @RequestBody Map configMap) { - return configGlobalService.configGlobalFirePoint(configMap); + return configGlobalFirePointService.configGlobalFirePoint(configMap); } - /** - * 短信全局配置服务 - */ @PostMapping("/configGlobalSMS") public String configGlobalSMS(@Nullable @RequestBody Map configMap) { - return configGlobalService.configGlobalSMS(configMap); + return configGlobalSMSService.configGlobalSMS(configMap); } } diff --git a/src/main/java/com/xkrs/model/entity/ConfigGlobalFirePointEntity.java b/src/main/java/com/xkrs/model/entity/ConfigGlobalFirePointEntity.java index 02cf350..78f1ba5 100644 --- a/src/main/java/com/xkrs/model/entity/ConfigGlobalFirePointEntity.java +++ b/src/main/java/com/xkrs/model/entity/ConfigGlobalFirePointEntity.java @@ -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; diff --git a/src/main/java/com/xkrs/model/entity/ConfigGlobalSMSEntity.java b/src/main/java/com/xkrs/model/entity/ConfigGlobalSMSEntity.java index c80ef98..7d2cb66 100644 --- a/src/main/java/com/xkrs/model/entity/ConfigGlobalSMSEntity.java +++ b/src/main/java/com/xkrs/model/entity/ConfigGlobalSMSEntity.java @@ -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; diff --git a/src/main/java/com/xkrs/model/vo/ConfigVo.java b/src/main/java/com/xkrs/model/vo/ConfigVo.java new file mode 100644 index 0000000..a2854c7 --- /dev/null +++ b/src/main/java/com/xkrs/model/vo/ConfigVo.java @@ -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; + } +} diff --git a/src/main/java/com/xkrs/service/ConfigGlobalFirePointService.java b/src/main/java/com/xkrs/service/ConfigGlobalFirePointService.java new file mode 100644 index 0000000..e4cb7b4 --- /dev/null +++ b/src/main/java/com/xkrs/service/ConfigGlobalFirePointService.java @@ -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 configMap); + +} diff --git a/src/main/java/com/xkrs/service/ConfigGlobalSMSService.java b/src/main/java/com/xkrs/service/ConfigGlobalSMSService.java new file mode 100644 index 0000000..3b41564 --- /dev/null +++ b/src/main/java/com/xkrs/service/ConfigGlobalSMSService.java @@ -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 configMap); + +} diff --git a/src/main/java/com/xkrs/service/ConfigGlobalService.java b/src/main/java/com/xkrs/service/ConfigGlobalService.java deleted file mode 100644 index 35440c1..0000000 --- a/src/main/java/com/xkrs/service/ConfigGlobalService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xkrs.service; - -import java.util.Map; - -/** - * 全局配置服务 - */ -public interface ConfigGlobalService { - - /** - * 用户全局配置服务 - */ - String configGlobalUser(Map configMap); - - /** - * 火情信息全局配置服务 - */ - String configGlobalFirePoint(Map configMap); - - /** - * 短信全局配置服务 - */ - String configGlobalSMS(Map configMap); - -} diff --git a/src/main/java/com/xkrs/service/ConfigGlobalUserService.java b/src/main/java/com/xkrs/service/ConfigGlobalUserService.java new file mode 100644 index 0000000..6e273c6 --- /dev/null +++ b/src/main/java/com/xkrs/service/ConfigGlobalUserService.java @@ -0,0 +1,14 @@ +package com.xkrs.service; + +import java.util.Map; + +/** + * 用户全局配置服务 + */ +public interface ConfigGlobalUserService { + + boolean loginAbleWhenExpired(); + + String configGlobalUser(Map configMap); + +} diff --git a/src/main/java/com/xkrs/service/impl/ConfigGlobalFirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/ConfigGlobalFirePointServiceImpl.java new file mode 100644 index 0000000..c9db95d --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/ConfigGlobalFirePointServiceImpl.java @@ -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 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 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); + } + +} diff --git a/src/main/java/com/xkrs/service/impl/ConfigGlobalServiceImpl.java b/src/main/java/com/xkrs/service/impl/ConfigGlobalSMSServiceImpl.java similarity index 50% rename from src/main/java/com/xkrs/service/impl/ConfigGlobalServiceImpl.java rename to src/main/java/com/xkrs/service/impl/ConfigGlobalSMSServiceImpl.java index 8ebff51..5deab09 100644 --- a/src/main/java/com/xkrs/service/impl/ConfigGlobalServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/ConfigGlobalSMSServiceImpl.java @@ -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 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 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 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 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 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 configGlobalSMSEntityList = configGlobalSMSDao.findAll(); if (configGlobalSMSEntityList.isEmpty()) { ConfigGlobalSMSEntity configGlobalSMSEntity = new ConfigGlobalSMSEntity(); diff --git a/src/main/java/com/xkrs/service/impl/ConfigGlobalUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/ConfigGlobalUserServiceImpl.java new file mode 100644 index 0000000..c6440b9 --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/ConfigGlobalUserServiceImpl.java @@ -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 configMap) { + if (configMap == null) { + return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale); + } + Long loginAbleWhenExpired = configMap.get("loginAbleWhenExpired"); + List 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); + } + +} diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 97240eb..b87b86e 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -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; diff --git a/src/main/java/com/xkrs/utils/ConfigConstant.java b/src/main/java/com/xkrs/utils/ConfigConstant.java new file mode 100644 index 0000000..8c58083 --- /dev/null +++ b/src/main/java/com/xkrs/utils/ConfigConstant.java @@ -0,0 +1,7 @@ +package com.xkrs.utils; + +public interface ConfigConstant { + + Long STATE_ACTIVE = 1L; + +}