Commit 7824135f06a2414fbfc913fb050f66f88217cf70

Authored by “wangming”
1 parent 38150443

修改了一些东西

netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchReturnInput.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.ComponentModel.DataAnnotations;
  3 +
  4 +namespace NCC.Extend.Entitys.Dto.LqLaundryFlow
  5 +{
  6 + /// <summary>
  7 + /// 批量送回记录输入
  8 + /// </summary>
  9 + public class LqLaundryFlowBatchReturnInput
  10 + {
  11 + /// <summary>
  12 + /// 送回记录列表
  13 + /// </summary>
  14 + [Required(ErrorMessage = "送回记录列表不能为空")]
  15 + [MinLength(1, ErrorMessage = "至少需要一条送回记录")]
  16 + public List<LqLaundryFlowReturnInput> Items { get; set; }
  17 + }
  18 +}
... ...
netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowBatchSendInput.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.ComponentModel.DataAnnotations;
  3 +
  4 +namespace NCC.Extend.Entitys.Dto.LqLaundryFlow
  5 +{
  6 + /// <summary>
  7 + /// 批量送出记录输入
  8 + /// </summary>
  9 + public class LqLaundryFlowBatchSendInput
  10 + {
  11 + /// <summary>
  12 + /// 送出记录列表
  13 + /// </summary>
  14 + [Required(ErrorMessage = "送出记录列表不能为空")]
  15 + [MinLength(1, ErrorMessage = "至少需要一条送出记录")]
  16 + public List<LqLaundryFlowSendInput> Items { get; set; }
  17 + }
  18 +}
