From 54da8a22c438e1495b9c5fbae75ca9d4b5ca7335 Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期一, 02 九月 2024 16:04:37 +0800
Subject: [PATCH] Merge branch 'master' into wxw

---
 Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs |  106 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 87 insertions(+), 19 deletions(-)

diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
index 9c8e36d..6dd80ee 100644
--- a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
+++ b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
@@ -1,4 +1,6 @@
 锘�
+using Admin.NET.Core.Service;
+
 namespace WCS.Application;
 
 /// <summary>
@@ -8,9 +10,11 @@
 public class WcsDeviceService : IDynamicApiController, ITransient
 {
     private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep;
-    public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep)
+    private readonly SysCacheService _sysCacheService;
+    public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService)
     {
         _wcsDeviceRep = wcsDeviceRep;
+        _sysCacheService = sysCacheService;
     }
 
     /// <summary>
@@ -28,19 +32,20 @@
             input.Field = "u.Id";
             input.Order = "desc";
         }
-		input.SearchKey = input.SearchKey?.Trim();
+        input.SearchKey = input.SearchKey?.Trim();
         var query = _wcsDeviceRep.AsQueryable()
             .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u =>
                 u.Text.Contains(input.SearchKey)
             )
-            .WhereIF(input.PlcId>0, u => u.PlcId == input.PlcId)
+            .WhereIF(input.PlcId > 0, u => u.PlcId == input.PlcId)
             .WhereIF(!string.IsNullOrWhiteSpace(input.Text), u => u.Text.Contains(input.Text.Trim()))
             //澶勭悊澶栭敭鍜孴reeSelector鐩稿叧瀛楁鐨勮繛鎺�
-            .LeftJoin<WcsPlc>((u, plcid) => u.PlcId == plcid.Id )
+            .LeftJoin<WcsPlc>((u, plcid) => u.PlcId == plcid.Id)
             .Select((u, plcid) => new WcsDeviceOutput
             {
                 Id = u.Id,
-                PlcId = u.PlcId, 
+                PlcId = u.PlcId,
+                DeviceType = (DeviceTypeEnum)u.DeviceType,
                 PlcIdIP = plcid.IP,
                 Level = (DeviceLevelEnum)u.Level,
                 DbNumber = u.DbNumber,
@@ -60,7 +65,7 @@
                 CreateOrgName = u.CreateOrgName,
                 IsDelete = u.IsDelete,
             });
-		return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
+        return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
     }
 
     /// <summary>
@@ -121,19 +126,6 @@
     }
 
     /// <summary>
-    /// 鑾峰彇璁惧淇℃伅鍒楄〃
-    /// </summary>
-    /// <param name="input"></param>
-    /// <returns></returns>
-    [HttpGet]
-    [ApiDescriptionSettings(Name = "List")]
-    [DisplayName("鑾峰彇璁惧淇℃伅鍒楄〃")]
-    public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
-    {
-        return await _wcsDeviceRep.AsQueryable().Select<WcsDeviceOutput>().ToListAsync();
-    }
-
-    /// <summary>
     /// 鑾峰彇PlcId鍒楄〃
     /// </summary>
     /// <returns></returns>
@@ -150,7 +142,83 @@
                 ).ToListAsync();
     }
 
+    /// <summary>
+    /// 鐢熸垚鐐逛綅
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [HttpPost]
+    [ApiDescriptionSettings(Name = "GeneratePos")]
+    [DisplayName("鐢熸垚鐐逛綅")]
+    public async Task GeneratePos(GeneratePosInput input)
+    {
+        var modDevice = await _wcsDeviceRep.GetByIdAsync(input.Id);
 
+        var listPosition = new List<WcsPosition>();
+        listPosition.Add(new WcsPosition()
+        {
+            DeviceId = modDevice.Id,
+            StationNum = modDevice.StationNum,
+            PlcPos = input.Pos.ToString(),
+            PosType = PLCDataTypeEnum.String,
+            Text = "TaskNo"
+        });
+        listPosition.Add(new WcsPosition()
+        {
+            DeviceId = modDevice.Id,
+            StationNum = modDevice.StationNum,
+            PlcPos = (input.Pos + 4).ToString(),
+            PosType = PLCDataTypeEnum.UShort,
+            Text = "TaskType"
+        });
+        listPosition.Add(new WcsPosition()
+        {
+            DeviceId = modDevice.Id,
+            StationNum = modDevice.StationNum,
+            PlcPos = (input.Pos + 6).ToString(),
+            PosType = PLCDataTypeEnum.UShort,
+            Text = "StartLocatNo"
+        });
+        listPosition.Add(new WcsPosition()
+        {
+            DeviceId = modDevice.Id,
+            StationNum = modDevice.StationNum,
+            PlcPos = (input.Pos + 8).ToString(),
+            PosType = PLCDataTypeEnum.UShort,
+            Text = "EndLocatNo"
+        });
 
+        await _wcsDeviceRep.Context.Insertable(listPosition).ExecuteCommandAsync();
+    }
 
+    /// <summary>
+    /// 鑾峰彇璁惧淇℃伅鍒楄〃
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [HttpGet]
+    [ApiDescriptionSettings(Name = "List")]
+    [DisplayName("鑾峰彇璁惧淇℃伅鍒楄〃")]
+    public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
+    {
+        var list = await _wcsDeviceRep.AsQueryable()
+                                    .LeftJoin<WcsPlc>((a, b) => a.PlcId == b.Id)
+                                    .Select<WcsDeviceOutput>((a, b) => new WcsDeviceOutput() { Type = b.Type }, true)
+                                    .ToListAsync();
+        //鑾峰彇璺烘満鐨勭姸鎬�
+        foreach (var modDevice in list)
+        {
+            if (_sysCacheService.ExistKey("PlcConn" + modDevice.PlcId))
+            {
+                var cachePlc = _sysCacheService.Get<WcsPlc>("PlcConn" + modDevice.PlcId);
+                modDevice.Status = cachePlc.IsConn;
+            }
+            else
+            {
+                modDevice.Status = false;
+            }
+        }
+
+        return list;
+    }
 }

--
Gitblit v1.8.0