WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
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
 
using JiepeiWMS.IServices;
using JiepeiWMS.Model.Models;
using JiepeiWMS.Services.BASE;
using JiepeiWMS.IRepository.Base;
using System.Threading.Tasks;
using JiepeiWMS.Model;
using System.Linq.Expressions;
using System;
using JiepeiWMS.Extends;
using SqlSugar;
using JiepeiWMS.Common.Enums;
using JiepeiWMS.Common.Helper;
using JiepeiWMS.Common.HttpContextUser;
using System.Security.Claims;
 
namespace JiepeiWMS.Services
{
    public class WMInInventoryServices : BaseServices<WMInInventory>, IWMInInventoryServices
    {
        private readonly IBaseRepository<WMInInventory> _dal;
        private readonly ISysUserInfoServices _sysUserInfoServices;
        readonly IUser _user;
        public WMInInventoryServices(IBaseRepository<WMInInventory> dal,
            ISysUserInfoServices sysUserInfoServices,
            IUser user)
        {
            this._dal = dal;
            base.BaseDal = dal;
            _sysUserInfoServices = sysUserInfoServices;
            _user = user;
        }
 
        /// <summary>
        /// 获取入库单分页
        /// </summary>
        /// <returns></returns>
        public async Task<PageModel<WMInInventory>> GetWMInInventoryPage(int page, int intPageSize, string department = "", string wareHouse = "", string supplier = "", string outInType = "")
        {
            Expression<Func<WMInInventory, bool>> whereExpression = InInventory => InInventory.Id > 0;
 
            //获取角色信息,判断是否数据展示
            var role = string.Join(",", _user.GetClaimValueByType(ClaimTypes.Role));
            if (role.Contains("SuperAdmin") || role.Contains("超级管理员") || role.Contains("仓库管理员"))
            {
 
            }
            else
            {
                whereExpression = whereExpression.And(InInventory => InInventory.EmployeeId == _user.ID);
            }
            //筛选主体Id
            var userInfoModel = await _sysUserInfoServices.QueryById(_user.ID);
            if (userInfoModel != null)
            {
                whereExpression = whereExpression.And(InInventory => InInventory.SysOrgId == userInfoModel.SysOrgId);
            }
            if (!string.IsNullOrWhiteSpace(department))
            {
                whereExpression = whereExpression.And(InInventory => InInventory.DepartmentId == department.ObjToInt());
            }
            if (!string.IsNullOrWhiteSpace(wareHouse))
            {
                whereExpression = whereExpression.And(InInventory => InInventory.WareHouseId == wareHouse.ObjToInt());
            }
            if (!string.IsNullOrWhiteSpace(supplier))
            {
                whereExpression = whereExpression.And(InInventory => InInventory.SupplierId == supplier.ObjToInt());
            }
            if (!string.IsNullOrWhiteSpace(outInType))
            {
                whereExpression = whereExpression.And(InInventory => InInventory.OutInType == outInType.ObjToInt());
            }
 
            var PageList = await base.QueryTabsPage<WMInInventory, Department, WMSupplier, WMWareHouse, sysUserInfo, WMInInventory>(
                (InInventory, Department, Supplier, WareHouse, UserInfo) => new object[]
                {
                    JoinType.Left,InInventory.DepartmentId==Department.Id,
                    JoinType.Left,InInventory.SupplierId==Supplier.Id,
                    JoinType.Left,InInventory.WareHouseId==WareHouse.Id,
                    JoinType.Left,InInventory.AdminId==UserInfo.uID,
                },
                (InInventory, Department, Supplier, WareHouse, UserInfo) => new WMInInventory()
                {
                    Id = InInventory.Id,
                    InInventoryCode = InInventory.InInventoryCode,
                    OutInType = InInventory.OutInType,
                    EmployeeId = InInventory.EmployeeId,
                    WareHouseId = InInventory.WareHouseId,
                    DepartmentId = InInventory.DepartmentId,
                    SupplierId = InInventory.SupplierId,
                    InTime = InInventory.InTime,
                    Remark = InInventory.Remark,
                    CreateTime = InInventory.CreateTime,
                    SysOrgId = InInventory.SysOrgId,
                    WareHouseName = WareHouse.Name,
                    DepartmentName = Department.Name,
                    SupplierName = Supplier.Name,
                    AdminName = UserInfo.uRealName,
                },
                whereExpression,
                page,
                intPageSize,
                " InInventory.Id desc"
                );
 
            foreach (var item in PageList.data)
            {
                var dicType = typeof(EnumWMInInventoryType)._GetValueDescriptionDicFromEnumType<EnumWMInInventoryType>();
                string name;
                item.OutInTypeName = dicType.TryGetValue((EnumWMInInventoryType)item.OutInType, out name) ? name : string.Empty;
 
                var UserInfoModel = await _sysUserInfoServices.QueryById(item.EmployeeId);
                if (UserInfoModel != null)
                    item.EmployeeName = UserInfoModel.uRealName;
            }
 
            return PageList;
        }
 
    }
}