南骏 池
5 天以前 459621921ba77d8cc8bf0789209b76d387b820e8
1.携客云字段优化
2.库位变更——hyx
已修改1个文件
已添加2个文件
310 ■■■■■ 文件已修改
Controllers/Warehouse/KwbgController.cs 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Dto/Xky/XkyBarcodeDataDto.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Warehouse/KwbgManager.cs 219 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Controllers/Warehouse/KwbgController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,89 @@
using System.Dynamic; // å¼•入动态类型支持
using Masuit.Tools.Win32.AntiVirus; // å¼•入防病毒工具库(但未在代码中使用)
using Microsoft.AspNetCore.Mvc; // å¼•å…¥ASP.NET Core MVC功能
using NewPdaSqlServer.Dto.service; // å¼•入项目特定的DTO服务
using NewPdaSqlServer.entity; // å¼•入项目实体类
using NewPdaSqlServer.service.@base; // å¼•入基础服务
using NewPdaSqlServer.service.Warehouse; // å¼•入仓库服务
using NewPdaSqlServer.util; // å¼•入工具类
using static Microsoft.EntityFrameworkCore.DbLoggerCategory; // å¼•å…¥EF日志类别(但未在代码中使用)
namespace NewPdaSqlServer.Controllers.Warehouse; // æŽ§åˆ¶å™¨å‘½åç©ºé—´
/// <summary>
/// åº“位变更控制器,处理与库位变更相关的API请求
/// </summary>
[ApiController] // æ ‡è®°è¯¥ç±»ä¸ºAPI控制器,自动进行模型验证和错误处理
[Route("api/[controller]")] // å®šä¹‰æŽ§åˆ¶å™¨è·¯ç”±æ¨¡æ¿ï¼Œè·¯ç”±å‰ç¼€ä¸ºapi/控制器名(Kwbg)
public class KwbgController : ControllerBase // æŽ§åˆ¶å™¨ç±»ç»§æ‰¿è‡ªControllerBase,提供Web API功能
{
    private readonly KwbgManager k = new(); // åˆ›å»ºåº“位变更管理器实例,用于处理业务逻辑
    private readonly MesPrintMangeer _kBG = new(); // åˆ›å»ºæ‰“印管理器实例,用于处理打印相关业务
    /// <summary>
    /// èŽ·å–æ¡ç ä¿¡æ¯å’Œç‰©æ–™ä¿¡æ¯
    /// </summary>
    /// <param name="unity">前端传递的WarehouseQuery对象,包含查询参数</param>
    /// <returns>统一的响应结果,包含条码信息和物料信息</returns>
    [HttpPost("GetBarInfo")] // å®šä¹‰HTTP POST方法及子路由,访问路径为api/Kwbg/GetBarInfo
    //public ResponseResult GetBarInfo(dynamic unity) // æ—§æ–¹æ³•签名,参数为dynamic类型(已注释)
    public ResponseResult GetBarInfo(dynamic unity) // æ–°æ–¹æ³•签名,参数为WarehouseQuery类型
    {
        try // æ•获异常,保证接口稳定性
        {
            dynamic resultInfos = new ExpandoObject(); // åˆ›å»ºåŠ¨æ€å¯¹è±¡ï¼Œç”¨äºŽå­˜å‚¨è¿”å›žç»“æžœ
            resultInfos.tbBillList = k.GetBarInfo(unity); // è°ƒç”¨ç®¡ç†å™¨æ–¹æ³•,获取条码信息,赋值给动态对象的tbBillList属性
            return new ResponseResult // æž„造统一响应结果对象
            {
                status = 0, // çŠ¶æ€ç 0表示成功
                message = "OK", // è¿”回消息为OK
                data = resultInfos // è¿”回数据为动态对象,包含条码和物料信息
            };
        }
        catch (Exception ex) // æ•获所有异常
        {
            return ResponseResult.ResponseError(ex); // è°ƒç”¨ç»Ÿä¸€é”™è¯¯å¤„理方法,返回错误响应
        }
    }
    /// <summary>
    /// åº“位变更接口。
    /// æŽ¥æ”¶å‰ç«¯ä¼ é€’çš„WarehouseQuery参数,完成条码变更及相关信息的查询和返回。
    /// </summary>
    /// <param name="unity">
    /// WarehouseQuery对象,包含条码、拆分数量、用户名等库位变更所需参数。
    /// </param>
    /// <returns>
    /// è¿”回ResponseResult统一响应对象,status为0表示成功,data包含变更后的条码及打印信息。
    /// </returns>
    [HttpPost("ChangeDepotSection")]
    public ResponseResult ChangeDepotSection(dynamic unity)
    {
        try
        {
            // åˆ›å»ºåŠ¨æ€å¯¹è±¡resultInfos,用于存储返回结果
            dynamic resultInfos = new ExpandoObject();
            // åˆå§‹åŒ–tbBillList属性为动态对象,用于存储条码相关信息
            resultInfos.tbBillList = new ExpandoObject();
            //resultInfos.tbBillList.printInfo = _kBG.getPrintInfo(unity);// èŽ·å–æ‰“å°ä¿¡æ¯ï¼Œè°ƒç”¨æ‰“å°ç®¡ç†å™¨çš„getPrintInfo方法,结果赋值给tbBillList.printInfo
            // è°ƒç”¨åº“位变更管理器的ChangeDepotSection方法,执行条码变更操作,返回拆分结果scanResult
            var scanResult = k.ChangeDepotSection(unity);
            //resultInfos.tbBillList.cfBarInfo = _kBG.getCfInfo(scanResult);// èŽ·å–æ‹†åˆ†åŽæ¡ç çš„è¯¦ç»†ä¿¡æ¯ï¼Œè°ƒç”¨æ‰“å°ç®¡ç†å™¨çš„getCfInfo方法,结果赋值给tbBillList.cfBarInfo
            // æž„造并返回统一响应对象,status为0表示成功,message为"OK",data为resultInfos
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            // æ•获异常,调用统一错误处理方法ResponseError,返回错误响应
            return ResponseResult.ResponseError(ex);
        }
    }
}
Dto/Xky/XkyBarcodeDataDto.cs
@@ -29,7 +29,7 @@
        public string OuterBarcode { get; set; }
        [JsonProperty("includeQty")]
        public int IncludeQty { get; set; }
        public decimal IncludeQty { get; set; }
        [JsonProperty("smallPackageLength")]
        public int? SmallPackageLength { get; set; }
