feat: 删除环境
This commit is contained in:
parent
f65f995cc5
commit
70c0ae9896
|
@ -37,4 +37,10 @@ public class ConfigEnvController {
|
|||
public ResponseEntity<Object> queryList(@Validated @RequestBody ConfigAppEnv args) {
|
||||
return new ResponseEntity<>(configAppEnvService.queryList(args), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/remove")
|
||||
public ResponseEntity<Object> remove(@Validated @RequestBody ConfigAppEnv args) {
|
||||
configAppEnvService.remove(args);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,4 +18,6 @@ public interface ConfigAppEnvService extends IService<ConfigAppEnv> {
|
|||
void create(ConfigAppEnv args);
|
||||
|
||||
List<SelectOption> queryList(ConfigAppEnv args);
|
||||
|
||||
void remove(ConfigAppEnv args);
|
||||
}
|
||||
|
|
|
@ -35,4 +35,6 @@ public interface ConfigFileService extends IService<ConfigFile> {
|
|||
String getContentById(ConfigFile args);
|
||||
|
||||
void upload(Long appId, String envCode, MultipartFile file) throws Exception;
|
||||
|
||||
List<ConfigFile> getByAppIdEnvCode(Long appId, String envCode);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package cn.odboy.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.model.SelectOption;
|
||||
import cn.odboy.domain.ConfigAppEnv;
|
||||
import cn.odboy.domain.ConfigFile;
|
||||
import cn.odboy.infra.exception.BadRequestException;
|
||||
import cn.odboy.mapper.ConfigAppEnvMapper;
|
||||
import cn.odboy.service.ConfigAppEnvService;
|
||||
import cn.odboy.service.ConfigFileService;
|
||||
import cn.odboy.service.ConfigVersionService;
|
||||
import cn.odboy.util.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 配置环境 服务实现类
|
||||
*
|
||||
|
@ -23,6 +28,9 @@ import java.util.stream.Collectors;
|
|||
@RequiredArgsConstructor
|
||||
public class ConfigAppEnvServiceImpl extends ServiceImpl<ConfigAppEnvMapper, ConfigAppEnv>
|
||||
implements ConfigAppEnvService {
|
||||
private final ConfigFileService configFileService;
|
||||
private final ConfigVersionService configVersionService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(ConfigAppEnv args) {
|
||||
|
@ -36,13 +44,38 @@ public class ConfigAppEnvServiceImpl extends ServiceImpl<ConfigAppEnvMapper, Con
|
|||
|
||||
@Override
|
||||
public List<SelectOption> queryList(ConfigAppEnv args) {
|
||||
return list(new LambdaQueryWrapper<ConfigAppEnv>()
|
||||
.eq(ConfigAppEnv::getAppId, args.getAppId())
|
||||
).stream()
|
||||
.map(m -> SelectOption.builder()
|
||||
.label(m.getEnvCode())
|
||||
.value(m.getEnvCode())
|
||||
.build())
|
||||
return list(new LambdaQueryWrapper<ConfigAppEnv>().eq(ConfigAppEnv::getAppId, args.getAppId()))
|
||||
.stream()
|
||||
.map(m -> SelectOption.builder().label(m.getEnvCode()).value(m.getEnvCode()).build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void remove(ConfigAppEnv args) {
|
||||
if (args.getAppId() == null) {
|
||||
throw new BadRequestException("appId必填");
|
||||
}
|
||||
if (StrUtil.isBlank(args.getEnvCode())) {
|
||||
throw new BadRequestException("envCode必填");
|
||||
}
|
||||
// delete from config_app_env
|
||||
remove(
|
||||
new LambdaQueryWrapper<ConfigAppEnv>()
|
||||
.eq(ConfigAppEnv::getAppId, args.getAppId())
|
||||
.eq(ConfigAppEnv::getEnvCode, args.getEnvCode()));
|
||||
List<ConfigFile> configFiles =
|
||||
configFileService.getByAppIdEnvCode(args.getAppId(), args.getEnvCode());
|
||||
if (CollUtil.isNotEmpty(configFiles)) {
|
||||
// delete from config_file
|
||||
List<Long> configFileId =
|
||||
configFiles.stream().map(ConfigFile::getId).collect(Collectors.toList());
|
||||
configFileService.removeBatchByIds(configFileId);
|
||||
Long fileId = configFileId.stream().findFirst().orElse(null);
|
||||
if (fileId != null) {
|
||||
// delete from config_version
|
||||
configVersionService.removeBatchByFileId(fileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,15 +11,14 @@ import cn.odboy.service.ConfigFileService;
|
|||
import cn.odboy.service.ConfigVersionService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置文件 服务实现类
|
||||
*
|
||||
|
@ -73,13 +72,9 @@ public class ConfigFileServiceImpl extends ServiceImpl<ConfigFileMapper, ConfigF
|
|||
public void modifyFileContent(ConfigFile.ModifyFileContentArgs args) {
|
||||
String originConfigFileContent = getBaseMapper().selectContentByFileId(args.getId());
|
||||
if (StrUtil.isNotBlank(originConfigFileContent)) {
|
||||
originConfigFileContent = originConfigFileContent
|
||||
.replaceAll("\r", "")
|
||||
.replaceAll("\n", "");
|
||||
originConfigFileContent = originConfigFileContent.replaceAll("\r", "").replaceAll("\n", "");
|
||||
}
|
||||
String commitContent = args.getFileContent()
|
||||
.replaceAll("\r", "")
|
||||
.replaceAll("\n", "");
|
||||
String commitContent = args.getFileContent().replaceAll("\r", "").replaceAll("\n", "");
|
||||
if (originConfigFileContent.equals(commitContent)) {
|
||||
throw new BadRequestException("未变更配置,无需提交");
|
||||
}
|
||||
|
@ -146,11 +141,19 @@ public class ConfigFileServiceImpl extends ServiceImpl<ConfigFileMapper, ConfigF
|
|||
configVersionService.save(newConfigVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigFile> getByAppIdEnvCode(Long appId, String envCode) {
|
||||
return list(
|
||||
new LambdaQueryWrapper<ConfigFile>()
|
||||
.eq(ConfigFile::getAppId, appId)
|
||||
.eq(ConfigFile::getEnvCode, envCode));
|
||||
}
|
||||
|
||||
private ConfigFile getVersionBy(Long appId, String envCode, String fileName) {
|
||||
return getOne(new LambdaQueryWrapper<ConfigFile>()
|
||||
return getOne(
|
||||
new LambdaQueryWrapper<ConfigFile>()
|
||||
.eq(ConfigFile::getAppId, appId)
|
||||
.eq(ConfigFile::getEnvCode, envCode)
|
||||
.eq(ConfigFile::getFileName, fileName)
|
||||
);
|
||||
.eq(ConfigFile::getFileName, fileName));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue