From b5904672914f1088841208b4084fc7619576fa2e Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周二, 20 5月 2025 11:50:32 +0800
Subject: [PATCH] 优化
---
PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs | 844 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 804 insertions(+), 40 deletions(-)
diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
index 5a25ab4..7b61b13 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
@@ -1,24 +1,29 @@
+using CMS.Extensions.Variable;
using CMS.Plugin.FormulaManagement.Abstractions;
+using CMS.Plugin.HIAWms.Application.Contracts.Dtos.CommonDto;
+using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsMaterialStocks;
+using CMS.Plugin.MaterialManagement.Abstractions;
using CMS.Plugin.OrderManagement.Abstractions;
using CMS.Plugin.OrderManagement.Abstractions.Enums;
using CMS.Plugin.OrderManagement.Abstractions.Models;
-using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan;
-using CMS.Plugin.ProductManagement.Abstractions;
-using Microsoft.Extensions.DependencyInjection;
-using Volo.Abp;
-using Microsoft.Extensions.DependencyInjection;
-using NPOI.Util;
-using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrder;
-using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.CallMaterialOrder;
-using Volo.Abp.Uow;
-using System.Text;
-using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
+using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan;
+using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
+using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrder;
using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
-using Volo.Abp.Users;
+using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
+using CMS.Plugin.ProcessManagement.Abstractions;
+using CMS.Plugin.ProductManagement.Abstractions;
+using CMS.Plugin.TraceManagement.Abstractions;
+using CMS.Plugin.TraceManagement.Abstractions.Models.Traces;
+using CmsQueryExtensions;
using CmsQueryExtensions.Entitys;
-using CMS.Unit.RuntimeValue.Abstractions;
-using CMS.Extensions.Variable;
+using CmsQueryExtensions.Extension;
+using KissUtil.Extensions;
+using Microsoft.Extensions.DependencyInjection;
+using Newtonsoft.Json;
+using Volo.Abp;
+using Volo.Abp.Uow;
namespace CMS.Plugin.PipeLineLems.Application.Implements;
@@ -28,29 +33,227 @@
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)
{
+ if (string.IsNullOrEmpty(input.TaskCode))
+ {
+ throw new UserFriendlyException("璇疯緭鍏ヤ换鍔$紪鍙�");
+ };
+ if (string.IsNullOrEmpty(input.PipeSpecCode))
+ {
+ throw new UserFriendlyException("璇疯緭鍏ョ娈电紪鐮�");
+ };
+ if (string.IsNullOrEmpty(input.ContinerNo))
+ {
+ throw new UserFriendlyException("璇疯緭鍏ユ墭鐩樺彿");
+ };
//1銆佽褰曞垎鎷h褰曡〃
//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>();
+ var callMaterialOrderAppService = _serviceProvider.GetRequiredService<ICallMaterialOrderAppService>();
- 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 firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.TaskCode == input.TaskCode);
+ var callMaterialOrder = await callMaterialOrderAppService.GetSingleByFilterAsync(x => x.DataIdentifier == firstWorkPlan.DataIdentifier);
+ //TODO:杩欓噷璋冪敤wms鐨勫彨鏂欐帴鍙�
+ try
+ {
+ WmsMaterialStockCreateDto param = new WmsMaterialStockCreateDto()
+ {
+ ContainerNo = input.ContinerNo,
+ MaterialModel = firstWorkPlan.MaterialMode,
+ PlaceNo = input.PlaceNo,
+ StockNumber = 1,
+ MaterialBatch = callMaterialOrder.MaterialBatch,
+
+ RedundantField1 = firstWorkPlan.ProcessRouteNumber, //鎵╁睍瀛楁鏄剧ず 宸ヨ壓娴佸悜缂栧彿
+ RedundantField2 = firstWorkPlan.PipeSpecCode, //鎵╁睍瀛楁鏄剧ず 绠℃缂栫爜
+ RedundantField3 = firstWorkPlan.PipeSectionName, //鎵╁睍瀛楁鏄剧ず 绠℃鍚嶇О
+
+ };
+ string baseUrl = @"http://127.0.0.1:18000/api/v1/HIAWms/";
+ string url = baseUrl + "LMesOperate/LMesPick";
+ string json = JsonConvert.SerializeObject(param);
+ var result = HttpApiRequest.HttpPost(url, json);
+ var res = JsonConvert.DeserializeObject<CmsApiResponse<WmsMaterialStockDto>>(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;
+ }
+
+
+
+
+
+ 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 = callMaterialOrder.MaterialBatch,//鎵规鏆傛椂鍐欐
+
+ });
+ }
+ };
+
+ //閰嶇疆杩囩▼鍙傛暟(閲囬泦鍙傛暟銆侀厤鏂瑰弬鏁�)
+ 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);
+ };
+ foreach (var item in workSection.FormulaParameters)
+ {
+ 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;
@@ -78,6 +281,13 @@
if (input.Count == 0)
{
throw new UserFriendlyException("杈撳叆鍙傛暟Data涓嶈兘涓虹┖");
+ }
+
+ //鍐欐 鎵撶爜鍐呭
+ foreach (var item in input)
+ {
+ //鏍煎紡 绠℃缂栫爜,绠℃鍚嶇О,鑸瑰彿,椤圭洰鍙�
+ item.MarkingContent = item.PipeSpecCode + "," + item.PipeSectionName + "," + item.ShipNumber + "," + item.ProjectNumber;
}
//鏍¢獙鏁版嵁
@@ -212,6 +422,7 @@
CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鏈墽琛�,
DataIdentifier = gTask.Key,
MaterialMode = gTask.ToList().First().MaterialMode,
+ CreatorName = userAccount,
Quantity = 1
};
@@ -230,6 +441,7 @@
insertObj.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鏈敓浜�;
insertObj.Sort = 1;
insertObj.CreatorName = userAccount;
+ insertObj.Remark = "绯荤粺瀵煎叆";
await workPlanAppService.CreateAsync(insertObj);
}
@@ -260,9 +472,7 @@
{
Code = "000000",
Data = orderModels,
- Fail = false,
- Mesg = "澶勭悊鎴愬姛",
- Success = true,
+ Message = "澶勭悊鎴愬姛",
Time = DateTime.UtcNow
};
return response;
@@ -312,9 +522,9 @@
/// <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("鍘熸枡鏍囪瘑涓嶈兘涓虹┖");
}
@@ -326,7 +536,7 @@
// 鏌ユ壘鏁版嵁
- var callMaterialOrder = await callMaterialOrderRepository.GetAsync(id);
+ var callMaterialOrder = await callMaterialOrderRepository.GetAsync(input.Id);
if (callMaterialOrder == null)
{
throw new UserFriendlyException($"鎵句笉鍒板彨鏂欒褰�");
@@ -335,19 +545,55 @@
// 楠岃瘉鐘舵��
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.鍙枡瀹屾垚;
@@ -359,6 +605,7 @@
var callMaterialOrderRecord = new CallMaterialOrderRecord()
{
CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鍙枡瀹屾垚,
+ MaterialBatch = callMaterialOrder.MaterialBatch,
MaterialMode = callMaterialOrder.MaterialMode,
DataIdentifier = callMaterialOrder.DataIdentifier,
Quantity = 1,
@@ -385,13 +632,521 @@
// 杩斿洖缁撴灉
var response = new MesOrderResponse
{
- Code = "000000",
- Fail = false,
- Mesg = "鍙枡鎴愬姛",
- Success = true,
+ Code = "200",
+ Message = "鍙枡鎴愬姛",
Time = DateTime.UtcNow
};
return response;
+ }
+
+ /// <summary>
+ ///瑁呴厤/鐒婃帴寮�宸�
+ /// </summary>
+ /// <param name="input"></param>
+ /// <param name="_serviceProvider"></param>
+ /// <param name="myCurrentUser"></param>
+ /// <returns></returns>
+ /// <exception cref="UserFriendlyException"></exception>
+ public async Task<MesOrderResponse> StartProduction(StartProductionInput input, IServiceProvider _serviceProvider, MyCurrentUser myCurrentUser)
+ {
+ if (string.IsNullOrEmpty(input.TaskCode.ToString()))
+ {
+ throw new UserFriendlyException("浠诲姟缂栫爜涓嶈兘涓虹┖");
+ }
+
+ string processName = "";
+
+ VariableService _variableService = _serviceProvider.GetRequiredService<VariableService>();
+ var callMaterialOrderRepository = _serviceProvider.GetRequiredService<ICallMaterialOrderRepository>();
+ var workPlanRepository = _serviceProvider.GetRequiredService<IWorkPlanRepository>();
+ var callMaterialOrderRecordRepository = _serviceProvider.GetRequiredService<ICallMaterialOrderRecordRepository>();
+ var orderManager = _serviceProvider.GetRequiredService<IOrderManager>();
+ var callMaterialOrderAppService = _serviceProvider.GetRequiredService<ICallMaterialOrderAppService>();
+
+ // 鏌ユ壘鏁版嵁
+
+ var workPlan = await workPlanRepository.GetSingleByFilterAsync(x => x.TaskCode == input.TaskCode);
+ if (workPlan == null)
+ {
+ throw new UserFriendlyException($"鎵句笉鍒颁綔涓氳鍒�");
+ }
+ if (workPlan.ProcessName == "瑁呴厤宸ュ簭")
+ {
+ processName = "瑁呴厤";
+ }
+ else if (workPlan.ProcessName == "鐒婃帴宸ュ簭")
+ {
+ processName = "鐒婃帴";
+ }
+
+ // 楠岃瘉鐘舵��
+ if (workPlan.WorkPlanStatus != Domain.Shared.Enums.WorkPlanStatusEnum.鏆傚仠涓� && workPlan.WorkPlanStatus != Domain.Shared.Enums.WorkPlanStatusEnum.鏈敓浜�)
+ {
+ //鏆傛椂娉ㄩ噴
+ //throw new UserFriendlyException($"浠诲姟缂栫爜 '{input.TaskCode}' 鐨勫綍鐘舵�佷负 '{workPlan.WorkPlanStatus}'锛屼笉鍏佽寮�宸�");
+ }
+
+ var callMaterialOrder = await callMaterialOrderAppService.GetSingleByFilterAsync(x => x.DataIdentifier == workPlan.DataIdentifier);
+ #region 浜嬪姟
+
+ using var scope = _serviceProvider.CreateScope();
+ var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
+ using var uow = unitOfWorkManager.Begin(requiresNew: true);
+
+ try
+ {
+ #region 鏁版嵁澶勭悊
+
+ //1銆佹洿鏂颁綔涓氳鍒掕〃涓� 鐢熶骇涓�
+ //2銆佺粰PLC鍙戝伐鑹哄弬鏁版寚浠�,骞跺啓鍏� plc涓� 浜у搧id
+ //if (workPlan.ProcessName == "瑁呴厤宸ュ簭")
+ //{
+ // workPlan.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鐢熶骇涓�;
+ //}
+ //else if (workPlan.ProcessName == "鐒婃帴宸ュ簭")
+ //{
+ // workPlan.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.宸插畬鎴�;
+ //}
+ workPlan.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鐢熶骇涓�;
+
+ await workPlanRepository.UpdateAsync(workPlan);
+
+ Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
+ {
+ { $"{processName}_ProductID", workPlan.PipeSpecCode },
+ { $"{processName}绠℃缂栫爜", workPlan.PipeSpecCode },
+ { $"{processName}绠℃鍚嶇О", workPlan.PipeSectionName },
+ { $"{processName}鍘熸枡绠℃壒娆�", callMaterialOrder.MaterialBatch },
+ { $"{processName}鍘熸枡绠″瀷鍙�", callMaterialOrder.MaterialMode },
+ { $"{processName}鍘熸枡绠℃爣璇�", callMaterialOrder.DataIdentifier },
+ { $"{processName}椤圭洰鍙�", workPlan.ProjectNumber },
+ { $"{processName}鑸瑰彿", workPlan.ShipNumber },
+
+ //閲囬泦鏁版嵁妯℃嫙鍐欏叆
+ { $"{processName}鍘嬪姏", "10.0 MPa" },
+ { $"{processName}閫熷害", "18mm/s"},
+
+ { $"{processName}浜�", myCurrentUser.UserAccount},
+ { $"{processName}闂撮殭","15mm"},
+ { $"{processName}浣嶇疆", "10,23,24"},
+ };
+ _variableService.WriteValueAsync(keyValuePairs);
+
+
+ #endregion
+
+ await uow.CompleteAsync();
+
+ // 杩斿洖缁撴灉
+ var response = new MesOrderResponse
+ {
+ Code = "200",
+ Message = "澶勭悊鎴愬姛",
+ Time = DateTime.UtcNow
+ };
+ return response;
+ }
+ catch (Exception)
+ {
+ await uow.RollbackAsync();
+ throw;
+ }
+ finally
+ {
+
+ }
+
+
+
+ #endregion
+ }
+
+
+
+ /// <summary>
+ /// 瑁呴厤宸ュ簭瀹屽伐
+ /// </summary>
+ /// <param name="_serviceProvider"></param>
+ /// <param name="input"></param>
+ /// <param name="myCurrentUser"></param>
+ /// <returns></returns>
+ public async Task<MesOrderResponse> CompleteAssemblyProcess(IServiceProvider _serviceProvider, CompleteAssemblyProcessInput input, MyCurrentUser myCurrentUser)
+ {
+ //1銆佽褰曞垎鎷h褰曡〃
+ //2銆佹洿鏂颁綔涓氳鍒掕〃鐨勭姸鎬� =宸插垎鎷�
+ //3銆佸啓鍏� 鍒嗘嫞鍙橀噺
+ //4銆佸啓鍏ヨ拷婧姤琛�
+ //5銆佺墿鏂欑粍鐩�
+
+ if (string.IsNullOrEmpty(input.PipeSpecCode))
+ {
+ throw new UserFriendlyException($"绠℃缂栫爜涓嶈兘涓虹┖");
+ }
+
+
+ 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>();
+ var workPlanRepository = _serviceProvider.GetRequiredService<IWorkPlanRepository>();
+ var callMaterialOrderAppService = _serviceProvider.GetRequiredService<ICallMaterialOrderAppService>();
+
+ string processName = "";
+ //鐗╂枡鍙傛暟鍒楄〃
+ var firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode && x.ProcessName == input.ProcessName);
+ if (firstWorkPlan == null)
+ {
+ throw new UserFriendlyException($"鎵句笉鍒颁綔涓氳鍒�");
+ }
+ if (firstWorkPlan.ProcessName == "瑁呴厤宸ュ簭")
+ {
+ processName = "瑁呴厤";
+ }
+ else if (firstWorkPlan.ProcessName == "鐒婃帴宸ュ簭")
+ {
+ processName = "鐒婃帴";
+ }
+
+ await CompleteHandleOutStoreFinish(_serviceProvider, processName, true);
+
+ //鏍规嵁宸ュ簭鍚嶈幏鍙栧伐搴忓璞�
+ var workSection = await _workSectionManager.GetByNameAsync($"{processName}宸ュ簭");
+ var workStation = await _workStationManager.GetByNameAsync($"{processName}宸ヤ綅");
+ //鍐欏叆杩芥函鎶ヨ〃
+ 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()
+ });
+ }
+
+ #region 浜嬪姟
+
+ using var scope = _serviceProvider.CreateScope();
+ var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
+ using var uow = unitOfWorkManager.Begin(requiresNew: true);
+
+ try
+ {
+ #region 鏁版嵁澶勭悊
+
+
+
+ firstWorkPlan.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.宸插畬鎴�;
+ await workPlanRepository.UpdateAsync(firstWorkPlan);
+
+ var callMaterialOrder = await callMaterialOrderAppService.GetSingleByFilterAsync(x => x.DataIdentifier == firstWorkPlan.DataIdentifier);
+
+ var rawPipe_DataIdentifier = await materialProvider.FindByNameAsync("鍘熸枡绠℃爣璇�");
+ var rawPipe_MaterialMode = await materialProvider.FindByNameAsync("鍘熸枡绠″瀷鍙�");
+ var rawPipe_Batch = await materialProvider.FindByNameAsync("鍘熸枡绠℃壒娆�");
+ var rawPipe_ProjectNumber = await materialProvider.FindByNameAsync("椤圭洰鍙�");
+ var rawPipe_ShipNumber = 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 = callMaterialOrder.MaterialBatch,//鎵规鏆傛椂鍐欐
+
+ });
+ }
+ if (item.Name == "椤圭洰鍙�")
+ {
+ _MaterialParams.Add(new TraceMaterialModel()
+ {
+ Key = item.Key,
+ Quantity = 1,
+ MaterialId = rawPipe_ProjectNumber.MaterialId,
+ MaterialDetailId = rawPipe_ProjectNumber.MaterialDetails.First().Id,
+ Value = firstWorkPlan.ProjectNumber,
+
+ });
+ }
+ if (item.Name == "鑸瑰彿")
+ {
+ _MaterialParams.Add(new TraceMaterialModel()
+ {
+ Key = item.Key,
+ Quantity = 1,
+ MaterialId = rawPipe_ShipNumber.MaterialId,
+ MaterialDetailId = rawPipe_ShipNumber.MaterialDetails.First().Id,
+ Value = firstWorkPlan.ShipNumber,
+
+ });
+ }
+ };
+
+ //閰嶇疆杩囩▼鍙傛暟(閲囬泦鍙傛暟銆侀厤鏂瑰弬鏁�)
+ traceModel.Params = new List<TraceParamModel>();
+ foreach (var item in workSection.ProcessParameters)
+ {
+ string _value = "";
+
+ //閲囬泦鍙傛暟
+ if (item.Name == $"{processName}鍘嬪姏")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}鍘嬪姏");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+ if (item.Name == $"{processName}浣嶇疆")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}浣嶇疆");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+ if (item.Name == $"{processName}閫熷害")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}閫熷害");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+
+ if (item.Name == $"{processName}闂撮殭")
+ {
+ _value = "15mm";
+ }
+ if (item.Name == $"{processName}浜�")
+ {
+ _value = myCurrentUser.UserAccount;
+ }
+ //item.Key
+ TraceParamModel traceParamModel = new TraceParamModel()
+ {
+ Key = item.Key,
+ Value = _value
+ };
+ traceModel.Params.Add(traceParamModel);
+ };
+ foreach (var item in workSection.FormulaParameters)
+ {
+ string _value = "";
+
+ //閲囬泦鍙傛暟
+ if (item.Name == $"{processName}鍘嬪姏")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}鍘嬪姏");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+ if (item.Name == $"{processName}浣嶇疆")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}浣嶇疆");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+ if (item.Name == $"{processName}閫熷害")
+ {
+ var _getValue = await _variableService.ReadValueAsync($"{processName}閫熷害");
+ _value = _getValue.Content.Value.SafeString().ToString();
+ }
+
+ if (item.Name == $"{processName}闂撮殭")
+ {
+ _value = "15mm";
+ }
+ if (item.Name == $"{processName}浜�")
+ {
+ _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 = "200",
+ Data = "",
+ Message = "澶勭悊鎴愬姛",
+ Time = DateTime.UtcNow
+ };
+ return response;
+
+ #endregion
+
+ await uow.CompleteAsync();
+ }
+ catch (Exception)
+ {
+ await uow.RollbackAsync();
+ throw;
+ }
+ finally
+ {
+
+ }
+
+
+
+ #endregion
+
+ }
+
+
+ /// <summary>
+ /// 鍏叡澶勭悊 鍝嶅簲鍑虹珯瀹屾垚淇″彿
+ /// </summary>
+ /// <param name="_serviceProvider"></param>
+ /// <param name="input"></param>
+ /// <param name="myCurrentUser"></param>
+ /// <returns></returns>
+ public async Task CompleteHandleOutStoreFinish(IServiceProvider _serviceProvider, string processName, bool isOutResult)
+ {
+
+ VariableService _variableService = _serviceProvider.GetRequiredService<VariableService>();
+
+ Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
+ {
+ { $"{processName}鍑虹珯瀹屾垚",isOutResult},
+ { $"{processName}鍑虹珯缁撴灉",isOutResult? "鎴愬姛":""},
+ };
+ await _variableService.WriteValueAsync(keyValuePairs);
+
+ }
+
+
+ /// <summary>
+ /// 鍒嗘嫞鏃惰幏鍙栫敓浜ц鍒掑拰鍒嗛厤鍖哄煙
+ /// </summary>
+ /// <param name="input"></param>
+ /// <param name="_serviceProvider"></param>
+ /// <param name="myCurrentUser"></param>
+ /// <returns></returns>
+ /// <exception cref="UserFriendlyException"></exception>
+ public async Task<CmsApiResponse<PickOutput>> GetPickRetAsync(GetWorkPlanInput input, IServiceProvider _serviceProvider, MyCurrentUser myCurrentUser)
+ {
+
+
+ var callMaterialOrderRepository = _serviceProvider.GetRequiredService<ICallMaterialOrderRepository>();
+ var workPlanRepository = _serviceProvider.GetRequiredService<IWorkPlanRepository>();
+ var _workPlanAppService = _serviceProvider.GetRequiredService<IWorkPlanAppService>();
+ var callMaterialOrderRecordRepository = _serviceProvider.GetRequiredService<ICallMaterialOrderRecordRepository>();
+ var orderManager = _serviceProvider.GetRequiredService<IOrderManager>();
+
+ // 鏌ユ壘鏁版嵁
+
+ WorkPlanDto workPlanDto = await _workPlanAppService.FindSingleByFilterAsync(input);
+
+ //TODO:杩欓噷璋冪敤wms鐨勫簱瀛樻煡璇㈡帴鍙�
+ try
+ {
+ GetWmsMaterialStockInput param = new GetWmsMaterialStockInput()
+ {
+ RedundantField1 = workPlanDto.ProcessRouteNumber,
+ RedundantField1_FilterMode = SearchFilterModeEnum.绮惧噯鏌ヨ
+ };
+
+ string baseUrl = @"http://127.0.0.1:18000/api/v1/HIAWms/";
+ string url = baseUrl + "LMesOperate/FindListByFilter";
+ string json = JsonConvert.SerializeObject(param);
+ var result = HttpApiRequest.HttpPost(url, json);
+ var res = JsonConvert.DeserializeObject<CmsApiResponse<List<WmsMaterialStockDto>>>(result);
+ if (res.Code == 200)
+ {
+ var retData = res.Data as List<WmsMaterialStockDto>;
+ var data = new PickOutput()
+ {
+ WorkPlan = workPlanDto,
+ PlaceNo = "",//寰呰祴鍊�
+ ContinerNo = ""//寰呰祴鍊�
+ };
+ if (retData?.Count > 0)
+ {
+ data.PlaceNo = retData.First().PlaceNo;
+ data.ContinerNo = retData.First().ContainerNo;
+ }
+
+ var response = new CmsApiResponse<PickOutput>
+ {
+ Code = 200,
+ Data = data,
+ Message = "澶勭悊鎴愬姛",
+ };
+ return response;
+
+ }
+ else
+ {
+ throw new UserFriendlyException(res.Message);
+ };
+ //*/
+ //妯℃嫙
+ //var data = new PickOutput()
+ //{
+ // WorkPlan = workPlanDto,
+ // PlaceNo = "",//寰呰祴鍊�
+ // ContinerNo = ""//寰呰祴鍊�
+ //};
+ //var response = new CmsApiResponse<PickOutput>
+ //{
+ // Code = 200,
+ // Data = data,
+ // Message = "澶勭悊鎴愬姛",
+ //};
+ //return response;
+
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
}
/// <summary>
@@ -406,4 +1161,13 @@
// 鐢熸垚鍓嶇紑
return $"WMS{timestamp}";
}
+
+ private string GenerateRandomBatch()
+ {
+ // 鑾峰彇褰撳墠鏃堕棿鎴筹紙浠�1970-01-01 00:00:00 UTC鍒扮幇鍦ㄧ殑绉掓暟锛�
+ long timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
+
+ // 鐢熸垚鍓嶇紑
+ return $"Batch{timestamp}";
+ }
}
--
Gitblit v1.9.3