Exemple #1
0
        public override bool Equals(object obj)
        {
            ProdOpReport another = obj as ProdOpReport;

            if (another == null)
            {
                return(false);
            }
            else
            {
                return(this.Id == another.Id);
            }
        }
        public void ReportProdOrderOperation(ProdOpReport prodOpReport, IList<ErrorMessage> errorMessageList, int maxFailCount)
        {
            #region 生产单报工
            try
            {
                if (prodOpReport.Status == Entity.SAP.StatusEnum.Success)
                {
                    return;
                }

                log.DebugFormat("开始连接Web服务进行生产报工, 生产单号{0}, 工作中心{1},数量{2},废品数{3}", prodOpReport.AUFNR, prodOpReport.WORKCENTER, prodOpReport.GAMNG, prodOpReport.SCRAP);

                prodOpReport.Status = Entity.SAP.StatusEnum.Success;
                this.UpdateSiSap(prodOpReport);
                this.genericMgr.FlushSession();

                MI_PO_CFR_LESService service = new MI_PO_CFR_LESService();
                service.Credentials = base.Credentials;
                service.Timeout = base.TimeOut;
                service.Url = ReplaceSAPServiceUrl(service.Url);

                ZSPOCOMF input = new ZSPOCOMF();
                input.AUFNR = prodOpReport.AUFNR;
                input.ARBPL = prodOpReport.WORKCENTER;
                input.LMNGA = prodOpReport.GAMNG;
                input.LMNGASpecified = input.LMNGA != 0;
                input.SCRAP = prodOpReport.SCRAP;
                input.SCRAPSpecified = input.SCRAP != 0;
                input.TEXT = prodOpReport.Id.ToString();
                //将工序的报工时间传给sap
                input.POSTG_DATE = prodOpReport.CreateDate.ToString("yyyyMMdd");
                //将报工工序的aufpl,plnfl,vornr传给sap
                OrderOperation orderOp = genericMgr.FindById<OrderOperation>(prodOpReport.OrderOpId);
                input.AUFPL = orderOp.AUFPL;
                input.PLNFL = orderOp.PLNFL;
                input.VORNR = orderOp.VORNR;

                string result = null;
                com.Sconit.Service.SAP.MI_PO_CFR_LES.ZITEM_LX[] orderOpAry = service.MI_PO_CFR_LES(input, out result);

                if (result.Equals("TRUE", StringComparison.OrdinalIgnoreCase))
                {
                    log.DebugFormat("生产报工成功,生产单号{0}, 工作中心{1},数量{2},废品数{3}。", prodOpReport.AUFNR, prodOpReport.WORKCENTER, prodOpReport.GAMNG, prodOpReport.SCRAP);

                    if (orderOpAry != null && orderOpAry.Count() > 0)
                    {
                        DateTime dateTimeNow = DateTime.Now;

                        foreach (com.Sconit.Service.SAP.MI_PO_CFR_LES.ZITEM_LX ZITEM_LX in orderOpAry)
                        {
                            ProdOpBackflush prodOpBackflush = new ProdOpBackflush();

                            prodOpBackflush.SAPOpReportId = prodOpReport.Id;
                            prodOpBackflush.AUFNR = ZITEM_LX.AUFNR;
                            prodOpBackflush.WERKS = ZITEM_LX.WERKS;
                            prodOpBackflush.AUFPL = ZITEM_LX.AUFPL.TrimStart('0');
                            prodOpBackflush.APLZL = ZITEM_LX.APLZL;
                            prodOpBackflush.PLNTY = ZITEM_LX.PLNTY;
                            prodOpBackflush.PLNNR = ZITEM_LX.PLNNR;
                            prodOpBackflush.PLNAL = ZITEM_LX.PLNAL;
                            prodOpBackflush.PLNFL = ZITEM_LX.PLNFL;
                            prodOpBackflush.VORNR = ZITEM_LX.VORNR;
                            prodOpBackflush.ARBPL = ZITEM_LX.ARBPL;
                            prodOpBackflush.RUEK = ZITEM_LX.RUEK;
                            prodOpBackflush.AUTWE = ZITEM_LX.AUTWE;
                            prodOpBackflush.WORKCENTER = prodOpReport.WORKCENTER;
                            prodOpBackflush.GAMNG = prodOpReport.GAMNG;
                            prodOpBackflush.SCRAP = prodOpReport.SCRAP;
                            prodOpBackflush.Status = StatusEnum.Pending;
                            prodOpBackflush.CreateDate = dateTimeNow;
                            prodOpBackflush.LastModifyDate = dateTimeNow;
                            prodOpBackflush.ErrorCount = 0;
                            prodOpBackflush.ProdLine = prodOpReport.ProdLine;
                            prodOpBackflush.OrderNo = prodOpReport.OrderNo;
                            prodOpBackflush.ReceiptNo = prodOpReport.ReceiptNo;
                            prodOpBackflush.OrderOpId = prodOpReport.OrderOpId;
                            prodOpBackflush.OrderOpReportId = prodOpReport.OrderOpReportId;
                            prodOpBackflush.EffectiveDate = prodOpReport.EffectiveDate;
                            prodOpBackflush.Version = 1;

                            this.genericMgr.Create(prodOpBackflush);
                        }
                    }
                }
                else
                {
                    prodOpReport.Status = Entity.SAP.StatusEnum.Fail;
                    prodOpReport.TEXT = result.Substring(0, result.Length < 250 ? result.Length : 250);
                    prodOpReport.ErrorCount++;
                    this.UpdateSiSap(prodOpReport);

                    string logMessage = string.Format("生产报工失败,生产单号{0}, 工作中心{1},数量{2},废品数{3},失败信息:{4}。", prodOpReport.AUFNR, prodOpReport.WORKCENTER, prodOpReport.GAMNG, prodOpReport.SCRAP, result);
                    log.Error(logMessage);
                    if (prodOpReport.ErrorCount >= maxFailCount)
                    {
                        errorMessageList.Add(new ErrorMessage
                        {
                            Template = NVelocityTemplateRepository.TemplateEnum.ReportProdOrderOpFail,
                            Message = logMessage
                        });
                    }
                }

                this.genericMgr.FlushSession();
            }
            catch (Exception ex)
            {
                this.genericMgr.CleanSession();

                prodOpReport.Status = Entity.SAP.StatusEnum.Fail;
                prodOpReport.TEXT = ex.Message.Substring(0, ex.Message.Length < 250 ? ex.Message.Length : 250);
                prodOpReport.ErrorCount++;
                this.UpdateSiSap(prodOpReport);

                string logMessage = string.Format("生产报工出现异常,生产单号{0}, 工作中心{1},数量{2},废品数{3},异常信息:{4}。", prodOpReport.AUFNR, prodOpReport.WORKCENTER, prodOpReport.GAMNG, prodOpReport.SCRAP, ex.Message);
                log.Error(logMessage, ex);
                if (prodOpReport.ErrorCount == 10)
                {
                    errorMessageList.Add(new ErrorMessage
                    {
                        Template = NVelocityTemplateRepository.TemplateEnum.ReportProdOrderOpFail,
                        Exception = ex,
                        Message = logMessage
                    });
                }
            }
            #endregion
        }