zhaowc
2025-05-20 d09a1552e45e6cfc8f83c0249cd296b8706c0dc2
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Model.ModelDto.BllQualityDto;
using Model.ModelVm;
using SqlSugar;
using WMS.DAL;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.BllQualityEntity;
using WMS.Entity.Context;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.IBllQualityServer;
 
namespace WMS.BLL.BllQualityServer
{
    public class QualityInspectServer : DbHelper<BllQualityInspect>, IQualityInspectServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public QualityInspectServer() : base(Db)
        {
        }
 
        #region 质检信息录入
 
        /// <summary>
        /// 获取质检物料信息
        /// </summary>
        /// <param name="model">质检信息实体模型</param>
        /// <returns></returns>
        public List<BllQualityInspectDto> GetBllQualityList(BllQualityInspect model)
        {
            string str = "select q.Id Id,q.InspectNo InspectNo,q.ASNNo ASNNo,q.LotNo LotNo,q.SupplierLot SupplierLot,q.SkuNo SkuNo,q.SkuName SkuName,q.Standard Standard,q.PassQty PassQty,q.FailQty FailQty,q.Origin Origin,q.InspectTime InspectTime,q.IsOut IsOut,q.Demo Demo,q.IsQualified IsQualified,q.IsDel IsDel,q.CreateTime CreateTime,u.RealName CreateUserName,q.UpdateTime UpdateTime,q.UpdateUser UpdateUserName from BllQualityInspect q left join SysUserInfor u on q.CreateUser = u.id where q.IsDel = @isdel";
 
            ////判断入库单号是否为空
            //if (!string.IsNullOrEmpty(model.ASNNo))
            //{
            //    str += " and q.ASNNo = @asnno";
            //}
            //判断物料号是否为空
            if (!string.IsNullOrEmpty(model.SkuNo))
            {
                str += " and q.SkuNo like @skuno";
            }
            //判断物料名称是否为空
            if (!string.IsNullOrEmpty(model.SkuName))
            {
                str += " and q.SkuName like @skuname";
            }
            //判断批次号是否为空
            if (!string.IsNullOrEmpty(model.LotNo))
            {
                str += " and q.LotNo = @lotno";
            }
            //判断是否合格状态是否为空
            if (!string.IsNullOrEmpty(model.IsQualified))
            {
                str += " and q.IsQualified = @isqualified";
            }
            //判断来源是否为空
            if (!string.IsNullOrEmpty(model.Origin))
            {
                str += " and q.Origin like @origin";
            }
 
            str += " order by q.CreateTime desc";
            List<BllQualityInspectDto> qualityList = Db.Ado.SqlQuery<BllQualityInspectDto>(str, new
            {
                isdel = "0", //是否删除
                asnno = model.ASNNo, //入库单号
                skuno = "%" + model.SkuNo + "%", //物料号
                skuname = "%" + model.SkuName + "%", //物料名称
                lotno = model.LotNo, //批次号
                isqualified = model.IsQualified, //是否合格
                origin=model.Origin//来源
            });
            return qualityList;
        }
 
 
        /// <summary>
        /// 添加物料质检信息
        /// </summary>
        /// <param name="model">质检信息实体模型</param>
        /// <returns></returns>
        public int InsertQuality(BllQualityInspect model)
        {
 
            //创建质检信息 需要 质检号、入库单号、物料号、批次号、是否合格
            //string str = "insert into BllQualityInspect values(@inspectno,@asnno,@lotno,@supplierlot,@skuno,@skuname,,@standard,@passqty,@failqty,@origin,@inspecttime,@isout,@isqualified,@isdel,@createtime,@createuser,@updatetime,@updateuser);";
 
            //验证质检号是否为空
            if (string.IsNullOrEmpty(model.InspectNo))
            {
                throw new Exception("质检号不可为空,请核查!");
            }
            //验证批次号是否为空
            if (string.IsNullOrEmpty(model.LotNo))
            {
                throw new Exception("批次号不可为空,请核查!");
            }
 
            model.Origin = "WMS"; //来源
            model.CreateTime = Db.GetDate(); //创建日期
            model.SkuNo = ""; //物料号
            model.SkuName = ""; //物料名称
            model.PassQty = 0; //合格数量
            model.FailQty = 0; //不合格数量
            model.Standard = ""; //规格
 
            //查找库存明细信息
            List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.LotNo == model.LotNo).ToList();
            foreach (var item in detail)
            {
                //判断合格状态是否合格
                if (model.IsQualified == "1")
                {
                    //合格
                    model.PassQty += item.Qty;
                    //修改库存明细合格状态
                    item.InspectStatus = "1"; //1合格
                }
                else //不合格
                {
                    //不合格
                    model.FailQty += item.Qty;
                    item.InspectStatus = "2"; //2不合格
                }
                Db.Updateable(item).ExecuteCommand();
            }
            var isquality = Db.Insertable(model).ExecuteCommand();
 
            return isquality;
        }
 
        /// <summary>
        /// 获取库存批次号集合
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public List<DataStockDetail> GetLotNoList()
        {
            try
            {
                var _list = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && !string.IsNullOrEmpty(w.LotNo)).ToList();
                return _list;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
 
    }
}