package com.steering.pss.plnsaleord.processOrder;

import java.util.ArrayList;
import java.util.List;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.base.PlnHelper;
import com.steering.pss.plnsaleord.processOrder.entity.ComBaseMandrelSpecEntity;

/**
 * 芯棒产线适用规格
 * 
 * @author peng
 * 
 */
public class FrmBaseMandrelSpec extends DBCommon {
	/**
	 * 初始化芯棒直径
	 * 
	 * @return
	 */
	public CoreReturnObject initDimater() {
		return this.getDataBySqlID("FrmBaseMandrelSpec.initDimater");
	}
	
	/**
	 * 查询
	 * 
	 * @param modelDesc
	 * @return
	 */
	public CoreReturnObject query(String plineCode) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("FrmBaseMandrelSpec.query");
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " and t.PLINE_CODE=? ";
		}
		sql += " order by to_number(t.RELATION_ID) ";
		return this.getData(sql, params.toArray());
	}
	/**
     * 查询
     * 
     * @param modelDesc
     * @return
     */
    public CoreReturnObject query1(String mandrelId) {
        List<String> params = new ArrayList<String>();
        String sql = CoreXmlSqlParsersFactory.getSql("FrmBaseMandrelSpec.query1");
//        if (!mandrelId.equals("")) {
            params.add(mandrelId);
            sql += " and t.MANDREL_ID=? ";
//        }
        sql += " order by to_number(t.DIAMETER_MANDREL) ";
        return this.getData(sql, params.toArray());
    }
	/**
	 * 新增
	 * 
	 * @param jsonStr
	 * @return
	 */
	public CoreReturnObject add(String jsonStr) {
		ComBaseMandrelSpecEntity entity = PlnHelper.jsonToEntity(
				ComBaseMandrelSpecEntity.class, jsonStr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmBaseMandrelSpec.add");
		sql = EntityTool.fillSqlByEntity(sql, entity);
		return this.setData(sql);
	}

	/**
	 * 修改
	 * 
	 * @param jsonStr
	 * @return
	 */
	public CoreReturnObject update(String jsonStr) {
		ComBaseMandrelSpecEntity entity = PlnHelper.jsonToEntity(
				ComBaseMandrelSpecEntity.class, jsonStr);
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmBaseMandrelSpec.update");
		sql = EntityTool.fillSqlByEntity(sql, entity);
		return this.setData(sql);
	}

	/**
	 * 删除
	 * 
	 * @param jsonStr
	 * @return
	 */
	public CoreReturnObject delete(String jsonStr) {
		ComBaseMandrelSpecEntity entity = PlnHelper.jsonToEntity(
				ComBaseMandrelSpecEntity.class, jsonStr);
		Object[] params = new Object[] { entity.getRelationId() };
		return this.setDataBySqlID("FrmBaseMandrelSpec.delete", params);
	}

}
