/// <summary> /// Обработчик события кода на погрузку /// </summary> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кода</param> /// <returns>Результат обработки</returns> public TCheckResult ShippingMng(TL4MsgInfo l4MsgInfo) { TCheckResult result = new TCheckResult(); TForShipping forShipping = TForShipping.NOShipped; L4L3InterfaceServiceGlobalCheck global = new L4L3InterfaceServiceGlobalCheck(); logger.Error($"ShippingMng - STARTED -> MsgId: {l4MsgInfo.msgCounter}"); L4L3ShippingRepo shippingRepo = new L4L3ShippingRepo(); List <L4L3Shipping> ship = shippingRepo.GetListData(l4MsgInfo); if (ship == null) { result.isOK = false; result.data = $"В таблице {l4l3unterfacetable} поле {l4MsgInfo.msgCounter} запись не найдена"; global.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); return(result); } L4L3ServiceCheckShipping checkship = new L4L3ServiceCheckShipping(); result = checkship.ShippingCheck(ship, l4MsgInfo); foreach (L4L3Shipping sship in ship) { if (result.isOK) { if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_NEW && sship.bolStatus == L4L3InterfaceServiceConst.BOL_NOT_SENT) { CreateBolIfNotEx(sship.bolId); forShipping = TForShipping.NOShipped; } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_UPD && sship.bolStatus == L4L3InterfaceServiceConst.BOL_NOT_SENT) { forShipping = TForShipping.NOShipped; } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_UPD && sship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { forShipping = TForShipping.YESShipped; } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_NEW && sship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { forShipping = TForShipping.YESShipped; } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_DEL && sship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { forShipping = TForShipping.YESShipped; } result = LocalSetPiece(l4MsgInfo, sship, TPieceAction.paAssign, forShipping); } } if (!result.isOK) { global.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); logger.Error(result.data); } else { global.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS, result.data); } logger.Error($"ShippingMng - STOPPED -> MsgId:{l4MsgInfo.msgCounter}"); return(result); }
/// <summary> /// Сообщение обработано успешно /// </summary> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кодов</param> /// <param name="result">Результат обработки</param> /// <returns>Результат обработки</returns> public TCheckResult MngSuccesed(TL4MsgInfo l4MsgInfo, TCheckResult result) { SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS, ""); result.isOK = true; result.data = l4MsgInfo.msgReport.remark; return(result); }
/// <summary> /// Получение аттрибутов из L4_L3_SO_LINE /// </summary> /// <param name="qryData">Модель таблицы L4L3SoHeader</param> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кода</param> /// <returns>Результат обработки</returns> public TCheckResult AttributeCheck(L4L3SoHeader qryData, TL4MsgInfo l4MsgInfo) { TCheckResult result = new TCheckResult(); result.isOK = false; L4L3SoLine l4L3SoLine; string sqlstr = $"SELECT * FROM L4_L3_SO_LINE WHERE MSG_COUNTER = {qryData.msgCounter}"; using (OracleConnection connection = GetConnection()) { l4L3SoLine = connection.QueryFirstOrDefault <L4L3SoLine>(sqlstr, null); } if (l4L3SoLine == null) { result.isOK = false; result.data = "Заказ не имеет записей в таблице L4_L3_SO_LINE"; l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = result.data; } else { result.isOK = true; } if (!result.isOK) { check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } else { check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS, result.data); } return(result); }
/// <summary> /// Инициализация результата работы с ошибкой /// </summary> /// <returns>Результат работы</returns> public TCheckResult InitResultWithFalse() { TCheckResult result = new TCheckResult(); result.isOK = false; result.rejType = L4L3InterfaceServiceConst.REJECT_GENERAL; result.data = ""; return(result); }
/// <summary> /// Получение детали (Требуется доработка) /// </summary> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кода</param> /// <param name="ship">Модель таблицы L4L3Shipping</param> /// <param name="action">Тип перечисления действий</param> /// <param name="forShipping">Тип перечисления отгрузки</param> /// <returns>Результат обработки</returns> public TCheckResult LocalSetPiece(TL4MsgInfo l4MsgInfo, L4L3Shipping ship, TPieceAction action, TForShipping forShipping) { TCheckResult checkResult = new TCheckResult(); OracleDynamicParameters odp = new OracleDynamicParameters(); List <int> pieceNum = new List <int>(); checkResult.isOK = false; string str = "SELECT PIECE_NUM_ID FROM PIECE WHERE PIECE_ID = :PIECE_ID AND STATUS= :STATUS AND PRODUCTION_MACHINE_CODE = 'HSM' "; if (forShipping == TForShipping.NOShipped) { str += "AND READY_TO_SHIP = :READY_TO_SHIP "; odp.Add("PIECE_ID", ship.pieceId); //odp.Add("STATUS",);// Узнать код PIECE_STATUS_EXIST //odp.Add("READY_TO_SHIP",)//Узнать код PIECE_READY_TO_SHIP } else if (action == TPieceAction.paAssign && forShipping == TForShipping.YESShipped) { str += "AND READY_TO_SHIP= :READY_TO_SHIP"; odp.Add("PIECE_ID", ship.pieceId); //odp.Add("STATUS",);// Узнать код PIECE_STATUS_EXIST //odp.Add("READY_TO_SHIP",)//Узнать код PIECE_READY_TO_SHIP } else if (action == TPieceAction.paDeAssign && forShipping == TForShipping.YESShipped) { str += "AND PIECE_EXIT_TYPE= :PIECE_EXIT_TYPE"; odp.Add("PIECE_ID", ship.pieceId); //odp.Add("STATUS",);// Узнать код PIECE_STATUS_EXIST //odp.Add("PIECE_EXIT_TYPE",)//Узнать код PIECE_EXIT_TYPE } using (OracleConnection connection = BaseRepo.GetDBConnection()) { pieceNum = connection.Query <int>(str, odp).AsList(); } if (forShipping == TForShipping.NOShipped) { foreach (int piece in pieceNum) { //SetPieceAssignExternalBOL(QryTemp.FieldByName('PIECE_NUM_ID').AsInteger, Action, Qry.FieldByName('BOL_ID').AsString); } } else if (forShipping == TForShipping.YESShipped) { foreach (int piece in pieceNum) { //SetPieceShippedFromExternal(QryTemp.FieldByName('PIECE_NUM_ID').AsInteger, Action, Qry.FieldByName('BOL_ID').AsString); } } checkResult.isOK = true; checkResult.data = $"В таблице {l4l3unterfacetable} поле MSG_COUNTER:{l4MsgInfo.msgCounter} Ошибок нет."; return(checkResult); }
/// <summary> /// Обработчик кода перемещения материала /// </summary> /// <param name="l4MsgInfo">Модель L4L3Event для обработки кода</param> /// <returns>Результат обработки</returns> public TCheckResult L4L3MaterialMovement(TL4MsgInfo l4MsgInfo) { L4L3InterfaceServiceGlobalCheck global = new L4L3InterfaceServiceGlobalCheck(); TCheckResult checkResult = global.InitResultWithFalse(); List <L4L3RmAndMatCat> l4L3Rms = new List <L4L3RmAndMatCat>(); OracleDynamicParameters odp = new OracleDynamicParameters(); string str = "select l4.material_id as sap_code, " + "M.MATERIAL_CODE," + "m.material_name," + "m.actual_qty l3_qty," + "l4.material_amount*1000 as material_amount," + "case" + "when (m.actual_qty < l4.material_amount*1000) then" + "(-1)*(m.actual_qty - l4.material_amount*1000)" + "else" + "(m.actual_qty - l4.material_amount*10000)" + "end as movement_qty" + "l4.movement_datetime" + "from L4_L3_RAW_MATERIAL l4," + "mat_catalog m " + "where trim(L4.MATERIAL_ID) = trim(M.MATERIAL_CODE_L4) " + "and l4.msg_counter = :Counter"; odp.Add("Counter", l4MsgInfo.msgCounter); using (OracleConnection connection = GetConnection()) { l4L3Rms = connection.Query <L4L3RmAndMatCat>(str, odp).AsList(); } if (l4L3Rms.Count == 0) { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = "Код материала не найдена в БД МЕТ2000"; } else { foreach (L4L3RmAndMatCat l4L3Rm in l4L3Rms) { if (InsertNewMovement(l4L3Rm.materialCode, "MT_RECONCILIATION", l4L3Rm.movementdatetime, l4L3Rm.movmetnqty, 1123, 0, "Корректировка остатков от SAP")) { check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS, "Материал перемещен"); } else { check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, "Ошибка добавления материала"); } } } return(checkResult); }
/// <summary> /// Основная проверка отгрузки /// </summary> /// <param name="ship">Модель таблицы L4_L3_SHIPPING для обработки</param> /// <param name="l4MsgInfo">Модель таблицы L4L3Event</param> /// <returns>Результат работы</returns> public TCheckResult ShippingGeneralCheck(List <L4L3Shipping> ship, TL4MsgInfo l4MsgInfo) { TCheckResult result = check.InitResultWithFalse(); result.isOK = true; bool firstloop = true; string bol_idUsedToCheck = "", strPieceId = "", strError = ""; int bol_status = -1, bol_statusUserToCheck = -1; if (ship == null) { check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, $"Запись не найдена Msg_counter={l4MsgInfo.msgCounter}"); return(result); } foreach (L4L3Shipping shp in ship) { if (firstloop) { bol_statusUserToCheck = shp.bolStatus; bol_idUsedToCheck = shp.bolId; } else { if (bol_idUsedToCheck != shp.bolId) { strError = $"Таблица L4_L3_SHIPPING MSG_COUNTER: {l4MsgInfo.msgCounter} значение Накладной должно совпадать для каждой записи"; result.isOK = false; result.data = strError; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, strError); break; } } bol_status = shp.bolStatus; if (bol_statusUserToCheck != bol_status) { strError = $"Таблица L4_L3_SHIPPING MSG_COUNTER: {l4MsgInfo.msgCounter} значение поля BOL_STATUS должно быть одинаковым для каждой записи"; result.isOK = false; result.data = strError; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, strError); break; } if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_NEW) { if (!(bol_status == L4L3InterfaceServiceConst.BOL_NOT_SENT || bol_status == L4L3InterfaceServiceConst.BOL_SENT)) { strPieceId = shp.pieceId; strError = $"Таблица L4_L3_SHIPPING MSG_COUNTER: {l4MsgInfo.msgCounter} значение PIECE_ID: {shp.pieceId} для BOL_STATUS = {bol_status} неверно"; result.isOK = false; result.data = strError; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, strError); break; } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_DEL) { if (bol_status != L4L3InterfaceServiceConst.BOL_SENT) { strPieceId = shp.pieceId; strError = $"Таблица L4_L3_SHIPPING MSG_COUNTER: {l4MsgInfo.msgCounter} значение PIECE_ID: {shp.pieceId} для BOL_STATUS = {bol_status} неверно"; result.isOK = false; result.data = strError; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, strError); break; } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_UPD) { if (!(bol_status == L4L3InterfaceServiceConst.BOL_NOT_SENT || bol_status == L4L3InterfaceServiceConst.BOL_SENT)) { strPieceId = shp.pieceId; strError = $"Таблица L4_L3_SHIPPING MSG_COUNTER: {l4MsgInfo.msgCounter} значение PIECE_ID: {shp.pieceId} для BOL_STATUS = {bol_status} неверно"; result.isOK = false; result.data = strError; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, strError); break; } } firstloop = false; } return(result); }
/// <summary> /// Проверка отгрузки /// </summary> /// <param name="ship">Набор строк таблицы L4_L3_SHIPPING для обработки</param> /// <param name="l4MsgInfo">Модель таблицы L4L3Event</param> /// <returns>Результат работы</returns> public TCheckResult ShippingCheck(List <L4L3Shipping> ship, TL4MsgInfo l4MsgInfo) { TCheckResult result = ShippingGeneralCheck(ship, l4MsgInfo); if (!result.isOK) { return(result); } foreach (L4L3Shipping sinship in ship) { if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_NEW && sinship.bolStatus == L4L3InterfaceServiceConst.BOL_NOT_SENT) { if (!L4L3ShipPieceSOCheck(sinship)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} одна из заготовок не может быть назначена в накладную BOL: {sinship.bolId}"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_UPD && sinship.bolStatus == L4L3InterfaceServiceConst.BOL_NOT_SENT) { if (!CheckBolExistNotShip(sinship.bolId)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} Накладная: {sinship.bolId} не существует или отгружена"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } if (!ShippingIsPieceAssignedToBOL(sinship, TForShipping.NOShipped)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} как минимум одна из заготовок не может быть назначена в накладную BOL: {sinship.bolId}"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_UPD && sinship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { if (!CheckBolExistIsShip(sinship.bolId)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} Накладная: {sinship.bolId} не существует или отгружена"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } if (!ShippingIsPieceAssignedToBOL(sinship, TForShipping.YESShipped)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} как минимум одна из заготовок не может быть назначена в накладную BOL: {sinship.bolId}"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_NEW && sinship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { if (!CheckBolExistIsShip(sinship.bolId)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} Накладная: {sinship.bolId} не существует или отгружена"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } if (!L4L3ShipPieceSOCheck(sinship)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} как минимум одна из заготовок не может быть назначена в накладную BOL: {sinship.bolId}"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } } else if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_DEL && sinship.bolStatus == L4L3InterfaceServiceConst.BOL_SENT) { if (!CheckBolExistNotShip(sinship.bolId)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} Накладная: {sinship.bolId} не существует или отгружена"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } if (L4L3ShipPieceSOCheck(sinship)) { result.isOK = false; result.data = $"Таблица L4_L3_SHIPPING MSG_COUNTER {l4MsgInfo.msgCounter} как минимум одна из заготовок не может быть назначена в накладную BOL: {sinship.bolId}"; check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, result.data); } } } return(result); }
/// <summary> /// Обработчик заказа /// </summary> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кода</param> /// <returns>Результат обработки</returns> public TCheckResult SalesOrderMng(TL4MsgInfo l4MsgInfo) { TCheckResult checkResult = new TCheckResult(); checkResult.isOK = false; tSo = new TSoHeaderRepo(); L4L3SoHeaderRepo header = new L4L3SoHeaderRepo(); L4L3SoHeader soHeader = header.GetData(l4MsgInfo); BlockForProcess(l4MsgInfo, true); string charval; string sqlstr = "SELECT CHAR_VALUE FROM AUX_CONSTANT WHERE CONSTANT_ID='ONE_TO_SEVERAL_ORDER_FROM_SAP'"; using (OracleConnection connection = BaseRepo.GetDBConnection()) { charval = connection.QueryFirstOrDefault <string>(sqlstr, null); } if (charval != null) { onetoSeveralirderFromSap = charval; } else { onetoSeveralirderFromSap = "N"; } if (onetoSeveralirderFromSap == "Y") { List <l4sol> l4s = new List <l4sol>(); sqlstr = "SELECT L4SOL.SO_LINE_ID, L4SOL.SO_LINE_ID/10 as MET_SO_LINE_ID " + "FROM L4_L3_SO_LINE L4SOL WHERE L4SOL.MSG_COUNTER = :MSG_COUNTER"; if (m_strSo_Lines_For_Where != "") { sqlstr += $"AND L4SOL.SO_LINE_ID IN {m_strSo_Lines_For_Where}"; } sqlstr += "ORDER BY L4SOL.SO_LINE_ID"; OracleDynamicParameters odp = new OracleDynamicParameters(); odp.Add("MSG_COUNTER", l4MsgInfo.msgCounter); using (OracleConnection connection = BaseRepo.GetDBConnection()) { l4s = connection.Query <l4sol>(sqlstr, null).AsList(); } if (l4s != null) { foreach (l4sol kSol in l4s) { if (!OrderCanBeProcess(soHeader.soID, l4MsgInfo.opCode, "")) { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = ""; } else if (!OrderCanBeProcess($"{soHeader.soID}_{kSol.metSoLineId}", l4MsgInfo.opCode, "")) { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = ""; } else { m_strSO_Line_Id_Params = kSol.soLineId; m_strSO_Line_Id_MET = kSol.metSoLineId; tSo.m_strSO_Line_Id_MET = kSol.metSoLineId; tSo.m_strSO_Line_Id_Params = kSol.soLineId; l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS; l4MsgInfo.msgReport.remark = ""; l4MsgInfo = CheckUpdateOPCODE(l4MsgInfo); switch (l4MsgInfo.opCode) { case L4L3InterfaceServiceConst.OP_CODE_NEW: CreateNewOrder(soHeader, l4MsgInfo); break; case L4L3InterfaceServiceConst.OP_CODE_DEL: UpdateOrder(soHeader, l4MsgInfo, true); break; case L4L3InterfaceServiceConst.OP_CODE_UPD: UpdateOrder(soHeader, l4MsgInfo); break; default: l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = $"{l4MsgInfo.opCode} неверный код операции"; break; } } } } checkResult.isOK = true; return(checkResult); } else { if (!OrderCanBeProcess(soHeader.soID, l4MsgInfo.opCode, "")) { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = "Заказ уже принимался по схеме с разбиением на несколько заказов."; return(checkResult); } CheckUpdateOPCODE(l4MsgInfo); switch (l4MsgInfo.opCode) { case L4L3InterfaceServiceConst.OP_CODE_NEW: CreateNewOrder(soHeader, l4MsgInfo); break; case L4L3InterfaceServiceConst.OP_CODE_DEL: UpdateOrder(soHeader, l4MsgInfo, true); break; case L4L3InterfaceServiceConst.OP_CODE_UPD: UpdateOrder(soHeader, l4MsgInfo); break; default: l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = $"{l4MsgInfo.opCode} неверный код операции"; break; } BlockForProcess(l4MsgInfo, false); checkResult.isOK = true; return(checkResult); } }
/// <summary> /// Обработчик события для кода заказчиков /// </summary> /// <param name="l4MsgInfo">Модель таблицы L4L3Event для обработки кода</param> /// <returns>Результат обработки</returns> public TCheckResult CustomerMng(TL4MsgInfo l4MsgInfo) { L4L3Customer customer = customerRepo.GetData(l4MsgInfo); TCheckResult checkres = new TCheckResult(); checkres.rejType = 0; TL4EngineInterfaceMngRepo engInterf = new TL4EngineInterfaceMngRepo(customer, l4MsgInfo); AddressEngine addressEngine = new AddressEngine(engInterf); CCatalEngine catalEngine = new CCatalEngine(engInterf); CCreditEngine creditEngine = new CCreditEngine(engInterf); bool res = true; float el4CustomerId; string l4CustomerId = "", customerIdForL4m = "", sAddressIdBillTo = "", l4CreateUserId = "", l4ModUserId = ""; logger.Info("Init 'CustomerMng' function"); l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS; try { l4CustomerId = customer.customerId.ToString(); el4CustomerId = customer.customerId; l4CreateUserId = engInterf.GetCreateUserId(); customerIdForL4m = l4CustomerId; logger.Info("'CustomerIdForL4':" + customerIdForL4m + "'l4CustomerId':" + l4CustomerId); if (l4MsgInfo.opCode == L4L3InterfaceServiceConst.OP_CODE_DEL) { if (catalEngine.LoadData(l4CustomerId) > 0) { if (catalEngine.IsCustomerDeletable(catalEngine.GetCustomerID())) { catalEngine.DeleteCustomer(catalEngine.GetCustomerID()); } } else { checkres.isOK = engInterf.NotifyErrorMessage($"Заказчик {l4CustomerId} не существует"); logger.Error($"Заказчик {l4CustomerId} не существует"); } } else { customerIdForL4m = engInterf.GetCreateUserId(); if (l4CustomerId == "") { res = false; } l4ModUserId = engInterf.GetModUserId(); if (l4ModUserId == "") { res = false; } if (res) { if (catalEngine.LoadData(l4CustomerId) > 0) { if (addressEngine.LoadData(catalEngine.GetAddressIdCatalog()) != 1) { checkres.isOK = engInterf.NotifyErrorMessage($"Ошибка при обработке заказчика - Фатальная ошибка - поле ADDRESS_ID={catalEngine.GetAddressIdCatalog().ToString() } не найдено"); logger.Error($"Ошибка при обработке заказчика - Фатальная ошибка - поле ADDRESS_ID ={ catalEngine.GetAddressIdCatalog().ToString() } не найдено"); res = false; } if (res) { catalEngine.SetCustomerDescrId(l4CustomerId); } } if (creditEngine.LoadData(catalEngine.GetCustomerID()) > 0) { if (addressEngine.LoadData(creditEngine.GetAddressIdBillTo()) != 1) { try { sAddressIdBillTo = creditEngine.GetAddressIdBillTo().ToString(); } catch { sAddressIdBillTo = ""; } checkres.isOK = engInterf.NotifyErrorMessage($"Ошибка при обработке заказчика - Фатальная ошибка - поле ADDRESS_ID={sAddressIdBillTo} не найдено"); res = false; } } } if (res) { res = FillAddressEngine(customer, addressEngine, l4ModUserId); } logger.Info("'CustomerMng - Load Customer Catalog data'"); if (res) { catalEngine.SetCustomerDescrId(l4CustomerId); catalEngine.SetAddressIdCatalog(addressEngine.GetAddressId().ToString()); catalEngine.SetInternalCustomerFlag(customer.internalCustomerFlag); catalEngine.SetInquiryValidityDays(30); catalEngine.SetCustomerCurrencyCode(customer.customerCurrencyCode); catalEngine.SetClassificationType(CheckClassificationType(customer.customerClassificationType)); catalEngine.SetWeightUnit("<NULL>"); if (customer.customerName.Length > 80) { catalEngine.SetCustomerShortName(customer.customerName.Substring(0, 80)); } else { catalEngine.SetCustomerShortName(customer.customerName); } catalEngine.SetCreationUserId(l4CreateUserId); if (customer.inn.Length > 40) { catalEngine.SetInn(customer.inn.Substring(0, 40)); } else { catalEngine.SetInn(customer.inn); } if (customer.kpp.Length > 40) { catalEngine.SetKpp(customer.kpp.Substring(0, 40)); } else { catalEngine.SetKpp(customer.kpp); } if (customer.rwstationCode.Length > 40) { catalEngine.SetRwStationCode(customer.rwstationCode.Substring(0, 40)); } else { catalEngine.SetRwStationCode(customer.rwstationCode); } if (customer.region.Length > 40) { catalEngine.SetRegion(customer.region.Substring(0, 40)); } else { catalEngine.SetRegion(customer.region); } catalEngine.SetLevel4CustomerId(customerIdForL4m); DateTime date = new DateTime(); if (customer.vailityFlag.ToString() == "Y") { if (catalEngine.GetExpirationDate() != date) { catalEngine.SetExpirationDate(date); } } else { if (catalEngine.GetExpirationDate() == date) { catalEngine.SetExpirationDate(DateTime.Now); } } catalEngine.ForceModUserDatetime(l4ModUserId); res = catalEngine.SaveData(); } logger.Info("'CustomerMng - Load Customer Catalog Credit Data'"); if (res) { creditEngine.SetCustomerID(GetCustIDFromDescr(l4CustomerId)); creditEngine.SetAddressIdBillTo(addressEngine.GetAddressId()); creditEngine.SetCreditStatus(1); creditEngine.ForceModUserDatetime(l4ModUserId); creditEngine.SetInvoiceType("Y"); creditEngine.SetDirectPaymnt("Y"); creditEngine.SetCustomerCode(Convert.ToInt32(customer.customerCurrencyCode)); res = creditEngine.SaveData(); } if (!res && l4MsgInfo.msgReport.status == L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS) { engInterf.NotifyErrorMessage("CistomerMng - Unknown fatal error."); checkres.data = "CistomerMng - Unknown fatal error."; checkres.isOK = false; } if (res && l4MsgInfo.msgReport.status == L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS) { checkres.data = "CistomerMng - SUCCESS."; checkres.isOK = true; } } logger.Info("End ''CustomerMng'' function"); return(checkres); } catch { return(checkres); } }
/// <summary> /// Распределение работы по обработчикам /// </summary> public void NewMessage() { TL4MsgInfo l4MsgInfo = new TL4MsgInfo(); OracleDynamicParameters odp = new OracleDynamicParameters(); bool isOpCodeOk; string acceptOrderConsts = ""; string sqlstr = "SELECT CHAR_VALUE " + "FROM AUX_CONSTANT " + "WHERE CONSTANT_ID='ACCEPT_ORDER_IN_SRV'"; try { using (OracleConnection connection = GetDBConnection()) { acceptOrderConsts = connection.ExecuteScalar <string>(sqlstr, null); } if (acceptOrderConsts == "") { acceptOrderConsts = "N"; } List <L4L3Event> events = new List <L4L3Event>(); sqlstr = "SELECT le.* FROM L4_L3_EVENT le WHERE MSG_STATUS = 1 AND msg_id IN (4301,4303, 4304, 4305) AND le.MSG_DATETIME > SYSDATE - 7 ORDER BY MSG_COUNTER"; using (OracleConnection connection = GetConnection()) { events = connection.Query <L4L3Event>(sqlstr, null).AsList(); } if (events == null) { logger.Error("SQL запрос из таблицы L4_L3_EVENT выполнен с ошибков в ServiceWorker.GetNewMessage."); throw new Exception(); } foreach (L4L3Event evnt in events) { l4MsgInfo.msgCounter = evnt.msgCounter; l4MsgInfo.msgId = evnt.msgId; l4MsgInfo.msgDatetime = evnt.msgDatetime; l4MsgInfo.opCode = evnt.opCode; l4MsgInfo.keyString1 = evnt.keyString1; l4MsgInfo.keyString2 = evnt.keyString2; l4MsgInfo.keyNumber1 = evnt.keyNumber1; l4MsgInfo.keyNumber2 = evnt.keyNumber2; l4MsgInfo.msgReport = new TMessageResult(); l4MsgInfo.msgReport.status = 1; l4MsgInfo.msgReport.remark = ""; logger.Info($"STARTED Event -> Table: L4_L3_EVENT, MsgCounter:{l4MsgInfo.msgCounter}"); using (OracleConnection conn = GetConnection()) { conn.Open(); using (var transaction = conn.BeginTransaction()) { try { switch (l4MsgInfo.opCode) { case L4L3InterfaceServiceConst.OP_CODE_NEW: isOpCodeOk = true; break; case L4L3InterfaceServiceConst.OP_CODE_DEL: isOpCodeOk = true; break; case L4L3InterfaceServiceConst.OP_CODE_UPD: isOpCodeOk = true; break; case L4L3InterfaceServiceConst.OP_CODE_INUP: isOpCodeOk = true; break; default: isOpCodeOk = false; l4MsgInfo = check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, $"OP_CODE: {l4MsgInfo.opCode} is not valid"); UpdateMsgStatus(l4MsgInfo, transaction); break; } if (isOpCodeOk) { switch (l4MsgInfo.msgId) { //Запуск задачи SALES_ORDER case L4L3InterfaceServiceConst.L4_L3_SALES_ORDER: if (IsBlocked(evnt.msgCounter)) { //somtask=Task.Run(() => som.SalesOrderMng(l4MsgInfo)); //somtask.Start(); //somtask.Wait(); cheker = som.SalesOrderMng(l4MsgInfo); } break; //Запуск задачи CUSTOMER_CATALOG case L4L3InterfaceServiceConst.L4_L3_CUSTOMER_CATALOG: //ccmtask = Task.Run(() => ccm.CustomerMng(l4MsgInfo)); //ccmtask.Start(); //ccmtask.Wait(); cheker = ccm.CustomerMng(l4MsgInfo); break; //Запуск задачи SHIPPING case L4L3InterfaceServiceConst.L4_L3_SHIPPING: //shiptask = Task.Run(() => sship.ShippingMng(l4MsgInfo)); //shiptask.Start(); //shiptask.Wait(); cheker = sship.ShippingMng(l4MsgInfo); break; //Запуск задачи MATERIAL case L4L3InterfaceServiceConst.L4_L3_RAW_MATERIAL: //mattask = Task.Run(() => mat.L4L3MaterialMovement(l4MsgInfo)); //mattask.Start(); //mattask.Wait(); cheker = mat.L4L3MaterialMovement(l4MsgInfo); break; } if (l4MsgInfo.msgReport.status == L4L3InterfaceServiceConst.MSG_STATUS_INSERT) { UpdateMsgStatus(l4MsgInfo, transaction); } if (cheker.isOK) { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_SUCCESS; l4MsgInfo.msgReport.remark = cheker.data; } else { l4MsgInfo.msgReport.status = L4L3InterfaceServiceConst.MSG_STATUS_ERROR; l4MsgInfo.msgReport.remark = cheker.data; } UpdateMsgStatus(l4MsgInfo, transaction); } logger.Info($"STOPPED Event -> Table: L4_L3_EVENT, MsgCounter:{l4MsgInfo.msgCounter}"); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); if (IsBlocked(l4MsgInfo.msgCounter)) { BlockForProcess(l4MsgInfo, false); } using (OracleConnection conn1 = GetConnection()) { using (var transaction1 = conn.BeginTransaction()) { try { l4MsgInfo = check.SetMsgResult(l4MsgInfo, L4L3InterfaceServiceConst.MSG_STATUS_ERROR, e.Message.Substring(0, 4000)); logger.Info($"STOPPED Event -> Table: L4_L3_EVENT, MsgCounter:{l4MsgInfo.msgCounter} with error"); UpdateMsgStatus(l4MsgInfo, transaction1); transaction1.Commit(); } catch { transaction1.Rollback(); if (IsBlocked(l4MsgInfo.msgCounter)) { BlockForProcess(l4MsgInfo, false); } } } } } } } } } catch { logger.Error("Ошибка выполнения обработчика событий"); } }