... ...
netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs
... ... @@ -139,6 +139,116 @@ namespace NCC.Extend
139 139 throw NCCException.Oh($"创建失败:{ex.Message}");
140 140 }
141 141 }
  142 +
  143 + /// <summary>
  144 + /// 批量创建送出记录
  145 + /// </summary>
  146 + /// <remarks>
  147 + /// 批量创建送出记录,每条记录独立生成批次号;任一条校验失败则全部回滚
  148 + ///
  149 + /// 示例请求:
  150 + /// ```json
  151 + /// {
  152 + /// "items": [
  153 + /// {
  154 + /// "storeId": "门店ID",
  155 + /// "productType": "毛巾",
  156 + /// "laundrySupplierId": "清洗商ID",
  157 + /// "quantity": 100,
  158 + /// "remark": "备注",
  159 + /// "sendTime": "2025-01-15T10:30:00"
  160 + /// }
  161 + /// ]
  162 + /// }
  163 + /// ```
  164 + ///
  165 + /// 参数说明:
  166 + /// - items: 送出记录列表(必填,至少一条)
  167 + /// - 每条记录字段与单条送出接口相同
  168 + /// </remarks>
  169 + /// <param name="input">批量送出输入</param>
  170 + /// <returns>成功条数、批次号列表</returns>
  171 + /// <response code="200">批量创建成功</response>
  172 + /// <response code="400">参数错误或任一条校验失败</response>
  173 + /// <response code="500">服务器错误</response>
  174 + [HttpPost("BatchSend")]
  175 + public async Task<dynamic> BatchSendAsync([FromBody] LqLaundryFlowBatchSendInput input)
  176 + {
  177 + if (input?.Items == null || !input.Items.Any())
  178 + {
  179 + throw NCCException.Oh("送出记录列表不能为空");
  180 + }
  181 +
  182 + try
  183 + {
  184 + var batchNumbers = new List<string>();
  185 + await _db.Ado.UseTranAsync(async () =>
  186 + {
  187 + for (var i = 0; i < input.Items.Count; i++)
  188 + {
  189 + var item = input.Items[i];
  190 + // 验证门店是否存在
  191 + var store = await _db.Queryable<LqMdxxEntity>()
  192 + .Where(x => x.Id == item.StoreId)
  193 + .FirstAsync();
  194 + if (store == null)
  195 + {
  196 + throw NCCException.Oh($"第{i + 1}条:门店不存在");
  197 + }
  198 +
  199 + // 验证清洗商是否存在
  200 + var supplier = await _db.Queryable<LqLaundrySupplierEntity>()
  201 + .Where(x => x.Id == item.LaundrySupplierId && x.IsEffective == StatusEnum.有效.GetHashCode())
  202 + .FirstAsync();
  203 + if (supplier == null)
  204 + {
  205 + throw NCCException.Oh($"第{i + 1}条:清洗商不存在或已失效");
  206 + }
  207 +
  208 + // 验证产品类型是否匹配
  209 + if (supplier.ProductType != item.ProductType)
  210 + {
  211 + throw NCCException.Oh($"第{i + 1}条:清洗商【{supplier.SupplierName}】不支持清洗产品类型【{item.ProductType}】");
  212 + }
  213 +
  214 + var batchId = YitIdHelper.NextId().ToString();
  215 + var entity = new LqLaundryFlowEntity
  216 + {
  217 + Id = batchId,
  218 + FlowType = 0,
  219 + BatchNumber = batchId,
  220 + StoreId = item.StoreId,
  221 + ProductType = item.ProductType,
  222 + LaundrySupplierId = item.LaundrySupplierId,
  223 + Quantity = item.Quantity,
  224 + LaundryPrice = supplier.LaundryPrice,
  225 + TotalPrice = item.Quantity * supplier.LaundryPrice,
  226 + Remark = item.Remark,
  227 + IsEffective = StatusEnum.有效.GetHashCode(),
  228 + CreateUser = _userManager.UserId,
  229 + CreateTime = DateTime.Now,
  230 + SendTime = item.SendTime ?? DateTime.Now
  231 + };
  232 +
  233 + var isOk = await _db.Insertable(entity).ExecuteCommandAsync();
  234 + if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
  235 + batchNumbers.Add(batchId);
  236 + }
  237 + });
  238 +
  239 + return new
  240 + {
  241 + successCount = batchNumbers.Count,
  242 + batchNumbers,
  243 + message = "批量送出成功"
  244 + };
  245 + }
  246 + catch (Exception ex)
  247 + {
  248 + _logger.LogError(ex, "批量创建送出记录失败");
  249 + throw NCCException.Oh($"批量送出失败:{ex.Message}");
  250 + }
  251 + }
