救援APP

This commit is contained in:
xiao-fajia 2024-08-23 19:56:14 +08:00
parent c6233b6eb0
commit 77f6d157a5
9 changed files with 771 additions and 0 deletions

View File

@ -11,4 +11,5 @@ public interface CommonErrorCodeConstants extends ErrorCodeConstants {
ErrorCode STAFF_NOT_CHANGE = new ErrorCode(2_002_000_003, "该员工还有工作未交接,不可删除");
ErrorCode LOGIN_ACCOUNT_EXIST = new ErrorCode(2_002_000_004, "登录账号已存在");
ErrorCode LOGIN_ACCOUNT_NOT_EXIST = new ErrorCode(2_002_000_005, "登录账号不存在");
ErrorCode SYSTEM_ERROR = new ErrorCode(2_002_000_005, "系统错误");
}

View File

@ -0,0 +1,44 @@
package cn.iocoder.yudao.module.constant;
/**
* 缓存的key 常量
*
* @author ruoyi
*/
public class CacheConstants
{
/**
* 登录用户 redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* 验证码 redis key
*/
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
/**
* 参数管理 cache key
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 防重提交 redis key
*/
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
/**
* 限流 redis key
*/
public static final String RATE_LIMIT_KEY = "rate_limit:";
/**
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
}

View File

@ -0,0 +1,78 @@
package cn.iocoder.yudao.module.constant;
/**
* 用户常量信息
*
* @author ruoyi
*/
public class UserConstants
{
/**
* 平台内系统用户的唯一标志
*/
public static final String SYS_USER = "SYS_USER";
/** 正常状态 */
public static final String NORMAL = "0";
/** 异常状态 */
public static final String EXCEPTION = "1";
/** 用户封禁状态 */
public static final String USER_DISABLE = "1";
/** 角色封禁状态 */
public static final String ROLE_DISABLE = "1";
/** 部门正常状态 */
public static final String DEPT_NORMAL = "0";
/** 部门停用状态 */
public static final String DEPT_DISABLE = "1";
/** 字典正常状态 */
public static final String DICT_NORMAL = "0";
/** 是否为系统默认(是) */
public static final String YES = "Y";
/** 是否菜单外链(是) */
public static final String YES_FRAME = "0";
/** 是否菜单外链(否) */
public static final String NO_FRAME = "1";
/** 菜单类型(目录) */
public static final String TYPE_DIR = "M";
/** 菜单类型(菜单) */
public static final String TYPE_MENU = "C";
/** 菜单类型(按钮) */
public static final String TYPE_BUTTON = "F";
/** Layout组件标识 */
public final static String LAYOUT = "Layout";
/** ParentView组件标识 */
public final static String PARENT_VIEW = "ParentView";
/** InnerLink组件标识 */
public final static String INNER_LINK = "InnerLink";
/** 校验是否唯一的返回标识 */
public final static boolean UNIQUE = true;
public final static boolean NOT_UNIQUE = false;
/**
* 用户名长度限制
*/
public static final int USERNAME_MIN_LENGTH = 2;
public static final int USERNAME_MAX_LENGTH = 20;
/**
* 密码长度限制
*/
public static final int PASSWORD_MIN_LENGTH = 5;
public static final int PASSWORD_MAX_LENGTH = 20;
}

View File

@ -0,0 +1,128 @@
package cn.iocoder.yudao.module.rescue.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.rescue.core.controller.BaseController;
import cn.iocoder.yudao.module.rescue.core.page.TableDataInfo;
import cn.iocoder.yudao.module.rescue.domain.SysConfig;
import cn.iocoder.yudao.module.rescue.service.ISysConfigService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 参数配置 信息操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/config")
public class SysConfigController extends BaseController
{
@Autowired
@Lazy
private ISysConfigService configService;
/**
* 获取参数配置列表
*/
@PreAuthorize("@ss.hasPermi('system:config:list')")
@GetMapping("/list")
public TableDataInfo list(SysConfig config)
{
startPage();
List<SysConfig> list = configService.selectConfigList(config);
return getDataTable(list);
}
// @Log(title = "参数管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:config:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, SysConfig config)
{
List<SysConfig> list = configService.selectConfigList(config);
ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
util.exportExcel(response, list, "参数数据");
}
/**
* 根据参数编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:config:query')")
@GetMapping(value = "/{configId}")
public CommonResult getInfo(@PathVariable Long configId)
{
return success(configService.selectConfigById(configId));
}
/**
* 根据参数键名查询参数值
*/
@GetMapping(value = "/configKey/{configKey}")
public CommonResult getConfigKey(@PathVariable String configKey)
{
return success(configService.selectConfigByKey(configKey));
}
/**
* 新增参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:add')")
// @Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping
public CommonResult add(@Validated @RequestBody SysConfig config)
{
if (!configService.checkConfigKeyUnique(config))
{
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setCreator(SecurityFrameworkUtils.getLoginUserNickname());
return toAjax(configService.insertConfig(config));
}
/**
* 修改参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:edit')")
// @Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PutMapping
public CommonResult edit(@Validated @RequestBody SysConfig config)
{
if (!configService.checkConfigKeyUnique(config))
{
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setUpdater(SecurityFrameworkUtils.getLoginUserNickname());
return toAjax(configService.updateConfig(config));
}
/**
* 删除参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:remove')")
// @Log(title = "参数管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{configIds}")
public CommonResult remove(@PathVariable Long[] configIds)
{
configService.deleteConfigByIds(configIds);
return success();
}
/**
* 刷新参数缓存
*/
@PreAuthorize("@ss.hasPermi('system:config:remove')")
// @Log(title = "参数管理", businessType = BusinessType.CLEAN)
@DeleteMapping("/refreshCache")
public CommonResult refreshCache()
{
configService.resetConfigCache();
return success();
}
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.rescue.domain;
import cn.iocoder.yudao.annotation.Excel;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import lombok.Data;
/**
* 参数配置表 sys_config
*
* @author ruoyi
*/
@Data
public class SysConfig extends TenantBaseDO
{
private static final long serialVersionUID = 1L;
/** 参数主键 */
@Excel(name = "参数主键", cellType = Excel.ColumnType.NUMERIC)
private Long configId;
/** 参数名称 */
@Excel(name = "参数名称")
private String configName;
/** 参数键名 */
@Excel(name = "参数键名")
private String configKey;
/** 参数键值 */
@Excel(name = "参数键值")
private String configValue;
/** 系统内置Y是 N否 */
@Excel(name = "系统内置", readConverterExp = "Y=是,N=否")
private String configType;
}

View File

@ -0,0 +1,78 @@
package cn.iocoder.yudao.module.rescue.mapper;
import cn.iocoder.yudao.module.rescue.domain.SysConfig;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 参数配置 数据层
*
* @author ruoyi
*/
@Mapper
public interface RescueSysConfigMapper {
/**
* 查询参数配置信息
*
* @param config 参数配置信息
* @return 参数配置信息
*/
public SysConfig selectConfig(SysConfig config);
/**
* 通过ID查询配置
*
* @param configId 参数ID
* @return 参数配置信息
*/
public SysConfig selectConfigById(Long configId);
/**
* 查询参数配置列表
*
* @param config 参数配置信息
* @return 参数配置集合
*/
public List<SysConfig> selectConfigList(SysConfig config);
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数键名
* @return 参数配置信息
*/
public SysConfig checkConfigKeyUnique(String configKey);
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果
*/
public int insertConfig(SysConfig config);
/**
* 修改参数配置
*
* @param config 参数配置信息
* @return 结果
*/
public int updateConfig(SysConfig config);
/**
* 删除参数配置
*
* @param configId 参数ID
* @return 结果
*/
public int deleteConfigById(Long configId);
/**
* 批量删除参数信息
*
* @param configIds 需要删除的参数ID
* @return 结果
*/
public int deleteConfigByIds(Long[] configIds);
}

View File

@ -0,0 +1,90 @@
package cn.iocoder.yudao.module.rescue.service;
import cn.iocoder.yudao.module.rescue.domain.SysConfig;
import java.util.List;
/**
* 参数配置 服务层
*
* @author ruoyi
*/
public interface ISysConfigService
{
/**
* 查询参数配置信息
*
* @param configId 参数配置ID
* @return 参数配置信息
*/
public SysConfig selectConfigById(Long configId);
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数键名
* @return 参数键值
*/
public String selectConfigByKey(String configKey);
/**
* 获取验证码开关
*
* @return true开启false关闭
*/
public boolean selectCaptchaEnabled();
/**
* 查询参数配置列表
*
* @param config 参数配置信息
* @return 参数配置集合
*/
public List<SysConfig> selectConfigList(SysConfig config);
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果
*/
public int insertConfig(SysConfig config);
/**
* 修改参数配置
*
* @param config 参数配置信息
* @return 结果
*/
public int updateConfig(SysConfig config);
/**
* 批量删除参数信息
*
* @param configIds 需要删除的参数ID
*/
public void deleteConfigByIds(Long[] configIds);
/**
* 加载参数缓存数据
*/
public void loadingConfigCache();
/**
* 清空参数缓存数据
*/
public void clearConfigCache();
/**
* 重置参数缓存数据
*/
public void resetConfigCache();
/**
* 校验参数键名是否唯一
*
* @param config 参数信息
* @return 结果
*/
public boolean checkConfigKeyUnique(SysConfig config);
}

View File

@ -0,0 +1,212 @@
package cn.iocoder.yudao.module.rescue.service.impl;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
import cn.iocoder.yudao.module.constant.CacheConstants;
import cn.iocoder.yudao.module.constant.UserConstants;
import cn.iocoder.yudao.module.rescue.core.redis.RedisCache;
import cn.iocoder.yudao.module.rescue.core.text.Convert;
import cn.iocoder.yudao.module.rescue.domain.SysConfig;
import cn.iocoder.yudao.module.rescue.mapper.RescueSysConfigMapper;
import cn.iocoder.yudao.module.rescue.service.ISysConfigService;
import cn.iocoder.yudao.module.rescue.utils.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 参数配置 服务层实现
*
* @author ruoyi
*/
@Service
public class SysConfigServiceImpl implements ISysConfigService {
@Resource
@Lazy
private RescueSysConfigMapper configMapper2;
@Resource
private RedisCache redisCache2;
/**
* 项目启动时初始化参数到缓存
*/
@PostConstruct
public void init() {
loadingConfigCache();
}
/**
* 查询参数配置信息
*
* @param configId 参数配置ID
* @return 参数配置信息
*/
@Override
// @DataSource(DataSourceType.MASTER)
public SysConfig selectConfigById(Long configId) {
SysConfig config = new SysConfig();
config.setConfigId(configId);
return configMapper2.selectConfig(config);
}
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数key
* @return 参数键值
*/
@Override
public String selectConfigByKey(String configKey) {
String configValue = Convert.toStr(redisCache2.getCacheObject(getCacheKey(configKey)));
if (StringUtils.isNotEmpty(configValue)) {
return configValue;
}
SysConfig config = new SysConfig();
config.setConfigKey(configKey);
SysConfig retConfig = configMapper2.selectConfig(config);
if (StringUtils.isNotNull(retConfig)) {
redisCache2.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
}
/**
* 获取验证码开关
*
* @return true开启false关闭
*/
@Override
public boolean selectCaptchaEnabled() {
String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled");
if (StringUtils.isEmpty(captchaEnabled)) {
return true;
}
return Convert.toBool(captchaEnabled);
}
/**
* 查询参数配置列表
*
* @param config 参数配置信息
* @return 参数配置集合
*/
@Override
public List<SysConfig> selectConfigList(SysConfig config) {
return configMapper2.selectConfigList(config);
}
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int insertConfig(SysConfig config) {
int row = configMapper2.insertConfig(config);
if (row > 0) {
redisCache2.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
}
/**
* 修改参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int updateConfig(SysConfig config) {
SysConfig temp = configMapper2.selectConfigById(config.getConfigId());
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
redisCache2.deleteObject(getCacheKey(temp.getConfigKey()));
}
int row = configMapper2.updateConfig(config);
if (row > 0) {
redisCache2.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
}
/**
* 批量删除参数信息
*
* @param configIds 需要删除的参数ID
*/
@Override
public void deleteConfigByIds(Long[] configIds) {
for (Long configId : configIds) {
SysConfig config = selectConfigById(configId);
if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
throw exception(CommonErrorCodeConstants.SYSTEM_ERROR);
}
configMapper2.deleteConfigById(configId);
redisCache2.deleteObject(getCacheKey(config.getConfigKey()));
}
}
/**
* 加载参数缓存数据
*/
@Override
public void loadingConfigCache() {
List<SysConfig> configsList = configMapper2.selectConfigList(new SysConfig());
for (SysConfig config : configsList) {
redisCache2.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
/**
* 清空参数缓存数据
*/
@Override
public void clearConfigCache() {
Collection<String> keys = redisCache2.keys(CacheConstants.SYS_CONFIG_KEY + "*");
redisCache2.deleteObject(keys);
}
/**
* 重置参数缓存数据
*/
@Override
public void resetConfigCache() {
clearConfigCache();
loadingConfigCache();
}
/**
* 校验参数键名是否唯一
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public boolean checkConfigKeyUnique(SysConfig config) {
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
SysConfig info = configMapper2.checkConfigKeyUnique(config.getConfigKey());
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
private String getCacheKey(String configKey) {
return CacheConstants.SYS_CONFIG_KEY + configKey;
}
}

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.rescue.mapper.RescueSysConfigMapper">
<resultMap type="cn.iocoder.yudao.module.rescue.domain.SysConfig" id="SysConfigResult">
<id property="configId" column="config_id" />
<result property="configName" column="config_name" />
<result property="configKey" column="config_key" />
<result property="configValue" column="config_value" />
<result property="configType" column="config_type" />
</resultMap>
<sql id="selectConfigVo">
select config_id, config_name, config_key, config_value, config_type, create_time, update_time, remark
from sys_config
</sql>
<!-- 查询条件 -->
<sql id="sqlwhereSearch">
<where>
<if test="configId !=null">
and config_id = #{configId}
</if>
<if test="configKey !=null and configKey != ''">
and config_key = #{configKey}
</if>
</where>
</sql>
<select id="selectConfig" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
<include refid="sqlwhereSearch"/>
</select>
<select id="selectConfigList" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
<where>
<if test="configName != null and configName != ''">
AND config_name like concat('%', #{configName}, '%')
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
</if>
<if test="configKey != null and configKey != ''">
AND config_key like concat('%', #{configKey}, '%')
</if>
</where>
</select>
<select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
where config_id = #{configId}
</select>
<select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
where config_key = #{configKey} limit 1
</select>
<insert id="insertConfig" >
insert into sys_config (
<if test="configName != null and configName != '' ">config_name,</if>
<if test="configKey != null and configKey != '' ">config_key,</if>
<if test="configValue != null and configValue != '' ">config_value,</if>
<if test="configType != null and configType != '' ">config_type,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time
)values(
<if test="configName != null and configName != ''">#{configName},</if>
<if test="configKey != null and configKey != ''">#{configKey},</if>
<if test="configValue != null and configValue != ''">#{configValue},</if>
<if test="configType != null and configType != ''">#{configType},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert>
<update id="updateConfig">
update sys_config
<set>
<if test="configName != null and configName != ''">config_name = #{configName},</if>
<if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
<if test="configValue != null and configValue != ''">config_value = #{configValue},</if>
<if test="configType != null and configType != ''">config_type = #{configType},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
where config_id = #{configId}
</update>
<delete id="deleteConfigById" parameterType="Long">
delete from sys_config where config_id = #{configId}
</delete>
<delete id="deleteConfigByIds" parameterType="Long">
delete from sys_config where config_id in
<foreach item="configId" collection="array" open="(" separator="," close=")">
#{configId}
</foreach>
</delete>
</mapper>