wanshenmean
2026-03-30 894f6a1d5204ee40ef41c61da32820bd1178021e
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
using SqlSugar;
using System.Dynamic;
using System.Reflection;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.DB.Models;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StockService
{
    public partial class StockViewService : IStockViewService
    {
        private readonly SqlSugarClient _dbBase;
 
        public StockViewService(IUnitOfWorkManage unitOfWorkManage)
        {
            _dbBase = unitOfWorkManage.GetDbClient();
        }
 
        public virtual PageGridData<StockViewDTO> GetPageData(PageDataOptions options)
        {
            string where = options.ValidatePageOptions(typeof(StockViewDTO).GetProperties());
            int totalCount = 0;
 
            var list = _dbBase.Queryable<Dt_StockInfo>()
                .InnerJoin<Dt_LocationInfo>((b, a) => a.LocationCode == b.LocationCode)
                .WhereIF(!string.IsNullOrEmpty(where), where)
                .Select((b, a) => new StockViewDTO
                {
                    LocationCode = b.LocationCode,
                    Column = a.Column,
                    CreateDate = b.CreateDate,
                    Creater = b.Creater,
                    Depth = a.Depth,
                    EnableStatus = a.EnableStatus,
                    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,
                })
                .ToPageList(options.Page, options.Rows, ref totalCount);
 
            return new PageGridData<StockViewDTO>(totalCount, list);
        }
 
        public virtual object GetDetailPage(PageDataOptions pageData)
        {
            if (pageData.Value == null)
                return new PageGridData<object>(total: 0, null);
 
            var propertyInfo = typeof(StockViewDTO).GetProperties()
                .FirstOrDefault(x => x.GetCustomAttribute<Navigate>() != null);
 
            if (propertyInfo == null)
                return new PageGridData<object>(total: 0, null);
 
            var detailType = propertyInfo.PropertyType.GetGenericArguments()[0];
            var navigate = propertyInfo.GetCustomAttribute<Navigate>();
 
            if (navigate == null)
                return new PageGridData<object>(total: 0, null);
 
            int totalCount = 0;
            var list = _dbBase.Queryable(detailType.Name, "detail")
                .Where(navigate.GetName(), "=", pageData.Value)
                .ToPageList(pageData.Page, pageData.Rows, ref totalCount);
 
            return new PageGridData<ExpandoObject>(totalCount, list);
        }
    }
}