From f53ddc0903c524e50959aeabfb6b93a6098fec8c Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期一, 21 四月 2025 08:47:59 +0800
Subject: [PATCH] 1.生产退库后台

---
 Controllers/Warehouse/MesSctkController.cs |  235 ++++++++++++++++++++++++++
 entity/MesScthSq.cs                        |   94 ++++++++++
 entity/MesScthSqDetail.cs                  |   64 +++++++
 service/Warehouse/MesSctkManager.cs        |  119 +++++++++++++
 4 files changed, 512 insertions(+), 0 deletions(-)

diff --git a/Controllers/Warehouse/MesSctkController.cs b/Controllers/Warehouse/MesSctkController.cs
new file mode 100644
index 0000000..a0e4517
--- /dev/null
+++ b/Controllers/Warehouse/MesSctkController.cs
@@ -0,0 +1,235 @@
+锘縰sing System.Dynamic;
+using MES.Service.Models;
+using Microsoft.AspNetCore.Mvc;
+using NewPdaSqlServer.Dto.service;
+using NewPdaSqlServer.entity;
+using NewPdaSqlServer.service.Warehouse;
+using NewPdaSqlServer.util;
+
+namespace NewPdaSqlServer.Controllers.Warehouse;
+
+[ApiController]
+[Route("api/[controller]")]
+public class MesSctkController : ControllerBase
+{
+    private readonly MesSctkManager m = new();
+
+
+    /// <summary>
+    ///     鑾峰彇鎵�鏈夊凡缁忓鏍哥殑鐢宠鍗�
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("GetMesSctkSq")]
+    public ResponseResult GetMesSctkSq()
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.GetMesSctkSq();
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     鑾峰彇鎵�鏈夊凡缁忓鏍哥殑鐢宠鍗�
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("GetSumItem")]
+    public ResponseResult GetSumItem(WarehouseQuery query)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.GetSumItem(query);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    //ScanCode
+    /// <summary>
+    ///     鑾峰彇鎵�鏈夊凡缁忓鏍哥殑鐢宠鍗�
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("ScanCode")]
+    public ResponseResult ScanCode(WarehouseQuery query)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.ScanCode(query);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     鑾峰彇鎵�鏈�
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("GetList")]
+    public ResponseResult GetList()
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.GetList();
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+
+    /// <summary>
+    ///     鏍规嵁涓婚敭鑾峰彇
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("GetById")]
+    public ResponseResult GetById(int id)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.GetById(id);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     鏍规嵁涓婚敭鍒犻櫎
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("DeleteByIds")]
+    public ResponseResult DeleteByIds([FromBody] object[] ids)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.DeleteByIds(ids);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     娣诲姞
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("Insert")]
+    public ResponseResult Add([FromBody] MesScthSq data)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.Insert(data);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     娣诲姞杩斿洖鑷
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("InsertReturnIdentity")]
+    public ResponseResult InsertReturnIdentity([FromBody] MesScthSq data)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.InsertReturnIdentity(data);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    ///     淇敼
+    /// </summary>
+    /// <returns></returns>
+    [HttpPost("Update")]
+    public ResponseResult Update([FromBody] MesScthSq data)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = m.Update(data);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+}
\ No newline at end of file
diff --git a/entity/MesScthSq.cs b/entity/MesScthSq.cs
new file mode 100644
index 0000000..a7f39dd
--- /dev/null
+++ b/entity/MesScthSq.cs
@@ -0,0 +1,94 @@
+锘縰sing SqlSugar;
+
+namespace MES.Service.Models;
+
+/// <summary>
+/// 鐢熶骇閫�璐ц〃瀹炰綋绫�
+/// </summary>
+[SugarTable("MES_SCTH_SQ")]
+public class MesScthSq
+{
+    /// <summary>
+    /// 涓婚敭guid
+    /// </summary>
+    [SugarColumn(ColumnName = "ID")]
+    public string Id { get; set; } // 浣跨敤string绫诲瀷鏉ュ瓨鍌╱niqueidentifier
+
+    /// <summary>
+    /// 鍗曞彿
+    /// </summary>
+    [SugarColumn(ColumnName = "BILL_NO")]
+    public string BillNo { get; set; }
+
+    /// <summary>
+    /// 寤虹珛鑰�
+    /// </summary>
+    [SugarColumn(ColumnName = "CREATE_BY")]
+    public string CreateBy { get; set; }
+
+    /// <summary>
+    /// 寤虹珛鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "CREATE_DATE")]
+    public DateTime? CreateDate { get; set; }
+
+    /// <summary>
+    /// 鏇存柊鑰�
+    /// </summary>
+    [SugarColumn(ColumnName = "LAST_UPDATE_USER")]
+    public string LastUpdateUser { get; set; }
+
+    /// <summary>
+    /// 鏇存柊鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "LAST_UPDATE_TIME")]
+    public DateTime? LastUpdateTime { get; set; }
+
+    /// <summary>
+    /// 瀹℃牳鑰�
+    /// </summary>
+    [SugarColumn(ColumnName = "CHECK_USER")]
+    public string CheckUser { get; set; }
+
+    /// <summary>
+    /// 瀹℃牳鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "CHECK_DATE")]
+    public DateTime? CheckDate { get; set; }
+
+    /// <summary>
+    /// 鐘舵��
+    /// </summary>
+    [SugarColumn(ColumnName = "STATUS")]
+    public bool Status { get; set; }
+
+    /// <summary>
+    /// 瀹屾垚鏍囪瘑
+    /// </summary>
+    [SugarColumn(ColumnName = "IS_FINISH")]
+    public bool IsFinish { get; set; }
+
+    /// <summary>
+    /// 閫�璐у師鍥�
+    /// </summary>
+    [SugarColumn(ColumnName = "RETURN_TYPE")]
+    public string ReturnType { get; set; }
+
+    /// <summary>
+    /// 浠撳簱
+    /// </summary>
+    [SugarColumn(ColumnName = "DEPOT_ID")]
+    public int DepotId { get; set; }
+
+    /// <summary>
+    /// 鐢宠澶囨敞
+    /// </summary>
+    [SugarColumn(ColumnName = "REMARK")]
+    public string Remark { get; set; }
+
+    /// <summary>
+    /// 缁勭粐
+    /// </summary>
+    [SugarColumn(ColumnName = "TH_ORG_ID")]
+    public string ThOrgId { get; set; }
+}
\ No newline at end of file
diff --git a/entity/MesScthSqDetail.cs b/entity/MesScthSqDetail.cs
new file mode 100644
index 0000000..c0d6e0f
--- /dev/null
+++ b/entity/MesScthSqDetail.cs
@@ -0,0 +1,64 @@
+锘縰sing SqlSugar;
+
+namespace MES.Service.Models;
+
+/// <summary>
+/// 鐢熶骇閫�璐ф槑缁嗚〃瀹炰綋绫�
+/// </summary>
+[SugarTable("MES_SCTH_SQ_DETAIL")]
+public class MesScthSqDetail
+{
+    /// <summary>
+    /// 涓婚敭
+    /// </summary>
+    [SugarColumn(ColumnName = "ID")]
+    public string Id { get; set; } // 浣跨敤string绫诲瀷鏉ュ瓨鍌╱niqueidentifier
+
+    /// <summary>
+    /// 澶栭敭
+    /// </summary>
+    [SugarColumn(ColumnName = "MID")]
+    public string Mid { get; set; } // 浣跨敤string绫诲瀷鏉ュ瓨鍌╱niqueidentifier
+
+    /// <summary>
+    /// 鐗╂枡Id
+    /// </summary>
+    [SugarColumn(ColumnName = "ITEM_ID")]
+    public int ItemId { get; set; }
+
+    /// <summary>
+    /// 鐢宠鏁伴噺
+    /// </summary>
+    [SugarColumn(ColumnName = "SQ_NUM")]
+    public decimal SqNum { get; set; }
+
+    /// <summary>
+    /// 宸叉壂鏁伴噺
+    /// </summary>
+    [SugarColumn(ColumnName = "YS_NUM")]
+    public decimal YsNum { get; set; }
+
+    /// <summary>
+    /// 澶囨敞
+    /// </summary>
+    [SugarColumn(ColumnName = "REMARK")]
+    public string Remark { get; set; }
+
+    /// <summary>
+    /// 瀹岀粨
+    /// </summary>
+    [SugarColumn(ColumnName = "IS_FINISH")]
+    public bool IsFinish { get; set; }
+
+    /// <summary>
+    /// 椤规
+    /// </summary>
+    [SugarColumn(ColumnName = "ORDER_NO")]
+    public int OrderNo { get; set; }
+
+    /// <summary>
+    /// 鍏ュ簱GUID
+    /// </summary>
+    [SugarColumn(ColumnName = "RKMX_GUID")]
+    public string RkmxGuid { get; set; } // 浣跨敤string绫诲瀷鏉ュ瓨鍌╱niqueidentifier
+}
\ No newline at end of file
diff --git a/service/Warehouse/MesSctkManager.cs b/service/Warehouse/MesSctkManager.cs
new file mode 100644
index 0000000..c5798ef
--- /dev/null
+++ b/service/Warehouse/MesSctkManager.cs
@@ -0,0 +1,119 @@
+锘縰sing System.Data;
+using System.Data.SqlClient;
+using Masuit.Tools;
+using MES.Service.Models;
+using NewPdaSqlServer.DB;
+using NewPdaSqlServer.Dto.service;
+using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
+using SqlSugar;
+
+namespace NewPdaSqlServer.service.Warehouse;
+
+public class MesSctkManager : Repository<MesScthSq>
+{
+    public List<MesScthSq> GetMesSctkSq()
+    {
+        return Db.Queryable<MesScthSq>()
+            .Where(s => s.Status == true)
+            .OrderByDescending(s => s.CreateDate)
+            .ToList();
+    }
+
+    public ProductionPickDto GetSumItem(WarehouseQuery query)
+    {
+        if (string.IsNullOrEmpty(query.billNo)) throw new Exception("鐢宠鍗曞彿涓虹┖");
+
+        var mesInvItemOuts = base.GetSingle(it => it.BillNo == query.billNo);
+        if (mesInvItemOuts == null) throw new Exception("閲囪喘閫�璐х敵璇峰崟涓嶅瓨鍦�");
+
+        var sql = string.Format(@"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,A.SQ_NUM FQty,A.YS_NUM SQty,A.SQ_NUM - A.YS_NUM DSQty,
+       dbo.F_QX_GETRECODEPOTSE(A.ITEM_ID) as RecoKw
+fROM MES_SCTH_SQ_DETAIL A
+         LEFT JOIN MES_SCTH_SQ B ON A.MID = B.ID
+         LEFT JOIN MES_ITEMS C ON A.ITEM_ID = C.item_id
+WHERE B.BILL_NO = '{0}'", query.billNo);
+
+        var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql);
+
+
+        var DS_list = womdabs.Where(s => s.DSQty > 0).ToList();
+
+        var YS_list = womdabs.Where(s => s.SQty > 0).ToList();
+
+        var dto = new ProductionPickDto
+        {
+            //daa001 = womdaa.Daa001,
+            //PlanNo = womcaa.Caa020,
+            items = DS_list,
+            Ysitems = YS_list
+        };
+
+        return dto;
+    }
+
+
+    public ProductionPickDto ScanCode(WarehouseQuery query)
+    {
+        var _strMsg = "";
+        var _intSum = "";
+        using (var conn = new SqlConnection(DbHelperSQL.strConn))
+        {
+            if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖");
+            if (query.billNo.IsNullOrEmpty()) throw new Exception("棰嗘枡鍗曞彿涓嶅厑璁镐负绌�");
+            if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�");
+
+            using (var cmd = new SqlCommand("[prc_pda_SCTK]", conn))
+            {
+                try
+                {
+                    conn.Open();
+                    cmd.CommandType = CommandType.StoredProcedure;
+                    SqlParameter[] parameters =
+                    {
+                        new("@outMsg", SqlDbType.NVarChar, 300),
+                        new("@outSum", SqlDbType.NVarChar, 300),
+                        new("@barcode_num", SqlDbType.NVarChar, 300),
+                        new("@split_num", SqlDbType.NVarChar, 300),
+                        new("@c_User", query.userName),
+                        new("@p_biLL_no", query.billNo),
+                        new("@p_item_barcode", query.barcode)
+                    };
+                    parameters[0].Direction = ParameterDirection.Output;
+                    parameters[1].Direction = ParameterDirection.Output;
+                    parameters[2].Direction = ParameterDirection.Output;
+                    parameters[3].Direction = ParameterDirection.Output;
+                    foreach (var parameter in parameters)
+                        cmd.Parameters.Add(parameter);
+                    cmd.ExecuteNonQuery();
+                    _strMsg = parameters[0].Value.ToString();
+                    _intSum = parameters[1].Value.ToString();
+
+                    var barcodeNum = parameters[2].Value.ToString();
+                    var splitNum = parameters[3].Value.ToString();
+
+                    var result = Convert.ToInt32(_intSum);
+                    if (result <= 0) throw new Exception(_strMsg);
+
+                    var dto = new ProductionPickDto
+                    {
+                        daa001 = query.daa001,
+                        barcodeNum = barcodeNum,
+                        splitNum = splitNum,
+                        barcode = query.barcode
+                    };
+
+                    return dto;
+                }
+                catch (Exception ex)
+                {
+                    throw new Exception(ex.Message);
+                }
+                finally
+                {
+                    conn.Close();
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3