private void Commitjob_transaction(ILog log) { //initial parameters Parameter maxJob = session.Load <Parameter>("PAYROLL_SCH_JOB_READ_MASS_INQ"); Parameter maxTrx = session.Load <Parameter>("PAYROLL_SCH_GENERATE_MASS_INQ_MAX_TRX"); int maxResult = int.Parse(maxTrx.Data); IList <TrxPayroll> trxList = session.CreateSQLQuery("select * from trxpayrolls where status=? and (seqnumber%?)=? and lastupdate<=? order by id ASC") .AddEntity(typeof(TrxPayroll)) .SetInt32(0, ParameterHelper.PAYROLL_WAITING_CHECKACC) //11 : waiting mass inq output .SetInt32(1, int.Parse(maxJob.Data)) //id mod(10) .SetInt32(2, jobNumber) //id mod = ini mod 0, ambil trxID kelipatan 10 .SetDateTime(3, DateTime.Now) //.SetMaxResults(maxResult) .List <TrxPayroll>(); //we've found some data foreach (TrxPayroll trx in trxList) { string outStatus = ""; Boolean isReject = false; //Pengecekkan retry, jika dr created time sudah 1 jam maka Lastupdate di tambah setMenitBye menit int setMenitBye = int.Parse(ParameterHelper.GetString("PAYROLL_SET_MINUTES_TROUBLE_MASSACC", session)); //60 int paramRetryPosition = int.Parse(ParameterHelper.GetString("PAYROLL_PARAMETER__MAX_RETRY_MASSACC", session)); //10 if (trx.RetryPosition > paramRetryPosition) { trx.ErrorDescription += "|Transaksi terdeteksi sudah retry sebanyak > " + paramRetryPosition.ToString() + " kali, REJECT Transactions"; isReject = MassInquiryHelper.rejectPayroll(trx, session, log, trx.RetryPosition); if (isReject) { log.Error(SchCode + " === (TrxID " + trx.Id + ") Transaksi terdeteksi sudah retry sebanyak > " + paramRetryPosition.ToString() + " kali, REJECT Transactions"); } else { log.Error(SchCode + " === (TrxID " + trx.Id + ") Transaksi terdeteksi sudah retry sebanyak > " + paramRetryPosition.ToString() + " kali, GAGAL REJECT Transactions"); trx.LastUpdate = DateTime.Now; trx.Status = ParameterHelper.TRXSTATUS_REJECT;//4 trx.Description = "ERROR - Problem in Host BRI, please contact Administrator"; trx.ErrorDescription += "|Reject Trx : Failed to Delete Transactions or Delete detail Payroll, Set Reject Payroll only"; session.Update(trx); session.Flush(); } } else { if (MassInquiryHelper.downloadHostResponse(trx, session, out outStatus, log, jobNumber)) { /* * SUKSES file valid maka normal * ERROR file jawaban host mengirim message error generate file lagi akan generate 10 menit * RETRY file blm complete, blm ada footer add 2 minutes * UNKNOWN unknown isi file Host belum dikenal, generate lagi add 10 menit * INVALID cek footer gagal, retry reading 2 minutes */ #region download true Parameter retryAja = session.Load <Parameter>("PAYROLL_ADD_MINUTES_RETRY_MASSACC"); Parameter retryError = session.Load <Parameter>("PAYROLL_ADD_MINUTES_RETRY_MASSACC2"); int retryAjaInt = int.Parse(retryAja.Data); int retryErrorInt = int.Parse(retryError.Data); if (outStatus.Equals("SUKSES"))//jika sukses download { #region sukses log.Info("Success download file."); trx.ErrorDescription += schInfo + "Success download file"; if (MassInquiryHelper.parsingFile(trx, session, log, jobNumber, SchCode, out outStatus)) { #region cek sudahkah anak2 keupdate semua? string temp_query = ""; string msg = ""; bool lanjut = true; int count = 0; string dbResult = ""; bool result = true; if (result) { temp_query = @"select count(1) from trxpayrolldetails where pid = '" + trx.Id + "' and status = " + ParameterHelper.PAYROLLDETAILS_WAITING_CHECK + " and instructioncode = '" + TotalOBHelper.IFT + "';"; if (!PayrollHelper.ExecuteQueryValue(session, temp_query, out dbResult, out msg)) { log.Error(SchCode + " === (TrxID " + trx.Id + ") Failed Query: " + temp_query + " " + msg); result = false; } else { try { if (int.TryParse(dbResult, out count)) { if (count > 0) { lanjut = false; log.Info(SchCode + " === (TrxID " + trx.Id + ") Processing update Detail Transactions not completed, retry parsing again in 1 minutes"); } } } catch (Exception ex) { lanjut = false; log.Error("=== (TrxID " + trx.Id + ") Msg : " + ex.Message + "Stack :" + ex.StackTrace + "Stack :" + ex.InnerException); } } } #endregion if (!lanjut && result) { log.Error(SchCode + " === (TrxID " + trx.Id + ") Ada " + count.ToString() + " anak yang beum keupdate, ulangi transaksi " + retryAja.Data.ToString() + " menit kemudian!"); trx.LastUpdate = DateTime.Now.AddMinutes(retryAjaInt); session.Update(trx); session.Flush(); return; } else if (result && lanjut) { trx.Status = ParameterHelper.PAYROLL_SUCCESS_PARSING; //46 trx.LastUpdate = DateTime.Now; log.Info(SchCode + " === (TrxID " + trx.Id + ") Finish Processing"); } log.Info("Success Parsing File."); } else { if (outStatus.Equals("[NULL]")) { //trx.Status = ParameterHelper.PAYROLL_WAITING_GENERATE_MASS_INQ;//10 trx.LastUpdate = DateTime.Now.AddMinutes(retryAjaInt); trx.ErrorDescription += "|file balikan host 0 KB / Not Completed-Pending 2 minutes : " + trx.LastUpdate + "|"; trx.RetryPosition += 1; } else { log.Error("Failed in Parsing File-try again to parsing at: " + trx.LastUpdate); trx.LastUpdate = DateTime.Now.AddMinutes(retryAjaInt); trx.ErrorDescription += schInfo + "Failed in Parsing File-Pending 2 minutes : " + trx.LastUpdate; trx.RetryPosition += 1; } } #endregion sukses } else if (outStatus.Equals("ERROR")) // File mendapat message error dr host dan generate lagi { trx.LastUpdate = DateTime.Now.AddMinutes(retryErrorInt); trx.Status = ParameterHelper.PAYROLL_WAITING_GENERATE_MASS_INQ;//10 trx.ErrorDescription += schInfo + " Message from Host error, generate again (" + retryErrorInt.ToString() + " minutes) at " + trx.LastUpdate; log.Error("ID : " + trx.SeqNumber + " Message from Host error, generate again (" + retryErrorInt.ToString() + " minutes) at " + trx.LastUpdate); trx.RetryPosition += 1; } else if (outStatus.Equals("RETRY")) // Not Completed { trx.LastUpdate = DateTime.Now.AddMinutes(retryAjaInt); trx.ErrorDescription += schInfo + "Mass Inq file is not Completed, try again (" + retryAjaInt.ToString() + " minutes) to read file at " + trx.LastUpdate; log.Error("ID : " + trx.SeqNumber + " Mass Inq file is not Completed, try again (" + retryAjaInt.ToString() + " minutes) to read file at " + trx.LastUpdate); trx.RetryPosition += 1; } else if (outStatus.Equals("UNKNOWN")) // UNKNOWN { trx.LastUpdate = DateTime.Now.AddMinutes(retryErrorInt); trx.Status = ParameterHelper.PAYROLL_WAITING_GENERATE_MASS_INQ;//10 trx.ErrorDescription += schInfo + "Message from host is unknown, generate again (" + retryErrorInt.ToString() + " minutes) at " + trx.LastUpdate; log.Error("ID : " + trx.SeqNumber + " Message from host is unknown, generate again (" + retryErrorInt.ToString() + " minutes) at " + trx.LastUpdate); trx.RetryPosition += 1; } else if (outStatus.Equals("INVALID")) // Cek footer gagal retry aja { trx.LastUpdate = DateTime.Now.AddMinutes(retryAjaInt); trx.ErrorDescription += schInfo + "Failed checking Footer, try again (" + retryAjaInt.ToString() + " minutes) to read file at " + trx.LastUpdate; log.Error("ID : " + trx.SeqNumber + " Failed checking Footer, try again (" + retryAjaInt.ToString() + " minutes) to read file at " + trx.LastUpdate); trx.RetryPosition += 1; } else { /* * JIka sejam retry sampai BOSOKS maksinal 1 jam maka akan reject transakski, eaea dan * Jika lebih dr 3 menit akan generate Mass Acc Inq, set 10 */ //if (!MassInquiryHelper.retryMassInq(trx, session, log)) //{ // log.Error("Something Wrong In Retry Mass Inq"); // trx.LastUpdate = DateTime.Now.AddMinutes(2); // trx.ErrorDescription += schInfo + "Something Wrong In Retry Mass Inq, try again at " + trx.LastUpdate; //} #endregion } } else { log.Error("Something Wrong In Download File :("); trx.LastUpdate = DateTime.Now.AddMinutes(2); trx.ErrorDescription += schInfo + "Something Wrong In Download File" + trx.LastUpdate; trx.RetryPosition += 1; } } session.Update(trx); session.Flush(); } }
private void Commitjob_transaction(ILog log) { //initial parameters Parameter maxJob = session.Load<Parameter>("PAYROLL_SCH_JOB_GENERATE_MASS_INQ"); Parameter maxTrx = session.Load<Parameter>("PAYROLL_SCH_GENERATE_MASS_INQ_MAX_TRX"); int maxResult = int.Parse(maxTrx.Data); /*Inisiasi*/ string temp_query = ""; string msg = ""; string outFileName = ""; IList<TrxPayroll> trxList = session.CreateSQLQuery("select * from trxpayrolls where status=? and (seqnumber%?)=? and lastupdate<=? order by id ASC") .AddEntity(typeof(TrxPayroll)) .SetInt32(0, ParameterHelper.PAYROLL_WAITING_GENERATE_MASS_INQ)//10 .SetInt32(1, int.Parse(maxJob.Data))//id mod(10) .SetInt32(2, jobNumber)//id mod = ini mod 0, ambil trxID kelipatan 10 .SetDateTime(3, DateTime.Now)//kurang dari last update .SetMaxResults(maxResult) .List<TrxPayroll>(); //we've found some data foreach(TrxPayroll trx in trxList) { #region patching instructioncode null //20170530 - sayedzul add handler instructioncode null dan account payrollBRI ga 15 digit int jumlahInstCodeNull = trx.TrxPayrollDetail.Where(x => String.IsNullOrEmpty(x.InstructionCode)).Count(); if (jumlahInstCodeNull > 0) { string theQuery = @"update trxpayrolldetails set instructioncode = '" + TotalOBHelper.IFT + "' where pid = '" + trx.Id + "' and (instructioncode is null or instructioncode = '');"; string msg1 = ""; PayrollHelper.ExecuteQuery(session, theQuery, out msg1); break; } int jumlahBenAccGa15Digit = trx.TrxPayrollDetail.Where(x => x.InstructionCode.Equals(TotalOBHelper.IFT) && x.Account.Length < 15).Count(); if (jumlahBenAccGa15Digit > 0) { string theQuery2 = @"update trxpayrolldetails set account = lpad(account, 15, '0') where pid = '" + trx.Id + "' and instructioncode = '" + TotalOBHelper.IFT + "' and length(account) < 15;"; string msg2 = ""; PayrollHelper.ExecuteQuery(session, theQuery2, out msg2); break; } #endregion int jumlahTrxIFT = trx.TrxPayrollDetail.Where(x => x.Status != ParameterHelper.TRXSTATUS_REJECT && x.InstructionCode.Equals(TotalOBHelper.IFT)).Count(); if (jumlahTrxIFT > 0) { if (MassInquiryHelper.generate(trx, session, log, SchCode, out outFileName)) { log.Info("Success Generate File, update to next process."); trx.ErrorDescription += schInfo + "Success Generate File"; if (MassInquiryHelper.sendToHost(trx, session, log, outFileName)) { log.Info("Success Generate File, update to next process."); //Skenario : jika file banyak agar respons host blm selesai, ada jeda int tambahMenit = 0; if (jumlahTrxIFT < 10000) { tambahMenit = 1; } else if ((jumlahTrxIFT < 50000) && (jumlahTrxIFT > 10000)) { tambahMenit = 2; } else { tambahMenit = int.Parse(Math.Floor((Decimal)(jumlahTrxIFT / 25000)).ToString()); } /*Native update*/ temp_query = @"update trxpayrolls p set p.status = 11, p.filemassinq = '" + outFileName + "', p.lastupdate = '" + DateTime.Now.AddMinutes(tambahMenit).ToString("yyyy-MM-dd HH:mm:ss") + "' where p.id = '" + trx.Id + "';"; if (!PayrollHelper.ExecuteQuery(session, temp_query, out msg)) { log.Error("Failed Execute query. " + msg.ToString()); } else log.Info("Trx Id = " + trx.Id + ", mempunyai transaksi IFT: " + jumlahTrxIFT + "||Akan set Lastupdate ::" + tambahMenit + "Minutes"); } else { /*Native update*/ temp_query = @"update trxpayrolls p set p.lastupdate = " + DateTime.Now.AddMinutes(2).ToString() + " where p.id = '" + trx.Id + "';"; if (!PayrollHelper.ExecuteQuery(session, temp_query, out msg)) { log.Error("Failed Execute query. " + msg.ToString()); } else log.Error("Something Wrong in send :( and try agagain in 2 minutes"); } } else { /*Native update*/ temp_query = @"update trxpayrolls p set p.lastupdate = " + DateTime.Now.AddMinutes(2).ToString() + " where p.id = '" + trx.Id + "';"; if (!PayrollHelper.ExecuteQuery(session, temp_query, out msg)) { log.Error("Failed Execute query. " + msg.ToString()); } else log.Error("Something Wrong in generate :( and try agagain in 2 minutes"); } } else { trx.Status = ParameterHelper.TRXSTATUS_INQUIRYNAMEPROCESS_FINISH;//17 trx.ErrorDescription = ""; //update transactions Transaction trans = session.CreateCriteria(typeof(Transaction)) .Add(Expression.In("TransactionId", new int[] { 101, 102, 103 })) .Add(Expression.Like("TObject", trx.Id, MatchMode.Anywhere)) .UniqueResult<Transaction>(); if (trans != null)//avoid Payroll Musimas { trans.Status = ParameterHelper.TRXSTATUS_WAITING_SCHEDULLER;//15 //string feeIFT = PayrollHelper.getFeeTransaction(session, trx.Id, TotalOBHelper.IFT, log); //string feeRTG = PayrollHelper.getFeeTransaction(session, trx.Id, TotalOBHelper.RTGS, log); //string feeLLG = PayrollHelper.getFeeTransaction(session, trx.Id, TotalOBHelper.LLG, log); //string reject = PayrollHelper.getCountRejectTransaction(session, trx.Id, TotalOBHelper.IFT, log); ///*Nilai Total*/ //string totalTrx = PayrollHelper.getTotalTransaction(session, trx.Id, log); /*Ini nih kunci utnuk laporan query dll nyaaa*/ trx.TotalTrx = "|0:0|0:0|0:0|0:0|0:0|";// "|" + feeIFT + "|" + reject + "|" + totalTrx + "|" + feeRTG + "|" + feeLLG + "|"; //trx.TotalTrx = "|" + _countSuccess + ":" + _sumSuccess + "|" + _countInvalid + ":" + _sumInvalid + "|" + _countTotal + ":" + _sumTotal + "|"; log.Info("Trx Id = " + trx.Id + ", Total Trx : " + trx.TotalTrx); session.Update(trans); session.Flush(); log.Info("Trx Id = " + trx.Id + " Update transactions success"); session.Update(trx); session.Flush(); } } } }