| | |
| | | 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; |
| | |
| | | |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, 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; |
| | |
| | | { |
| | | 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 WebResponseContent.Instance.Error("未找到此出库单据"); |
| | | } |
| | | if (oldOutboundOrder.OrderStatus != InboundStatusEnum.未开始.ObjToInt()) |
| | | if (oldOutboundOrder.OrderStatus == OutboundStatusEnum.出库完成.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error("该入库单任务已开始执行,不可取消"); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | oldOutboundOrder.OrderStatus = InboundStatusEnum.取消.ObjToInt(); |
| | | BaseDal.UpdateData(oldOutboundOrder); |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |