分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-30 01a80700ea03a332785fb8cbd16aecaf7cce2ccb
´úÂë¹ÜÀí/WMS/WMS_Server/WIDESEA_WMS/ToMes/agvTransferList.cs
@@ -1,17 +1,23 @@
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Xml.Linq;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.MES_Info;
using WIDESEA_Comm.MES_Info.Request;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.ManageUser;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.Mes;
using WIDESEA_WMS.Common;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static WIDESEA_Comm.MES_Info.BasicSN;
namespace WIDESEA_WMS
@@ -27,24 +33,32 @@
        {
            WebResponseContent content = new WebResponseContent();
            string postJson = "";
            string mesData = "";
            try
            {
                string sn = saveModel.MainData["sn"].ToString();
                string user = saveModel.MainData["creator"].ToString();
                return content.Error($"{user}无操作权限!");
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(Context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
                //return content.Error($"{user}无操作权限!");
                //工单号生成
                string jobID = "TW" + DateTime.Now.ToString("HH-mm-ss-ff");
                //根据库存查询车轮信息
                dt_inventory inventory = freeDB.Select<dt_inventory>().Where(x => x.SN.Contains(sn)).First();
                dt_inventory inventory = inventoryRepository.Find(x => x.SN.Contains(sn)).FirstOrDefault();
                if (inventory == null)
                {
                    return content.Error($"无此车轮{sn}SN号,请核查库存记录!");
                }
                var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
                //if (!station.enable) return content.Error($"库位{station.stationCode}未启用,请核实!");
                if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode || x.agv_toaddress == station.stationCode).Any())
                    return content.Error($"库位{station.stationCode}存在AGV任务,请核实!");
                List<detail> list = new List<detail>(); //车轮信息
                foreach (var item in inventory.SN.Split(","))
                foreach (var item in station.bindSN.Split(","))
                {
                    detail detail = new detail();
                    detail.sn = item;
@@ -54,29 +68,58 @@
                agvTransferListPara listPara = new agvTransferListPara
                {
                    details = list,
                    transferListID = jobID,
                    transferListID = jobID,// station.Number,
                    toWarehouse = "毛轮库",
                    fromWarehouse = "AGV库",
                    updateTime = DateTime.Now.ToString(),
                    drawingNoVer = "",
                    materialCode = "",
                    drawingNoVer = inventory.drawingNoVer,
                    materialCode = inventory.materialCode,
                    Operator = user == null ? "admin" : user
                };
                var postJson = JsonConvert.SerializeObject(listPara);
                string mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvTransferList");
                postJson = JsonConvert.SerializeObject(listPara);
                mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvTransferList");
                if (mesData.Contains("连接尝试失败"))
                    throw new Exception(mesData);
                var requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData);
                if (requestMes.code == "200" && requestMes.Type == "success")
                {
                    return content.OK("移库交接成功!");
                    dt_agvtask agvtask = new dt_agvtask()
                    {
                        agv_fromaddress = station.stationCode,
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                        agv_grade = 0,
                        agv_createtime = DateTime.Now,
                        agv_taskstate = "Queue",
                        agv_materielid = station.stationType,
                        agv_qty = station.quantity,
                        agv_tasktype = "TaskType_OutsourceCarry",
                        agv_toaddress = "",
                        agv_userid = user,//"系统",
                        jobID = jobID,// mes_head.jobID,
                        bindSN = station.bindSN,
                        agv_worktype = 101, //Convert.ToInt32(mes_head.processCode),
                        agv_materbarcode = inventory.materialCode,
                        agv_Traytype = station.tray_type,
                        agv_TrayStatus = station.tray_status
                    };
                    agvtaskRepository.Add(agvtask, true);
                    station.location_state = LocationStateEnum.OutBusy.ToString();
                    stationinfoRepository.Update(station, true);
                    content.OK("下发移库外协成功!");
                    //日志记录上传数据成功
                    WriteWMSLog.LogAdd("", "成功", "MES", "WMS", postJson, mesData, "AB库移库外协", "agvTransferList", requestMes.message);
                }
                else
                    throw new Exception(requestMes.message);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
                WriteWMSLog.LogAdd("", "失败", "MES", "WMS", postJson, mesData, "AB库移库外协", "agvTransferList", ex.Message);
            }
            return content;
        }