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
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 JiepeiWMS.Common.Enums;
using JiepeiWMS.Common.Helper;
using JiepeiWMS.Extends;
using JiepeiWMS.IServices;
using JiepeiWMS.Model;
using JiepeiWMS.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
 
namespace JiepeiWMS.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Permissions.Name)]
    public class WMInInventoryController : ControllerBase
    {
        /// <summary>
        /// 入库单管理
        /// </summary>
        private readonly IWMInInventoryServices _wMInInventoryServices;
        private readonly IWMInInventoryInfoServices _wMInInventoryInfoServices;
        private readonly ISysUserInfoServices _sysUserInfoServices;
        private readonly IDepartmentServices _departmentServices;
        private readonly IWMWareHouseServices _wMWareHouseServices;
        private readonly IWMSupplierServices _wMSupplierServices;
        private readonly IWMProductListServices _wMProductListServices;
        private readonly IWMProductSpecServices _wMProductSpecServices;
        private readonly IWMPurchaseQuoteDetailServices _wMPurchaseQuoteDetail;
        private readonly IWMProductLocationServices _wMProductLocationServices;
 
        public WMInInventoryController(
            IWMInInventoryServices WMInInventoryServices,
            IWMInInventoryInfoServices WMInInventoryInfoServices,
            ISysUserInfoServices sysUserInfoServices,
            IDepartmentServices DepartmentServices,
            IWMWareHouseServices WMWareHouseServices,
            IWMSupplierServices WMSupplierServices,
            IWMProductListServices WMProductListServices,
            IWMProductSpecServices WMProductSpecServices,
            IWMPurchaseQuoteDetailServices BllWMPurchaseQuoteDetail,
            IWMProductLocationServices WMProductLocationServices)
        {
            _wMInInventoryServices = WMInInventoryServices;
            _wMInInventoryInfoServices = WMInInventoryInfoServices;
            _sysUserInfoServices = sysUserInfoServices;
            _departmentServices = DepartmentServices;
            _wMWareHouseServices = WMWareHouseServices;
            _wMSupplierServices = WMSupplierServices;
            _wMProductListServices = WMProductListServices;
            _wMProductSpecServices = WMProductSpecServices;
            _wMPurchaseQuoteDetail = BllWMPurchaseQuoteDetail;
            _wMProductLocationServices = WMProductLocationServices;
        }
 
        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="page">页数</param>
        /// <param name="department">部门</param>
        /// <param name="wareHouse">仓库</param>
        /// <param name="supplier">供应商</param>
        /// <param name="outInType">出入库类型</param>
        /// <param name="intPageSize">条数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<PageModel<WMInInventory>>> Index(string department = "", string wareHouse = "", string supplier = "", string outInType = "", int page = 1, int intPageSize = 20)
        {
            if (string.IsNullOrWhiteSpace(department))
                department = "";
            if (string.IsNullOrWhiteSpace(wareHouse))
                wareHouse = "";
            if (string.IsNullOrWhiteSpace(supplier))
                supplier = "";
            if (string.IsNullOrWhiteSpace(outInType))
                outInType = "";
 
            var PageList = await _wMInInventoryServices.GetWMInInventoryPage(page, intPageSize, department, wareHouse, supplier, outInType);
 
            return new MessageModel<PageModel<WMInInventory>>()
            {
                msg = "获取成功",
                success = PageList.dataCount >= 0,
                response = PageList
            };
        }
 
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<WMInInventory>> Get(int id = 0)
        {
            return new MessageModel<WMInInventory>()
            {
                msg = "获取成功",
                success = true,
                response = await _wMInInventoryServices.QueryById(id)
            };
        }
 
        /// <summary>
        /// 入库单详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<WMInInventory>> Detail(int Id = 0)
        {
            var model = await _wMInInventoryServices.QueryById(Id);
            if (model != null)
            {
                //采购员
                var UserInfoModel = await _sysUserInfoServices.QueryById(model.EmployeeId);
                if (UserInfoModel != null)
                    model.EmployeeName = UserInfoModel.uRealName;
 
                //部门名称
                var DepartmentModel = await _departmentServices.QueryById(model.DepartmentId);
                if (DepartmentModel != null)
                    model.DepartmentName = DepartmentModel.Name;
 
                //仓库名称
                var WareHouseModel = await _wMWareHouseServices.QueryById(model.WareHouseId);
                if (WareHouseModel != null)
                    model.WareHouseName = WareHouseModel.Name;
 
                //供应商
                var SupplierModel = await _wMSupplierServices.QueryById(model.SupplierId);
                if (SupplierModel != null)
                    model.SupplierName = SupplierModel.Name;
 
                var dicType = typeof(EnumWMInInventoryType)._GetValueDescriptionDicFromEnumType<EnumWMInInventoryType>();
                string name;
                model.OutInTypeName = dicType.TryGetValue((EnumWMInInventoryType)model.OutInType, out name) ? name : string.Empty;
 
                model.InInventoryInfoList = await _wMInInventoryInfoServices.Query(w => w.InInventoryId == model.Id);
                foreach (var item in model.InInventoryInfoList)
                {
                    //商品信息
                    var ProductModel = await _wMProductListServices.GetModel(w => w.Id == item.ProductId);
                    if (ProductModel != null)
                    {
                        item.ProductName = ProductModel.Name;
                        item.ProductCode = ProductModel.Code;
                        //计算总价
                        item.ActualAmount = item.StorageNum.Value * item.Price;
                        //商品规格
                        var ProductSpecModel = await _wMProductSpecServices.GetModel(w => w.Id == ProductModel.SpecIds);
                        if (ProductSpecModel != null)
                        {
                            item.ProductSpec = ProductSpecModel.Name;
                        }
                    }
 
                    //库位
                    var ProductLocationModel = await _wMProductLocationServices.QueryById(item.LocationId);
                    if (ProductLocationModel != null)
                        item.LocationName = ProductLocationModel.LocationName;
                }
            }
 
            return new MessageModel<WMInInventory>()
            {
                msg = "获取成功",
                success = true,
                response = model
            };
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public async Task<MessageModel<string>> Delete(int id = 0)
        {
            var data = new MessageModel<string>();
            if (id > 0)
            {
                var detail = await _wMInInventoryServices.QueryById(id);
 
                if (detail != null)
                {
                    data.success = await _wMInInventoryServices.Update(detail);
                    if (data.success)
                    {
                        data.msg = "删除成功";
                        data.response = detail?.Id.ObjToString();
                    }
                }
            }
 
            return data;
        }
    }
}