Beispiel #1
0
 public ActionResult HandAdd(ShippingDocument entity)
 {
     if (entity.TaskID != null)
     {
         ProduceTask task = this.service.ProduceTask.Get(entity.TaskID);
         entity.CustMixpropID = task.CustMixpropID;
         entity.CarpRadii     = task.CarpRadii;
         entity.CastMode      = task.CastMode;
         entity.CementBreed   = task.CementBreed;
         entity.ConsPos       = task.ConsPos;
         entity.ConStrength   = task.ConStrength;
         entity.ConstructUnit = task.ConstructUnit;
         entity.ContractID    = task.ContractID;
         entity.ContractName  = task.Contract.ContractName;
         entity.CustName      = task.Contract.CustName;
         entity.CustomerID    = task.Contract.CustomerID;
         entity.Distance      = task.Distance;
         entity.ForkLift      = task.ForkLift;
         entity.ImdGrade      = task.ImdGrade;
         entity.ImpGrade      = task.ImpGrade;
         entity.ImyGrade      = task.ImyGrade;
         entity.LinkMan       = task.LinkMan;
         entity.RealSlump     = task.Slump;
         entity.SupplyUnit    = task.SupplyUnit;
         entity.Tel           = task.Tel;
     }
     return(base.Add(entity));
 }
        public override System.Web.Mvc.ActionResult Add(Commission Commission)
        {
            ProduceTask task = this.service.ProduceTask.Get(Commission.TaskID);

            task.IsDatum = true;
            this.service.ProduceTask.Update(task, null);

            return(base.Add(Commission));
        }
Beispiel #3
0
        //public ActionResult Center(int id)
        //{

        //    //查找当前用户所属的搅拌站,若没有找到,则默认第一个搅拌站

        //    Company factory = this.service.Company.GetCurrentCompany();

        //    var pList = this.service.ProduceTask.Query().Where(s => !s.IsCompleted && s.BuildTime >= DateTime.Now.AddDays(-30)).OrderByDescending(
        //        p => p.ShippingDocuments.Where(s => s.IsEffective).Max(s => s.BuildTime)).ToList();
        //    foreach (ProduceTask t in pList)
        //    {
        //        Project p = this.service.GetGenericService<Project>().Get(t.ProjectID);
        //        if (p != null)
        //        {
        //            if (factory.Latitude.HasValue &&
        //                factory.Longtide.HasValue &&
        //                p.Latitude.HasValue &&
        //                p.Longitude.HasValue)
        //            {
        //                t.Distance = Convert.ToDecimal(LatLonUtils.GetDistance(factory.Latitude.Value, factory.Longtide.Value, p.Latitude.Value, p.Longitude.Value));
        //            }
        //        }
        //        if (t.Distance == null)
        //        {
        //            t.Distance = 0;
        //        }
        //    }
        //    ViewBag.Tasks = pList;

        //    IList<ShippingDocument> shipping = this.service.ShippingDocument.getShippingTask(null);
        //    ViewBag.CarTasks = shipping;

        //    return base.Index();
        //}


        public ActionResult Center(int id)
        {
            //查找当前用户所属的搅拌站,若没有找到,则默认第一个搅拌站

            Company factory = this.service.Company.GetCurrentCompany();

            var _pList = this.service.GetGenericService <distance>().Query().OrderBy(m => m.projectid).ToList();
            IList <ProduceTask> pList = new List <ProduceTask>();
            ProduceTask         op    = new ProduceTask();

            foreach (distance t in _pList)
            {
                op = new ProduceTask();
                Project p = this.service.GetGenericService <Project>().Get(t.projectid);
                if (p == null)
                {
                    continue;
                }
                if (p != null)
                {
                    if (factory.Latitude.HasValue &&
                        factory.Longtide.HasValue &&
                        p.Latitude.HasValue &&
                        p.Longitude.HasValue)
                    {
                        if (t.distance <= 0.00m)
                        {
                            op.Distance = Convert.ToDecimal(LatLonUtils.GetDistance(factory.Latitude.Value, factory.Longtide.Value, p.Latitude.Value, p.Longitude.Value));
                        }
                        else
                        {
                            op.Distance = t.distance;
                        }
                    }
                }
                if (t.distance <= 0.00m)
                {
                    op.Distance = 0.00m;
                }

                op.ID          = t.ID.ToString();
                op.ProjectName = t.ProjectName;
                op.ProjectID   = t.projectid;
                op.ConsPos     = "";
                op.ConStrength = "";
                op.CastMode    = t.CastModeName;
                pList.Add(op);
            }
            ViewBag.Tasks = pList;

            IList <ShippingDocument> shipping = this.service.ShippingDocument.getShippingTask(null);

            ViewBag.CarTasks = shipping;

            return(base.Index());
        }
 public ActionResult UpdateTodayPlan(int[] ids)
 {
     foreach (int id in ids)
     {
         ProducePlan plan = this.m_ServiceBase.Get(id);
         ProduceTask task = plan.ProduceTask;
         task.NeedDate = DateTime.Now;
         this.service.ProduceTask.Update(task, null);
     }
     return(OperateResult(true, Lang.Msg_Operate_Success, true));
 }
 public override System.Web.Mvc.ActionResult Delete(string[] id)
 {
     foreach (string str in id)
     {
         Commission  obj  = this.service.GetGenericService <Commission>().Get(str);
         ProduceTask task = this.service.ProduceTask.Get(obj.TaskID);
         task.IsDatum = false;
         this.service.ProduceTask.Update(task);
     }
     return(base.Delete(id));
 }
        private bool getTaskIsCompleted(string taskID)
        {
            ProduceTask pt = this.service.ProduceTask.Get(taskID);

            if (pt == null)
            {
                return(true);
            }
            else
            {
                return(pt.IsCompleted);
            }
        }
