package com.kingdee.eas.hr.project.builder;

import com.google.common.collect.Maps;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.rabbitmq.guava.Lists;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.TreeBaseInfo;
import com.kingdee.eas.hr.project.*;
import com.kingdee.shr.base.syssetting.app.builder.CommonTreeBuilder;
import org.apache.commons.lang3.StringUtils;

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

/**
 * @BelongsProject: dataImpExp820
 * @BelongsPackage: com.kingdee.eas.hr.project.builder
 * @Author: lhbj
 * @CreateTime: 2024-11-27  19:15
 * @Description: TODO
 * @Version: 1.0
 */
public class ProjectMTreeBuilder extends CommonTreeBuilder {
    public Object getChildren(Context ctx, Map<String, String> params) throws EASBizException, BOSException {
        return null;
    }
    @Override
    public Object getAllNodes(Context ctx, Map<String, String> params) throws EASBizException, BOSException {
         super.getAllNodes(ctx, params);
         List<Map<String, Object>> list = Lists.newArrayList();
        list.add((Map<String, Object>)this.getRootNode(ctx,params));
        IProjectManagement pm = ProjectManagementFactory.getLocalInstance(ctx);
        StringBuffer sql = new StringBuffer("select * where projectState in('1','2')");
        String domain = params.get("domain");
        if(StringUtils.isNotBlank(domain)) {
            String userAdminOrgRangeSql = params.get("userAdminOrgRangeSql");
            sql.append("and adminOrg.id in(");
            sql.append(userAdminOrgRangeSql);
            sql.append(")");
        }
        ProjectManagementCollection pc = pm.getProjectManagementCollection(sql.toString());
        if(null!=pc&&!pc.isEmpty()) {
            for (int i=0;i<pc.size();i++) {
                ProjectManagementInfo pmInfo = pc.get(i);
                Map<String, Object> root = Maps.newHashMap();
                root.put("id", pmInfo.getId().toString());
                root.put("name", pmInfo.getProjectName());
                root.put("number", pmInfo.getNumber());
                root.put("longNumber", root.get("id"));
                root.put("isLeaf", false);
                root.put("isPosition", false);
                root.put("isEnable", true);
                root.put("orgType", null);
                root.put("level", 2);
                root.put("selectLevel", 0);
                root.put("earliestEffdt", null);
                root.put("isParent", false);
                root.put("parentId", "rootId");
                root.put("hasPermission", true);
                root.put("adjTypeMap", null);
                root.put("personNum", 0);
                root.put("enableStatus", false);
                list.add(root);
            }
        }

        return list;
    }
    public Object getRootNode(Context ctx, Map<String, String> params) throws EASBizException, BOSException {
        Map<String, Object> root = new HashMap();
        root.put("id", "rootId");
        root.put("name", "项目管理");
        root.put("longNumber", "");
        root.put("number", "rootId");
        root.put("isLeaf", false);
        root.put("isPosition", false);
        root.put("isEnable", true);
        root.put("orgType", null);
        root.put("level", 1);
        root.put("selectLevel", 0);
        root.put("earliestEffdt", null);
        root.put("isParent", false);
        root.put("parentId", null);
        root.put("hasPermission", true);
        root.put("adjTypeMap", null);
        root.put("personNum", 0);
        root.put("enableStatus", false);
        return root;

    }
}
