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

@@ -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;
}