普通用户和VIP用户区别对待:

1、普通用户不能查看历史火情,VIP可以。
2、普通用户不能导航,VIP可以。
3、普通用户不能接收短信通知,VIP可以。
This commit is contained in:
liuchengqian 2022-06-17 15:43:48 +08:00
parent 0efa94368b
commit 6a6302ff43
27 changed files with 386 additions and 997 deletions

View File

@ -2,7 +2,6 @@ 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;
@ -26,8 +25,6 @@ import static com.xkrs.utils.EncryptDecryptUtil.encry256;
/**
* 自定义认证Provider
*
* @author tajochen
*/
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@ -41,9 +38,6 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
@Resource
private SysAuthorityService sysAuthorityService;
@Resource
private ConfigGlobalUserService configGlobalUserService;
/**
* 初使化时将已静态化的Service实例化
*/
@ -58,7 +52,6 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
customAuthenticationProvider.sysUserService = this.sysUserService;
customAuthenticationProvider.sysRoleService = this.sysRoleService;
customAuthenticationProvider.sysAuthorityService = this.sysAuthorityService;
customAuthenticationProvider.configGlobalUserService = this.configGlobalUserService;
}
/**
@ -73,7 +66,6 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
// 获取认证的用户名 & 密码
String userName = authentication.getName();
String password = authentication.getCredentials().toString();
SysUserEntity userEntity = customAuthenticationProvider.sysUserService.getSysUserByUserName(userName);
// 检查用户是否存在
@ -82,7 +74,7 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
}
// 检查用户是否激活
if (userEntity.getActiveFlag().intValue() != 0) {
if (userEntity.getActiveFlag() != 0) {
throw new DisabledException("该账号还未激活,请联系管理员");
}
@ -91,14 +83,6 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
throw new DisabledException("用户状态不正常,请联系管理员");
}
if (userEntity.getDayNum() == 7) {
if (DateTimeUtil.dateTimeToString(LocalDateTime.now()).compareTo(userEntity.getOverTime()) > 0) {
if (!customAuthenticationProvider.configGlobalUserService.loginAbleWhenExpired()) {
throw new DisabledException("该账号已过期,请联系管理员");
}
}
}
// 认证逻辑
String encryptPassword = encry256(password + userEntity.getSalt());
if (encryptPassword.equals(userEntity.getPassword())) {

View File

@ -2,14 +2,9 @@ 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;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
@ -33,19 +28,12 @@ import java.util.Locale;
/**
* jwt登录过滤器
*
* @author tajochen
*/
public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
private static final Logger logger = LoggerFactory.getLogger(JwtLoginFilter.class);
@Resource
private SysUserService sysUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
public JwtLoginFilter(String url, AuthenticationManager authManager) {
super(new AntPathRequestMatcher(url));
setAuthenticationManager(authManager);
@ -88,12 +76,6 @@ 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,27 +83,7 @@ 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, 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;
TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName);
}
/**

View File

@ -2,7 +2,6 @@ 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 io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
@ -34,6 +33,7 @@ public class TokenAuthenticationService {
* 加密密钥
*/
static public final String SECRET_KEY = "0Y9H364Q9Y908262F25LMXGIKIN5N858XM3674GWL2DD8X1DS4W6I722IRY8PS4XPNB6U303" + "45HBVCUL94STG8C3Z53T7A09JJ100I56YE9894CI11PX9J71HIZ8L5Y2O504C4E2K8276425UA8734833F45K36878FXAG799QV9LXU" + "JOI3XA2046UPG8TB2OT84R5T6ZB127N9ZPJ7AJMC41JVHB2WK2B6H8NL45LZNAZ666KHZH3QUT65UX6F8";
/**
* Token前缀
*/
@ -52,7 +52,7 @@ public class TokenAuthenticationService {
* @param userName
* @param authorities
*/
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity, ConfigVo config) {
static void addAuthentication(HttpServletResponse response, String userName, Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity) {
Locale locale = new Locale("zh", "CN");
Map map = new HashMap(3);
@ -67,50 +67,10 @@ 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;
//
// // 生成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)
// 保存权限
@ -121,7 +81,6 @@ public class TokenAuthenticationService {
.signWith(key).compact();
map.put("token", jwt);
map.put("user", sysUserEntity);
map.put("config", config);
// JWT 写入 body
PrintWriter out = null;
try {
@ -161,4 +120,5 @@ public class TokenAuthenticationService {
return null;
}
}
}

View File

@ -33,6 +33,11 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//.antMatchers("/").permitAll()
// 所有OPTIONS请求都放行
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfig").permitAll()
.antMatchers(HttpMethod.POST, "/globalConfig").permitAll()
.antMatchers(HttpMethod.POST, "/globalConfigDict").permitAll()
// 所有 /user/add 用户注册 的POST请求 都放行
.antMatchers(HttpMethod.POST, "/api/user/add").permitAll()
// 所有 /user/check/duplicate 检查用户名是否重复 的POST请求 都放行

View File

@ -1,42 +1,53 @@
package com.xkrs.controller;
import com.xkrs.service.ConfigGlobalFirePointService;
import com.xkrs.service.ConfigGlobalSMSService;
import com.xkrs.service.ConfigGlobalUserService;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.model.qo.GlobalConfigDictQo;
import com.xkrs.service.GlobalConfigService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 全局配置服务
*/
@RestController
public class ConfigGlobalController {
private final Locale locale = LocaleContextHolder.getLocale();
@Resource
private ConfigGlobalUserService configGlobalUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
@Resource
private ConfigGlobalSMSService configGlobalSMSService;
private GlobalConfigService globalConfigService;
@PostMapping("/configGlobalUser")
public String configGlobalUser(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalUserService.configGlobalUser(configMap);
@GetMapping("/selectGlobalConfigDict")
public String selectGlobalConfigDict() {
return globalConfigService.selectGlobalConfigDict();
}
@PostMapping("/configGlobalFirePoint")
public String configGlobalFirePoint(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalFirePointService.configGlobalFirePoint(configMap);
@GetMapping("/selectGlobalConfigValue")
public String selectGlobalConfigValue(@RequestParam(value = "code") Long code) {
Long value = globalConfigService.selectGlobalConfigValue(code);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, value, locale);
}
@PostMapping("/configGlobalSMS")
public String configGlobalSMS(@Nullable @RequestBody Map<String, Long> configMap) {
return configGlobalSMSService.configGlobalSMS(configMap);
@GetMapping("/selectGlobalConfig")
public String selectGlobalConfig(@RequestParam(required = false, value = "code") Long code) {
return globalConfigService.selectGlobalConfig(code);
}
@PostMapping("/globalConfig")
public String globalConfig(@Nullable @RequestBody Map<Long, Long> configMap) {
return globalConfigService.globalConfig(configMap);
}
@PostMapping("/globalConfigDict")
public String globalConfigDict(@RequestBody GlobalConfigDictQo globalConfigDictQo) {
return globalConfigService.globalConfigDict(globalConfigDictQo);
}
}

View File

@ -1,11 +0,0 @@
package com.xkrs.dao;
import com.xkrs.model.entity.ConfigGlobalFirePointEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
@Component
public interface ConfigGlobalFirePointDao extends JpaRepository<ConfigGlobalFirePointEntity, Long>, JpaSpecificationExecutor<ConfigGlobalFirePointEntity> {
}

View File

@ -1,10 +0,0 @@
package com.xkrs.dao;
import com.xkrs.model.entity.ConfigGlobalSMSEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
@Component
public interface ConfigGlobalSMSDao extends JpaRepository<ConfigGlobalSMSEntity, Long>, JpaSpecificationExecutor<ConfigGlobalSMSEntity> {
}

View File

@ -1,10 +0,0 @@
package com.xkrs.dao;
import com.xkrs.model.entity.ConfigGlobalUserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
@Component
public interface ConfigGlobalUserDao extends JpaRepository<ConfigGlobalUserEntity, Long>, JpaSpecificationExecutor<ConfigGlobalUserEntity> {
}

View File

@ -0,0 +1,15 @@
package com.xkrs.dao;
import com.xkrs.model.entity.GlobalConfigEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public interface GlobalConfigDao extends JpaRepository<GlobalConfigEntity, Long>, JpaSpecificationExecutor<GlobalConfigEntity> {
Optional<GlobalConfigEntity> findByCode(Long code);
}

View File

@ -0,0 +1,15 @@
package com.xkrs.dao;
import com.xkrs.model.entity.GlobalConfigDictEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public interface GlobalConfigDictDao extends JpaRepository<GlobalConfigDictEntity, Long>, JpaSpecificationExecutor<GlobalConfigDictEntity> {
Optional<GlobalConfigDictEntity> findByCode(Long code);
}

View File

@ -1,91 +0,0 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 火情信息全局配置信息
*/
@Entity
@Table(name = "config_global_fire_point")
public class ConfigGlobalFirePointEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "config_global_fire_point_seq_gen")
@SequenceGenerator(name = "config_global_fire_point_seq_gen", sequenceName = "config_global_fire_point_id_seq", allocationSize = 1)
private Long id;
/**
* 过期后能否获取今日火情信息
* 0不能获取
* 1能够获取
*/
private Long todayAbleWhenExpired;
/**
* 过期后能否获取历史火情信息
* 0不能获取
* 1能够获取
*/
private Long historyAbleWhenExpired;
/**
* 过期后能否获取统计分析数据
* 0不能获取
* 1能够获取
*/
private Long statisticsAbleWhenExpired;
/**
* 过期后能否使用导航功能
* 0不能导航
* 1能够导航
*/
private Long navigateAbleWhenExpired;
public ConfigGlobalFirePointEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
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

@ -1,162 +0,0 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 短信全局配置信息
*/
@Entity
@Table(name = "config_global_sms")
public class ConfigGlobalSMSEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "config_global_sms_seq_gen")
@SequenceGenerator(name = "config_global_sms_seq_gen", sequenceName = "config_global_sms_id_seq", allocationSize = 1)
private Long id;
/**
* 过期后能否接收短信
* 0不能
* 1
*/
private Long smsAbleWhenExpired;
/**
* 省过期前能否提前通知
* 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;
public ConfigGlobalSMSEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getSmsAbleWhenExpired() {
return smsAbleWhenExpired;
}
public void setSmsAbleWhenExpired(Long smsAbleWhenExpired) {
this.smsAbleWhenExpired = smsAbleWhenExpired;
}
public Long getProAnAbleBeforeExpired() {
return proAnAbleBeforeExpired;
}
public void setProAnAbleBeforeExpired(Long proAnAbleBeforeExpired) {
this.proAnAbleBeforeExpired = proAnAbleBeforeExpired;
}
public Long getProAnDayBeforeExpired() {
return proAnDayBeforeExpired;
}
public void setProAnDayBeforeExpired(Long proAnDayBeforeExpired) {
this.proAnDayBeforeExpired = proAnDayBeforeExpired;
}
public Long getCityAnAbleBeforeExpired() {
return cityAnAbleBeforeExpired;
}
public void setCityAnAbleBeforeExpired(Long cityAnAbleBeforeExpired) {
this.cityAnAbleBeforeExpired = cityAnAbleBeforeExpired;
}
public Long getCityAnDayBeforeExpired() {
return cityAnDayBeforeExpired;
}
public void setCityAnDayBeforeExpired(Long cityAnDayBeforeExpired) {
this.cityAnDayBeforeExpired = cityAnDayBeforeExpired;
}
public Long getCountyAnAbleBeforeExpired() {
return countyAnAbleBeforeExpired;
}
public void setCountyAnAbleBeforeExpired(Long countyAnAbleBeforeExpired) {
this.countyAnAbleBeforeExpired = countyAnAbleBeforeExpired;
}
public Long getCountyAnDayBeforeExpired() {
return countyAnDayBeforeExpired;
}
public void setCountyAnDayBeforeExpired(Long countyAnDayBeforeExpired) {
this.countyAnDayBeforeExpired = countyAnDayBeforeExpired;
}
public Long getStreetAnAbleBeforeExpired() {
return streetAnAbleBeforeExpired;
}
public void setStreetAnAbleBeforeExpired(Long streetAnAbleBeforeExpired) {
this.streetAnAbleBeforeExpired = streetAnAbleBeforeExpired;
}
public Long getStreetAnDayBeforeExpired() {
return streetAnDayBeforeExpired;
}
public void setStreetAnDayBeforeExpired(Long streetAnDayBeforeExpired) {
this.streetAnDayBeforeExpired = streetAnDayBeforeExpired;
}
}

View File

@ -1,46 +0,0 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 用户全局配置信息
*/
@Entity
@Table(name = "config_global_user")
public class ConfigGlobalUserEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "config_global_user_seq_gen")
@SequenceGenerator(name = "config_global_user_seq_gen", sequenceName = "config_global_user_id_seq", allocationSize = 1)
private Long id;
/**
* 过期后能否继续登录
* 0不能登录
* 1能够登录
*/
private Long loginAbleWhenExpired;
public ConfigGlobalUserEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getLoginAbleWhenExpired() {
return loginAbleWhenExpired;
}
public void setLoginAbleWhenExpired(Long loginAbleWhenExpired) {
this.loginAbleWhenExpired = loginAbleWhenExpired;
}
}

