liuying
2025-09-24 16edbbe772e24eb71f6519558576d513e3cf2746
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
@@ -23,12 +24,15 @@
    {
        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;
        }
@@ -44,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))
@@ -51,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>
        /// 增加工件出库信息
@@ -127,17 +153,33 @@
                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.OutRemark = "撤销入库";
                    workPiece.OutTime = DateTime.Now;
                    workPiece.IsOut = false;