From db7f57324b8b0e0afc669a7d8127b696766168bc Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期六, 13 四月 2024 16:28:17 +0800
Subject: [PATCH] 盟祺-查询条码API

---
 Tiger.Business/WMS/MengQi/Biz.Mq.SNData.cs          |   94 +++++++++++++++++++++++++++++++
 Tiger.IBusiness/WMS/MengQi/IMqSNData.cs             |   17 +++++
 Tiger.Api/Controllers/WMS/WMSController.MqSNData.cs |   53 +++++++++++++++++
 3 files changed, 164 insertions(+), 0 deletions(-)

diff --git a/Tiger.Api/Controllers/WMS/WMSController.MqSNData.cs b/Tiger.Api/Controllers/WMS/WMSController.MqSNData.cs
new file mode 100644
index 0000000..63db929
--- /dev/null
+++ b/Tiger.Api/Controllers/WMS/WMSController.MqSNData.cs
@@ -0,0 +1,53 @@
+锘縰sing Microsoft.AspNetCore.Mvc;
+using Rhea.Common;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Tiger.IBusiness;
+using Tiger.Model;
+
+namespace Tiger.Api.Controllers.WMS
+{
+    public partial class WMSController : ControllerBase
+    {
+        /// <summary>
+        /// 閫�鍥炲垹闄�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> ReturnSN([FromBody] ApiAction action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IMqSNData>().ReturnSN(action.Data?.ToString()));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+        /// <summary>
+        /// 鑾峰彇鍒嗛〉
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> GetSNDataHis([FromBody] ApiAction<PageAble<SNData_His>> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IMqSNData>().GetSNDataHis(action.Data));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+    }
+}
diff --git a/Tiger.Business/WMS/MengQi/Biz.Mq.SNData.cs b/Tiger.Business/WMS/MengQi/Biz.Mq.SNData.cs
new file mode 100644
index 0000000..2dcdbf7
--- /dev/null
+++ b/Tiger.Business/WMS/MengQi/Biz.Mq.SNData.cs
@@ -0,0 +1,94 @@
+锘縰sing Rhea.Common;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tiger.IBusiness;
+using Tiger.Model;
+using static Tiger.Business.Biz;
+
+namespace Tiger.Business
+{
+    public partial class Biz
+    {
+        /// <summary>
+        /// SN鎿嶄綔
+        /// </summary>
+        public partial class MqSNData : IMqSNData
+        {
+            /// <summary>
+            /// 閫�鍥炲垹闄ゆ潯鐮�
+            /// </summary>
+            /// <param name="barcode"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> ReturnSN(string barcode)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    SNData_His data_His = await Db.Queryable<SNData_His>().Where(x => x.OriginalSN == barcode).FirstAsync();
+                    if (data_His == null)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"閫�鍥炲垹闄ゆ潯鐮佷笉瀛樺湪";
+                        return result;
+                    }
+                    List<SNData> sndatas = await Db.Queryable<SNData>().Where(x => x.SN == barcode || x.SN == data_His.SN).ToListAsync();
+                    if (sndatas == null && sndatas.Count>0)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"閫�鍥炲垹闄ゆ潯鐮佷笉瀛樺湪";
+                        return result;
+                    }
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        db.Deleteable(data_His).ExecuteCommand();
+                        db.Deleteable(sndatas).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false; 
+                        result.Message = $"閫�鍥炲垹闄ゆ潯鐮佸紓甯�";
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "閫�鍥炲垹闄ゆ潯鐮佸紓甯�");
+                }
+                return result;
+            }
+
+            /// <summary>
+            /// 鍒嗛〉
+            /// </summary>
+            /// <param name="pageList"></param>
+            /// <returns></returns>
+            public async Task<ApiAction<PageAble<SNData_His>>> GetSNDataHis(PageAble<SNData_His> pageList)
+            {
+                var res = new ApiAction<PageAble<SNData_His>>();
+                try
+                {
+                    string[] strTime = pageList.sqlcmd?.Split(',');
+                    RefAsync<int> total = 0;
+                    pageList.data = await Db.Queryable<SNData_His>()
+                        .WhereIF(!string.IsNullOrEmpty(strTime[0]), x => Convert.ToDateTime(x.ScanTime) > Convert.ToDateTime(strTime[0]))
+                        .WhereIF(!string.IsNullOrEmpty(strTime[1]) && strTime.Length == 2, x => Convert.ToDateTime(x.ScanTime) < Convert.ToDateTime(strTime[1]))
+                        .WhereIF(!string.IsNullOrEmpty(strTime[2]), x => x.ModelCode.Equals(strTime[2]))
+                        .WhereIF(!string.IsNullOrEmpty(strTime[3]), x => x.CustomerCode.Equals(strTime[3]))
+                        .ToPageListAsync(pageList.pageIndex, pageList.pageSize, total);
+                    pageList.totals = total;
+                }
+                catch (Exception ex)
+                {
+                    res.CatchExceptionWithLog(ex, "鏌ヨ寮傚父");
+                }
+                res.Data = pageList;
+                return res;
+            }
+        }
+    }
+}
diff --git a/Tiger.IBusiness/WMS/MengQi/IMqSNData.cs b/Tiger.IBusiness/WMS/MengQi/IMqSNData.cs
new file mode 100644
index 0000000..16156cc
--- /dev/null
+++ b/Tiger.IBusiness/WMS/MengQi/IMqSNData.cs
@@ -0,0 +1,17 @@
+锘縰sing Rhea.Common;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tiger.Model;
+
+namespace Tiger.IBusiness
+{
+    public interface IMqSNData
+    {
+        public Task<ApiAction> ReturnSN(string barcode);
+        public Task<ApiAction<PageAble<SNData_His>>> GetSNDataHis(PageAble<SNData_His> pageList);
+    }
+}

--
Gitblit v1.9.3