MatrixServiceImpl.java 2.83 KB
Newer Older
1 2
package com.ruoyi.service.impl;

王飞's avatar
王飞 committed
3 4
import com.ruoyi.domain.TestScenario;
import com.ruoyi.domain.TestType;
5
import com.ruoyi.domain.TestUseCase;
王飞's avatar
王飞 committed
6 7 8 9
import com.ruoyi.domain.vo.MatrixColumnVO;
import com.ruoyi.domain.vo.MatrixRowVO;
import com.ruoyi.service.ITestScenarioService;
import com.ruoyi.service.ITestTypeService;
10 11 12 13 14
import com.ruoyi.service.MatrixService;
import com.ruoyi.service.TestUseCaseService;
import com.ruoyi.web.response.MatrixResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
王飞's avatar
王飞 committed
15
import org.springframework.transaction.annotation.Transactional;
16

王飞's avatar
王飞 committed
17 18 19
import java.time.format.TextStyle;
import java.util.ArrayList;
import java.util.HashMap;
20
import java.util.List;
王飞's avatar
王飞 committed
21
import java.util.Map;
22

王飞's avatar
王飞 committed
23
@Transactional
24 25 26 27 28 29
@Service
public class MatrixServiceImpl implements MatrixService {

    @Autowired
    private TestUseCaseService testUseCaseService;

王飞's avatar
王飞 committed
30 31 32 33 34 35
    @Autowired
    private ITestScenarioService testScenarioService;

    @Autowired
    private ITestTypeService testTypeService;

36 37 38 39
    @Override
    public MatrixResponse getMatrix() {

        List<TestUseCase> useCases = testUseCaseService.list();
王飞's avatar
王飞 committed
40 41
        List<TestScenario> scenarios = testScenarioService.list();
        List<TestType> types = testTypeService.list();
42

王飞's avatar
王飞 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        MatrixResponse response = new MatrixResponse();
        setHeader(response, types);
        setRows(response, scenarios, types, useCases);

        return response;
    }

    private void setHeader(MatrixResponse response, List<TestType> types) {

        List<MatrixColumnVO> columns = new ArrayList();

        for(TestType type : types) {
            MatrixColumnVO column = new MatrixColumnVO(type.getId(), type.getTestType(), null);
            columns.add(column);
        }

        response.setHeader(columns);
60 61 62

    }

王飞's avatar
王飞 committed
63
    private void setRows(MatrixResponse response, List<TestScenario> scenarios, List<TestType> types, List<TestUseCase> useCases) {
64

王飞's avatar
王飞 committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        List<Map<String, Object>> rows = new ArrayList();


        for(TestScenario scenario : scenarios) {

            Map<String, Object> row = new HashMap();
            row.put("name", scenario.getTestScenario());

            for(TestType type : types) {
                String columnId = String.valueOf(type.getId());
                String coordinates = scenario.getId() + columnId;
                Long useCaseId = getUseCaseIdByCoordinates(useCases, coordinates);
                row.put(columnId, useCaseId == null ? "" : String.valueOf(useCaseId));
            }

            rows.add(row);
        }

        response.setRows(rows);
    }

    public Long getUseCaseIdByCoordinates(List<TestUseCase> useCases, String coordinates) {

        for(TestUseCase useCase : useCases) {
            if(useCase.getCoordinates().equals(coordinates)) {
                return useCase.getId();
            }
        }
        return null;
    }
95
}