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.ComBaseMandrelEntity;

/**
 * 芯棒基础
 * @author peng
 */
public class FrmComBaseMandrel extends DBCommon {
    /**
     * 初始化扣型
     * @return
     */
    public CoreReturnObject initModel() {
        return this.getDataBySqlID("FrmComBaseMandrel.initModel");
    }

    /**
     * 查询
     * @param modelDesc
     * @return
     */
    public CoreReturnObject query(String modelDesc) {
        List<String> params = new ArrayList<String>();
        String sql = CoreXmlSqlParsersFactory.getSql("FrmComBaseMandrel.query");
        if (!modelDesc.equals("")) {
            params.add(modelDesc);
            sql += " and t.SCREW_MODEL=? ";
        }
        sql += " order by to_number(t.DIAMETER_MANDREL) ";
        return this.getData(sql, params.toArray());
    }

    /**
     * 新增
     * @param jsonStr
     * @return
     */
    public CoreReturnObject add(String jsonStr) {
        ComBaseMandrelEntity entity = PlnHelper.jsonToEntity(
                ComBaseMandrelEntity.class, jsonStr);
        String sql = CoreXmlSqlParsersFactory.getSql("FrmComBaseMandrel.add");
        sql = EntityTool.fillSqlByEntity(sql, entity);
        return this.setData(sql);
    }

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

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

    /**
     * 验证芯棒是否重复
     * @param mandrel
     * @return
     */
    public CoreReturnObject checkMandrel(String mandrel) {
        Object[] params = new Object[] { mandrel };
        return this.getDataBySqlID("FrmComBaseMandrel.checkMandrel", params);
    }

    /**
     * 验证芯棒直径，长度，锥度，芯棒扣型，实心空心是否重复
     * @param mandrel
     * @return
     */
    public CoreReturnObject checkMandrel1(ArrayList<String> params) {

        return this.getDataBySqlID("FrmComBaseMandrel.checkMandrel1", params
                .toArray());
    }
}