Beispiel #7
0
        /// <inheritdoc />
        public async Task <ProduceResponse.Topic> SendAsync(IEnumerable <Message> messages, string topicName, int partitionId, ISendMessageConfiguration configuration, CancellationToken cancellationToken)
        {
            var produceTopicTask = new ProduceTask(topicName, partitionId, messages, configuration ?? Configuration.SendDefaults, cancellationToken);

            Interlocked.Add(ref _sendingMessageCount, produceTopicTask.Messages.Count);
            try {
                await _produceMessageQueue.EnqueueAsync(produceTopicTask, cancellationToken).ConfigureAwait(false);

                return(await produceTopicTask.Tcs.Task.ConfigureAwait(false));
            } catch (InvalidOperationException ex) {
                throw new ObjectDisposedException("Cannot send messages after Stopped or Disposed", ex);
            } finally {
                Interlocked.Add(ref _sendingMessageCount, -produceTopicTask.Messages.Count);
                produceTopicTask.Dispose();
            }
        }
 public ActionResult PromptTodayTasks(int id)
 {
     try
     {
         ProducePlan plan = this.m_ServiceBase.Get(id);
         ProduceTask task = plan.ProduceTask;
         plan.PlanDate = DateTime.Now;
         this.m_ServiceBase.Update(plan, null);
         task.NeedDate = DateTime.Now;
         this.service.ProduceTask.Update(task, null);
         this.service.ProduceTask.PromptTodayTasks();
         return(OperateResult(true, Lang.Msg_Operate_Success, true));
     }
     catch (Exception ex)
     {
         return(OperateResult(false, ex.Message, false));
     }
 }
