package com.steering.pss.plnsaleord.steelMarkingPlan;

import java.util.ArrayList;

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

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.processOrder.entity.SlmBaseMaterialAPlEntity;

public class FrmBasematerialAPl extends DBCommon {
    public CoreReturnObject getBaseMaterialA(String inMaterialNo,
            String outMaterialNo) {
        Object[] params = new Object[] { inMaterialNo, outMaterialNo };
        return this.getDataBySqlID("FrmBasematerialAPl.getBaseMaterialA",
                params);
    }

    public CoreReturnObject getBaseMaterialAPl(String plineCode,
            String outMaterialNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmBasematerialAPl.getBaseMaterialAPl");
        if (!plineCode.equals("")) {
            sql += "    AND T.PLINE_CODE = '"+plineCode+"'";
        }
        if (!outMaterialNo.equals("")) {
            sql += " AND T.OUT_MATERIAL_NO = '"+outMaterialNo+"'";
        }
        return this.getData(sql);
    }

    /**
     * 修改
     * @param jsonStrList
     * @return
     */
    public CoreReturnObject updateBaseMaterialAPl(ArrayList<String> jsonStrList) {
        ArrayList<String> sqlList = new ArrayList<String>();
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmBasematerialAPl.updateBaseMaterialAPl");
        for (String jsonStr : jsonStrList) {
            JSONObject obj = JSONObject.fromObject(jsonStr);
            SlmBaseMaterialAPlEntity entity = (SlmBaseMaterialAPlEntity) JSONObject
                    .toBean(obj, SlmBaseMaterialAPlEntity.class);
            if (entity.getDisableFl().equals("True")) {
                entity.setDisableFl("1");
            }
            else {
                entity.setDisableFl("0");
            }
            sql = EntityTool.fillSqlByEntity(sql, entity);
            sqlList.add(sql);
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqlList);
    }
}