service/Warehouse/KwbgManager.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,219 @@
using System.Data;
using System.Data.SqlClient;
using Masuit.Tools;
using Masuit.Tools.Hardware;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using SqlSugar;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
/// <summary>
/// åº“位变更管理类,继承自通用仓储类Repository,操作采购退货申请表(MesCgthSq)
/// </summary>
public class KwbgManager : Repository<MesCgthSq>
{
    /// <summary>
    /// æ ¹æ®ä¼ å…¥çš„WarehouseQuery对象(包含条码信息),查询物料库存表MES_INV_ITEM_STOCKS,获取对应的库存信息
    /// </summary>
    /// <param name="unity">WarehouseQuery对象,包含条码编号等查询条件</param>
    /// <returns>
    /// è¿”回MES_INV_ITEM_STOCKS表中与条码匹配的第一条库存信息(MesInvItemStocks类型)。
    /// å¦‚果未找到,则抛出异常提示“该条码库存不存在!”
    /// resultInfos.tbBillList = m.GetBarInfo(unity);
    /// </returns>
    ///public MesInvItemStocks GetBarInfo(WarehouseQuery unity)
    public dynamic GetBarInfo(dynamic query)
    {
        if (query == null)
            throw new ArgumentNullException(nameof(query), "参数对象不能为null");
        if (string.IsNullOrEmpty(query.barcode?.ToString()))
            throw new ArgumentException("物料条码不能为空", nameof(query.barcode));
        var parameters = new[]
    {
        new SugarParameter("@pi_barcode", query.barcode),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
    };
        try
        {
            List<dynamic>? ZsBarInfo = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_kwbg_selKwInfoByBarcode @pi_barcode,@inP1,@inP2,@inP3,@inP4", parameters);
            return ZsBarInfo;
        }
        catch (Exception ex)
        {
            // ä¿ç•™åŽŸæœ‰å¼‚å¸¸å¤„ç†é€»è¾‘
            throw new Exception($"{ex.Message}");
        }
    }
    /// <summary>
    /// æ ¹æ®ç‰©æ–™ID查询物料表MES_ITEMS,获取物料详细信息
    /// </summary>
    /// <param name="strItemId">物料ID(decimal类型)</param>
    /// <returns>
    /// è¿”回MES_ITEMS表中与ID匹配且未禁用(Fforbidstatus为"A")的第一条物料信息(MesItems类型)。
    /// å¦‚果未找到,则抛出异常提示“该条码对应物料信息不存在或已禁用!”
    /// resultInfos.tbMesItems = m.GetItemNo(resultInfos.tbBillList.ItemId);
    /// </returns>
    public MesItems GetItemNo(decimal strItemId)
    {
        // ä½¿ç”¨SqlSugar的Queryable方法,查询MES_ITEMS表
        // æ¡ä»¶ï¼šId字段等于strItemId,且Fforbidstatus字段为"A"(表示未禁用)
        var itemInfo = Db.Queryable<MesItems>()
            .Where(s => s.Id == strItemId && s.Fforbidstatus == "A")
            .First(); // èŽ·å–ç¬¬ä¸€æ¡åŒ¹é…è®°å½•
        // å¦‚果未查询到结果(itemInfo为null),则抛出异常,提示物料信息不存在或已禁用
        if (itemInfo is null) throw new Exception("该条码对应物料信息不存在或已禁用!");
        // è¿”回查询到的物料信息对象
        return itemInfo;
    }
    /// <summary>
    /// ä»“库信息表
    /// </summary>
    /// <param name="depot_id"></param>
    /// <returns></returns>
    public MesDepots GetDepot(decimal depot_id)
    {
        var depotInfo = Db.Queryable< MesDepots >()
            .Where(s => s.DepotId == depot_id)
            .First(); // èŽ·å–ç¬¬ä¸€æ¡åŒ¹é…è®°å½•
        // å¦‚果未查询到结果(itemInfo为null),则抛出异常,提示物料信息不存在或已禁用
        if (depotInfo is null) throw new Exception("该条码库存不存在仓库!");
        return depotInfo;
    }
    /// <summary>
    /// å˜æ›´åº“位
    /// </summary>
    /// <param name="unity"></param>
    /// <returns></returns>
    /// <exception cref="Exception"></exception>
    public dynamic ChangeDepotSection(dynamic unity)
    {
        // å­˜å‚¨è¿‡ç¨‹è¾“出信息
        var _strMsg = "";
        // å­˜å‚¨è¿‡ç¨‹è¾“出的数量(用于判断变更是否成功)
        var _intSum = "";
        // å­˜å‚¨è¿‡ç¨‹è¾“出的新库位代码
        var _NewDepotSectionCode = ""; // æ–°åº“位代码
        // åˆ›å»ºSQL连接,使用配置的连接字符串
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            //if (string.IsNullOrEmpty(query.barcode?.ToString()))
            //throw new ArgumentException("物料条码不能为空", nameof(query.barcode));
            if (string.IsNullOrEmpty(unity.userName?.ToString()))
                throw new ArgumentException("用户名不允许为空", nameof(unity.userName));
            if (string.IsNullOrEmpty(unity.OldDepotSectionCode?.ToString()))
                throw new ArgumentException("原库位不允许为空", nameof(unity.OldDepotSectionCode));
            if (string.IsNullOrEmpty(unity.NewDepotSectionCode?.ToString()))
                throw new ArgumentException("新库位不允许为空", nameof(unity.NewDepotSectionCode));
            if (string.IsNullOrEmpty(unity.barcode?.ToString()))
                throw new ArgumentException("物料条码不允许为空", nameof(unity.barcode));
            //if (unity.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
            //if (unity.OldDepotSectionCode.IsNullOrEmpty()) throw new Exception("原库位不允许为空");
            //if (unity.NewDepotSectionCode.IsNullOrEmpty()) throw new Exception("新库位不允许为空");
            //if (unity.barcode.IsNullOrEmpty()) throw new Exception("物料条码不允许为空");
            // åˆ›å»ºSQL命令,指定要执行的存储过程
            using (var cmd = new SqlCommand("[prc_pda_change_depot]", conn))
            {
                try
                {
                    // æ‰“开数据库连接
                    conn.Open();
                    // è®¾ç½®å‘½ä»¤ç±»åž‹ä¸ºå­˜å‚¨è¿‡ç¨‹
                    cmd.CommandType = CommandType.StoredProcedure;
                    // æž„造存储过程参数数组
                    SqlParameter[] parameters =
                    {
                    // è¾“出参数:返回信息
                    new("@outMsg", SqlDbType.NVarChar, 2000),
                    // è¾“出参数:返回数量
                    new("@outSum", SqlDbType.Int),
                    // è¾“出参数:返回新库位代码
                    new("@new_depotSectionsCode", SqlDbType.NVarChar, 300),
                    // è¾“入参数:操作用户
                    new SqlParameter("@c_user", unity.userName?.ToString() ?? ""),
                    // è¾“入参数:原条码
                    new SqlParameter("@p_barcode", unity.barcode?.ToString() ?? ""),
                    // è¾“入参数:原库位代码
                    new("@old_depotSectionsCode", unity.OldDepotSectionCode?.ToString() ??""),
                    // è¾“入参数:新库位代码
                    new("@new_depotSectionsCode_input", unity.NewDepotSectionCode?.ToString() ??""),
                    // è¾“入参数:仓库代码
                    new("@DepotCode", unity.DepotCode) { Value = unity.DepotCode ?? "" },
                    // è¾“入参数:仓库id
                    new SqlParameter("@DepotId", (int?)unity.DepotId ?? (object)DBNull.Value)
                };
                    // è®¾ç½®è¾“出参数方向
                    parameters[0].Direction = ParameterDirection.Output;
                    parameters[1].Direction = ParameterDirection.Output;
                    parameters[2].Direction = ParameterDirection.Output;
                    // æ·»åŠ æ‰€æœ‰å‚æ•°åˆ°å‘½ä»¤å¯¹è±¡
                    foreach (var parameter in parameters)
                        cmd.Parameters.Add(parameter);
                    // æ‰§è¡Œå­˜å‚¨è¿‡ç¨‹
                    cmd.ExecuteNonQuery();
                    // èŽ·å–å­˜å‚¨è¿‡ç¨‹è¾“å‡ºå‚æ•°çš„å€¼
                    _strMsg = parameters[0].Value.ToString();    // è¿”回信息
                    _intSum = parameters[1].Value.ToString();    // è¿”回数量
                    _NewDepotSectionCode = parameters[2].Value.ToString();     // æ–°åº“位代码
                    // åˆ¤æ–­å˜æ›´ç»“果,如果数量小于等于0,则表示变更失败,抛出异常并返回错误信息
                    var result = Convert.ToInt32(_intSum);
                    if (result <= 0) throw new Exception(_strMsg);
                    // ä½¿ç”¨åŒ¿åå¯¹è±¡è€Œä¸æ˜¯ dynamic? æ›´åˆé€‚
                    var dto = new
                    {
                        barcode = unity.barcode,
                        OldDepotSectionCode = unity.OldDepotSectionCode,
                        NewDepotSectionCode = _NewDepotSectionCode
                    };
                    return dto;
                }
                catch (Exception ex)
                {
                    // æ•获异常并抛出,保留原始异常信息
                    throw new Exception(ex.Message);
                }
                finally
                {
                    // å…³é—­æ•°æ®åº“连接
                    conn.Close();
                }
            }
        }
    }
    /*ProductionPickDto、WarehouseQuery有过添加
    public string? OldDepotSectionCode { get; set; }    //旧库位编码
    public string? NewDepotSectionCode { get; set; }    //新库位编码
    ProductionPickDto有过添加
    public int? DepotId { get; set; }    //仓库id
     */
}