liuying
2025-09-24 16edbbe772e24eb71f6519558576d513e3cf2746
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
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.Extras.iWare.Wms.Util.LowCode.Front.Code;
using Furion.FriendlyException;
using iWare.Wms.Core;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SharpYaml;
using System.Linq.Dynamic.Core;
 
namespace iWare.Wms.Application
{
    /// <summary>
    /// 工件出库信息服务
    /// </summary>
    //[Route("api")]
    [ApiDescriptionSettings("自己的业务", Name = "WorkPieceOutbound", Order = 100)]
    [Route("api/[Controller]")]
    [DisableOpLog]
    public class WorkPieceOutboundService : IWorkPieceOutboundService, IDynamicApiController, ITransient
    {
        private readonly IRepository<WorkPieceOutbound, MasterDbContextLocator> _workPieceOutboundRep;
        private readonly IRepository<WorkPieceInfo, MasterDbContextLocator> _workPieceInfoRep;
        private readonly IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> _workPieceOutboundRecordRep;
 
        public WorkPieceOutboundService(
              IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> workPieceOutboundRecordRep,
            IRepository<WorkPieceInfo, MasterDbContextLocator> workPieceInfoRep,
            IRepository<WorkPieceOutbound, MasterDbContextLocator> workPieceOutboundRep
        )
        {
            _workPieceOutboundRecordRep = workPieceOutboundRecordRep;
            _workPieceInfoRep = workPieceInfoRep;
            _workPieceOutboundRep = workPieceOutboundRep;
        }
 
