ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
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
using Admin.NET.Core.Helper.ExcelHelper;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using iWare.Wms.Core;
using iWare.Wms.Core.Enum;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
 
namespace iWare.Wms.Application
{
    /// <summary>
    /// 库位信息
    /// </summary>
    [ApiDescriptionSettings("基础信息", Name = "WmsPlace", Order = 100)]
    [Route("api/[Controller]")]
    public class WmsPlaceService : ControllerBase, IWmsPlaceService, IDynamicApiController, ITransient
    {
        private readonly IRepository<WmsPlace, MasterDbContextLocator> _wmsPlaceRep;
        private readonly IRepository<WmsArea> _wmsAreaRep;
        private readonly IRepository<v_empty_location> _v_empty_location;
 
        public WmsPlaceService(
            IRepository<WmsArea> wmsAreaRep,
            IRepository<WmsPlace, MasterDbContextLocator> wmsPlaceRep,
            IRepository<v_empty_location> v_empty_location
        )
        {
            _wmsAreaRep = wmsAreaRep;
            _wmsPlaceRep = wmsPlaceRep;
            _v_empty_location = v_empty_location;
        }
 
        /// <summary>
        /// 分页查询库位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<PageResult<WmsPlaceOutput>> Page([FromQuery] WmsPlaceSearch input)
        {
            var wmsPlaces = await _wmsPlaceRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.Placecode), u => EF.Functions.Like(u.PlaceCode, $"%{input.Placecode.Trim()}%"))
                                     .Where(input.Placestatus != null, u => u.PlaceStatus == input.Placestatus)
                                     .Where(input.Areaid > 0, u => u.AreaId == input.Areaid)
                                     .Where(input.Rowno != null, u => u.RowNo == input.Rowno)
                                     .Where(input.Columnno != null, u => u.ColumnNo == input.Columnno)
                                     .Where(input.Layerno != null, u => u.LayerNo == input.Layerno)
                                     .Where(input.Aisle != null, u => u.Aisle == input.Aisle)
                                     .Where(input.Islock != null, u => u.Islock == input.Islock)
                                     //.OrderBy(PageInputOrder.OrderBuilder<WmsPlaceSearch>(input))
                                     .OrderBy(u => u.PlaceCode)
                                     .ProjectToType<WmsPlaceOutput>()
                                     .ToADPagedListAsync(input.PageNo, input.PageSize);
            return wmsPlaces;
        }
 
        /// <summary>
        /// 增加库位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task Add([FromBody] AddWmsPlaceInput input)
        {
            var wmsPlace = input.Adapt<WmsPlace>();
            for (int t = 1; t <= wmsPlace.RowNo; t++)   //循环排
            {
                for (int i = 1; i <= wmsPlace.ColumnNo; i++)   //循环列
                {
                    for (int j = 1; j <= wmsPlace.LayerNo; j++)  //循环层
                    {
                        var model = new WmsPlace();
                        model.PlaceStatus = Core.Enum.PlaceStatus.KONGXIAN;
                        model.AreaId = wmsPlace.AreaId;
                        model.RowNo = t;
                        model.ColumnNo = i;
                        model.LayerNo = j;
                        model.Aisle = wmsPlace.Aisle;
                        model.Islock = YesOrNot.N;
                        model.Length = new decimal(1.2);
                        model.Width = new decimal(1.5);
                        model.Height = new decimal(1.8);
                        model.MaxWeight = new decimal(2.8);
                        model.HeightLevel = Core.Enum.Heightlevel.DI;
                        model.Priority = 0;
                        model.PlaceCode = String.Format("{0}-{1}-{2}-{3}", wmsPlace.Aisle, t.ToString().PadLeft(2, '0'), i.ToString().PadLeft(2, '0'), j.ToString().PadLeft(2, '0'));
                        model.DeepcellNo = t == 1 ? (int)DeepcellNoEnum.远伸 : (int)DeepcellNoEnum.近伸;
                        var isExit = await _wmsPlaceRep.AnyAsync(n => n.PlaceCode == model.PlaceCode);
                        if (!isExit) await _wmsPlaceRep.InsertAsync(model);
                    }
                }
            }
        }
 
        /// <summary>
        /// 删除库位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task Delete([FromBody] DeleteWmsPlaceInput input)
        {
            var wmsPlace = await _wmsPlaceRep.FirstOrDefaultAsync(u => u.Id == input.Id);
            await _wmsPlaceRep.DeleteAsync(wmsPlace);
        }
 
        /// <summary>
        /// 更新库位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("edit")]
        public async Task Update([FromBody] UpdateWmsPlaceInput input)
        {
            var isExist = await _wmsPlaceRep.AnyAsync(u => u.Id == input.Id, false);
            if (!isExist) throw Oops.Oh(ErrorCode.D3000);
 
            var wmsPlace = input.Adapt<WmsPlace>();
            await _wmsPlaceRep.UpdateAsync(wmsPlace, ignoreNullValues: true);
        }
 
        /// <summary>
        /// 获取库位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public async Task<WmsPlaceOutput> Get([FromQuery] QueryeWmsPlaceInput input)
        {
            return (await _wmsPlaceRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WmsPlaceOutput>();
        }
 
        /// <summary>
        /// 获取库位信息列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<List<WmsPlaceOutput>> List([FromQuery] WmsPlaceInput input)
        {
            return await _wmsPlaceRep.DetachedEntities.ProjectToType<WmsPlaceOutput>().ToListAsync();
        }
 
        /// <summary>
        /// 获取WmsArea列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("fkWmsArea")]
        public async Task<dynamic> FkWmsAreaList()
        {
            var list = await _wmsAreaRep.DetachedEntities.ToListAsync();
            return list.Select(e => new { Code = e.Id, Name = e.AreaName });
        }
 
        /// <summary>
        /// 获取空库位信息列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("emptylist")]
        public async Task<dynamic> EmptyList([FromQuery] WmsPlaceInput input)
        {
            return await _v_empty_location.DetachedEntities
                .Where(!string.IsNullOrEmpty(input.Placecode), u => u.PlaceCode == input.Placecode)
                .Where(!string.IsNullOrEmpty(input.ContainerTypeCode), u => u.WareLocationTypeCode == input.ContainerTypeCode)
                .Select(u => new { locationno = u.PlaceCode, locationname = u.DeepcellNo == Core.Enum.DeepcellNoEnum.近伸 ? "近伸" : "远伸" }).ToListAsync();
        }
 
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="input">筛选条件</param>
        /// <returns></returns>
        [HttpPost("download")]
        [AllowAnonymous]
        public async Task<ActionResult> Download([FromBody] WmsPlaceSearch input)
        {
            var dataRecords = await _wmsPlaceRep.DetachedEntities
                                    .Where(!string.IsNullOrEmpty(input.Placecode), u => EF.Functions.Like(u.PlaceCode, $"%{input.Placecode.Trim()}%"))
                                     .Where(input.Placestatus != null, u => u.PlaceStatus == input.Placestatus)
                                     .Where(input.Areaid > 0, u => u.AreaId == input.Areaid)
                                     .Where(input.Rowno != null, u => u.RowNo == input.Rowno)
                                     .Where(input.Columnno != null, u => u.ColumnNo == input.Columnno)
                                     .Where(input.Layerno != null, u => u.LayerNo == input.Layerno)
                                     .Where(input.Aisle != null, u => u.Aisle == input.Aisle)
                                     .Where(input.Islock != null, u => u.Islock == input.Islock)
                                     .OrderBy(u => u.PlaceCode)
                                     .ProjectToType<WmsPlaceExcel>().ToListAsync();
 
            var excelBaseResult = new Excel2003Result<WmsPlaceExcel>(dataRecords, "库位表格" + DateTime.Now.ToString("yyyyMMdd"), false, "生产记录");
            return File(excelBaseResult.GetExcelStream(), "application/vnd.ms-excel");
        }
    }
}