1
heshaofeng
2026-03-16 569b9900086f06fbd986f69534c8d5af54c4d55b
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using SqlSugar;
using WIDESEA_Common.StockEnum;
using System.Collections.Generic;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.HttpContextUser;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StockService
{
    public partial class StockInfoDetailService : ServiceBase<Dt_StockInfoDetail, IRepository<Dt_StockInfoDetail>>, IStockInfoDetailService
    {
        public StockInfoDetailService(IRepository<Dt_StockInfoDetail> BaseDal, IRepository<Dt_StockInfo> stockinfoRepository) : base(BaseDal)
        {
            _stockinfoRepository = stockinfoRepository;
        }
 
        public IRepository<Dt_StockInfo> _stockinfoRepository;
        public IRepository<Dt_StockInfoDetail> Repository => BaseDal;
 
        public bool ExistBarcodes(string barcode)
        {
            return BaseDal.QueryFirst(x => x.Barcode == barcode) != null;
        }
 
        public bool ExistBarcodes(List<string> barcodes)
        {
            return BaseDal.QueryFirst(x => !string.IsNullOrEmpty(x.Barcode) && barcodes.Contains(x.Barcode)) != null;
        }
 
        public PageGridData<StockInfoDetailWithPalletDto> GetPageData2(PageDataOptions options)
        {
 
            var sugarQueryable = Db.Queryable<Dt_StockInfoDetail>().InnerJoin<Dt_StockInfo>((detail, item) => detail.StockId == item.Id)
                .Where((detail, item) => item.StockStatus == StockStatusEmun.入库完成.ObjToInt() || item.StockStatus == StockStatusEmun.出库完成.ObjToInt());
 
            Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
            List<OrderByModel> orderByModels = new List<OrderByModel>();
            foreach (var item in orderbyDic)
            {
                if (item.Key.ToLower() == "id")
                {
                    OrderByModel orderByModel = new()
                    {
                        FieldName = "detail." + item.Key,
                        OrderByType = item.Value
                    };
                    orderByModels.Add(orderByModel);
                }
                else
                {
                    OrderByModel orderByModel = new()
                    {
                        FieldName = item.Key,
                        OrderByType = item.Value
                    };
                    orderByModels.Add(orderByModel);
                }
 
            }
            int totalCount = 0;
            List<SearchParameters> searchParametersList = new List<SearchParameters>();
 
 
            if (!string.IsNullOrEmpty(options.Wheres))
            {
                try
                {
                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                    if (searchParametersList != null && searchParametersList.Any())
                    {
                        foreach (var param in searchParametersList)
                        {
                            if (param.Name.Equals(nameof(Dt_StockInfo.PalletCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                sugarQueryable = sugarQueryable.Where((detail, item) => item.PalletCode.Contains(param.Value));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.MaterielCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.MaterielCode.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.MaterielName).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.MaterielName.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.OrderNo).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.OrderNo.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.BatchNo).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.BatchNo.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.Barcode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.Barcode.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.MaterielCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.MaterielCode.Contains(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.Status).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.Status.Equals(queryValue));
                            }
                            if (param.Name.Equals(nameof(Dt_StockInfoDetail.WarehouseCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string queryValue = param.Value.ToString().Trim();
                                sugarQueryable = sugarQueryable.Where((detail, item) => detail.WarehouseCode.Equals(queryValue));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }          
            var data = sugarQueryable
             .OrderBy(orderByModels)
             .Select((detail, item) => new StockInfoDetailWithPalletDto
             {
                 Id = detail.Id,
                 StockId = detail.StockId,
                 MaterielCode = detail.MaterielCode,
                 MaterielName = detail.MaterielName,
                 OrderNo = detail.OrderNo,
                 BatchNo = detail.BatchNo,
                 ProductionDate = detail.ProductionDate,
                 EffectiveDate = detail.EffectiveDate,
                 SerialNumber = detail.SerialNumber,
                 StockQuantity = detail.StockQuantity,
                 OutboundQuantity = detail.OutboundQuantity,
                 Status = detail.Status,
                 Unit = detail.Unit,
                 InboundOrderRowNo = detail.InboundOrderRowNo,
                 SupplyCode = detail.SupplyCode,
                 WarehouseCode = detail.WarehouseCode,
                 Barcode = detail.Barcode,
                 BusinessType = detail.BusinessType,
                 Remark = detail.Remark,
                 Creater = detail.Creater,
                 CreateDate = detail.CreateDate,
                 Modifier = detail.Modifier,
                 ModifyDate = detail.ModifyDate,
                 PalletCode = item.PalletCode,
                 LocationCode = item.LocationCode,
                 ValidDate = detail.ValidDate,
 
 
             })
             .ToPageList(options.Page, options.Rows, ref totalCount);
 
 
            return new PageGridData<StockInfoDetailWithPalletDto>(totalCount, data);
 
        }
 
 
        public async Task<WebResponseContent> LockOrUpLockStockDetail(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var details = await BaseDal.QueryDataAsync(x => saveModel.DelKeys.Contains(x.Id));
 
                bool flag = Convert.ToBoolean(saveModel.Extra);
 
                details.ForEach(x => x.Status = flag ? StockStatusEmun.手动冻结.ObjToInt(): StockStatusEmun.手动解锁.ObjToInt());
 
                await BaseDal.UpdateDataAsync(details);
 
                return content.OK(flag ? "冻结成功!" : "解锁成功!");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }
}