From c725c305325e1e485a6804e5eced888056195125 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期四, 29 八月 2024 14:05:21 +0800
Subject: [PATCH] 生成点位

---
 Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs   |   57 ++++++++++++++++++++++++++--
 Web/src/views/wcs/wcsDevice/index.vue                             |   26 ++++++++++---
 Admin.NET/WCS.Application/Service/WcsDevice/Dto/WcsDeviceInput.cs |   13 ++++++
 Web/src/api/wcs/wcsDevice.ts                                      |    8 ++++
 Admin.NET/WCS.Application/PLC/PLCTaskAction.cs                    |    5 ++
 5 files changed, 98 insertions(+), 11 deletions(-)

diff --git a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
index 63086d6..facc754 100644
--- a/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
+++ b/Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -4,6 +4,9 @@
 namespace WCS.Application;
 public static class PLCTaskAction
 {
+    //鏈嶅姟杩愯鐘舵��
+    public static bool boRunningState = false;
+
     private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
 
     private static List<WcsPlc> listPlc;
@@ -48,6 +51,7 @@
             listPlcUtil.Add(plc);
         }
         cts = new CancellationTokenSource();
+        boRunningState = true;
         StartRead();
     }
     /// <summary>
@@ -127,5 +131,6 @@
     public static void Stop()
     {
         cts.Cancel();
+        boRunningState = false;
     }
 }
\ No newline at end of file
diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/Dto/WcsDeviceInput.cs b/Admin.NET/WCS.Application/Service/WcsDevice/Dto/WcsDeviceInput.cs
index b0c07e3..a4b8c8a 100644
--- a/Admin.NET/WCS.Application/Service/WcsDevice/Dto/WcsDeviceInput.cs
+++ b/Admin.NET/WCS.Application/Service/WcsDevice/Dto/WcsDeviceInput.cs
@@ -210,3 +210,16 @@
 {
 
 }
+public class GeneratePosInput
+{
+    /// <summary>
+    /// 涓婚敭Id
+    /// </summary>
+    [Required(ErrorMessage = "涓婚敭Id涓嶈兘涓虹┖")]
+    public long Id { get; set; }
+    /// <summary>
+    /// 璧峰鐐逛綅
+    /// </summary>
+    [Required(ErrorMessage = "璧峰鐐逛綅涓嶈兘涓虹┖")]
+    public int Pos { get; set; }
+}
\ No newline at end of file
diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
index 9c8e36d..b52d4b1 100644
--- a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
+++ b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs
@@ -28,19 +28,19 @@
             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,
                 PlcIdIP = plcid.IP,
                 Level = (DeviceLevelEnum)u.Level,
                 DbNumber = u.DbNumber,
@@ -60,7 +60,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>
@@ -150,7 +150,54 @@
                 ).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();
+    }
 
 
 }
diff --git a/Web/src/api/wcs/wcsDevice.ts b/Web/src/api/wcs/wcsDevice.ts
index 985447f..8bd165a 100644
--- a/Web/src/api/wcs/wcsDevice.ts
+++ b/Web/src/api/wcs/wcsDevice.ts
@@ -6,6 +6,7 @@
   PageWcsDevice = '/api/wcsDevice/page',
   DetailWcsDevice = '/api/wcsDevice/detail',
   GetWcsPlcPlcIdDropdown = '/api/wcsDevice/WcsPlcPlcIdDropdown',
+  GeneratePos = '/api/wcsDevice/GeneratePos',
 }
 
 // 澧炲姞璁惧淇℃伅
@@ -54,3 +55,10 @@
 		method: 'get'
 		});
 
+export const generatePos = (params?: any) =>
+	request({
+	url: Api.GeneratePos,
+	method: 'post',
+	data: params
+	});
+	
\ No newline at end of file
diff --git a/Web/src/views/wcs/wcsDevice/index.vue b/Web/src/views/wcs/wcsDevice/index.vue
index adb4f8f..bb543eb 100644
--- a/Web/src/views/wcs/wcsDevice/index.vue
+++ b/Web/src/views/wcs/wcsDevice/index.vue
@@ -37,7 +37,6 @@
                   style="margin-left:5px;"> 闅愯棌 </el-button>
                 <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddWcsDevice"
                   v-auth="'wcsDevice:add'"> 鏂板 </el-button>
