コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: Material.cs プロジェクト: Wraithname/LPKService
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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("Ошибка выполнения обработчика событий");
            }
        }