From c06382f1b619e1dc7f37be36a0cee126239abdee Mon Sep 17 00:00:00 2001
From: chengsc <Demo@DESKTOP-CPA90BF>
Date: 星期三, 30 十月 2024 11:35:22 +0800
Subject: [PATCH] Merge branch 'master' into csc
---
Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs | 433 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 432 insertions(+), 1 deletions(-)
diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
index 612c67d..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,14 +15,443 @@
[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>
/// 鍒嗛〉鏌ヨ璁惧淇℃伅
/// </summary>
--
Gitblit v1.8.0