package com.engine.salary.cmd.TaxRate;

import com.cloudstore.eccom.pc.table.WeaTableCheckboxpopedom;
import com.cloudstore.eccom.pc.table.WeaTableOperate;
import com.cloudstore.eccom.pc.table.WeaTableOperates;
import com.cloudstore.eccom.pc.table.WeaTablePopedom;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.salary.component.SalaryWeaTable;
import com.engine.salary.entity.taxrate.vo.TaxRateTableVO;
import com.engine.salary.util.db.DBType;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;

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

public class TaxRateListCmd extends AbstractCommonCommand<Map<String, Object>> {

    public TaxRateListCmd(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<String, Object>(16);

        String sql = "from (select  create_time,creator,delete_type, description, id, name, system_type, tenant_key, update_time  from hrsa_sys_tax_rate_base s " +
                " where s.delete_type = 0";

        DBType dbType = DBType.get(new RecordSet().getDBType());

        //模糊查询
        String name = Util.null2String(params.get("name"));
        if (StringUtils.isNotBlank(name)) {
            sql += " and s.name " + dbType.like(name);
        }
        sql += " union all " +
                " select create_time,creator,delete_type, description, id, name, system_type, tenant_key, update_time  " +
                " from hrsa_tax_rate_base b " +
                " where b.delete_type = 0 ";
        //模糊查询
        if (StringUtils.isNotBlank(name)) {
            sql += " and b.name " + dbType.like(name);
        }
        sql += ") t";

        SalaryWeaTable<TaxRateTableVO> table = new SalaryWeaTable<TaxRateTableVO>(user, TaxRateTableVO.class);
        table.setSqlform(sql);

        //设置check是否可用
        List<WeaTableCheckboxpopedom> checkboxpopedomList = new ArrayList<>();
        WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom();
        checkboxpopedom.setPopedompara("column:system_type");
        checkboxpopedom.setShowmethod("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom");
        checkboxpopedomList.add(checkboxpopedom);
        table.setCheckboxList(checkboxpopedomList);
        table.setCheckboxpopedom(null);

        List<WeaTableOperate> operateList = new ArrayList<>();
        WeaTableOperate editOperate = new WeaTableOperate("编辑", "", "0");
//        editOperate.setOtherpara("column:system_type");
//        editOperate.setIsalwaysshow("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom");
        operateList.add(editOperate);
        WeaTableOperate deleteOperate = new WeaTableOperate("删除", "", "1");
//        deleteOperate.setOtherpara("column:system_type");
//        deleteOperate.setIsalwaysshow("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom");
        operateList.add(deleteOperate);
        WeaTableOperate logOperate = new WeaTableOperate("操作日志", "", "3");
        operateList.add(logOperate);

        WeaTablePopedom popedom = new WeaTablePopedom();
        popedom.setTransmethod("com.engine.salary.transmethod.TaxRateTransMethod.getOpratePopedomWithType");
        popedom.setOtherpara("column:system_type");


        WeaTableOperates weaTableOperates = new WeaTableOperates();
        weaTableOperates.setOperate(operateList);
        weaTableOperates.setPopedom(popedom);
        table.setOperates(weaTableOperates);




        WeaResultMsg result = new WeaResultMsg(false);
        result.putAll(table.makeDataResult());
        result.success();
        apidatas = result.getResultMap();
        return apidatas;
    }


}