-
               </el-button-group>
             </el-form-item>
 
@@ -59,7 +58,7 @@
         <el-table-column prop="level" label="璁惧绾у埆" show-overflow-tooltip="">
           <template #default="scope">
             <el-tag :type="dv('DeviceLevelEnum', scope.row.level)?.tagType"> {{ dv('DeviceLevelEnum',
-              scope.row.level)?.name}}</el-tag>
+              scope.row.level)?.name }}</el-tag>
           </template>
         </el-table-column>
         <el-table-column prop="dbNumber" label="DB鍖哄煙" show-overflow-tooltip="" />
@@ -69,7 +68,7 @@
         <el-table-column prop="posType" label="娴佺▼瀛楃被鍨�" show-overflow-tooltip="">
           <template #default="scope">
             <el-tag :type="dv('PLCDataTypeEnum', scope.row.posType)?.tagType"> {{ dv('PLCDataTypeEnum',
-              scope.row.posType)?.name}}</el-tag>
+              scope.row.posType)?.name }}</el-tag>
           </template>
         </el-table-column>
         <el-table-column prop="ledIP" label="鏄剧ず灞廼p鍦板潃" show-overflow-tooltip="" />
@@ -79,13 +78,15 @@
             <ModifyRecord :data="scope.row" />
           </template>
         </el-table-column>
-        <el-table-column label="鎿嶄綔" width="140" align="center" fixed="right" show-overflow-tooltip=""
+        <el-table-column label="鎿嶄綔" width="220" align="center" fixed="right" show-overflow-tooltip=""
           v-if="auth('wcsDevice:update') || auth('wcsDevice:delete')">
           <template #default="scope">
             <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditWcsDevice(scope.row)"
               v-auth="'wcsDevice:update'"> 缂栬緫 </el-button>
             <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delWcsDevice(scope.row)"
               v-auth="'wcsDevice:delete'"> 鍒犻櫎 </el-button>
+            <el-button icon="ele-Plus" size="small" text="" type="primary" @click="generateDevicePos(scope.row)"
+              v-auth="'wcsDevice:generate'"> 鐢熸垚鐐逛綅 </el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -112,7 +113,7 @@
 
 import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
 import editDialog from '/@/views/wcs/wcsDevice/component/editDialog.vue'
-import { pageWcsDevice, deleteWcsDevice } from '/@/api/wcs/wcsDevice';
+import { pageWcsDevice, deleteWcsDevice, generatePos } from '/@/api/wcs/wcsDevice';
 import { getWcsPlcPlcIdDropdown } from '/@/api/wcs/wcsDevice';
 
 const showAdvanceQueryUI = ref(false);
@@ -167,7 +168,20 @@
   editWcsDeviceTitle.value = '缂栬緫璁惧淇℃伅';
   editDialogRef.value.openDialog(row);
 };
-
+//鐢熸垚鐐逛綅
+const generateDevicePos = (row: any) => {
+  ElMessageBox.prompt('璇疯緭鍏ヨ捣濮嬬偣浣�', '鐢熸垚鐐逛綅', {
+    confirmButtonText: '纭畾',
+    cancelButtonText: '鍙栨秷',
+  })
+    .then(async ({ value }) => {
+      await generatePos({ id: row.id, pos: value });
+      ElMessage({
+        type: 'success',
+        message: `鐢熸垚鐐逛綅鎴愬姛`,
+      })
+    })
+}
 // 鍒犻櫎
 const delWcsDevice = (row: any) => {
   ElMessageBox.confirm(`纭畾瑕佸垹闄ゅ悧?`, "鎻愮ず", {

--
Gitblit v1.8.0