package com.steering.pss.ydm.pipemanage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

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.ydm.entity.QcmZbsInfoEntity;

public class FrmUpdateMemo extends DBCommon{
	/***
	 * 查询质保书数据
	 * @return
	 */
	public CoreReturnObject doQueryZbs(ArrayList<String> list,String startTim,String endTim)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmUpdateMemo.doQueryZbs");
		if(!list.get(0).equals(""))
		{
			sql += " AND T.ORDER_NO LIKE '%"+list.get(0)+"%'";
		}
		if(!startTim.equals(""))
		{
			sql += " AND T.CREATE_TIME >= TO_DATE('"+startTim+"','YYYY-MM-DD HH24:MI:SS') AND T.CREATE_TIME <= TO_DATE('"+endTim+"','YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += " GROUP BY T.ORDER_NO,T.ORDER_SEQ,T.ORD_LN_PK,T.ORD_LN_DLY_PK";
		return this.getData(sql);
	}
	/***
	 * 修改质保书备注
	 * @return
	 */
	public CoreReturnObject updateMemo(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				QcmZbsInfoEntity qcmZbsEntity = EntityTool.getEntityByJSONStr(str, QcmZbsInfoEntity.class);
				String updateMemoSql = CoreXmlSqlParsersFactory.getSql("FrmUpdateMemo.updateMemo");
				updateMemoSql = EntityTool.fillSqlByEntity(updateMemoSql, qcmZbsEntity);
				sqllist.add(updateMemoSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

}
