| | |
| | |
|
| | | using System.Data.OracleClient;
|
| | | using CCSTrace.CCS.Domain;
|
| | | using NLog;
|
| | |
|
| | | namespace CCSTrace.CCS.Function
|
| | | {
|
| | | public class Leach
|
| | | {
|
| | | private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
| | |
|
| | | private readonly MergeCase _mergeCase = new MergeCase();
|
| | | private readonly RecordLog _pLog;
|
| | | private readonly OracleConnection _connectionTpc;
|
| | | private readonly OracleTransaction _transaction;
|
| | | private readonly string _traceConnectionString;
|
| | |
|
| | | public Leach(OracleConnection conn, OracleTransaction trx, string traceConnection, RecordLog log)
|
| | | public Leach(OracleConnection conn, OracleTransaction trx, string traceConnection)
|
| | | {
|
| | | _connectionTpc = conn;
|
| | | _transaction = trx;
|
| | | _traceConnectionString = traceConnection;
|
| | | _pLog = log;
|
| | | }
|
| | |
|
| | | public int LeachCase(Object.EventRecord mNewRec)
|
| | |
| | | int importCase = -1;
|
| | | int tmpCaseId = 0;
|
| | | int caseType = -1;
|
| | | _pLog.Info("利用電號或地址檢查是否有已成立之案件.");
|
| | | Logger.Info("利用電號或地址檢查是否有已成立之案件.");
|
| | | // 檢查資料庫中此電號或地址是否已成立案件
|
| | |
|
| | | if (mNewRec.Meter.Trim().Length != 0)
|
| | |
| | | tmpCaseId = Convert.ToInt32(reader["CASEID"].ToString());
|
| | | caseType = Convert.ToInt32(reader["CASETYPE"].ToString());
|
| | | mNewRec.TmpCaseId = tmpCaseId;
|
| | | _pLog.Info("案件已成立:" + reader["ACCEPTNUM"].ToString() + " " + tmpCaseId + " " + caseType);
|
| | | Logger.Info("案件已成立:" + reader["ACCEPTNUM"].ToString() + " " + tmpCaseId + " " + caseType);
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | Logger.Error(e.Message);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | | finally
|
| | |
| | | break;
|
| | |
|
| | | default:
|
| | | _pLog.Error("無法辨別案件種類.");
|
| | | Logger.Error("無法辨別案件種類.");
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | | _pLog.Info("檢查該案件有無切開關紀錄.");
|
| | | Logger.Info("檢查該案件有無切開關紀錄.");
|
| | |
|
| | | try
|
| | | {
|
| | |
| | | // 有開關尚未恢復
|
| | | if (reader["CLOSETIME"] == null)
|
| | | {
|
| | | _pLog.Info("有切開關且尚未恢復.");
|
| | | Logger.Info("有切開關且尚未恢復.");
|
| | | if ((mNewRec.ImportCase== importCase) || (importCase == GlobalVariable.IsImportCase))
|
| | | {
|
| | | mResult = AddCount(tmpCaseId);
|
| | |
| | | else
|
| | | {
|
| | | // 開關都已恢復(同用戶須重新受理)
|
| | | _pLog.Info("有切開關且已經恢復.");
|
| | | Logger.Info("有切開關且已經恢復.");
|
| | | int caseId;
|
| | |
|
| | | // 找出案件編號需以母案件編號或該案件編號去找casestatus
|
| | |
| | | else
|
| | | {
|
| | | // 未切過開關
|
| | | _pLog.Info("無切開關紀錄.");
|
| | | Logger.Info("無切開關紀錄.");
|
| | | if ((mNewRec.ImportCase== importCase) || (importCase == GlobalVariable.IsImportCase))
|
| | | {
|
| | | mResult = AddCount(tmpCaseId);
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | Logger.Error(e, e.Message);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | | finally
|
| | |
| | |
|
| | | private int AddCount(int mCaseId)
|
| | | {
|
| | | string sqlStmt = "UPDATE EOS.EVENTS SET COUNT = COUNT + 1 WHERE CASEID = " + mCaseId;
|
| | | var sqlStmt = "UPDATE EOS.EVENTS SET COUNT = COUNT + 1 WHERE CASEID = " + mCaseId;
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
|
| | |
|
| | | try
|
| | | {
|
| | | if (command.ExecuteNonQuery() > 0)
|
| | | return GlobalVariable.SameCustomer;
|
| | | else
|
| | | return GlobalVariable.FailureByDb;
|
| | | return command.ExecuteNonQuery() > 0 ? GlobalVariable.SameCustomer : GlobalVariable.FailureByDb;
|
| | | }
|
| | | catch (Exception)
|
| | | catch (Exception e)
|
| | | {
|
| | | Logger.Warn(e, e.Message);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | | finally
|
| | |
| | |
|
| | | private int GetCastStatus(int caseId)
|
| | | {
|
| | | string sqlStmt;
|
| | | int status = 0;
|
| | |
|
| | | sqlStmt = "SELECT CASESTATUS FROM CCS.EVENTQUERY WHERE CCSID IN (SELECT CCSID FROM CCS.NUM_CONTRAST " + "WHERE CASEID = " + caseId + ")";
|
| | | var sqlStmt = "SELECT CASESTATUS FROM CCS.EVENTQUERY WHERE CCSID IN (SELECT CCSID FROM CCS.NUM_CONTRAST " + "WHERE CASEID = " + caseId + ")";
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
|
| | | OracleDataReader reader = null;
|
| | |
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | Console.WriteLine(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | Logger.Error(e, e.Message);
|
| | | }
|
| | | finally
|
| | | {
|
| | |
| | | {
|
| | | mNewRec.LocateEquipment.SetFsc(GlobalVariable.Breaker);
|
| | | mNewRec.LocateEquipment.SetUfid(mNewRec.Ufid);
|
| | | _pLog.Info("饋線全停:" + mNewRec.Fsc+ ", " + mNewRec.Ufid);
|
| | | _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString, _pLog);
|
| | | Logger.Info("饋線全停:" + mNewRec.Fsc+ ", " + mNewRec.Ufid);
|
| | | _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString);
|
| | | return GlobalVariable.Success;
|
| | | }
|
| | | }
|
| | | catch (EventAI.TraceLoopException)
|
| | | catch (EventAI.TraceLoopException e)
|
| | | {
|
| | | Logger.Warn(e, e.Message);
|
| | | return GlobalVariable.TraceCounts3;
|
| | | }
|
| | | catch (TraceException)
|
| | | catch (TraceException e)
|
| | | {
|
| | | Logger.Warn(e, e.Message);
|
| | | return GlobalVariable.TraceFailure;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | _pLog.Error(ex.Message);
|
| | | Logger.Error(ex, ex.Message);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | _pLog.Info("定位損壞設備!");
|
| | | Logger.Info("定位損壞設備!");
|
| | | int result = GetEquipment(mNewRec);
|
| | | _pLog.Info("FSC:" + mNewRec.Fsc+ ", Ufid:" + mNewRec.Ufid+ ", Tpclid:" + mNewRec.Tpclid+ ", FeederID:" + mNewRec.FdrId);
|
| | | Logger.Info("FSC:" + mNewRec.Fsc+ ", Ufid:" + mNewRec.Ufid+ ", Tpclid:" + mNewRec.Tpclid+ ", FeederID:" + mNewRec.FdrId);
|
| | |
|
| | | switch (result)
|
| | | { // get fsc,ufid,fdrid of sxfmr by meter
|
| | |
| | |
|
| | | if (mNewRec.Brief.Length != 0 && mNewRec.Brief.Substring(0, 1).Equals("A"))
|
| | | { // A類事故原因,做追蹤合併
|
| | | _pLog.Info("<A類案件>");
|
| | | _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString, _pLog);
|
| | | Logger.Info("<A類案件>");
|
| | | _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString);
|
| | | }
|
| | | else
|
| | | {
|
| | | _pLog.Info("<非A類案件>");
|
| | | Logger.Info("<非A類案件>");
|
| | | }
|
| | |
|
| | | if (changeCaseType)
|
| | |
| | | break;
|
| | | }
|
| | | }
|
| | | catch (EventAI.TraceLoopException)
|
| | | catch (EventAI.TraceLoopException e)
|
| | | {
|
| | | Logger.Warn(e, e.Message);
|
| | | return GlobalVariable.TraceCounts3;
|
| | | }
|
| | | catch (TraceException)
|
| | | catch (TraceException e)
|
| | | {
|
| | | Logger.Warn(e, e.Message);
|
| | | mResult = GlobalVariable.TraceFailure;
|
| | | }
|
| | | catch (Exception ex1)
|
| | | {
|
| | | _pLog.Error(ex1.Message);
|
| | | Logger.Error(ex1, ex1.Message);
|
| | | mResult = GlobalVariable.FailureByDb;
|
| | | }
|
| | | return mResult;
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error(e.Message);
|
| | | Logger.Error(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | |
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | _pLog.Error(ex.Message);
|
| | | Logger.Error(ex, ex.Message);
|
| | | }
|
| | | finally
|
| | | {
|
| | |
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | _pLog.Error(ex.Message);
|
| | | Logger.Error(ex, ex.Message);
|
| | | return GlobalVariable.FailureByDb;
|
| | | }
|
| | | finally
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | Logger.Error(e, e.Message);
|
| | | }
|
| | | finally
|
| | | {
|