diff --git a/MDM/Controllers/Process/ProcessOperationWorkstationMappingController.cs b/MDM/Controllers/Process/ProcessOperationWorkstationMappingController.cs index 01ea4e6..c06f9d7 100644 --- a/MDM/Controllers/Process/ProcessOperationWorkstationMappingController.cs +++ b/MDM/Controllers/Process/ProcessOperationWorkstationMappingController.cs @@ -59,8 +59,8 @@ namespace MDM.Controllers.Process { var response = _ProcessOperationWorkstationMappingService.GetInfo(Id); - var info = response.Adapt(); - return SUCCESS(info); + // var info = response.Adapt(); + return SUCCESS(response); } /// @@ -112,6 +112,31 @@ namespace MDM.Controllers.Process } + //TODO 采集参数 实体化 (同步) + /// + /// + /// + /// + /// int 同步的数据条数 + [HttpGet("sync_CollectParameter")] + + public IActionResult SyncCollectParameter(int OperationWorkstationMappingId) + { + var response = _ProcessOperationWorkstationMappingService.SyncCollectParameter(OperationWorkstationMappingId); + + return ToResponse(response); + } + + + //TODO 添加plc点位 + [HttpGet("update_plc_point")] + public IActionResult UpdatePlcPoint(int ProcessOperationWorkstationFlowCollectParameterId, string plc_point) + { + var response = _ProcessOperationWorkstationMappingService.UpdatePlcPoint(ProcessOperationWorkstationFlowCollectParameterId, plc_point); + return ToResponse(response); + } + + } diff --git a/MDM/Models/Process/Dto/ProcessOperationWorkstationFlowCollectParameterDto.cs b/MDM/Models/Process/Dto/ProcessOperationWorkstationFlowCollectParameterDto.cs new file mode 100644 index 0000000..9985a6a --- /dev/null +++ b/MDM/Models/Process/Dto/ProcessOperationWorkstationFlowCollectParameterDto.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Process.Dto +{ + public class ProcessOperationWorkstationFlowCollectParameterDto + { + + + + /// + /// 工序路线code + /// + + public string FkRoutingCode { get; set; } + + /// + /// 工序code + /// + + public string FkOperationCode { get; set; } + + + /// + /// 生产线体/工作中心code + /// + + public string FkProductlinebodyCode { get; set; } + + /// + /// 工位ID + /// + + public string FkWorkstationCode { get; set; } + + + /// + /// 所属流程code + /// + [SugarColumn(ColumnName = "fk_flow_code")] + public string FkFlowCode { get; set; } + + + /// + /// 所属plc Ip + /// + [SugarColumn(ColumnName = "fk_plc_ip")] + public string FkPlcIp { get; set; } + + + + + /// + /// 参数名称,如:温度、压力、时间 + /// + + public string ParameterCode { get; set; } + + + + /// + ///plc 点位 + /// + + public string PlcPoint { get; set; } + + + + + /// + /// 显示名称(用于UI展示,可和name一样) + /// + + public string ParameterName { get; set; } + + /// + /// 参数描述,如:模具温度,用于热压工序 + /// + public string Description { get; set; } + + /// + /// 数据类型:FLOAT, INT, STRING, BOOL, AI(模拟量输入)等 + /// + + public string DataType { get; set; } + + /// + /// 单位,如:℃、MPa、秒、mm + /// + public string Unit { get; set; } + + /// + /// 标准/目标值(如目标温度 200.0 ℃) + /// + + public decimal StandardValue { get; set; } + + /// + /// 最小允许值(用于报警/校验) + /// + + public decimal MinValue { get; set; } + + /// + /// 最大允许值(用于报警/校验) + /// + + public decimal MaxValue { get; set; } + + /// + /// 是否为控制参数:1=是(如PID控制),0=否(仅采集) + /// + + public int IsControlled { get; set; } + + /// + /// 是否为监控参数(是否采集/显示):1=是,0=否 + /// + + public int IsMonitored { get; set; } + + /// + /// 控制类型(如PID、ON/OFF、手动设定等,可选) + /// + + public string ControlType { get; set; } + + /// + /// 默认值(如未采集时使用) + /// + + public decimal DefaultValue { get; set; } + + /// + /// 是否必填/必采:1=是,0=否 + /// + + public int IsRequired { get; set; } + + /// + /// 参数排序(用于UI展示顺序) + /// + public int? Sequence { get; set; } + + + } +} diff --git a/MDM/Models/Process/Dto/ProcessOperationWorkstationMappingDto.cs b/MDM/Models/Process/Dto/ProcessOperationWorkstationMappingDto.cs index 47f4653..4f535b8 100644 --- a/MDM/Models/Process/Dto/ProcessOperationWorkstationMappingDto.cs +++ b/MDM/Models/Process/Dto/ProcessOperationWorkstationMappingDto.cs @@ -1,3 +1,5 @@ +using DOAN.Model.MES.recipe.Dto; +using MDM.Models.Process; using System.ComponentModel.DataAnnotations; namespace MDM.Model.Process.Dto @@ -57,5 +59,35 @@ namespace MDM.Model.Process.Dto + } + + /// + /// 工序工位详情 + /// + + public class ProcessOperationWorkstationMappingInfoDto : ProcessOperationWorkstationMappingDto + { + /// + /// 关联的流程 + /// + public List OperationFlows { set; get; } + /// + /// 关联的配方及其配方参数 + /// + public List OperationRecipeParameters { set; get; } + + + /// + /// 关联的采集参数 + /// + public List ProcessOperationWorkstationCollectParameters { set; get; } + + + /// + /// 关联的物料参数 + /// + public List ProcessOperationFlowMaterialParamters { set; get; } + + } } \ No newline at end of file diff --git a/MDM/Models/Process/ProcessOperationWorkstationFlowCollectParameter.cs b/MDM/Models/Process/ProcessOperationWorkstationFlowCollectParameter.cs new file mode 100644 index 0000000..ee3310d --- /dev/null +++ b/MDM/Models/Process/ProcessOperationWorkstationFlowCollectParameter.cs @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Process +{ + /// + /// 工艺参数实体化工位表(如温度、压力、时间等,关联工艺路线与工序) + /// + /// + + [SugarTable("process_operation_workstation_flow_collect_parameter")] + public class ProcessOperationWorkstationFlowCollectParameter + { + + /// + /// Id + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 工序路线code + /// + [SugarColumn(ColumnName = "fk_routing_code")] + public string FkRoutingCode { get; set; } + + /// + /// 工序code + /// + [SugarColumn(ColumnName = "fk_operation_code")] + public string FkOperationCode { get; set; } + + + /// + /// 生产线体/工作中心code + /// + [SugarColumn(ColumnName = "fk_productlinebody_code")] + public string FkProductlinebodyCode { get; set; } + + /// + /// 工位ID + /// + [SugarColumn(ColumnName = "fk_workstation_code")] + public string FkWorkstationCode { get; set; } + + + /// + /// 所属流程code + /// + [SugarColumn(ColumnName = "fk_flow_code")] + public string FkFlowCode { get; set; } + + + /// + /// 所属plc Ip + /// + [SugarColumn(ColumnName = "fk_plc_ip")] + public string FkPlcIp { get; set; } + + + + + /// + /// 参数名称,如:温度、压力、时间 + /// + [SugarColumn(ColumnName = "parameter_code")] + public string ParameterCode { get; set; } + + + + /// + ///plc 点位 + /// + [SugarColumn(ColumnName = "plc_point")] + public string PlcPoint { get; set; } + + + + + /// + /// 显示名称(用于UI展示,可和name一样) + /// + [SugarColumn(ColumnName = "parameter_name")] + public string ParameterName { get; set; } + + /// + /// 参数描述,如:模具温度,用于热压工序 + /// + public string Description { get; set; } + + /// + /// 数据类型:FLOAT, INT, STRING, BOOL, AI(模拟量输入)等 + /// + [SugarColumn(ColumnName = "data_type")] + public string DataType { get; set; } + + /// + /// 单位,如:℃、MPa、秒、mm + /// + public string Unit { get; set; } + + /// + /// 标准/目标值(如目标温度 200.0 ℃) + /// + [SugarColumn(ColumnName = "standard_value")] + public decimal StandardValue { get; set; } + + /// + /// 最小允许值(用于报警/校验) + /// + [SugarColumn(ColumnName = "min_value")] + public decimal MinValue { get; set; } + + /// + /// 最大允许值(用于报警/校验) + /// + [SugarColumn(ColumnName = "max_value")] + public decimal MaxValue { get; set; } + + /// + /// 是否为控制参数:1=是(如PID控制),0=否(仅采集) + /// + [SugarColumn(ColumnName = "is_controlled")] + public int IsControlled { get; set; } + + /// + /// 是否为监控参数(是否采集/显示):1=是,0=否 + /// + [SugarColumn(ColumnName = "is_monitored")] + public int IsMonitored { get; set; } + + /// + /// 控制类型(如PID、ON/OFF、手动设定等,可选) + /// + [SugarColumn(ColumnName = "control_type")] + public string ControlType { get; set; } + + /// + /// 默认值(如未采集时使用) + /// + [SugarColumn(ColumnName = "default_value")] + public decimal DefaultValue { get; set; } + + /// + /// 是否必填/必采:1=是,0=否 + /// + [SugarColumn(ColumnName = "is_required")] + public int IsRequired { get; set; } + + /// + /// 参数排序(用于UI展示顺序) + /// + public int? Sequence { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + } +} diff --git a/MDM/Services/Process/IService/IProcessOperationWorkstationMappingService.cs b/MDM/Services/Process/IService/IProcessOperationWorkstationMappingService.cs index d5d8119..695619d 100644 --- a/MDM/Services/Process/IService/IProcessOperationWorkstationMappingService.cs +++ b/MDM/Services/Process/IService/IProcessOperationWorkstationMappingService.cs @@ -19,5 +19,10 @@ namespace MDM.Services.IProcessService int UpdateProcessOperationWorkstationMapping(ProcessOperationWorkstationMapping parm); + + int SyncCollectParameter(int OperationWorkstationMappingId); + + int UpdatePlcPoint(int ProcessOperationWorkstationFlowCollectParameterId, string plc_point); + } } diff --git a/MDM/Services/Process/ProcessOperationWorkstationMappingService.cs b/MDM/Services/Process/ProcessOperationWorkstationMappingService.cs index 77b533a..5daff3a 100644 --- a/MDM/Services/Process/ProcessOperationWorkstationMappingService.cs +++ b/MDM/Services/Process/ProcessOperationWorkstationMappingService.cs @@ -1,8 +1,11 @@ +using DOAN.Model.MES.recipe; +using DOAN.Model.MES.recipe.Dto; using Infrastructure.Attribute; using MDM.Model; using MDM.Model.Process; using MDM.Model.Process.Dto; +using MDM.Models.Process; using MDM.Repository; using MDM.Service; using MDM.Services.IProcessService; @@ -43,11 +46,57 @@ namespace MDM.Services.Process /// /// /// - public ProcessOperationWorkstationMapping GetInfo(int Id) + public ProcessOperationWorkstationMappingInfoDto GetInfo(int Id) { var response = Queryable() - .Where(x => x.Id == Id) - .First(); + .Where(x => x.Id == Id) + .Select(it => new ProcessOperationWorkstationMappingInfoDto() + { + Id = it.Id, + FkRoutingCode = it.FkRoutingCode, + FkProductlinebodyCode = it.FkProductlinebodyCode, + FkOperationCode = it.FkOperationCode, + FkWorkstationCode = it.FkWorkstationCode, + IsActive = it.IsActive, + Priority = it.Priority, + StandardTime = it.StandardTime, + SetupTime = it.SetupTime, + CreatedTime = it.CreatedTime, + CreatedBy = it.CreatedBy, + Remark = it.Remark, + UpdatedTime = it.UpdatedTime, + UpdatedBy = it.UpdatedBy, + + + //绑定的流程信息 + OperationFlows = SqlFunc.Subqueryable().Where(s => s.FkRoutingCode == it.FkRoutingCode && s.FkOperationCode == it.FkOperationCode).ToList(), + + ////绑定的配方参数信息 + OperationRecipeParameters = SqlFunc.Subqueryable() + .LeftJoin((refpr, ver) => refpr.RecipeCode == ver.RecipeCode) + .LeftJoin((refpr, ver, param) => ver.RecipeCode == param.RecipeCode && ver.Version == param.Version) + .Where((refpr, ver, param) => refpr.FkRoutingCode == it.FkRoutingCode && refpr.FkOperationCode == it.FkOperationCode) + .ToList((refpr, ver, param) => new PfRecipeParametersDto + { + Id = param.Id, + RecipeCode = param.RecipeCode, + Version = param.Version, + ParamName = param.ParamName, + Unit = param.Unit, + UpperLimit = param.UpperLimit, + LowerLimit = param.LowerLimit, + StandardValue = param.StandardValue, + Remark = param.Remark + }), + ////绑定的工序工位采集参数 + ProcessOperationWorkstationCollectParameters = SqlFunc.Subqueryable().Where(s => s.FkRoutingCode == it.FkRoutingCode && s.FkOperationCode == it.FkOperationCode&&s.FkProductlinebodyCode==it.FkProductlinebodyCode&&s.FkWorkstationCode==it.FkWorkstationCode).ToList(), + + // 绑定的物料参数 + ProcessOperationFlowMaterialParamters = SqlFunc.Subqueryable().Where(s => s.FkRoutingCode == it.FkRoutingCode && s.FkOperationCode == it.FkOperationCode).ToList(), + + + }) + .First(); return response; } @@ -87,5 +136,86 @@ namespace MDM.Services.Process return Update(model, true); } + /// + /// 采集参数 实体化 (同步) + /// + /// + /// + public int SyncCollectParameter(int OperationWorkstationMappingId) + { + int result = 0; + //获取工序工位映射信息 + ProcessOperationWorkstationMapping selectMapping = Context.Queryable().Where(it => it.Id == OperationWorkstationMappingId).First(); + if(selectMapping!=null&&!string.IsNullOrEmpty(selectMapping.FkRoutingCode) && !string.IsNullOrEmpty(selectMapping.FkOperationCode)) + { + // 获取工序的采集参数 + List ProcessOperationCollectParameterList = Context.Queryable() + .Where(it => it.FkRoutingCode == selectMapping.FkRoutingCode && it.FkOperationCode == selectMapping.FkOperationCode).ToList(); + + //同步 + if (ProcessOperationCollectParameterList != null && ProcessOperationCollectParameterList.Count > 0) + { + List insertData = new List(); + foreach (var parameter in ProcessOperationCollectParameterList) + { + //判断是否存在 + int count = Context.Queryable() + .Where(it => it.FkRoutingCode == parameter.FkRoutingCode + && it.FkOperationCode == parameter.FkOperationCode + && it.ParameterCode == parameter.ParameterCode) + .Count(); + if (count == 0) + { + //不存在则添加 + ProcessOperationWorkstationFlowCollectParameter newEntity = new ProcessOperationWorkstationFlowCollectParameter() + { + FkRoutingCode = parameter.FkRoutingCode, + FkOperationCode = parameter.FkOperationCode, + FkProductlinebodyCode = selectMapping.FkProductlinebodyCode, + FkWorkstationCode = selectMapping.FkWorkstationCode, + ParameterCode = parameter.ParameterCode, + ParameterName = parameter.ParameterName, + Description = parameter.Description, + DataType = parameter.DataType, + Unit = parameter.Unit, + StandardValue = parameter.StandardValue, + MinValue = parameter.MinValue, + MaxValue = parameter.MaxValue, + IsControlled = parameter.IsControlled, + IsMonitored = parameter.IsMonitored, + ControlType = parameter.ControlType, + DefaultValue = parameter.DefaultValue, + IsRequired = parameter.IsRequired, + Sequence = parameter.Sequence, + CreatedTime = DateTime.Now, + CreatedBy = "SystemSync" + }; + insertData.Add(newEntity); + + } + + + + + } + + if (insertData.Count > 0) + { + result = Context.Insertable(insertData).ExecuteCommand(); + } + } + } + return result; + } + + + public int UpdatePlcPoint( int ProcessOperationWorkstationFlowCollectParameterId, string plc_point) + { + return Context.Updateable() + .SetColumns(it => new ProcessOperationWorkstationFlowCollectParameter() { PlcPoint = plc_point }) + .Where(it => it.Id == ProcessOperationWorkstationFlowCollectParameterId) + .ExecuteCommand(); + } + } } \ No newline at end of file