package com.steering.pss.qcm;

import java.util.ArrayList;

import net.sf.json.JSONObject;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;
import com.steering.pss.qcm.model.ComBaseChemRatioEntity;
 
public class CoreComBaseChemRatio extends DBCommon {

    public CoreReturnObject query(Boolean flag) {
        Object[] obj = new Object[] { flag ? "1" : "0" };
        return this.getDataBySqlID("CoreComBaseChemRatio.QUERY", obj);
    }

    public CoreReturnObject getChem() {

        return this.getDataBySqlID("CoreComBaseChemRatio.QUERYChem");
    }

    public CoreReturnObject getRatio() {

        return this.getDataBySqlID("CoreComBaseChemRatio.QUERYRatio");
    }

    public CoreReturnObject save(ArrayList<Object> list) {

        ArrayList<String> sqlIdList = new ArrayList<String>();
        // 字段集合
        ArrayList<Object[]> params = new ArrayList<Object[]>();
        CoreReturnObject cro = new CoreReturnObject();
        for (int i = 0; i < list.size(); i++) {
            JSONObject json = JSONObject.fromObject(list.get(i).toString());
            ComBaseChemRatioEntity res = (ComBaseChemRatioEntity) JSONObject
                    .toBean(json, ComBaseChemRatioEntity.class);
            if (res.getValidflag().equals("")) {
                Object[] obj = new Object[] { res.getChemCode(),
                        res.getChemName(), res.getMinSign(), res.getMinValue(),
                        res.getMaxSign(), res.getMaxValue(),
                        res.getGroupText(), res.getRatioCode(),
                        res.getRatioName(), res.getRatioValue(),
                        res.getCreateName(), res.getMemo()
                };
                sqlIdList.add(CoreXmlSqlParsersFactory
                        .getSql("CoreComBaseChemRatio.INSERT"));
                params.add(obj);
            }
            else {
                Object[] obj = new Object[] { res.getChemCode(),
                        res.getChemName(), res.getMinSign(), res.getMinValue(),
                        res.getMaxSign(), res.getMaxValue(),
                        res.getGroupText(), res.getRatioCode(),
                        res.getRatioName(), res.getRatioValue(),
                        res.getCreateName(), res.getMemo(),
                        res.getChemCodeOld(), res.getGroupTextOld(),
                        res.getRatioCodeOld()
                };
                sqlIdList.add(CoreXmlSqlParsersFactory
                        .getSql("CoreComBaseChemRatio.UPDATE"));
                params.add(obj);
            }
        }
        cro = this.setData(sqlIdList, params);
        return cro;
    }

    public CoreReturnObject isReapt(String chem, String text, String ratio) {

        Object[] obj = new Object[] { chem, text, ratio };
        return this.getDataBySqlID("CoreComBaseChemRatio.ISREAPT", obj);

    }

    public CoreReturnObject deleteOrResume(ArrayList<Object> parm, Boolean flag) {

        ArrayList<String> sqlIdList = new ArrayList<String>();
        // 字段集合
        ArrayList<Object[]> params = new ArrayList<Object[]>();
        if (flag) {
            for (int i = 0; i < parm.size(); i++) {
                JSONObject json = JSONObject.fromObject(parm.get(i).toString());
                ComBaseChemRatioEntity res = (ComBaseChemRatioEntity) JSONObject
                        .toBean(json, ComBaseChemRatioEntity.class);
                Object[] obj = new Object[] { res.getDeleteName(),
                        res.getChemCode(), res.getGroupText(),
                        res.getRatioCode() };
                sqlIdList.add(CoreXmlSqlParsersFactory
                        .getSql("CoreComBaseChemRatio.DELETE"));
                params.add(obj);
            }
        }
        else {
            for (int i = 0; i < parm.size(); i++) {
                JSONObject json = JSONObject.fromObject(parm.get(i).toString());
                ComBaseChemRatioEntity res = (ComBaseChemRatioEntity) JSONObject
                        .toBean(json, ComBaseChemRatioEntity.class);
                Object[] obj = new Object[] { res.getChemCode(),
                        res.getGroupText(), res.getRatioCode()
                       };
                sqlIdList.add(CoreXmlSqlParsersFactory
                        .getSql("CoreComBaseChemRatio.RESUME"));
                params.add(obj);
            }
        }
        return this.setData(sqlIdList, params);
    }

}
