dengjunjie
2024-11-14 c827fe7b0c5b3b444d76ba0d96a2649c764630dd
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
using Org.BouncyCastle.Crypto;
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Enums;
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicRepository;
using WIDESEA_IStockRepository;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StockRepository
{
    public class StockInfoRepository : RepositoryBase<Dt_StockInfo>, IStockInfoRepository
    {
        public StockInfoRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage)
        {
        }
 
        public List<StockViewDTO> GetAllStockViews()
        {
            ISugarQueryable<Dt_LocationInfo> sugarQueryable = Db.Queryable<Dt_LocationInfo>();
            ISugarQueryable<Dt_StockInfo> sugarQueryable1 = Db.Queryable<Dt_StockInfo>();
 
            return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => new StockViewDTO
            {
                AreaId = a.AreaId,
                LocationCode = b.LocationCode,
                Column = a.Column,
                CreateDate = b.CreateDate,
                Creater = b.Creater,
                Depth = a.Depth,
                EnalbeStatus = a.EnableStatus,
                IsFull = b.IsFull,
                Layer = a.Layer,
                LocationName = a.LocationName,
                LocationStatus = a.LocationStatus,
                LocationType = a.LocationType,
                Modifier = b.Modifier,
                ModifyDate = b.ModifyDate,
                PalletCode = b.PalletCode,
                StockRemark = b.Remark,
                RoadwayNo = a.RoadwayNo,
                Row = a.Row,
                StockId = b.Id,
                StockStatus = b.StockStatus,
                Details = b.Details,
            }).Includes(x => x.Details).ToList();
        }
 
        public Dt_StockInfo GetStockInfo(string palletCode)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
        }
 
        public Dt_StockInfo GetStockInfo(int id)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => x.Id == id).Includes(x => x.Details).First();
        }
 
        public List<Dt_StockInfo> GetStockInfos(string materielCode)
        {
            return Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList();
            //ISugarQueryable<Dt_LocationInfo> sugarQueryable = Db.Queryable<Dt_LocationInfo>();
            //ISugarQueryable<Dt_StockInfo> sugarQueryable1 = Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode));
            //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).Includes(x => x.Details).ToList();
        }
        /// <summary>
        /// 根据货位编号获取组盘库存信息
        /// </summary>
        /// <param name="locationCodes"></param>
        /// <returns></returns>
        public List<Dt_StockInfo> LocationCodesGetStockInfos(List<string> locationCodes, StockStatusEmun statusEmun = StockStatusEmun.已入库)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode) /*&& x.StockStatus == statusEmun.ObjToInt()*/).Includes(x => x.Details).ToList();
        }
        public List<Dt_StockInfo> GetStockInfos(string materielCode, List<string> locationCodes)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList();
 
 
            //ISugarQueryable<Dt_LocationInfo> sugarQueryable = Db.Queryable<Dt_LocationInfo>().Where(x => locationCodes.Contains(x.LocationCode));
            //ISugarQueryable<Dt_StockInfo> sugarQueryable1 = Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode));
            //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).OrderBy(a => a.CreateDate).Includes(a => a.Details).ToList();
        }
 
        public List<Dt_StockInfo> GetStockInfosByIds(List<int> ids)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => ids.Contains(x.Id)).Includes(x => x.Details).ToList();
        }
 
        public List<Dt_StockInfo> GetStockInfosByPalletCodes(List<string> palletCodes)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => palletCodes.Contains(x.PalletCode)).Includes(x => x.Details).ToList();
        }
 
        public List<Dt_StockInfo> GetStockInfosExclude(string materielCode, List<string> palletCodes)
        {
            return Db.Queryable<Dt_StockInfo>().Where(x => !palletCodes.Contains(x.PalletCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList();
        }
 
        public bool UpdateDataWithDetail(Dt_StockInfo stockInfo)
        {
            return Db.UpdateNav(stockInfo).Include(x => x.Details).ExecuteCommand();
        }
        public List<object> GetBatchNoStockInfo(string materielCode)
        {
            List<object> strings = new List<object>();
            var Dt_StockInfoDetails = Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCode && x.Status == StockStatusEmun.已入库.ObjToInt()).ToList().GroupBy(x => x.BatchNo).Select(x => x.Key);
            foreach (var item in Dt_StockInfoDetails)
            {
                strings.Add(item);
            }
            return strings;
        }
 
        public Dt_StockInfo GetPalletStockInfo(string roadwayNo)
        {
            //ISugarQueryable<string> locationCodes = Db.Queryable<Dt_LocationInfo>().Where(x => x.RoadwayNo == roadwayNo && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (x.EnalbeStatus == LocationEnalbeStatusEnum.OnlyOut.ObjToInt() || LocationEnalbeStatusEnum.Normal.ObjToInt() == x.EnalbeStatus)).Select(x => x.LocationCode);
 
            return Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == StockStatusEmun.已入库.ObjToInt() && SqlFunc.Subqueryable<Dt_LocationInfo>().Where(v => v.LocationCode == x.LocationCode && v.RoadwayNo == roadwayNo && v.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (v.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || EnableStatusEnum.Normal.ObjToInt() == v.EnableStatus)).Any()).OrderBy(x => x.ModifyDate).First();
        }
    }
}