From 32420f572c9e4d2f0c424214bc92f75e7dfe56f1 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期二, 14 一月 2025 09:01:37 +0800
Subject: [PATCH] 1
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 224 insertions(+), 14 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
index efc8049..cdfafc9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
@@ -3,6 +3,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,9 +16,13 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.CodeConfigEnum;
+using WIDESEA_Core.DB;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
+using WIDESEA_Core.Seed;
using WIDESEA_Core.Utilities;
+using WIDESEA_DTO.Basic;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
@@ -38,23 +43,20 @@
private readonly IUnitOfWorkManage _unitOfWorkManage;
private readonly IBasicService _basicService;
private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
- private readonly IStockInfoService _stockInfoService;
- private readonly IStockInfoRepository _stockInfoRepository;
+ private readonly IStockService _stockService;
public IOutboundOrderRepository Repository => BaseDal;
private readonly IInvokeERPService _invokeERPService;
private readonly IOutStockLockInfoService _outStockLockInfoService;
private readonly IOutboundOrderRepository _outboundOrderRepository;
- public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService,
- IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService,
+ public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockService stockService, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService,
IOutboundOrderRepository outboundOrderRepository) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
_basicService = basicService;
_outboundOrderDetailRepository = outboundOrderDetailRepository;
- _stockInfoService = stockInfoService;
- _stockInfoRepository = stockInfoRepository;
+ _stockService = stockService;
_invokeERPService = invokeERPService;
_outStockLockInfoService = outStockLockInfoService;
_outboundOrderRepository = outboundOrderRepository;
@@ -83,17 +85,163 @@
List<Dt_OutboundOrder> dt_ReceiveOrders = new List<Dt_OutboundOrder>();
if (string.IsNullOrEmpty(orderNo))
{
- dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderStatus < OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).ToPageList(pageNo, 5);
+ dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderStatus < OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
}
else
{
- dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).ToPageList(pageNo, 5);
+ dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
}
content.OK(data: dt_ReceiveOrders);
}
catch (Exception ex)
{
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ public WebResponseContent outpinku(SaveModel saveModel)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ var orderNo = saveModel.MainData["orderNo"].ToString();
+ var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+ var serNum = saveModel.MainData["sn"].ToString();
+ Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+ if (warehouse == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+ }
+
+ Dt_OutboundOrder outboundOrder = BaseDal.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First();
+ if (outboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟淇℃伅");
+ }
+ if (outboundOrder.Details == null || outboundOrder.Details.Count <= 0)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+ }
+
+ MatSerNumAnalysisModel model = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serNum);
+ Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == model.MaterielCode);
+ if (materielInfo == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+ }
+ if (materielInfo.WarehouseId != outboundOrder.WarehouseId)
+ {
+ return WebResponseContent.Instance.Error($"璇ョ墿鏂欎笉灞炰簬鏈粨");
+ }
+
+ Dt_OutboundOrderDetail outboundOrderDetail = outboundOrder.Details.FirstOrDefault(x => x.MaterielCode == model.MaterielCode);
+ if (outboundOrderDetail == null) return WebResponseContent.Instance.Error($"璇ョ墿鏂欎笉灞炰簬鏈嚭搴撳崟");
+ if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
+ return WebResponseContent.Instance.Error($"鏈嚭搴撳崟褰撳墠鐗╂枡宸插嚭搴撳畬鎴�");
+
+ if (outboundOrderDetail.OrderQuantity - outboundOrderDetail.OverOutQuantity < model.Quantity)
+ return WebResponseContent.Instance.Error($"鍑哄簱鏁伴噺瓒呭嚭鍑哄簱鍗�");
+
+ Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo);
+
+ if (stockInfoDetail == null) return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛�");
+ if (stockInfoDetail.StockQuantity < model.Quantity) return WebResponseContent.Instance.Error($"搴撳瓨涓嶈冻");
+ Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.Id == stockInfoDetail.StockId);
+ if (stockInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛樹富琛�");
+ if (stockInfo.LocationCode != "骞冲簱浣�") return WebResponseContent.Instance.Error($"搴撳瓨涓嶅睘浜庡钩搴撲綅");
+
+ Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo()
+ {
+ PalletCode = stockInfo.PalletCode,
+ AssignQuantity = model.Quantity,
+ MaterielCode = model.MaterielCode,
+ BatchNo = model.LotNo,
+ LocationCode = stockInfo.LocationCode,
+ MaterielName = materielInfo.MaterielName,
+ OrderDetailId = outboundOrderDetail.Id,
+ OrderNo = outboundOrder.OrderNo,
+ OrderType = outboundOrder.OrderType,
+ OriginalQuantity = stockInfoDetail.StockQuantity,
+ Status = OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt(),
+ StockId = stockInfo.Id,
+ TaskNum = 0,
+ OrderQuantity = outboundOrderDetail.OrderQuantity,
+ Unit = outboundOrderDetail.Unit
+ };
+
+ #region 淇敼鍑哄簱鍗�
+ outboundOrderDetail.OverOutQuantity += outStockLockInfo.AssignQuantity;
+ if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.OverOutQuantity)
+ outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+ else
+ outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+ int overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+ if (outboundOrder.Details.Count == overCount)
+ outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+ else
+ outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+ #endregion
+
+ #region 淇敼搴撳瓨
+ stockInfoDetail.StockQuantity -= stockInfoDetail.StockQuantity - outStockLockInfo.AssignQuantity;
+ #endregion
+
+
+ _unitOfWorkManage.BeginTran();
+ _outStockLockInfoService.Repository.AddData(outStockLockInfo);
+ BaseDal.UpdateData(outboundOrder);
+ _outboundOrderDetailRepository.UpdateData(outboundOrderDetail);
+ if (stockInfoDetail.StockQuantity > 0)
+ {
+ _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
+ }
+ else
+ {
+ _stockService.StockInfoDetailService.Repository.DeleteData(stockInfoDetail);
+ if (stockInfo.Details.Count <= 1) _stockService.StockInfoService.Repository.DeleteData(stockInfo);
+ }
+ _unitOfWorkManage.CommitTran();
+
+ #region 鍑哄簱瀹屾垚涓婃姤ERP
+ ERPPickItemModel pickItemModel = new ERPPickItemModel()
+ {
+ Lotno = model.LotNo,
+ Qty = model.Quantity.ToString(),
+ Location = warehouse.WarehouseCode
+ };
+ ERPPickModel pickModel = new ERPPickModel()
+ {
+ Rowindex = outboundOrderDetail.RowNo,
+ Material = outboundOrderDetail.MaterielCode,
+ Qty = pickItemModel.Qty,
+ Dataitem = new List<ERPPickItemModel> { pickItemModel }
+ };
+ List<ERPPickModel> eRPPickModels = new List<ERPPickModel>() { pickModel };
+ ERPIssueItemModel issueItemModel = new ERPIssueItemModel()
+ {
+ Pickcode = outboundOrder.UpperOrderNo,
+ PickList = eRPPickModels
+ };
+ ERPIssueModel issueModel = new ERPIssueModel()
+ {
+ UniqueTag = outboundOrderDetail.OrderId.ToString(),
+ Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)),
+ WarehouseCode = warehouse.WarehouseCode,
+ Docremark = "",
+ Deptno = outboundOrder.DepartmentCode,
+ Deptname = outboundOrder.DepartmentName,
+ Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+ Createuser = App.User.UserName,
+ Issitem = new List<ERPIssueItemModel>() { issueItemModel },
+ };
+ _invokeERPService.InvokeOutStandardsApi(issueModel);
+ #endregion
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
content.Error(ex.Message);
}
return content;
@@ -164,7 +312,9 @@
WarehouseId = warehouse.WarehouseId,
DepartmentCode = model.DepartmentCode,
DepartmentName = model.DepartmentName,
- Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
+ Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail },
+ Remark= model.Node
+
};
Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
}
@@ -192,6 +342,7 @@
MaterielName = materielInfo.MaterielName,
OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
OrderQuantity = model.Qty,
+ Unit=model.Unit,
};
_outboundOrderDetailRepository.UpdateData(outboundOrderDetail);
@@ -274,7 +425,7 @@
issueModel = new ERPIssueModel()
{
UniqueTag = id.ToString(),
- Code = outboundOrder.OrderNo,//娴嬭瘯
+ Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)),//娴嬭瘯
WarehouseCode = warehouse.WarehouseCode,
Docremark = "",
Deptno = outboundOrder.DepartmentCode,
@@ -321,7 +472,7 @@
issueModel = new ERPIssueModel()
{
UniqueTag = id.ToString(),
- Code = outboundOrder.OrderNo,
+ Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)),
WarehouseCode = warehouse.WarehouseCode,
Docremark = "",
Deptno = outboundOrder.DepartmentCode,
@@ -334,7 +485,7 @@
if (stockInfos.Count > 0)
{
- _stockInfoRepository.UpdateData(stockInfos);
+ _stockService.StockInfoService.Repository.UpdateData(stockInfos);
}
else
{
@@ -349,18 +500,77 @@
return WebResponseContent.Instance.Error(ex.Message);
}
}
+ static object lock_code = new object();
+ public string CreateCodeByRule(string ruleCode)
+ {
+ lock (lock_code)
+ {
+
+ string code = string.Empty;
+ DateTime dateTime = DateTime.Now;
+ DateTime now = DateTime.Now;
+ try
+ {
+ if (string.IsNullOrEmpty(ruleCode))
+ throw new ArgumentNullException(nameof(ruleCode));
+ SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
+ {
+ IsAutoCloseConnection = false,
+ DbType = DbType.SqlServer,
+ ConnectionString = DBContext.ConnectionString
+ });
+ Dt_CodeRuleConfig codeRuleConfig = sugarClient.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First();
+ if (codeRuleConfig == null)
+ throw new ArgumentNullException(nameof(codeRuleConfig));
+ if (codeRuleConfig.ModifyDate != null)
+ {
+ dateTime = Convert.ToDateTime(codeRuleConfig.ModifyDate);
+ }
+ else
+ {
+ dateTime = Convert.ToDateTime(codeRuleConfig.CreateDate);
+ }
+
+ if (now.Year == dateTime.Year && now.Month == dateTime.Month && now.Day == dateTime.Day)
+ {
+ now = dateTime;
+ codeRuleConfig.CurrentVal = Convert.ToInt32(codeRuleConfig.CurrentVal) + 1;
+ }
+ else
+ {
+ codeRuleConfig.CurrentVal = 1;
+ }
+ codeRuleConfig.ModifyDate = DateTime.Now;
+ code = codeRuleConfig.Format;
+ code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0'));
+ code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0'));
+ code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0'));
+ code = code.Replace($"[{CodeFormatTypeEnum.ST}]", codeRuleConfig.StartStr?.ToString() ?? "");
+ code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", codeRuleConfig.CurrentVal.ToString().PadLeft(codeRuleConfig.Length, '0'));
+ Dictionary<string, object> keyValuePairs = new Dictionary<string, object>() { { nameof(codeRuleConfig.CurrentVal), codeRuleConfig.CurrentVal }, { nameof(codeRuleConfig.Id), codeRuleConfig.Id }, { nameof(codeRuleConfig.ModifyDate), DateTime.Now } };
+ sugarClient.Updateable(keyValuePairs).AS(MainDb.CodeRuleConfig).WhereColumns(nameof(codeRuleConfig.Id)).ExecuteCommand();
+ sugarClient.Updateable(codeRuleConfig);
+
+ }
+ catch (Exception ex)
+ {
+
+ }
+ return code;
+ }
+ }
/// <summary>
/// 鏇存敼鍑哄簱鍗曞簱瀛樼姸鎬�
/// </summary>
/// <param name="warehouse"></param>
/// <param name="model"></param>
/// <returns></returns>
- public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse,Dt_OutboundOrderDetail outboundOrderDetails)
+ public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse, Dt_OutboundOrderDetail outboundOrderDetails)
{
try
{
//鑾峰彇鍑哄簱鍗曞簱瀛�
- List<Dt_StockInfo> stockInfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x=>x.Details.Any(j=>j.MaterielCode== outboundOrderDetails.MaterielCode)).Take((int)outboundOrderDetails.OrderQuantity).ToList();
+ List<Dt_StockInfo> stockInfos = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(j => j.MaterielCode == outboundOrderDetails.MaterielCode)).Take((int)outboundOrderDetails.OrderQuantity).ToList();
if (stockInfos.Count <= 0)
{
return WebResponseContent.Instance.OK();
--
Gitblit v1.9.3