public TableData MaterialConfirmApp(int id, string containercode, string stockplace)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                TableData tab = new TableData();
                tab.code = 200;
                try
                {
                    MaterialDistributeTaskHeader materialDistributeTaskHeader = _unitWork.Find <MaterialDistributeTaskHeader>(u => u.Id == id).FirstOrDefault();
                    materialDistributeTaskHeader.StartPlace      = stockplace;
                    materialDistributeTaskHeader.ContainerCode   = containercode;
                    materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.已确认;
                    _app.Update(materialDistributeTaskHeader);
                    tab.msg = "备料信息确认成功!";

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    tab.code = 300;
                    tab.msg += ex.Message;
                }
                return(tab);
            }
        }
        public TableData Query(MaterialDistributeTaskHeader entity)
        {
            var result = new TableData();
            var data   = _app.Find(EntityToExpression <MaterialDistributeTaskHeader> .GetExpressions(entity));

            GetData(data, result);
            result.count = data.Count();

            return(result);
        }
Exemplo n.º 3
0
        public Response StockConfirmApp(MaterialDemandConfirmModel mdConfirmList)
        {
            Response Response  = new Response();
            string   sErrorMsg = "";

            //if (!CheckLogin())
            //{
            //    Response.Code = 500;
            //    Response.Status = false;
            //    Response.Message = "请先登录!";
            //    return Response;
            //}
            foreach (MaterialDemandConfirm mdConfirm in mdConfirmList.Data)
            {
                try
                {
                    MaterialDemand materialDemand = _unitWork.FindSingle <MaterialDemand>(u => u.Id.Equals(mdConfirm.Id));
                    if (materialDemand != null)
                    {
                        materialDemand.DistributeQty = mdConfirm.DistributeQty;
                        materialDemand.UpdateBy      = "ConfirmAPI";
                        materialDemand.UpdateTime    = DateTime.Now;
                        _unitWork.Update(materialDemand);
                    }
                    MaterialDistributeTaskDetail materialDistributeTaskDetail = _unitWork.FindSingle <MaterialDistributeTaskDetail>(u => u.OrderCode == mdConfirm.OrderCode && u.MaterialCode == mdConfirm.MaterialCode);
                    if (materialDistributeTaskDetail != null)
                    {
                        materialDistributeTaskDetail.Qty           = mdConfirm.DistributeQty;
                        materialDistributeTaskDetail.ContainerCode = mdConfirm.ContainerCode;
                        materialDistributeTaskDetail.UpdateBy      = "ConfirmAPI";
                        materialDistributeTaskDetail.UpdateTime    = DateTime.Now;
                        _unitWork.Update(materialDistributeTaskDetail);

                        MaterialDistributeTaskHeader materialDistributeTaskHeader = _unitWork.FindSingle <MaterialDistributeTaskHeader>(u => u.Id == materialDistributeTaskDetail.MaterialDistributeTaskHeaderId);
                        if (materialDistributeTaskHeader.MaterialConfirm != MaterialConfirm.已确认)
                        {
                            materialDistributeTaskHeader.ContainerCode   = mdConfirm.ContainerCode;
                            materialDistributeTaskHeader.StartPlace      = mdConfirm.ContainerPlace;
                            materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.已确认;
                            materialDistributeTaskHeader.UpdateBy        = "ConfirmAPI";
                            materialDistributeTaskHeader.UpdateTime      = DateTime.Now;
                            _unitWork.Update(materialDistributeTaskHeader);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Code    = 500;
                    Response.Status  = false;
                    Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "OrderCode:" + mdConfirm.OrderCode + "确认失败!" + ex.Message;
                }
            }
            return(Response);
        }
Exemplo n.º 4
0
 public string Upd(MaterialDistributeTaskHeader Table_entity)
 {
     try
     {
         _app.Upd(Table_entity);
     }
     catch (Exception ex)
     {
         Result.Status  = false;
         Result.Message = ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
Exemplo n.º 5
0
        public string GetTemplate()
        {
            var result = new TableData();
            List <MaterialDistributeTaskHeader> listMaterialDistributeTaskHeader = new List <MaterialDistributeTaskHeader>();
            MaterialDistributeTaskHeader        entity = _app.FindSingle(u => u.Id > 0);

            if (entity != null)
            {
                listMaterialDistributeTaskHeader.Add(entity);
            }
            else
            {
                listMaterialDistributeTaskHeader.Add(new MaterialDistributeTaskHeader());
            }

            result.data  = listMaterialDistributeTaskHeader;
            result.count = listMaterialDistributeTaskHeader.Count;

            return(JsonHelper.Instance.Serialize(result));
        }
        public Response ImportIn(IFormFile excelfile)
        {
            Response result = new Infrastructure.Response();
            List <MaterialDistributeTaskHeader> exp = imp.ConvertToModel <MaterialDistributeTaskHeader>(excelfile);
            string sErrorMsg = "";

            for (int i = 0; i < exp.Count; i++)
            {
                try
                {
                    MaterialDistributeTaskHeader e = exp[i];
                    e.Id = null;
                    _app.Add(e);
                }
                catch (Exception ex)
                {
                    sErrorMsg     += "第" + (i + 2) + "行:" + ex.Message + "<br>";
                    result.Message = sErrorMsg;
                    break;
                }
            }
            if (sErrorMsg.Equals(string.Empty))
            {
                if (exp.Count == 0)
                {
                    sErrorMsg     += "没有发现有效数据, 请确定模板是否正确, 或是否有填充数据!";
                    result.Message = sErrorMsg;
                }
                else
                {
                    result.Message = "导入完成";
                }
            }
            else
            {
                result.Status  = false;
                result.Message = result.Message;
            }
            return(result);
        }
Exemplo n.º 7
0
        public TableData CreateDistributeTaskApp(List <MaterialCallHeader> mcheaderlist)
        {
            TableData tab = new TableData
            {
                code = 200
            };
            int      hcount    = 0;
            int      listcount = 0;
            string   sErrorMsg = "";
            Location location  = null;

            try
            {
                listcount = mcheaderlist.Count;
                foreach (MaterialCallHeader materialCallHeader in mcheaderlist)
                {
                    MaterialDistributeTaskHeader materialDistributeTaskHeader = new MaterialDistributeTaskHeader();
                    List <MaterialCallDetail>    materialCallDetails          = _unitWork.Find <MaterialCallDetail>(u => u.CallHeaderId.Equals(materialCallHeader.Id)).ToList();
                    if (!_unitWork.IsExist <MaterialDistributeTaskHeader>(u => u.MaterialCallId.Equals(materialCallHeader.Id)))
                    {
                        //生成配送主数据
                        // MaterialDistributeTaskHeader materialDistributeTaskHeader = new MaterialDistributeTaskHeader();
                        var pcode = _unitWork.Find <MaterialCallDetail>(u => u.CallHeaderId == materialCallHeader.Id).Select(a => a.ProductCode).FirstOrDefault();
                        var pid   = _unitWork.Find <ProductHeader>(u => u.Code == pcode).Select(a => a.Id).FirstOrDefault();
                        location = _unitWork.Find <Location>(u => u.Code == materialCallHeader.LocationCode).FirstOrDefault();
                        materialDistributeTaskHeader.MaterialCallId = materialCallHeader.Id;
                        materialDistributeTaskHeader.ProductId      = pid;
                        materialDistributeTaskHeader.ProductCode    = pcode;
                        materialDistributeTaskHeader.NeedStation    = materialCallHeader.NeedStation;
                        materialDistributeTaskHeader.LocationCode   = materialCallHeader.LocationCode;
                        materialDistributeTaskHeader.ContainerType  = location.Type;
                        if (!string.IsNullOrEmpty(location.ContainerCode))
                        {
                            materialDistributeTaskHeader.ContainerCode = location.ContainerCode;
                        }
                        materialDistributeTaskHeader.NeedTime = materialCallHeader.CallTime;
                        materialDistributeTaskHeader.Status   = 1;
                        materialDistributeTaskHeader.UserCode = _app._loginInfo.Account;
                        if (materialCallHeader.CallType == CallType.料)
                        {
                            if (location.Status == LocationStatus.空仓位)
                            {//第一次上料
                                materialDistributeTaskHeader.TaskNo   = _app.GetTaskNo(AGVTaskNo.工位叫料);
                                materialDistributeTaskHeader.CallType = TaskType.料配送;
                                materialDistributeTaskHeader.EndPlace = materialCallHeader.LocationCode;
                                if (string.IsNullOrEmpty(pcode))
                                {
                                    materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.已确认;
                                }
                                else
                                {
                                    materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.未确认;
                                }
                                _appmh.Add(materialDistributeTaskHeader);
                            }
                            else
                            {
                                //先生成取空料框任务
                                MaterialDistributeTaskHeader mt = new MaterialDistributeTaskHeader();
                                materialDistributeTaskHeader.CopyTo(mt);
                                mt.Id              = null;
                                mt.TaskNo          = _app.GetTaskNo(AGVTaskNo.取空料框);
                                mt.CallType        = TaskType.回收料框;
                                mt.StartPlace      = materialCallHeader.LocationCode;
                                mt.MaterialConfirm = MaterialConfirm.已确认;
                                _appmh.Add(mt);
                                //再成上料任务
                                materialDistributeTaskHeader.TaskNo        = _app.GetTaskNo(AGVTaskNo.工位叫料);
                                materialDistributeTaskHeader.CallType      = TaskType.料配送;
                                materialDistributeTaskHeader.StartPlace    = "";
                                materialDistributeTaskHeader.ContainerCode = "";
                                materialDistributeTaskHeader.EndPlace      = materialCallHeader.LocationCode;
                                if (string.IsNullOrEmpty(pcode))
                                {
                                    materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.已确认;
                                }
                                else
                                {
                                    materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.未确认;
                                }
                                _appmh.Add(materialDistributeTaskHeader);
                            }
                            //只有呼叫类型是上料任务时,才有呼叫明细数据,其它呼叫类型无需写入任务配送明细表
                            if (materialCallDetails.Count > 0)
                            {
                                foreach (MaterialCallDetail mcdetail in materialCallDetails)
                                {
                                    List <MaterialDemand> materialDemands = _unitWork.Find <MaterialDemand>(u => u.OrderCode == mcdetail.OrderCode).ToList();
                                    //判断此工单的物料需求是否生成
                                    if (materialDemands.Count > 0)
                                    {
                                        //判断此工单的物料配送任务是否已经建立
                                        //if (!_unitWork.IsExist<MaterialDistributeTaskDetail>(u => u.OrderCode == mcdetail.OrderCode))
                                        //{
                                        //生成配送明细数据
                                        foreach (MaterialDemand md in materialDemands)
                                        {
                                            if (md.ClassABC == location.Type)
                                            {
                                                MaterialDistributeTaskDetail materialDistributeTaskDetail = new MaterialDistributeTaskDetail();
                                                materialDistributeTaskDetail.MaterialDistributeTaskHeaderId = materialDistributeTaskHeader.Id;
                                                materialDistributeTaskDetail.OrderCode    = md.OrderCode;
                                                materialDistributeTaskDetail.MaterialCode = md.MaterialCode;
                                                materialDistributeTaskDetail.SerialNumber = mcdetail.SerialNumber;
                                                materialDistributeTaskDetail.Qty          = md.DistributeQty;
                                                materialDistributeTaskDetail.UserCode     = _app._loginInfo.Account;
                                                _appmd.Add(materialDistributeTaskDetail);
                                            }
                                        }
                                        hcount = hcount + 1;
                                        //}
                                        //else
                                        //{
                                        //    sErrorMsg += "工单号为:" + mcdetail.OrderCode + "的配送任务已经建立过,不可重复建立!<br>";
                                        //    tab.msg = sErrorMsg;
                                        //}
                                    }
                                    else
                                    {
                                        sErrorMsg += "工单号为:" + mcdetail.OrderCode + "未建立工单对应的物料需求,无法生成!<br>";
                                        tab.msg    = sErrorMsg;
                                    }
                                }
                            }
                        }
                        else if (materialCallHeader.CallType == CallType.料)
                        {
                            if (location.Status == LocationStatus.空仓位)
                            {//第一次下料,即只补空料框
                                materialDistributeTaskHeader.TaskNo          = _app.GetTaskNo(AGVTaskNo.补给空框);
                                materialDistributeTaskHeader.CallType        = TaskType.补给料框;
                                materialDistributeTaskHeader.EndPlace        = materialCallHeader.LocationCode;
                                materialDistributeTaskHeader.MaterialConfirm = MaterialConfirm.已确认;
                                _appmh.Add(materialDistributeTaskHeader);
                            }
                            else
                            {//先生成下料任务
                                materialDistributeTaskHeader.TaskNo     = _app.GetTaskNo(AGVTaskNo.成品下料);
                                materialDistributeTaskHeader.CallType   = TaskType.料取件;
                                materialDistributeTaskHeader.StartPlace = materialCallHeader.LocationCode;
                                _appmh.Add(materialDistributeTaskHeader);
                                //再生成补空料框任务
                                MaterialDistributeTaskHeader mtbk = new MaterialDistributeTaskHeader();
                                materialDistributeTaskHeader.CopyTo(mtbk);
                                mtbk.Id              = null;
                                mtbk.TaskNo          = _app.GetTaskNo(AGVTaskNo.补给空框);
                                mtbk.CallType        = TaskType.补给料框;
                                mtbk.ContainerCode   = "";
                                mtbk.StartPlace      = "";
                                mtbk.EndPlace        = materialCallHeader.LocationCode;
                                mtbk.MaterialConfirm = MaterialConfirm.已确认;
                                _appmh.Add(mtbk);
                            }
                        }
                    }
                }

                if (listcount <= hcount)
                {
                    tab.code = 200;
                    tab.msg  = "配送任务已成功生成!";
                }
                else
                {
                    tab.code = 200;
                    tab.msg  = "执行完成!部分生成失败的信息如下:<br>" + tab.msg;
                }
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg += ex.Message;
            }
            return(tab);
        }
Exemplo n.º 8
0
 public string Load(PageReq pageRequest, MaterialDistributeTaskHeader entity)
 {
     return(JsonHelper.Instance.Serialize(_app.Load(pageRequest, entity)));
 }
Exemplo n.º 9
0
 public string Export(MaterialDistributeTaskHeader entity)
 {
     return(JsonHelper.Instance.Serialize(_app.ExportData(entity)));
 }
        public void Upd(MaterialDistributeTaskHeader entity)
        {
            if (entity.Status == AGVTaskState.配送完成 || entity.Status == AGVTaskState.放料车完成)
            {
                //同步更新物料呼叫状态为完成
                MaterialCallHeader materialCallHeader = _unitWork.FindSingle <MaterialCallHeader>(u => u.Id.Equals(entity.MaterialCallId));
                materialCallHeader.Status     = CallStatus.完成;
                materialCallHeader.UpdateTime = DateTime.Now;
                materialCallHeader.UpdateBy   = _app._loginInfo.Account;
                _unitWork.Update(materialCallHeader);
                if (entity.Status == AGVTaskState.配送完成)
                {
                    List <MaterialCallDetail> materialCallDetail = _unitWork.Find <MaterialCallDetail>(u => u.CallHeaderId.Equals(materialCallHeader.Id)).ToList();
                    foreach (MaterialCallDetail mcdetail in materialCallDetail)
                    {
                        //同步更新物料需求状态
                        List <MaterialDemand> materialDemands = _unitWork.Find <MaterialDemand>(u => u.OrderCode.Equals(mcdetail.OrderCode) && u.ProductCode == mcdetail.ProductCode).ToList();
                        foreach (MaterialDemand md in materialDemands)
                        {
                            md.Status     = CallStatus.完成;
                            md.UpdateTime = DateTime.Now;
                            md.UpdateBy   = _app._loginInfo.Account;
                            _unitWork.Update(md);
                        }
                    }
                }

                //更新缓存区位置存放的料框编号和状态
                Location location = _unitWork.Find <Location>(u => u.Code == entity.LocationCode).FirstOrDefault();
                location.UpdateTime    = DateTime.Now;
                location.UpdateBy      = _app._loginInfo.Account;
                location.ContainerCode = entity.ContainerCode;
                location.Status        = LocationStatus.货;
                _unitWork.Update(location);

                //容器
                Container container = _unitWork.Find <Container>(u => u.Code == entity.ContainerCode).FirstOrDefault();
                container.UpdateTime   = DateTime.Now;
                container.UpdateBy     = _app._loginInfo.Account;
                container.LocationCode = entity.LocationCode;
                container.Status       = ContainerStatus.;
                _unitWork.Update(container);
            }
            if (entity.Status == AGVTaskState.回收料框完成 || entity.Status == AGVTaskState.取工件完成)
            {
                //更新缓存区位置存放的料框编号和状态
                Location location = _unitWork.Find <Location>(u => u.Code == entity.LocationCode).FirstOrDefault();
                location.UpdateTime    = DateTime.Now;
                location.UpdateBy      = _app._loginInfo.Account;
                location.ContainerCode = "";
                location.Status        = LocationStatus.空仓位;
                _unitWork.Update(location);

                //容器
                Container container = _unitWork.Find <Container>(u => u.Code == entity.ContainerCode).FirstOrDefault();
                container.UpdateTime   = DateTime.Now;
                container.UpdateBy     = _app._loginInfo.Account;
                container.LocationCode = "";
                container.Status       = ContainerStatus.空;
                _unitWork.Update(container);
            }
            entity.Status = AGVTaskState.任务完成;
            _app.Update(entity);
        }
 public void Ins(MaterialDistributeTaskHeader entity)
 {
     _app.Add(entity);
 }
 public TableData Load(PageReq pageRequest, MaterialDistributeTaskHeader entity)
 {
     return(_app.Load(pageRequest, entity));
 }
        public TableData SendAGVTaskApp(List <MaterialDistributeTaskHeader> mhlist, string url)
        {
            TableData tab = new TableData
            {
                code = 200
            };
            int    hcount    = 0;
            int    listcount = 0;
            string sErrorMsg = "";

            listcount = mhlist.Count;
            dynamic temp = new ExpandoObject();

            try
            {
                HttpHelper httpHelper = new HttpHelper(url);
                //if (string.IsNullOrEmpty(httpHelper.GetCookie("Token", cookies)))
                if (cookies.Count == 0)
                {
                    string loginjson = "{\"username\":\"System\",\"password\":\"Aa123456\"}";
                    string result    = httpHelper.HttpPostLogin("http://localhost:23512/api/Login/Login", loginjson, cookies);
                    //登录接口有返回TOKEN码,直接把token写入cookie
                    JObject jresult = JObject.Parse(result);
                    if (jresult["code"].ToString() == "200")
                    {
                        Cookie cookie1 = new Cookie("Token", jresult["token"].ToString());
                        cookie1.Expires = DateTime.Now.AddDays(100);
                        cookie1.Domain  = "localhost";
                        cookies.Add(cookie1);
                    }
                    //----适用于直接从登录接口回应头中解析读取Token码或解析loginjson = "{\"username\":\"System\",\"password\":\"Aa123456\"}"直接把账号密码写入cookie进行认证
                    //JObject jresult = JObject.Parse(result);
                    //if (!string.IsNullOrEmpty(result))
                    //{
                    //    foreach (string s in result.Split(';'))
                    //    {
                    //        string name = s.Split('=')[0].Trim();
                    //        string value = s.Contains("=") ? s.Split('=')[1].Trim() : "";
                    //        Cookie cookie1 = new Cookie(name, value);
                    //        cookie1.Domain = "localhost";
                    //        cookies.Add(cookie1);
                    //    }
                    //}
                    //--------end-------
                }

                foreach (MaterialDistributeTaskHeader mdth in mhlist)
                {
                    if (mdth.Status == 1)
                    {
                        //temp.postmodel = new List<dynamic>();
                        //temp.postmodel.Add(new
                        //{
                        //    OrderCode = mdth.OrderCode,
                        //    SerialNumber = "",
                        //    CarNo = "",
                        //    ContainerCode = "",
                        //    Status = "",
                        //});
                        TaskNodeModel tm = new TaskNodeModel();
                        tm.TaskNo = mdth.TaskNo;
                        var pdata        = JsonHelper.Instance.Serialize(tm);
                        var responsedata = httpHelper.HttpPost(url, pdata, cookies);
                        // var responsedata = httpHelper.Post(tm, url);
                        JObject jo = JObject.Parse(responsedata);
                        JObject jr = JObject.Parse(jo["Result"].ToString());
                        if (jo["Code"].ToString() == "200")
                        {
                            //获取上料工位的缓存位置是否有料框
                            //string emptyc = _unitWork.Find<Location>(u => u.Code == mdth.LocationCode).Select(a => a.ContainerCode).FirstOrDefault();
                            MaterialDistributeTaskHeader materialDistributeTaskHeader = _unitWork.Find <MaterialDistributeTaskHeader>(u => u.TaskNo == mdth.TaskNo).FirstOrDefault();
                            materialDistributeTaskHeader.Status = AGVTaskState.任务下发;
                            //如果缓存位有空料框,任务状态为先拉空料框,否则任务为直接配送物料
                            //if (string.IsNullOrEmpty(emptyc))
                            //{
                            //    materialDistributeTaskHeader.Status = 50;
                            //}
                            //else
                            //{
                            //    materialDistributeTaskHeader.Status = 10;
                            //}
                            materialDistributeTaskHeader.CarNo         = jr["CarNo"].ToString();
                            materialDistributeTaskHeader.ContainerCode = jr["ContainerCode"].ToString();
                            _app.Update(materialDistributeTaskHeader);
                            hcount = hcount + 1;
                            List <MaterialDistributeTaskDetail> materialDistributeTaskDetails = _unitWork.Find <MaterialDistributeTaskDetail>(u => u.MaterialDistributeTaskHeaderId.Equals(materialDistributeTaskHeader.Id)).ToList();
                            foreach (MaterialDistributeTaskDetail mdtDetail in materialDistributeTaskDetails)
                            {
                                mdtDetail.ContainerCode = jr["ContainerCode"].ToString();
                                _appd.Update(mdtDetail);
                            }
                        }
                        else
                        {
                            sErrorMsg += "任务号为:" + mdth.TaskNo + "接口下发失败,错误信息:" + jo["Message"].ToString() + "<br>";
                            tab.msg    = sErrorMsg;
                        }
                    }
                    else
                    {
                        sErrorMsg += "任务号为:" + mdth.TaskNo + "接口下发失败,错误信息:此任务状态不在可下发状态!<br>";
                        tab.msg    = sErrorMsg;
                    }
                }

                if (listcount == hcount)
                {
                    tab.code = 200;
                    tab.msg  = "任务全部成功下发!";
                }
                else
                {
                    tab.code = 200;
                    tab.msg  = "下发执行完成!部分下发失败的信息如下:<br>" + tab.msg;
                }
            }
            catch (Exception ex)
            {
                tab.code = 300;
                tab.msg += ex.Message;
            }
            return(tab);
        }
 public TableData ExportData(MaterialDistributeTaskHeader entity)
 {
     return(_app.ExportData(entity));
 }
Exemplo n.º 15
0
        public Response AGVTaskNodeApp(TaskNodeModel taskNodeModel)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                Response <TaskNodeModel> Response = new Response <TaskNodeModel>();
                string    sErrorMsg = "";
                Location  location  = null;
                Container container = null;
                if (!CheckLogin())
                {
                    Response.Code    = 500;
                    Response.Status  = false;
                    Response.Message = "请先登录!";
                    return(Response);
                }

                try
                {
                    MaterialDistributeTaskHeader materialDistributeTaskHeader = _unitWork.FindSingle <MaterialDistributeTaskHeader>(u => u.TaskNo.Equals(taskNodeModel.TaskNo));
                    if (materialDistributeTaskHeader == null)
                    {
                        sErrorMsg       += "任务号为:" + taskNodeModel.TaskNo + "不存在,请确认<br>";
                        Response.Message = sErrorMsg;
                    }
                    else
                    {
                        MaterialCallHeader        materialCallHeader = _unitWork.FindSingle <MaterialCallHeader>(u => u.Id.Equals(materialDistributeTaskHeader.MaterialCallId));
                        List <MaterialCallDetail> materialCallDetail = _unitWork.Find <MaterialCallDetail>(u => u.CallHeaderId.Equals(materialCallHeader.Id)).ToList();
                        //更新配送状态
                        if (materialDistributeTaskHeader.Status < AGVTaskState.任务完成)
                        {
                            if (taskNodeModel.Status == AGVTaskState.配送完成 || taskNodeModel.Status == AGVTaskState.放料车完成)
                            {
                                //更新配送任务头表状态为完成
                                materialDistributeTaskHeader.Status = AGVTaskState.任务完成;
                                //同步更新物料呼叫状态为完成
                                materialCallHeader.Status     = CallStatus.完成;
                                materialCallHeader.UpdateTime = DateTime.Now;
                                materialCallHeader.UpdateBy   = "AGVapi";
                                _unitWork.Update(materialCallHeader);

                                if (materialCallDetail.Count > 0)
                                {
                                    foreach (MaterialCallDetail mcdetail in materialCallDetail)
                                    {
                                        //同步更新物料需求状态
                                        List <MaterialDemand> materialDemands = _unitWork.Find <MaterialDemand>(u => u.OrderCode.Equals(mcdetail.OrderCode) && u.ProductCode == mcdetail.ProductCode).ToList();
                                        foreach (MaterialDemand md in materialDemands)
                                        {
                                            md.Status     = CallStatus.完成;
                                            md.UpdateTime = DateTime.Now;
                                            md.UpdateBy   = "AGVapi";
                                            _unitWork.Update(md);
                                        }
                                    }
                                }

                                //上料缓存区域
                                if (_unitWork.IsExist <Location>(u => u.Code == materialDistributeTaskHeader.LocationCode))
                                {
                                    //更新缓存区位置存放的料框编号和状态
                                    location               = _unitWork.Find <Location>(u => u.Code == materialDistributeTaskHeader.LocationCode).FirstOrDefault();
                                    location.UpdateTime    = DateTime.Now;
                                    location.UpdateBy      = "AGVapi";
                                    location.ContainerCode = materialDistributeTaskHeader.ContainerCode;
                                    location.Status        = LocationStatus.货;
                                    _unitWork.Update(location);
                                }
                                else
                                {
                                    throw new Exception("缓存位置为:" + materialDistributeTaskHeader.LocationCode + "不存在,请先建立!");
                                }

                                //容器
                                if (_unitWork.IsExist <Container>(u => u.Code == materialDistributeTaskHeader.ContainerCode))
                                {
                                    container              = _unitWork.Find <Container>(u => u.Code == materialDistributeTaskHeader.ContainerCode).FirstOrDefault();
                                    container.UpdateTime   = DateTime.Now;
                                    container.UpdateBy     = "AGVapi";
                                    container.LocationCode = materialDistributeTaskHeader.LocationCode;
                                    container.Status       = ContainerStatus.;
                                    _unitWork.Update(container);
                                }
                                else
                                {
                                    throw new Exception("料框为:" + materialDistributeTaskHeader.ContainerCode + "不存在,请先建立!");
                                }
                            }
                            else if (taskNodeModel.Status == AGVTaskState.回收料框完成 || taskNodeModel.Status == AGVTaskState.取工件完成)
                            {
                                //更新缓存区位置存放的料框编号和状态
                                materialDistributeTaskHeader.Status = AGVTaskState.任务完成;
                                if (_unitWork.IsExist <Location>(u => u.Code == materialDistributeTaskHeader.LocationCode))
                                {
                                    //更新缓存区位置存放的料框编号和状态
                                    location               = _unitWork.Find <Location>(u => u.Code == materialDistributeTaskHeader.LocationCode).FirstOrDefault();
                                    location.UpdateTime    = DateTime.Now;
                                    location.UpdateBy      = "AGVapi";
                                    location.ContainerCode = "";
                                    location.Status        = LocationStatus.空仓位;
                                    _unitWork.Update(location);
                                }
                                else
                                {
                                    throw new Exception("缓存位置为:" + materialDistributeTaskHeader.LocationCode + "不存在,请先建立!");
                                }


                                //容器
                                if (_unitWork.IsExist <Container>(u => u.Code == materialDistributeTaskHeader.ContainerCode))
                                {
                                    container              = _unitWork.Find <Container>(u => u.Code == materialDistributeTaskHeader.ContainerCode).FirstOrDefault();
                                    container.UpdateTime   = DateTime.Now;
                                    container.UpdateBy     = "AGVapi";
                                    container.LocationCode = "";
                                    container.Status       = ContainerStatus.空;
                                    _unitWork.Update(container);
                                }
                                else
                                {
                                    throw new Exception("料框为:" + materialDistributeTaskHeader.ContainerCode + "不存在,请先建立!");
                                }
                            }
                            else if (taskNodeModel.Status == AGVTaskState.回收料框开始 || taskNodeModel.Status == AGVTaskState.取工件开始 || taskNodeModel.Status == AGVTaskState.放料车开始)
                            {
                                //更新配送任务头表的小车编号和料框编号
                                // materialDistributeTaskHeader.Status = AGVTaskState.回收料框开始;
                                materialDistributeTaskHeader.Status = taskNodeModel.Status;
                                if (taskNodeModel.Status == AGVTaskState.放料车开始)
                                {
                                    materialDistributeTaskHeader.ContainerCode = taskNodeModel.ContainerCode;
                                }
                                materialDistributeTaskHeader.CarNo = taskNodeModel.CarNo;
                                //同步更新物料呼叫状态
                                materialCallHeader.Status     = CallStatus.执行;
                                materialCallHeader.UpdateTime = DateTime.Now;
                                materialCallHeader.UpdateBy   = "AGVapi";
                                _unitWork.UpdateByTracking(materialCallHeader);
                            }
                            else if (taskNodeModel.Status == AGVTaskState.配送开始)
                            {
                                //更新配送任务头表的小车编号和料框编号
                                materialDistributeTaskHeader.Status        = AGVTaskState.配送开始;
                                materialDistributeTaskHeader.CarNo         = taskNodeModel.CarNo;
                                materialDistributeTaskHeader.ContainerCode = taskNodeModel.ContainerCode;
                                List <MaterialDistributeTaskDetail> materialDistributeTaskDetails = _unitWork.Find <MaterialDistributeTaskDetail>(u => u.MaterialDistributeTaskHeaderId.Equals(materialDistributeTaskHeader.Id)).ToList();
                                //更新配送明细
                                foreach (MaterialDistributeTaskDetail mdtdetail in materialDistributeTaskDetails)
                                {
                                    mdtdetail.ContainerCode = taskNodeModel.ContainerCode;
                                    mdtdetail.UpdateTime    = DateTime.Now;
                                    mdtdetail.UpdateBy      = "AGVapi";
                                    _unitWork.Update(mdtdetail);
                                }

                                //同步更新物料呼叫状态为完成
                                materialCallHeader.Status     = CallStatus.执行;
                                materialCallHeader.UpdateTime = DateTime.Now;
                                materialCallHeader.UpdateBy   = "AGVapi";
                                _unitWork.UpdateByTracking(materialCallHeader);


                                foreach (MaterialCallDetail mcdetail in materialCallDetail)
                                {
                                    //同步更新物料需求状态
                                    List <MaterialDemand> materialDemands = _unitWork.Find <MaterialDemand>(u => u.OrderCode.Equals(mcdetail.OrderCode) && u.ProductCode == mcdetail.ProductCode).ToList();
                                    foreach (MaterialDemand md in materialDemands)
                                    {
                                        md.Status     = CallStatus.执行;
                                        md.UpdateTime = DateTime.Now;
                                        md.UpdateBy   = "AGVapi";
                                        _unitWork.UpdateByTracking(md);
                                    }
                                }
                            }
                            else
                            {
                                materialDistributeTaskHeader.Status = taskNodeModel.Status;
                            }
                            materialDistributeTaskHeader.UpdateTime = DateTime.Now;
                            materialDistributeTaskHeader.UpdateBy   = "AGVapi";
                            _unitWork.Update(materialDistributeTaskHeader);
                        }
                        else
                        {
                            sErrorMsg       += "任务号为:" + taskNodeModel.TaskNo + "任务已经结束,无法更新状态<br>";
                            Response.Message = sErrorMsg;
                        }
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Response.Code    = 500;
                    Response.Status  = false;
                    Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "TaskNo:" + taskNodeModel.TaskNo + "AGV反馈失败!" + ex.Message;
                }

                return(Response);
            }
        }