1
647556386
2 天以前 3c506974e141024ed26a0c348d896c70ea42891b
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
using SqlSugar;
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)
        {
            // 1. 获取基础分页数据
            ISugarQueryable<Dt_StockInfoDetail> sugarQueryable1 = BaseDal.Db.Queryable<Dt_StockInfoDetail>();
            ISugarQueryable<Dt_StockInfo> sugarQueryable = BaseDal.Db.Queryable<Dt_StockInfo>();
 
            if (!string.IsNullOrEmpty(options.Wheres))
            {
                try
                {
                    List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                    if (searchParametersList?.Any() == true)
                    {
                        foreach (var param in searchParametersList)
                        {
                            if (param.Name.Equals(nameof(Dt_StockInfo.PalletCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
                                && !string.IsNullOrEmpty(param.Value?.ToString()))
                            {
                                string palletCode = param.Value.ToString().Trim();
                                var targetStock = _stockinfoRepository.QueryFirst(x => x.PalletCode == palletCode);
 
                                if (targetStock != null)
                                {
                                    sugarQueryable1 = sugarQueryable1.Where(x => x.StockId == targetStock.Id);
                                }
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            EntityProperties.ValidatePageOptions(options, ref sugarQueryable1);
            ISugarQueryable<StockInfoDetailWithPalletDto> list = sugarQueryable1.InnerJoin(sugarQueryable, (b, a) => a.Id == b.StockId).Select((b, a) => new StockInfoDetailWithPalletDto
            {
                    Id = b.Id,
                    StockId = b.StockId,
                    MaterielCode = b.MaterielCode,
                    MaterielName = b.MaterielName,
                    OrderNo = b.OrderNo,
                    BatchNo = b.BatchNo,
                    ProductionDate = b.ProductionDate,
                    EffectiveDate = b.EffectiveDate,
                    SerialNumber = b.SerialNumber,
                    StockQuantity = b.StockQuantity,
                    OutboundQuantity = b.OutboundQuantity,
                    Status = b.Status,
                    Unit = b.Unit,
                    InboundOrderRowNo = b.InboundOrderRowNo,
                    SupplyCode = b.SupplyCode,
                    WarehouseCode = b.WarehouseCode,
                    Barcode = b.Barcode,
                    BusinessType = b.BusinessType,
                    Remark = b.Remark,
                    Creater = b.Creater,
                    CreateDate = b.CreateDate,
                    Modifier = b.Modifier,
                    ModifyDate = b.ModifyDate,
                    PalletCode = a.PalletCode??"无托盘编号"
                });
 
 
            int totalCount = 0;
            var stockViewDTOs = list.ToPageList(options.Page, options.Rows, ref totalCount);
            return new PageGridData<StockInfoDetailWithPalletDto>(totalCount, stockViewDTOs);
            
        }
 
    }
    }