diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchReturnInput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchReturnInput.cs
new file mode 100644
index 0000000..6976cca
--- /dev/null
+++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchReturnInput.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+
+namespace NCC.Extend.Entitys.Dto.LqLaundryFlow
+{
+ ///
+ /// 批量送回记录输入
+ ///
+ public class LqLaundryFlowBatchReturnInput
+ {
+ ///
+ /// 送回记录列表
+ ///
+ [Required(ErrorMessage = "送回记录列表不能为空")]
+ [MinLength(1, ErrorMessage = "至少需要一条送回记录")]
+ public List Items { get; set; }
+ }
+}
diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchSendInput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchSendInput.cs
new file mode 100644
index 0000000..f7c8867
--- /dev/null
+++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchSendInput.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+
+namespace NCC.Extend.Entitys.Dto.LqLaundryFlow
+{
+ ///
+ /// 批量送出记录输入
+ ///
+ public class LqLaundryFlowBatchSendInput
+ {
+ ///
+ /// 送出记录列表
+ ///
+ [Required(ErrorMessage = "送出记录列表不能为空")]
+ [MinLength(1, ErrorMessage = "至少需要一条送出记录")]
+ public List Items { get; set; }
+ }
+}
diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs
index 7037644..b0f3570 100644
--- a/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs
+++ b/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs
@@ -139,6 +139,116 @@ namespace NCC.Extend
throw NCCException.Oh($"创建失败:{ex.Message}");
}
}
+
+ ///
+ /// 批量创建送出记录
+ ///
+ ///
+ /// 批量创建送出记录,每条记录独立生成批次号;任一条校验失败则全部回滚
+ ///
+ /// 示例请求:
+ /// ```json
+ /// {
+ /// "items": [
+ /// {
+ /// "storeId": "门店ID",
+ /// "productType": "毛巾",
+ /// "laundrySupplierId": "清洗商ID",
+ /// "quantity": 100,
+ /// "remark": "备注",
+ /// "sendTime": "2025-01-15T10:30:00"
+ /// }
+ /// ]
+ /// }
+ /// ```
+ ///
+ /// 参数说明:
+ /// - items: 送出记录列表(必填,至少一条)
+ /// - 每条记录字段与单条送出接口相同
+ ///
+ /// 批量送出输入
+ /// 成功条数、批次号列表
+ /// 批量创建成功
+ /// 参数错误或任一条校验失败
+ /// 服务器错误
+ [HttpPost("BatchSend")]
+ public async Task BatchSendAsync([FromBody] LqLaundryFlowBatchSendInput input)
+ {
+ if (input?.Items == null || !input.Items.Any())
+ {
+ throw NCCException.Oh("送出记录列表不能为空");
+ }
+
+ try
+ {
+ var batchNumbers = new List();
+ await _db.Ado.UseTranAsync(async () =>
+ {
+ for (var i = 0; i < input.Items.Count; i++)
+ {
+ var item = input.Items[i];
+ // 验证门店是否存在
+ var store = await _db.Queryable()
+ .Where(x => x.Id == item.StoreId)
+ .FirstAsync();
+ if (store == null)
+ {
+ throw NCCException.Oh($"第{i + 1}条:门店不存在");
+ }
+
+ // 验证清洗商是否存在
+ var supplier = await _db.Queryable()
+ .Where(x => x.Id == item.LaundrySupplierId && x.IsEffective == StatusEnum.有效.GetHashCode())
+ .FirstAsync();
+ if (supplier == null)
+ {
+ throw NCCException.Oh($"第{i + 1}条:清洗商不存在或已失效");
+ }
+
+ // 验证产品类型是否匹配
+ if (supplier.ProductType != item.ProductType)
+ {
+ throw NCCException.Oh($"第{i + 1}条:清洗商【{supplier.SupplierName}】不支持清洗产品类型【{item.ProductType}】");
+ }
+
+ var batchId = YitIdHelper.NextId().ToString();
+ var entity = new LqLaundryFlowEntity
+ {
+ Id = batchId,
+ FlowType = 0,
+ BatchNumber = batchId,
+ StoreId = item.StoreId,
+ ProductType = item.ProductType,
+ LaundrySupplierId = item.LaundrySupplierId,
+ Quantity = item.Quantity,
+ LaundryPrice = supplier.LaundryPrice,
+ TotalPrice = item.Quantity * supplier.LaundryPrice,
+ Remark = item.Remark,
+ IsEffective = StatusEnum.有效.GetHashCode(),
+ CreateUser = _userManager.UserId,
+ CreateTime = DateTime.Now,
+ SendTime = item.SendTime ?? DateTime.Now
+ };
+
+ var isOk = await _db.Insertable(entity).ExecuteCommandAsync();
+ if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
+ batchNumbers.Add(batchId);
+ }
+ });
+
+ return new
+ {
+ successCount = batchNumbers.Count,
+ batchNumbers,
+ message = "批量送出成功"
+ };
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "批量创建送出记录失败");
+ throw NCCException.Oh($"批量送出失败:{ex.Message}");
+ }
+ }
#endregion
#region 创建送回记录
@@ -245,6 +355,123 @@ namespace NCC.Extend
throw NCCException.Oh($"创建失败:{ex.Message}");
}
}
+
+ ///
+ /// 批量创建送回记录
+ ///
+ ///
+ /// 批量创建送回记录;任一条校验失败则全部回滚
+ ///
+ /// 示例请求:
+ /// ```json
+ /// {
+ /// "items": [
+ /// {
+ /// "batchNumber": "批次号",
+ /// "laundrySupplierId": "清洗商ID",
+ /// "quantity": 95,
+ /// "remark": "5条损坏",
+ /// "returnTime": "2025-01-20T14:30:00"
+ /// }
+ /// ]
+ /// }
+ /// ```
+ ///
+ /// 参数说明:
+ /// - items: 送回记录列表(必填,至少一条)
+ /// - 每条记录字段与单条送回接口相同
+ ///
+ /// 批量送回输入
+ /// 成功条数
+ /// 批量创建成功
+ /// 参数错误或任一条校验失败
+ /// 服务器错误
+ [HttpPost("BatchReturn")]
+ public async Task BatchReturnAsync([FromBody] LqLaundryFlowBatchReturnInput input)
+ {
+ if (input?.Items == null || !input.Items.Any())
+ {
+ throw NCCException.Oh("送回记录列表不能为空");
+ }
+
+ try
+ {
+ var successCount = 0;
+ await _db.Ado.UseTranAsync(async () =>
+ {
+ for (var i = 0; i < input.Items.Count; i++)
+ {
+ var item = input.Items[i];
+ // 验证对应的送出记录是否存在
+ var sendRecord = await _db.Queryable()
+ .Where(x => x.BatchNumber == item.BatchNumber && x.FlowType == 0 && x.IsEffective == StatusEnum.有效.GetHashCode())
+ .FirstAsync();
+ if (sendRecord == null)
+ {
+ throw NCCException.Oh($"第{i + 1}条:对应的送出记录不存在或已失效");
+ }
+
+ // 检查是否已经存在送回记录
+ var existingReturn = await _db.Queryable()
+ .Where(x => x.BatchNumber == item.BatchNumber && x.FlowType == 1 && x.IsEffective == StatusEnum.有效.GetHashCode())
+ .FirstAsync();
+ if (existingReturn != null)
+ {
+ throw NCCException.Oh($"第{i + 1}条:该批次已存在送回记录");
+ }
+
+ // 验证清洗商是否存在
+ var supplier = await _db.Queryable()
+ .Where(x => x.Id == item.LaundrySupplierId && x.IsEffective == StatusEnum.有效.GetHashCode())
+ .FirstAsync();
+ if (supplier == null)
+ {
+ throw NCCException.Oh($"第{i + 1}条:清洗商不存在或已失效");
+ }
+
+ // 验证产品类型是否匹配
+ if (supplier.ProductType != sendRecord.ProductType)
+ {
+ throw NCCException.Oh($"第{i + 1}条:清洗商【{supplier.SupplierName}】不支持清洗产品类型【{sendRecord.ProductType}】");
+ }
+
+ var totalPrice = item.Quantity * supplier.LaundryPrice;
+ var entity = new LqLaundryFlowEntity
+ {
+ Id = YitIdHelper.NextId().ToString(),
+ FlowType = 1,
+ BatchNumber = item.BatchNumber,
+ StoreId = sendRecord.StoreId,
+ ProductType = sendRecord.ProductType,
+ LaundrySupplierId = item.LaundrySupplierId,
+ Quantity = item.Quantity,
+ LaundryPrice = supplier.LaundryPrice,
+ TotalPrice = totalPrice,
+ Remark = item.Remark,
+ IsEffective = StatusEnum.有效.GetHashCode(),
+ CreateUser = _userManager.UserId,
+ CreateTime = DateTime.Now,
+ ReturnTime = item.ReturnTime ?? DateTime.Now
+ };
+
+ var isOk = await _db.Insertable(entity).ExecuteCommandAsync();
+ if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
+ successCount++;
+ }
+ });
+
+ return new
+ {
+ successCount,
+ message = "批量送回成功"
+ };
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "批量创建送回记录失败");
+ throw NCCException.Oh($"批量送回失败:{ex.Message}");
+ }
+ }
#endregion
#region 修改送出/送回记录