        /// <summary>
        /// 分页查询工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<PageResult<WorkPieceOutboundOutput>> Page([FromQuery] WorkPieceOutboundSearch input)
        {
            var workPieceOutbounds = await _workPieceOutboundRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.WorkPieceID), u => u.WorkPieceID.Contains(input.WorkPieceID))
                                     .Where(!string.IsNullOrEmpty(input.OP80NewCode), u => u.OP80NewCode.Contains(input.OP80NewCode))
                                     .Where(!string.IsNullOrEmpty(input.WorkPieceOutboundUserName), u => u.WorkPieceOutboundUserName.Contains(input.WorkPieceOutboundUserName))
                                     .Where(!string.IsNullOrEmpty(input.StartTimeBeginTime.ToString()), u => u.WorkPieceOutboundTime >= input.StartTimeBeginTime)
                                     .Where(!string.IsNullOrEmpty(input.StartTimeEndTime.ToString()), u => u.WorkPieceOutboundTime <= input.StartTimeEndTime)
                                     .OrderBy(PageInputOrder.OrderBuilder<WorkPieceOutboundSearch>(input))
                                     .ProjectToType<WorkPieceOutboundOutput>()
                                     .ToADPagedListAsync(input.PageNo, input.PageSize);
            return workPieceOutbounds;
        }
 
        /// <summary>
        /// 分页查询工件出库历史信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("pageForRecord")]
        public async Task<PageResult<WorkPieceOutboundRecord>> PageForRecord([FromQuery] WorkPieceOutboundSearch input)
        {
            var workPieceOutbounds = await _workPieceOutboundRecordRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.WorkPieceID), u => u.WorkPieceID.Contains(input.WorkPieceID))
                                     .Where(!string.IsNullOrEmpty(input.OP80NewCode), u => u.OP80NewCode.Contains(input.OP80NewCode))
                                     .Where(!string.IsNullOrEmpty(input.WorkPieceOutboundUserName), u => u.CreatedUserName.Contains(input.WorkPieceOutboundUserName))
                                     .Where(!string.IsNullOrEmpty(input.StartTimeBeginTime.ToString()), u => u.CreatedTime >= input.StartTimeBeginTime)
                                     .Where(!string.IsNullOrEmpty(input.StartTimeEndTime.ToString()), u => u.CreatedTime <= input.StartTimeEndTime)
                                     .OrderBy(PageInputOrder.OrderBuilder<WorkPieceOutboundSearch>(input))
                                     .ProjectToType<WorkPieceOutboundRecord>()
                                     .ToADPagedListAsync(input.PageNo, input.PageSize);
            return workPieceOutbounds;
        }
 
 
        /// <summary>
        /// 增加工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task Add(AddWorkPieceOutboundInput input)
        {
            var workPieceOutbound = input.Adapt<WorkPieceOutbound>();
            await _workPieceOutboundRep.InsertAsync(workPieceOutbound);
        }
 
        /// <summary>
        /// 删除工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task Delete(DeleteWorkPieceOutboundInput input)
        {
            var workPieceOutbound = await _workPieceOutboundRep.FirstOrDefaultAsync(u => u.Id == input.Id);
            await _workPieceOutboundRep.DeleteAsync(workPieceOutbound);
        }
 
        /// <summary>
        /// 更新工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("edit")]
        public async Task Update(UpdateWorkPieceOutboundInput input)
        {
            var isExist = await _workPieceOutboundRep.AnyAsync(u => u.Id == input.Id, false);
            if (!isExist) throw Oops.Oh(ErrorCode.D3000);
 
            var workPieceOutbound = input.Adapt<WorkPieceOutbound>();
            await _workPieceOutboundRep.UpdateAsync(workPieceOutbound, ignoreNullValues: true);
        }
 
        /// <summary>
        /// 获取工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public async Task<WorkPieceOutboundOutput> Get([FromQuery] QueryeWorkPieceOutboundInput input)
        {
            return (await _workPieceOutboundRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WorkPieceOutboundOutput>();
        }
 
        /// <summary>
        /// 获取工件出库信息列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<List<WorkPieceOutboundOutput>> List([FromQuery] WorkPieceOutboundInput input)
        {
            return await _workPieceOutboundRep.DetachedEntities.ProjectToType<WorkPieceOutboundOutput>().ToListAsync();
        }
 
        /// <summary>
        /// 撤销工件出库信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("revoke")]
        [UnitOfWork]
        public async Task Revoke(List<DeleteWorkPieceOutboundInput> input)
        {
            foreach (var item in input)
            {
                var workPieceOutbound = await _workPieceOutboundRep.FirstOrDefaultAsync(u => u.Id == item.Id);
                if (workPieceOutbound == null)
                {
                    throw Oops.Oh("工件入库信息不存在");
                }
                //workPieceOutbound.IsDeleted = true;
                //workPieceOutbound.Remark = workPieceOutbound.Remark ?? "" + "撤销入库";
                //await _workPieceOutboundRep.UpdateAsync(workPieceOutbound);
                await _workPieceOutboundRep.DeleteAsync(workPieceOutbound);
 
                var outBoundLog = new WorkPieceOutboundRecord
                {
                    OperationType = OutboundOperationType.撤销入库.ToString(),
                    WorkPieceID = workPieceOutbound?.WorkPieceID,
                    OP80NewCode = workPieceOutbound?.OP80NewCode,
 
                    CreatedUserId = CurrentUserInfo.UserId,
                    CreatedUserName = CurrentUserInfo.Name,
 
                    // CarNo = itemModel.CarNo,
                    Remark = "撤销入库",
 
                };
                await _workPieceOutboundRecordRep.InsertAsync(outBoundLog);
 
                var workPiece = await _workPieceInfoRep.FirstOrDefaultAsync(u => u.WorkPieceID == workPieceOutbound.WorkPieceID);
                if (workPiece != null)
                {
                    workPiece.OutPerson = CurrentUserInfo.Name;
                    workPiece.OutRemark = "撤销入库";
                    workPiece.OutTime = DateTime.Now;
                    workPiece.IsOut = false;
 
                    await _workPieceInfoRep.UpdateAsync(workPiece);
                }
            }
 
        }
 
    }
}