22
schangxiang@126.com
2025-05-20 5b189017d143be6366f56ffcdd3c3699a381e034
PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
@@ -1,37 +1,31 @@
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.Dtos.WorkTask;
using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrder;
using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
using Volo.Abp.Users;
using CmsQueryExtensions.Entitys;
using CMS.Unit.RuntimeValue.Abstractions;
using CMS.Extensions.Variable;
using CMS.Plugin.TraceManagement.Abstractions.Models.Traces;
using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
using CMS.Plugin.ProcessManagement.Abstractions;
using KissUtil.Extensions;
using CMS.Plugin.ProductManagement.Abstractions;
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 CMS.Plugin.TraceManagement.Abstractions.Models.Traces;
using CmsQueryExtensions;
using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsMaterialStocks;
using CmsQueryExtensions.Entitys;
using CmsQueryExtensions.Extension;
using KissUtil.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Volo.Abp;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Uow;
namespace CMS.Plugin.PipeLineLems.Application.Implements;
@@ -50,6 +44,10 @@
    /// <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("请输入管段编码");
@@ -111,13 +109,19 @@
            });
        }
        //物料参数列表
        var firstWorkPlans = await workPlanAppService.GetListByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode);
        var firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode);
        var firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.TaskCode == input.TaskCode);
        var callMaterialOrder = await callMaterialOrderAppService.GetSingleByFilterAsync(x => x.DataIdentifier == firstWorkPlan.DataIdentifier);
        //TODO:这里调用wms的叫料接口
        try
        {
            //首先判断库存是否存在
            var dto = await IsExistInWms(input.PipeSpecCode);
            if (dto != null)
            {
                throw new UserFriendlyException($"已经分拣过,库存在库位{dto.PlaceNo},托盘号{dto.ContainerNo}");
            }
            WmsMaterialStockCreateDto param = new WmsMaterialStockCreateDto()
            {
                ContainerNo = input.ContinerNo,
@@ -126,7 +130,9 @@
                StockNumber = 1,
                MaterialBatch = callMaterialOrder.MaterialBatch,
                RedundantField1 = firstWorkPlan.ProcessRouteNumber //扩展字段显示 工艺流向编号
                RedundantField1 = firstWorkPlan.ProcessRouteNumber, //扩展字段显示 工艺流向编号
                RedundantField2 = firstWorkPlan.PipeSpecCode, //扩展字段显示 管段编码
                RedundantField3 = firstWorkPlan.PipeSectionName, //扩展字段显示 管段名称
            };
            string baseUrl = @"http://127.0.0.1:18000/api/v1/HIAWms/";
@@ -262,6 +268,7 @@
        };
        return response;
    }
    /// <summary>
    /// 创建作业计划
    /// </summary>
