|
@@ -0,0 +1,94 @@
|
|
|
|
|
+package cn.seecoder.web.service.impl.devmanage;
|
|
|
|
|
+
|
|
|
|
|
+import cn.seecoder.web.dao.pipeline.DeploymentMapper;
|
|
|
|
|
+import cn.seecoder.web.dao.pipeline.PipelineRecordMapper;
|
|
|
|
|
+import cn.seecoder.web.dao.user.UserMapper;
|
|
|
|
|
+import cn.seecoder.web.model.po.pipeline.DeploymentPO;
|
|
|
|
|
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
|
|
|
|
|
+import cn.seecoder.web.model.po.user.UserPO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.devmanage.DeploymentVO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.user.UserVO;
|
|
|
|
|
+import cn.seecoder.web.service.devmanage.DevmanageService;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class DevmanageServiceImpl implements DevmanageService {
|
|
|
|
|
+ private final DeploymentMapper deploymentMapper;
|
|
|
|
|
+ private final PipelineRecordMapper pipelineRecordMapper;
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
|
|
+ private static final int[] validPageSizes = new int[]{5, 10, 20};
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<DeploymentVO> getPagedDeployments(Integer pageNo, Integer pageSize) {
|
|
|
|
|
+ if (isInvalidPageSize(pageSize)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DeploymentPO> deploymentPOList = deploymentMapper.selectPagedDeployments(pageNo, pageSize);
|
|
|
|
|
+ List<DeploymentVO> deploymentVOList = new ArrayList<>();
|
|
|
|
|
+ for (DeploymentPO po: deploymentPOList) {
|
|
|
|
|
+ deploymentVOList.add(new DeploymentVO(po));
|
|
|
|
|
+ }
|
|
|
|
|
+ return deploymentVOList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<DeploymentVO> searchPagedDeployments(String keyword, Integer pageNo, Integer pageSize) {
|
|
|
|
|
+ if (isInvalidPageSize(pageSize)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DeploymentPO> deploymentPOList = deploymentMapper.searchDeployments(keyword, pageNo, pageSize);
|
|
|
|
|
+ List<DeploymentVO> deploymentVOList = new ArrayList<>();
|
|
|
|
|
+ for (DeploymentPO po: deploymentPOList) {
|
|
|
|
|
+ deploymentVOList.add(new DeploymentVO(po));
|
|
|
|
|
+ }
|
|
|
|
|
+ return deploymentVOList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public UserVO getOwnerOfNamespace(String namespace) {
|
|
|
|
|
+ DeploymentPO deploymentPO = deploymentMapper.selectByNamespace(namespace);
|
|
|
|
|
+ return new UserVO(getUserPO(deploymentPO));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public UserVO getOwnerOfDeployment(String deployName) {
|
|
|
|
|
+ DeploymentPO deploymentPO = deploymentMapper.selectByDeployName(deployName);
|
|
|
|
|
+ return new UserVO(getUserPO(deploymentPO));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Integer getTotalPageCount(Integer pageSize) {
|
|
|
|
|
+ Integer totalItemCount = deploymentMapper.selectTotalItemCount();
|
|
|
|
|
+ return totalItemCount / pageSize + (totalItemCount % pageSize == 0 ? 0 : 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isInvalidPageSize(Integer pageSize) {
|
|
|
|
|
+ for (int validPageSize: validPageSizes) {
|
|
|
|
|
+ if (validPageSize == pageSize) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private UserPO getUserPO(DeploymentPO deploymentPO) {
|
|
|
|
|
+ Integer pipelineId = deploymentPO.getPipelineId();
|
|
|
|
|
+ List<PipelineRecordPO> pipelineRecordPOS = pipelineRecordMapper.selectByPipelineId(pipelineId);
|
|
|
|
|
+ if (pipelineRecordPOS.size() == 0) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer userId = pipelineRecordPOS.get(0).getUserId();
|
|
|
|
|
+ return userMapper.select(userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|