Beispiel #9
0
        public bool CancelAuditing(CustomerPlan plan)
        {
            // var plan = this.Get(id);
            if (plan != null)
            {
                ProduceTask task = new ProduceTask();
                task = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Get(plan.TaskID);
                if (task.IsFormulaSend)
                {
                    throw new Exception("单据已下发配比,不能取消审核!");
                }
                else
                {
                    //更新CustomerPlan表记录
                    plan.AuditTime = null;
                    plan.Auditor   = string.Empty;
                    string TaskID = plan.TaskID;
                    plan.TaskID = null;
                    this.Update(plan, null);

                    PublicService ps = new PublicService();
                    if (TaskID != "")
                    {
                        //删除ProducePlan表记录
                        ProducePlan pplan = new ProducePlan();
                        pplan = this.m_UnitOfWork.GetRepositoryBase <ProducePlan>().Query().Where(p => p.TaskID.Contains(TaskID)).OrderByDescending(p => p.ID).FirstOrDefault();
                        if (pplan != null)
                        {
                            ps.GetGenericService <ProducePlan>().Delete(pplan);
                        }
                        //删除ProduceTask表记录
                        if (task != null)
                        {
                            ps.GetGenericService <ProduceTask>().Delete(task);
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
Beispiel #10
0
        public dynamic getPumpTypeAndPumpCost(string taskId, DateTime?pumpDate)
        {
            ProduceTask task = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Get(taskId);
            //合同编号
            string contractId = task.ContractID;
            //合同明细编号
            int          contractItemId = task.ContractItemsID;
            ContractItem contractItem   = task.ContractItem;
            //泵车类型
            string pumpType = task.PumpType;

            //发货单数量
            decimal?shipSum = this.getShipSum(taskId, pumpDate);

            return(new {
                Result = true,
                PumpType = pumpType,
                PumpCost = contractItem == null ? 0 : contractItem.PumpCost,
                ShipSum = shipSum == null ? 0 : shipSum
            });
        }
Beispiel #11
0
        /// <summary>
        /// 看板发货
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public ActionResult AddDispatch(string taskId)
        {
            ProduceTask pt = this.service.ProduceTask.Get(taskId);

            if (pt != null)
            {
                //下拉列表车号自然排序
                var carList = this.service.Car.GetMixerCarListOrderByID();

                var pumpList = this.service.Car.GetPumpList()
                               .OrderBy(p => p.ID);

                ViewBag.CarDics  = new SelectList(carList, "ID", "CarNo");
                ViewBag.PumpList = new SelectList(pumpList, "ID", "CarNo");

                ViewBag.TaskInfo = pt;
                var DefaultManufactureCubeConfig = this.service.SysConfig.GetSysConfig(Model.Enums.SysConfigEnum.DefaultManufactureCube);
                ViewBag.DefaultManufactureCube = DefaultManufactureCubeConfig == null ? "" : DefaultManufactureCubeConfig.ConfigValue;
            }
            InitCommonViewBag();
            return(View());
        }
        public override ActionResult Delete(string[] id)
        {
            foreach (object item in id)
            {
                ConsMixprop cm  = this.m_ServiceBase.Get(item);
                DateTime    dt1 = cm.BuildTime;

                string           taskid = cm.TaskID;
                string           pid    = cm.ProductLineID;
                ProduceTask      pt     = this.service.ProduceTask.Get(taskid);
                ShippingDocument doc    = this.service.ShippingDocument.Find("TaskID = '" + taskid + "' AND IsEffective = 1 AND ShipDocType = '0'", 1, 1, "ID", "DESC").FirstOrDefault();
                if (doc != null)
                {
                    DateTime dt2 = doc.BuildTime;

                    if (doc.ProvidedCube > 0 && doc.ProductLineID == pid && dt1 < dt2)
                    {
                        return(OperateResult(false, Lang.Msg_Operate_Failed + "已生产的施工配比不允许删除", ""));
                    }
                }
            }
            return(base.Delete(id));
        }
Beispiel #13
0
        public ActionResult Save(SchedulerViewModel entity)
        {
            lock (obj)
            {
                try
                {
                    if (bool.Parse(this.service.SysConfig.GetSysConfig("Gps").ConfigValue)) //若GPS开关打开,只能发送待命队列中的车
                    {
                        Car c = this.service.Car.Get(entity.ShippingDocument.CarID);
                        if (c.CarStatus != Model.Enums.CarStatus.AllowShipCar)
                        {
                            return(OperateResult(false, "在使用GPS的情况下,只能调派待命状态的车辆。", null));
                        }
                    }

                    //判断是否存在自动过磅并且未处理的记录
                    TZRalation objchk = this.service.TZRalation.Query()
                                        .Where(p => p.CarID == entity.ShippingDocument.CarID && p.IsCompleted == false).OrderByDescending(p => p.BuildTime)
                                        .FirstOrDefault();
                    if (objchk != null)
                    {
                        if (string.IsNullOrEmpty(objchk.ActionType))
                        {
                            IList <SysFunc> FuncList = this.service.User.GetUserFuncs(AuthorizationService.CurrentUserID);
                            SysFunc         sf       = FuncList.Where(p => p.ID == "410505").FirstOrDefault();
                            if (sf != null)              //有权限
                            {
                                return(OperateResult(false, Lang.Msg_hasAutoTz, objchk));
                            }
                            else
                            {
                                return(OperateResult(false, Lang.Msg_hasAutoTz, 0));
                            }
                        }
                    }

                    string      taskid      = entity.ShippingDocument.TaskID;
                    ProduceTask produceTask = this.service.ProduceTask.Get(taskid);
                    SysConfig   config      = this.service.SysConfig.GetSysConfig(Model.Enums.SysConfigEnum.IsAllowConsMixpropLimit);
                    if (config != null && config.ConfigValue == "true" && produceTask.CementType == Model.Enums.CementType.CommonCement)
                    {
                        string measureError = this.service.DispatchList.CheckCheckMesureScale(entity);
                        if (!string.IsNullOrEmpty(measureError))
                        {
                            return(OperateResult(false, measureError, null));
                        }
                    }
                    //检查合同限额控制
                    string msg = this.service.DispatchList.CheckCubeLimit(entity);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        return(OperateResult(true, msg, null));
                    }

                    entity.DispatchList.Field2 = "";
                    if (entity.DispatchList.SlurryCount > 0 && entity.DispatchList.BetonCount == 0)
                    {
                        entity.DispatchList.Field2 = "1";
                    }

                    SchedulerViewModel saveEntity = this.service.DispatchList.SaveScheduler(entity);
                    return(OperateResult(true, Lang.Msg_Operate_Success, saveEntity.ShippingDocument.GetId()));
                }
                catch (Exception e)
                {
                    return(OperateResult(false, Lang.Msg_Operate_Failed + e.Message, null));
                }
            }
        }
Beispiel #14
0
        private void AddGPSDispatch(object obj)
        {
            logger.Debug("GPS接口,调用:AddGPSDispatch");
            //开启了重庆天助GPS接口

            /***** 注销重庆天助GPS模块 *****
             * if (base.GPSSwitch("CQTZGPS"))
             * {
             *  try
             *  {
             *      DispatchList dispatch = (DispatchList)obj;
             *      GpsClass gps = new GpsClass();
             *      //GpsClass gps = new GpsClass("tzyl", "123456");
             *      Customer customer = dispatch.ProduceTask.Contract.Customer;
             *      ProduceTask task = dispatch.ProduceTask;
             *      ShippingDocument document = dispatch.ShippingDocument;
             *      int CustomerID;
             *      if ((CustomerID = gps.GetCustomer(customer.CustName)) == 0)
             *          CustomerID = gps.AddCustomer(customer.CustName, customer.LinkMan, customer.LinkTel, customer.BusinessAddr, customer.Remark);
             *      int CSID;
             *      if ((CSID = gps.GetConstructionSite(task.ProjectName)) == 0)
             *          CSID = gps.AddConstructionSite(task.ProjectName, task.ProjectAddr, CustomerID, task.LinkMan, task.Tel, task.Remark);
             *      int TaskID;
             *      if ((TaskID = gps.GetTask(task.ID)) == 0)
             *          TaskID = gps.AddTask(task.ID, CSID, task.ConsPos, task.ConStrength, 0, Convert.ToInt32(task.PlanCube), task.NeedDate.ToString("yyyy-MM-dd HH:mm:ss"), 0, 0, "", 0, task.Remark);
             *      gps.AddDispatch(dispatch.ID, dispatch.CarID, TaskID.ToString(), Convert.ToDouble(document.ParCube), (document.DeliveryTime ?? DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss"), string.IsNullOrEmpty(dispatch.Driver) ? "司机" : dispatch.Driver, 0, dispatch.Remark);
             *  }
             *  catch (Exception e)
             *  {
             *      logger.Error(e.Message, e);
             *  }
             * }
             * ******/
            //开启了中联重科GPS接口
            //if (base.GPSSwitch("ZLZKGPS"))
            //{
            try
            {
                DispatchList dispatch = (DispatchList)obj;
                Customer     customer = dispatch.ProduceTask.Contract.Customer;
                ProduceTask  task     = dispatch.ProduceTask;

                string   tokenKey;
                string   projectId;
                string   timestamp;
                TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
                timestamp = Convert.ToInt64(ts.TotalSeconds).ToString();    //生成时间戳作为ProjectID
                projectId = task.ProjectID == null ? "P" + timestamp : task.ProjectID;
                tokenKey  = base.GPSLogin();
                GPSService.EntryServiceClient gpsclient = new GPSService.EntryServiceClient();
                // 添加工程,先判断GPS中是否存在此工程
                string ProjectXML = gpsclient.ProjectTryGetInfo(tokenKey, projectId);
                if (string.Empty == ProjectXML)
                {
                    gpsclient.ProjectAdd(tokenKey, projectId, task.ProjectAddr, task.ProjectName, task.BuildUnit, task.ConstructUnit, task.LinkMan, task.Tel, null, null, null, 0, true);
                }

                //发车
                //1、检查车辆是否存在
                string carid      = dispatch.CarID;
                string CarinfoXML = gpsclient.CarTryGetInfo(tokenKey, carid);
                //if (CarinfoXML == string.Empty)
                //{
                //    Car tempcar = this.m_UnitOfWork.GetRepositoryBase<Car>().Get(carid);
                //    gpsclient.CarAdd(tokenKey, tempcar.ID, tempcar.ID, "TERM00001", "SIM00001", tempcar.Owner, null, null, (double?)tempcar.CarWeight, (double?)tempcar.MaxCube, null);
                //}

                //2、检查任务单是否存在
                string taskid  = dispatch.TaskID;
                string TaskXML = gpsclient.TaskTryGetInfo(tokenKey, taskid);
                if (TaskXML == string.Empty)
                {
                    gpsclient.TaskAdd(tokenKey, taskid, projectId, task.Contract.CustName, task.LinkMan, task.Tel, task.ConstructUnit, task.ConsPosType, task.ConsPos, (double)task.PlanCube, task.IsCommission, "", task.CastMode, task.ConStrength, task.Slump, task.OpenTime, task.IsCompleted, task.CompleteDate, task.Remark);
                }
                gpsclient.CarTaskAdd(tokenKey, dispatch.ID, dispatch.TaskID, dispatch.CarID, "", (double)dispatch.ParCube, DateTime.Now, null, dispatch.ProductLineName, string.Empty);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                //throw ex;
            }
            //}
        }
Beispiel #15
0
        //根据计划创建新任务单
        void CreateProduceTask(CustomerPlan cPlan, IUnitOfWork uow, out string TaskID)
        {
            var contractItem   = CreateContractItem(cPlan, uow);
            int contractItemId = contractItem.ID ?? 0;

            TaskID = string.Empty;;
            if (contractItem != null && contractItemId > 0)
            {
                ProduceTask task = new ProduceTask();

                task.ContractID      = cPlan.ContractID;
                task.ContractItemsID = contractItemId;

                task.ConstructUnit = cPlan.ConstructUnit;
                task.ProjectName   = cPlan.ProjectName;
                task.ProjectAddr   = cPlan.ProjectAddr;
                task.ConStrength   = contractItem.ConStrength;
                task.ConsPos       = cPlan.ConsPos;
                task.Slump         = cPlan.Slump;
                task.CastMode      = cPlan.CastMode;
                task.PlanCube      = cPlan.PlanCube;
                task.PumpType      = cPlan.PumpName;
                task.SupplyUnit    = cPlan.SupplyUnit;
                DateTime dt;
                if (!DateTime.TryParse(cPlan.PlanDate.ToString("yyyy-MM-dd") + " " + cPlan.NeedDate, out dt))
                {
                    DateTime.TryParse(cPlan.PlanDate.ToString("yyyy-MM-dd") + " 21:00:00", out dt);
                }
                task.NeedDate = dt;

                task.Tel      = cPlan.Tel;
                task.LinkMan  = cPlan.LinkMan;
                task.Remark   = cPlan.Remark;
                task.RegionID = cPlan.RegionID;
                task.TaskType = TaskType.ContractTask;
                ProduceTaskService pts = new ProduceTaskService(uow);
                pts.CheckIsAutoAudit(task);
                var project = pts.CreateProject(task);
                task.ProjectID = project.ID;


                string      ID = "";
                ProduceTask pj = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Query().Where(p => p.ID.Contains(DateTime.Now.ToString("yyMMdd"))).OrderByDescending(p => p.ID).FirstOrDefault();
                if (pj == null)
                {
                    ID = DateTime.Now.ToString("yyMMdd") + "001";
                }
                else
                {
                    ID = pj.ID.Substring(6, 3);
                    int k = Convert.ToInt32(ID);
                    k++;
                    ID = DateTime.Now.ToString("yyMMdd") + (k.ToString().Length == 1 ? ("00" + k.ToString()) : (k.ToString().Length == 2 ? ("0" + k.ToString()) : k.ToString()));
                }
                task.ID = ID;


                task         = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Add(task);
                TaskID       = task.ID;
                cPlan.TaskID = task.ID;
                CreateProducePlan(cPlan);
            }
        }
Beispiel #16
0
        /// <summary>
        /// 整车转发
        /// </summary>
        /// <param name="sourceShipDocID">源运输单ID</param>
        /// <param name="targetTaskId">转至任务单</param>
        /// <param name="isOriginComplete">原任务单已完成(不需要转料后补)</param>
        /// <param name="isTrashOrigin">原任务单作废</param>
        /// <param name="returnReason">转发原因</param>
        /// <returns></returns>
        public ShippingDocument Forward(string sourceShipDocID, string targetTaskId, bool isOriginComplete, bool isTrashOrigin, string returnReason, out string message, string[] _carids)
        {
            var shipDocRepo         = this.m_UnitOfWork.GetRepositoryBase <ShippingDocument>();
            ShippingDocument oldDoc = shipDocRepo.Get(sourceShipDocID);
            ProduceTask      task   = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Get(targetTaskId);

            message = Lang.Msg_Operate_Success;
            if (oldDoc != null && task != null)
            {
                //UNDONE: 转发方量和生产方量是否要处理
                ShippingDocument newDoc = new ShippingDocument();// oldDoc.Clone() as ShippingDocument;\

                //如果有_carids说明不光转发还要换车
                if (_carids == null || _carids.Length == 0 || string.IsNullOrEmpty(_carids[0]))
                {
                    newDoc.CarID = oldDoc.CarID;
                }
                else
                {
                    newDoc.CarID = _carids[0];
                }

                newDoc.IsEffective = true;
                newDoc.ContractID  = task.ContractID;

                newDoc.ContractName = task.Contract.ContractName;
                newDoc.CustName     = task.Contract.CustName;
                newDoc.CustomerID   = task.Contract.CustomerID;

                newDoc.CustMixpropID = task.CustMixpropID;

                newDoc.ProductLineName = oldDoc.ProductLineName;
                newDoc.ProductLineID   = oldDoc.ProductLineID;

                newDoc.DeliveryTime = DateTime.Now;
                //newDoc.ProduceDate = oldDoc.ProduceDate;
                newDoc.ProduceDate = DateTime.Now;

                newDoc.ConsMixpropID       = oldDoc.ConsMixpropID;
                newDoc.SlurryConsMixpropID = oldDoc.SlurryConsMixpropID;
                newDoc.FormulaName         = oldDoc.FormulaName;
                newDoc.ProjectName         = task.ProjectName;
                newDoc.ProjectAddr         = task.ProjectAddr;
                newDoc.ProjectID           = task.ProjectID;
                newDoc.ShipDocType         = "0";
                newDoc.ConStrength         = task.ConStrength;
                newDoc.CastMode            = task.CastMode;
                newDoc.ConsPos             = task.ConsPos;
                newDoc.ImpGrade            = task.ImpGrade;
                newDoc.ImyGrade            = task.ImyGrade;
                newDoc.ImdGrade            = task.ImdGrade;
                newDoc.CarpRadii           = task.CarpRadii;
                newDoc.CementBreed         = task.CementBreed;
                newDoc.Distance            = oldDoc.Distance;
                newDoc.RealSlump           = task.Slump;//oldDoc.RealSlump;此处换成目标工地的坍落度,保持与票面一致
                newDoc.BetonCount          = oldDoc.BetonCount;
                newDoc.SlurryCount         = oldDoc.SlurryCount;
                newDoc.OtherCube           = oldDoc.OtherCube;
                newDoc.XuCube     = oldDoc.XuCube;
                newDoc.RemainCube = oldDoc.RemainCube;


                newDoc.ShippingCube = oldDoc.ShippingCube;
                newDoc.PlanCube     = task.PlanCube;



                //调度方量 = 混凝土 + 砂浆
                newDoc.SendCube = newDoc.BetonCount + newDoc.SlurryCount;
                //出票方量 = 调度方量 + 其它方量 + 剩余方量
                decimal?parCube = newDoc.SendCube + newDoc.OtherCube + (newDoc.RemainCube ?? 0);
                newDoc.ParCube      = parCube ?? 0;
                newDoc.SignInCube   = newDoc.ParCube;
                newDoc.ScrapCube    = 0;
                newDoc.TransferCube = 0;
                newDoc.Surveyor     = oldDoc.Surveyor;

                newDoc.Operator  = oldDoc.Operator;
                newDoc.RegionID  = task.RegionID;
                newDoc.ForkLift  = task.ForkLift;
                newDoc.PlanClass = task.PlanClass;
                //newDoc.ProduceDate = DateTime.Now;
                newDoc.SupplyUnit    = task.SupplyUnit;
                newDoc.ConstructUnit = task.ConstructUnit;

                newDoc.Signer  = AuthorizationService.CurrentUserID;
                newDoc.LinkMan = task.LinkMan;
                newDoc.Tel     = task.Tel;
                //是否代外生产.
                newDoc.EntrustUnit = task.IsCommission ? task.SupplyUnit : "";
                newDoc.Remark      = string.Format("CODEADD由运输单:{0}整车转发生成", sourceShipDocID);
                newDoc.IsProduce   = oldDoc.IsProduce;

                newDoc.ID     = null;
                newDoc.TaskID = targetTaskId;

                //从最后一个发货单取得累计方量和车数
                ShippingDocumentService sdService = new ShippingDocumentService(this.m_UnitOfWork);
                ShippingDocument        doc       = sdService.Query()
                                                    .Where(p => p.TaskID == targetTaskId && p.IsEffective == true && p.ShipDocType == "0")
                                                    .OrderByDescending(p => p.BuildTime)
                                                    .FirstOrDefault();
                if (doc != null)
                {
                    newDoc.ProvidedTimes = doc.ProvidedTimes + 1;
                    newDoc.ProvidedCube  = doc.ProvidedCube + newDoc.ParCube;

                    newDoc.PumpName = doc.PumpName;
                }
                else
                {
                    newDoc.ProvidedTimes = 1;
                    newDoc.ProvidedCube  = newDoc.ParCube;
                }

                //newDoc.ProjectName = task.ProjectName;
                //newDoc.ConStrength = task.ConStrength;
                //newDoc.CastMode = task.CastMode;
                //newDoc.ConsPos = task.ConsPos;
                //newDoc.ImpGrade = task.ImpGrade;
                //newDoc.ImyGrade = task.ImyGrade;
                //newDoc.ImdGrade = task.ImdGrade;
                //newDoc.CarpRadii = task.CarpRadii;
                //newDoc.CementBreed = task.CementBreed;  
                //newDoc.ForkLift = task.ForkLift;
                //newDoc.PlanClass = task.PlanClass;
                //newDoc.ProduceDate = DateTime.Now;
                //newDoc.SupplyUnit = task.SupplyUnit;
                //newDoc.ConstructUnit = task.ConstructUnit;

                ////是否托外生产.
                //newDoc.EntrustUnit = task.IsCommission ? task.SupplyUnit : "";
                //newDoc.IsEffective = true;

                //生产登记关系转移到新发货单

                newDoc.DispatchLists = new List <DispatchList>();
                //newDoc.DispatchLists.Clear();
                //newDoc.DispatchLists = null;
                newDoc.TZRalations = null;
                foreach (var d in oldDoc.DispatchLists)
                {
                    newDoc.DispatchLists.Add(d);
                }

                //原调度关系清空
                oldDoc.DispatchLists.Clear();
                //原运输单是否作废
                oldDoc.IsEffective = !isTrashOrigin;

                //记录作废原因
                if (oldDoc.IsEffective)
                {
                    oldDoc.Remark = (string.IsNullOrEmpty(oldDoc.Remark) ? "" : oldDoc.Remark + " ") + "CODEADD整车转发";
                }
                else
                {
                    oldDoc.Remark = (string.IsNullOrEmpty(oldDoc.Remark) ? "" : oldDoc.Remark + " ") + "CODEADD整车转发作废";
                }

                //退转料记录
                TZRalation tzRelation = new TZRalation
                {
                    SourceShipDocID = oldDoc.ID,
                    SourceCube      = oldDoc.ParCube,
                    CarID           = oldDoc.CarID,
                    Driver          = oldDoc.Driver,
                    Cube            = oldDoc.ParCube,
                    ReturnType      = ZLERP.Model.Enums.ReturnType.Forward,
                    ActionType      = ZLERP.Model.Enums.ActionType.Transfer,
                    IsCompleted     = true,
                    ReturnReason    = returnReason
                };
                //UNDONE:目标任务单是否要更新已供和累计方量
                using (IGenericTransaction tx = this.m_UnitOfWork.BeginTransaction())
                {
                    try
                    {
                        oldDoc.IsProduce = false;
                        shipDocRepo.Update(oldDoc, null);
                        //this.m_UnitOfWork.Flush();
                        shipDocRepo.Add(newDoc);
                        // this.m_UnitOfWork.Flush();
                        tzRelation.TargetShipDocID = newDoc.ID;
                        //整车转发时,生产记录自动转
                        List <ProductRecord> prList = this.m_UnitOfWork.GetRepositoryBase <ProductRecord>().Query()
                                                      .Where(m => m.ShipDocID == oldDoc.ID)
                                                      .ToList();
                        foreach (ProductRecord pr in prList)
                        {
                            pr.ShipDocID = newDoc.ID;
                            this.m_UnitOfWork.GetRepositoryBase <ProductRecord>().Update(pr, null);
                        }
                        DateTime ts = DateTime.Now;
                        tzRelation.ActionTime = ts;
                        tzRelation.ActionCube = tzRelation.Cube;

                        //整车转发状态设置为3
                        tzRelation.IsLock = "3";
                        //转退料单号
                        tzRelation.TzRalationFlag = getZtlDh() + "ZC";

                        base.Add(tzRelation);
                        tx.Commit();
                        return(newDoc);
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        tx.Rollback();
                        logger.Error(ex.Message, ex);
                    }
                }
            }
            return(null);
        }