分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-10 639f5a744312de88aa27fbba2e7f27eb52287ed6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
{
    public partial class ToMesServer
    {
        /// <summary>
        /// PDA移库交接
        /// </summary>
        /// <param name="requestTemp"></param>
        /// <returns></returns>
        public WebResponseContent agvTransferList(SaveModel saveModel)
        {
 
            WebResponseContent content = new WebResponseContent();
            string postJson = "";
            string mesData = "";
            try
            {
                string sn = saveModel.MainData["sn"].ToString();
                string user = saveModel.MainData["creator"].ToString();
                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 = 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 station.bindSN.Split(","))
                {
                    detail detail = new detail();
                    detail.sn = item;
                    list.Add(detail);
                }
 
                agvTransferListPara listPara = new agvTransferListPara
                {
                    details = list,
                    transferListID = jobID,// station.Number,
                    toWarehouse = "毛轮库",
                    fromWarehouse = "AGV库",
                    updateTime = DateTime.Now.ToString(),
                    drawingNoVer = inventory.drawingNoVer,
                    materialCode = inventory.materialCode,
                    Operator = user == null ? "admin" : user
                };
 
                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")
                {
                    dt_agvtask agvtask = new dt_agvtask()
                    {
                        agv_fromaddress = station.stationCode,
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                        agv_grade = 1,
                        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;
        }
    }
}