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
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using iWare.Wms.Core;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
 
namespace iWare.Wms.Application
{
    /// <summary>
    /// 端拾器小车类型信息服务
    /// </summary>
    [ApiDescriptionSettings("基础信息", Name = "WmsContainerType", Order = 100)]
    [Route("api/[Controller]")]
    public class WmsContainerTypeService : IDynamicApiController, ITransient
    {
        private readonly IRepository<WmsContainerType, MasterDbContextLocator> _wmsContainerTypeRep;
 
 
        public WmsContainerTypeService(
            IRepository<WmsContainerType, MasterDbContextLocator> wmsContainerTypeRep
        )
        {
            _wmsContainerTypeRep = wmsContainerTypeRep;
        }
 
        /// <summary>
        /// 分页查询端拾器小车类型信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<PageResult<WmsContainerTypeOutput>> Page([FromQuery] WmsContainerTypeSearch input)
        {
            var wmsContainerTypes = await _wmsContainerTypeRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.WareContainerTypeCode), u => u.WareContainerTypeCode == input.WareContainerTypeCode)
                                     .Where(!string.IsNullOrEmpty(input.WareContainerTypeName), u => u.WareContainerTypeName == input.WareContainerTypeName)
                                     .Where(!string.IsNullOrEmpty(input.LocationType), u => u.LocationType == input.LocationType)
                                     .Where(input.Status != null, u => u.Status == input.Status)
                                     .OrderBy(PageInputOrder.OrderBuilder<WmsContainerTypeSearch>(input))
                                     .ProjectToType<WmsContainerTypeOutput>()
                                     .ToADPagedListAsync(input.PageNo, input.PageSize);
            return wmsContainerTypes;
        }
 
        /// <summary>
        /// 增加端拾器小车类型信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task Add(AddWmsContainerTypeInput input)
        {
            //string str = "";
            //for (int i = 0; i < input.LocationType.Count; i++)
            //{
            //    str = str + input.LocationType[i] + ",";
            //}
            //WmsContainerType wmsContainerType = new WmsContainerType()
            //{
            //    WareContainerTypeCode = input.WareContainerTypeCode,
            //    WareContainerTypeName = input.WareContainerTypeName,
            //    Length = input.Length,
            //    LocationType = str.Trim(','),
            //    Height = input.Height,
            //    Width = input.Width,
            //    Status = input.Status
            //};
            var isExist = await _wmsContainerTypeRep.AnyAsync(n => n.WareContainerTypeCode == input.WareContainerTypeCode);
            if (isExist) throw Oops.Oh("存在的相同的类型编码!");
 
            var wmsContainerType = input.Adapt<WmsContainerType>();
            await _wmsContainerTypeRep.InsertAsync(wmsContainerType);
        }
 
        /// <summary>
        /// 删除端拾器小车类型信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task Delete(DeleteWmsContainerTypeInput input)
        {
            var wmsContainerType = await _wmsContainerTypeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
            await _wmsContainerTypeRep.DeleteAsync(wmsContainerType);
        }
 
        /// <summary>
        /// 更新端拾器小车类型信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("edit")]
        public async Task Update([FromBody] UpdateWmsContainerTypeInput input)
        {
            var isExist = await _wmsContainerTypeRep.AnyAsync(n => n.WareContainerTypeCode == input.WareContainerTypeCode && n.Id != input.Id);
            if (isExist) throw Oops.Oh("存在的相同的类型编码!");
            //var isExist = await _wmsContainerTypeRep.AnyAsync(u => u.Id == input.Id, false);
            //if (!isExist) throw Oops.Oh(ErrorCode.D3000);
            //string str = "";
            //for (int i = 0; i < input.LocationType.Count; i++)
            //{
            //    str = str + input.LocationType[i] + ",";
            //}
            //WmsContainerType wmsContainerType = new WmsContainerType()
            //{
            //    WareContainerTypeCode = input.WareContainerTypeCode,
            //    WareContainerTypeName = input.WareContainerTypeName,
            //    Length = input.Length,
            //    LocationType = str.Trim(','),
            //    Height = input.Height,
            //    Width = input.Width,
            //    Status = input.Status
            //};
            var wmsContainerType = input.Adapt<WmsContainerType>();
            await _wmsContainerTypeRep.UpdateAsync(wmsContainerType, ignoreNullValues: true);
        }
 
        /// <summary>
        /// 获取端拾器小车类型信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public async Task<WmsContainerTypeOutput> Get([FromQuery] QueryeWmsContainerTypeInput input)
        {
            return (await _wmsContainerTypeRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WmsContainerTypeOutput>();
        }
 
        ///// <summary>
        ///// 获取端拾器小车类型信息列表
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpGet("list")]
        //public async Task<List<WmsContainerTypeOutput>> List([FromQuery] WmsContainerTypeInput input)
        //{
        //    return await _wmsContainerTypeRep.DetachedEntities.ProjectToType<WmsContainerTypeOutput>().ToListAsync();
        //}
 
 
        /// <summary>
        /// 获取容器类型列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("fkWmsContainerType")]
        public async Task<dynamic> FkWmsMaterialList()
        {
            var list = await _wmsContainerTypeRep.DetachedEntities.ToListAsync();
            return list.Select(e => new { Code = e.WareContainerTypeCode, Name = e.WareContainerTypeName });
        }
    }
}