jinlin
2023-11-14 3a985f6b77989c95029d273864aa5f782e15ef96
modules/mainPart/src/main/java/com/zt/life/modules/project/service/SoftwareTestOrderService.java
@@ -1,6 +1,11 @@
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.project.dao.SoftwareTestOrderDao;
import com.zt.life.modules.project.dto.SoftwareTestOrderDto;
import com.zt.life.modules.project.model.SoftwareTestOrder;
@@ -8,14 +13,22 @@
import com.zt.life.modules.project.model.SoftwareTestOrderMeasured;
import com.zt.life.modules.sysBaseInfo.service.TestAgencyInfoService;
import com.zt.modules.coderule.service.SysCodeRuleService;
import com.zt.modules.sys.service.SysDictTypeService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -37,6 +50,11 @@
    private TestAgencyInfoService testAgencyInfoService;
    @Autowired
    private SysCodeRuleService sysCodeRuleService;
    @Autowired
    private SysDictTypeService sysDictTypeService;
    @Autowired
    private WordFileService wordFileService;
    /**
     * 分页查询
@@ -71,7 +89,7 @@
            softwareTestOrderId = softwareTestOrderDto.getSoftwareTestOrder().getId();
        }
        for (SoftwareTestOrderMeasured softwareTestOrderMeasured : softwareTestOrderDto.getSoftwareTestOrderMeasuredList()) {
        for (SoftwareTestOrderMeasured softwareTestOrderMeasured : softwareTestOrderDto.getMeasuredList()) {
            softwareTestOrderMeasured.setOrderId(softwareTestOrderId);
            if (softwareTestOrderMeasured.getId() != null) {
                softwareTestOrderMeasuredService.update(softwareTestOrderMeasured);
@@ -80,7 +98,7 @@
            }
        }
        for (SoftwareTestOrderDeliverable softwareTestOrderDeliverable : softwareTestOrderDto.getSoftwareTestOrderDeliverableList()) {
        for (SoftwareTestOrderDeliverable softwareTestOrderDeliverable : softwareTestOrderDto.getDeliverableList()) {
            softwareTestOrderDeliverable.setOrderId(softwareTestOrderId);
            if (softwareTestOrderDeliverable.getId() != null) {
                softwareTestOrderDeliverableService.update(softwareTestOrderDeliverable);
@@ -98,4 +116,116 @@
        return true;
    }
    public SoftwareTestOrderDto getDto(Long orderId, Long projectId) {
        SoftwareTestOrderDto data = new SoftwareTestOrderDto();
        if (orderId != null) {
            data.setId(orderId);
            SoftwareTestOrder softwareTestOrder = this.get(orderId);
            data.setSoftwareTestOrder(softwareTestOrder);
            if (projectId == null)
                projectId = softwareTestOrder.getProjectId();
            data.setTestAgencyInfo(testAgencyInfoService.get(orderId));
            List<SoftwareTestOrderDeliverable> deliverableList = softwareTestOrderDeliverableService.childrenTables(orderId);
            if (deliverableList.isEmpty()) {
                deliverableList = this.deliverableDict();
                deliverableList = deliverableList.stream()
                        .peek(deliverable -> {
                            if (deliverable.getIdentify() == null) {
                                // 修改 identify 字段的值为新值
                                deliverable.setIdentify("1.0.0");
                            }
                        })
                        .collect(Collectors.toList());
            }
            data.setDeliverableList(deliverableList);
            List<SoftwareTestOrderMeasured> measuredList = softwareTestOrderMeasuredService.childrenTables(orderId);
            if (measuredList.isEmpty()) {
                measuredList = this.MeasuredDict();
                measuredList = measuredList.stream()
                        .peek(measured -> {
                            if (measured.getIdentify() == null) {
                                // 修改 identify 字段的值为新值
                                measured.setIdentify("1.0.0");
                            }
                        })
                        .collect(Collectors.toList());
            }
            data.setMeasuredList(measuredList);
        } else {
            data.setTestAgencyInfo(testAgencyInfoService.get(10000L));
        }
        if (projectId != null) {
            data.setProjectId(projectId);
            data.setProject(projectService.get(projectId));
        }
        return data;
    }
    public List<SoftwareTestOrderDeliverable> deliverableDict() {
        return baseDao.getdeliverableDictList();
    }
    public List<SoftwareTestOrderMeasured> MeasuredDict() {
        return baseDao.getMeasuredDictList();
    }
    public void exportWord(Long id, HttpServletRequest request, HttpServletResponse response) {
        WordFile wordFile = new WordFile();
        wordFile.setModulePath("aaaa");
        wordFile.setWordName("aaa");
        SoftwareTestOrderDto dataObj = this.getDto(id, null);
        List<DictDto> userDicts = sysDictTypeService.getUserDicts();
        DictDto testType1Dict = userDicts.stream()
                .filter(c -> c.getDictType().equals("test_type1"))
                .collect(Collectors.toList()).get(0);
        List<String> testType11 = new ArrayList<>();
        List<String> testType12 = new ArrayList<>();
        List<String> testType21 = new ArrayList<>();
        List<String> testType22 = new ArrayList<>();
        int i = 0;
        String testType = "," + dataObj.getSoftwareTestOrder().getTestType1() + ",";
        for (DictItemDto dictItemDto : ((DictLeafDto) testType1Dict).getDataList()) {
            String value = dictItemDto.getDictValue();
            String desc = (testType.contains("," + value + ",")?"☑":"□")+dictItemDto.getDictLabel();
            if ((i++) % 2 == 0) {
                testType12.add(desc);
            } else {
                testType11.add(desc);
            }
        }
        i = 0;
        testType = "," + dataObj.getSoftwareTestOrder().getTestType2() + ",";
        for (DictItemDto dictItemDto : ((DictLeafDto) testType1Dict).getDataList()) {
            String value = dictItemDto.getDictValue();
            String desc = (testType.contains("," + value + ",")?"☑":"□")+dictItemDto.getDictLabel();
            if ((i++) % 2 == 0) {
                testType22.add(desc);
            } else {
                testType21.add(desc);
            }
        }
        dataObj.getSoftwareTestOrder().setTestType11(testType11);
        dataObj.getSoftwareTestOrder().setTestType12(testType12);
        dataObj.getSoftwareTestOrder().setTestType21(testType21);
        dataObj.getSoftwareTestOrder().setTestType22(testType22);
        List<Object> measuredList = new ArrayList<>();
        try {
            wordFileService.exportWordFile(request, dataObj, wordFile, response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}