|
|
@@ -2,20 +2,14 @@ package cn.reghao.autodop.dmaster.app.service.crud;
|
|
|
|
|
|
import cn.reghao.autodop.common.utils.data.db.CrudOps;
|
|
|
import cn.reghao.autodop.common.utils.data.db.PageList;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.config.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployApp;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.log.BuildDeployAppRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -23,18 +17,15 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class BuildDeployAppCrudService implements CrudOps<BuildDeployApp> {
|
|
|
- private AppOrchestrationRepository appRepository;
|
|
|
private BuildDeployAppRepository buildDeployAppRepository;
|
|
|
|
|
|
- public BuildDeployAppCrudService(AppOrchestrationRepository appRepository,
|
|
|
- BuildDeployAppRepository buildDeployAppRepository) {
|
|
|
- this.appRepository = appRepository;
|
|
|
+ public BuildDeployAppCrudService(BuildDeployAppRepository buildDeployAppRepository) {
|
|
|
this.buildDeployAppRepository = buildDeployAppRepository;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addOrUpdate(BuildDeployApp buildDeployApp) throws Exception {
|
|
|
- BuildDeployApp entity = buildDeployAppRepository.findByApp(buildDeployApp.getApp());
|
|
|
+ BuildDeployApp entity = buildDeployAppRepository.findByAppId(buildDeployApp.getAppId());
|
|
|
if (entity != null) {
|
|
|
buildDeployApp.setId(entity.getId());
|
|
|
buildDeployApp.setCreateTime(entity.getCreateTime());
|
|
|
@@ -46,41 +37,26 @@ public class BuildDeployAppCrudService implements CrudOps<BuildDeployApp> {
|
|
|
|
|
|
@Override
|
|
|
public PageList<BuildDeployApp> getByPage(int page, int size, String env) {
|
|
|
- PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "bdTime"));
|
|
|
- Page<BuildDeployApp> buildDeployApps = buildDeployAppRepository.findAll(pageRequest);
|
|
|
-
|
|
|
+ // 默认按更新时间倒序
|
|
|
+ PageRequest pageRequest =
|
|
|
+ PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
+ Page<BuildDeployApp> page1 =
|
|
|
+ buildDeployAppRepository.findByIsDeleteFalseAndEnableIsTrueAndEnv(env, pageRequest);
|
|
|
PageList<BuildDeployApp> pageList = new PageList<>();
|
|
|
- int minus = size - buildDeployApps.getContent().size();
|
|
|
- if (minus > 0) {
|
|
|
- PageRequest pageRequest1 =
|
|
|
- PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
- Page<AppOrchestration> apps = appRepository.findByIsDeleteFalseAndEnableIsTrueAndEnv(env, pageRequest1);
|
|
|
- if (minus == size) {
|
|
|
- pageList.setTotalSize(apps.getTotalElements());
|
|
|
- pageList.setTotalPages(apps.getTotalPages());
|
|
|
- pageList.setList(apps.getContent().stream().map(BuildDeployApp::new).collect(Collectors.toList()));
|
|
|
- } else {
|
|
|
- Set<BuildDeployApp> set = new HashSet<>(buildDeployApps.getContent());
|
|
|
- List<BuildDeployApp> list = apps.getContent().stream()
|
|
|
- .map(BuildDeployApp::new).collect(Collectors.toList());
|
|
|
-
|
|
|
- for (BuildDeployApp buildDeployApp : list) {
|
|
|
- if (!set.contains(buildDeployApp) && minus != 0) {
|
|
|
-
|
|
|
- minus--;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- pageList.setTotalSize(buildDeployApps.getTotalElements());
|
|
|
- pageList.setTotalPages(buildDeployApps.getTotalPages());
|
|
|
- pageList.setList(buildDeployApps.getContent());
|
|
|
- }
|
|
|
-
|
|
|
+ pageList.setTotalSize(page1.getTotalElements());
|
|
|
+ pageList.setTotalPages(page1.getTotalPages());
|
|
|
+ pageList.setList(page1.getContent());
|
|
|
return pageList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void delete(String uniqueKey) throws Exception {
|
|
|
+ BuildDeployApp entity = buildDeployAppRepository.findByIsDeleteFalseAndAppId(uniqueKey);
|
|
|
+ if (entity == null) {
|
|
|
+ throw new Exception(uniqueKey + " 不存在");
|
|
|
+ } else {
|
|
|
+ entity.setIsDelete(true);
|
|
|
+ buildDeployAppRepository.save(entity);
|
|
|
+ }
|
|
|
}
|
|
|
}
|