南骏 池
3 天以前 4f8d1da89bc7cf399e6d90d6230ad6c28114443a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using Masuit.Tools;
using MES.Service.Models;
using MES.Service.Modes;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.entity.Base;
using NewPdaSqlServer.util;
using OracleInternal.Sharding;
using SqlSugar;
using SqlSugar.Extensions;
using System.Data;
using System.Data.SqlClient;
 
namespace NewPdaSqlServer.service.Warehouse;
 
public class MesStrkManager : Repository<MesItemBl>
{
    /// <summary>
    ///     获取受托入库申请列表
    /// </summary>
    /// <returns>受托入库申请列表</returns>
    public List<string> GetStrkBillNo(WarehouseQuery query)
    {
        var list = Db.Queryable<MesShouTuo>()
            .Where(s => s.IsCheck == true && s.IsFinish == false)
            .Select(s => s.BillNo).ToList();
 
        return list;
    }
 
    /// <summary>
    ///     根据单号获取MES物料表明细
    /// </summary>
    /// <param name="query">仓库查询参数</param>
    /// <returns>物料明细列表</returns>
    public List<ItemDetailModel> GetMesItemDetailByBillNo(
        WarehouseQuery query)
    {
        // 关联查询物料表、物料明细表和物料基础信息表
        var mesItemTblDetails = Db
            .Queryable<MesShouTuo, MesShouTuoDetail, MesItems>(
                (a, b, c) => new JoinQueryInfos(
                    JoinType.Left,
                    a.Guid == b.PGuid,
                    JoinType.Left,
                    b.FMaterialId == c.Id.ToString())
            ).Where((a, b, c) => a.BillNo == query.billNo && a.IsCheck == true)
            .Select<ItemDetailModel>((a, b, c) => new ItemDetailModel
            {
                ItemNo = c.ItemNo,
                ItemName = c.ItemName,
                ItemModel = c.ItemModel,
                FQty = b.FQty, // 申请数量
                SQty = b.SQty, // 已扫数量
                Pid = b.PGuid.ToString(),
                FMaterialId = b.FMaterialId,
                Id = b.Guid.ToString()
            }).ToList();
 
        // 筛选出待退数量大于已退数量的记录
        //var itemTblDetails = mesItemTblDetails
        //    .Where(s => (s.Tld005 ?? 0) - (s.Tld006 ?? 0) > 0).ToList();
 
        return mesItemTblDetails;
    }
 
    /// <summary>
    /// 受托入库入库
    /// </summary>
    /// <param name="unity"></param>
    /// <returns></returns>
    /// <exception cref="Exception"></exception>
    public string XsthScanBarcode(WarehouseQuery unity)
    {
        var _strMsg = "";
        var _intSum = "";
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            if (unity.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
            if (unity.sectionCode.IsNullOrEmpty()) throw new Exception("库位编号不允许为空");
            if (unity.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
            if (unity.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空");
 
            using (var cmd = new SqlCommand("[prc_pda_inv_strk]", conn))
            {
                try
                {
                    conn.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter[] parameters =
                    {
                        new("@po_outMsg", SqlDbType.NVarChar, 300),
                        new("@po_outSum", SqlDbType.NVarChar, 300),
                        //new("@po_womInBarSum", SqlDbType.NVarChar, 300),
                        new("@pi_user", unity.userName),
                        new("@pi_barcode", unity.barcode),
                        new("@pi_sectionCode", unity.sectionCode),
                        new("@pi_billno", unity.billNo),
 
                    };
                    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();
 
                    var result = Convert.ToInt32(_intSum);
                    if (result <= 0) throw new Exception(_strMsg);
 
                    return _strMsg;
 
                    //return 0;
 
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
}