package com.engine.salary.cmd.sicategory;

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.sicategory.dto.ICategoryListDTO;
import weaver.hrm.User;

import java.util.Map;
import java.util.Objects;

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

    public SICategoryListCmd(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) {
        SalaryWeaTable<ICategoryListDTO> table = new SalaryWeaTable<>(user,ICategoryListDTO.class);
        String sqlWhere = buildSqlWhere(params);
        table.setSqlwhere(sqlWhere);

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

    private String buildSqlWhere(Map<String, Object> params) {
        String sqlWhere = "where delete_Type = 0 and data_type != 1";
        Integer welfareType = (Integer)params.get("welfareType");

        if (Objects.nonNull(welfareType)){
            sqlWhere += " and welfare_type ="+welfareType;
        }
        return sqlWhere;
    }
}
