From 673b5a596f611099eaacc310f6e7def0e022daca Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期三, 29 四月 2026 11:00:55 +0800
Subject: [PATCH] 添加盘点模板和胶箱台账功能

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 3 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index d195df9..8677a3f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -100,6 +100,7 @@
         public readonly IRepository<Dt_LocationType> _locationTypeRepository;
         public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
         private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository;
+        private readonly IRepository<Dt_PlasticContainerLedger> _plasticContainerLedger;
         public IRepository<Dt_Task> Repository => BaseDal;
 
         private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -119,7 +120,7 @@
 
         public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
 
-        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository) : base(BaseDal)
+        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_PlasticContainerLedger> plasticContainerLedger) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -151,6 +152,7 @@
             _locationTypeRepository = locationTypeRepository;
             _warehouseAreaRepository = warehouseAreaRepository;
             _outboundLockInfoRepository = outboundLockInfoRepository;
+            _plasticContainerLedger = plasticContainerLedger;
         }
 
         public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum)
@@ -191,6 +193,54 @@
                     return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
                 }
                 _logger.LogInformation($"TaskService TaskCompleted: {JsonConvert.SerializeObject(task)} , {task.TaskType} ");
+
+
+                var taskType = (TaskTypeEnum)task.TaskType;
+                bool isInboundTask = taskType is
+                    TaskTypeEnum.Inbound
+                    or TaskTypeEnum.InEmpty
+                    or TaskTypeEnum.InInventory
+                    or TaskTypeEnum.InPick
+                    or TaskTypeEnum.InQuality
+                    or TaskTypeEnum.ProductionReturn
+                    or TaskTypeEnum.MesMatReturn
+                    or TaskTypeEnum.InAllocate
+                    or TaskTypeEnum.AllocateInWarehouse;
+
+                if (isInboundTask && !string.IsNullOrEmpty(task.PalletCode))
+                {
+                    string palletCode = task.PalletCode;
+
+                    // 1. 寮傛鏌ヨ鎵樼洏瀵瑰簲鐨勫�熷嚭鍙拌处锛堟纭啓娉曪級
+                    var ledger = await _plasticContainerLedger.Db.Queryable<Dt_PlasticContainerLedger>()
+                        .FirstAsync(x => x.PalletCode == palletCode);
+
+                    if (ledger != null)
+                    {
+                        // 2. 鍒犻櫎鍙拌处锛堝凡褰掕繕锛�
+                        await _plasticContainerLedger.DeleteDataAsync(ledger);
+
+                        // 3. 鏌ヨ搴撳瓨
+                        var stock = await _stockService.StockInfoService.Repository
+                            .QueryFirstAsync(x => x.PalletCode == palletCode);
+
+                        if (stock != null)
+                        {
+                            // 4. 鎷兼帴澶囨敞
+                            string borrowTime = ledger.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
+                            string returnTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                            string remark = $"{borrowTime} 鍊熷嚭锛寋returnTime} 杩樺洖";
+
+                            stock.Remark = string.IsNullOrEmpty(stock.Remark)
+                                ? remark
+                                : $"{stock.Remark}锛泏remark}";
+
+                            stock.SupplyCode = ledger.SupplyCode;
+                            stock.BorrowTime = ledger.CreateDate;
+                            await _stockService.StockInfoService.Repository.UpdateDataAsync(stock);
+                        }
+                    }
+                }
 
                 MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
                 if (methodInfo != null)
@@ -1091,6 +1141,7 @@
                 stockInfo.LocationCode = locationInfo.LocationCode;
                 stockInfo.PalletCode = task.PalletCode;
                 stockInfo.LocationCode = task.TargetAddress;
+                stockInfo.Remark ="";
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                 _stockRepository.UpdateData(stockInfo);
 
@@ -1346,6 +1397,7 @@
                 // 鏇存柊搴撳瓨淇℃伅
                 stockInfo.LocationCode = task.TargetAddress;
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                stockInfo.Remark = "";
 
                 // 鏇存柊搴撳瓨鏄庣粏鐘舵��
                 if (stockInfo.Details != null && stockInfo.Details.Any())
@@ -2259,7 +2311,7 @@
                 {
                     return content.Error($"鐩樼偣鍗晎task.OrderNo}鐩樼偣宸插畬鎴愭垨鏈紑濮�");
                 }
-                if (stockInfo.StockStatus != StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.鐩樼偣鍑哄簱閿佸畾.ObjToInt())
                 {
                     return content.Error($"{stockInfo.PalletCode}搴撳瓨鐘舵�佷笉姝g‘");
                 }
@@ -2351,7 +2403,7 @@
                 {
                     _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
                 }
-                return content;
+                return content.OK();
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3