package com.engine.htsc.workflow.cmd;

import com.alibaba.fastjson.JSON;
import com.api.browser.bean.BrowserBean;
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.hrm.User;

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

public class DesignatedProcessorTableConditionCmd extends AbstractCommonCommand<Map<String, Object>> {
    public DesignatedProcessorTableConditionCmd(Map<String, Object> params, User user) {
        this.params = params;
        this.user = user;
    }


    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        writeLog("Enter DesignatedProcessorTableConditionCmd");
        Map<String, Object> apidatas = new HashMap<>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user) {
            apidatas.put("hasRight", false);
            return apidatas;
        }
        apidatas.put("hasRight", true);
        ConditionFactory conditionFactory = new ConditionFactory(user);
        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<>();
        List<SearchConditionItem> conditionItems = new ArrayList<>();

        //161
        // 流程框
        SearchConditionItem demo_select = conditionFactory.createCondition(ConditionType.BROWSER, 502327, "lc", "161");
        demo_select.setColSpan(2);
        demo_select.setFieldcol(16);
        demo_select.setLabelcol(8);
        demo_select.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        demo_select.setLabel("流程");

        //browser.ll_lcxx
        String fielddbtype = "browser.ll_lcxx";
        String type = "161";
        BrowserBean browserBean = demo_select.getBrowserConditionParam();
        Map<String, Object> conditionParams = new HashMap<>();
        conditionParams.put("type", fielddbtype);
        browserBean.setConditionDataParams(conditionParams);
        Map<String, Object> completeParams = new HashMap<>();
        completeParams.put("type", type);
        completeParams.put("fielddbtype", fielddbtype);
        browserBean.setCompleteParams(completeParams);
        browserBean.getDestDataParams().put("type", fielddbtype);
        browserBean.getDataParams().put("type", fielddbtype);
        demo_select.setBrowserConditionParam(browserBean);
        conditionItems.add(demo_select);

        //流程处理人
        SearchConditionItem dqpzld = conditionFactory.createCondition(ConditionType.BROWSER, 502327, "dqpzld", "17");
        dqpzld.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        dqpzld.setFieldcol(16);    //条件输入框所占宽度，默认值18
        dqpzld.setLabelcol(8);
        dqpzld.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        dqpzld.setLabel("流程处理人"); //设置文本值  这个将覆盖多语言标签的值
        conditionItems.add(dqpzld);

        addGroups.add(new SearchConditionGroup("", true, conditionItems));
        apidatas.put("condition", addGroups);
        writeLog("Result condition:" + JSON.toJSONString(apidatas));
        System.out.println(JSON.toJSONString(apidatas));
        return apidatas;
    }

}
