| | |
| | | using WIDESEA_Comm.LogInfo; |
| | | using WIDESEA_Core.ManageUser; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using WIDESEA_Core.EFDbContext; |
| | | using WIDESEA_WMS.Repositories; |
| | | using System.Collections.Generic; |
| | | using System.Threading.Tasks; |
| | | using static WIDESEA_Comm.MES_Info.BasicSN; |
| | | using System.Collections; |
| | | using static FreeSql.Internal.GlobalFilter; |
| | | using WIDESEA_Comm.MES_Info.Request; |
| | | using System.Xml.Linq; |
| | | using Newtonsoft.Json; |
| | | using Confluent.Kafka; |
| | | using WIDESEA_WMS.Common; |
| | | using WIDESEA_Comm.MES_Info; |
| | | using System.Reflection; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | |
| | | namespace WIDESEA_WMS.Services |
| | | { |
| | |
| | | //base.Init(dbRepository); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ·»å åºå |
| | | /// </summary> |
| | | /// <param name="saveDataModel"></param> |
| | | /// <returns></returns> |
| | | public override WebResponseContent Add(SaveModel saveDataModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | VOLContext context = new VOLContext(); |
| | | IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | var stationCode = saveDataModel.MainData["stationCode"].ToString(); |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(stationCode)) throw new Exception($"ç¼åæ¶ç¼å·ä¸è½ä¸ºç©º!"); |
| | | if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"ç¼åæ¶ç±»åæè¯¯!"); |
| | | var station = stationinfoRepository.Find(x => x.stationCode == stationCode).FirstOrDefault(); |
| | | if (station == null) throw new Exception($"æªæ¾å°è´§ä½{stationCode}"); |
| | | var bindSNs = saveDataModel.MainData["SN"].ToString().Split(","); |
| | | var SNS = bindSNs.GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key); |
| | | foreach (var SN in SNS) |
| | | { |
| | | throw new Exception($"éå¤çSNå·{SN}"); |
| | | } |
| | | List<detail> list = new List<detail>(); |
| | | List<VV_Mes_Workinfo> workinfos = new List<VV_Mes_Workinfo>(); |
| | | foreach (var item in bindSNs) |
| | | { |
| | | var work = workinfoRepository.Find(x => x.SN == item && x.processCode == "17").FirstOrDefault(); |
| | | if (work == null) throw new Exception($"æªæ¾å°è½¦è½®SNå·ï¼{item}çå·¥åä¿¡æ¯ï¼"); |
| | | workinfos.Add(work); |
| | | detail detail = new detail(); |
| | | detail.sn = item; |
| | | list.Add(detail); |
| | | } |
| | | agvInWarehousePara outWarehousePara = new agvInWarehousePara() |
| | | { |
| | | //WorkOrder = task.jobID, |
| | | zoneID = stationCode, |
| | | //processCode = task.agv_worktype.ToString(), |
| | | details = list, |
| | | layerNo = 1, |
| | | stackID = "1", |
| | | warehouseName = "Agvåº", |
| | | Operator = UserContext.Current.UserName, |
| | | }; |
| | | var postJson = JsonConvert.SerializeObject(outWarehousePara); |
| | | var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvInWarehouse"); |
| | | if (mesData.Contains("è¿æ¥å°è¯å¤±è´¥")) throw new Exception(mesData); |
| | | MES_Response requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData); |
| | | |
| | | if (requestMes.code == "200" && requestMes.Type == "success") |
| | | { |
| | | //æ¥å¿è®°å½ä¸ä¼ æ°æ®æå |
| | | WriteWMSLog.LogAdd("", "æå", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮å
¥åº", "agvInWarehouse", requestMes.message); |
| | | foreach (var workinfo in workinfos) |
| | | { |
| | | dt_inventory inventory = new dt_inventory() |
| | | { |
| | | SN = workinfo.SN, |
| | | Name = workinfo.productName, |
| | | FigureNumber = workinfo.drawingNo, |
| | | materialCode = workinfo.materialCode, |
| | | HeatNumber = workinfo.heatID, |
| | | drawingNoVer = workinfo.drawingNoVer, |
| | | BilletNumber = workinfo.billetID, |
| | | OnlineTime = DateTime.Now, |
| | | Operator = "admin", |
| | | stationCode = stationCode, |
| | | area = station.area, |
| | | jobID = workinfo.jobID, |
| | | workOrder = workinfo.workOrder, |
| | | ID = Guid.NewGuid() |
| | | }; |
| | | _repository.Add(inventory, true); |
| | | } |
| | | WriteDBLog.Write($"æå¨æ·»å åºå ", $"è´§ä½ç¼å·ï¼{stationCode}ï¼SNå·ï¼{saveDataModel.MainData["SN"]}", LogState.Sucess, "WMS", UserContext.Current.UserName); |
| | | } |
| | | else |
| | | { |
| | | WriteWMSLog.LogAdd("", "失败", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮å
¥åº", "agvInWarehouse", requestMes.message); |
| | | throw new Exception("äººå·¥åæ¥MES车轮å
¥åºå¤±è´¥ï¼" + requestMes.message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Message = ex.Message; |
| | | WriteDBLog.Write($"æå¨æ·»å åºå ", new { éè¯¯ä¿¡æ¯ = ex.Message, æ°æ® = $"è´§ä½ç¼å·ï¼{stationCode}ï¼SNå·ï¼{saveDataModel.MainData["SN"]}" }, LogState.Error, "WMS", UserContext.Current.UserName); |
| | | } |
| | | return content; |
| | | //return base.Add(saveDataModel); |
| | | } |
| | | /// <summary> |
| | | /// ä¿®æ¹åºå |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public override WebResponseContent Update(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string str = ""; |
| | | try |
| | | { |
| | | VOLContext context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | var stationCode = saveModel.MainData["stationCode"].ToString(); |
| | | if (string.IsNullOrEmpty(stationCode)) throw new Exception($"ç¼åæ¶ç¼å·ä¸è½ä¸ºç©º!"); |
| | | if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"ç¼åæ¶ç±»åæè¯¯!"); |
| | | if (!stationinfoRepository.Find(x => x.stationCode == stationCode).Any()) throw new Exception($"æªæ¾å°è´§ä½{stationCode}"); |
| | | var inventory = _repository.Find(x => x.ID.ToString() == saveModel.MainData["ID"].ToString()).FirstOrDefault(); |
| | | str = $"åè´§ä½ç¼å·ï¼{inventory.stationCode}ï¼ç°è´§ä½ç¼å·ï¼{stationCode}ï¼SNå·ï¼{inventory.SN}"; |
| | | List<detail1> list1 = new List<detail1>(); |
| | | detail1 detail = new detail1(); |
| | | detail.sn = inventory.SN; |
| | | list1.Add(detail); |
| | | agvMoveWarehousePara moveWarehousePara = new agvMoveWarehousePara() |
| | | { |
| | | fromZoneID = inventory.stationCode, |
| | | toZoneID = stationCode, |
| | | details = list1, |
| | | fromLayerNo = "1", |
| | | fromStackID = "1", |
| | | fromWarehouseName = "Agvåº", |
| | | toLayerNo = "1", |
| | | toStackID = "1", |
| | | toWarehouseName = "Agvåº", |
| | | Operator = UserContext.Current.UserName, |
| | | }; |
| | | var postJson = JsonConvert.SerializeObject(moveWarehousePara); |
| | | var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvMoveWarehouse"); |
| | | if (mesData.Contains("è¿æ¥å°è¯å¤±è´¥")) |
| | | throw new Exception(mesData); |
| | | MES_Response requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData); |
| | | if (requestMes.code == "200" && requestMes.Type == "success") |
| | | { |
| | | //æ¥å¿è®°å½ä¸ä¼ æ°æ®æå |
| | | WriteWMSLog.LogAdd("", "æå", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮移åº", "agvMoveWarehouse", requestMes.message); |
| | | inventory.stationCode = stationCode; |
| | | _repository.Update(inventory, true); |
| | | WriteDBLog.Write($"æå¨ç§»åºåºå ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); |
| | | } |
| | | else |
| | | { |
| | | WriteWMSLog.LogAdd("", "失败", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮移åº", "agvMoveWarehouse", requestMes.message); |
| | | throw new Exception("äººå·¥åæ¥MES车轮移åºå¤±è´¥ï¼" + requestMes.message); |
| | | } |
| | | |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Message = ex.Message; |
| | | WriteDBLog.Write($"æå¨ç§»åºåºå ", new { éè¯¯ä¿¡æ¯ = ex.Message, æ°æ® = str }, LogState.Error, "WMS", UserContext.Current.UserName); |
| | | } |
| | | return content; |
| | | //return base.Update(saveModel); |
| | | } |
| | | /// <summary> |
| | | /// å é¤åºå |
| | | /// </summary> |
| | | /// <param name="keys"></param> |
| | | /// <param name="delList"></param> |
| | | /// <returns></returns> |
| | | public override WebResponseContent Del(object[] keys, bool delList = true) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | KeyList.Add(key); |
| | | } |
| | | var inventoryList= _repository.Find(x=>KeyList.Contains(x.ID.ToString())).ToList(); |
| | | str = $"{string.Join('ã', inventoryList.Select(t => t.SN).ToArray())}"; |
| | | content = base.Del(keys, delList); |
| | | WriteDBLog.Write($"æå¨å é¤åºå ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); |
| | | //str = $"{string.Join('ã', inventoryList.Select(t => t.SN).ToArray())}"; |
| | | foreach (var inventorys in inventoryList.GroupBy(x => x.stationCode)) |
| | | { |
| | | try |
| | | { |
| | | List<detail> lists = new List<detail>(); |
| | | foreach (var inventory in inventorys) |
| | | { |
| | | detail detail = new detail(); |
| | | detail.sn = inventory.SN; |
| | | lists.Add(detail); |
| | | str = str == "" ? inventory.SN : "," + inventory.SN; |
| | | } |
| | | agvInWarehousePara outWarehousePara = new agvInWarehousePara() |
| | | { |
| | | //WorkOrder = task.jobID, |
| | | zoneID = inventorys.Key, |
| | | //processCode = task.agv_worktype.ToString(), |
| | | details = lists, |
| | | layerNo = 1, |
| | | stackID = "1", |
| | | warehouseName = "Agvåº", |
| | | Operator = UserContext.Current.UserName, |
| | | }; |
| | | var postJson = JsonConvert.SerializeObject(outWarehousePara); |
| | | var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvOutWarehouse"); |
| | | if (mesData.Contains("è¿æ¥å°è¯å¤±è´¥")) throw new Exception(mesData); |
| | | MES_Response requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData); |
| | | if (requestMes.code == "200" && requestMes.Type == "success") |
| | | { |
| | | //æ¥å¿è®°å½ä¸ä¼ æ°æ®æå |
| | | WriteWMSLog.LogAdd("", "æå", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮åºåº", "agvOutWarehouse", requestMes.message); |
| | | |
| | | foreach (var inventory in inventorys) |
| | | { |
| | | _repository.Delete(inventory, true); |
| | | } |
| | | WriteDBLog.Write($"æå¨å é¤åºå ", $"è´§ä½ç¼å·ï¼{inventorys.Key}ï¼SNå·ï¼{str}", LogState.Sucess, "WMS", UserContext.Current.UserName); |
| | | } |
| | | else |
| | | { |
| | | WriteWMSLog.LogAdd("", "失败", "MES", "WMS", postJson, mesData, "äººå·¥åæ¥MES车轮åºåº", "agvOutWarehouse", requestMes.message); |
| | | throw new Exception("äººå·¥åæ¥MES车轮åºåºå¤±è´¥ï¼" + requestMes.message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Message = ex.Message; |
| | | WriteDBLog.Write($"æå¨å é¤åºå ", new { éè¯¯ä¿¡æ¯ = ex.Message, æ°æ® = str }, LogState.Error, "WMS", UserContext.Current.UserName); |
| | | } |
| | | |
| | | } |
| | | content.OK(); |
| | | //content = base.Del(keys, delList); |
| | | //WriteDBLog.Write($"æå¨å é¤åºå ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Message = ex.Message; |
| | | WriteDBLog.Write($"æå¨å é¤åºå ", new { éè¯¯ä¿¡æ¯ = ex.Message, æ°æ® = str }, LogState.Error, "WMS", UserContext.Current.UserName); |
| | | } |
| | | |