@@ -270,7 +277,6 @@
    /// <param name="workPlanAppService"></param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException"></exception>
    public async Task<MesOrderResponse> CommonCreatebyApsAsync(List<WorkPlanInput> input, IServiceProvider _serviceProvider,
    WorkPlanAppService workPlanAppService,
    string userId, string userAccount
@@ -310,6 +316,8 @@
        var orderManager = _serviceProvider.GetRequiredService<IOrderManager>();
        var productProvider = _serviceProvider.GetRequiredService<IProductProvider>();
        var formulaProvider = _serviceProvider.GetRequiredService<IFormulaProvider>();
        var workTaskAppService = _serviceProvider.GetRequiredService<IWorkTaskAppService>();
        List<OrderModel> orderModels = new List<OrderModel>();
@@ -447,16 +455,36 @@
                insertObj.CreatorName = userAccount;
                insertObj.Remark = "系统导入";
                await workPlanAppService.CreateAsync(insertObj);
                //增加新增计划任务表数据 【Editby shaocx,2025-05-20】
                var org_insertTaskObj = ObjectMapper.Map<WorkPlanCreateDto, WorkTaskCreateDto>(insertObj);
                org_insertTaskObj.Son_TaskCode = insertObj.TaskCode;
                await workTaskAppService.CreateAsync(org_insertTaskObj);
                if (insertObj.ProcessName == "切割工序")
                {//新建 分拣工序
                    var insertTaskObj = ObjectMapper.Map<WorkPlanCreateDto, WorkTaskCreateDto>(insertObj);
                    insertTaskObj.Son_TaskCode = insertObj.TaskCode + "_1";
                    insertTaskObj.ProcessName = "分拣工序";
                    await workTaskAppService.CreateAsync(insertTaskObj);
                }
                else if (insertObj.ProcessName == "装配工序")
                {//新建 法兰冲码工序(多个)
                 //目前暂时搞成一个法兰
                    var insertTaskObj = ObjectMapper.Map<WorkPlanCreateDto, WorkTaskCreateDto>(insertObj);
                    insertTaskObj.Son_TaskCode = insertObj.TaskCode + "_1";
                    insertTaskObj.ProcessName = "法兰冲码工序";
                    await workTaskAppService.CreateAsync(insertTaskObj);
                }
            }
            #endregion
            await uow.CompleteAsync();
        }
        catch (Exception)
        catch (Exception ex)
        {
            await uow.RollbackAsync();
            throw;
            throw ex;
        }
        finally
        {
@@ -565,6 +593,7 @@
            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)
            {
@@ -577,6 +606,7 @@
            {
                throw new UserFriendlyException(res.Message);
            }
            //*/
        }
        catch (Exception)
        {
@@ -1085,33 +1115,34 @@
        WorkPlanDto workPlanDto = await _workPlanAppService.FindSingleByFilterAsync(input);
        //TODO:这里调用wms的叫料接口
        //TODO:这里调用wms的库存查询接口
        try
        {
            List<LMesCallMaterialInput> param = new List<LMesCallMaterialInput>() {
             new LMesCallMaterialInput(){
            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/LMesCallMaterial";
            string url = baseUrl + "LMesOperate/FindListByFilter";
            string json = JsonConvert.SerializeObject(param);
            var result = HttpApiRequest.HttpPost(url, json);
            var res = JsonConvert.DeserializeObject<CmsApiResponse<List<MyCallMaterialOutput>>>(result);
            var res = JsonConvert.DeserializeObject<CmsApiResponse<List<WmsMaterialStockDto>>>(result);
            if (res.Code == 200)
            {
                var retData = res.Data;
                //callMaterialOrder.MaterialBatch = retData[0].MaterialBatch;
                //callMaterialOrder.WmsTaskNo = retData[0].TaskNo;
                //callMaterialOrder.WmsRetResult = res.Message;
                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>
                {
@@ -1125,24 +1156,67 @@
            else
            {
                throw new UserFriendlyException(res.Message);
            }
            };
            //*/
            //模拟
            var data = new PickOutput()
            //var data = new PickOutput()
            //{
            //    WorkPlan = workPlanDto,
            //    PlaceNo = "",//待赋值
            //    ContinerNo = ""//待赋值
            //};
            //var response = new CmsApiResponse<PickOutput>
            //{
            //    Code = 200,
            //    Data = data,
            //    Message = "处理成功",
            //};
            //return response;
        }
        catch (Exception)
        {
            throw;
        }
    }
    /// <summary>
    /// 管段编码是否存在库存中
    /// </summary>
    /// <param name="pipeSpecCode"></param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException"></exception>
    public async Task<WmsMaterialStockDto> IsExistInWms(string pipeSpecCode)
    {
        //TODO:这里调用wms的库存查询接口
        try
        {
            GetWmsMaterialStockInput param = new GetWmsMaterialStockInput()
            {
                WorkPlan = workPlanDto,
                PlaceNo = "",//待赋值
                ContinerNo = ""//待赋值
                RedundantField2 = pipeSpecCode,
                RedundantField2_FilterMode = SearchFilterModeEnum.精准查询
            };
            var response = new CmsApiResponse<PickOutput>
            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)
            {
                Code = 200,
                Data = data,
                Message = "处理成功",
            };
            return response;
                var retData = res.Data as List<WmsMaterialStockDto>;
                if (retData?.Count > 0)
                {
                    return retData.First();
                }
                return null;
            }
            else
            {
                throw new UserFriendlyException(res.Message);
            };
        }
        catch (Exception)
        {