package com.engine.htsc.subcompany.service.impl;

import com.engine.htsc.subcompany.model.ReportSequenceVO;
import com.engine.htsc.subcompany.model.UfZgsspl;
import com.engine.htsc.subcompany.model.ZgsDept;
import com.engine.htsc.subcompany.model.ZgsUser;
import com.engine.htsc.subcompany.tools.XgUfzgsServiceTools;
import weaver.general.Util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class XgtySubCompanyLinkServiceImpl extends SubCompanyLinkServiceImpl {

    protected XgUfzgsServiceTools xgUfzgsServiceTools = new XgUfzgsServiceTools();

    /**
     * 查询具体审批链
     * [香港子类重写]
     * @param unumbercode
     * @param reqMapList
     * @return
     */

    @Override
    protected List<ReportSequenceVO> getReportVO(String unumbercode, List<Map<String,String>> reqMapList) {
        //香港特殊逻辑
        List<ReportSequenceVO> respListBefore = new ArrayList<>();
        for(Map<String,String> mingxiMap : reqMapList) {
            String code = "";
            Double dxfymx = Util.getDoubleValue(Util.null2String(mingxiMap.get("dxfymx")));
            Double yssped = Util.getDoubleValue(Util.null2String(mingxiMap.get("yssped")));
            String cxsprjs = ufzgsplModelTools.getUfzgsJobGrade(mingxiMap.get("ngr"));
            if ("PT_LV2".equals(cxsprjs)||"FZR_LV2".equals(cxsprjs)){
                if (dxfymx<5000){
                    code = "0";
                }else {
                    code = "1";
                }
            }else {
                if (dxfymx<yssped||yssped<0){
                    code = "0";
                }else {
                    code = "1";
                }
            }
            mingxiMap.put("CASE", code);
        }
        for(Map<String,String> mingxiMap : reqMapList) {
            //根据不同业务获取Dao层入参
            Map<String,String> mapReqSql = this.getMapReqSql(unumbercode, mingxiMap);
            //查询初步符合条件的审批链
            List<UfZgsspl> ufFzjgsplList = ufZgssplDao.getUfzgsspl(mapReqSql);
            //条件过滤并赋值
            List<ReportSequenceVO> fzjgsplVoList = xgUfzgsServiceTools.convertModelToVO(ufFzjgsplList,mingxiMap.get("bxry"),(HashMap)mingxiMap,unumbercode);
            //费用承担部门不同时 获取的费用承担部门二级部门负责人和一级部门负责人
            ZgsUser zgsUser = new ZgsUser(Util.null2String(mingxiMap.get("bxry")));
            if (!zgsUser.getDepId().equals(Util.null2String(mingxiMap.get("fycdbm")))){
                ZgsDept fycdDept = new ZgsDept(Util.null2String(mingxiMap.get("fycdbm")));
                //如果是二级部门则放入二级部门负责人
                if ("2".equals(fycdDept.getDepLevel())){
                    for(ReportSequenceVO reportSequenceVO : fzjgsplVoList){
                        String ejbmfzr = reportSequenceVO.getEjbmfzr();
                        ejbmfzr += ejbmfzr==""? fycdDept.getDirectorId():","+fycdDept.getDirectorId();
                        reportSequenceVO.setEjbmfzr(ejbmfzr);
                        String yjbmfzr = reportSequenceVO.getYjbmfzr();
                        ZgsDept sjDept = new ZgsDept(fycdDept.getParentDepId());
                        yjbmfzr += yjbmfzr==""? sjDept.getDirectorId():","+sjDept.getDirectorId();
                        reportSequenceVO.setYjbmfzr(yjbmfzr);
                    }
                }else if ("1".equals(fycdDept.getDepLevel())){
                    for(ReportSequenceVO reportSequenceVO : fzjgsplVoList){
                        String yjbmfzr = reportSequenceVO.getYjbmfzr();
                        yjbmfzr += yjbmfzr==""? fycdDept.getDirectorId():","+fycdDept.getDirectorId();
                        reportSequenceVO.setYjbmfzr(yjbmfzr);
                    }
                }
            }
            respListBefore.addAll(fzjgsplVoList);
        }
        return respListBefore;
    }

}
