package com.steering.pss.plnsaleord.planStove;


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.plnsaleord.planStove.entity.SlmOrderLinePrdcrLstEntity;

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

public class FrmProInformation  extends DBCommon{
    /***
     * 查询监制信息
     * @param proNo
     * @param indexNo
     * @param processCode
     * @return
     */
    public CoreReturnObject doQueryPro(String proNo,String indexNo,String processCode)
    {
        String sql = "";
        if(processCode.equals("A"))
        {
            return  this.getDataBySqlID("FrmProInformation.doQueryProLg",new Object[]{proNo});
        }else if(processCode.equals("H"))
        {
            return  this.getDataBySqlID("FrmProInformation.doQueryProH",new Object[]{proNo,processCode});
        }else
        {
            return  this.getDataBySqlID("FrmProInformation.doQueryPro",new Object[]{proNo,indexNo,processCode});
        }

    }

    /***
     * 通知监制
     * @return
     */
    public CoreReturnObject notice(ArrayList<String> parmList,String userName)
    {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            ArrayList<String> sqllist = new ArrayList<String>();
            for(String str : parmList)
            {
                SlmOrderLinePrdcrLstEntity slmOrderEntity = EntityTool.getEntityByJSONStr(str,SlmOrderLinePrdcrLstEntity.class);
                slmOrderEntity.setIsNotice("1");
                String updateSql = CoreXmlSqlParsersFactory.getSql("FrmProInformation.notice");
                updateSql = EntityTool.fillSqlByEntity(updateSql,slmOrderEntity);
                sqllist.add(updateSql);
            }
            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;
    }

    /***
     * 撤销通知监制
     * @return
     */
    public CoreReturnObject cancelNotice(ArrayList<String> parmList,String userName)
    {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            ArrayList<String> sqllist = new ArrayList<String>();
            for(String str : parmList)
            {
                SlmOrderLinePrdcrLstEntity slmOrderEntity = EntityTool.getEntityByJSONStr(str,SlmOrderLinePrdcrLstEntity.class);
                String updateSql = CoreXmlSqlParsersFactory.getSql("FrmProInformation.cancelNotice");
                updateSql = EntityTool.fillSqlByEntity(updateSql,slmOrderEntity);
                sqllist.add(updateSql);
            }
            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;
    }
}
