#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEA_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SqlSugar; using System.Reflection.Emit; using System.Threading.Tasks; using WIDESEA_Common.CommonEnum; using WIDESEA_Common.LocationEnum; using WIDESEA_Common.MaterielEnum; using WIDESEA_Common.OrderEnum; using WIDESEA_Common.StockEnum; using WIDESEA_Common.TaskEnum; using WIDESEA_Common.WareHouseEnum; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_DTO; using WIDESEA_DTO.ERP; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.Outbound; using WIDESEA_DTO.Stock; using WIDESEA_DTO.Task; using WIDESEA_External.ERPService; using WIDESEA_External.MESService; using WIDESEA_External.Model; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_IInboundRepository; using WIDESEA_IInboundService; using WIDESEA_InboundRepository; using WIDESEA_IOutboundRepository; using WIDESEA_IOutboundService; using WIDESEA_IRecordService; using WIDESEA_IStockRepository; using WIDESEA_IStockService; using WIDESEA_ITaskInfoRepository; using WIDESEA_ITaskInfoService; using WIDESEA_Model.Models; using WIDESEA_TaskInfoRepository; namespace WIDESEA_TaskInfoService { public partial class TaskService : ServiceBase, ITaskService { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IRecordService _recordService; private readonly IStockRepository _stockRepository; private readonly IStockService _stockService; private readonly IBasicRepository _basicRepository; private readonly IBasicService _basicService; private readonly IInvokeERPService _invokeERPService; private readonly IInvokeMESService _invokeMESService; private readonly IOutboundRepository _outboundRepository; private readonly IOutboundService _outboundService; private readonly IInboundRepository _inboundRepository; private readonly IInboundService _inboundService; public ITaskRepository Repository => BaseDal; private Dictionary _taskOrderBy = new() { {nameof(Dt_Task.Grade),OrderByType.Desc }, {nameof(Dt_Task.CreateDate),OrderByType.Asc}, }; public List TaskInboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 500 && x < 900).ToList(); public List TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 100 && x < 500).ToList(); public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository, IInvokeERPService invokeERPService, IOutboundRepository outboundRepository, IOutboundService outboundService, IInboundRepository inboundRepository,IInboundService inboundService,IInvokeMESService invokeMESService) : base(BaseDal) { _mapper = mapper; _unitOfWorkManage = unitOfWorkManage; _stockRepository = stockRepository; _basicService = basicService; _recordService = recordService; _stockService = stockService; _basicRepository = basicRepository; _invokeERPService = invokeERPService; _invokeMESService = invokeMESService; _outboundRepository = outboundRepository; _outboundService = outboundService; _inboundRepository = inboundRepository; _inboundService = inboundService; } /// /// 任务信息推送至WCS /// /// public WebResponseContent PushTasksToWCS(List tasks, string agvDescription = "") { try { if (tasks==null || tasks.Count == 0) { return WebResponseContent.Instance.Error($"传入任务为空"); } List taskDTOs = _mapper.Map>(tasks); taskDTOs.ForEach(x => { x.AGVArea = agvDescription; }); string url = AppSettings.Get("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize()); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 任务信息推送至WCS /// /// public List ExistRoadwaysError() { try { string url = AppSettings.Get("WCS"); if (string.IsNullOrEmpty(url)) { return null; } string response = HttpHelper.Get($"{url}/api/Task/ExistRoadwaysError"); return JsonConvert.DeserializeObject>(response) ?? throw new Exception("返回错误"); } catch (Exception ex) { return null; } } /// /// 放货完成 /// /// /// public WebResponseContent PutFinish(string code, string barCode = "", string taskNum = "") { try { string url = AppSettings.Get("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSAApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code={code}&barCode={barCode}&taskNum={taskNum}" ); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } private readonly static object lockerAddSG = new object(); public WebResponseContent AddOutSGOrder(List outOrderDTOs) { WebResponseContent content = new WebResponseContent(); try { lock (lockerAddSG) { int outDetailId = _outboundRepository.OutSGOrderDetailRepository.QueryData().OrderByDescending(x=>x.Id).FirstOrDefault()?.Id ?? 0; content = _outboundService.OutSGOrderService.AddOutSGOrder(outOrderDTOs); if (!content.Status) { return content; } //获取所有的出库详情判断是否满足出库量小于5万且小于17卷 List outStockLockInfos = _outboundRepository.OutStockLockInfoRepository.QueryData(x=>x.OrderType==OutOrderTypeEnum.OutSGPick.ObjToInt() && x.Status<=OutLockStockStatusEnum.关闭.ObjToInt()); decimal sumAssignQty = outStockLockInfos.Sum(x => x.AssignQuantity); int outCount= outStockLockInfos.Select(x=>x.PalletCode).Distinct().Count(); if (sumAssignQty < AppSettings.Get("OutSGLength").ObjToInt() && outCount < AppSettings.Get("OutSGCount").ObjToInt()) { List ints = _outboundRepository.OutSGOrderDetailRepository.QueryData(x => x.Id > outDetailId).Select(x => x.Id).ToList(); int[] reseponse = new int[ints.Count]; for (int i = 0; i < ints.Count; i++) { reseponse[i] = ints[i]; } content.Message = CreateSGOutboundTasks(reseponse).Message; } else { return content.Error($"当前出库量:{sumAssignQty},当前出库卷数:{outCount},不满足小于5万且小于17卷出库条件"); } } } catch (Exception ex) { content.Error(ex.Message); } return content; } /// /// 启用 /// /// public WebResponseContent EnableStatus(int[] keys) { WebResponseContent content = new WebResponseContent(); try { List tasks = BaseDal.QueryData(x => x.TaskType < TaskTypeEnum.Inbound.ObjToInt()); List stationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => keys.Contains(x.Id)); foreach (var station in stationInfos) { Dt_Task? taskOld = tasks.FirstOrDefault(x => x.TargetAddress == station.AGVStationCode); if (taskOld!=null) { content.Message+= $"{station.AGVStationCode}出库{taskOld.TaskNum}任务执行中;"; continue; } if (station.StationArea==StationAreaEnum.一楼暂存架.ToString()) { Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x=>x.LocationCode==station.AGVStationCode); if (stockInfo!=null) { content.Message += $"{station.AGVStationCode}{stockInfo.PalletCode}库存绑定;"; continue; } } station.IsOccupied = WhetherEnum.False.ObjToInt(); } _basicRepository.AGVStationInfoRepository.UpdateData(stationInfos); content.OK(content.Message.IsNullOrEmpty() ? "成功" : $"部分成功启用!{content.Message}无法启用"); } catch (Exception ex) { content.Error(ex.Message); } return content; } /// /// 禁用 /// /// public WebResponseContent DisableStatus(int[] keys) { WebResponseContent content = new WebResponseContent(); try { List stationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => keys.Contains(x.Id)); stationInfos.ForEach(x => { x.IsOccupied = WhetherEnum.True.ObjToInt(); }); _basicRepository.AGVStationInfoRepository.UpdateData(stationInfos); content.OK("成功"); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }