package com.steering.pss.pncost.base;

import java.sql.Connection;

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.qcm.model.GenericEntity;
import com.steering.pss.pncost.entity.CostBaseBatchingEntity;

public class ComBaseBatching extends DBCommon{
    public CoreReturnObject query(String strPei,String strChan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.query");
        if(!strPei.equals("")){
            sql += " AND BATCHING_NAME LIKE '%" + strPei + "%'";
        }
        if(!strChan.equals("")){
            sql += " AND PLINE_NAME LIKE '%" + strChan + "%'";
        }
        sql += "ORDER BY t.validflag desc,t.BATCHING_CODE";
        return this.getData(sql);
    }
    public CoreReturnObject queryNum(String str,String plinecode){
        String sql =  CoreXmlSqlParsersFactory.getSql("ComBaseBatching.queryNum");
        if(!str.equals("")){
            sql += " AND VALIDFLAG='1' AND BATCHING_NAME = '" + str + "'";
        }
        if(!plinecode.equals("")){
            sql += "  AND PLINE_NAME = '" + plinecode + "'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject queryNum1(String plinecode){
        String sql =  CoreXmlSqlParsersFactory.getSql("ComBaseBatching.queryNum1");
        if(!plinecode.equals("")){
            sql += "  AND PLINE_NAME = '" + plinecode + "'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject queryNum2(String str,String plinecode){
        String sql =  CoreXmlSqlParsersFactory.getSql("ComBaseBatching.queryNum2");
        if(!str.equals("")){
            sql += "  AND BATCHING_NAME <> '" + str + "'";
        }
        if(!plinecode.equals("")){
            sql += "  AND PLINE_NAME = '" + plinecode + "'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject querycodeNum(String str){
        String sql =  CoreXmlSqlParsersFactory.getSql("ComBaseBatching.querycodeNum");
        if(!str.equals("")){
            sql += " AND VALIDFLAG='1' AND BATCHING_NAME = '" + str + "'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject insert(String strJSON){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.insert");
        Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        GenericEntity pk = EntityTool.getEntityBySql(CoreXmlSqlParsersFactory.getSql(
                "ComBaseBatching.queryPk"), con, GenericEntity.class);
        batching.setBatchingCode(pk.getValue());
        sql = EntityTool.fillSqlByEntity(sql, batching);
        return this.setData(sql);
    }
    public CoreReturnObject insertnew(String strJSON){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.insert");
        sql = EntityTool.fillSqlByEntity(sql, batching);
        return this.setData(sql);
    }
    public CoreReturnObject update(String strJSON,String batchcode,String plinecode){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.update");
        sql = EntityTool.fillSqlByEntity(sql, batching);
        sql += "AND T.BATCHING_CODE =  '" + batchcode + "'";
        sql += "AND T.PLINE_CODE =  '" + plinecode + "'";
        return this.setData(sql);
    }
    public CoreReturnObject updatenew(String strJSON,String batchcode,String plinecode){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.update");
        Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        GenericEntity pk = EntityTool.getEntityBySql(CoreXmlSqlParsersFactory.getSql(
                "ComBaseBatching.queryPk"), con, GenericEntity.class);
        batching.setBatchingCode(pk.getValue());
        sql = EntityTool.fillSqlByEntity(sql, batching);
        sql += "AND T.BATCHING_CODE =  '" + batchcode + "'";
        sql += "AND T.PLINE_CODE =  '" + plinecode + "'";
        return this.setData(sql);
    }
    public CoreReturnObject delete(String strJSON){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.delete");
        sql = EntityTool.fillSqlByEntity(sql, batching); 
        return this.setData(sql);
    }
    public CoreReturnObject resume(String strJSON){
        CostBaseBatchingEntity batching = EntityTool.getEntityByJSONStr(strJSON, CostBaseBatchingEntity.class);
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.resume");
        sql = EntityTool.fillSqlByEntity(sql, batching); 
        return this.setData(sql);
    }
    public CoreReturnObject queryPline(){
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.queryPline");
        return this.getData(sql);
    }
    public CoreReturnObject queryPlineNew(){
        String sql = CoreXmlSqlParsersFactory.getSql("ComBaseBatching.queryPlineNew");
        return this.getData(sql);
    }
}