142 252 #endregion
143 253  
144 254 #region 创建送回记录
... ... @@ -245,6 +355,123 @@ namespace NCC.Extend
245 355 throw NCCException.Oh($"创建失败:{ex.Message}");
246 356 }
247 357 }
  358 +
  359 + /// <summary>
  360 + /// 批量创建送回记录
  361 + /// </summary>
  362 + /// <remarks>
  363 + /// 批量创建送回记录;任一条校验失败则全部回滚
  364 + ///
  365 + /// 示例请求:
  366 + /// ```json
  367 + /// {
  368 + /// "items": [
  369 + /// {
  370 + /// "batchNumber": "批次号",
  371 + /// "laundrySupplierId": "清洗商ID",
  372 + /// "quantity": 95,
  373 + /// "remark": "5条损坏",
  374 + /// "returnTime": "2025-01-20T14:30:00"
  375 + /// }
  376 + /// ]
  377 + /// }
  378 + /// ```
  379 + ///
  380 + /// 参数说明:
  381 + /// - items: 送回记录列表(必填,至少一条)
  382 + /// - 每条记录字段与单条送回接口相同
  383 + /// </remarks>
  384 + /// <param name="input">批量送回输入</param>
  385 + /// <returns>成功条数</returns>
  386 + /// <response code="200">批量创建成功</response>
  387 + /// <response code="400">参数错误或任一条校验失败</response>
  388 + /// <response code="500">服务器错误</response>
  389 + [HttpPost("BatchReturn")]
  390 + public async Task<dynamic> BatchReturnAsync([FromBody] LqLaundryFlowBatchReturnInput input)
  391 + {
  392 + if (input?.Items == null || !input.Items.Any())
  393 + {
  394 + throw NCCException.Oh("送回记录列表不能为空");
  395 + }
  396 +
  397 + try
  398 + {
  399 + var successCount = 0;
  400 + await _db.Ado.UseTranAsync(async () =>
  401 + {
  402 + for (var i = 0; i < input.Items.Count; i++)
  403 + {
  404 + var item = input.Items[i];
  405 + // 验证对应的送出记录是否存在
  406 + var sendRecord = await _db.Queryable<LqLaundryFlowEntity>()
  407 + .Where(x => x.BatchNumber == item.BatchNumber && x.FlowType == 0 && x.IsEffective == StatusEnum.有效.GetHashCode())
  408 + .FirstAsync();
  409 + if (sendRecord == null)
  410 + {
  411 + throw NCCException.Oh($"第{i + 1}条:对应的送出记录不存在或已失效");
  412 + }
  413 +
  414 + // 检查是否已经存在送回记录
  415 + var existingReturn = await _db.Queryable<LqLaundryFlowEntity>()
  416 + .Where(x => x.BatchNumber == item.BatchNumber && x.FlowType == 1 && x.IsEffective == StatusEnum.有效.GetHashCode())
  417 + .FirstAsync();
  418 + if (existingReturn != null)
  419 + {
  420 + throw NCCException.Oh($"第{i + 1}条:该批次已存在送回记录");
  421 + }
  422 +
  423 + // 验证清洗商是否存在
  424 + var supplier = await _db.Queryable<LqLaundrySupplierEntity>()
  425 + .Where(x => x.Id == item.LaundrySupplierId && x.IsEffective == StatusEnum.有效.GetHashCode())
  426 + .FirstAsync();
  427 + if (supplier == null)
  428 + {
  429 + throw NCCException.Oh($"第{i + 1}条:清洗商不存在或已失效");
  430 + }
  431 +
  432 + // 验证产品类型是否匹配
  433 + if (supplier.ProductType != sendRecord.ProductType)
  434 + {
  435 + throw NCCException.Oh($"第{i + 1}条:清洗商【{supplier.SupplierName}】不支持清洗产品类型【{sendRecord.ProductType}】");
  436 + }
  437 +
  438 + var totalPrice = item.Quantity * supplier.LaundryPrice;
  439 + var entity = new LqLaundryFlowEntity
  440 + {
  441 + Id = YitIdHelper.NextId().ToString(),
  442 + FlowType = 1,
  443 + BatchNumber = item.BatchNumber,
  444 + StoreId = sendRecord.StoreId,
  445 + ProductType = sendRecord.ProductType,
  446 + LaundrySupplierId = item.LaundrySupplierId,
  447 + Quantity = item.Quantity,
  448 + LaundryPrice = supplier.LaundryPrice,
  449 + TotalPrice = totalPrice,
  450 + Remark = item.Remark,
  451 + IsEffective = StatusEnum.有效.GetHashCode(),
  452 + CreateUser = _userManager.UserId,
  453 + CreateTime = DateTime.Now,
  454 + ReturnTime = item.ReturnTime ?? DateTime.Now
  455 + };
  456 +
  457 + var isOk = await _db.Insertable(entity).ExecuteCommandAsync();
  458 + if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
  459 + successCount++;
  460 + }
  461 + });
  462 +
  463 + return new
  464 + {
  465 + successCount,
  466 + message = "批量送回成功"
  467 + };
  468 + }
  469 + catch (Exception ex)
  470 + {
  471 + _logger.LogError(ex, "批量创建送回记录失败");
  472 + throw NCCException.Oh($"批量送回失败:{ex.Message}");
  473 + }
  474 + }
248 475 #endregion
249 476  
250 477 #region 修改送出/送回记录
... ...