From ed3673db0356c3d9e8e2d880275051a2871fdb24 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Fri, 5 Jul 2024 14:36:34 +0800 Subject: [PATCH] 1 --- WCS.BLL/DbModels/DingDingSendUser.cs | 19 - WCS.BLL/DbModels/MatInfoLog.cs | 49 + WCS.BLL/DbModels/Task/CurrentTask.cs | 121 ++ WCS.BLL/DbModels/Task/FinishedTask.cs | 125 ++ WCS.BLL/DbModels/Task/UploadedTask.cs | 125 ++ WCS.BLL/Manager/DbInit.cs | 2 +- WCS.BLL/Manager/TCPClientManager.cs | 8 + WCS.BLL/Services/IService/IMXL4Service.cs | 20 + .../Services/IService/ISingleLightService.cs | 19 + WCS.BLL/Services/IService/IUploadService.cs | 22 + .../Services/Service/InstoreService.cs.orig | 552 ------- WCS.BLL/Services/Service/MXL4Service.cs | 125 ++ .../Services/Service/MatBaseInfoService.cs | 3 +- WCS.BLL/Services/Service/OutstoreService.cs | 5 +- .../Services/Service/OutstoreService.cs.orig | 1311 ----------------- .../Services/Service/SingleLightService.cs | 152 ++ WCS.BLL/Services/Service/UploadService.cs | 136 ++ WCS.BLL/Tool/Helper.cs | 101 +- WCS.BLL/Tool/TCPClient.cs | 10 +- .../ApiModel/MXL4/SysOrderMXL4Request.cs | 69 + WCS.Model/ApiModel/MXL4/TaskEnum.cs | 29 + .../SingleLight/SingleLightControlRequest.cs | 52 + .../ApiModel/UpLoad/UploadReelInfoRequest.cs | 15 + WCS.WebApi/Controllers/DIYController.cs | 31 - WCS.WebApi/Controllers/MXL4Controller.cs | 49 + .../Controllers/SingleLightController.cs | 48 + WCS.WebApi/Controllers/UpLoadController.cs | 68 + WCS.WebApi/Program.cs | 5 + .../ViewModels/InOutRecordViewModel.cs | 1 + .../MatBaseInoScanGenarateMatInfoViewModel.cs | 79 +- 货架标准上位机/Views/MatBaseInfoView.xaml.cs | 3 +- .../Views/MatBaseInoScanGenarateMatInfoView.xaml | 12 +- .../Views/MatBaseInoScanGenarateMatInfoView.xaml.cs | 5 + 货架标准上位机/Views/MatInfoView.xaml.cs | 2 +- 货架标准上位机/Views/ModuleInfoView.xaml | 1 + 35 files changed, 1435 insertions(+), 1939 deletions(-) delete mode 100644 WCS.BLL/DbModels/DingDingSendUser.cs create mode 100644 WCS.BLL/DbModels/MatInfoLog.cs create mode 100644 WCS.BLL/DbModels/Task/CurrentTask.cs create mode 100644 WCS.BLL/DbModels/Task/FinishedTask.cs create mode 100644 WCS.BLL/DbModels/Task/UploadedTask.cs create mode 100644 WCS.BLL/Services/IService/IMXL4Service.cs create mode 100644 WCS.BLL/Services/IService/ISingleLightService.cs create mode 100644 WCS.BLL/Services/IService/IUploadService.cs delete mode 100644 WCS.BLL/Services/Service/InstoreService.cs.orig create mode 100644 WCS.BLL/Services/Service/MXL4Service.cs delete mode 100644 WCS.BLL/Services/Service/OutstoreService.cs.orig create mode 100644 WCS.BLL/Services/Service/SingleLightService.cs create mode 100644 WCS.BLL/Services/Service/UploadService.cs create mode 100644 WCS.Model/ApiModel/MXL4/SysOrderMXL4Request.cs create mode 100644 WCS.Model/ApiModel/MXL4/TaskEnum.cs create mode 100644 WCS.Model/ApiModel/SingleLight/SingleLightControlRequest.cs create mode 100644 WCS.Model/ApiModel/UpLoad/UploadReelInfoRequest.cs delete mode 100644 WCS.WebApi/Controllers/DIYController.cs create mode 100644 WCS.WebApi/Controllers/MXL4Controller.cs create mode 100644 WCS.WebApi/Controllers/SingleLightController.cs create mode 100644 WCS.WebApi/Controllers/UpLoadController.cs diff --git a/WCS.BLL/DbModels/DingDingSendUser.cs b/WCS.BLL/DbModels/DingDingSendUser.cs deleted file mode 100644 index d19c848..0000000 --- a/WCS.BLL/DbModels/DingDingSendUser.cs +++ /dev/null @@ -1,19 +0,0 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WCS.BLL.DbModels -{ - [SugarTable("ding_ding_send_user")] - public class DingDingSendUser - { - /// - /// 工号 - /// - [SugarColumn(ColumnName = "user_name", Length = 50, IsNullable = true, ColumnDescription = "创建人")] - public string UserName { get; set; } - } -} diff --git a/WCS.BLL/DbModels/MatInfoLog.cs b/WCS.BLL/DbModels/MatInfoLog.cs new file mode 100644 index 0000000..aa6c178 --- /dev/null +++ b/WCS.BLL/DbModels/MatInfoLog.cs @@ -0,0 +1,49 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WCS.BLL.DbModels +{ + /// + ///物料信息表 + /// + [SugarTable("wcs_mat_info_log")] + public class MatInfoLog + { + /// + /// 主键 Id 自增 + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 物料编码 + /// + [SugarColumn(ColumnName = "mat_Sn", Length = 200, IsNullable = false, ColumnDescription = "物料唯一码")] + public string MatSn { get; set; } + + /// + /// 更新信息 + /// + [SugarColumn(ColumnName = "info", Length = 200, IsNullable = false, ColumnDescription = "更新信息")] + public string Info { get; set; } + + /// + /// 物料数量 + /// + [SugarColumn(ColumnName = "mat_qty", IsNullable = false, ColumnDescription = "物料数量")] + public int MatQty { get; set; } + + /// + /// Desc:更新时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "modify_time", IsNullable = true, ColumnDescription = "更新时间")] + public DateTime? ModifyTime { get; set; } = DateTime.Now; + + } +} diff --git a/WCS.BLL/DbModels/Task/CurrentTask.cs b/WCS.BLL/DbModels/Task/CurrentTask.cs new file mode 100644 index 0000000..6bc009b --- /dev/null +++ b/WCS.BLL/DbModels/Task/CurrentTask.cs @@ -0,0 +1,121 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.BLL.DbModels.Task; +using WCS.DAL.DbModels; + +namespace WCS.BLL.DbModels +{ + /// + /// 当前正在进行中的任务 + /// + [SugarTable("wcs_current_task")] + public class CurrentTask + { + /// + /// 主键 自增Id + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)] + public int Id { get; set; } + + #region 库位属性 + /// + /// 入库的库位表ID + /// + [SugarColumn(ColumnName = "store_id", IsNullable = false, ColumnDescription = "库位ID")] + public int StoreId { get; set; } + + /// + /// 入库的库位编码 + /// + [SugarColumn(ColumnName = "store_code", Length = 50, IsNullable = false, ColumnDescription = "库位编码")] + public string StoreCode { get; set; } + + [Navigate(NavigateType.OneToOne, nameof(StoreId))] + public StoreInfo StoreInfo { get; set; } + #endregion + + #region 任务属性 + /// + /// 任务Id + /// + [SugarColumn(ColumnName = "task_id", IsNullable = false, ColumnDescription = "任务Id,同一个库位只支持1-7")] + public int TaskID { get; set; } = 0; + + /// + /// Guid + /// + [SugarColumn(ColumnName = "guid", IsNullable = false, ColumnDescription = "Guid 系统那边任务的唯一ID")] + public Guid Guid { get; set; } + + /// + /// 任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2 + /// + [SugarColumn(ColumnName = "task_mode", IsNullable = false, ColumnDescription = "任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2")] + public TaskModeEnum TaskMode { get; set; } + + /// + /// 出库单据号 + /// + [SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")] + public string OrderNumber { get; set; } + + /// + /// 按钮颜色 + /// + [SugarColumn(ColumnName = "button_color", IsNullable = false, ColumnDescription = "按钮颜色 红色 = 1, 绿色 = 2, 黄色 = 3, 蓝色 = 4, 紫色 = 5, 青色 = 6, 白色 = 7,")] + public ButtonColorEnum ButtonColor { get; set; } + + /// + /// 物料编码 + /// + [SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")] + public string MatCode { get; set; } + + /// + /// 物料名称 + /// + [SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = true, ColumnDescription = "物料名称")] + public string MatName { get; set; } + + /// + /// 物料规格 + /// + [SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")] + public string MatSpec { get; set; } + + /// + /// 物料批次 + /// + [SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")] + public string MatBatch { get; set; } + + /// + /// 物料数量 + /// + [SugarColumn(ColumnName = "qty", IsNullable = false, ColumnDescription = "目标数量")] + public int Qty { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "创建时间")] + public DateTime CreateTime { get; set; } = DateTime.Now; + + /// + /// 任务是否被挂起 用于入库时取消入库,还没切换库位时 认为任务被挂起 同时只支持一个库位的任务被挂起 + /// + [SugarColumn(ColumnName = "is_suspended", IsNullable = false, ColumnDescription = "任务是否被挂起 用于入库时取消入库,还没切换库位时 认为任务被挂起")] + public bool IsSuspended { get; set; } = false; + + /// + /// 任务是否已发送至标签 + /// + [SugarColumn(ColumnName = "is_sended", IsNullable = false, ColumnDescription = "任务是否已发送至标签")] + public bool IsSended { get; set; } = false; + #endregion + } +} diff --git a/WCS.BLL/DbModels/Task/FinishedTask.cs b/WCS.BLL/DbModels/Task/FinishedTask.cs new file mode 100644 index 0000000..c3a7e59 --- /dev/null +++ b/WCS.BLL/DbModels/Task/FinishedTask.cs @@ -0,0 +1,125 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.BLL.DbModels.Task; +using WCS.DAL.DbModels; + +namespace WCS.BLL.DbModels +{ + /// + /// 已完成未提交的任务 + /// + [SugarTable("wcs_finished_task")] + public class FinishedTask + { + /// + /// 主键 自增Id + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)] + public int Id { get; set; } + + #region 库位属性 + /// + /// 入库的库位表ID + /// + [SugarColumn(ColumnName = "store_id", IsNullable = false, ColumnDescription = "库位ID")] + public int StoreId { get; set; } + + /// + /// 入库的库位编码 + /// + [SugarColumn(ColumnName = "store_code", Length = 50, IsNullable = false, ColumnDescription = "库位编码")] + public string StoreCode { get; set; } + + [Navigate(NavigateType.OneToOne, nameof(StoreId))] + public StoreInfo StoreInfo { get; set; } + #endregion + + #region 任务属性 + /// + /// 任务Id + /// + [SugarColumn(ColumnName = "task_id", IsNullable = false, ColumnDescription = "任务Id,同一个库位只支持1-7")] + public int TaskID { get; set; } + + /// + /// Guid + /// + [SugarColumn(ColumnName = "guid", IsNullable = false, ColumnDescription = "Guid 系统那边任务的唯一ID")] + public Guid Guid { get; set; } + + /// + /// 任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2 + /// + [SugarColumn(ColumnName = "task_mode", IsNullable = false, ColumnDescription = "任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2")] + public TaskModeEnum TaskMode { get; set; } + + /// + /// 出库单据号 + /// + [SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")] + public string OrderNumber { get; set; } + + /// + /// 按钮颜色 + /// + [SugarColumn(ColumnName = "button_color", IsNullable = false, ColumnDescription = "按钮颜色 红色 = 1, 绿色 = 2, 黄色 = 3, 蓝色 = 4, 紫色 = 5, 青色 = 6, 白色 = 7,")] + public ButtonColorEnum ButtonColor { get; set; } + + /// + /// 物料编码 + /// + [SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")] + public string MatCode { get; set; } + /// + /// 物料名称 + /// + [SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = true, ColumnDescription = "物料名称")] + public string MatName { get; set; } + + /// + /// 物料规格 + /// + [SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")] + public string MatSpec { get; set; } + + /// + /// 物料批次 + /// + [SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")] + public string MatBatch { get; set; } + + /// + /// 物料数量 + /// + [SugarColumn(ColumnName = "qty", IsNullable = false, ColumnDescription = "目标数量")] + public int Qty { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "创建时间")] + public DateTime CreateTime { get; set; } = DateTime.Now; + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "create_user", Length = 100, IsNullable = true, ColumnDescription = "创建人")] + public string CreateUser { get; set; } = string.Empty; + + /// + /// 完成时物料数量 + /// + [SugarColumn(ColumnName = "finish_qty", IsNullable = false, ColumnDescription = "完成数量")] + public int FinishQty { get; set; } = 0; + /// + /// 完成时间 + /// + [SugarColumn(ColumnName = "finish_time", IsNullable = false, ColumnDescription = "完成时间")] + public DateTime FinishTime { get; set; } = DateTime.Now; + #endregion + } +} diff --git a/WCS.BLL/DbModels/Task/UploadedTask.cs b/WCS.BLL/DbModels/Task/UploadedTask.cs new file mode 100644 index 0000000..f6b7ebd --- /dev/null +++ b/WCS.BLL/DbModels/Task/UploadedTask.cs @@ -0,0 +1,125 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.BLL.DbModels.Task; +using WCS.DAL.DbModels; + +namespace WCS.BLL.DbModels +{ + /// + /// 已完成已提交的历史任务 + /// + [SugarTable("wcs_uploaded_task")] + public class UploadededTask + { + /// + /// 主键 自增Id + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)] + public int Id { get; set; } + + #region 库位属性 + /// + /// 入库的库位表ID + /// + [SugarColumn(ColumnName = "store_id", IsNullable = false, ColumnDescription = "库位ID")] + public int StoreId { get; set; } + + /// + /// 入库的库位编码 + /// + [SugarColumn(ColumnName = "store_code", Length = 50, IsNullable = false, ColumnDescription = "库位编码")] + public string StoreCode { get; set; } + + [Navigate(NavigateType.OneToOne, nameof(StoreId))] + public StoreInfo StoreInfo { get; set; } + #endregion + + #region 任务属性 + /// + /// 任务Id + /// + [SugarColumn(ColumnName = "task_id", IsNullable = false, ColumnDescription = "任务Id,同一个库位只支持1-7")] + public int TaskID { get; set; } + + /// + /// Guid + /// + [SugarColumn(ColumnName = "guid", IsNullable = false, ColumnDescription = "Guid 系统那边任务的唯一ID")] + public Guid Guid { get; set; } + + /// + /// 任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2 + /// + [SugarColumn(ColumnName = "task_mode", IsNullable = false, ColumnDescription = "任务模式:入库模式 = 0, 出库模式 = 1, 盘点模式 = 2")] + public TaskModeEnum TaskMode { get; set; } + + /// + /// 出库单据号 + /// + [SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")] + public string OrderNumber { get; set; } + + /// + /// 按钮颜色 + /// + [SugarColumn(ColumnName = "button_color", IsNullable = false, ColumnDescription = "按钮颜色 红色 = 1, 绿色 = 2, 黄色 = 3, 蓝色 = 4, 紫色 = 5, 青色 = 6, 白色 = 7,")] + public ButtonColorEnum ButtonColor { get; set; } + + /// + /// 物料编码 + /// + [SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")] + public string MatCode { get; set; } + /// + /// 物料名称 + /// + [SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = true, ColumnDescription = "物料名称")] + public string MatName { get; set; } + + /// + /// 物料规格 + /// + [SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")] + public string MatSpec { get; set; } + + /// + /// 物料批次 + /// + [SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")] + public string MatBatch { get; set; } + + /// + /// 物料数量 + /// + [SugarColumn(ColumnName = "qty", IsNullable = false, ColumnDescription = "目标数量")] + public int Qty { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "创建时间")] + public DateTime CreateTime { get; set; } = DateTime.Now; + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "create_user", Length = 100, IsNullable = true, ColumnDescription = "创建人")] + public string CreateUser { get; set; } = string.Empty; + + /// + /// 完成时物料数量 + /// + [SugarColumn(ColumnName = "finish_qty", IsNullable = false, ColumnDescription = "完成数量")] + public int FinishQty { get; set; } = 0; + /// + /// 完成时间 + /// + [SugarColumn(ColumnName = "finish_time", IsNullable = false, ColumnDescription = "完成时间")] + public DateTime FinishTime { get; set; } = DateTime.Now; + #endregion + } +} diff --git a/WCS.BLL/Manager/DbInit.cs b/WCS.BLL/Manager/DbInit.cs index 69b92e8..ccba627 100644 --- a/WCS.BLL/Manager/DbInit.cs +++ b/WCS.BLL/Manager/DbInit.cs @@ -72,7 +72,7 @@ namespace WCS.BLL.Manager , typeof(InventoryDetail), typeof(OutOrder), typeof(OutOrderDetail), typeof(OutOrderMatDetail) , typeof(ShelfTypeInfo), typeof(MatBaseInfo), typeof(MatInfo) , typeof(StockTakingOrder), typeof(StockTakingOrderMatDetail), typeof(InOutRecord) - , typeof(DocumentSerialNumber),typeof(OrderLight) + , typeof(DocumentSerialNumber),typeof(OrderLight),typeof(MatInfoLog) ); Logs.Write("【初始化数据库】db建表", LogsType.StartBoot); diff --git a/WCS.BLL/Manager/TCPClientManager.cs b/WCS.BLL/Manager/TCPClientManager.cs index 955ca1a..cfbd4fa 100644 --- a/WCS.BLL/Manager/TCPClientManager.cs +++ b/WCS.BLL/Manager/TCPClientManager.cs @@ -60,6 +60,14 @@ namespace WCS.BLL.Manager return EasyTask.CompletedTask; } + if (tcpCleint.ShelfTypeName == "液晶货架") + { + Logs.Write($"【液晶货架开始处理接收数据】{BitConverter.ToString(data)}", LogsType.Instructions); + //Helper.ReturnDataProcess(TcpCleint, data); + Logs.Write($"【液晶货架完成处理接收数据】{BitConverter.ToString(data)}", LogsType.Instructions); + return EasyTask.CompletedTask; + } + for (int index = 0; index < data.Length - TcpCleint.PreFixLength; index++) { //协议拆包 通过前缀校验是否为完整数据包 diff --git a/WCS.BLL/Services/IService/IMXL4Service.cs b/WCS.BLL/Services/IService/IMXL4Service.cs new file mode 100644 index 0000000..08e9a61 --- /dev/null +++ b/WCS.BLL/Services/IService/IMXL4Service.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.Model; +using WCS.Model.ApiModel.MXL4; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.WebSocketModel; + +namespace WCS.BLL.Services.IService +{ + /// + /// 处理、查询报警使用的服务 + /// + public interface IMXL4Service + { + public Task> sysOrderMXL4(SysOrderMXL4Request request); + } +} diff --git a/WCS.BLL/Services/IService/ISingleLightService.cs b/WCS.BLL/Services/IService/ISingleLightService.cs new file mode 100644 index 0000000..16efc4e --- /dev/null +++ b/WCS.BLL/Services/IService/ISingleLightService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.Model; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.WebSocketModel; + +namespace WCS.BLL.Services.IService +{ + /// + /// 处理、查询报警使用的服务 + /// + public interface ISingleLightService + { + public Task> SingleLightControl(SingleLightControlRequest request); + } +} diff --git a/WCS.BLL/Services/IService/IUploadService.cs b/WCS.BLL/Services/IService/IUploadService.cs new file mode 100644 index 0000000..bfe5967 --- /dev/null +++ b/WCS.BLL/Services/IService/IUploadService.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.Model; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.UpLoad; +using WCS.Model.WebSocketModel; + +namespace WCS.BLL.Services.IService +{ + /// + /// 处理、查询报警使用的服务 + /// + public interface IUploadService + { + public Task UploadReelInfo(UploadReelInfoRequest request); + + public Task GetReelInfo(string MatSn); + } +} diff --git a/WCS.BLL/Services/Service/InstoreService.cs.orig b/WCS.BLL/Services/Service/InstoreService.cs.orig deleted file mode 100644 index b0977c8..0000000 --- a/WCS.BLL/Services/Service/InstoreService.cs.orig +++ /dev/null @@ -1,552 +0,0 @@ -using OracleInternal.SqlAndPlsqlParser.LocalParsing; -using System.ComponentModel.DataAnnotations.Schema; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -using WCS.BLL.Config; -using WCS.BLL.DbModels; -using WCS.BLL.HardWare; -using WCS.BLL.Manager; -using WCS.BLL.Services.IService; -using WCS.BLL.Tool; -using WCS.BLL.Tool.Api.ApiModel; -using WCS.DAL.Db; -using WCS.DAL.DbModels; -using WCS.Model; -using WCS.Model.ApiModel.InOutRecord; -using WCS.Model.ApiModel.MXBackgroundThread; - -namespace WCS.BLL.Services.Service -{ - public class InstoreService : IInstoreService - { - public InstoreService() { } - - public ResponseBase shelfGoInInStore(ShelfGoInInstoreRequest request) - { - //校验货架编码规则 - //取配置文件中得货架编码规则 - bool isValid = false; - var patterns = LocalFile.Config.ModuleCodePatterns; - if (patterns != null && patterns.Count > 0) - { - foreach (var pattern in patterns) - { - isValid = Regex.IsMatch(request.ModuleCode, pattern); - //匹配到第一个符合条件的货架码 就直接退出循环 认为匹配成功 - if (isValid) - break; - } - } - //如果配置文件缺失 使用默认正则进行匹配 - else - { - isValid = Regex.IsMatch(request.ModuleCode, LocalFile.DefaultModuleCodePattern); - } - - if (!isValid) - { - return new ResponseBase() - { - Code = 202, - Message = $"模组编码{request.ModuleCode}不满足模组编码规则!", - }; - } - //找到模组对应的货架 - var shelf = ShelfManager.Shelves.Where(t => t.ModulesStr.Contains(request.ModuleCode)).FirstOrDefault(); - if (shelf == null)//未找到 - { - return new ResponseBase() - { - Code = 201, - Message = "未找到模组对应的货架", - }; - } - //已找到模组对应货架 - shelf.GoInInstore(request.IpAdress); - - if (shelf.CurrentMode == Mode.入库模式) - //成功进入入库模式 - return new ShelfGoInInstoreResponse() - { - Code = 200, - Message = $"货架进入入库模式成功!{string.Join(",", shelf.ExceptionMessages)}", - Data = new ShelfGoInInstoreDto() - { - ShelfCode = shelf.ShelfCode, - ModulesStr = shelf.ModulesStr, - } - }; - else - return new ShelfGoInInstoreResponse() - { - Code = 201, - Message = $"货架进入入库模式失败:{string.Join(",", shelf.ExceptionMessages)}", - Data = null - }; - - } - - public ResponseBase shelfGoOutInStore(ShelfGoOutInStoreRequest request) - { - //获取货架 - var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault(); - if (shelf == null)//货架不存在 - { - return new ResponseCommon() - { - Code = 201, - Message = $"退出入库模式失败:货架[{request.ShelfCode}]不存在!", - }; - } - - //判断扫码枪 是否被其他扫码枪所占用 如果占用 直接退出入库模式 不发指令 - shelf.GoOutInstore(); - - if (shelf.ExceptionMessages == null || shelf.ExceptionMessages.Count == 0) - //已退出 - return new ResponseCommon() - { - Code = 200, - Message = $"货架[{request.ShelfCode}]已退出入库模式!", - }; - else - return new ResponseCommon() - { - Code = 200, - Message = $"货架[{request.ShelfCode}]已退出入库模式!{string.Join(",", shelf.ExceptionMessages)}", - }; - } - - public async Task queryByMatSn(QueryByMatSnRequest request) - { - //判断物料是否已入库 - var inventory = await DbHelp.db.Queryable().Where(t => t.MatSN == request.MatSn).FirstAsync(); - if (inventory != null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:物料{inventory.MatSN}已入库!库位为{inventory.StoreCode}", - }; - } - - IShelfBase shelf = null; - if (!request.SingleLightIn) - { - //获取货架 - shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault(); - if (shelf == null)//货架不存在 - { - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:货架[{request.ShelfCode}]不存在!", - }; - } - //判断当前是否是入库模式 - if (shelf.CurrentMode != Mode.入库模式) - { - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurrentMode}", - }; - } - } - - #region 获取物料数据 //调用接口或者直接查询数据库 - // 调用接口 - if (LocalFile.Config.IsAccessWMS) - { - #region 调用WMS接口获取物料信息 - try - { - var body = new - { - materialBar = request.MatSn - }; - var Result = ApiHelp.GetDataFromHttp>>("http://192.168.2.23:9213/integrate/instock/queryBybar", body, "POST", true); - - //查询到物料信息 - if (Result != null && Result.Code == 200 && Result.Data != null && Result.Data.Count > 0) - { - var data = Result.Data.First(); - if (!request.SingleLightIn && shelf != null) - shelf.InStoreData = new MatInfoResponse() - { - materialBar = data.materialBar, - materialCode = data.materialCode, - materialName = data.materialName, - materialQty = data.materialQty, - materialSpec = data.materialSpec, - batchNo = data.batchNo, - supplier = "", - customer = "", - - InstoreUser = request.UserName - }; - - var matInfo = new MatInfo() - { - MatSn = data.materialBar, - MatCode = data.materialCode, - MatName = data.materialName, - MatBatch = data.batchNo, - MatQty = (int)data.materialQty, - MatSpec = data.materialSpec, - MatSupplier = "", - MatCustomer = "", - }; - - return new ResponseCommon() - { - Code = 200, - Data = matInfo, - Message = "success" - }; - } - else if (Result != null && Result.Code == 200 && Result.Data == null) - { - //Mes系统中未获取到物料信息 - - //简单校验看是否满足海康物料 - //海康物料 只扫了外箱码 未扫条码 - if ((request.MatSn.Length == 54 || request.MatSn.Length == 56) && !request.MatSn.Contains("\\") && !request.MatSn.Contains("/")) - { - - if (!request.SingleLightIn && shelf != null) - shelf.InStoreData = new MatInfoResponse() - { - materialBar = request.MatSn, - materialCode = "暂时未知", - materialName = "暂时未知", - materialQty = 0, - materialSpec = "暂时未知", - batchNo = "暂时未知", - supplier = "", - customer = "", - - InstoreUser = request.UserName - }; - - var matInfo = new MatInfo() - { - MatSn = request.MatSn, - MatCode = "暂时未知", - MatName = "暂时未知", - MatBatch = "暂时未知", - MatQty = 0, - MatSpec = "暂时未知", - MatSupplier = "", - MatCustomer = "", - }; - - return new ResponseCommon() - { - Code = 200, - Data = matInfo, - Message = "success" - }; - } - - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:调用Mes接口未获取到物料信息!", - }; - } - else - { - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:调用Mes接口失败!", - }; - } - } - catch (Exception e) - { - return new ResponseCommon() - { - Code = 300, - Message = $"操作失败:调用Mes接口发生异常{e.Message}", - }; - } - #endregion - } - //查询数据库是否存在这个物料 - else - { - var matInfo = await DbHelp.db.Queryable().Where(t => t.MatSn == request.MatSn).FirstAsync(); - if (matInfo != null) - { - //TODO 改成wcs的实体 - if (!request.SingleLightIn && shelf != null) - shelf.InStoreData = new MatInfoResponse() - { - materialBar = matInfo.MatSn, - materialCode = matInfo.MatCode, - materialName = matInfo.MatName, - materialQty = matInfo.MatQty, - materialSpec = matInfo.MatSpec, - batchNo = matInfo.MatBatch, - supplier = matInfo.MatSupplier, - customer = matInfo.MatCustomer, - - InstoreUser = request.UserName - }; - - return new ResponseCommon() - { - Code = 200, - Data = matInfo, - Message = "success" - }; - } - else - return new ResponseCommon() - { - Code = 201, - Data = null, - Message = $"不存在物料{request.MatSn}" - }; - } - #endregion - } - - /// - /// 单灯出库时查询物料信息 这里返回库存的数据 - /// - /// - /// - public async Task queryByMatSnOut(QueryByMatSnRequest request) - { - //判断物料是否已入库 - var inventory = await DbHelp.db.Queryable().Where(t => t.MatSN == request.MatSn).FirstAsync(); - if (inventory == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"操作失败:物料不在库存内,无法进行出库!", - }; - } - else - { - return new ResponseCommon() - { - Code = 200, - Message = $"Success", - Data = new MatInfo() - { - MatSn = inventory.MatSN, - MatCode = inventory.MatCode, - MatName = inventory.MatName, - MatBatch = inventory.MatBatch, - MatQty = inventory.MatQty, - MatSpec = inventory.MatSpec, - MatSupplier = inventory.MatSupplier, - MatCustomer = inventory.MatCustomer, - } - }; - } - } - - public async Task queryInstoreStatus(QueryByMatSnRequest request) - { - //获取货架 - var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault(); - if (shelf == null)//货架不存在 - { - return new ResponseCommon() - { - Code = 201, - Message = $"货架[{request.ShelfCode}]不存在!", - }; - } - - //判断当前是否是入库模式 - if (shelf.CurrentMode != Mode.入库模式) - { - return new ResponseCommon() - { - Code = 201, - Message = $"货架[{request.ShelfCode}]已退出入库模式!\r\n当前为{shelf.CurrentMode}", - }; - } - - //TODO 配置这个时间相当于需要入库扫码后需要等待的时间 - var timeOut = 5000; - var timeSpan = TimeSpan.FromMilliseconds(0); - var beginTime = DateTime.Now; - while (timeSpan <= TimeSpan.FromMilliseconds(timeOut)) - { - timeSpan = DateTime.Now - beginTime; - //已入库当前扫码的物料时 查询数据库 - if (shelf.InStoreData == null || (shelf.InStoreData as object) == null) - { - await Task.Delay(50); - var inventoryDetail = DbHelp.db.Queryable() - .Where(t => t.MatSN == request.MatSn) - .First(); - if (inventoryDetail != null) - { - return new ResponseCommon() - { - Code = 200, - Message = $"入库成功!物料已放入库位{inventoryDetail.StoreCode}", - Data = new - { - StoreCode = inventoryDetail.StoreCode, - } - }; - } - else - break; - } - //延时处理 - Thread.Sleep(50); - } - //超时未成功入库 - shelf.InStoreData = null; - return new ResponseCommon() - { - Code = 201, - Message = $"超时未入库!请重新扫码后入库!", - Data = new - { - StoreCode = string.Empty, - } - }; - } - - public async Task queryInstoreStatusSingle(QueryByMatSnRequestSingle request) - { - //获取货架 - //var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault(); - //if (shelf == null)//货架不存在 - //{ - // return new ResponseCommon() - // { - // Code = 201, - // Message = $"货架[{request.ShelfCode}]不存在!", - // }; - //} - List MI = DbHelp.db.Queryable().Where(it => it.ModuleCode == request.ShelfCode).ToList(); - if (MI.Count == 0) - { - return new ResponseCommonSingle() - { - Code = 201, - Message = $"货架[{request.ShelfCode}]不存在!", - }; - } - ResponseCommonSingle rcs = new ResponseCommonSingle(); - rcs.Data = new List(); - - string sendIP = MI[0].CleintIp; //单灯IP - int PCBId = MI[0].BoardId; //单灯PCB板ID - - List SI = DbHelp.db.Queryable().Where(it => it.ModuleCode == request.ShelfCode).ToList(); - - List si = DbHelp.db.Queryable().Where(it => it.ShelfCode == MI[0].ShelfCode).ToList(); - int warnLightID = si[0].LightId; - - foreach (QueryByMatSnRequestSingle.MatSnListDetail matSnListDetail in request.MatSnList) - { - Detail detail = new Detail(); - try - { - InventoryDetail inventoryDetail = new InventoryDetail(); - inventoryDetail.MatSN = matSnListDetail.MatSn; - inventoryDetail.MatCode = matSnListDetail.MatCode; - inventoryDetail.MatName = matSnListDetail.MatName; - inventoryDetail.MatSpec = matSnListDetail.MatSpec; - inventoryDetail.MatBatch = matSnListDetail.MatBatch; - inventoryDetail.MatQty = matSnListDetail.MatQty; - inventoryDetail.MatCustomer = matSnListDetail.MatCustomer; - inventoryDetail.MatSupplier = matSnListDetail.MatSupplier; - inventoryDetail.StoreCode = request.ShelfCode; - inventoryDetail.StoreId = SI[0].Id; - - int count = DbHelp.db.Insertable(inventoryDetail).ExecuteCommand(); - - InOutRecord ior = new InOutRecord(); - ior.MatSN = matSnListDetail.MatSn; - ior.MatCode = matSnListDetail.MatCode; - ior.MatName = matSnListDetail.MatName; - ior.MatSpec = matSnListDetail.MatSpec; - ior.MatBatch = matSnListDetail.MatBatch; - ior.MatQty = matSnListDetail.MatQty; - ior.MatCustomer = matSnListDetail.MatCustomer; - ior.MatSupplier = matSnListDetail.MatSupplier; - ior.StoreCode = request.ShelfCode; - ior.StoreId = SI[0].Id; - ior.Direction = DirectionEnum.入库; - ior.OperateTime = DateTime.Now; - ior.OperateUser = request.UserName; - int count1 = DbHelp.db.Insertable(ior).ExecuteCommand(); - - detail.matsn = matSnListDetail.MatSn; - detail.result = "入库成功"; - rcs.Data.Add(detail); - } - catch (Exception ee) - { - detail.matsn = matSnListDetail.MatSn; - detail.result = "入库失败"; - detail.reason = ee.Message; - rcs.Data.Add(detail); - } - } - //亮灯 - TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(sendIP); -<<<<<<< HEAD - //byte[] data1 = new byte[8]; - //data1[0] = 0xff; - //data1[1] = 0x02; - //data1[2] = 0x00; - //data1[3] = 0x0a; - //data1[4] = (byte)warnLightID; - //data1[5] = 0x03; - //data1[6] = 0x02; - //data1[7] = 0x02; - //byte[] senddata1 = Tool.Helper.Crc16(data1, data1.Length, true); - byte[] senddata1 = Tool.Helper.InstoreWarnLight(warnLightID); -======= - byte[] data1 = new byte[8]; - data1[0] = 0xff; - data1[1] = 0x02; - data1[2] = 0x00; - data1[3] = 0x0a; - data1[4] = (byte)warnLightID; - data1[5] = 0x03; - data1[6] = 0x02; - data1[7] = 0x02; - byte[] senddata1 = Tool.Helper.Crc16(data1, data1.Length, false); ->>>>>>> 11 - tCPClient.Send(senddata1); //报警灯短亮一次 - - //byte[] data2 = new byte[8]; - //data2[0] = 0xff; - //data2[1] = 0x01; - //data2[2] = 0x00; - //data2[3] = 0x0a; - //data2[4] = 0x01; - //data2[5] = (byte)PCBId; - //data2[6] = 0x03; - //data2[7] = 0x02; - //byte[] senddata2 = Tool.Helper.Crc16(data2, data2.Length, true); - byte[] senddata2 = Tool.Helper.InstoreLight(PCBId); - tCPClient.Send(senddata2); //库位灯短亮一次 - - return new ResponseCommonSingle() - { - Code = 200, - Message = $"入库成功!", - Data = rcs.Data, - }; - - } - } -} diff --git a/WCS.BLL/Services/Service/MXL4Service.cs b/WCS.BLL/Services/Service/MXL4Service.cs new file mode 100644 index 0000000..7bc3678 --- /dev/null +++ b/WCS.BLL/Services/Service/MXL4Service.cs @@ -0,0 +1,125 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml.Xsl; +using TouchSocket.Core; +using WCS.BLL.DbModels; +using WCS.BLL.Manager; +using WCS.BLL.Services.IService; +using WCS.BLL.Tool; +using WCS.DAL; +using WCS.DAL.Db; +using WCS.DAL.Db.AuthDb; +using WCS.DAL.DbModels; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.MXL4; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; +using static System.Formats.Asn1.AsnWriter; +using static WCS.BLL.Tool.Helper; + +namespace WCS.BLL.Services.Service +{ + public class MXL4Service : IMXL4Service + { + public async Task> sysOrderMXL4(SysOrderMXL4Request request) + { + try + { + //第一步:获取所有库位码 校验库位在数据库中是否都存在 + var storeCodeList = request.List.Select(t => t.StoreCode) + .Distinct() + .ToList(); + var stores = DbHelp.db.Queryable() + .LeftJoin((si, sti) => si.ShelfTypeId == sti.Id) + .Where((si, sti) => sti.ShelfTypeName == "液晶货架") + .Where((si, sti) => storeCodeList.Contains(si.StoreCode)) + .Select((st, sti) => st) + .ToList(); + if (stores.Count < storeCodeList.Count) + { + var storeCodesInDB = stores.Select(t => t.StoreCode).ToList(); + storeCodeList.RemoveAll(t => storeCodesInDB.Contains(t)); + return new ResponseCommon + { + Code = 200, + Message = $"操作失败:库位【{string.Join(",", storeCodeList)}】不存在!", + }; + } + //第二步 获取当前所有库位任务 + //模式相同视为可以继续发送任务 + var currenTasks = DbHelp.db.Queryable() + .Where(t => storeCodeList.Contains(t.StoreCode)) + .ToList(); + var currenTasksNotThisMode = currenTasks.Where(t => t.TaskMode != request.OrderType).ToList(); ; + if (currenTasksNotThisMode.Any()) + { + var task = currenTasksNotThisMode.First(); + return new ResponseCommon + { + Code = 200, + Message = $"操作失败:库位【{task.StoreCode}】当前在{task.TaskMode}!", + }; + } + var tasks = new List(); + //生成任务数据 + foreach (var orderDetail in request.List) + { + var store = stores.Where(t => t.StoreCode == orderDetail.StoreCode).First(); + var task = new CurrentTask() + { + StoreId = store.Id, + StoreCode = store.StoreCode, + + Guid = orderDetail.Guid, + TaskMode = request.OrderType, + OrderNumber = request.OrderNumber, + ButtonColor = request.Corlor, + MatCode = orderDetail.MatCode, + MatName = orderDetail.MatName, + MatSpec = orderDetail.MatSpec, + MatBatch = orderDetail.MatBatch, + Qty = orderDetail.Qty + }; + tasks.Add(task); + } + try + { + DbHelp.db.BeginTran(); + DbHelp.db.Insertable(tasks).ExecuteCommand(); + DbHelp.db.CommitTran(); + } + catch (Exception ex) + { + DbHelp.db.RollbackTran(); + return new ResponseCommon + { + Code = 300, + Message = $"操作失败:{ex.Message}" + }; + } + //发送任务至各个标签 + return new ResponseCommon + { + Code = 200, + Message = "success" + }; + } + catch (Exception ex) + { + return new ResponseCommon + { + Code = 200, + Message = "操作失败:" + ex.Message, + + }; + } + } + } +} diff --git a/WCS.BLL/Services/Service/MatBaseInfoService.cs b/WCS.BLL/Services/Service/MatBaseInfoService.cs index 56ff8bb..3e2033e 100644 --- a/WCS.BLL/Services/Service/MatBaseInfoService.cs +++ b/WCS.BLL/Services/Service/MatBaseInfoService.cs @@ -386,9 +386,9 @@ namespace WCS.BLL.Services.Service if (request.IsFromBaseData) { matCodeList = await DbHelp.db.Queryable() + .OrderBy(t => t.MatCode) .Select(t => t.MatCode) .Distinct() - .OrderBy(t => t) .ToListAsync(); } else @@ -396,7 +396,6 @@ namespace WCS.BLL.Services.Service matCodeList = await DbHelp.db.Queryable() .Select(t => t.MatCode) .Distinct() - .OrderBy(t => t) .ToListAsync(); } return new ResponseCommon>() diff --git a/WCS.BLL/Services/Service/OutstoreService.cs b/WCS.BLL/Services/Service/OutstoreService.cs index 574e31f..476a8ab 100644 --- a/WCS.BLL/Services/Service/OutstoreService.cs +++ b/WCS.BLL/Services/Service/OutstoreService.cs @@ -1345,7 +1345,7 @@ namespace WCS.BLL.Services.Service } } //发送间隔 - Thread.Sleep(300); + //Thread.Sleep(300); foreach (string shelfcode in WarnLightShelfCode) { List si = DbHelp.db.Queryable().Where(it => it.ShelfCode == shelfcode).ToList(); @@ -1353,12 +1353,11 @@ namespace WCS.BLL.Services.Service { for (int i = 0; i < si.Count; i++) { + Thread.Sleep(250); TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(si[i].ClientIp); - //byte[] warnlightOn = Helper.OutstoreWarnLight(si[i].LightId, LightColor, 0, 0); byte[] warnlightOn = Helper.OutstoreWarnLight_1(si[i].LightId, LightColor, 0, 0); tCPClient.Send(warnlightOn); Logs.Write("出库,报警灯灭:" + BitConverter.ToString(warnlightOn)); - Thread.Sleep(100); } } } diff --git a/WCS.BLL/Services/Service/OutstoreService.cs.orig b/WCS.BLL/Services/Service/OutstoreService.cs.orig deleted file mode 100644 index 3ec8826..0000000 --- a/WCS.BLL/Services/Service/OutstoreService.cs.orig +++ /dev/null @@ -1,1311 +0,0 @@ -using Microsoft.Data.SqlClient; -using SqlSugar; -using WCS.BLL.Config; -using WCS.BLL.DbModels; -using WCS.BLL.Manager; -using WCS.BLL.Services.IService; -using WCS.BLL.Tool; -using WCS.DAL.Db; -using WCS.Model; -using WCS.Model.ApiModel.InOutRecord; -using WCS.Model.ApiModel.MatInventoryDetail; -using WCS.Model.ApiModel.OutStore; - -namespace WCS.BLL.Services.Service -{ - public class OutstoreService : IOutstoreService - { - public OutstoreService() - { - - } - public async Task>> importMat(List list) - { - //数据校验 - if (list == null || list.Count == 0) - { - return new ResponseCommon>() - { - Code = 201, - Message = "导入失败:导入文件中没有内容!" - }; - } - //需求数量 - var errorCount = list.Where(t => t.需求数量 <= 0).ToList(); - if (errorCount != null && errorCount.Count > 0) - { - return new ResponseCommon>() - { - Code = 201, - Message = "导入失败:需求数量需要大于0!" - }; - } - //每一个物料进行搜索库存 - var returnList = new List(); - foreach (var item in list) - { - var inventoryCount = await DbHelp.db.Queryable() - .Where(t => t.MatCode == item.物料编码) - .Where(t => t.MatBatch == item.物料批次) - .Where(t => t.IsLocked == false) - .SumAsync(t => t.MatQty); - var info = inventoryCount < item.需求数量 ? "库存数量小于需求数量" : string.Empty; - returnList.Add(new MatInventorySummaryModel() - { - MatCode = item.物料编码, - MatName = item.物料名称, - MatBatch = item.物料批次, - NeedQty = item.需求数量, - TotalQty = inventoryCount, - Info = info - }); - } - return new ResponseCommon>() - { - Code = 200, - Data = returnList - }; - } - public async Task SysOutOrderByMatCode(SysOutOrderByMatCodeRequest request) - { - //参数合法性校验 - if (request.ItemList == null || request.ItemList.Count == 0) - { - return new ResponseBase() - { - Code = 201, - Message = "出库单据同步失败:缺少需要出库的物料类型!" - }; - } - //补齐货架类型名称 - if (string.IsNullOrEmpty(request.ShelfTypeName)) - { - var shelfType = await DbHelp.db.Queryable() - .Where(t => t.Id == request.ShelfTypeId) - .FirstAsync(); - if (shelfType == null) - { - return new ResponseBase() - { - Code = 201, - Message = $"出库单据同步失败:缺少必要参数!ShelfTypeId" - }; - } - else - request.ShelfTypeName = shelfType.ShelfTypeName; - } - - //保存数据 - await DbHelp.db.BeginTranAsync(); - try - { - var order = new OutOrder() - { - OrderNumber = request.OrderNumber, - OrderSource = request.OrderSource, - OrderType = request.OrderType, - ShelfTypeId = request.ShelfTypeId, - ShelfTypeName = request.ShelfTypeName, - SyncType = SyncTypeEnum.ByMatCode, - CreateUser = request.UserName, - }; - order.Id = await DbHelp.db.Insertable(order).ExecuteReturnIdentityAsync(); - request.ItemList.ForEach(async item => - { - var orderDetail = new OutOrderDetail() - { - OrderId = order.Id, - OrderNumber = order.OrderNumber, - MatCode = item.MatCode, - MatName = item.MatName, - MatBatch = item.MatBatch, - ReqQty = item.ReqQty, - OutQty = 0, - CreateUser = request.UserName - }; - await DbHelp.db.Insertable(orderDetail).ExecuteCommandAsync(); - }); - await DbHelp.db.CommitTranAsync(); - return new ResponseCommon() - { - Code = 200, - Message = $"出库单据同步成功!\r\n出库单据号为{request.OrderNumber}", - }; ; - } - catch (Exception ex) - { - await DbHelp.db.RollbackTranAsync(); - Console.WriteLine(ex.Message); - return new ResponseBase() - { - Code = 200, - Message = $"出库单据同步失败:{ex.Message}" - }; - } - } - - public async Task SysOutOrderByMatSn(SysOutOrderByMatSnRequest request) - { - - //参数合法性校验 - if (request.SnList == null || request.SnList.Count == 0) - { - return new ResponseBase() - { - Code = 201, - Message = "出库单据同步失败:缺少物料明细!" - }; - } - //标准版逻辑-库存有无校验 & 库存已锁校验 - if (!LocalFile.Config.IsMx) - { - try - { - await DbHelp.db.BeginTranAsync(); - var inventoryDetails = await DbHelp.db.Queryable() - .Where(t => request.SnList.Contains(t.MatSN)) - .TranLock(DbLockType.Wait) - .ToListAsync(); - if (inventoryDetails.Count < request.SnList.Count)//库存的物料少于需求的物料数量 - { - var existsSns = inventoryDetails.Select(t => t.MatSN).ToList(); - request.SnList.RemoveAll(t => existsSns.Contains(t)); - await DbHelp.db.RollbackTranAsync(); - //返回提示哪些物料库存不存在 - return new ResponseCommon() - { - Code = 201, - Message = "出库单据同步失败:存在物料不在库存中!", - Data = request.SnList - - }; - } - else if (inventoryDetails.Where(t => t.IsLocked).Any()) - { - await DbHelp.db.RollbackTranAsync(); - //返回提示哪些物料库存已被锁定 - return new ResponseCommon() - { - Code = 201, - Message = "出库单据同步失败:存在物料被锁定!", - Data = inventoryDetails.Where(t => t.IsLocked).Select(t => t.MatSN).ToList() - }; - } - - #region 保存数据 - - //锁库存 - inventoryDetails.ForEach(t => - { - t.IsLocked = true; - }); - var lockTask = DbHelp.db.Updateable(inventoryDetails).ExecuteCommandAsync(); - - //保存数据 - var order = new OutOrder() - { - OrderNumber = request.OrderNumber, - OrderSource = request.OrderSource, - OrderType = request.OrderType, - SyncType = SyncTypeEnum.ByMatSn, - CreateUser = request.UserName, - }; - order.Id = await DbHelp.db.Insertable(order).ExecuteReturnIdentityAsync(); - - //通过库存数据保存出库物料明细表 - var matDetailTasks = inventoryDetails.Select(async t => - { - var orderMatDetail = new OutOrderMatDetail() - { - OrderId = order.Id, - OrderNumber = order.OrderNumber, - InventoryDetailId = t.Id, - StoreId = t.StoreId, - StoreCode = t.StoreCode, - MatSN = t.MatSN, - MatCode = t.MatCode, - MatName = t.MatName, - MatSpec = t.MatSpec, - MatBatch = t.MatBatch, - MatQty = t.MatQty, - MatSupplier = t.MatSupplier, - MatCustomer = t.MatCustomer, - CreateUser = request.UserName - }; - await DbHelp.db.Insertable(orderMatDetail).ExecuteCommandAsync(); - }).ToList(); - - await lockTask; - await Task.WhenAll(matDetailTasks); - - await DbHelp.db.CommitTranAsync(); - return new ResponseCommon() - { - Code = 200, - Message = $"出库单据同步成功!\r\n出库单据号为{request.OrderNumber}", - Data = order.Id - }; - #endregion - } - catch (Exception ex) - { - await DbHelp.db.RollbackTranAsync(); - return new ResponseBase() - { - Code = 201, - Message = $"出库单据同步失败:{ex.Message}" - }; - } - } - //盟讯公司逻辑 不锁库存 直接保存数据/清除未发送的 - else - { - try - { - DbHelp.db.BeginTran(); - //1. 获取库存物料明细 - var inventoryDetails = await DbHelp.db.Queryable() - .Where(t => request.SnList.Contains(t.MatSN)) - .ToListAsync(); - if (inventoryDetails == null || inventoryDetails.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = "保存出库单失败!请重试!", - Data = request.SnList - }; - } - //2. 先获取对应单号是否已经保存 - var outOrder = DbHelp.db.Queryable() - .Where(t => t.OrderNumber == request.OrderNumber) - .Where(t => t.GroupName == LocalFile.Config.GroupName) - .First(); - //数据库中没有才添加 - if (outOrder == null) - { - //OutOrder - outOrder = new OutOrder() - { - OrderNumber = request.OrderNumber, - OutOrderExeStatus = OutOrderExeStatus.开始发料, - OrderSource = "WCS前端", - SyncType = SyncTypeEnum.ByMatSn, - ShelfTypeName = "智能货架", - ShelfTypeId = 0, - GroupName = LocalFile.Config.GroupName, - }; - outOrder.Id = await DbHelp.db.Insertable(outOrder).ExecuteReturnIdentityAsync(); - outOrder = await DbHelp.db.Queryable().Where(t => t.OrderNumber == request.OrderNumber) - .Where(t => t.Id == outOrder.Id) - .FirstAsync(); - //保存单据失败了 - if (outOrder == null) - return new ResponseCommon() - { - Code = 201, - Message = "保存出库单失败!保存Order失败!", - Data = request.SnList - }; - - //出库物料明细 - foreach (var item in inventoryDetails) - { - var orderMatDetail = new OutOrderMatDetail() - { - OrderId = outOrder.Id, - OrderNumber = outOrder.OrderNumber, - InventoryDetailId = item.Id, - StoreId = item.StoreId, - StoreCode = item.StoreCode, - MatSN = item.MatSN, - MatCode = item.MatCode, - MatName = item.MatName, - MatSpec = item.MatSpec, - MatBatch = item.MatBatch, - MatQty = item.MatQty, - MatSupplier = item.MatSupplier, - MatCustomer = item.MatCustomer, - CreateUser = request.UserName - }; - await DbHelp.db.Insertable(orderMatDetail).ExecuteCommandAsync(); - } - DbHelp.db.CommitTran(); - } - //数据库已有该Order - else - { - outOrder.CreateTime = DateTime.Now; - DbHelp.db.Updateable(outOrder).ExecuteCommand(); - //删除未出库的 - var outOrderDetails = DbHelp.db.Deleteable() - .Where(t => t.OrderId == outOrder.Id) - .Where(t => t.IsSended == false) - .ExecuteCommand(); - //当前已出库的 //已出库的也不在库存中了 应该查询不到了 - //避免影响效率 就不查重了 - foreach (var item in inventoryDetails) - { - var orderMatDetail = new OutOrderMatDetail() - { - OrderId = outOrder.Id, - OrderNumber = outOrder.OrderNumber, - InventoryDetailId = item.Id, - StoreId = item.StoreId, - StoreCode = item.StoreCode, - MatSN = item.MatSN, - MatCode = item.MatCode, - MatName = item.MatName, - MatSpec = item.MatSpec, - MatBatch = item.MatBatch, - MatQty = item.MatQty, - MatSupplier = item.MatSupplier, - MatCustomer = item.MatCustomer, - CreateUser = request.UserName - }; - await DbHelp.db.Insertable(orderMatDetail).ExecuteCommandAsync(); - } - DbHelp.db.CommitTran(); - - //更新订单状态 - Task.Run(() => - { - if (outOrder != null) - { - #region 物料明细表是否已发完 - var orderMatDetails = DbHelp.db.Queryable() - .Where(t => t.OrderId == outOrder.Id) - .ToList(); - var isExistNoSendMat = orderMatDetails.Where(t => t.IsSended == false) - .Any(); - if (isExistNoSendMat) - { - outOrder.OrderStatus = OutOrderStatus.部分发料; - } - else - { - outOrder.OrderStatus = OutOrderStatus.全部发料; - outOrder.OutOrderExeStatus = OutOrderExeStatus.发料完成; - } - #endregion - DbHelp.db.Updateable(outOrder).ExecuteCommand(); - } - }); - } - return new ResponseCommon() - { - Code = 200, - Message = $"Success", - Data = request.SnList - }; - - } - catch (Exception ex) - { - DbHelp.db.RollbackTran(); - Logs.Write($"同步出库单据发生异常{ex.Message}", LogsType.Info); - return new ResponseCommon() - { - Code = 201, - Message = $"保存出库单失败!{ex.Message}!", - Data = request.SnList - }; - } - - } - - } - - public async Task GetOutOrderList(GetOutOrderListRequest request) - { - //直接查询 - var recordsQueryable = DbHelp.db.Queryable() - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber.Contains(request.OrderNumber)) - .WhereIF(!string.IsNullOrEmpty(request.OrderSource), t => t.OrderSource.Contains(request.OrderSource)) - .WhereIF(!string.IsNullOrEmpty(request.OrderType), t => t.OrderType.Contains(request.OrderType)) - .WhereIF(request.ShelfTypeId != 0, t => t.ShelfTypeId == request.ShelfTypeId); - - var totalCount = await recordsQueryable.CountAsync(); - var records = await recordsQueryable - .Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize) - .ToListAsync(); - //生成序号 - for (int i = 0; i < records.Count; i++) - { - records[i].RowNumber = (request.PageNumber - 1) * request.PageSize + i + 1; - } - - return new PageQueryResponse() - { - Code = 200, - Message = $"success", - Data = new PageQueryResponseData() - { - TotalCount = totalCount, - MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize), - Count = records.Count, - Lists = records.ToList() - } - }; - } - - public async Task GetOutOrderListByStatus(GetOutOrderListByStatusRequest request) - { - if (request.OrderExeStatus == null || request.OrderExeStatus.Count == 0) - { - //不传入状态不显示 - return new PageQueryResponse() - { - Code = 200, - Message = $"success", - Data = new PageQueryResponseData() - { - Lists = new List() - } - }; - } - //直接查询 - var recordsQueryable = DbHelp.db.Queryable().Where(t => request.OrderExeStatus.Contains(t.OutOrderExeStatus)); - - var totalCount = await recordsQueryable.CountAsync(); - var records = await recordsQueryable - .OrderByDescending(t => t.CreateTime) - //.Take(request.PageSize) - .ToListAsync(); - - return new PageQueryResponse() - { - Code = 200, - Message = $"success", - Data = new PageQueryResponseData() - { - //TotalCount = totalCount, - //MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize), - //Count = records.Count, - Lists = records.ToList() - } - }; - } - public async Task GetOutOrderDetail(GetOutOrderDetailRequest request) - { - OutOrder outOrder = null; - - #region 查询出库单 - if (request.OrderId != 0) - { - outOrder = await DbHelp.db.Queryable().Where(t => t.Id == request.OrderId).FirstAsync(); - if (outOrder == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:不存在Id为{request.OrderId}的出库单!", - }; - } - } - else if (!string.IsNullOrEmpty(request.OrderNumber)) - { - outOrder = await DbHelp.db.Queryable().Where(t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (outOrder == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:不存在出库单据号为{request.OrderNumber}的出库单!", - }; - } - } - else - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:缺少必要参数!", - }; - } - #endregion - - #region 查询出库单明细 - var orderDetailTask = DbHelp.db.Queryable() - .Where(t => t.OrderId == outOrder.Id) - .ToListAsync(); - var orderDetail = await orderDetailTask; - //生成序号 - for (int i = 0; i < orderDetail.Count; i++) - { - orderDetail[i].RowNumber = i + 1; - } - #endregion - - return new ResponseCommon>() - { - Code = 200, - Message = "Success", - Data = orderDetail - }; - } - - public async Task GetOutOrderMatDetail(GetOutOrderDetailRequest request) - { - OutOrder outOrder = null; - - #region 查询出库单 - if (request.OrderId != 0) - { - outOrder = await DbHelp.db.Queryable().Where(t => t.Id == request.OrderId).FirstAsync(); - if (outOrder == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:不存在Id为{request.OrderId}的出库单!", - }; - } - } - else if (!string.IsNullOrEmpty(request.OrderNumber)) - { - outOrder = await DbHelp.db.Queryable().Where(t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (outOrder == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:不存在出库单据号为{request.OrderNumber}的出库单!", - }; - } - } - else - { - return new ResponseCommon() - { - Code = 201, - Message = $"查询失败:缺少必要参数!", - }; - } - #endregion - - #region 出库物料明细 - var orderMatDetailTask = DbHelp.db.Queryable() - .Where(t => t.OrderId == outOrder.Id) - .ToListAsync(); - var orderMatDetail = await orderMatDetailTask; - //生成序号 - for (int i = 0; i < orderMatDetail.Count; i++) - { - orderMatDetail[i].RowNumber = i + 1; - } - #endregion - - - return new ResponseCommon> - { - Code = 200, - Message = outOrder.OrderStatus.ToString(), - Data = orderMatDetail - }; - } - - public async Task GoInOutstore(GetOutOrderDetailRequest request) - { - try - { - //获取出库单 - var order = await DbHelp.db.Queryable() - .WhereIF(request.OrderId != 0, t => t.Id == request.OrderId) - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (order == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"不存在对应的出库单据{request.OrderNumber}!", - Data = null - }; - } - - - //如果是按物料编码出库 需要计算物料明细、并进行物料锁定 - if (order.SyncType == SyncTypeEnum.ByMatCode) - { - var result = CaculateOutOrderMatDetails(order, request.UserName); - if (result.Code != 200) - { - return result; - } - } - - //获取需要出库的物料明细 - var outOrderMatDetails = DbHelp.db.Queryable() - .Where(t => t.OrderId == order.Id) - .Where(t => t.IsSended == false) - .Includes(t => t.StoreInfo) - .ToList(); - if (outOrderMatDetails == null || outOrderMatDetails.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"出库单据{request.OrderNumber}物料已全部完成出库!", - Data = null - }; - } - - if (request.IsStart)//&& order.OutOrderExeStatus != OutOrderExeStatus.发料完成 - { - order.OutOrderExeStatus = OutOrderExeStatus.开始发料; - DbHelp.db.Updateable(order).ExecuteCommand(); - } - - //按货架分组 按物料找到对应的货架 - var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId) - .Distinct() - .ToList(); - var shelfs = ShelfManager.Shelves.Where(t => shelfIds.Contains(t.ShelfId)).ToList(); ; - - var outherModeShelfs = shelfs.Where(t => t.CurrentMode != HardWare.Mode.待机模式).Select(t => t.ShelfCode).ToList(); - if (outherModeShelfs != null && outherModeShelfs.Count > 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"进入出库模式失败:货架{string.Join("", outherModeShelfs)}不在待机模式", - Data = null - }; - } - //看是否是分批次出库的情况 分批次亮灯 - if (LocalFile.Config.IsSameMatCodeOut) - { - var outOrderDetailCount = outOrderMatDetails.GroupBy(t => t.MatCode) - .Select(o => new { count = o.Count(), bb = o }) - .Where(o => o.count >= 2) - .OrderByDescending(o => o.count) - .ToList(); - //相同物料存在盘数超过2的情况,亮下一个盘数多的物料 - if (outOrderDetailCount.Count > 0) - { - var matCode = outOrderDetailCount.First().bb.Key; - outOrderMatDetails = outOrderMatDetails.Where(t => t.MatCode == matCode) - .ToList(); - Logs.Write($"出库单{order.OrderNumber},本次亮灯物料{matCode}!"); - } - //相同物料不存在盘数超过n的情况,剩余物料全部亮灯 - else - { - //剩余物料全出 - Logs.Write($"出库单{order.OrderNumber},剩余物料灯全亮!"); - } - } - - //对应的货架对应位置 进入出库模式 亮灯 - shelfs.ForEach(shelf => - { - var matDetails = outOrderMatDetails.Where(t => t.StoreInfo.ShelfCode == shelf.ShelfCode) - .Distinct() - .ToList(); - shelf.GoInOutstore(matDetails, order); - shelf.OrderNumber = order.OrderNumber; - }); - - //返回 - return new ResponseCommon() - { - Code = 200, - Message = "Success", - Data = null - }; - } - catch (Exception ex) - { - await GoOutOutstore(request); - throw ex; - } - } - - public async Task GoInOutstoreSingle(GetOutOrderDetailRequest request) - { - try - { - //获取出库单 - var order = await DbHelp.db.Queryable() - .WhereIF(request.OrderId != 0, t => t.Id == request.OrderId) - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (order == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"不存在对应的出库单据{request.OrderNumber}!", - Data = null - }; - } - - - //如果是按物料编码出库 需要计算物料明细、并进行物料锁定 - if (order.SyncType == SyncTypeEnum.ByMatCode) - { - var result = CaculateOutOrderMatDetails(order, request.UserName); - if (result.Code != 200) - { - return result; - } - } - - //获取需要出库的物料明细 - var outOrderMatDetails = DbHelp.db.Queryable() - .Where(t => t.OrderId == order.Id) - .Where(t => t.IsSended == false) - .Includes(t => t.StoreInfo) - .ToList(); - if (outOrderMatDetails == null || outOrderMatDetails.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"出库单据{request.OrderNumber}物料已全部完成出库!", - Data = null - }; - } - - if (request.IsStart)//&& order.OutOrderExeStatus != OutOrderExeStatus.发料完成 - { - order.OutOrderExeStatus = OutOrderExeStatus.开始发料; - DbHelp.db.Updateable(order).ExecuteCommand(); - } - //获取亮灯颜色 - List UsedColor = new List(); - string LightColor = ""; - List ol = DbHelp.db.Queryable().OrderBy(it => it.Id, OrderByType.Asc).ToList(); - foreach (OrderLight orderLight in ol) - { - UsedColor.Add(orderLight.LightColor); - if (orderLight.OrderNumber == request.OrderNumber) - { - LightColor = orderLight.LightColor; - break; - } - } - if (LightColor == "") - { - foreach (OrderLight orderLight in ol) - { - if (orderLight.OrderNumber == null) - { - LightColor = orderLight.LightColor; - DbHelp.db.Updateable().SetColumns(it => it.OrderNumber, request.OrderNumber).Where(it => it.LightColor == LightColor).ExecuteCommand(); - break; - } - } - } - //获取出库需求 - List outorderdetal = DbHelp.db.Queryable() - .WhereIF(request.OrderId != 0, t => t.OrderId == request.OrderId) - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber) - .ToList(); - - OutResponseCommonSingle orcs = new OutResponseCommonSingle(); - orcs.Data = new List(); - foreach (OutOrderDetail outdetail in outorderdetal) - { - OutDetail od = new OutDetail(); - od.OrderId = outdetail.OrderId; - od.OrderNumber = outdetail.OrderNumber; - od.MatCode = outdetail.MatCode; - od.MatBatch = outdetail.MatBatch; - od.ReqQty = outdetail.ReqQty; - od.CreateTime = outdetail.CreateTime; - od.CreateUser = outdetail.CreateUser; - od.MatName = outdetail.MatName; - od.OutQty = outdetail.OutQty; - od.LightColor = LightColor; - orcs.Data.Add(od); - } - //需要出库的货架名 - List StoreCode = new List(); - //库位灯亮灯 - Dictionary> dict = new Dictionary>(); - foreach (OutOrderMatDetail oomd in outOrderMatDetails) - { - List mi= DbHelp.db.Queryable().Where(it => it.ModuleCode == oomd.StoreCode).ToList(); - if (mi.Count != 0) - { - if (!StoreCode.Contains(oomd.StoreCode)) - { - StoreCode.Add(oomd.StoreCode); - } - if (!dict.Keys.Contains(mi[0].CleintIp)) - { - List board_id = new List(); - board_id.Add(mi[0].BoardId); - dict.Add(mi[0].CleintIp, board_id); - } - else - { - foreach (var v in dict) - { - if (v.Key == mi[0].CleintIp) - { - if (!v.Value.Contains(mi[0].BoardId)) - { - v.Value.Add(mi[0].BoardId); - } - } - } - } - } - } - foreach (var v in dict) - { - string sendIP = v.Key; - TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(sendIP); - byte[] lightOn = Helper.OutstoreLight(v.Value, LightColor,1); - tCPClient.Send(lightOn); - Thread.Sleep(100); - } - //报警灯亮 - List WarnLightShelfCode = new List(); - foreach (string storecode in StoreCode) - { - List mi = DbHelp.db.Queryable().Where(it => it.ModuleCode == storecode).ToList(); - if (mi.Count != 0) - { - if (!WarnLightShelfCode.Contains(mi[0].ShelfCode)) - { - WarnLightShelfCode.Add(mi[0].ShelfCode); - } - } - } - foreach (string shelfcode in WarnLightShelfCode) - { - List si = DbHelp.db.Queryable().Where(it => it.ShelfCode == shelfcode).ToList(); - if (si.Count != 0) - { - for (int i = 0; i < si.Count; i++) - { - TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(si[i].ClientIp); - byte[] warnlightOn = Helper.OutstoreWarnLight(si[i].LightId,"无",1,0); - tCPClient.Send(warnlightOn); - Thread.Sleep(100); - } - } - } - //返回 - return new OutResponseCommonSingle() - { - Code = 200, - Message = "Success", - Data = orcs.Data - }; - } - catch (Exception ex) - { - await GoOutOutstore(request); - throw ex; - } - } - - //计算、加锁 - private ResponseBase CaculateOutOrderMatDetails(OutOrder order, string createUser = "") - { - try - { - DbHelp.db.BeginTran(); - //第一步 物料需求表 - var outOrderDetails = DbHelp.db.Queryable() - .Where(t => t.OrderId == order.Id) - .ToList(); - if (outOrderDetails == null || outOrderDetails.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"计算物料失败,{order.OrderNumber}没有出库单据明细!" - }; - } - //第二步 开始计算物料 - List outOrderMatDetails = new List(); - foreach (var outOrderDetail in outOrderDetails) - { - //2.1筛选 满足 物料编码、批次的库存 - var matInventoryDetails = DbHelp.db.Queryable() - .Where(t => t.MatCode == outOrderDetail.MatCode) - .WhereIF(!string.IsNullOrEmpty(outOrderDetail.MatBatch), t => t.MatBatch == outOrderDetail.MatBatch) - .Where(t => t.IsLocked == false)//未锁定的物料 - .Where(t => t.StoreInfo.ShelfTypeId == order.ShelfTypeId) - .OrderBy(t => t.MatBatch)//按批次先进先出 - //(t => t.MatQty)//零散料先出 - .ToList(); - - //2.2按照搜索出来的库存和当前未出的数量 计算需要出的SN - for (int i = 0; i < matInventoryDetails.Count && outOrderDetail.ReqQty - outOrderDetail.OutQty > 0; i++) - { - if (outOrderDetail.ReqQty - outOrderDetail.OutQty <= matInventoryDetails[i].MatQty) - { - outOrderMatDetails.Add(new OutOrderMatDetail() - { - OrderId = order.Id, - OrderNumber = order.OrderNumber, - OutOrderDetailId = outOrderDetail.Id, - InventoryDetailId = matInventoryDetails[i].Id, - StoreId = matInventoryDetails[i].StoreId, - StoreCode = matInventoryDetails[i].StoreCode, - MatSN = matInventoryDetails[i].MatSN, - MatCode = matInventoryDetails[i].MatCode, - MatName = matInventoryDetails[i].MatName, - MatSpec = matInventoryDetails[i].MatSpec, - MatBatch = matInventoryDetails[i].MatBatch, - MatQty = matInventoryDetails[i].MatQty, - MatSupplier = matInventoryDetails[i].MatSupplier, - MatCustomer = matInventoryDetails[i].MatCustomer, - IsSended = false, - CreateUser = createUser, - }); - outOrderDetail.ReqQty = 0; - - matInventoryDetails[i].IsLocked = true; - DbHelp.db.Updateable(matInventoryDetails[i]).ExecuteCommand(); - } - else - { - outOrderDetail.ReqQty = outOrderDetail.ReqQty - matInventoryDetails[i].MatQty; - - outOrderMatDetails.Add(new OutOrderMatDetail() - { - OrderId = order.Id, - OrderNumber = order.OrderNumber, - OutOrderDetailId = outOrderDetail.Id, - InventoryDetailId = matInventoryDetails[i].Id, - StoreId = matInventoryDetails[i].StoreId, - StoreCode = matInventoryDetails[i].StoreCode, - MatSN = matInventoryDetails[i].MatSN, - MatCode = matInventoryDetails[i].MatCode, - MatName = matInventoryDetails[i].MatName, - MatSpec = matInventoryDetails[i].MatSpec, - MatBatch = matInventoryDetails[i].MatBatch, - MatQty = matInventoryDetails[i].MatQty, - MatSupplier = matInventoryDetails[i].MatSupplier, - MatCustomer = matInventoryDetails[i].MatCustomer, - IsSended = false, - CreateUser = createUser, - }); - - matInventoryDetails[i].IsLocked = true; - DbHelp.db.Updateable(matInventoryDetails[i]).ExecuteCommand(); - } - } - } - DbHelp.db.Insertable(outOrderMatDetails).ExecuteCommand(); - DbHelp.db.CommitTran(); - if (outOrderMatDetails.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"计算物料失败,没有满足条件的物料进行出库!(请检查对应物料是否已被锁定)" - }; - } - else - - return new ResponseCommon() - { - Code = 200, - Message = $"Success" - }; - } - catch (Exception ex) - { - DbHelp.db.RollbackTran(); - return new ResponseCommon() - { - Code = 300, - Message = $"发生异常:{ex.Message}" - }; - } - } - - //删除 解锁 - private ResponseBase CancelOutOrderMatDetails(OutOrder order) - { - try - { - DbHelp.db.BeginTran(); - var outOrderMatDetails = DbHelp.db.Queryable() - .Where(t => t.OrderId == order.Id) - .Where(t => t.IsSended == false) - .ToList(); - - var inventoryIds = outOrderMatDetails.Select(t => t.InventoryDetailId).ToList(); - var inventoryDetails = DbHelp.db.Queryable() - .Where(t => inventoryIds.Contains(t.Id)) - .ToList(); - inventoryDetails.ForEach(t => { t.IsLocked = false; }); - DbHelp.db.Deleteable(outOrderMatDetails).ExecuteCommand(); - DbHelp.db.Updateable(inventoryDetails).ExecuteCommand(); - - DbHelp.db.CommitTran(); - return new ResponseCommon() - { - Code = 200, - Message = $"Success" - }; - } - catch (Exception ex) - { - DbHelp.db.RollbackTran(); - return new ResponseCommon() - { - Code = 300, - Message = $"解锁物料时发生异常:{ex.Message}" - }; - } - } - - public async Task GoOutOutstore(GetOutOrderDetailRequest request) - { - - //获取出库单 - var order = await DbHelp.db.Queryable() - .WhereIF(request.OrderId != 0, t => t.Id == request.OrderId) - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (order == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"不存在对应的出库单据{request.OrderNumber}!", - Data = null - }; - } - - //执行状态改为暂停 - if (request.IsPause && order.OutOrderExeStatus != OutOrderExeStatus.发料完成) - { - order.OutOrderExeStatus = OutOrderExeStatus.暂停发料; - DbHelp.db.Updateable(order).ExecuteCommand(); - } - - //解锁物料 删除物料明细 - if (order.SyncType == SyncTypeEnum.ByMatCode) - CancelOutOrderMatDetails(order); - - //找到正在出对应出库单的货架 - var shelves = ShelfManager.Shelves.Where(t => t.OrderNumber == request.OrderNumber) - .Where(t => t.CurrentMode == HardWare.Mode.出库模式) - .ToList(); - - if (shelves == null || shelves.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"出库单据【{request.OrderNumber}】不在出库中!", - Data = null - }; - } - - - - //退出出库模式 - shelves.ForEach(t => - { - t.GoOutOutstore(); - }); - - - - return new ResponseCommon() - { - Code = 200, - Message = "Success", - Data = null - }; - - } - - public async Task GoOutOutstoreSingle(GetOutOrderDetailRequest request) - { - - //获取出库单 - var order = await DbHelp.db.Queryable() - .WhereIF(request.OrderId != 0, t => t.Id == request.OrderId) - .WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber) - .FirstAsync(); - if (order == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"不存在对应的出库单据{request.OrderNumber}!", - Data = null - }; - } - - //判断出库状态 - bool isComplete = true; - List ood = DbHelp.db.Queryable().Where(it => it.OrderNumber == request.OrderNumber).ToList(); - foreach (OutOrderDetail detail in ood) - { - if (detail.ReqQty > detail.OutQty) - { - isComplete = false; - break; - } - } - if (isComplete == false) - { - order.OutOrderExeStatus = OutOrderExeStatus.暂停发料; - DbHelp.db.Updateable(order).ExecuteCommand(); - } - else - { - order.OutOrderExeStatus = OutOrderExeStatus.发料完成; - DbHelp.db.Updateable(order).ExecuteCommand(); - } - //解锁物料 - List List = DbHelp.db.Queryable().Where(it => it.OrderNumber == request.OrderNumber).ToList(); - foreach (OutOrderMatDetail listdetail in List) - { - DbHelp.db.Updateable().SetColumns(it => it.IsLocked == false).Where(it => it.MatSN == listdetail.MatSN).ExecuteCommand(); - } - - DbHelp.db.Updateable().SetColumns(it => it.OrderNumber == null).Where(it => it.OrderNumber == request.OrderNumber).ExecuteCommand(); - //灭灯 -<<<<<<< HEAD - //获取需要出库的物料明细 - var outOrderMatDetails = DbHelp.db.Queryable() - .Where(t => t.OrderNumber == request.OrderNumber) - .ToList(); - //需要出库的货架名 - List StoreCode = new List(); - //库位灯灭灯 - Dictionary> dict = new Dictionary>(); - foreach (OutOrderMatDetail oomd in outOrderMatDetails) - { - List mi = DbHelp.db.Queryable().Where(it => it.ModuleCode == oomd.StoreCode).ToList(); - if (mi.Count != 0) - { - if (!StoreCode.Contains(oomd.StoreCode)) - { - StoreCode.Add(oomd.StoreCode); - } - if (!dict.Keys.Contains(mi[0].CleintIp)) - { - List board_id = new List(); - board_id.Add(mi[0].BoardId); - dict.Add(mi[0].CleintIp, board_id); - } - else - { - foreach (var v in dict) - { - if (v.Key == mi[0].CleintIp) - { - if (!v.Value.Contains(mi[0].BoardId)) - { - v.Value.Add(mi[0].BoardId); - } - } - } - } - } - } - foreach (var v in dict) - { - string sendIP = v.Key; - TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(sendIP); - byte[] lightOn = Helper.OutstoreLight(v.Value, "无",0); - tCPClient.Send(lightOn); - Thread.Sleep(100); - } - //报警灯灭 - List WarnLightShelfCode = new List(); - foreach (string storecode in StoreCode) - { - List mi = DbHelp.db.Queryable().Where(it => it.ModuleCode == storecode).ToList(); - if (mi.Count != 0) - { - if (!WarnLightShelfCode.Contains(mi[0].ShelfCode)) - { - WarnLightShelfCode.Add(mi[0].ShelfCode); - } - } - } - foreach (string shelfcode in WarnLightShelfCode) - { - List si = DbHelp.db.Queryable().Where(it => it.ShelfCode == shelfcode).ToList(); - if (si.Count != 0) - { - for (int i = 0; i < si.Count; i++) - { - TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(si[i].ClientIp); - byte[] warnlightOn = Helper.OutstoreWarnLight(si[i].LightId, "无", 0, 0); - tCPClient.Send(warnlightOn); - Thread.Sleep(100); - } - } - } - - -======= ->>>>>>> 11 - - return new ResponseCommon() - { - Code = 200, - Message = "Success", - Data = null - }; - - } - - public async Task SingleLightConfirmOutstore(OutOrderMatDetailModelSingle request) - { - InOutRecord ior = new InOutRecord(); - List id = DbHelp.db.Queryable().Where(it => it.MatSN == request.MatSn).ToList(); - if (id.Count == 0) - { - return new ResponseCommon() - { - Code = 201, - Message = $"此SN不在库存中{request.MatSn}!", - Data = null - }; - } - ior.StoreId = id[0].StoreId; - ior.StoreCode = id[0].StoreCode; - ior.MatSN = request.MatSn; - ior.MatCode = request.MatCode; - ior.MatName = request.MatName; - ior.MatSpec = request.MatSpec; - ior.MatBatch = request.MatBatch; - ior.MatQty = request.Qty; - ior.MatSupplier = request.MatSupplier; - ior.MatCustomer = request.MatCustomer; - ior.OrderNumber = request.orderNumber; - ior.Direction = DirectionEnum.出库; - ior.OperateUser = request.userName; - ior.OperateTime = DateTime.Now; - //保存出库记录 - int count = DbHelp.db.Insertable(ior).ExecuteCommand(); - //删除库存 - DbHelp.db.Deleteable().Where(it => it.MatSN == request.MatSn).ExecuteCommand(); - //更新需求表 - List odd = DbHelp.db.Queryable().Where(it => it.OrderNumber == request.orderNumber).Where(it => it.MatCode == request.MatCode).ToList(); - odd[0].OutQty += request.Qty; - DbHelp.db.Updateable(odd[0]).ExecuteCommand(); - - return new ResponseCommon() - { - Code = 200, - Message = $"出库成功", - Data = null - }; - } - - - } -} diff --git a/WCS.BLL/Services/Service/SingleLightService.cs b/WCS.BLL/Services/Service/SingleLightService.cs new file mode 100644 index 0000000..3b342c3 --- /dev/null +++ b/WCS.BLL/Services/Service/SingleLightService.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using TouchSocket.Core; +using WCS.BLL.Manager; +using WCS.BLL.Services.IService; +using WCS.BLL.Tool; +using WCS.DAL; +using WCS.DAL.Db; +using WCS.DAL.Db.AuthDb; +using WCS.DAL.DbModels; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; +using static System.Formats.Asn1.AsnWriter; +using static WCS.BLL.Tool.Helper; + +namespace WCS.BLL.Services.Service +{ + public class SingleLightService : ISingleLightService + { + public async Task> SingleLightControl(SingleLightControlRequest request) + { + try + { + //传入数据校验 + if (request.StoreList == null || request.StoreList.Count == 0) + { + return new ResponseCommon() + { + Code = 201, + Message = "操作失败:没有需要控制的库位", + }; + } + //对应库位 + var storeCodes = request.StoreList.Select(t => t.StoreCode) + .Distinct() + .ToList(); + var stores = DbHelp.db.Queryable().Where(t => storeCodes.Contains(t.StoreCode)) + .ToList(); + if (stores == null || stores.Count == 0) + { + return new ResponseCommon + { + Code = 201, + Message = $"操作失败:所有库位不存在!" + }; + } + + //对应货架(获取TCP和报警灯ID) + var shelfIds = stores.Select(t => t.ShelfId).Distinct().ToList(); + var shelfs = DbHelp.db.Queryable().Where(t => shelfIds.Contains(t.Id)) + .ToList(); + //对应模组信息 + var moduleIds = stores.Select(t => t.ModuleId).Distinct().ToList(); + var modules = DbHelp.db.Queryable().Where(t => moduleIds.Contains(t.Id)) + .ToList(); + + //加载请求参数中的库位灯 板子ID和货架ID + foreach (var store in request.StoreList) + { + var storeInDb = stores.Where(t => t.StoreCode == store.StoreCode).FirstOrDefault(); + if (storeInDb == null) + { + return new ResponseCommon + { + Code = 201, + Message = $"操作失败:库位{store.StoreCode}不存在(store)!" + }; + } + else + store.ShelfId = storeInDb.ShelfId; + + var moduleInDb = modules.Where(t => t.Id == storeInDb.ModuleId).FirstOrDefault(); + if (moduleInDb == null) + { + return new ResponseCommon + { + Code = 201, + Message = $"操作失败:库位{store.StoreCode}不存在(module)!" + }; + } + else + store.BoardId = moduleInDb.BoardId; + } + + //合并:同一个货架的库位合并 + var shelfModels = new List(); + foreach (var shelf in shelfs) + { + var shelfModel = new SingleLightShelfModel(); + //报警灯 + shelfModel.WarningLightMode = request.WarningLightMode; + shelfModel.WarningBuzzerMode = request.WarningBuzzerMode; + shelfModel.WarningLightColor = request.WarningLightColor; + shelfModel.WarningBoardId = shelf.LightId; + shelfModel.ClientIp = shelf.ClientIp; + //库位 + var storesThisShelf = request.StoreList + .Where(t => t.ShelfId == shelf.Id) + .ToList(); + foreach (var storeThisShelf in storesThisShelf) + { + shelfModel.StoreList.Add(new SingleLightStoreModel() + { + BoardId = storeThisShelf.BoardId, + LightColor = storeThisShelf.LightColor, + LightMode = storeThisShelf.LightMode, + }); + } + shelfModels.Add(shelfModel); + } + + //合并:同一个TCP的货架合并 报警灯和库位灯统一只发送一条指令 + var clientIpList = shelfs.Select(t => t.ClientIp) + .Distinct() + .ToList(); + foreach (var clientIp in clientIpList) + { + var shelfModelsInOneIp = shelfModels.Where(t => t.ClientIp == clientIp).ToList(); + var sendData = Helper.SingleLightControl(shelfModelsInOneIp); + + TCPClient tCPClient = TCPClientManager.GetTCPClientByIPHost(clientIp); + tCPClient.Send(sendData); + Logs.Write("【单灯单独控制】发送指令" + BitConverter.ToString(sendData)); + } + + //返回成功 + return new ResponseCommon() + { + Code = 200, + Message = "success", + }; + } + catch (Exception ex) + { + + //操作失败 + return new ResponseCommon() + { + Code = 300, + Message = $"操作失败:{ex.Message}", + }; + } + } + } +} diff --git a/WCS.BLL/Services/Service/UploadService.cs b/WCS.BLL/Services/Service/UploadService.cs new file mode 100644 index 0000000..015f7f7 --- /dev/null +++ b/WCS.BLL/Services/Service/UploadService.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using TouchSocket.Core; +using WCS.BLL.DbModels; +using WCS.BLL.Manager; +using WCS.BLL.Services.IService; +using WCS.BLL.Tool; +using WCS.DAL; +using WCS.DAL.Db; +using WCS.DAL.Db.AuthDb; +using WCS.DAL.DbModels; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.UpLoad; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; +using static System.Formats.Asn1.AsnWriter; +using static WCS.BLL.Tool.Helper; + +namespace WCS.BLL.Services.Service +{ + public class UploadService : IUploadService + { + public async Task GetReelInfo(string MatSn) + { + if (string.IsNullOrEmpty(MatSn)) + { + return new ResponseBase() + { + Code = 201, + Message = "操作失败:条码不能为空" + }; + } + + //查询物料条码是否存在 + var matInfo = await DbHelp.db.Queryable() + .Where(t => t.MatSn == MatSn) + .FirstAsync(); + return new ResponseBase() + { + Code = 200, + Message = "success", + Data = new + { + MatSN = matInfo?.MatSn, + Qty = matInfo?.MatQty + } + }; + } + + public async Task UploadReelInfo(UploadReelInfoRequest request) + { + //校验参数 + if (string.IsNullOrEmpty(request.MatSN) || request.Qty <= 0) + { + return new ResponseBase() + { + Code = 201, + Message = "操作失败:条码或数量不合法!" + }; + } + + //查询物料条码是否存在 + var matInfo = await DbHelp.db.Queryable() + .Where(t => t.MatSn == request.MatSN) + .FirstAsync(); + + if (matInfo == null) + { + return new ResponseBase() + { + Code = 201, + Message = $"操作失败:不存在此条码【{request.MatSN}】" + }; + } + + //是否在库存中 + var inventoryDetail = await DbHelp.db.Queryable() + .Where(t => t.MatSN == request.MatSN) + .FirstAsync(); + + if (inventoryDetail != null) + { + return new ResponseBase() + { + Code = 201, + Message = $"操作失败:此条码在库位{inventoryDetail.StoreCode}上,请下架后再进行操作。" + }; + } + try + { + DbHelp.db.BeginTran(); + + //记录日志 + var MatInfoLog = new MatInfoLog() + { + MatQty = request.Qty, + MatSn = request.MatSN, + Info = $"[{request.IPAddress}]数量从{matInfo.MatQty}修改为{request.Qty}!" + }; + DbHelp.db.Insertable(MatInfoLog).ExecuteCommand(); + + + //修改数量 + matInfo.MatQty = request.Qty; + DbHelp.db.Updateable(matInfo).ExecuteCommand(); + + DbHelp.db.CommitTran(); + return new ResponseBase() + { + Code = 200, + Message = "success" + }; + + + } + catch (Exception ex) + { + DbHelp.db.RollbackTran(); + return new ResponseBase() + { + Code = 300, + Message = "操作失败:" + ex.Message + }; + } + + + + } + } +} diff --git a/WCS.BLL/Tool/Helper.cs b/WCS.BLL/Tool/Helper.cs index b3b8e06..5e404df 100644 --- a/WCS.BLL/Tool/Helper.cs +++ b/WCS.BLL/Tool/Helper.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -83,7 +84,6 @@ namespace WCS.BLL.Tool } return data.ToArray(); } - public static byte[] Query() { byte[] data2 = new byte[4]; @@ -94,7 +94,6 @@ namespace WCS.BLL.Tool byte[] senddata2 = Tool.Helper.Crc16(data2, data2.Length, true); return senddata2; } - public static byte[] SetId() { byte[] data2 = new byte[6]; @@ -107,7 +106,6 @@ namespace WCS.BLL.Tool byte[] senddata2 = Tool.Helper.Crc16(data2, data2.Length, true); return senddata2; } - //出库库位灯亮灯 public static byte[] OutstoreLight(List board_id, string lightcolor, int status) { @@ -155,7 +153,6 @@ namespace WCS.BLL.Tool byte[] data = Crc16(data1, data1.Length, true); return data; } - //出库警示灯亮灯 public static byte[] OutstoreWarnLight(int lightid, string lightcolor, int status, int beestatus) { @@ -240,8 +237,6 @@ namespace WCS.BLL.Tool byte[] senddata1 = Tool.Helper.Crc16(data1, data1.Length, true); return senddata1; } - - public static byte[] InstoreLightAndWarnLight(int board_id, int lightid) { byte[] data1 = new byte[8 + 3 * 7]; @@ -340,6 +335,92 @@ namespace WCS.BLL.Tool return data; } + /// + /// 单灯货架控制 + /// + /// + /// + /// + /// + public static byte[] SingleLightControl(List shelfs) + { + byte[] dataBase = new byte[5]; + dataBase[0] = 0xff; + dataBase[1] = 0x01; + + //一个报警灯一个货架 + var lightCount = 0; + foreach (var shelf in shelfs) + { + //6个报警灯需要发送指令 + + if (shelf.WarningLightMode != -1) + { + for (int i = 0; i < 6; i++) + { + var singleLightData = GenerateSingleLightData(shelf.WarningBoardId + i, shelf.WarningLightMode, shelf.WarningLightColor); + lightCount++; + dataBase = dataBase.Concat(singleLightData).ToArray(); + } + } + //蜂鸣器需要发送指令 + if (shelf.WarningBuzzerMode != -1) + { + var singleLightData = GenerateSingleLightData(shelf.WarningBoardId + 6, shelf.WarningBuzzerMode, shelf.WarningLightColor); + lightCount++; + dataBase = dataBase.Concat(singleLightData).ToArray(); + } + + //库位灯指令 + if (shelf.StoreList != null && shelf.StoreList.Count > 0) + { + foreach (var store in shelf.StoreList) + { + var singleLightData = GenerateSingleLightData(store.BoardId, store.LightMode, store.LightColor); + lightCount++; + dataBase = dataBase.Concat(singleLightData).ToArray(); + } + } + } + + byte[] length_base = BitConverter.GetBytes(dataBase.Length + 2); + dataBase[2] = length_base[1]; + dataBase[3] = length_base[0]; + //控制灯的数量 + dataBase[4] = (byte)lightCount; + + byte[] dataWithCRC = Crc16(dataBase, dataBase.Length, true); + return dataWithCRC; + } + //单独拼接一个灯的协议 + public static byte[] GenerateSingleLightData(int lightId, int lightMode, int lightColor) + { + var data = new byte[3]; + + data[0] = (byte)lightId; + data[1] = (byte)lightMode; + data[2] = (byte)lightColor; + + return data; + } + + public class SingleLightShelfModel + { + public string ClientIp { get; set; } = string.Empty; + public int WarningBoardId { get; set; } + public int WarningLightMode { get; set; } + public int WarningBuzzerMode { get; set; } + public int WarningLightColor { get; set; } + public List StoreList { get; set; } = new List(); + } + + public class SingleLightStoreModel + { + public int BoardId { get; set; } + public int LightMode { get; set; } + public int LightColor { get; set; } + } + /// /// 返回数据处理 /// @@ -396,9 +477,9 @@ namespace WCS.BLL.Tool data1[6 + i * 3] = (byte)status; data1[7 + i * 3] = color; } - //data1[5 + 3 * 7 - 3] = (byte)(lightid + 6); - //data1[5 + 3 * 7 - 2] =(byte)beestatus; - //data1[5 + 3 * 7 - 1] = 0x00; + //dataBase[5 + 3 * 7 - 3] = (byte)(lightid + 6); + //dataBase[5 + 3 * 7 - 2] =(byte)beestatus; + //dataBase[5 + 3 * 7 - 1] = 0x00; byte[] data2 = Crc16(data1, data1.Length, true); return data2; } diff --git a/WCS.BLL/Tool/TCPClient.cs b/WCS.BLL/Tool/TCPClient.cs index 697d01f..b0fc136 100644 --- a/WCS.BLL/Tool/TCPClient.cs +++ b/WCS.BLL/Tool/TCPClient.cs @@ -100,17 +100,21 @@ namespace WCS.BLL { //查询当前板子是否有待验证的指令 var message = new MessageDto(); - var firstMessage = MessageList.Select(t => new { Id = t.Key ,Value = t.Value }) + var firstMessage = MessageList.Select(t => new { Id = t.Key, Value = t.Value }) .OrderBy(t => t.Value.CreateTime) .First(); if (firstMessage != null) { MessageList.TryRemove(firstMessage.Id, out message); - Logs.Write($"【信息化货架】以下指令已不重发:{BitConverter.ToString(firstMessage.Value.Message)}"); + Logs.Write($"【信息化货架】以下指令已不重发:{BitConverter.ToString(firstMessage.Value.Message)}", LogsType.InstructionResend); } } } } + else if (ShelfTypeName == "液晶货架") + { + Logs.Write($"【液晶货架】接收到指令{BitConverter.ToString(data)}", LogsType.InstructionResend); + } //智能货架 else { @@ -235,7 +239,7 @@ namespace WCS.BLL } catch (Exception ex) { - Logs.Write("【发送指令时发生异常】" + ex.Message , LogsType.Instructions); + Logs.Write("【发送指令时发生异常】" + ex.Message, LogsType.Instructions); //因异常断连时(网线已经被断了) 手动重连一次 if (ex is NotConnectedException) { diff --git a/WCS.Model/ApiModel/MXL4/SysOrderMXL4Request.cs b/WCS.Model/ApiModel/MXL4/SysOrderMXL4Request.cs new file mode 100644 index 0000000..1b7e17f --- /dev/null +++ b/WCS.Model/ApiModel/MXL4/SysOrderMXL4Request.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; +using WCS.BLL.DbModels.Task; + +namespace WCS.Model.ApiModel.MXL4 +{ + public class SysOrderMXL4Request : RequestBase + { + + /// + /// 按钮颜色 + /// + public ButtonColorEnum Corlor { get; set; } + + /// + /// 任务单号 + /// + public string OrderNumber { get; set; } + + /// + /// 任务类型 出库/入库/盘点 + /// + public TaskModeEnum OrderType { get; set; } + + /// + /// 单据明细 + /// + public List List { get; set; } + } + + public class MXL4OrderDetail + { + /// + /// Guid系统那边任务的主键 + /// + public Guid Guid { get; set; } + + /// + /// 库位编码 + /// + public string StoreCode { get; set; } + + /// + /// 物料编码 + /// + public string MatCode { get; set; } + + /// + /// 物料名称 + /// + public string MatName { get; set; } + + /// + /// 物料规格 + /// + public string MatSpec { get; set; } + + /// + /// 物料批次 + /// + public string MatBatch { get; set; } + + /// + /// 数量 + /// + public int Qty { get; set; } + } +} diff --git a/WCS.Model/ApiModel/MXL4/TaskEnum.cs b/WCS.Model/ApiModel/MXL4/TaskEnum.cs new file mode 100644 index 0000000..b92b9a3 --- /dev/null +++ b/WCS.Model/ApiModel/MXL4/TaskEnum.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WCS.BLL.DbModels.Task +{ + /// + /// 按键灯颜色 + /// + public enum ButtonColorEnum + { + 红色 = 1, + 绿色 = 2, + 黄色 = 3, + 蓝色 = 4, + 紫色 = 5, + 青色 = 6, + 白色 = 7, + } + + public enum TaskModeEnum + { + 入库模式 = 0, + 出库模式 = 1, + 盘点模式 = 2 + } +} diff --git a/WCS.Model/ApiModel/SingleLight/SingleLightControlRequest.cs b/WCS.Model/ApiModel/SingleLight/SingleLightControlRequest.cs new file mode 100644 index 0000000..f350d54 --- /dev/null +++ b/WCS.Model/ApiModel/SingleLight/SingleLightControlRequest.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.SingleLight +{ + public class SingleLightControlRequest : RequestBase + { + /// + /// 巷道灯颜色 如果不传 默认为-1 不发送对应指令 + /// + public int WarningLightColor { get; set; } = -1; + public int WarningLightMode { get; set; } = -1; + /// + /// 巷道灯蜂鸣器模式 如果不传 默认为-1 不发送对应指令 + /// + public int WarningBuzzerMode { get; set; } = -1; + + /// + /// 库位灯控制 + /// + public List StoreList { get; set; } + } + + public class StoreListItem + { + #region + /// + /// 库位编码 + /// + public string StoreCode { get; set; } + /// + /// 货架Id + /// + public int ShelfId { get; set; } = 0; + /// + /// 板子Id + /// + public int BoardId { get; set; } = 0; + /// + /// 亮灯模式 + /// + public int LightMode { get; set; } = 0; + + /// + /// 亮灯颜色 + /// + public int LightColor { get; set; } = 0; + #endregion + } + +} diff --git a/WCS.Model/ApiModel/UpLoad/UploadReelInfoRequest.cs b/WCS.Model/ApiModel/UpLoad/UploadReelInfoRequest.cs new file mode 100644 index 0000000..64c9771 --- /dev/null +++ b/WCS.Model/ApiModel/UpLoad/UploadReelInfoRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.UpLoad +{ + public class UploadReelInfoRequest + { + public string MatSN { get; set; } + + public int Qty { get; set; } + + public string IPAddress { get; set; } + } +} diff --git a/WCS.WebApi/Controllers/DIYController.cs b/WCS.WebApi/Controllers/DIYController.cs deleted file mode 100644 index 7ad6997..0000000 --- a/WCS.WebApi/Controllers/DIYController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using WCS.BLL.Services.IService; -using WCS.BLL.Services.Service; -using WCS.Model; -using WCS.Model.ApiModel; -using WCS.Model.ApiModel.Stocktaking; -using WCS.Model.ApiModel.User; -using WCS.Model.WebSocketModel; - -namespace WCS.WebApi.Controllers -{ - /// - /// 本地化Controller - /// - [ApiController] - [Route("[controller]")] - public class DIYController : ControllerBase - { - public DIYController() - { - - } - - [Route("getStockTakingOrders")] - [HttpPost(Name = "getStockTakingOrders")] - public async Task getStockTakingOrders(GetStockTakingOrdersRequest request) - { - return await _stockTakingService.getStockTakingOrders(request); - } - } -} diff --git a/WCS.WebApi/Controllers/MXL4Controller.cs b/WCS.WebApi/Controllers/MXL4Controller.cs new file mode 100644 index 0000000..bf44b1f --- /dev/null +++ b/WCS.WebApi/Controllers/MXL4Controller.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Mvc; +using WCS.BLL.Services.IService; +using WCS.BLL.Services.Service; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.MXL4; +using WCS.Model.ApiModel.SelfCheck; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.Stocktaking; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; + +namespace WCS.WebApi.Controllers +{ + /// + /// 单灯单独控制亮灯接口 煤科院钻探分院项目 + /// + [ApiController] + [Route("[controller]")] + public class MXL4Controller : ControllerBase + { + + public IMXL4Service _mxl4Service { get; set; } + + public MXL4Controller(IMXL4Service mxl4Service) + { + _mxl4Service = mxl4Service; + } + + [Route("sysOrderMXL4")] + [HttpPost(Name = "sysOrderMXL4")] + public async Task sysOrderMXL4(SysOrderMXL4Request request) + { + try + { + return await _mxl4Service.sysOrderMXL4(request); + } + catch (Exception ex) + { + return new ResponseBase() + { + Code = 300, + Message = "操作失败:" + ex.Message, + }; + } + } + + } +} diff --git a/WCS.WebApi/Controllers/SingleLightController.cs b/WCS.WebApi/Controllers/SingleLightController.cs new file mode 100644 index 0000000..0c3c8a6 --- /dev/null +++ b/WCS.WebApi/Controllers/SingleLightController.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Mvc; +using WCS.BLL.Services.IService; +using WCS.BLL.Services.Service; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.SelfCheck; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.Stocktaking; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; + +namespace WCS.WebApi.Controllers +{ + /// + /// 单灯单独控制亮灯接口 煤科院钻探分院项目 + /// + [ApiController] + [Route("[controller]")] + public class SingleLightController : ControllerBase + { + + public ISingleLightService _singleLightService { get; set; } + + public SingleLightController(ISingleLightService singleLightService) + { + _singleLightService = singleLightService; + } + + [Route("singleLightControl")] + [HttpPost(Name = "singleLightControl")] + public async Task SingleLightControl(SingleLightControlRequest request) + { + try + { + return await _singleLightService.SingleLightControl(request); + } + catch (Exception ex) + { + return new ResponseBase() + { + Code = 300, + Message = "操作失败:" + ex.Message, + }; + } + } + + } +} diff --git a/WCS.WebApi/Controllers/UpLoadController.cs b/WCS.WebApi/Controllers/UpLoadController.cs new file mode 100644 index 0000000..d1ed4be --- /dev/null +++ b/WCS.WebApi/Controllers/UpLoadController.cs @@ -0,0 +1,68 @@ +using Microsoft.AspNetCore.Mvc; +using WCS.BLL.Services.IService; +using WCS.BLL.Services.Service; +using WCS.Model; +using WCS.Model.ApiModel; +using WCS.Model.ApiModel.SingleLight; +using WCS.Model.ApiModel.Stocktaking; +using WCS.Model.ApiModel.UpLoad; +using WCS.Model.ApiModel.User; +using WCS.Model.WebSocketModel; + +namespace WCS.WebApi.Controllers +{ + /// + /// 本地化Controller 离线点料机上传数据 + /// + [ApiController] + [Route("[controller]")] + public class UpLoadController : ControllerBase + { + public IUploadService _uploadService { get; set; } + public UpLoadController(IUploadService uploadService) + { + _uploadService = uploadService; + } + + + [Route("uploadReelInfo")] + [HttpPost(Name = "uploadReelInfo")] + public async Task uploadReelInfo(UploadReelInfoRequest request) + { + try + { + var IPAdress = HttpContext?.Connection?.RemoteIpAddress?.ToString(); + request.IPAddress = IPAdress; + + return await _uploadService.UploadReelInfo(request); + } + catch (Exception ex) + { + return new ResponseBase() + { + Code = 300, + Message = "操作失败:" + ex.Message, + }; + } + } + + [Route("getReelInfo")] + [HttpGet(Name = "getReelInfo")] + public async Task getReelInfo(string MatSN) + { + try + { + return await _uploadService.GetReelInfo(MatSN); + } + catch (Exception ex) + { + return new ResponseBase() + { + Code = 300, + Message = "操作失败:" + ex.Message, + }; + } + } + + } +} diff --git a/WCS.WebApi/Program.cs b/WCS.WebApi/Program.cs index df70181..580efb7 100644 --- a/WCS.WebApi/Program.cs +++ b/WCS.WebApi/Program.cs @@ -70,6 +70,11 @@ namespace WebApi builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); + + builder.Services.AddScoped(); + builder.Services.AddScoped(); + //롢ɵõģʽ builder.Services.AddSingleton(); diff --git a/货架标准上位机/ViewModels/InOutRecordViewModel.cs b/货架标准上位机/ViewModels/InOutRecordViewModel.cs index f04f396..e39ab3e 100644 --- a/货架标准上位机/ViewModels/InOutRecordViewModel.cs +++ b/货架标准上位机/ViewModels/InOutRecordViewModel.cs @@ -126,6 +126,7 @@ namespace 货架标准上位机.ViewModel FilterItems(value); } } + public ManualObservableCollection Items { get; set; } = new(); private List matCodes = new List(); private void FilterItems(string key) diff --git a/货架标准上位机/ViewModels/MatBaseInoScanGenarateMatInfoViewModel.cs b/货架标准上位机/ViewModels/MatBaseInoScanGenarateMatInfoViewModel.cs index 73ad2d7..29fc3e0 100644 --- a/货架标准上位机/ViewModels/MatBaseInoScanGenarateMatInfoViewModel.cs +++ b/货架标准上位机/ViewModels/MatBaseInoScanGenarateMatInfoViewModel.cs @@ -1,9 +1,12 @@ -using HandyControl.Controls; +using HandyControl.Collections; +using HandyControl.Controls; using HandyControl.Tools.Extension; using Ping9719.WpfEx.Mvvm; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Security.Cryptography; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Input; @@ -30,8 +33,68 @@ namespace 货架标准上位机.ViewModel get => matCode; set { SetProperty(ref matCode, value); + + App.Current.Dispatcher.Invoke(() => + { + FilterItems(value); + }); + + if (matCode.Length >= 8 + || matCodes.Where(t => t.MatCode == matCode).Any() ) + { + GetMatBaseInfoRequest(); + } } } + public ManualObservableCollection Items { get; set; } = new(); + private List matCodes = new List(); + private void FilterItems(string key) + { + //至少输入三个字符 避免删除或输入时界面变卡 + if (string.IsNullOrEmpty(key) || key.Length < 3) + { + Items.Clear(); + return; + } + key = key.ToUpper(); + Items.CanNotify = false; + Items.Clear(); + foreach (var matCode in matCodes) + { + if (matCode.MatCode.ToUpper().Contains(key)) + { + Items.Add(matCode); + } + } + Items.CanNotify = true; + } + public class DataModel + { + public string MatCode { get; set; } + } + + public void InitMatCode() + { + //调用接口更新! + Task.Run(() => + { + var body = new GetMatCodeListRequest() + { + IsFromBaseData = true, + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + }; + + var Result = ApiHelp.GetDataFromHttp>>(LocalFile.Config.ApiIpHost + "matBaseInfo/getMatCodeList", body, "POST"); + if (Result != null && Result.Data != null && Result.Data.Count() > 0) + { + matCodes = Result.Data.Select(t => new DataModel() + { + MatCode = t + }).ToList(); + } + }); + } private string matName; public string MatName @@ -164,6 +227,12 @@ namespace 货架标准上位机.ViewModel #region 调用接口获取物料 MatBaseInfo try { + if (MatQty == 0) + { + HandyControl.Controls.MessageBox.Show("数量不能为0!"); + return; + } + var body = new JinChuanCommitMatInfoRequest() { MatId = MatBaseInfo.Id, @@ -267,7 +336,7 @@ namespace 货架标准上位机.ViewModel // 提取第一个字段 CPN物料编码 //string firstField = Regex.Match(input, @"^[0-9,a-z,A-Z, ]{9}{").Value; string firstField = Regex.Match(input, LocalFile.Config.RegexMatCode).Value; - MatCode = firstField.Replace("{", "").Replace(" ", ""); + try { @@ -289,6 +358,12 @@ namespace 货架标准上位机.ViewModel MatBatch = thirdField.Replace("{", "").Replace(" ", ""); ; #endregion + MatCode = firstField.Replace("{", "").Replace(" ", ""); + //GetMatBaseInfoRequest(); + } + + public void GetMatBaseInfoRequest() + { //调用接口获取物料信息 #region 调用接口获取物料 MatBaseInfo try diff --git a/货架标准上位机/Views/MatBaseInfoView.xaml.cs b/货架标准上位机/Views/MatBaseInfoView.xaml.cs index fcdd7cd..5c67adf 100644 --- a/货架标准上位机/Views/MatBaseInfoView.xaml.cs +++ b/货架标准上位机/Views/MatBaseInfoView.xaml.cs @@ -39,8 +39,7 @@ namespace 货架标准上位机 { viewModel.SelectedataGridItem.IsSelected = !viewModel.SelectedataGridItem.IsSelected; dataGrid.UnselectAllCells();//取消选中 避免手动点击check选项时反选失败 和重新点击该项时反选失败 - } - + } } catch { diff --git a/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml b/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml index be2535b..629b96f 100644 --- a/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml +++ b/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml @@ -7,7 +7,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:hc="https://handyorg.github.io/handycontrol" mc:Ignorable="d" - Height="400" Width="340" WindowStyle="None" BorderThickness="0" Background="{x:Null}" AllowsTransparency="True" WindowStartupLocation="CenterScreen" Opacity="1"> + Loaded="UserControlBase_Loaded" + Height="400" Width="340" WindowStyle="None" BorderThickness="0" Background="{x:Null}" AllowsTransparency="True" WindowStartupLocation="CenterScreen" Opacity="1"> @@ -35,7 +36,14 @@ - + + diff --git a/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml.cs b/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml.cs index 038c927..3f8827f 100644 --- a/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml.cs +++ b/货架标准上位机/Views/MatBaseInoScanGenarateMatInfoView.xaml.cs @@ -69,5 +69,10 @@ namespace 货架标准上位机 txtTotalCount.Focus(); } } + + private void UserControlBase_Loaded(object sender, RoutedEventArgs e) + { + viewModel.InitMatCode(); + } } } diff --git a/货架标准上位机/Views/MatInfoView.xaml.cs b/货架标准上位机/Views/MatInfoView.xaml.cs index 42a51d7..eceb839 100644 --- a/货架标准上位机/Views/MatInfoView.xaml.cs +++ b/货架标准上位机/Views/MatInfoView.xaml.cs @@ -39,7 +39,7 @@ namespace 货架标准上位机 if (viewModel.SelectedataGridItem != null) { viewModel.SelectedataGridItem.IsSelected = !viewModel.SelectedataGridItem.IsSelected; - //dataGrid.UnselectAllCells(); + dataGrid.UnselectAllCells(); } } diff --git a/货架标准上位机/Views/ModuleInfoView.xaml b/货架标准上位机/Views/ModuleInfoView.xaml index cd3f376..297a453 100644 --- a/货架标准上位机/Views/ModuleInfoView.xaml +++ b/货架标准上位机/Views/ModuleInfoView.xaml @@ -72,6 +72,7 @@ +