6
jinlin
2023-12-03 c8d8a511f45c96ed3a5123a88e48de2ffdbf632a
modules/mainPart/src/main/java/com/zt/life/modules/project/service/EnvironService.java
@@ -1,20 +1,38 @@
package com.zt.life.modules.project.service;
import com.zt.common.service.BaseService;
import com.zt.core.sys.dto.DictDto;
import com.zt.core.sys.dto.DictItemDto;
import com.zt.core.sys.dto.DictLeafDto;
import com.zt.life.export.dto.WordFile;
import com.zt.life.export.service.WordFileService;
import com.zt.life.modules.mainPart.utils.GetShowDictList;
import com.zt.life.modules.project.dao.EnvironDao;
import com.zt.life.modules.project.dto.EnvironDto;
import com.zt.life.modules.project.dto.SoftwareTestOrderDto;
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.dto.OssDto;
import com.zt.life.sys.service.SysOssConfigService;
import com.zt.modules.coderule.service.SysCodeRuleService;
import com.zt.modules.oss.cloud.LocalStorageService;
import com.zt.modules.oss.model.SysOss;
import com.zt.modules.oss.service.SysOssService;
import com.zt.modules.sys.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.zt.common.db.query.QueryFilter;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -33,7 +51,10 @@
    private EnvironHardwareResourcesService environHardwareResourcesService;
    @Autowired
    private SoftwareTestOrderService softwareTestOrderService;
    private GetShowDictList getShowDictList;
    @Autowired
    private WordFileService wordFileService;
    @Autowired
    private SysCodeRuleService sysCodeRuleService;
@@ -50,10 +71,19 @@
    @Autowired
    private TestAgencyInfoService testAgencyInfoService;
    @Autowired
    private SysOssService sysOssService;
    public SoftwareTestOrderDto getDto(Long environId, Long projectId) {
        SoftwareTestOrderDto data = new SoftwareTestOrderDto();
    @Autowired
    private LocalStorageService localStorageService;
    @Value("${zt.oss.local-path}")
    private String localPath;
    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));
@@ -68,7 +98,7 @@
            List<EnvironAnalysis> environAnalysesList = environAnalysisService.getList(environId);
            data.setEnvironAnalysisList(environAnalysesList);
        } else {
            Environ environ =new Environ();
            Environ environ = new Environ();
            data.setEnviron(environ);
        }
        if (projectId != null) {
@@ -77,6 +107,12 @@
        }
        if (data.getTestAgencyInfo() == null)
            data.setTestAgencyInfo(testAgencyInfoService.get(10000L));
        if (environId != null) {
            OssDto ossDto = sysOssConfigService.getOssByBusiType(environId, "test_environt_diagram");
            if (ossDto != null) {
                data.setFiles(ossDto);
            }
        }
        return data;
    }
@@ -100,25 +136,25 @@
        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");
            map.put("year",year);
            softwareTestOrderDto.getEnviron().setYear(year);
            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();
        }
        int i = 0;
        for (EnvironSoftwareResources environSoftwareResources : softwareTestOrderDto.getSoftwareResourcesList()) {
        for (EnvironSoftwareResources environSoftwareResources : environDto.getSoftwareResourcesList()) {
            environSoftwareResources.setEnvironId(environId);
            if (environSoftwareResources.getId() != null) {
                environSoftwareResourcesService.update(environSoftwareResources);
@@ -130,7 +166,7 @@
            }
        }
        i = 0;
        for (EnvironHardwareResources environHardwareResources : softwareTestOrderDto.getHardwareResourcesList()) {
        for (EnvironHardwareResources environHardwareResources : environDto.getHardwareResourcesList()) {
            environHardwareResources.setEnvironId(environId);
            if (environHardwareResources.getId() != null) {
                environHardwareResourcesService.update(environHardwareResources);
@@ -143,7 +179,7 @@
        }
        i = 0;
        for (EnvironAnalysis environAnalysis : softwareTestOrderDto.getEnvironAnalysisList()) {
        for (EnvironAnalysis environAnalysis : environDto.getEnvironAnalysisList()) {
            environAnalysis.setEnvironId(environId);
            if (environAnalysis.getId() != null) {
                environAnalysisService.update(environAnalysis);
@@ -154,13 +190,51 @@
                environAnalysisService.insert(environAnalysis);
            }
        }
        if (softwareTestOrderDto.getTestAgencyInfo().getId() == 10000) {
            softwareTestOrderDto.getTestAgencyInfo().setId(environId);
            testAgencyInfoService.insert(softwareTestOrderDto.getTestAgencyInfo());
        if (environDto.getTestAgencyInfo().getId() == 10000) {
            environDto.getTestAgencyInfo().setId(environId);
            testAgencyInfoService.insert(environDto.getTestAgencyInfo());
        } else {
            testAgencyInfoService.update(softwareTestOrderDto.getTestAgencyInfo());
            testAgencyInfoService.update(environDto.getTestAgencyInfo());
        }
        sysOssConfigService.updateOss(softwareTestOrderDto.getEnviron().getId(), softwareTestOrderDto.getFiles());// 保存附件
        sysOssConfigService.updateOss(environDto.getEnviron().getId(), environDto.getFiles());// 保存附件
        return true;
    }
    public void exportEnviron(Long id, HttpServletRequest request, HttpServletResponse response) {
        try {
            EnvironDto dataObj = this.getDto(id, null);
            String imagePath = "文件图片:"+getFirstImagePath(dataObj.getFiles());
            dataObj.getEnviron().setTestEnvirontDiagram(imagePath);
            //通用字典列表字符串生成
            String isVirusScanStr = getShowDictList.getShowDictList(dataObj.getEnviron().getIsVirusScan(), "is_or_not", false);
            dataObj.getEnviron().setIsVirusScanStr(isVirusScanStr);
            WordFile wordFile = new WordFile();
            wordFile.setModulePath("测试环境建立确认表.docx");
            wordFile.setWordName(dataObj.getProject().getSoftwareName() + "_测试环境建立确认表.docx");
            wordFileService.exportWordFile(request, dataObj, wordFile, response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    public String getFirstImagePath(OssDto oss) {
        String filePath = "";
        if (oss != null) {
            if (oss.getGroups().size() > 0) {
                OssDto.OssFieldGroupDto group = oss.getGroups().get(0);
                if (group.getFields().size() > 0) {
                    OssDto.OssFieldDto field = group.getFields().get(0);
                    if (field.getFiles().size() > 0) {
                        com.zt.core.oss.dto.OssDto file = field.getFiles().get(0);
                        SysOss sysOss = sysOssService.get(file.getId());
                        filePath = localPath+sysOss.getPath();
                    }
                }
            }
        }
        return filePath;
    }
}