tjx
2025-10-13 e1e65422e4a53c54fe2c730b881a1ca220b0cafa
1111
已修改2个文件
365 ■■■■ 文件已修改
Controllers/Warehouse/MesCgthSqController.cs 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Warehouse/MesCgthSqManager.cs 300 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Controllers/Warehouse/MesCgthSqController.cs
@@ -26,7 +26,7 @@
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.GetMesCgthSq(RequestInfo);
            resultInfos.tbBillList = m.GetMesCgthSq();
            return new ResponseResult
            {
                status = 0,
@@ -39,7 +39,7 @@
            return ResponseResult.ResponseError(ex);
        }
    }
    /// <summary>
    ///     获取所有已经审核的申请单
    /// </summary>
@@ -50,7 +50,7 @@
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.GetSumItem(query,  RequestInfo);
            resultInfos.tbBillList = m.GetSumItem(query);
            return new ResponseResult
            {
                status = 0,
@@ -63,10 +63,10 @@
            return ResponseResult.ResponseError(ex);
        }
    }
    //ScanCode
    /// <summary>
    ///    采购退货
    ///     获取所有已经审核的申请单
    /// </summary>
    /// <returns></returns>
    [HttpPost("ScanCode")]
@@ -97,60 +97,7 @@
            return ResponseResult.ResponseError(ex);
        }
    }
    //ScanCode
    /// <summary>
    ///    采购验退
    /// </summary>
    /// <returns></returns>
    [HttpPost("ScanCgyt")]
    public ResponseResult ScanCgyt(dynamic query)
    {
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.ScanCgyt(query);
            resultInfos.YtItem = m.getYtItem(resultInfos.tbBillList.ytdh);
            resultInfos.YtBarInfo = m.getYtBarInfo(resultInfos.tbBillList.ytdh);
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    //ScanCode
    /// <summary>
    ///    采购退货删除
    /// </summary>
    /// <returns></returns>
    [HttpPost("deleteCgyt")]
    public ResponseResult deleteCgyt(dynamic query)
    {
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.deleteCgyt(query);
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
    [HttpPost("ScanCodeCF")]
    public ResponseResult ScanCodeCF(WarehouseQuery query)
    {
service/Warehouse/MesCgthSqManager.cs
@@ -12,79 +12,70 @@
public class MesCgthSqManager : Repository<MesCgthSq>
{
    public dynamic GetMesCgthSq(dynamic RequestInfo)
    public List<string> GetMesCgthSq()
    {
        var orgId = RequestInfo.OrgId;
        if (orgId == null)
            throw new Exception("组织不存在!");
        // 获取未完成的退料单号列表
        var parameters = new[]
        {
        new SugarParameter("@pi_orgId", orgId),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
        };
        try
        {
            // 返回单号字符串列表
            var blDetails = Db.Ado.SqlQuery<string>(
                "EXEC prc_pda_cgth_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
            return blDetails;
        }
        catch (Exception ex)
        {
            throw new Exception($"{ex.Message}");
        }
        return Db.Queryable<MesCgthSq>()
            .Where(s => s.Status == true)
            // .Where(s => s.Status == false)
            .OrderByDescending(s => s.CreateDate)
            .Select<string>(s => s.BillNo)
            .ToList();
    }
    public dynamic GetSumItem(WarehouseQuery query, dynamic RequestInfo)
    public ProductionPickDto GetSumItem(WarehouseQuery query)
    {
        // 验证申请单号是否为空
        if (string.IsNullOrEmpty(query.billNo))
            throw new Exception("请选单据号!");
            throw new Exception("申请单号为空");
        if (query == null)
            throw new ArgumentNullException(nameof(query), "参数对象不能为null");
        var mesInvItemOuts = base.GetSingle(it =>
            it.BillNo == query.billNo && it.Status == true);
        if (mesInvItemOuts == null) throw new Exception("采购退货申请单不存在或未审核");
        if (string.IsNullOrEmpty(query.billNo?.ToString()))
            throw new ArgumentException("单据号不能为空", nameof(query.billNo));
        // 构建查询明细数据的SQL语句
        var sql = string.Format(@"
        SELECT
            c.item_no ItemNo,
            c.item_name ItemName,
            c.item_model ItemModel,
            ISNULL(A.SQ_NUM, 0) FQty,
            ISNULL(A.YS_NUM, 0) SQty,
            ISNULL(A.SQ_NUM, 0) - ISNULL(A.YS_NUM, 0) DSQty,
            dbo.F_QX_GETRECODEPOTSE(A.ITEM_ID, '', '', '') as RecoKw
        FROM
            MES_CGTH_SQ_DETAIL A
            LEFT JOIN MES_CGTH_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 orgId = RequestInfo.OrgId;
        // 执行SQL查询获取明细列表
        var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql);
        if (orgId == null)
            throw new Exception("组织不存在!");
        // 获取未完成的发货通知单明细
        var parameters = new[]
{
        new SugarParameter("@billNo", query.billNo),
        new SugarParameter("@pi_orgId",orgId),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
    };
        try
        // 验证明细数据是否存在
        if (womdabs.Count < 1)
        {
            List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_cgth_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
            var items = blDetails.Where(x => x.DSQty > 0).ToList();    // 待扫物料
            var ysitems = blDetails.Where(x => x.SQty > 0).ToList();   // 已扫物料
            return new
            {
                items = items,
                ysitems = ysitems,
                allList = blDetails
            };
            throw new Exception("该采购退货申请单明细不存在");
        }
        catch (Exception ex)
        // 筛选待处理明细(DSQty > 0)
        var DS_list = womdabs.Where(s => s.DSQty > 0).ToList();
        // 筛选已处理明细(SQty > 0)
        var YS_list = womdabs.Where(s => s.SQty > 0).ToList();
        // 构建并返回DTO对象
        var dto = new ProductionPickDto
        {
            // 保留原有异常处理逻辑
            throw new Exception($"{ex.Message}");
        }
            // 注释:原计划号相关映射(当前未使用)
            // daa001 = womdaa.Daa001,
            // PlanNo = womcaa.Caa020,
            items = DS_list,
            Ysitems = YS_list
        };
        return dto;
    }
    public List<MesCgthSqDetail> GetItems(WarehouseQuery query)
@@ -99,11 +90,11 @@
            throw new ApplicationException("GUID转换错误"); // 如果转换失败,则抛出异常
        // 使用SqlSugar框架查询MesInvItemOutItems和MesItems表,根据ItemId进行内连接
        var mesInvItemOutItemsList = Db.Queryable<MesCgthSqDetail, MesItems>(
                (c, s) => new object[]
                {
                    JoinType.Inner, c.ItemId == s.Id // 内连接条件
                }).Where((c, s) => c.Mid == parsedGuid) // 根据ItemOutId过滤
        var mesInvItemOutItemsList = Db
            .Queryable<MesCgthSqDetail, MesItems>((c, s) => new object[]
            {
                JoinType.Inner, c.ItemId == s.Id // 内连接条件
            }).Where((c, s) => c.Mid == parsedGuid) // 根据ItemOutId过滤
            .Select<MesCgthSqDetail>((c, s) =>
                new MesCgthSqDetail // 选择并映射到MesInvItemOutItems对象
                {
@@ -134,7 +125,8 @@
        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("条码不允许为空");
            if (query.billNo.IsNullOrEmpty()) throw new Exception("领料单号不允许为空");
            if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
            using (var cmd = new SqlCommand("[prc_pda_CGTH]", conn))
            {
@@ -170,7 +162,7 @@
                    var dto = new ProductionPickDto
                    {
                        daa001 = query.billNo,
                        daa001 = query.daa001,
                        barcodeNum = barcodeNum,
                        splitNum = splitNum,
                        barcode = query.barcode,
@@ -195,14 +187,15 @@
    public ProductionPickDto ScanCodeCF(WarehouseQuery query)
    {
        if (query.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
        if (query.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空");
        // if (query.daa001.IsNullOrEmpty()) throw new Exception("领料单号不允许为空");
        if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
        if (query.Num is null or 0) throw new Exception("条码拆分数不允许为空或者为0");
        if (query.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空");
        var _strMsg = "";
        var _intSum = "";
        var _cfBar = "";//拆分后条码
        var _cfBar = ""; //拆分后条码
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            using (var cmd = new SqlCommand("[prc_pda_CGTH_CF]", conn))
@@ -217,6 +210,7 @@
                        new("@outSum", SqlDbType.NVarChar, 300),
                        new("@outCfBar", SqlDbType.NVarChar, 300),
                        new("@c_User", query.userName),
                        // new("@p_biLL_no", query.daa001),
                        new("@p_biLL_no", query.billNo),
                        new("@p_item_barcode", query.barcode),
                        new("@num", query.Num)
@@ -237,9 +231,9 @@
                    var dto = new ProductionPickDto
                    {
                        daa001 = query.billNo,
                        barcode = query.barcode,//原条码
                        cfBarcode = _cfBar//拆分后条码
                        daa001 = query.daa001,
                        barcode = query.barcode, //原条码
                        cfBarcode = _cfBar //拆分后条码
                    };
                    return dto;
@@ -254,165 +248,5 @@
                }
            }
        }
    }
    /// <summary>
    /// 采购扫码验退
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
    /// <exception cref="ArgumentException"></exception>
    /// <exception cref="Exception"></exception>
    public dynamic ScanCgyt(dynamic query)
    {
        if (query == null) throw new ArgumentNullException(nameof(query), "参数对象不能为 null");
        // 2. 使用 string.IsNullOrEmpty 直接判断字符串属性(避免 NullReferenceException)
        if (string.IsNullOrEmpty(query.userName?.ToString()))
            throw new ArgumentException("用户名不允许为空", nameof(query.userName));
        if (string.IsNullOrEmpty(query.barcode?.ToString()))
            throw new ArgumentException("采购物料条码不允许为空", nameof(query.barcode));
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            using (var cmd = new SqlCommand("prc_pda_scan_CGYT", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                var parameters = new SqlParameter[]
                {
                    new("@pi_user", SqlDbType.NVarChar, 100) { Value = query.userName },
                    new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = query.barcode },
                    new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
                    new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output },
                    new("@po_ygdh", SqlDbType.NVarChar, 200) { Direction = ParameterDirection.Output }
                };
                cmd.Parameters.AddRange(parameters);
                conn.Open();
                cmd.ExecuteNonQuery();
                var result = new
                {
                    result = parameters[3].Value.ToString(),
                    barcode = query.barcode,
                    ytdh = parameters[4].Value.ToString(),
                    msg = parameters[2].Value.ToString()
                };
                if (result.result == "-1")
                    throw new Exception(parameters[2].Value.ToString());
                return result;
            }
        }
    }
    /// <summary>
    /// 删除验退单
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
    /// <exception cref="ArgumentException"></exception>
    /// <exception cref="Exception"></exception>
    public dynamic deleteCgyt(dynamic query)
    {
        if (query == null) throw new ArgumentNullException(nameof(query), "参数对象不能为 null");
        // 2. 使用 string.IsNullOrEmpty 直接判断字符串属性(避免 NullReferenceException)
        if (string.IsNullOrEmpty(query.userName?.ToString()))
            throw new ArgumentException("用户名不允许为空", nameof(query.userName));
        if (string.IsNullOrEmpty(query.ytdh?.ToString()))
            throw new ArgumentException("追溯码不允许为空", nameof(query.ytdh));
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            using (var cmd = new SqlCommand("prc_pda_delete_CGYT", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                var parameters = new SqlParameter[]
                {
                    new("@pi_user", SqlDbType.NVarChar, 100) { Value = query.userName },
                    new("@pi_ytdh", SqlDbType.NVarChar, 100) { Value = query.ytdh },
                    new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
                    new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }
                };
                cmd.Parameters.AddRange(parameters);
                conn.Open();
                cmd.ExecuteNonQuery();
                var result = new
                {
                    result = parameters[3].Value.ToString(),
                    msg = parameters[2].Value.ToString(),
                };
                if (result.result == "-1")
                    throw new Exception(parameters[2].Value.ToString());
                return result;
            }
        }
    }
    /// <summary>
    /// 获取验退单已扫物料信息
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    public dynamic getYtItem(string ytdh)
    {
        if (string.IsNullOrEmpty(ytdh?.ToString()))
            throw new ArgumentException("验退单号不允许为空", nameof(ytdh));
        var sqlParams = new List<SugarParameter> { new("@ytdh", ytdh) };
        var sql1 = @"SELECT C.item_id,C.item_no,C.item_name,C.item_model,A.quantity
FROM MES_INV_ITEM_CGYT_ITEMS A
         LEFT JOIN MES_INV_ITEM_CGYT B ON A.item_cgyt_id = B.GUID
        LEFT JOIN MES_ITEMS C ON A.item_id = C.item_id
WHERE B.item_cgyt_no = @ytdh";
        var YtItem = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams);
        //if (YtItem.Count < 1)
        //{
        //    throw new Exception($"该验退单号{ytdh}物料明细不存在!");
        //}
        return YtItem;
    }
    /// <summary>
    /// 获取验退单已扫条码信息
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    public dynamic getYtBarInfo(string ytdh)
    {
        if (string.IsNullOrEmpty(ytdh?.ToString()))
            throw new ArgumentException("验退单号不允许为空", nameof(ytdh));
        var sqlParams = new List<SugarParameter> { new("@ytdh", ytdh) };
        var sql1 = @"SELECT C.item_id,C.item_no,C.item_name,C.item_model,A.quantity,A.ITEM_BARCODE
FROM MES_INV_ITEM_CGYT_C_DETAILS A
         LEFT JOIN MES_INV_ITEM_CGYT B ON A.item_cgyt_id = B.GUID
        LEFT JOIN MES_ITEMS C ON A.item_id = C.item_id
WHERE B.item_cgyt_no = @ytdh";
        var YtBarInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams);
        //if (YtBarInfo.Count < 1)
        //{
        //    throw new Exception($"该验退单号{ytdh}他们不存在!");
        //}
        return YtBarInfo;
    }
}