package com.steering.pss.qcm;

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.pss.qcm.model.ComBasePhyRStdEntity;

/**
 * 检验项目和标准关系表
 * @author Administrator
 */
public class ComBasePhyRStdMng extends DBCommon {
    /**
     * 查询检验项目和标准关系
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject query(ArrayList<String> list) {
        return this.getDataBySqlID("ComBasePhyRStdMng.Query", list.toArray());
    }

    /**
     * 新增检验项目和标准关系
     * @param listPhyRStd 实体类对象
     * @return obj
     */
    public CoreReturnObject insert(ArrayList<String> listPhyRStd) {
        ArrayList<String> sqlList = new ArrayList<String>();
        for (String strPhyRStd : listPhyRStd) {
            JSONObject jsonObject = JSONObject.fromObject(strPhyRStd);
            ComBasePhyRStdEntity comBasePhyRStdEntity = (ComBasePhyRStdEntity) JSONObject
                    .toBean(jsonObject, ComBasePhyRStdEntity.class);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("ComBasePhyRStdMng.Insert");
            sql = sql.replaceAll(":STD_CODE_ALPHA",
                    comBasePhyRStdEntity.getStdCodeAlpha());
            sql = sql.replaceAll(":STD_NAME_ALPHA",
                    comBasePhyRStdEntity.getStdNameAlpha());
            sql = sql.replaceAll(":CREATE_NAME",
                    comBasePhyRStdEntity.getCreateName());
            sql = sql.replaceAll(":UPDATE_NAME",
                    comBasePhyRStdEntity.getUpdateName());
            sql = sql.replaceAll(":DELETE_NAME",
                    comBasePhyRStdEntity.getDeleteName());
            sql = sql
                    .replaceAll(":STD_CODE", comBasePhyRStdEntity.getStdCode());
            sql = sql
                    .replaceAll(":STD_NAME", comBasePhyRStdEntity.getStdName());
            sql = sql
                    .replaceAll(":PHY_CODE", comBasePhyRStdEntity.getPhyCode());
            sql = sql
                    .replaceAll(":PHY_TYPE", comBasePhyRStdEntity.getPhyType());
            sql = sql.replaceAll(":PHY_STD", comBasePhyRStdEntity.getPhyStd());
            sql = sql.replaceAll(":MEMO", comBasePhyRStdEntity.getMemo());
            sql=sql.replaceAll(":STD_FILE_PATH", comBasePhyRStdEntity.getStdFilePath());
            sqlList.add(sql);
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqlList);
    }

    /**
     * 修改检验项目和标准关系
     * @param listPhyRStd 实体类对象
     * @return obj
     */
    public CoreReturnObject update(ArrayList<String> listPhyRStd) {
        ArrayList<String> sqlList = new ArrayList<String>();
        for (String strPhyRStd : listPhyRStd) {
            JSONObject jsonObject = JSONObject.fromObject(strPhyRStd);
            ComBasePhyRStdEntity comBasePhyRStdEntity = (ComBasePhyRStdEntity) JSONObject
                    .toBean(jsonObject, ComBasePhyRStdEntity.class);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("ComBasePhyRStdMng.Update");
            sql = sql.replaceAll(":STD_CODE_ALPHA",
                    comBasePhyRStdEntity.getStdCodeAlpha());
            sql = sql.replaceAll(":STD_NAME_ALPHA",
                    comBasePhyRStdEntity.getStdNameAlpha());
            sql = sql.replaceAll(":UPDATE_NAME",
                    comBasePhyRStdEntity.getUpdateName());
            sql = sql.replaceAll(":PHY_STD_ID",
                    comBasePhyRStdEntity.getPhyStdId());
            sql = sql
                    .replaceAll(":STD_CODE", comBasePhyRStdEntity.getStdCode());
            sql = sql
                    .replaceAll(":STD_NAME", comBasePhyRStdEntity.getStdName());
            sql = sql
                    .replaceAll(":PHY_CODE", comBasePhyRStdEntity.getPhyCode());
            sql = sql
                    .replaceAll(":PHY_TYPE", comBasePhyRStdEntity.getPhyType());
            sql = sql.replaceAll(":PHY_STD", comBasePhyRStdEntity.getPhyStd());
            sql = sql.replaceAll(":MEMO", comBasePhyRStdEntity.getMemo());
            sql=sql.replaceAll(":STD_FILE_PATH", comBasePhyRStdEntity.getStdFilePath());
            sqlList.add(sql);
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqlList);
    }

    /**
     * 作废或者恢复
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject deleteOrResume(ArrayList<String> list) {
        return this.setDataBySqlID("ComBasePhyRStdMng.DeleteOrResume",
                list.toArray());
    }

    /**
     * 是否存在关系主键
     * @param strPhyRStd 实体类
     * @return obj
     */
    public CoreReturnObject isExistPhyStdId(String strPhyRStd) {
        JSONObject jsonObject = JSONObject.fromObject(strPhyRStd);
        ComBasePhyRStdEntity comBasePhyRStdEntity = (ComBasePhyRStdEntity) JSONObject
                .toBean(jsonObject, ComBasePhyRStdEntity.class);
        String sql = CoreXmlSqlParsersFactory
                .getSql("ComBasePhyRStdMng.isExistPhyStdId");
        sql = sql.replaceAll(":STD_CODE_ALPHA",
                comBasePhyRStdEntity.getStdCodeAlpha());
        sql = sql.replaceAll(":PHY_CODE", comBasePhyRStdEntity.getPhyCode());
        sql = sql.replaceAll(":STD_CODE", comBasePhyRStdEntity.getStdCode());
        sql = sql.replaceAll(":PHY_STD", comBasePhyRStdEntity.getPhyStd());
        return this.getData(sql);
    }

    public CoreReturnObject getStdAlpha(String stdCode) {
        Object[] obj = new Object[] { stdCode };
        return this.getDataBySqlID("ComBasePhyRStdMng.getStdAlpha", obj);
    }

}