View File

@ -0,0 +1,70 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 全局配置字典表
*/
@Entity
@Table(name = "global_config_dict")
public class GlobalConfigDictEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_config_dict_seq_gen")
@SequenceGenerator(name = "global_config_dict_seq_gen", sequenceName = "global_config_dict_id_seq", allocationSize = 1)
private Long id;
/**
* 全局配置字典的编码
*/
private Long code;
/**
* 全局配置字典的名称
*/
private String name;
/**
* 全局配置字典的备注
*/
private String remark;
public GlobalConfigDictEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -0,0 +1,57 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 全局配置表
*/
@Entity
@Table(name = "global_config")
public class GlobalConfigEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_config_seq_gen")
@SequenceGenerator(name = "global_config_seq_gen", sequenceName = "global_config_id_seq", allocationSize = 1)
private Long id;
/**
* 全局配置项的编号
*/
private Long code;
/**
* 全局配置项的值
*/
private Long value;
public GlobalConfigEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

View File

@ -0,0 +1,46 @@
package com.xkrs.model.qo;
public class GlobalConfigDictQo {
/**
* 全局配置字典的编码
*/
private Long code;
/**
* 全局配置字典的名称
*/
private String name;
/**
* 全局配置字典的备注
*/
private String remark;
public GlobalConfigDictQo() {
}
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -1,69 +0,0 @@
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

@ -1,24 +0,0 @@
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

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

View File

@ -0,0 +1,19 @@
package com.xkrs.service;
import com.xkrs.model.qo.GlobalConfigDictQo;
import java.util.Map;
public interface GlobalConfigService {
String selectGlobalConfigDict();
Long selectGlobalConfigValue(Long code);
String selectGlobalConfig(Long code);
String globalConfig(Map<Long, Long> globalConfigMap);
String globalConfigDict(GlobalConfigDictQo globalConfigDictQo);
}

View File

@ -1,126 +0,0 @@
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,200 +0,0 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.ConfigGlobalSMSDao;
import com.xkrs.model.entity.ConfigGlobalSMSEntity;
import com.xkrs.service.ConfigGlobalSMSService;
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 ConfigGlobalSMSServiceImpl implements ConfigGlobalSMSService {
private final Locale locale = LocaleContextHolder.getLocale();
/**
* 短信全局配置信息
*/
@Resource
private ConfigGlobalSMSDao configGlobalSMSDao;
@Override
public boolean smsAbleWhenExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getSmsAbleWhenExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean proAnAbleBeforeExpired() {
try {
return ConfigConstant.STATE_ACTIVE.longValue() == configGlobalSMSDao.findAll().get(0).getProAnAbleBeforeExpired().longValue();
} catch (Exception e) {
e.printStackTrace();
}
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");
List<ConfigGlobalSMSEntity> configGlobalSMSEntityList = configGlobalSMSDao.findAll();
if (configGlobalSMSEntityList.isEmpty()) {
ConfigGlobalSMSEntity configGlobalSMSEntity = new ConfigGlobalSMSEntity();
configGlobalSMSEntity.setSmsAbleWhenExpired(smsAbleWhenExpired);
configGlobalSMSEntity.setProAnAbleBeforeExpired(proAnAbleBeforeExpired);
configGlobalSMSEntity.setProAnDayBeforeExpired(proAnDayBeforeExpired);
configGlobalSMSEntity.setCityAnAbleBeforeExpired(cityAnAbleBeforeExpired);
configGlobalSMSEntity.setCityAnDayBeforeExpired(cityAnDayBeforeExpired);
configGlobalSMSEntity.setCountyAnAbleBeforeExpired(countyAnAbleBeforeExpired);
configGlobalSMSEntity.setCountyAnDayBeforeExpired(countyAnDayBeforeExpired);
configGlobalSMSEntity.setStreetAnAbleBeforeExpired(streetAnAbleBeforeExpired);
configGlobalSMSEntity.setStreetAnDayBeforeExpired(streetAnDayBeforeExpired);
configGlobalSMSDao.save(configGlobalSMSEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
ConfigGlobalSMSEntity configGlobalSMSEntity = configGlobalSMSEntityList.get(0);
if (smsAbleWhenExpired != null) {
if (configGlobalSMSEntity.getSmsAbleWhenExpired() == null || configGlobalSMSEntity.getSmsAbleWhenExpired().longValue() != smsAbleWhenExpired.longValue()) {
configGlobalSMSEntity.setSmsAbleWhenExpired(smsAbleWhenExpired);
}
}
if (proAnAbleBeforeExpired != null) {
if (configGlobalSMSEntity.getProAnAbleBeforeExpired() == null || configGlobalSMSEntity.getProAnAbleBeforeExpired().longValue() != proAnAbleBeforeExpired.longValue()) {
configGlobalSMSEntity.setProAnAbleBeforeExpired(proAnAbleBeforeExpired);
}
}
if (proAnDayBeforeExpired != null) {
if (configGlobalSMSEntity.getProAnDayBeforeExpired() == null || configGlobalSMSEntity.getProAnDayBeforeExpired().longValue() != proAnDayBeforeExpired.longValue()) {
configGlobalSMSEntity.setProAnDayBeforeExpired(proAnDayBeforeExpired);
}
}
if (cityAnAbleBeforeExpired != null) {
if (configGlobalSMSEntity.getCityAnAbleBeforeExpired() == null || configGlobalSMSEntity.getCityAnAbleBeforeExpired().longValue() != cityAnAbleBeforeExpired.longValue()) {
configGlobalSMSEntity.setCityAnAbleBeforeExpired(cityAnAbleBeforeExpired);
}
}
if (cityAnDayBeforeExpired != null) {
if (configGlobalSMSEntity.getCityAnDayBeforeExpired() == null || configGlobalSMSEntity.getCityAnDayBeforeExpired().longValue() != cityAnDayBeforeExpired.longValue()) {
configGlobalSMSEntity.setCityAnDayBeforeExpired(cityAnDayBeforeExpired);
}
}
if (countyAnAbleBeforeExpired != null) {
if (configGlobalSMSEntity.getCountyAnAbleBeforeExpired() == null || configGlobalSMSEntity.getCountyAnAbleBeforeExpired().longValue() != countyAnAbleBeforeExpired.longValue()) {
configGlobalSMSEntity.setCountyAnAbleBeforeExpired(countyAnAbleBeforeExpired);
}
}
if (countyAnDayBeforeExpired != null) {
if (configGlobalSMSEntity.getCountyAnDayBeforeExpired() == null || configGlobalSMSEntity.getCountyAnDayBeforeExpired().longValue() != countyAnDayBeforeExpired.longValue()) {
configGlobalSMSEntity.setCountyAnDayBeforeExpired(countyAnDayBeforeExpired);
}
}
if (streetAnAbleBeforeExpired != null) {
if (configGlobalSMSEntity.getStreetAnAbleBeforeExpired() == null || configGlobalSMSEntity.getStreetAnAbleBeforeExpired().longValue() != streetAnAbleBeforeExpired.longValue()) {
configGlobalSMSEntity.setStreetAnAbleBeforeExpired(streetAnAbleBeforeExpired);
}
}
if (streetAnDayBeforeExpired != null) {
if (configGlobalSMSEntity.getStreetAnDayBeforeExpired() == null || configGlobalSMSEntity.getStreetAnDayBeforeExpired().longValue() != streetAnDayBeforeExpired.longValue()) {
configGlobalSMSEntity.setStreetAnDayBeforeExpired(streetAnDayBeforeExpired);
}
}
configGlobalSMSDao.save(configGlobalSMSEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
}

View File

@ -1,65 +0,0 @@
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,10 +8,8 @@ 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.service.GlobalConfigService;
import com.xkrs.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -87,13 +85,9 @@ public class FirePointServiceImpl implements FirePointService {
@Resource
private FirePointQueryHelper firePointQueryHelper;
@Resource
private ConfigGlobalUserService configGlobalUserService;
@Resource
private ConfigGlobalFirePointService configGlobalFirePointService;
@Resource
private ConfigGlobalSMSService configGlobalSMSService;
@Resource
private GlobalConfigService globalConfigService;
/**
* 添加火点信息
@ -431,9 +425,14 @@ public class FirePointServiceImpl implements FirePointService {
continue;
}
LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME);
if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {//过期用户
//过期用户需要根据配置决定是否发送短信
if (!configGlobalSMSService.smsAbleWhenExpired()) {
if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {//普通用户
boolean smsEnable = 1L == globalConfigService.selectGlobalConfigValue(9L);
if (!smsEnable) {//根据配置信息决定是否发送短信
continue;
}
} else {//VIP用户
boolean smsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
if (!smsEnable) {//根据配置信息决定是否发送短信
continue;
}
}

View File

@ -0,0 +1,111 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.GlobalConfigDao;
import com.xkrs.dao.GlobalConfigDictDao;
import com.xkrs.model.entity.GlobalConfigDictEntity;
import com.xkrs.model.entity.GlobalConfigEntity;
import com.xkrs.model.qo.GlobalConfigDictQo;
import com.xkrs.service.GlobalConfigService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.util.*;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class GlobalConfigServiceImpl implements GlobalConfigService {
private final Locale locale = LocaleContextHolder.getLocale();
@Resource
private GlobalConfigDao globalConfigDao;
@Resource
private GlobalConfigDictDao globalConfigDictDao;
@Override
public String selectGlobalConfigDict() {
List<GlobalConfigDictEntity> globalConfigDictList = globalConfigDictDao.findAll(Sort.by(Sort.Direction.ASC, "id"));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, globalConfigDictList, locale);
}
@Override
public Long selectGlobalConfigValue(Long code) {
try {
Optional<GlobalConfigEntity> existsGlobalConfigOptional = globalConfigDao.findByCode(code);
if (existsGlobalConfigOptional.isEmpty()) {
return 0L;
}
return existsGlobalConfigOptional.get().getValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
@Override
public String selectGlobalConfig(Long code) {
Specification<GlobalConfigEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
//查询条件集合
List<Predicate> predicateList = new ArrayList<>();
if (code != null) {
predicateList.add(criteriaBuilder.equal(root.get("code").as(Long.class), code));
}
Predicate[] predicateArray = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicateArray));
};
List<GlobalConfigEntity> globalConfigList = globalConfigDao.findAll(specification, Sort.by(Sort.Direction.ASC, "id"));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, globalConfigList, locale);
}
@Override
public String globalConfig(Map<Long, Long> globalConfigMap) {
if (globalConfigMap == null || globalConfigMap.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
}
for (Map.Entry<Long, Long> entry : globalConfigMap.entrySet()) {
Long code = entry.getKey();
Long value = entry.getValue();
if (code == null || value == null) {
continue;
}
Optional<GlobalConfigEntity> existsGlobalConfigOptional = globalConfigDao.findByCode(code);
if (existsGlobalConfigOptional.isEmpty()) {
GlobalConfigEntity globalConfigEntity = new GlobalConfigEntity();
globalConfigEntity.setCode(code);
globalConfigEntity.setValue(value);
globalConfigDao.save(globalConfigEntity);
} else {
GlobalConfigEntity existsGlobalConfig = existsGlobalConfigOptional.get();
existsGlobalConfig.setCode(code);
existsGlobalConfig.setValue(value);
globalConfigDao.save(existsGlobalConfig);
}
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
@Override
public String globalConfigDict(GlobalConfigDictQo globalConfigDictQo) {
Long code = globalConfigDictQo.getCode();
String name = globalConfigDictQo.getName();
String remark = globalConfigDictQo.getRemark();
Optional<GlobalConfigDictEntity> existsGlobalConfigDictOptional = globalConfigDictDao.findByCode(code);
if (existsGlobalConfigDictOptional.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "配置失败", locale);
}
GlobalConfigDictEntity globalConfigDictEntity = new GlobalConfigDictEntity();
globalConfigDictEntity.setCode(code);
globalConfigDictEntity.setName(name);
globalConfigDictEntity.setRemark(remark);
globalConfigDictDao.save(globalConfigDictEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
}

View File

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