diff --git a/Sln.Wcs.Business/IBusiness.cs b/Sln.Wcs.Business/BaseBusiness.cs similarity index 76% rename from Sln.Wcs.Business/IBusiness.cs rename to Sln.Wcs.Business/BaseBusiness.cs index 6574c46..309f6b8 100644 --- a/Sln.Wcs.Business/IBusiness.cs +++ b/Sln.Wcs.Business/BaseBusiness.cs @@ -27,10 +27,11 @@ using Sln.Wcs.Business.Domain.Dto.CreateTask; using Sln.Wcs.Business.Domain.Dto.FilterLocation; using Sln.Wcs.Business.Domain.Dto.SaveTask; using Sln.Wcs.Business.Domain.Dto.ValidateMaterial; +using Sln.Wcs.Business.Util; namespace Sln.Wcs.Business; -public interface IBusiness +public abstract class BaseBusiness:EntityWrapper { /// @@ -38,25 +39,26 @@ public interface IBusiness /// /// /// - ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto); + public abstract ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto); /// /// 创建任务 /// /// - CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto ); + public abstract CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto ); /// /// 筛选目标库位 /// /// /// - FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto); + public abstract FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto); /// /// 保存任务 /// /// /// - SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto); + public abstract SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto); + } \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Dto/CreateTask/CreateTaskDto.cs b/Sln.Wcs.Business/Domain/Dto/CreateTask/CreateTaskDto.cs index ebf678f..546f418 100644 --- a/Sln.Wcs.Business/Domain/Dto/CreateTask/CreateTaskDto.cs +++ b/Sln.Wcs.Business/Domain/Dto/CreateTask/CreateTaskDto.cs @@ -23,6 +23,8 @@ #endregion << 版 本 注 释 >> +using Sln.Wcs.Business.Domain.Enum; + namespace Sln.Wcs.Business.Domain.Dto.CreateTask; public class CreateTaskDto @@ -45,5 +47,25 @@ public class CreateTaskDto /// /// 数量 /// - public string amount {get;set;} + public int amount {get;set;} + + /// + /// 起点 + /// + public string startPoint { get; set; } + + /// + /// 终点 + /// + public string endPoint { get; set; } + + /// + /// 任务类型:1-入库;2-出库; + /// + public TaskTypeEnum taskType { get; set; } + + /// + /// 任务类别:1-包材;2-成品;3-托盘 + /// + public TaskCategoryEnum taskCategory { get; set; } } \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Dto/SaveTask/SaveTaskDto.cs b/Sln.Wcs.Business/Domain/Dto/SaveTask/SaveTaskDto.cs index 395587d..e78af4d 100644 --- a/Sln.Wcs.Business/Domain/Dto/SaveTask/SaveTaskDto.cs +++ b/Sln.Wcs.Business/Domain/Dto/SaveTask/SaveTaskDto.cs @@ -23,9 +23,25 @@ #endregion << 版 本 注 释 >> +using Sln.Wcs.Model.Domain; + namespace Sln.Wcs.Business.Domain.Dto.SaveTask; public class SaveTaskDto { + /// + /// 任务编号 + /// + public string taskCode { get; set; } + + /// + /// 任务队列 + /// + public LiveTaskQueue taskQueue { get; set; } + + /// + /// 任务明细 + /// + public List taskDetails { get; set; } } \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Enum/BusinessStatusEnum.cs b/Sln.Wcs.Business/Domain/Enum/BusinessStatusEnum.cs index e164e7f..eee398c 100644 --- a/Sln.Wcs.Business/Domain/Enum/BusinessStatusEnum.cs +++ b/Sln.Wcs.Business/Domain/Enum/BusinessStatusEnum.cs @@ -8,4 +8,5 @@ public enum BusinessStatusEnum 其他未知错误调用失败后可以重试 = 99, 该任务不存在上层系统不需重发需要人工介入处理=100, SDK调用异常=101, + 方法执行异常=102, } \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Enum/TaskCategoryEnum.cs b/Sln.Wcs.Business/Domain/Enum/TaskCategoryEnum.cs new file mode 100644 index 0000000..45f4e53 --- /dev/null +++ b/Sln.Wcs.Business/Domain/Enum/TaskCategoryEnum.cs @@ -0,0 +1,19 @@ +namespace Sln.Wcs.Business.Domain.Enum; + +public enum TaskCategoryEnum +{ + /// + /// 包材 + /// + Material = 1, + + /// + /// 成品 + /// + Product = 2, + + /// + /// 托盘 + /// + Pallet = 3, +} \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Enum/TaskTypeEnum.cs b/Sln.Wcs.Business/Domain/Enum/TaskTypeEnum.cs new file mode 100644 index 0000000..ae6832e --- /dev/null +++ b/Sln.Wcs.Business/Domain/Enum/TaskTypeEnum.cs @@ -0,0 +1,14 @@ +namespace Sln.Wcs.Business.Domain.Enum; + +public enum TaskTypeEnum +{ + /// + /// 入库 + /// + InStore = 1, + + /// + /// 出库 + /// + OutStore = 2, +} \ No newline at end of file diff --git a/Sln.Wcs.Business/Domain/Model/SaveTask/SaveTaskResultModel.cs b/Sln.Wcs.Business/Domain/Model/SaveTask/SaveTaskResultModel.cs index 202ff94..6dec17b 100644 --- a/Sln.Wcs.Business/Domain/Model/SaveTask/SaveTaskResultModel.cs +++ b/Sln.Wcs.Business/Domain/Model/SaveTask/SaveTaskResultModel.cs @@ -31,4 +31,5 @@ public class SaveTaskResultModel /// 结果 /// public bool isRes { get; set; } + } \ No newline at end of file diff --git a/Sln.Wcs.Business/InStore/MaterialInStore.cs b/Sln.Wcs.Business/InStore/MaterialInStore.cs index fe91f57..9dd15e9 100644 --- a/Sln.Wcs.Business/InStore/MaterialInStore.cs +++ b/Sln.Wcs.Business/InStore/MaterialInStore.cs @@ -23,32 +23,113 @@ #endregion << 版 本 注 释 >> +using System.Linq.Expressions; using Sln.Wcs.Business.Domain.Dto.CreateTask; using Sln.Wcs.Business.Domain.Dto.FilterLocation; using Sln.Wcs.Business.Domain.Dto.SaveTask; using Sln.Wcs.Business.Domain.Dto.ValidateMaterial; +using Sln.Wcs.Business.Domain.Enum; +using Sln.Wcs.Business.Domain.Model.CreateTask; +using Sln.Wcs.Business.Domain.Model.SaveTask; +using Sln.Wcs.Model.Domain; +using Sln.Wcs.Repository.service; namespace Sln.Wcs.Business.InStore; -public class MaterialInStore:IBusiness +/// +/// 包材入库 +/// +public class MaterialInStore:BaseBusiness { - public ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto) + private readonly IBasePathInfoService _basePathInfoService; + private readonly ILiveTaskQueueService _liveTaskQueueService; + + public MaterialInStore(IBasePathInfoService basePathInfoService, ILiveTaskQueueService liveTaskQueueService) + { + _basePathInfoService = basePathInfoService; + _liveTaskQueueService = liveTaskQueueService; + } + + public override ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto) { throw new NotImplementedException(); } - public CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto) + /// + /// 创建任务 + /// + /// + /// + /// + public override CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto) + { + CreateTaskResultDto resultDto = new CreateTaskResultDto(); + try + { + createTaskDto.taskType = TaskTypeEnum.InStore; + createTaskDto.taskCategory = TaskCategoryEnum.Material; + //获取包材入库路径 + Expression> exp = x=>x.startPoint == createTaskDto.startPoint && x.endPoint == createTaskDto.endPoint && x.pathType == (int)createTaskDto.taskType && x.pathCategory == (int)createTaskDto.taskCategory; + BasePathInfo pathInfo = _basePathInfoService.GetBasePathInfo(exp).FirstOrDefault() ?? throw new InvalidOperationException($"包材入库输送路径为 NULL"); + + #region 路径转为任务 + + string taskCode = "2026050700001"; //需根据现场实际定义生成规则 + + List taskDetails = pathInfo.pathDetails.Select( item => base.LiveTaskDetailWrapper(taskCode,createTaskDto,item)).ToList(); + + var taskQueue = base.LiveTaskQueueWrapper(taskCode, createTaskDto, pathInfo); + taskQueue.taskSteps = taskDetails.Count; + taskQueue.taskDetails = taskDetails; + #endregion + + resultDto.code = BusinessStatusEnum.成功; + resultDto.msg = $"包材入库任务创建成功:{taskCode};关联路径:{pathInfo.pathName}"; + resultDto.data = new CreateTaskResultModel() + { + taskCode = taskCode, + taskQueue = taskQueue, + taskDetails = taskDetails, + }; + } + catch (Exception e) + { + resultDto.code = BusinessStatusEnum.方法执行异常; + resultDto.msg = e.Message; + } + return resultDto; + } + + public override FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto) { throw new NotImplementedException(); } - public FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto) + /// + /// 保存任务 + /// + /// + /// + public override SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto) { - throw new NotImplementedException(); - } + SaveTaskResultDto resultDto = new SaveTaskResultDto(); + try + { + var inRes = _liveTaskQueueService.InsertTaskQueue(saveTaskDto.taskQueue); + + resultDto.code = BusinessStatusEnum.成功; + resultDto.msg = "执行完成"; + resultDto.data = new SaveTaskResultModel() + { + isRes = inRes + }; + } + catch (Exception e) + { + resultDto.code = BusinessStatusEnum.方法执行异常; + resultDto.msg = e.Message; + } - public SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto) - { - throw new NotImplementedException(); + return resultDto; } } \ No newline at end of file diff --git a/Sln.Wcs.Business/InStore/PalletInStore.cs b/Sln.Wcs.Business/InStore/PalletInStore.cs index a383e7e..9b05506 100644 --- a/Sln.Wcs.Business/InStore/PalletInStore.cs +++ b/Sln.Wcs.Business/InStore/PalletInStore.cs @@ -23,9 +23,32 @@ #endregion << 版 本 注 释 >> +using Sln.Wcs.Business.Domain.Dto.CreateTask; +using Sln.Wcs.Business.Domain.Dto.FilterLocation; +using Sln.Wcs.Business.Domain.Dto.SaveTask; +using Sln.Wcs.Business.Domain.Dto.ValidateMaterial; + namespace Sln.Wcs.Business.InStore; -public class PalletInStore +public class PalletInStore:BaseBusiness { - + public override ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto) + { + throw new NotImplementedException(); + } + + public override CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto) + { + throw new NotImplementedException(); + } + + public override FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto) + { + throw new NotImplementedException(); + } + + public override SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/Sln.Wcs.Business/Sln.Wcs.Business.csproj b/Sln.Wcs.Business/Sln.Wcs.Business.csproj index 478c447..0c02f8e 100644 --- a/Sln.Wcs.Business/Sln.Wcs.Business.csproj +++ b/Sln.Wcs.Business/Sln.Wcs.Business.csproj @@ -9,6 +9,8 @@ + + diff --git a/Sln.Wcs.Business/Util/EntityWrapper.cs b/Sln.Wcs.Business/Util/EntityWrapper.cs new file mode 100644 index 0000000..5cbe6e5 --- /dev/null +++ b/Sln.Wcs.Business/Util/EntityWrapper.cs @@ -0,0 +1,123 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2026 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Wcs.Business.Util +* 唯一标识:6942BA6E-D8FC-4847-BBF6-5977C3A999D6 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2026-05-07 18:07:25 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Reflection; +using Sln.Wcs.Business.Domain.Enum; +using Sln.Wcs.Model.Domain; + +namespace Sln.Wcs.Business.Util; + +public class EntityWrapper +{ + + /// + /// 反射辅助方法 + /// + /// + /// + /// + private (string materialCode, string palletBarcode, string materialBarcode, int materialCount,int taskType,int taskCategory) ExtractTaskFields(object source) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + var type = source.GetType(); + + object GetPropertyValue(string propName) + { + var prop = type.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance); + if (prop != null && prop.CanRead) return prop.GetValue(source); + var field = type.GetField(propName, BindingFlags.Public | BindingFlags.Instance); + return field?.GetValue(source); + } + + string GetString(string propName) => GetPropertyValue(propName)?.ToString() ?? string.Empty; + int GetInt(string propName) + { + var val = GetPropertyValue(propName); + return val != null ? Convert.ToInt32(val) : 0; + } + + return ( + materialCode: GetString("materialCode"), + palletBarcode: GetString("palletBarcode"), + materialBarcode: GetString("materialBarcode"), + materialCount: GetInt("amount"), + taskType: GetInt("taskType"), + taskCategory: GetInt("taskCategory") + ); + } + + /// + /// 任务明细包装 + /// + /// + /// + /// + /// + public LiveTaskDetail LiveTaskDetailWrapper(string taskCode,object source, BasePathDetails pathDetails) + { + var fields = ExtractTaskFields(source); + + return new LiveTaskDetail + { + taskCode = taskCode, + materialCode = fields.materialCode, + palletBarcode = fields.palletBarcode, + materialBarcode = fields.materialBarcode, + materialCount = fields.materialCount, + startPoint = pathDetails.startPoint, + endPoint = pathDetails.endPoint, + deviceType = pathDetails.deviceType, + pathCode = $"{pathDetails.pathCode}_{pathDetails.objId}", + taskType = fields.taskType, + taskCategory = fields.taskCategory + }; + } + + /// + /// 任务队列包装 + /// + /// + /// + /// + /// + public LiveTaskQueue LiveTaskQueueWrapper(string taskCode, object source, BasePathInfo pathInfo) + { + var fields = ExtractTaskFields(source); + + return new LiveTaskQueue() + { + taskCode = taskCode, + materialCode = fields.materialCode, + palletBarcode = fields.palletBarcode, + materialBarcode = fields.materialBarcode, + materialCount = fields.materialCount, + startPoint = pathInfo.startPoint, + endPoint = pathInfo.endPoint, + pathCode = pathInfo.pathCode, + taskType = fields.taskType, + taskCategory = fields.taskCategory + }; + } +} \ No newline at end of file diff --git a/Sln.Wcs.Common/ExpressionExtensions.cs b/Sln.Wcs.Common/ExpressionExtensions.cs new file mode 100644 index 0000000..2da0741 --- /dev/null +++ b/Sln.Wcs.Common/ExpressionExtensions.cs @@ -0,0 +1,168 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2026 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Wcs.Common +* 唯一标识:0D6CF267-193F-4A82-897F-C7920B81FB27 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2026-05-07 15:27:58 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Linq.Expressions; + +namespace Sln.Wcs.Common; + +public static class ExpressionExtensions +{ + /// + /// 创建一个值恒为 true 的表达式。 + /// + /// 表达式方法类型 + /// 一个值恒为 true 的表达式。 + public static Expression> True() { return p => true; } + + /// + /// 创建一个值恒为 false 的表达式。 + /// + /// 表达式方法类型 + /// 一个值恒为 false 的表达式。 + public static Expression> False() { return f => false; } + + /// + /// 使用 Expression.OrElse 的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// 拼接完成的 System.Linq.Expression。 + public static Expression Or(this Expression left, Expression right) + { + return MakeBinary(left, right, Expression.OrElse); + } + + /// + /// 使用 Expression.AndAlso 的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// 拼接完成的 System.Linq.Expression。 + public static Expression And(this Expression left, Expression right) + { + return MakeBinary(left, right, Expression.AndAlso); + } + + /// + /// 使用自定义的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// + /// 拼接完成的 System.Linq.Expression。 + private static Expression MakeBinary(this Expression left, Expression right, Func func) + { + return MakeBinary((LambdaExpression)left, right, func) as Expression; + } + + /// + /// 拼接两个 + /// System.Linq.Expression + /// ,两个 + /// System.Linq.Expression + /// 的参数必须完全相同。 + /// + /// 左边的 + /// System.Linq.Expression + /// + /// 右边的 + /// System.Linq.Expression + /// + /// 表达式拼接的具体逻辑 + /// 拼接完成的 + /// System.Linq.Expression + /// + private static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func func) + { + var data = Combinate(right.Parameters, left.Parameters).ToArray(); + + right = ParameterReplace.Replace(right, data) as LambdaExpression; + + return Expression.Lambda(func(left.Body, right.Body), left.Parameters.ToArray()); + } + + /// + /// 合并参数 + /// + /// + /// + /// + /// + private static IEnumerable> Combinate(IEnumerable left, IEnumerable right) + { + var a = left.GetEnumerator(); + var b = right.GetEnumerator(); + while (a.MoveNext() && b.MoveNext()) + yield return new KeyValuePair(a.Current, b.Current); + } +} + +internal sealed class ParameterReplace : ExpressionVisitor +{ + public static Expression Replace(Expression e, IEnumerable> paramList) + { + var item = new ParameterReplace(paramList); + return item.Visit(e); + } + + private readonly Dictionary _parameters; + + public ParameterReplace(IEnumerable> paramList) + { + _parameters = paramList.ToDictionary(p => p.Key, p => p.Value, new ParameterEquality()); + } + + protected override Expression VisitParameter(ParameterExpression p) + { + ParameterExpression result; + if (_parameters.TryGetValue(p, out result)) + return result; + return base.VisitParameter(p); + } + + #region class: ParameterEquality + private class ParameterEquality : IEqualityComparer + { + public bool Equals(ParameterExpression x, ParameterExpression y) + { + if (x == null || y == null) + return false; + + return x.Type == y.Type; + } + + public int GetHashCode(ParameterExpression obj) + { + if (obj == null) + return 0; + + return obj.Type.GetHashCode(); + } + } + #endregion +} \ No newline at end of file diff --git a/Sln.Wcs.Model/Domain/BasePathDetails.cs b/Sln.Wcs.Model/Domain/BasePathDetails.cs index 791843f..04d04da 100644 --- a/Sln.Wcs.Model/Domain/BasePathDetails.cs +++ b/Sln.Wcs.Model/Domain/BasePathDetails.cs @@ -50,6 +50,14 @@ namespace Sln.Wcs.Model.Domain /// [SugarColumn(ColumnName = "path_code")] public string pathCode { get; set; } + + /// + /// Desc:路径名称 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "path_name")] + public string pathName { get; set; } /// /// Desc:起点 @@ -66,6 +74,14 @@ namespace Sln.Wcs.Model.Domain /// [SugarColumn(ColumnName = "end_point")] public string endPoint { get; set; } + + /// + /// Desc:设备类型:0-输送线;1-AGV;2-提升机 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "device_type")] + public int? deviceType { get; set; } /// /// Desc:是否标识:1-是;0-否 diff --git a/Sln.Wcs.Model/Domain/BasePathInfo.cs b/Sln.Wcs.Model/Domain/BasePathInfo.cs index 19271af..612c64a 100644 --- a/Sln.Wcs.Model/Domain/BasePathInfo.cs +++ b/Sln.Wcs.Model/Domain/BasePathInfo.cs @@ -58,6 +58,38 @@ namespace Sln.Wcs.Model.Domain /// [SugarColumn(ColumnName = "path_name")] public string pathName { get; set; } + + /// + /// Desc:路径类型:1-入库;2-出库; + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "path_type")] + public int? pathType { get; set; } + + /// + /// Desc:路径类别:1-包材;2-成品;3-托盘 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "path_category")] + public int? pathCategory { get; set; } + + /// + /// Desc:起点 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_point")] + public string startPoint { get; set; } + + /// + /// Desc:终点 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "end_point")] + public string endPoint { get; set; } /// /// Desc:是否标识:1-是;0-否 @@ -111,6 +143,7 @@ namespace Sln.Wcs.Model.Domain /// 明细集合 /// [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToMany, nameof(BasePathDetails.pathCode), nameof(pathCode))] public List pathDetails { get; set; } } } diff --git a/Sln.Wcs.Model/Domain/LiveTaskDetail.cs b/Sln.Wcs.Model/Domain/LiveTaskDetail.cs index 12bf4ae..a91d7b3 100644 --- a/Sln.Wcs.Model/Domain/LiveTaskDetail.cs +++ b/Sln.Wcs.Model/Domain/LiveTaskDetail.cs @@ -48,6 +48,14 @@ public class LiveTaskDetail /// [SugarColumn(ColumnName = "task_code")] public string taskCode { get; set; } + + /// + /// Desc:路径编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "path_code")] + public string pathCode { get; set; } /// /// Desc:物料编号 @@ -113,6 +121,14 @@ public class LiveTaskDetail [SugarColumn(ColumnName = "end_point")] public string endPoint { get; set; } + /// + /// Desc:设备类型:0-输送线;1-AGV;2-提升机 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "device_type")] + public int? deviceType { get; set; } + /// /// Desc:是否校验物料:1-是;0-否 /// Default: diff --git a/Sln.Wcs.Model/Domain/LiveTaskQueue.cs b/Sln.Wcs.Model/Domain/LiveTaskQueue.cs index c0ff1fc..5d5991c 100644 --- a/Sln.Wcs.Model/Domain/LiveTaskQueue.cs +++ b/Sln.Wcs.Model/Domain/LiveTaskQueue.cs @@ -112,6 +112,14 @@ public class LiveTaskQueue /// [SugarColumn(ColumnName = "end_point")] public string endPoint { get; set; } + + /// + /// Desc:路径编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "path_code")] + public string pathCode { get; set; } /// /// Desc:任务状态:1-待执行;2-执行中;3-已完成; diff --git a/Sln.Wcs.Repository/service/IBasePathInfoService.cs b/Sln.Wcs.Repository/service/IBasePathInfoService.cs index 5f90316..c7919a7 100644 --- a/Sln.Wcs.Repository/service/IBasePathInfoService.cs +++ b/Sln.Wcs.Repository/service/IBasePathInfoService.cs @@ -3,6 +3,7 @@ using Sln.Wcs.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; @@ -10,5 +11,11 @@ namespace Sln.Wcs.Repository.service { public interface IBasePathInfoService:IBaseService { + /// + /// 获取路径信息 + /// + /// + /// + List GetBasePathInfo(Expression> exp); } } diff --git a/Sln.Wcs.Repository/service/ILiveTaskQueueService.cs b/Sln.Wcs.Repository/service/ILiveTaskQueueService.cs index d205b0f..4eb70cb 100644 --- a/Sln.Wcs.Repository/service/ILiveTaskQueueService.cs +++ b/Sln.Wcs.Repository/service/ILiveTaskQueueService.cs @@ -30,5 +30,5 @@ namespace Sln.Wcs.Repository.service; public interface ILiveTaskQueueService:IBaseService { - + bool InsertTaskQueue(LiveTaskQueue taskQueue); } \ No newline at end of file diff --git a/Sln.Wcs.Repository/service/Impl/BasePathInfoServiceImpl.cs b/Sln.Wcs.Repository/service/Impl/BasePathInfoServiceImpl.cs index 8430dbd..7b69a63 100644 --- a/Sln.Wcs.Repository/service/Impl/BasePathInfoServiceImpl.cs +++ b/Sln.Wcs.Repository/service/Impl/BasePathInfoServiceImpl.cs @@ -3,8 +3,10 @@ using Sln.Wcs.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; +using SqlSugar; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -32,8 +34,24 @@ namespace Sln.Wcs.Repository.service.Impl { public class BasePathInfoServiceImpl : BaseServiceImpl, IBasePathInfoService { + public BasePathInfoServiceImpl(Repository rep) : base(rep) { } + + public List GetBasePathInfo(Expression> exp) + { + try + { + return _rep.Context.Queryable() + .Includes(x => x.pathDetails.Where(p => p.isFlag == 1).ToList()) + .Where(exp) + .ToList(); + } + catch (Exception ex) + { + throw new InvalidOperationException($"通过导航查询方式获取设备信息及下属参数执行异常:{ex.Message}"); + } + } } } diff --git a/Sln.Wcs.Repository/service/Impl/LiveTaskQueueServiceImpl.cs b/Sln.Wcs.Repository/service/Impl/LiveTaskQueueServiceImpl.cs index 4f81c36..89718db 100644 --- a/Sln.Wcs.Repository/service/Impl/LiveTaskQueueServiceImpl.cs +++ b/Sln.Wcs.Repository/service/Impl/LiveTaskQueueServiceImpl.cs @@ -30,7 +30,30 @@ namespace Sln.Wcs.Repository.service.Impl; public class LiveTaskQueueServiceImpl: BaseServiceImpl, ILiveTaskQueueService { - public LiveTaskQueueServiceImpl(Repository rep) : base(rep) + private ILiveTaskDetailService liveTaskDetailService; + public LiveTaskQueueServiceImpl(Repository rep, ILiveTaskDetailService liveTaskDetailService) : base(rep) { + this.liveTaskDetailService = liveTaskDetailService; + } + + public bool InsertTaskQueue(LiveTaskQueue taskQueue) + { + bool res = false; + try + { + _rep.AsTenant().BeginTran(); + + res = _rep.Insert(taskQueue); + + res = liveTaskDetailService.Insert(taskQueue.taskDetails); + + _rep.AsTenant().CommitTran(); + } + catch (Exception e) + { + _rep.AsTenant().RollbackTran(); + throw new InvalidOperationException($"保存任务队列异常:{e.Message}"); + } + return res; } } \ No newline at end of file diff --git a/Sln.Wcs.Repository/service/base/BaseServiceImpl.cs b/Sln.Wcs.Repository/service/base/BaseServiceImpl.cs index 08d2487..5637e7c 100644 --- a/Sln.Wcs.Repository/service/base/BaseServiceImpl.cs +++ b/Sln.Wcs.Repository/service/base/BaseServiceImpl.cs @@ -79,14 +79,14 @@ namespace Sln.Wcs.Repository.service.@base try { - // _rep.AsTenant().BeginTran(); - var info = _rep.CopyNew().InsertRange(lisT); - // _rep.AsTenant().CommitTran(); + //_rep.AsTenant().BeginTran(); + var info = _rep.InsertRange(lisT); + //_rep.AsTenant().CommitTran(); return true; } catch (Exception ex) { - // _rep.AsTenant().RollbackTran(); + //_rep.AsTenant().RollbackTran(); throw new InvalidOperationException($"批量添加实体集合异常:{ex.Message}"); } } diff --git a/Sln.Wcs/Program.cs b/Sln.Wcs/Program.cs index f18e1d3..3fa7c52 100644 --- a/Sln.Wcs/Program.cs +++ b/Sln.Wcs/Program.cs @@ -4,11 +4,16 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NeoSmart.Caching.Sqlite; using Newtonsoft.Json; +using Sln.Wcs.Business; +using Sln.Wcs.Business.Domain.Dto.CreateTask; +using Sln.Wcs.Business.Domain.Dto.SaveTask; +using Sln.Wcs.Business.InStore; using Sln.Wcs.HikRoBotSdk; using Sln.Wcs.HoistApi.Domain.Dto.HoistControl; using Sln.Wcs.HoistApi.Domain.Enum; using Sln.Wcs.HoistApi.Service; using Sln.Wcs.Model.Configs; +using Sln.Wcs.Model.Domain; using Sln.Wcs.Repository; using Sln.Wcs.Repository.service; using Sln.Wcs.Serilog; @@ -35,6 +40,26 @@ namespace Sln.Wcs var log = serviceProvider.GetService(); log.Info($"系统启动成功,日志存放位置:{config["logPath"]}"); + + var bus = serviceProvider.GetService(); + + var info = bus.CreateTask(new CreateTaskDto() + { + materialCode = "Material2", + materialBarcode = "Material2", + palletBarcode = "Material2", + amount = 1, + startPoint = "13#_L1_01", + endPoint = "15#_L3_03", + }); + + var res = bus.SaveTask(new SaveTaskDto() + { + taskCode = info.data.taskCode, + taskQueue = info.data.taskQueue, + taskDetails = info.data.taskDetails, + }); + } private static void ConfigureServices(IServiceCollection services) @@ -52,6 +77,7 @@ namespace Sln.Wcs Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HoistApi.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HoistSdk.dll")), Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Plc.dll")), + Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Business.dll")), }; services.Scan(scan => scan.FromAssemblies(assemblies) diff --git a/Sln.Wcs/Sln.Wcs.csproj b/Sln.Wcs/Sln.Wcs.csproj index da9664b..f049ba9 100644 --- a/Sln.Wcs/Sln.Wcs.csproj +++ b/Sln.Wcs/Sln.Wcs.csproj @@ -26,6 +26,7 @@ +