package com.diagbot.aggregate;

import com.diagbot.dto.HomePageImproveDTO;
import com.diagbot.dto.HomePageNumDTO;
import com.diagbot.dto.NumDTO;
import com.diagbot.facade.BehospitalInfoFacade;
import com.diagbot.vo.FilterVO;
import io.github.lvyahui8.spring.annotation.DataConsumer;
import io.github.lvyahui8.spring.annotation.DataProvider;
import io.github.lvyahui8.spring.annotation.InvokeParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description:
 * @Author:zhaops
 * @time: 2020/7/22 11:45
 */
@Component
public class HomePageStatisticsAggregate {
    @Autowired
    private BehospitalInfoFacade behospitalInfoFacade;

    @DataProvider("setAllHomePage")
    public Map<String, Object> setAllHomePage(
            @InvokeParameter("filterVO") FilterVO filterVO,
            @DataConsumer("getQcNumDTO") HomePageNumDTO qcNumDTO,
            @DataConsumer("getEmptyNumDTO") HomePageNumDTO emptyNumDTO,
            @DataConsumer("getImproveDTO") HomePageImproveDTO improveDTO) {
        Map<String, Object> retMap = new LinkedHashMap<>();
        retMap.put("合格率", null);
        retMap.put("不合格率", null);
        retMap.put("完整率", null);
        retMap.put("改善率", null);

        if (qcNumDTO != null) {
            //合格率
            NumDTO pass = new NumDTO();
            pass.setName("合格率");
            pass.setNum(qcNumDTO.getFirstLevelNum());
            pass.setTotleNum(qcNumDTO.getMrNum());
            pass.setPercent(qcNumDTO.getFirstLevelPercent());
            pass.setPercentStr(qcNumDTO.getFirstLevelPercentStr());
            //不合格率
            NumDTO unPass = new NumDTO();
            unPass.setName("不合格率");
            unPass.setNum(qcNumDTO.getSecondLevelNum());
            unPass.setTotleNum(qcNumDTO.getMrNum());
            unPass.setPercent(qcNumDTO.getSecondLevelPercent());
            unPass.setPercentStr(qcNumDTO.getSecondLevelPercentStr());

            retMap.put("合格率", pass);
            retMap.put("不合格率", unPass);
        }
        if (emptyNumDTO != null) {
            //完整率
            NumDTO full = new NumDTO();
            full.setName("完整率");
            full.setNum(emptyNumDTO.getEntryTotleNum() - emptyNumDTO.getEmptyNum());
            full.setTotleNum(emptyNumDTO.getEntryTotleNum());
            full.setPercent(emptyNumDTO.getEmptyPercent());
            full.setPercentStr(emptyNumDTO.getEmptyPercentStr());

            retMap.put("完整率", full);
        }

        if (improveDTO != null) {
            //改善率
            NumDTO improve = new NumDTO();
            improve.setName("改善率");
            improve.setNum(improveDTO.getImproveNum());
            improve.setTotleNum(improveDTO.getHomePageMRNum());
            improve.setPercent(improveDTO.getImprovePercent());
            improve.setPercentStr(improveDTO.getImprovePercentStr());

            retMap.put("改善率", improve);
        }
        return retMap;
    }

    /**
     * 合格率
     *
     * @param filterVO
     * @return
     */
    @DataProvider("getQcNumDTO")
    public HomePageNumDTO getQcNumDTO(@InvokeParameter("filterVO") FilterVO filterVO) {
        return behospitalInfoFacade.homePageQcPercent(filterVO);
    }

    /**
     * 完整率
     *
     * @param filterVO
     * @return
     */
    @DataProvider("getEmptyNumDTO")
    public HomePageNumDTO getEmptyNumDTO(@InvokeParameter("filterVO") FilterVO filterVO) {
        return behospitalInfoFacade.hmEmptyEntryPercent(filterVO);
    }

    /**
     * 改善率
     *
     * @param filterVO
     * @return
     */
    @DataProvider("getImproveDTO")
    public HomePageImproveDTO getImproveDTO(@InvokeParameter("filterVO") FilterVO filterVO) {
        return behospitalInfoFacade.homePageImproveCount(filterVO);
    }
}