From c7acb51c3ace14e509704f453adc58b9eb6613a8 Mon Sep 17 00:00:00 2001
From: liuying <1427574514@qq.com>
Date: 周三, 16 10月 2024 16:23:28 +0800
Subject: [PATCH] 细节

---
 iWara.SCADA.Code/iWare.Wms.Application/Service/WorkPieceOutbound/WorkPieceOutboundService.cs |   77 +++++++++++++++++++++++++++++++++-----
 1 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/iWara.SCADA.Code/iWare.Wms.Application/Service/WorkPieceOutbound/WorkPieceOutboundService.cs b/iWara.SCADA.Code/iWare.Wms.Application/Service/WorkPieceOutbound/WorkPieceOutboundService.cs
index a3c2b34..ba88729 100644
--- a/iWara.SCADA.Code/iWare.Wms.Application/Service/WorkPieceOutbound/WorkPieceOutboundService.cs
+++ b/iWara.SCADA.Code/iWare.Wms.Application/Service/WorkPieceOutbound/WorkPieceOutboundService.cs
@@ -8,6 +8,7 @@
 using Mapster;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
+using SharpYaml;
 using System.Linq.Dynamic.Core;
 
 namespace iWare.Wms.Application
@@ -21,13 +22,18 @@
     [DisableOpLog]
     public class WorkPieceOutboundService : IWorkPieceOutboundService, IDynamicApiController, ITransient
     {
-        private readonly IRepository<WorkPieceOutbound,MasterDbContextLocator> _workPieceOutboundRep;
-
+        private readonly IRepository<WorkPieceOutbound, MasterDbContextLocator> _workPieceOutboundRep;
+        private readonly IRepository<WorkPieceInfo, MasterDbContextLocator> _workPieceInfoRep;
+        private readonly IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> _workPieceOutboundRecordRep;
 
         public WorkPieceOutboundService(
-            IRepository<WorkPieceOutbound,MasterDbContextLocator> workPieceOutboundRep
+              IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> workPieceOutboundRecordRep,
+            IRepository<WorkPieceInfo, MasterDbContextLocator> workPieceInfoRep,
+            IRepository<WorkPieceOutbound, MasterDbContextLocator> workPieceOutboundRep
         )
         {
+            _workPieceOutboundRecordRep = workPieceOutboundRecordRep;
+            _workPieceInfoRep = workPieceInfoRep;
             _workPieceOutboundRep = workPieceOutboundRep;
         }
 
@@ -42,6 +48,7 @@
             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))
@@ -49,6 +56,27 @@
                                      .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>
         /// 澧炲姞宸ヤ欢鍑哄簱淇℃伅
@@ -86,7 +114,7 @@
             if (!isExist) throw Oops.Oh(ErrorCode.D3000);
 
             var workPieceOutbound = input.Adapt<WorkPieceOutbound>();
-            await _workPieceOutboundRep.UpdateAsync(workPieceOutbound,ignoreNullValues:true);
+            await _workPieceOutboundRep.UpdateAsync(workPieceOutbound, ignoreNullValues: true);
         }
 
         /// <summary>
@@ -117,19 +145,48 @@
         /// <param name="input"></param>
         /// <returns></returns>
         [HttpPost("revoke")]
+        [UnitOfWork]
         public async Task Revoke(List<DeleteWorkPieceOutboundInput> input)
         {
-            foreach (var item in input) {
+            foreach (var item in input)
+            {
                 var workPieceOutbound = await _workPieceOutboundRep.FirstOrDefaultAsync(u => u.Id == item.Id);
                 if (workPieceOutbound == null)
                 {
-                    throw Oops.Oh("宸ヤ欢鍑哄簱淇℃伅涓嶅瓨鍦�");
+                    throw Oops.Oh("宸ヤ欢鍏ュ簱淇℃伅涓嶅瓨鍦�");
                 }
-                workPieceOutbound.IsDeleted = true;
-                workPieceOutbound.Remark = workPieceOutbound.Remark??""+"鎾ら攢鍙戣揣";
-                await _workPieceOutboundRep.UpdateAsync(workPieceOutbound);
+                //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);
+                }
             }
-            
+
         }
 
     }

--
Gitblit v1.9.3