From dd98dc6eadf4cd7855214dec422b411b340beea8 Mon Sep 17 00:00:00 2001 From: taoleite Date: Tue, 10 Jun 2025 16:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=85=A5=E5=BA=93=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20inputrequest=EF=BC=9A=201.=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0entity=EF=BC=9Amanage=20main=EF=BC=8CproductInformatio?= =?UTF-8?q?n=EF=BC=8CV=5FMANAGE=5FIN=5FCOUNT,V=5FWH=5FCELL=5FENABLE=202.?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=8C=81=E4=B9=85=E5=B1=82?= =?UTF-8?q?=EF=BC=9B=203.=E6=B7=BB=E5=8A=A0=E8=B4=A7=E4=BD=8D=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=92=8C=E4=BB=BB=E5=8A=A1=E6=9C=8D=E5=8A=A1=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/InputRequestController.cs | 257 +++++++++++++++++- Data/MichelinDbContext.cs | 16 +- Entities/MANAGE_MAIN.cs | 5 +- Entities/ProductInformation.cs | 5 +- Entities/V_MANAGE_IN_COUNT.cs | 19 ++ Entities/V_WH_CELL_ENABLE.cs | 37 +++ Entities/WH_CELL.cs | 100 +++++++ .../Implement/IoControlRouteRepository.cs | 33 +++ .../Implement/ProductInformationRepository.cs | 89 ++++++ Repositories/Implement/WhCellRepository.cs | 33 +++ .../Interface/IIoControlRouteRepository.cs | 6 + .../Interface/IManageMainRepository.cs | 5 + .../IProductInformationRepository.cs | 13 + Repositories/Interface/IWhCellRepository.cs | 10 + TaskServices/CellLogicService.cs | 144 ++++++++++ TaskServices/ManageTaskService.cs | 64 ++++- 16 files changed, 823 insertions(+), 13 deletions(-) create mode 100644 Entities/V_MANAGE_IN_COUNT.cs create mode 100644 Entities/V_WH_CELL_ENABLE.cs create mode 100644 Entities/WH_CELL.cs create mode 100644 Repositories/Implement/IoControlRouteRepository.cs create mode 100644 Repositories/Implement/ProductInformationRepository.cs create mode 100644 Repositories/Implement/WhCellRepository.cs create mode 100644 Repositories/Interface/IIoControlRouteRepository.cs create mode 100644 Repositories/Interface/IProductInformationRepository.cs create mode 100644 Repositories/Interface/IWhCellRepository.cs create mode 100644 TaskServices/CellLogicService.cs diff --git a/Controllers/InputRequestController.cs b/Controllers/InputRequestController.cs index 56a479c..2ed0703 100644 --- a/Controllers/InputRequestController.cs +++ b/Controllers/InputRequestController.cs @@ -1,5 +1,12 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; using WMS_GIRAF_Interface.Models; +using WMS_GIRAF_Interface.Repositories.Implement; +using WMS_GIRAF_Interface.Repositories.Interface; +using WMS_GIRAF_Interface.TaskServices; namespace WMS_GIRAF_Interface.Controllers; @@ -7,20 +14,266 @@ namespace WMS_GIRAF_Interface.Controllers; /// 入库申请Giraf->WMS /// [ApiController, Route("/Input")] -public class InputRequestController : ControllerBase +public class InputRequestController( + ILogger logger, + IdestinationIdRepository destinationIdRepository, + ManageTaskService manageTaskService, + IManageMainRepository manageMainRepository, + IWhCellRepository whCellRepository, + IProductInformationRepository productInformationRepository, + CellLogicService cellLogicService) + : ControllerBase { + private readonly ILogger _logger = logger; + /// /// 入库任务请求 /// /// 轮胎入库任务请求json [HttpPost] - public void GetInputRequestFromGiraf(InputRequest.RootObject inputRequest) + public InputRequestReturn.RootObject GetInputRequestFromGiraf(InputRequest.RootObject inputRequest) { + bool bResult = true; + string totalResult = ""; + string sResult = string.Empty; //TODO:获取入库任务,并生成到巷道的任务 + InputRequestReturn.RootObject returnParameter = new InputRequestReturn.RootObject(); + //优先判断products是否包含轮胎信息 + if (inputRequest!=null) + { + if (!string.IsNullOrEmpty(inputRequest.introductionPost)) + { + //检查当前post number是否存在 + var checkPost = + destinationIdRepository.GetDestinationId(Convert.ToInt32(inputRequest.introductionPost)); + if (checkPost!=null) + { + //创建入库任务 + if (inputRequest is { products: { Count: > 0 }, support: not null }) + { + string lineWay = string.Empty; + foreach (var inputRequestProduct in inputRequest.products) + { + //更新产品信息 + + //判断当前入库胎号是否有任务 + var checkTireTask = + manageMainRepository.GetManageMain("barcode", inputRequestProduct.identifier); + if (checkTireTask!=null) + { + //tlt:查看是否有物料信息,如果包含物料信息,就进行更新 + var checkProductInfo = productInformationRepository.GetProductInformation( + inputRequestProduct.identifier); + if (checkProductInfo != null) + { + //更新物料信息 + checkProductInfo.BarCode = inputRequestProduct.identifier; + checkProductInfo.LotNumber = inputRequest.sku; + checkProductInfo.PopulationNumber = inputRequestProduct.productClass; + checkProductInfo.SupportType = [inputRequest.support.type]; + checkProductInfo.FabricationDateTimeInUtc = (DateTime)inputRequestProduct.fabricationDate!; + checkProductInfo.DryDateTimeInUtc = (DateTime)inputRequestProduct.maturationDate!; + checkProductInfo.OldDateTimeInUtc = (DateTime)inputRequestProduct.highPriorityDate!; + checkProductInfo.HdvDateTimeInUtc = (DateTime)inputRequestProduct.expirationDate!; + checkProductInfo.IsBlocked = inputRequestProduct.isBlocked; + checkProductInfo.IsPriority = inputRequestProduct.isPriority; + productInformationRepository.UpdateProductInformation(checkProductInfo); + logger.LogInformation($"Update product information:{inputRequestProduct.identifier}"); + } + else + { + + ProductInformation newProductInfo = new ProductInformation() + { + //新增物料信息 + BarCode = inputRequestProduct.identifier, + LotNumber = inputRequest.sku, + PopulationNumber = inputRequestProduct.productClass, + SupportType = [inputRequest.support.type], + FabricationDateTimeInUtc = (DateTime)inputRequestProduct.fabricationDate!, + DryDateTimeInUtc = (DateTime)inputRequestProduct.maturationDate!, + OldDateTimeInUtc = (DateTime)inputRequestProduct.highPriorityDate!, + HdvDateTimeInUtc = (DateTime)inputRequestProduct.expirationDate!, + IsBlocked = inputRequestProduct.isBlocked, + IsPriority = inputRequestProduct.isPriority + }; + + productInformationRepository.AddProductInformation(newProductInfo); + + logger.LogInformation($"Add product information:{inputRequestProduct.identifier};/r/n Json String : {JsonConvert.SerializeObject(newProductInfo)}"); + } + + + if (checkTireTask.MANAGE_TYPE_CODE != "ManageLineMove") + { + //出现问题 生成任务错误 + returnParameter.status = "2"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Tire barcode {inputRequestProduct.identifier} already have manual loading task! ;"; + } + else + { + //更新任务信息:将当前的信息保存到任务信息中,根据新的起点来更新可用的入库路径信息,筛选一个可用的入库巷道 + var cellInfoEnd = whCellRepository.GetCell(checkTireTask.END_CELL_ID); + //判断当前任务终点是否包含在接口可用的终点列表中 + if (inputRequest.availableIntroductionPosts != null) + { + if (inputRequest.availableIntroductionPosts.Contains(cellInfoEnd.CELL_CODE)) + { + lineWay = cellInfoEnd.LANE_WAY; + } + else + { + //获取当前申请的起点 decision point + var cellInfoStart = whCellRepository.GetCell(inputRequest.introductionPost); + bResult = cellLogicService.GetLaneWayFromDecisionPoint(cellInfoStart, + checkTireTask.CELL_MODEL, checkTireTask.STOCK_BARCODE, + inputRequest.availableIntroductionPosts, checkTireTask.LOTNUMBER, + out int endLaneWay, out sResult); + if (bResult) + { + //更新终点信息到任务中 + checkTireTask.END_CELL_ID = endLaneWay; + checkTireTask.requestNumber = inputRequest.inputRequestId; + checkTireTask.CELL_MODEL = inputRequest.support.type; + checkTireTask.START_CELL_ID = cellInfoStart.CELL_ID; + checkTireTask.LOTNUMBER = inputRequest.sku; + checkTireTask.POPULATIONNUMBER = inputRequestProduct.productClass; + checkTireTask.keepRequestInMemoryEventIfLackOfProductIssue = true; + checkTireTask.keepRequestInMemoryEventIfMechanicalIssue = true; + bResult = manageMainRepository.UpdateManageMain(checkTireTask); + if (bResult) + { + //任务更新成功:完成本次 + returnParameter.status = "1"; + returnParameter.introductionPost = inputRequest.introductionPost; + + logger.LogInformation($"Update task info success! tire barcode :{checkTireTask.STOCK_BARCODE};/r/n task info: {JsonConvert.SerializeObject(checkTireTask)} "); + } + else + { + //更新任务信息失败 + returnParameter.status = "2"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Tire barcode {inputRequestProduct.identifier} error reason : Insert task failed! ;"; + logger.LogError($"Update task info failed! tire barcode :{inputRequestProduct.identifier}; error reason : Insert task failed!"); + } + + } + else + { + returnParameter.status = "4"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Update task info failed! reason: WMS can not get available input post number!"; + logger.LogError($"Update task info failed! tire barcode :{inputRequestProduct.identifier}; error reason : WMS can not get available input post number!"); + } + } + } + else + { + //无可用终点,返回错误信息 + returnParameter.status = "4"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Update task info failed! reason: Json string parameter availableIntroductionPosts is null!"; + logger.LogError($"tire barcode :{inputRequestProduct.identifier} parameter availableIntroductionPosts is null ,can not create task "); + } + } + + } + else + { + var cellInfoStart = whCellRepository.GetCell(inputRequest.introductionPost); + if (cellInfoStart != null) + { + int endLaneWay = 0; + //入库申请点位为Decision Point DP + if (cellInfoStart.CELL_MODEL=="DP") + { + bResult = cellLogicService.GetLaneWayFromDecisionPoint(cellInfoStart, + checkTireTask.CELL_MODEL, checkTireTask.STOCK_BARCODE, + inputRequest.availableIntroductionPosts, checkTireTask.LOTNUMBER, + out endLaneWay, out sResult); + } + else//一楼入库时,入库点为VP,CP,EP,CV + { + bResult = cellLogicService.GetCellLocationFromCheckPoint(cellInfoStart, + out endLaneWay, out sResult); + } + + if (bResult) + { + //生成任务 + bResult = manageTaskService.CreateInputTaskFromGiraf(inputRequestProduct, + inputRequest.introductionPost, endLaneWay, inputRequest.sku, inputRequest.support.type,inputRequest.inputRequestId, + inputRequest.support.IsBlocked, false, false, + out sResult); + if (bResult) + { + //生成任务成功 + returnParameter.status = "1"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += + $"Tire barcode {inputRequestProduct.identifier} created task success! ;"; + logger.LogInformation($"Create task info success! tire barcode :{checkTireTask.STOCK_BARCODE};/r/n task info: {JsonConvert.SerializeObject(checkTireTask)} "); + } + else + { + //生成任务错误 + //出现问题 生成任务错误 + returnParameter.status = "2"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += + $"Tire barcode {inputRequestProduct.identifier} create task failed! the reason: {sResult} ;"; + } + } + else + { + //找不到可用巷道 + returnParameter.status = "4"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Update task info failed! reason: WMS can not get available input post number!"; + logger.LogError($"Update task info failed! tire barcode :{inputRequestProduct.identifier}; error reason : WMS can not get available input post number!"); + + } + } + else + { + //找不到对应起点信息 + returnParameter.status = "4"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails += $"Update task info failed! reason: Json string parameter availableIntroductionPosts is null!"; + logger.LogError($"tire barcode :{inputRequestProduct.identifier} parameter availableIntroductionPosts is null ,can not create task "); + } + } + } + } + } + else + { + //出现问题:找不到对应终点 + returnParameter.status = "5"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails = $"WMS didn't find the post number{inputRequest.introductionPost} "; + } + + } + } + else + { + //未收到有效信息 + returnParameter.status = "2"; + returnParameter.introductionPost = inputRequest.introductionPost; + returnParameter.errorDetails = $"WMS didn't receive the right format input parameters! "; + + } + + return returnParameter; } + + /// /// 入库轮胎申请 /// /Input/ItemDropped diff --git a/Data/MichelinDbContext.cs b/Data/MichelinDbContext.cs index d84db75..b87fa79 100644 --- a/Data/MichelinDbContext.cs +++ b/Data/MichelinDbContext.cs @@ -15,10 +15,22 @@ public class MichelinDbContext : DbContext public DbSet Manage_Main { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { + public DbSet IoControlRoute { get; set; } + + public DbSet Wh_Cell { get; set; } + + public DbSet ProductInformation { get; set; } + + public virtual DbSet V_ManageInCount { get; set; } + public virtual DbSet V_WhCellEnable { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + //视图无主键 + modelBuilder.Entity().HasNoKey(); + modelBuilder.Entity().HasNoKey(); } } \ No newline at end of file diff --git a/Entities/MANAGE_MAIN.cs b/Entities/MANAGE_MAIN.cs index 3d46fad..f4f5312 100644 --- a/Entities/MANAGE_MAIN.cs +++ b/Entities/MANAGE_MAIN.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.Serialization; namespace WMS_GIRAF_Interface.Entities; @@ -10,6 +11,8 @@ public class MANAGE_MAIN /// 任务编号 /// [Column("MANAGE_ID")] + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int MANAGE_ID { get; set; } /// /// 终点 diff --git a/Entities/ProductInformation.cs b/Entities/ProductInformation.cs index 3b83e57..8637600 100644 --- a/Entities/ProductInformation.cs +++ b/Entities/ProductInformation.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.Serialization; namespace WMS_GIRAF_Interface.Entities; @@ -6,7 +7,9 @@ namespace WMS_GIRAF_Interface.Entities; [Table("ProductInformation")] public class ProductInformation { + [Column("BarCode")] + [Key] public string BarCode { get; set; } /// diff --git a/Entities/V_MANAGE_IN_COUNT.cs b/Entities/V_MANAGE_IN_COUNT.cs new file mode 100644 index 0000000..9b32c15 --- /dev/null +++ b/Entities/V_MANAGE_IN_COUNT.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace WMS_GIRAF_Interface.Entities; + +[Table("V_MANAGE_IN_COUNT")] +public class V_MANAGE_IN_COUNT +{ + [Column("START_DEVICE")] + public string START_DEVICE { get; set; } + + [Column("END_DEVICE")] + public string END_DEVICE { get; set; } + + [Column("MANAGE_COUNT")] + public string MANAGE_COUNT { get; set; } + + [Column("ENABLE_CELL_COUNT")] + public string ENABLE_CELL_COUNT { get; set; } +} \ No newline at end of file diff --git a/Entities/V_WH_CELL_ENABLE.cs b/Entities/V_WH_CELL_ENABLE.cs new file mode 100644 index 0000000..f16ac83 --- /dev/null +++ b/Entities/V_WH_CELL_ENABLE.cs @@ -0,0 +1,37 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace WMS_GIRAF_Interface.Entities; + +[Table("V_WH_CELL_ENABLE")] +public class V_WH_CELL_ENABLE +{ + [Column("PRIORITY")] + public int PRIORITY { get; set; } + + [Column("YPRIORITY")] + public int YPRIORITY { get; set; } + + [Column("CELL_ID")] + public int CELL_ID { get; set; } + + [Column("CELL_TYPE")] + public string CELL_TYPE { get; set; } + + [Column("CELL_STATUS")] + public string CELL_STATUS { get; set; } + + [Column("RUN_STATUS")] + public string RUN_STATUS { get; set; } + + [Column("CELL_CODE")] + public string CELL_CODE { get; set; } + + [Column("CELL_X")] + public int CELL_X { get; set; } + + [Column("CELL_Y")] + public int CELL_Y { get; set; } + + [Column("LANE_WAY")] + public string LANE_WAY { get; set; } +} \ No newline at end of file diff --git a/Entities/WH_CELL.cs b/Entities/WH_CELL.cs new file mode 100644 index 0000000..2526207 --- /dev/null +++ b/Entities/WH_CELL.cs @@ -0,0 +1,100 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace WMS_GIRAF_Interface.Entities; + +[Table("WH_CELL")] +public class WH_CELL +{ + [Column("CELL_ID")] + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int CELL_ID { get; set; } + + [Column("WAREHOUSE_ID")] + public int WAREHOUSE_ID { get; set; } + + [Column("AREA_ID")] + public int AREA_ID { get; set; } + + [Column("LOGIC_ID")] + public int LOGIC_ID { get; set; } + + [Column("CELL_NAME")] + public string CELL_NAME { get; set; } + + [Column("CELL_CODE")] + public string CELL_CODE { get; set; } + + [Column("CELL_TYPE")] + public string CELL_TYPE { get; set; } + + [Column("DEVICE_CODE")] + public string DEVICE_CODE { get; set; } + + [Column("CELL_Z")] + public int CELL_Z { get; set; } + + [Column("CELL_X")] + public int CELL_X { get; set; } + + [Column("CELL_Y")] + public int CELL_Y { get; set; } + + [Column("CELL_INOUT")] + public string CELL_INOUT { get; set; } + + [Column("CELL_MODEL")] + public string CELL_MODEL { get; set; } + + [Column("CELL_STATUS")] + public string CELL_STATUS { get; set; } + + [Column("RUN_STATUS")] + public string RUN_STATUS { get; set; } + + [Column("CELL_FORK_TYPE")] + public string CELL_FORK_TYPE { get; set; } + + [Column("CELL_LOGICAL_NAME")] + public string CELL_LOGICAL_NAME { get; set; } + + [Column("LANE_WAY")] + public string LANE_WAY { get; set; } + + [Column("CELL_GROUP")] + public string CELL_GROUP { get; set; } + + [Column("SHELF_TYPE")] + public string SHELF_TYPE { get; set; } + + [Column("SHELF_NEIGHBOUR")] + public string SHELF_NEIGHBOUR { get; set; } + + [Column("CELL_STORAGE_TYPE")] + public string CELL_STORAGE_TYPE { get; set; } + + [Column("LOCK_DEVICE_CODE")] + public string LOCK_DEVICE_CODE { get; set; } + + [Column("CELL_WIDTH")] + public int CELL_WIDTH { get; set; } + + [Column("CELL_HEIGHT")] + public int CELL_HEIGHT { get; set; } + + [Column("LOCK_CELL_ID")] + public string LOCK_CELL_ID { get; set; } + + [Column("BELONG_AREA")] + public string BELONG_AREA { get; set; } + + [Column("BELONG_ZCQ_ID")] + public int BELONG_ZCQ_ID { get; set; } + + [Column("CELL_FLAG")] + public string CELL_FLAG { get; set; } + + [Column("CELL_TRANS_FLAG")] + public int CELL_TRANS_FLAG { get; set; } +} \ No newline at end of file diff --git a/Repositories/Implement/IoControlRouteRepository.cs b/Repositories/Implement/IoControlRouteRepository.cs new file mode 100644 index 0000000..91e4ebf --- /dev/null +++ b/Repositories/Implement/IoControlRouteRepository.cs @@ -0,0 +1,33 @@ +using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; +using WMS_GIRAF_Interface.Repositories.Interface; + +namespace WMS_GIRAF_Interface.Repositories.Implement; + +public class IoControlRouteRepository:IIoControlRouteRepository +{ + + private readonly MichelinDbContext _context; + private readonly ILogger _logger; + + public IoControlRouteRepository(MichelinDbContext context, ILogger logger) + { + _context = context; + _logger = logger; + } + + public IO_CONTROL_ROUTE? GetIoControlRoute(int? lineNumber) + { + try + { + var ioControlRoute = _context.IoControlRoute.Where(x => x.CONTROL_ROUTE_TYPE == lineNumber).FirstOrDefault(); + return ioControlRoute; + } + catch (Exception ex) + { + _logger.LogError(ex, "Error in GetIoControlRoute"); + return null; + } + } + +} \ No newline at end of file diff --git a/Repositories/Implement/ProductInformationRepository.cs b/Repositories/Implement/ProductInformationRepository.cs new file mode 100644 index 0000000..4e69789 --- /dev/null +++ b/Repositories/Implement/ProductInformationRepository.cs @@ -0,0 +1,89 @@ +using System.Data.SqlTypes; +using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; +using WMS_GIRAF_Interface.Repositories.Interface; + +namespace WMS_GIRAF_Interface.Repositories.Implement; + +public class ProductInformationRepository(MichelinDbContext context) :IProductInformationRepository +{ + /// + /// Get ProductInformation by barCode + /// + /// + /// + + public ProductInformation? GetProductInformation(string barCode) + { + var productInformation = context.ProductInformation.FirstOrDefault(x => x.BarCode == barCode); + return productInformation; + } + + /// + /// Add ProductInformation + /// + /// + /// + /// + public string AddProductInformation(ProductInformation productInformation) + { + if (productInformation==null) + { + throw new ArgumentNullException(nameof(productInformation)); + } + //如果时间为空时间,那就置为系统最小值 + if(productInformation.DryDateTimeInUtc.Year < 2000) + { + productInformation.DryDateTimeInUtc = SqlDateTime.MinValue.Value; + } + + if (productInformation.HdvDateTimeInUtc.Year < 2000) + { + productInformation.HdvDateTimeInUtc = SqlDateTime.MinValue.Value; + + } + + if (productInformation.OldDateTimeInUtc.Year < 2000) + { + productInformation.OldDateTimeInUtc = SqlDateTime.MinValue.Value; + } + + var checkAdd= context.ProductInformation.Add(productInformation); + context.SaveChanges(); + return checkAdd.Entity.BarCode; + } + /// + /// 修改产品信息 + /// + /// + /// + public void UpdateProductInformation(ProductInformation productInformation) + { + if (productInformation == null) + { + throw new ArgumentNullException(nameof(productInformation)); + } + + if (productInformation.DryDateTimeInUtc.Year < 2000) + { + productInformation.DryDateTimeInUtc = SqlDateTime.MinValue.Value; + } + + if (productInformation.HdvDateTimeInUtc.Year < 2000) + { + productInformation.HdvDateTimeInUtc = SqlDateTime.MinValue.Value; + } + + if (productInformation.OldDateTimeInUtc.Year < 2000) + { + productInformation.OldDateTimeInUtc = SqlDateTime.MinValue.Value; + } + + context.ProductInformation.Update(productInformation); + context.SaveChanges(); + + } + + + +} \ No newline at end of file diff --git a/Repositories/Implement/WhCellRepository.cs b/Repositories/Implement/WhCellRepository.cs new file mode 100644 index 0000000..5c63edd --- /dev/null +++ b/Repositories/Implement/WhCellRepository.cs @@ -0,0 +1,33 @@ +using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; + +namespace WMS_GIRAF_Interface.Repositories.Implement; + +public class WhCellRepository(MichelinDbContext context) +{ + public WH_CELL? GetCell(int cellId) + { + var cell = context.Wh_Cell.First(x => x.CELL_ID == cellId); + return cell; + } + + public WH_CELL? GetCell(string cellCode) + { + var cell = context.Wh_Cell.FirstOrDefault(x => x.CELL_CODE == cellCode); + return cell; + } + + + public bool UpdateCellStatus(WH_CELL whCell) + { + if (whCell == null) + { + throw new ArgumentNullException(nameof(whCell)); + } + + context.Wh_Cell.Update(whCell); + context.SaveChanges(); + return true; + + } +} \ No newline at end of file diff --git a/Repositories/Interface/IIoControlRouteRepository.cs b/Repositories/Interface/IIoControlRouteRepository.cs new file mode 100644 index 0000000..a660e02 --- /dev/null +++ b/Repositories/Interface/IIoControlRouteRepository.cs @@ -0,0 +1,6 @@ +namespace WMS_GIRAF_Interface.Repositories.Interface; + +public interface IIoControlRouteRepository +{ + +} \ No newline at end of file diff --git a/Repositories/Interface/IManageMainRepository.cs b/Repositories/Interface/IManageMainRepository.cs index 8ad858b..5df0da9 100644 --- a/Repositories/Interface/IManageMainRepository.cs +++ b/Repositories/Interface/IManageMainRepository.cs @@ -5,4 +5,9 @@ namespace WMS_GIRAF_Interface.Repositories.Interface; public interface IManageMainRepository { public MANAGE_MAIN? GetManageMain(string type,string filterInfo); + + public bool AddManageMain(MANAGE_MAIN manageMain, out int manageId); + + public bool UpdateManageMain(MANAGE_MAIN manageMain); + public void DeleteManageMain(MANAGE_MAIN manageMain); } \ No newline at end of file diff --git a/Repositories/Interface/IProductInformationRepository.cs b/Repositories/Interface/IProductInformationRepository.cs new file mode 100644 index 0000000..4942c59 --- /dev/null +++ b/Repositories/Interface/IProductInformationRepository.cs @@ -0,0 +1,13 @@ +using WMS_GIRAF_Interface.Entities; + +namespace WMS_GIRAF_Interface.Repositories.Interface; + +public interface IProductInformationRepository +{ + public ProductInformation? GetProductInformation(string barCode); + + public string AddProductInformation(ProductInformation productInformation); + + + public void UpdateProductInformation(ProductInformation productInformation); +} \ No newline at end of file diff --git a/Repositories/Interface/IWhCellRepository.cs b/Repositories/Interface/IWhCellRepository.cs new file mode 100644 index 0000000..34fda9e --- /dev/null +++ b/Repositories/Interface/IWhCellRepository.cs @@ -0,0 +1,10 @@ +using WMS_GIRAF_Interface.Entities; + +namespace WMS_GIRAF_Interface.Repositories.Interface; + +public interface IWhCellRepository +{ + public WH_CELL? GetCell(int cellId); + public WH_CELL? GetCell(string cellCode); + public bool UpdateCellStatus(WH_CELL whCell); +} \ No newline at end of file diff --git a/TaskServices/CellLogicService.cs b/TaskServices/CellLogicService.cs new file mode 100644 index 0000000..806aa37 --- /dev/null +++ b/TaskServices/CellLogicService.cs @@ -0,0 +1,144 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; +using WMS_GIRAF_Interface.Repositories.Implement; +using WMS_GIRAF_Interface.Repositories.Interface; + +namespace WMS_GIRAF_Interface.TaskServices; + +public class CellLogicService(MichelinDbContext context,IWhCellRepository whCellRepository, ILogger logger) +{ + /// + /// 自动入库 获取line way number + /// + /// + /// + /// + /// + /// + /// + /// + public bool GetLaneWayFromDecisionPoint(WH_CELL startCell, + string cellModel, + string stockBarcode, + string[] endLineNumbers, + string lotNumber, out int selectedLaneWay , out string sResult) + { + selectedLaneWay = 0; + sResult = string.Empty; + string endDeviceList = ""; + foreach (var endLineNumber in endLineNumbers) + { + if (endDeviceList=="") + { + endDeviceList = $"'{endLineNumber}'"; + } + else + { + endDeviceList += $",'{endLineNumber}'"; + } + } + + string endDeviceCode = ""; + var getSelectedLaneWay = + context.V_ManageInCount.FromSqlRaw($@"SELECT + t3.START_DEVICE, + t3.END_DEVICE, + t3.MANAGE_COUNT, + t3.ENABLE_CELL_COUNT + FROM + ( + SELECT + top 4 t1.*, + ISNULL( t2.LOTCOUNTS, 0 ) LOTCOUNTS + FROM + ( + ( SELECT * FROM V_MANAGE_IN_COUNT WHERE START_DEVICE = '{startCell.DEVICE_CODE}' AND ENABLE_CELL_COUNT > 0 + AND END_DEVICE in (SELECT DEVICE_CODE FROM WH_CELL WHERE CELL_TYPE = 'Cell' and LANE_WAY in ({endDeviceList}))) t1 + LEFT JOIN ( SELECT ISNULL( COUNT ( DEVICE_CODE ), 0 ) LOTCOUNTS, DEVICE_CODE FROM V_STORAGE_LIST t2 + WHERE LOTNUMBER = '{lotNumber}' GROUP BY DEVICE_CODE ) t2 ON t1.END_DEVICE = t2.DEVICE_CODE + ) + ORDER BY + LOTCOUNTS, + ENABLE_CELL_COUNT DESC, + END_DEVICE DESC + ) t3").ToList(); + + if (getSelectedLaneWay.Count > 0) + { + endDeviceCode = getSelectedLaneWay[0].END_DEVICE; + selectedLaneWay = whCellRepository.GetCell(endDeviceCode)!.CELL_ID; + return true; + } + else + { + sResult = "did not find the enable lane way"; + return false; + } + + } + + /// + /// 手工入库获取终点货位信息 + /// + /// 起始位置 + /// 终点ID + /// 错误信息 + /// + public bool GetCellLocationFromCheckPoint(WH_CELL startCell, out int endCellId, out string sResult) + { + bool bResult = true; + sResult = string.Empty; + endCellId = 0; + switch (startCell.CELL_MODEL) + { + case "CP": + var getPosition = context.Wh_Cell + .FromSqlRaw( + $@"SELECT TOP 1 CELL_ID,CELL_CODE FROM WH_CELL + WHERE CELL_STATUS = 'Nohave' AND RUN_STATUS = 'Enable' AND CELL_TYPE = 'Cell' AND LANE_WAY = '{startCell.LANE_WAY}' + ORDER BY CELL_X,CELL_Y") + .ToList(); + + if (getPosition is { Count: > 0 }) + { + endCellId = getPosition[0].CELL_ID; + sResult = $"{startCell.CELL_CODE} (CP): get right end position:{getPosition[0].CELL_CODE}"; + } + else + { + sResult = $"cell_model:{startCell.CELL_CODE} (CP); not find the enable position !"; + bResult = false; + } + + break; + case "MP": + case "EP": + var getManualPosition = context.V_WhCellEnable + .FromSqlRaw( + $@"SELECT TOP 1 CELL_ID,CELL_CODE FROM V_WH_CELL_ENABLE + WHERE LANE_WAY = '{startCell.LANE_WAY}' + ORDER BY PRIORITY,CELL_X,YPRIORITY,CELL_Y") + .ToList(); + if (getManualPosition is { Count : >0}) + { + endCellId = getManualPosition[0].CELL_ID; + sResult = $"{startCell.CELL_CODE} (EP): get right end position:{getManualPosition[0].CELL_CODE}"; +} + else + { + sResult = $"cell_model:{startCell.CELL_CODE} (EP); not find the enable position !"; + bResult = false; + } + break; + default: + goto case "EP"; + break; + + } + logger.LogInformation(sResult); + return bResult; + + } +} \ No newline at end of file diff --git a/TaskServices/ManageTaskService.cs b/TaskServices/ManageTaskService.cs index 30819db..422e6d3 100644 --- a/TaskServices/ManageTaskService.cs +++ b/TaskServices/ManageTaskService.cs @@ -1,5 +1,7 @@ using WMS_GIRAF_Interface.Data; +using WMS_GIRAF_Interface.Entities; using WMS_GIRAF_Interface.Models; +using WMS_GIRAF_Interface.Repositories.Implement; using WMS_GIRAF_Interface.Repositories.Interface; namespace WMS_GIRAF_Interface.TaskServices; @@ -10,22 +12,70 @@ public class ManageTaskService(MichelinDbContext context,IManageMainRepository m private readonly IManageMainRepository _mangeMainRepository = mangeMainRepository; /// - /// 生成入库到line任务逻辑 + /// 生成入库到line任务逻辑/一楼手工入库的任务逻辑 /// - /// - public bool CreateInputTaskFromGiraf( InputRequest.Product inputRequest,bool trans,bool IssendControl ,out string sResult) + /// 产品信息 + /// 起始post number + /// 类型信息 + /// block属性 + /// 事务属性 + /// 是否生成控制任务 + /// 返回信息 + public bool CreateInputTaskFromGiraf( InputRequest.Product inputRequest,string startPostNumber,int endLaneWay,string sku,string supportType,string requestNumber,bool isBlocked,bool trans,bool IssendControl ,out string sResult) { bool bResult = true; sResult = string.Empty; //判断当前胎号是否有任务 - var manageMain = _mangeMainRepository.GetManageMain("barcode", inputRequest.identifier); - if (manageMain!=null) + var cellInfoStart = _context.Wh_Cell.FirstOrDefault(x => x.CELL_CODE == startPostNumber); + //获取起点信息 + if (cellInfoStart != null) { - + + var manageMain = _mangeMainRepository.GetManageMain("barcode", inputRequest.identifier); + if (manageMain != null) + { + //更新当前任务信息 + manageMain.END_CELL_ID = endLaneWay; + manageMain.requestNumber = requestNumber; + manageMain.CELL_MODEL = supportType; + manageMain.START_CELL_ID = cellInfoStart.CELL_ID; + manageMain.LOTNUMBER = sku; + manageMain.POPULATIONNUMBER = inputRequest.productClass; + manageMain.keepRequestInMemoryEventIfLackOfProductIssue = true; + manageMain.keepRequestInMemoryEventIfMechanicalIssue = true; + bResult = _mangeMainRepository.UpdateManageMain(manageMain); + + } + else + { + //创建任务 + + + var newManageMain = new MANAGE_MAIN + { + STOCK_BARCODE = inputRequest.identifier, + requestNumber = requestNumber, + MANAGE_TYPE_CODE = cellInfoStart.CELL_MODEL == "DP" ? "ManageLineMove" : "ManageInlocal", + MANAGE_STATUS = "WaitingSend", + MANAGE_OPERATOR = "AUTO", + MANAGE_BEGIN_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + CELL_MODEL = supportType, + START_CELL_ID = cellInfoStart.CELL_ID, + END_CELL_ID = endLaneWay, + LOTNUMBER = sku, + POPULATIONNUMBER = inputRequest.productClass, + keepRequestInMemoryEventIfLackOfProductIssue = true, + keepRequestInMemoryEventIfMechanicalIssue = true, + + }; + + + + } } else { - + //起点信息出问题 } return bResult;