| | |
| | | using AutoMapper; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Common.OrderEnum; |
| | | 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.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | |
| | | public partial class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IMaterielInfoService _materielInfoService; |
| | | private readonly IStockInfoService _stockService; |
| | | private readonly IStockInfoDetailService _stockDetailService; |
| | | private readonly IOutboundOrder_HtyService _outboundOrder_HtyService; |
| | | private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService; |
| | | private readonly IOutboundOrderDetailService _outboundOrderDetailService; |
| | | //private readonly ITaskService _taskService; |
| | | |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService) : base(BaseDal) |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IUnitOfWorkManage unitOfWorkManage, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _materielInfoService = materielInfoService; |
| | | _stockDetailService = stockDetailService; |
| | | _stockService = stockInfoService; |
| | | _outboundOrder_HtyService = outboundOrder_HtyService; |
| | | _outboundOrderDetail_HtyService = outboundOrderDetail_HtyService; |
| | | _outboundOrderDetailService = outboundOrderDetailService; |
| | | //_taskService = taskService; |
| | | } |
| | | |
| | |
| | | { |
| | | BatchNo = x.FirstOrDefault()?.BatchNo ?? "", |
| | | MaterielCode = x.Key, |
| | | MaterielName = x.FirstOrDefault()?.MaterielName??"", |
| | | OrderQuantity = x.Sum(x => x.OrderQuantity), |
| | | Remark = x.FirstOrDefault(v => !string.IsNullOrEmpty(v.Remark))?.Remark ?? "" |
| | | }).ToList(); |
| | |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent AddOutboundOrders(Houseounbound orderAddDTO) |
| | | { |
| | | WebResponseContent content = new(); |
| | | try |
| | | { |
| | | OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO(); |
| | | orderAddDTO1.OrderNo = orderAddDTO.No; |
| | | orderAddDTO1.UpperOrderNo = orderAddDTO.No; |
| | | orderAddDTO1.OutWareHouse = orderAddDTO.OutWareHouse; |
| | | orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode; |
| | | orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt(); |
| | | orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>(); |
| | | #region 验证数据 |
| | | (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO1); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | #endregion |
| | | //public WebResponseContent AddOutboundOrders(Houseounbound orderAddDTO) |
| | | //{ |
| | | // WebResponseContent content = new(); |
| | | // try |
| | | // { |
| | | // OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO(); |
| | | // orderAddDTO1.OrderNo = orderAddDTO.No; |
| | | // orderAddDTO1.UpperOrderNo = orderAddDTO.No; |
| | | // orderAddDTO1.OutWareHouse = orderAddDTO.OutWareHouse; |
| | | // orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode; |
| | | // orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt(); |
| | | // orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>(); |
| | | // #region 验证数据 |
| | | // (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO1); |
| | | // if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | // #endregion |
| | | |
| | | Dt_OutboundOrder inboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO1); |
| | | inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt(); |
| | | inboundOrder.Creater = "WMS"; |
| | | inboundOrder.CreateDate = DateTime.Now; |
| | | bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | // Dt_OutboundOrder inboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO1); |
| | | // inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt(); |
| | | // inboundOrder.Creater = "WMS"; |
| | | // inboundOrder.CreateDate = DateTime.Now; |
| | | // bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | // content = WebResponseContent.Instance.OK(); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // content = WebResponseContent.Instance.Error(ex.Message); |
| | | // } |
| | | // finally |
| | | // { |
| | | |
| | | } |
| | | return content; |
| | | } |
| | | // } |
| | | // return content; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 单据取消 |
| | | /// 出库单据取消 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent CancelOut(HouseCancelOut houseCancelOut) |
| | |
| | | OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO(); |
| | | orderAddDTO1.OrderNo = houseCancelOut.No; |
| | | orderAddDTO1.Details = houseCancelOut.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>(); |
| | | #region 验证数据 |
| | | (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO1); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | #endregion |
| | | Dt_OutboundOrder oldOutboundOrder = BaseDal.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == orderAddDTO1.OrderNo).Includes(x => x.Details).First(); |
| | | Dt_OutboundOrderDetail OutboundOrderDetail = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.OrderId == oldOutboundOrder.Id).First(); |
| | | if (oldOutboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("未找到此出库单据"); |
| | | } |
| | | if (oldOutboundOrder.OrderStatus == OutboundStatusEnum.出库完成.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | oldOutboundOrder.OrderStatus = InboundStatusEnum.取消.ObjToInt(); |
| | | BaseDal.UpdateData(oldOutboundOrder); |
| | | |
| | | Dt_OutboundOrder inboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO1); |
| | | inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt(); |
| | | inboundOrder.OrderType = OutOrderTypeEnum.OutInventory.ObjToInt(); |
| | | inboundOrder.Creater = "WMS"; |
| | | inboundOrder.CreateDate = DateTime.Now; |
| | | bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty |
| | | { |
| | | OrderStatus = oldOutboundOrder.OrderStatus, |
| | | CreateType = oldOutboundOrder.CreateType, |
| | | //SourceId = oldOutboundOrder.SourceId, |
| | | UpperOrderNo = oldOutboundOrder.UpperOrderNo, |
| | | OrderNo = oldOutboundOrder.OrderNo, |
| | | OutWareHouse = oldOutboundOrder.OutWareHouse, |
| | | TransactionCode = oldOutboundOrder.TransactionCode, |
| | | InoutType = oldOutboundOrder.InoutType, |
| | | OrderType = oldOutboundOrder.OrderType, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | _outboundOrder_HtyService.AddData(inboundOrder_Hty); |
| | | |
| | | foreach (var item in oldOutboundOrder.Details) |
| | | { |
| | | Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty |
| | | { |
| | | OrderId = OutboundOrderDetail.OrderId, |
| | | MaterielCode = OutboundOrderDetail.MaterielCode, |
| | | MaterielName = OutboundOrderDetail.MaterielName, |
| | | BatchNo = OutboundOrderDetail.BatchNo, |
| | | OrderQuantity = OutboundOrderDetail.OrderQuantity, |
| | | OrderDetailStatus = OutboundOrderDetail.OrderDetailStatus, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty); |
| | | _outboundOrderDetailService.DeleteData(item); |
| | | } |
| | | BaseDal.DeleteData(oldOutboundOrder); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return (true, "成功", outboundOrderAddDTO); |
| | | } |
| | | |
| | | |
| | | public WebResponseContent ReleaseOutOrder(int orderId) |
| | | /// <summary> |
| | | /// 重写出库新建页面 |
| | | /// </summary> |
| | | /// <param name="orderAddDTO"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent Save(OutboundOrderAddDTO orderAddDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | Random random = new Random(); |
| | | if (orderAddDTO.Details != null) |
| | | { |
| | | foreach (var model in orderAddDTO.Details) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail() |
| | | { |
| | | MaterielCode = model.MaterielCode, |
| | | MaterielName = model.MaterielName, |
| | | OrderQuantity = model.OrderQuantity, |
| | | BatchNo = model.BatchNo, |
| | | OrderDetailStatus = InOrderStatusEnum.未开始.ObjToInt(), |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | |
| | | }; |
| | | outboundOrderDetails.Add(outboundOrderDetail); |
| | | } |
| | | } |
| | | int randomNum2 = random.Next(1, 1000); |
| | | string datePart2 = DateTime.Now.ToString("yyyyMMdd"); |
| | | Dt_Warehouse warehouse = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => x.WarehouseId == orderAddDTO.WarehouseId).First(); |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("该仓库信息尚未配置"); |
| | | } |
| | | Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder() |
| | | { |
| | | OrderNo = "WMSOUT" + $"{datePart2}{randomNum2}", |
| | | UpperOrderNo = "WMSOUT" + $"{datePart2}{randomNum2}", |
| | | OutWareHouse = warehouse.WarehouseCode, |
| | | OrderType = OrderTypeEnum.生产出库单.ObjToInt(), |
| | | InoutType = InoutTypeEnum.OtherOut.ToString(), |
| | | OrderStatus = InOrderStatusEnum.未开始.ObjToInt(), |
| | | CreateType = OrderCreateTypeEnum.CreateInSystem.ObjToInt(), |
| | | System = "WMS", |
| | | Details = outboundOrderDetails, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | |
| | | } |
| | | |
| | | public WebResponseContent GetCodeByWarehouse(int warehouseId) |
| | | { |
| | | try |
| | | { |
| | | //获取所有库存型号 |
| | | List<Dt_StockInfoDetail> StockInfoDetails = _stockService.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((master, detail) => master.Id == detail.StockId) |
| | | .Where((master, detail) => master.WarehouseId == warehouseId) |
| | | .Select((master, detail) => detail) |
| | | .ToList(); |
| | | //过滤重复 |
| | | List<string> code = StockInfoDetails.Select(x => x.MaterielCode).Distinct().ToList(); |
| | | return WebResponseContent.Instance.OK("成功", data: code); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent GetVersionByCode(string materielCode, int warehouseId) |
| | | { |
| | | try |
| | | { |
| | | //获取指定产品库存版本 |
| | | List<Dt_StockInfoDetail> StockInfoDetails = _stockService.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((master, detail) => master.Id == detail.StockId) |
| | | .Where((master, detail) => master.WarehouseId == warehouseId && detail.MaterielCode == materielCode) |
| | | .Select((master, detail) => detail) |
| | | .ToList(); |
| | | //过滤重复 |
| | | List<string> materielName = StockInfoDetails.Select(x => x.MaterielName).Distinct().ToList(); |
| | | return WebResponseContent.Instance.OK("成功", data: materielName); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent GetLotNoByCode(string materielCode, int warehouseId) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_StockInfoDetail> StockInfoDetails = _stockService.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((master, detail) => master.Id == detail.StockId) |
| | | .Where((master, detail) => master.WarehouseId == warehouseId && detail.MaterielCode == materielCode) |
| | | .Select((master, detail) => detail) |
| | | .ToList(); |
| | | //过滤重复 |
| | | List<string> batchNo = StockInfoDetails.Select(x => x.BatchNo).Distinct().ToList(); |
| | | return WebResponseContent.Instance.OK("成功", data: batchNo); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | 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 = true, |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |