package com.engine.htsc.subcompany.tools;

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 weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

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

public class ZgfkUfzgsServiceTools extends UfzgsServiceTools {
    @Override
    public List<ReportSequenceVO> convertModelToVO(List<UfZgsspl> ufZgssplList, String userId, HashMap<String, String> map, String unumbercode) {
        List<ReportSequenceVO> resultList = new ArrayList<>();
        //获取人员及部门信息
        ZgsUser zgsUser = new ZgsUser(userId);
        //获取审批链List过滤条件
        List<UfZgsspl> ufFzjgsplRy = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplBm = new ArrayList<>();
        List<UfZgsspl> ufFzjgsplJg = new ArrayList<>();
        //匹配条件的list
        List<UfZgsspl> ufFzjgsplR = new ArrayList<>();
        //过滤审批链
        for(UfZgsspl ufZgsspl:ufZgssplList){
            //判断条件
            if(null!=ufZgsspl.getTj()&&!"".equals(ufZgsspl.getTj())){
                if(!getConitionParams(ufZgsspl.getTj(),map)){
                    continue;
                }
            }
            List<String> list = Arrays.asList(Util.null2String(ufZgsspl.getBm()).split(","));
            if (ufZgsspl.getCxsprjs().equals("WK_"+zgsUser.getWorkCode())){
                ufFzjgsplRy.add(ufZgsspl);//单人，联合部分为董事会或执行委员会成员,且要是董事会或执行委员会的账号
            }else if (list.contains(zgsUser.getDepId())||list.contains(zgsUser.getDepCode())){
                ufFzjgsplBm.add(ufZgsspl);
            }else if (ufZgsspl.getJg().equals(zgsUser.getZgsDept().getDepTypeCode())&&"".equals(Util.null2String(ufZgsspl.getBm()))){
                ufFzjgsplJg.add(ufZgsspl);
            }
        }
        if (ufFzjgsplRy.size()>0){
            ufFzjgsplR.addAll(ufFzjgsplRy);
        }else if (ufFzjgsplBm.size()>0){
            ufFzjgsplR.addAll(ufFzjgsplBm);
        }else if (ufFzjgsplJg.size()>0){
            ufFzjgsplR.addAll(ufFzjgsplJg);
        }
        for(UfZgsspl ufZgsspl:ufFzjgsplR){
            JAVATools.writelog("筛选审批链id为："+ufZgsspl.getId());
            ReportSequenceVO reportSequenceVO = getVo(ufZgsspl,zgsUser,map,unumbercode);
            resultList.add(reportSequenceVO);
        }
        return resultList;
    }

    //固收业务负责人（资管特有）
    protected String getGsywfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String gsywfzrsp = Util.null2String(map.get("gsywfzrsp"));
        String hrmids = "";
        //资管通用付款由前端之前传入
        if(!"".equals(gsywfzrsp)){
            hrmids = gsywfzrsp;
        }
        return hrmids ;
    }

    //二级部门负责人
    protected String getEjbmfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        //资管暂不考虑二级部门负责人
        return hrmids ;
    }

    //一级部门负责人
    protected String getYjbmfzr(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String fycdbmldsp = Util.null2String(map.get("fycdbmldsp"));
        String hrmids = "";
        //紫金通用付款由前端之前传入
        if(!"".equals(fycdbmldsp)){
            hrmids = fycdbmldsp;
        }
        return hrmids ;
    }
    //分管领导
    protected String getFgld(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids = "";
        ZgsDept zgsDept = new ZgsDept(map.get("fycdbm"));
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    if (null!=zgsDept.getLeaderId()&&!"".equals(zgsDept.getLeaderId())){
                        hrmids+=hrmids==""?zgsDept.getLeaderId():","+zgsDept.getLeaderId();
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }

}
