package com.engine.salary.cmd.sischeme;

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.sischeme.vo.SISchemeTableVO;
import weaver.hrm.User;

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

/**
 * @Author weaver_cl
 * 
 * @Date 2022/3/10
 * @Version V1.0
 **/
@Deprecated
public class SISchemeListCmd extends AbstractCommonCommand<Map<String, Object>> {

    public SISchemeListCmd(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<SISchemeTableVO> table = new SalaryWeaTable<>(user,SISchemeTableVO.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 a.id = b.primary_id and b.insurance_id = c.id and a.delete_Type = 0";

        Integer welfareType = (Integer)params.get("welfareType");


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

        return sqlWhere;
    }
}
