package com.microservices.pms.test;

import com.alibaba.fastjson2.JSON;
import com.microservices.pms.enums.TestCaseStatus;
import com.microservices.pms.project.domain.PmsProjectTestsheetCases;
import com.microservices.pms.project.domain.vo.PmsProjectTestcaseStepDataVo;
import com.microservices.pms.project.domain.vo.PmsProjectTestsheetCaseStepVo;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class PmsProjectTestSheetTest {

    public static void main(String[] args) {
        List<PmsProjectTestsheetCases> testsheetCasesList= new ArrayList<PmsProjectTestsheetCases>();
        PmsProjectTestsheetCases a = new PmsProjectTestsheetCases();
        a.setTestStatus(1l);
        PmsProjectTestsheetCases b = new PmsProjectTestsheetCases();
        b.setTestStatus(1l);
        PmsProjectTestsheetCases c = new PmsProjectTestsheetCases();
        c.setTestStatus(3l);
        PmsProjectTestsheetCases d = new PmsProjectTestsheetCases();
        d.setTestStatus(3l);

        testsheetCasesList.add(a);
        testsheetCasesList.add(b);
        testsheetCasesList.add(c);
        testsheetCasesList.add(d);
        Map<Long, Integer> listMap = Optional.ofNullable(testsheetCasesList).orElse(Collections.emptyList()).stream()
                .collect(Collectors.groupingBy(PmsProjectTestsheetCases::getTestStatus, Collectors.summingInt(value -> 1)));
        listMap.forEach((key, value) -> System.out.println("" + key + ":" + value));

        Long passCount = Optional.ofNullable(testsheetCasesList).orElse(Collections.emptyList()).stream()
                .filter(testCase -> testCase.getTestStatus().intValue() == 1).count();
        // 总 = 失败+通过+阻塞+未执行(或者排除跳过的)
        Long execTotalCount = Optional.ofNullable(testsheetCasesList).orElse(Collections.emptyList()).stream()
                .filter(testCase -> testCase.getTestStatus().intValue() != 2).count();
        //Long execTotalCount = testsheetCasesList.stream().filter(testCase -> new HashSet<>(Arrays.asList(0L, 1L, 2L, 3L)).contains(testCase.getTestStatus())).count();
        // 通过率s
        System.out.println(passCount);
        System.out.println(execTotalCount);
        System.out.println(BigDecimal.valueOf(passCount / execTotalCount.doubleValue()).setScale(2, BigDecimal.ROUND_HALF_UP));
//        System.out.println(BigDecimal.valueOf(0 / 0d).setScale(2, BigDecimal.ROUND_HALF_UP));
        System.out.println(BigDecimal.valueOf(new Double("0.1114")));

        List<PmsProjectTestsheetCaseStepVo> testcaseStepList = new ArrayList<>();
        PmsProjectTestsheetCaseStepVo aaa = new PmsProjectTestsheetCaseStepVo();
        aaa.setStepId(1l);
        aaa.setStepStatus(1);
        PmsProjectTestsheetCaseStepVo bbb = new PmsProjectTestsheetCaseStepVo();
        bbb.setStepId(2l);
        bbb.setStepStatus(1);
        testcaseStepList.add(aaa);
        testcaseStepList.add(bbb);

        System.out.println(JSON.toJSONString(Optional.ofNullable(testcaseStepList).orElse(Collections.emptyList())));
        System.out.println(JSON.parseArray("[{\"stepId\":1,\"stepStatus\":1},{\"stepId\":2,\"stepStatus\":1}]", PmsProjectTestcaseStepDataVo.class));
        System.out.println(JSON.parseArray("[{\"stepId\":1,\"stepStatus\":1},{\"stepId\":2,\"stepStatus\":1}]", HashMap.class));

        Long[] testsheetCasesIds = testsheetCasesList.stream().map(PmsProjectTestsheetCases::getTestStatus).toArray(Long[]::new);
    }
}
