zbj//1.系统配置操作出现两个已激活状态bug修改

This commit is contained in:
zhangbaojian
2023-04-21 14:31:10 +08:00
parent 3e6daa700e
commit f13711161a
5 changed files with 46 additions and 11 deletions

View File

@@ -38,6 +38,7 @@ public enum SystemResponseEnum {
MONITORY_TYPE_EMPTY("A00366","查询字典监测对象类型为空"),
TERMINAL_WIRING_EMPTY("A00367","查询字典监测终端接线方式为空"),
MONITOR_TYPE_EMPTY("A00368","查询字典监测点类别为空"),
ACTIVATED_STATE("A00369","必须存在一个已激活的系统类型"),

View File

@@ -45,6 +45,15 @@ public class ConfigParam {
@ApiModelProperty("审计日志存储时间1-6个月默认3个月")
private Integer logTime;
/**
* 系统类型
*/
@ApiModelProperty("激活状态0-未激活1-激活")
@NotNull(message = "激活状态不可为空")
@Max(value = 1)
@Min(value = 0)
private Integer state;
/**
* 更新操作实体
*/

View File

@@ -1,7 +1,6 @@
package com.njcn.system.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
@@ -27,7 +26,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* <p>

View File

@@ -12,8 +12,7 @@
sys_config sys_config
LEFT JOIN sys_user sys_usera ON sys_config.create_by = sys_usera.id
LEFT JOIN sys_user sys_userb ON sys_config.update_by = sys_userb.id
WHERE
sys_config.state = 1
ORDER BY
sys_config.create_time DESC
</select>

View File

@@ -1,6 +1,9 @@
package com.njcn.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.system.enums.SystemResponseEnum;
import com.njcn.system.mapper.ConfigMapper;
import com.njcn.system.pojo.param.ConfigParam;
import com.njcn.system.pojo.po.Config;
@@ -8,6 +11,7 @@ import com.njcn.system.service.IConfigService;
import com.njcn.web.utils.RequestUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@@ -15,7 +19,7 @@ import java.util.Objects;
/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author hongawen
@@ -25,7 +29,6 @@ import java.util.Objects;
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {
@Override
public boolean addSysConfig(ConfigParam configParam) {
Config config = new Config();
@@ -39,14 +42,39 @@ public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> impleme
}
@Override
@Transactional
public boolean updateSysConfig(ConfigParam.ConfigUpdateParam configUpdateParam) {
Config config = this.baseMapper.selectById(configUpdateParam.getId());
if (!Objects.isNull(config)) {
BeanUtils.copyProperties(configUpdateParam, config);
config.setUpdateBy(RequestUtil.getUserIndex());
config.setUpdateTime(LocalDateTime.now());
this.baseMapper.updateById(config);
return true;
if (config.getState() == 1) {
if (Objects.equals(configUpdateParam.getState(), config.getState())) {
BeanUtils.copyProperties(configUpdateParam, config);
config.setUpdateBy(RequestUtil.getUserIndex());
config.setUpdateTime(LocalDateTime.now());
this.baseMapper.updateById(config);
return true;
} else {
//不可更改当前激活状态,必须保留一个激活系统
throw new BusinessException(SystemResponseEnum.ACTIVATED_STATE);
}
} else {
if (configUpdateParam.getState() == 1) {
LambdaUpdateWrapper<Config> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(Config::getState, 0);
this.baseMapper.update(null, updateWrapper);
BeanUtils.copyProperties(configUpdateParam, config);
config.setUpdateBy(RequestUtil.getUserIndex());
config.setUpdateTime(LocalDateTime.now());
this.baseMapper.updateById(config);
return true;
} else {
BeanUtils.copyProperties(configUpdateParam, config);
config.setUpdateBy(RequestUtil.getUserIndex());
config.setUpdateTime(LocalDateTime.now());
this.baseMapper.updateById(config);
return true;
}
}
}
return false;
}