From 25184cadd4011856d95e76f1d79b37ce51a3e548 Mon Sep 17 00:00:00 2001 From: chengsc <Demo@DESKTOP-CPA90BF> Date: 星期三, 30 十月 2024 11:34:12 +0800 Subject: [PATCH] 修改问题 --- Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs | 457 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 455 insertions(+), 2 deletions(-) diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs index bcb8ec0..ee6a929 100644 --- a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs +++ b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs @@ -1,7 +1,9 @@ 锘� using Admin.NET.Core.Service; using Elastic.Clients.Elasticsearch; +using Microsoft.CodeAnalysis.Text; using StackExchange.Profiling.Internal; +using System.Drawing.Drawing2D; using WCS.Application.Entity; using WCS.Application.Service.WcsDevice.Dto; @@ -13,13 +15,442 @@ [ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)] public class WcsDeviceService : IDynamicApiController, ITransient { + private readonly SqlSugarRepository<WcsPlc> _wcsPlcRep; private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep; private readonly SysCacheService _sysCacheService; - public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService) + public WcsDeviceService(SqlSugarRepository<WcsPlc> wcsPlcRep,SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService) { + _wcsPlcRep = wcsPlcRep; _wcsDeviceRep = wcsDeviceRep; _sysCacheService = sysCacheService; } + + #region 宸ヤ綔鍙版搷浣� + + /// <summary> + /// 鎵嬪姩鎿嶄綔PLC淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteInfo")] + [DisplayName("鎵嬪姩鎿嶄綔Plc")] + public async Task WriteInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m=>m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = "91"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + + PLCUtil modUtil = new PLCUtil(modPlc); + var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4"); + if (result.IsSucceed) + { + if (input.TypeName != "shoudong" && value.ToString().ToLower() != "false") + { + throw Oops.Bah("褰撳墠涓鸿嚜鍔ㄦā寮忥紝璇峰厛鍒囨崲涓烘墜鍔ㄦā寮�"); + } + } + else + { + throw Oops.Bah("璇诲彇PLC鎵嬭嚜鍔ㄥ�煎け璐�"); + } + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + switch (input.TypeName) + { + case "zidong": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "true"); + break; + case "shoudong": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "false"); + break; + case "huifu": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "47.0", "true"); + break; + case "1diandong": + if(input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "1liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "2diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "2liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "3diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "3liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "4diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "4liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "yizaisheng": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "yizaijiang": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "fanzhuansheng": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.7", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.7", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "fanzhuanjiang": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "52.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "52.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "UpTask": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0", "true"); + break; + default: + break; + } + + modUtil.Close(); + } + + + /// <summary> + /// 鎵嬪姩鍐欏叆PLC浠诲姟淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteTaskInfo")] + [DisplayName("鍐欏叆Plc浠诲姟淇℃伅")] + public async Task WriteTaskInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + string TaskDbNum = "";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = "91"; + TaskDbNum = "1101"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + + PLCUtil modUtil = new PLCUtil(modPlc); + var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0"); + if (result.IsSucceed) + { + if (value.ToString().ToLower() != "false") + { + throw Oops.Bah("璇峰厛鍒囨崲涓烘洿鏀逛换鍔℃ā寮�"); + } + } + else + { + throw Oops.Bah("璇诲彇PLC鎵嬭嚜鍔ㄥ�煎け璐�"); + } + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + switch (input.TypeName) + { + case "writeTask": + modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "4", input.PalletNo); + modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "14", input.TaskNo); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "34", input.StartLoction); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "36", input.EndLoction); + + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "38", input.StartPai); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "40", input.StartLie); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "42", input.StartCeng); + + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "44", input.EndPai); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "46", input.EndLie); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "48", input.EndCeng); + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.3", "true"); + break; + case "writeTaskDelete": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.2", "true"); + break; + + default: + break; + } + + modUtil.Close(); + } + + + + /// <summary> + /// 鎵嬪姩鍐欏叆PLC鍚仠淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteStartStop")] + [DisplayName("鍐欏叆PLC鍚仠淇℃伅")] + public async Task WriteStartStop(WcsDeviceStartStop input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + + + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + if (input.Layer == "1") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌1妤煎眰PLC淇℃伅"); + DbNum = ""; + } + else if (input.Layer == "2") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌2妤煎眰PLC淇℃伅"); + DbNum = "91"; + PLCUtil modUtil = new PLCUtil(modPlc); + switch (input.Type) + { + case "TwoPalletStart": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.0", "true"); + break; + case "OnePalletStop": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.1", "true"); + break; + case "TwoMaStart": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.0", "true"); + break; + case "TwoMaStop": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.1", "true"); + break; + case "TwoMaTwoStart": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.2", "true"); + break; + case "TwoMaTwoStop": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.3", "true"); + break; + case "TwoBoxStart": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.2", "true"); + break; + case "TwoBoxStop": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.3", "true"); + break; + default: + break; + } + modUtil.Close(); + } + else if (input.Layer == "3") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌3妤煎眰PLC淇℃伅"); + DbNum = ""; + } + else + { + throw Oops.Bah("鎿嶄綔绫诲瀷淇℃伅閿欒"); + } + + } + + #endregion /// <summary> /// 鍒嗛〉鏌ヨ璁惧淇℃伅 @@ -555,7 +986,14 @@ [DisplayName("鑾峰彇璁惧瀵瑰簲宸ヤ綅鍒楄〃")] public async Task<List<WcsDeviceTaskOrderDto>> WcsPackStationPlcList([FromQuery] WcsDeviceBaseInput entry) { - return await _wcsDeviceRep.Context.Queryable<WcsDevice>() + //var list = await _wcsDeviceRep.AsQueryable() + // .LeftJoin<WcsPlc>((a, b) => a.PlcId == b.Id) + // .Where((a, b) => a.DeviceType == DeviceTypeEnum.Business) + // .Select<WcsDeviceOutput>((a, b) => new WcsDeviceOutput() { Type = b.Type }, true) + // .ToListAsync(); + + + var list = await _wcsDeviceRep.Context.Queryable<WcsDevice>() .InnerJoin<WcsPlc>((device, plc) => device.PlcId == plc.Id) .LeftJoin<WcsCheckTask>((device, plc, task) => device.StationNum == task.Port) .Where((device, plc, task) => device.PlcId == entry.PlcId) @@ -574,9 +1012,24 @@ PZNo = task.PZNo, Qty = task.Qty, + PlcId=device.PlcId, Type = plc.Type }) .ToListAsync(); + + bool connStatus = false; + //鑾峰彇璁惧鐨勭姸鎬� + var modPlc = await _wcsDeviceRep.Context.Queryable<WcsPlc>().FirstAsync(s => s.Id == list[0].PlcId); + PLCUtil modUtil = new PLCUtil(modPlc); + if (modUtil.Connected) + { + connStatus = true; + } + foreach (var item in list) + { + item.PlcStatus = connStatus; + } + return list; } #endregion } -- Gitblit v1.8.0