예제 #1
0
        /// <summary>
        /// 将汽车入厂煤运输记录同步到批次明细中
        /// </summary>
        /// <param name="transportId">汽车入厂煤运输记录Id</param>
        /// <returns></returns>
        public void SyncToBatch(Action <string, eOutputType> output)
        {
            int  res    = 0;
            bool succes = false;

            //已完结的有效数据
            foreach (CmcsBuyFuelTransport transport in commonDAO.SelfDber.Entities <CmcsBuyFuelTransport>("where IsUse=1 and IsFinish=1 and IsSyncBatch=0 "))
            {
                if (transport.TareTime == null)
                {
                    continue;
                }

                if (transport.TareTime.Year < 2000)
                {
                    continue;
                }

                string oldBatchId = transport.InFactoryBatchId;

                // 生成批次以及采制化三级编码数据
                CmcsInFactoryBatch batch = commonDAO.GCQCInFactoryBatchByBuyFuelTransport(transport);
                if (batch == null)
                {
                    continue;
                }

                CmcsTransport truck = commonDAO.SelfDber.Entity <CmcsTransport>("where PKID=:PKID and IsDeleted=0", new { PKID = transport.Id });
                if (truck != null)
                {
                    truck.TransportNo          = transport.CarNumber;
                    truck.LastModificAtionTime = transport.LastModificAtionTime;
                    truck.InfactoryTime        = transport.InFactoryTime;
                    truck.ArriveDate           = transport.GrossTime;
                    truck.TareDate             = transport.TareTime;
                    truck.OutfactoryTime       = transport.OutFactoryTime;
                    truck.TicketQty            = transport.TicketWeight;
                    truck.GrossQty             = transport.GrossWeight;
                    truck.SkinQty          = transport.TareWeight;
                    truck.SuttleQty        = transport.SuttleWeight;
                    truck.KgQty            = transport.DeductWeight;
                    truck.CheckQty         = transport.SuttleWeight - transport.DeductWeight;
                    truck.MarginQty        = transport.SuttleWeight - transport.DeductWeight - transport.TicketWeight;
                    truck.InFactoryBatchId = batch.Id;
                    truck.PKID             = transport.Id;
                    truck.DataFrom         = "汽车智能化";
                    succes = commonDAO.SelfDber.Update(truck) > 0;
                }
                else
                {
                    truck = new CmcsTransport()
                    {
                        TransportNo          = transport.CarNumber,
                        LastModificAtionTime = transport.LastModificAtionTime,
                        InfactoryTime        = transport.CreationTime,
                        ArriveDate           = transport.GrossTime,
                        TareDate             = transport.TareTime,
                        OutfactoryTime       = transport.OutFactoryTime,
                        TicketQty            = transport.TicketWeight,
                        GrossQty             = transport.GrossWeight,
                        SkinQty          = transport.TareWeight,
                        SuttleQty        = transport.SuttleWeight,
                        KgQty            = transport.DeductWeight,
                        CheckQty         = transport.SuttleWeight - transport.DeductWeight,
                        MarginQty        = transport.SuttleWeight - transport.DeductWeight - transport.TicketWeight,
                        InFactoryBatchId = batch.Id,
                        PKID             = transport.Id,
                        DataFrom         = "汽车智能化"
                    };

                    succes = commonDAO.SelfDber.Insert(truck) > 0;
                }

                if (succes)
                {
                    succes = UpdateInFactoryBatch(batch);                     //更新新批次
                    if (succes)
                    {
                        if (oldBatchId != batch.Id)
                        {
                            CmcsInFactoryBatch oldInFactoryBatch = Dbers.GetInstance().SelfDber.Get <CmcsInFactoryBatch>(oldBatchId);
                            UpdateInFactoryBatch(oldInFactoryBatch);                             //更新旧批次
                        }

                        //更新智能化运输记录
                        transport.IsSyncBatch      = 1;
                        transport.InFactoryBatchId = batch.Id;
                        Dbers.GetInstance().SelfDber.Update <CmcsBuyFuelTransport>(transport);

                        res++;
                    }
                }
            }

            output(string.Format("同步批次明细数据 {0} 条", res), eOutputType.Normal);
        }