package com.engine.salary.cmd.sicategory;

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 com.engine.salary.biz.SICategoryBiz;
import com.engine.salary.entity.sicategory.dto.ICategoryFormDTO;
import weaver.hrm.User;

import java.util.*;

/**
 * @Author weaver_cl
 * @Description:
 * @Date 2022/3/9
 * @Version V1.0
 **/
public class SICategoryGetFormCmd extends AbstractCommonCommand<Map<String, Object>> {

    public SICategoryGetFormCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
    }

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> apidatas = new HashMap<>(16);
        SICategoryBiz siCategoryBiz = new SICategoryBiz();
        Long id = (Long) params.get("id");
        ICategoryFormDTO form = siCategoryBiz.getForm(id);
        apidatas.put("form",form);
        ConditionFactory conditionFactory = new ConditionFactory(user);
        Map<String,SearchConditionItem> items = new HashMap<>();

        SearchConditionItem input = conditionFactory.createCondition(ConditionType.INPUT,502327, "insuranceName");
        input.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        input.setFieldcol(12);	//条件输入框所占宽度，默认值18
        input.setViewAttr(3);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        input.setLength(10);    //  设置输入长度
        input.setLabel("福利名称"); //设置文本值  这个将覆盖多语言标签的值
        input.setRules("required"); //设置字段填入规则

        items.put("insuranceName",input);

        SearchConditionItem radio = conditionFactory.createCondition(ConditionType.RADIO,502327,"welfareType");
        List<SearchConditionOption> radioOptions = new ArrayList <>();
        radioOptions.add(new SearchConditionOption("SOCIAL_SECURITY","社保",true));
        radioOptions.add(new SearchConditionOption("ACCUMULATION_FUND","公积金"));
        radioOptions.add(new SearchConditionOption("OTHER","企业年金及其他福利"));
        radio.setColSpan(2);
        radio.setFieldcol(12);
        radio.setLabelcol(6);
        radio.setViewAttr(3);
        radio.setIsQuickSearch(false);
        radio.setOptions(radioOptions);
        radio.setLabel("类型");
        radio.setRules("required");
        items.put("welfareType",radio);

        SearchConditionItem checkbox = conditionFactory.createCondition(ConditionType.CHECKBOX,502327,"paymentScope");
        List<SearchConditionOption> checkOptions = new ArrayList <>();
        checkOptions.add(new SearchConditionOption("SCOPE_COMPANY","公司"));
        checkOptions.add(new SearchConditionOption("SCOPE_PERSON","个人"));
        checkbox.setColSpan(2);
        checkbox.setFieldcol(12);
        checkbox.setLabelcol(6);
        checkbox.setViewAttr(3);
        checkbox.setIsQuickSearch(false);
        checkbox.setOptions(checkOptions);
        checkbox.setLabel("缴纳对象");
        checkbox.setRules("required");
        items.put("paymentScope",checkbox);

        apidatas.put("item",items);
        return apidatas;
    }
}
