package com.steering.mes.mcp.heatTreatment;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.Util.StringUtils;
import com.steering.comm.db.DBCommon;
import com.steering.common.EntityTool;
import com.steering.mes.mcp.entity.HttSteelChangeEntity;

import java.util.ArrayList;
import java.util.UUID;

public class FcaHttSteelChange extends DBCommon {

    /**
     * 查询接箍系数
     * @return
     */
    public CoreReturnObject doQuery(String flag) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FcaHttSteelChange.doQuery");
        if (!StringUtils.isEmpty(flag)) {
            sql += " AND T.VALIDFLAG = '" + flag +"'";
        }
        return this.getData(sql);
    }

    /**
     * 新增
     *
     * @param parm
     * @return
     */
    public CoreReturnObject doAdd(ArrayList<String> parm) {
        return this.setData(sqlSplit("FcaHttSteelChange.doAdd", parm, "doAdd"), null);
    }

    /**
     * 修改
     *
     * @param parm
     * @return
     */
    public CoreReturnObject doUpdate(ArrayList<String> parm) {
        return this.setData(sqlSplit("FcaHttSteelChange.doUpdate", parm, "doUpdate"), null);
    }

    /**
     * 作废/恢复
     *
     * @param parm
     * @return
     */
    public CoreReturnObject doNullifyOrRecover(ArrayList<String> parm) {
        return this.setData(sqlSplit("FcaHttSteelChange.doNullifyOrRecover", parm, "doNullifyOrRecover"), null);
    }

    private ArrayList<String> sqlSplit(String sqlID, ArrayList<String> parm, String add) {
        ArrayList<String> sqlList = new ArrayList<String>();// 存放执行语句
        for (String json : parm) {
            HttSteelChangeEntity Load = EntityTool.getEntityByJSONStr(json, HttSteelChangeEntity.class);
            if ("doAdd".equals(add)) {
                Load.setId(UUID.randomUUID().toString().replace("-", ""));
            }
            if (StringUtils.isEmpty(Load.getValidflag())) {
                Load.setValidflag("1");
            }
            String sql = CoreXmlSqlParsersFactory.getSql(sqlID);
            sql = EntityTool.fillSqlByEntity(sql, Load);
            sqlList.add(sql);
        }
        return sqlList;
    }
}
