package com.engine.htsc.subcompany.tools;

import com.engine.htsc.subcompany.dao.UfZgssplDao;
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 LhghgkUfzgsServiceTools extends UfzgsServiceTools {

    private final UfZgssplDao ufZgssplDao = new UfZgssplDao();

    @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<UfZgsspl> ufFzjgsplTy = 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())){
                ufFzjgsplBm.add(ufZgsspl);
            }else if (ufZgsspl.getJg().equals(zgsUser.getZgsDept().getDepTypeCode())&&"".equals(Util.null2String(ufZgsspl.getBm()))){
                ufFzjgsplJg.add(ufZgsspl);
            }else if ("".equals(Util.null2String(ufZgsspl.getBm()))&&"".equals(Util.null2String(ufZgsspl.getJg()))){
                ufFzjgsplTy.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);
        }else if (ufFzjgsplTy.size()>0){
            ufFzjgsplR.addAll(ufFzjgsplTy);
        }
        for(UfZgsspl ufZgsspl:ufFzjgsplR){
            JAVATools.writelog("筛选审批链id为："+ufZgsspl.getId());
            ReportSequenceVO reportSequenceVO = getVo(ufZgsspl,zgsUser,map,unumbercode);
            resultList.add(reportSequenceVO);
        }
        return resultList;
    }

    //财务中心会计
    @Override
    protected String getKj(String value, HashMap<String, String> map, ZgsUser zgsUser) {
        String hrmids="";
        for (String hrmst:value.split(",") ) {
            String hrmid=getHrmType(hrmst);
            //不是指定WK_则判断是否为1
            if("".equals(hrmid)){
                //如果是1的情况下，便从获取对应负责人id
                if ("1".equals(hrmst)){
                    String fyhj = ufZgssplDao.getFykj(map.get("fkdd"));
                    if (!"".equals(fyhj)) {
                        hrmids += hrmids == "" ? fyhj : "," + fyhj;
                    }
                }
            }else{
                hrmids+=hrmids==""?hrmid:","+hrmid;
            }
        }
        return hrmids ;
    }

}
