6
jinlin
2023-11-29 d89ef43c4713adf26f74b796653d1dd15ff1f81a
modules/mainPart/src/main/java/com/zt/life/modules/project/service/EnvironService.java
@@ -2,20 +2,20 @@
import com.zt.common.service.BaseService;
import com.zt.life.modules.project.dao.EnvironDao;
import com.zt.life.modules.project.dto.SoftwareTestOrderDto;
import com.zt.life.modules.project.dto.EnvironDto;
import com.zt.life.modules.project.model.*;
import com.zt.life.modules.sysBaseInfo.model.TestAgencyInfo;
import com.zt.life.modules.sysBaseInfo.service.TestAgencyInfoService;
import com.zt.life.sys.service.SysOssConfigService;
import com.zt.modules.coderule.service.SysCodeRuleService;
import com.zt.modules.oss.service.SysOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zt.common.db.query.QueryFilter;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -51,16 +51,18 @@
    @Autowired
    private TestAgencyInfoService testAgencyInfoService;
    @Autowired
    private SysOssService sysOssService;
    public SoftwareTestOrderDto getDto(Long projectId, Long environId) {
        SoftwareTestOrderDto data = new SoftwareTestOrderDto();
    public EnvironDto getDto(Long environId, Long projectId) {
        EnvironDto data = new EnvironDto();
        if (environId != null) {
            data.setId(environId);
            Environ environ = this.get(environId);
            data.setEnviron(environ);
            data.setTestAgencyInfo(testAgencyInfoService.get(environId));
            projectId = environ.getProjectId();
            List<EnvironSoftwareResources> softwareResourcesList = environSoftwareResourcesService.getList(environId);
            data.setSoftwareResourcesList(softwareResourcesList);
@@ -70,17 +72,15 @@
            List<EnvironAnalysis> environAnalysesList = environAnalysisService.getList(environId);
            data.setEnvironAnalysisList(environAnalysesList);
        } else {
            Project project = projectService.get(projectId);
            data.getEnviron().setSoftwareName(project.getSoftwareName());
            data.getEnviron().setSoftwareIdentity(project.getSoftwareIdentity());
            Environ environ =new Environ();
            data.setEnviron(environ);
        }
        if (projectId != null) {
            data.setProjectId(projectId);
            data.setProject(projectService.get(projectId));
        }
        if (data.getTestAgencyInfo() == null)
           data.getEnviron().setAgencyName(testAgencyInfoService.get(10000L).getAgencyName());
           data.getEnviron().setSite(testAgencyInfoService.get(10000L).getSite());
        if (projectId != null) {
            data.setOrderId(projectId);
            data.setSoftwareTestOrder(softwareTestOrderService.get(projectId));
        }
            data.setTestAgencyInfo(testAgencyInfoService.get(10000L));
        return data;
    }
@@ -104,50 +104,67 @@
        super.deleteLogic(ids);
    }
    public Boolean save(SoftwareTestOrderDto softwareTestOrderDto) {
        Long environId = softwareTestOrderDto.getEnviron().getId();
    public Boolean save(EnvironDto environDto) {
        Long environId = environDto.getEnviron().getId();
        if (environId != null)
            baseDao.updateById(softwareTestOrderDto.getEnviron());
            baseDao.updateById(environDto.getEnviron());
        else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            String year = sdf.format(new Date());
            Map<String, String> map = new HashMap<>();
            map.put("funCode", "environ");
            softwareTestOrderDto.getEnviron().setProjectId(softwareTestOrderDto.getProjectId());
            softwareTestOrderDto.getEnviron().setCode(sysCodeRuleService.getNewCode(map));
            baseDao.insert(softwareTestOrderDto.getEnviron());
            environId = softwareTestOrderDto.getEnviron().getId();
            map.put("projectId",environDto.getProjectId().toString());
            environDto.getEnviron().setYear(year);
            environDto.getEnviron().setProjectId(environDto.getProjectId());
            environDto.getEnviron().setCode(sysCodeRuleService.getNewCode(map));
            baseDao.insert(environDto.getEnviron());
            environId = environDto.getEnviron().getId();
        }
        for (EnvironSoftwareResources environSoftwareResources : softwareTestOrderDto.getSoftwareResourcesList()) {
        int i = 0;
        for (EnvironSoftwareResources environSoftwareResources : environDto.getSoftwareResourcesList()) {
            environSoftwareResources.setEnvironId(environId);
            if (environSoftwareResources.getId() != null) {
                environSoftwareResourcesService.update(environSoftwareResources);
            } else {
                i++;
                environSoftwareResources.setNo(i);
                environSoftwareResources.setEnvironId(environId);
                environSoftwareResourcesService.insert(environSoftwareResources);
            }
        }
        for (EnvironHardwareResources environHardwareResources : softwareTestOrderDto.getHardwareResourcesList()) {
        i = 0;
        for (EnvironHardwareResources environHardwareResources : environDto.getHardwareResourcesList()) {
            environHardwareResources.setEnvironId(environId);
            if (environHardwareResources.getId() != null) {
                environHardwareResourcesService.update(environHardwareResources);
            } else {
                i++;
                environHardwareResources.setNo(i);
                environHardwareResources.setEnvironId(environId);
                environHardwareResourcesService.insert(environHardwareResources);
            }
        }
        for (EnvironAnalysis environAnalysis : softwareTestOrderDto.getEnvironAnalysisList()) {
        i = 0;
        for (EnvironAnalysis environAnalysis : environDto.getEnvironAnalysisList()) {
            environAnalysis.setEnvironId(environId);
            if (environAnalysis.getId() != null) {
                environAnalysisService.update(environAnalysis);
            } else {
                i++;
                environAnalysis.setNo(i);
                environAnalysis.setEnvironId(environId);
                environAnalysisService.insert(environAnalysis);
            }
        }
        sysOssConfigService.updateOss(softwareTestOrderDto.getId(), softwareTestOrderDto.getFiles());// 保存附件
        if (environDto.getTestAgencyInfo().getId() == 10000) {
            environDto.getTestAgencyInfo().setId(environId);
            testAgencyInfoService.insert(environDto.getTestAgencyInfo());
        } else {
            testAgencyInfoService.update(environDto.getTestAgencyInfo());
        }
        sysOssConfigService.updateOss(environDto.getEnviron().getId(), environDto.getFiles());// 保存附件
        return true;
    }
}