| | |
| | | using CmsQueryExtensions.Entitys; |
| | | using CMS.Unit.RuntimeValue.Abstractions; |
| | | using CMS.Extensions.Variable; |
| | | using CMS.Plugin.TraceManagement.Abstractions.Models.Traces; |
| | | using CMS.Plugin.ProcessManagement.Abstractions; |
| | | using KissUtil.Extensions; |
| | | using CMS.Plugin.TraceManagement.Abstractions; |
| | | using CMS.Plugin.ProductManagement.Abstractions.Models; |
| | | using CMS.Plugin.MaterialManagement.Abstractions; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Services; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.CommonDto; |
| | | using System.Collections.Generic; |
| | | using CMS.Plugin.HIAWms.Abstractions; |
| | | using Newtonsoft.Json; |
| | | using CmsQueryExtensions; |
| | | |
| | | namespace CMS.Plugin.PipeLineLems.Application.Implements; |
| | | |
| | |
| | | public class SharedService : CMSPluginAppService |
| | | { |
| | | |
| | | |
| | | /// <summary> |
| | | /// 分拣功能 |
| | | /// </summary> |
| | | /// <param name="_serviceProvider"></param> |
| | | /// <param name="input"></param> |
| | | /// <param name="myCurrentUser"></param> |
| | | /// <returns></returns> |
| | | public async Task<MesOrderResponse> CommonPick(IServiceProvider _serviceProvider, PickInput input, MyCurrentUser myCurrentUser) |
| | | { |
| | | //1、记录分拣记录表 |
| | | //2、更新作业计划表的状态 =已分拣 |
| | | //3、写入 分拣变量 |
| | | //4、写入追溯报表 |
| | | //5、物料组盘 |
| | | |
| | | VariableService _variableService = _serviceProvider.GetRequiredService<VariableService>(); |
| | | var _workSectionManager = _serviceProvider.GetRequiredService<IWorkSectionManager>(); |
| | | var _workStationManager = _serviceProvider.GetRequiredService<IWorkStationManager>(); |
| | | var traceProvider = _serviceProvider.GetRequiredService<ITraceProvider>(); |
| | | var materialProvider = _serviceProvider.GetRequiredService<IMaterialProvider>(); |
| | | var workPlanAppService = _serviceProvider.GetRequiredService<IWorkPlanAppService>(); |
| | | |
| | | Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?> |
| | | { |
| | | { "分拣托盘号","托盘1"}, |
| | | { "分拣方向", "短管装配"}, |
| | | { "分拣人", myCurrentUser.UserAccount } |
| | | }; |
| | | _variableService.WriteValueAsync(keyValuePairs); |
| | | //Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?> |
| | | // { |
| | | // { "分拣托盘号","托盘1"}, |
| | | // { "分拣方向", "短管装配"}, |
| | | // { "分拣人", myCurrentUser.UserAccount } |
| | | // }; |
| | | //_variableService.WriteValueAsync(keyValuePairs); |
| | | |
| | | //根据工序名获取工序对象 |
| | | var workSection = await _workSectionManager.GetByNameAsync("分拣工序"); |
| | | var workStation = await _workStationManager.GetByNameAsync("分拣工位"); |
| | | //写入追溯报表 |
| | | var finishTime = DateTime.Now; |
| | | TraceModel traceModel = new TraceModel() |
| | | { |
| | | SerialNumber = input.PipeSpecCode, |
| | | WorkSectionId = workSection.Id, |
| | | WorkSectionName = workSection.Name, |
| | | WorkStationName = workStation.Name, |
| | | |
| | | FinishTime = finishTime, |
| | | IsQualified = true, |
| | | UnqualifiedReason = "", |
| | | ProductModel = "", |
| | | ProductName = "", |
| | | |
| | | }; |
| | | traceModel.Params = new List<TraceParamModel>(); |
| | | foreach (var item in workSection.ProcessParameters) |
| | | { |
| | | var value = "ssss"; |
| | | traceModel.Params.Add(new TraceParamModel() |
| | | { |
| | | Key = item.Key, |
| | | Value = value.SafeString() |
| | | }); |
| | | } |
| | | //物料参数列表 |
| | | var firstWorkPlans = await workPlanAppService.GetListByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode); |
| | | |
| | | var firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode); |
| | | var rawPipe_DataIdentifier = await materialProvider.FindByNameAsync("原料管标识"); |
| | | var rawPipe_MaterialMode = await materialProvider.FindByNameAsync("原料管型号"); |
| | | var rawPipe_Batch = await materialProvider.FindByNameAsync("原料管批次"); |
| | | List<TraceMaterialModel> _MaterialParams = new List<TraceMaterialModel>(); |
| | | foreach (var item in workSection.MaterialParameters) |
| | | { |
| | | if (item.Name == "原料管型号") |
| | | { |
| | | _MaterialParams.Add(new TraceMaterialModel() |
| | | { |
| | | Key = item.Key, |
| | | Quantity = 1, |
| | | MaterialId = rawPipe_MaterialMode.MaterialId, |
| | | MaterialDetailId = rawPipe_MaterialMode.MaterialDetails.First().Id, |
| | | Value = firstWorkPlan.MaterialMode |
| | | |
| | | }); |
| | | } |
| | | if (item.Name == "原料管标识") |
| | | { |
| | | _MaterialParams.Add(new TraceMaterialModel() |
| | | { |
| | | Key = item.Key, |
| | | Quantity = 1, |
| | | MaterialId = rawPipe_DataIdentifier.MaterialId, |
| | | MaterialDetailId = rawPipe_DataIdentifier.MaterialDetails.First().Id, |
| | | Value = firstWorkPlan.DataIdentifier, |
| | | |
| | | }); |
| | | } |
| | | if (item.Name == "原料管批次") |
| | | { |
| | | _MaterialParams.Add(new TraceMaterialModel() |
| | | { |
| | | Key = item.Key, |
| | | Quantity = 1, |
| | | MaterialId = rawPipe_Batch.MaterialId, |
| | | MaterialDetailId = rawPipe_Batch.MaterialDetails.First().Id, |
| | | Value = "111",//批次暂时写死 |
| | | |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | //配置过程参数(采集参数、配方参数) |
| | | traceModel.Params = new List<TraceParamModel>(); |
| | | foreach (var item in workSection.ProcessParameters) |
| | | { |
| | | string _value = ""; |
| | | if (item.Name == "分拣方向") |
| | | { |
| | | _value = "短管装配"; |
| | | } |
| | | if (item.Name == "分拣托盘号") |
| | | { |
| | | _value = input.ContinerNo; |
| | | } |
| | | if (item.Name == "分拣人") |
| | | { |
| | | _value = myCurrentUser.UserAccount; |
| | | } |
| | | //item.Key |
| | | TraceParamModel traceParamModel = new TraceParamModel() |
| | | { |
| | | Key = item.Key, |
| | | Value = _value |
| | | }; |
| | | traceModel.Params.Add(traceParamModel); |
| | | }; |
| | | |
| | | traceModel.MaterialParams = _MaterialParams; |
| | | |
| | | await traceProvider.CreateTraceAsync(traceModel); |
| | | |
| | | var response = new MesOrderResponse |
| | | { |
| | | Code = "000000", |
| | | Code = "200", |
| | | Data = "", |
| | | Fail = false, |
| | | Mesg = "处理成功", |
| | | Success = true, |
| | | Message = "处理成功", |
| | | Time = DateTime.UtcNow |
| | | }; |
| | | return response; |
| | |
| | | if (input.Count == 0) |
| | | { |
| | | throw new UserFriendlyException("输入参数Data不能为空"); |
| | | } |
| | | |
| | | //写死 打码内容 |
| | | foreach (var item in input) |
| | | { |
| | | //格式 管段编码,管段名称,船号,项目号 |
| | | item.MarkingContent = item.PipeSpecCode + "," + item.PipeSectionName + "," + item.ShipNumber + "," + item.ProjectNumber; |
| | | } |
| | | |
| | | //校验数据 |
| | |
| | | { |
| | | Code = "000000", |
| | | Data = orderModels, |
| | | Fail = false, |
| | | Mesg = "处理成功", |
| | | Success = true, |
| | | Message = "处理成功", |
| | | Time = DateTime.UtcNow |
| | | }; |
| | | return response; |
| | |
| | | /// <param name="_serviceProvider">服务提供者</param> |
| | | /// <returns>操作结果</returns> |
| | | /// <exception cref="UserFriendlyException">当数据不存在或状态不允许叫料时抛出</exception> |
| | | public async Task<MesOrderResponse> CallMaterialByDataIdentifier(Guid id, IServiceProvider _serviceProvider) |
| | | public async Task<MesOrderResponse> CallMaterial(CallMaterialByDataIdentifierInput input, IServiceProvider _serviceProvider, MyCurrentUser myCurrentUser) |
| | | { |
| | | if (string.IsNullOrEmpty(id.ToString())) |
| | | if (string.IsNullOrEmpty(input.Id.ToString())) |
| | | { |
| | | throw new UserFriendlyException("原料标识不能为空"); |
| | | } |
| | |
| | | |
| | | // 查找数据 |
| | | |
| | | var callMaterialOrder = await callMaterialOrderRepository.GetAsync(id); |
| | | var callMaterialOrder = await callMaterialOrderRepository.GetAsync(input.Id); |
| | | if (callMaterialOrder == null) |
| | | { |
| | | throw new UserFriendlyException($"找不到叫料记录"); |
| | |
| | | // 验证状态 |
| | | if (callMaterialOrder.CallMaterialStatus != Domain.Shared.Enums.CallMaterialStatusEnum.未执行) |
| | | { |
| | | throw new UserFriendlyException($"原料标识为 '{callMaterialOrder.DataIdentifier}' 的叫料记录状态为 '{callMaterialOrder.CallMaterialStatus}',不允许叫料"); |
| | | //throw new UserFriendlyException($"原料标识为 '{callMaterialOrder.DataIdentifier}' 的叫料记录状态为 '{callMaterialOrder.CallMaterialStatus}',不允许叫料"); |
| | | } |
| | | |
| | | //TODO:这里调用wms的叫料接口 |
| | | try |
| | | { |
| | | List<LMesCallMaterialInput> param = new List<LMesCallMaterialInput>() { |
| | | new LMesCallMaterialInput(){ |
| | | DataIdentifier=callMaterialOrder.DataIdentifier, |
| | | MaterialMode=callMaterialOrder.MaterialMode, |
| | | } |
| | | }; |
| | | string baseUrl = @"http://127.0.0.1:18000/api/v1/HIAWms/"; |
| | | string url = baseUrl + "lMesOperate/LMesCallMaterial"; |
| | | string json = JsonConvert.SerializeObject(param); |
| | | var result = HttpApiRequest.HttpPost(url, json); |
| | | var res = JsonConvert.DeserializeObject<CmsApiResponse<List<MyCallMaterialOutput>>>(result); |
| | | if (res.Code == 200) |
| | | { |
| | | var retData = res.Data; |
| | | callMaterialOrder.MaterialBatch = retData[0].MaterialBatch; |
| | | callMaterialOrder.WmsTaskNo = retData[0].TaskNo; |
| | | callMaterialOrder.WmsRetResult = res.Message; |
| | | } |
| | | else |
| | | { |
| | | throw new UserFriendlyException(res.Message); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | // 更新数据 |
| | | callMaterialOrder.WmsRetResult = "成功"; |
| | | callMaterialOrder.WmsTaskNo = GenerateRandomTaskNo(); |
| | | //callMaterialOrder.MaterialBatch = GenerateRandomBatch();//wms返回的原料批次 |
| | | //callMaterialOrder.WmsRetResult = "成功"; |
| | | //callMaterialOrder.WmsTaskNo = GenerateRandomTaskNo(); |
| | | callMaterialOrder.CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.叫料完成; |
| | | callMaterialOrder.LastModifierName = "SuperAdmin"; |
| | | |
| | | await callMaterialOrderRepository.UpdateAsync(callMaterialOrder); |
| | | |
| | | //更新作业计划表 |
| | | var workPlanList = await workPlanRepository.FindByDataIdentifierAsync(callMaterialOrder.DataIdentifier); |
| | | var workPlanList = await workPlanRepository.GetListByFilterAsync(x => x.DataIdentifier == callMaterialOrder.DataIdentifier); |
| | | foreach (var item in workPlanList) |
| | | { |
| | | item.CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.叫料完成; |
| | |
| | | var callMaterialOrderRecord = new CallMaterialOrderRecord() |
| | | { |
| | | CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.叫料完成, |
| | | MaterialBatch = callMaterialOrder.MaterialBatch, |
| | | MaterialMode = callMaterialOrder.MaterialMode, |
| | | DataIdentifier = callMaterialOrder.DataIdentifier, |
| | | Quantity = 1, |
| | |
| | | // 返回结果 |
| | | var response = new MesOrderResponse |
| | | { |
| | | Code = "000000", |
| | | Fail = false, |
| | | Mesg = "叫料成功", |
| | | Success = true, |
| | | Code = "200", |
| | | Message = "叫料成功", |
| | | Time = DateTime.UtcNow |
| | | }; |
| | | return response; |
| | |
| | | // 生成前缀 |
| | | return $"WMS{timestamp}"; |
| | | } |
| | | |
| | | private string GenerateRandomBatch() |
| | | { |
| | | // 获取当前时间戳(从1970-01-01 00:00:00 UTC到现在的秒数) |
| | | long timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); |
| | | |
| | | // 生成前缀 |
| | | return $"Batch{timestamp}"; |
| | | } |
| | | } |