From 9376389dbf19d202f766a4fe47cf80dfe4db4f42 Mon Sep 17 00:00:00 2001
From: xiaojiao <xiaojiao@kaokeziliao.com>
Date: 星期四, 30 四月 2026 11:47:19 +0800
Subject: [PATCH] 规范读取modbus,增加容器出入场调接口
---
项目代码/WIDESEA_WCSServer/WIDESEAWCS_BasicInfoService/Dt_MaterialInfoService.cs | 145 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 137 insertions(+), 8 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_BasicInfoService/Dt_MaterialInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_BasicInfoService/Dt_MaterialInfoService.cs"
index 5ea22b0..3b9941c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_BasicInfoService/Dt_MaterialInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_BasicInfoService/Dt_MaterialInfoService.cs"
@@ -1,12 +1,22 @@
-锘縰sing Microsoft.AspNetCore.Mvc;
+锘縰sing AutoMapper;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Common.Log;
+using WIDESEAWCS_BasicInfoRepository;
+using WIDESEAWCS_Common.APIEnum;
+using WIDESEAWCS_Common.StationEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_DTO.PDA;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
@@ -18,10 +28,18 @@
{
private readonly IDt_ContainerInfoRepository _ContainerInfoRepository;
private readonly IUnitOfWorkManage _unitOfWorkManage;
- public Dt_MaterialInfoService(IDt_MaterialInfoRepository BaseDal, IDt_ContainerInfoRepository dt_ContainerInfoRepository, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
+ private readonly IDt_MaterialInfo_HtyRepository _MaterialInfo_HtyRepository;
+ private readonly IMapper _mapper;
+ private readonly IDt_StationManagerRepository _stationManagerRepository;
+ private readonly ApiInfoRepository _apiInfoRepository;
+ public Dt_MaterialInfoService(IDt_MaterialInfoRepository BaseDal, IDt_ContainerInfoRepository dt_ContainerInfoRepository, IUnitOfWorkManage unitOfWorkManage, IDt_MaterialInfo_HtyRepository materialInfo_HtyRepository,IMapper mapper, IDt_StationManagerRepository stationManagerRepository, ApiInfoRepository apiInfoRepository) : base(BaseDal)
{
_ContainerInfoRepository = dt_ContainerInfoRepository;
_unitOfWorkManage = unitOfWorkManage;
+ _MaterialInfo_HtyRepository = materialInfo_HtyRepository;
+ _mapper = mapper;
+ _stationManagerRepository = stationManagerRepository;
+ _apiInfoRepository = apiInfoRepository;
}
/// <summary>
/// 鏂板缁勭洏淇℃伅
@@ -39,30 +57,55 @@
Dt_MaterialInfo dt_MaterialInfo = await BaseDal.QueryFirstAsync(x => x.ContainerCode == containerbindingDTO.VehicleNumber);
if (dt_MaterialInfo != null) return content.Error("褰撳墠瀹瑰櫒宸茬粦瀹� 璇峰嬁閲嶅鎻愪氦");
- dt_MaterialInfo = await BaseDal.QueryFirstAsync(x => x.MaterialName == containerbindingDTO.materSn);
- if (dt_MaterialInfo != null) return content.Error("褰撳墠闆朵欢鍙峰凡瀛樺湪 璇峰嬁閲嶅鎻愪氦");
+ Dt_StationManager dt_StationManager = _stationManagerRepository.QueryFirst(
+ x => x.StationLocation == containerbindingDTO.Position
+ && x.StationStatus == ((int)StationEnum.Enable).ToString());
+
+ Dt_ContainerInfo containerInfo = await _ContainerInfoRepository.QueryFirstAsync(x => x.ContainerCode == containerbindingDTO.VehicleNumber);
+
+ if (dt_StationManager == null) return content.Error("褰撳墠绔欏彴鏈変换鍔� 鎴栧凡鍋滅敤");
+
+ ContainerInDTO containerInDTO = new ContainerInDTO(); // 瀹瑰櫒鍏ュ満DTO
+ containerInDTO.requestId = Guid.NewGuid().ToString().Replace("-", "");
+ containerInDTO.containerCode = containerbindingDTO.VehicleNumber;
+ containerInDTO.position = containerbindingDTO.Position;
+ if (containerInfo == null)
+ {
+ containerInDTO.isNew = true;
+ }
+ WebResponseContent contentIn = AgvSendContainerIn(containerInDTO, APIEnum.AgvcontainerIn);
+ if (!content.Status)
+ throw new Exception(content.Message);
+
+
+
dt_MaterialInfo = new Dt_MaterialInfo();
dt_MaterialInfo.MaterialName = containerbindingDTO.materSn;
dt_MaterialInfo.ContainerCode = containerbindingDTO.VehicleNumber;
dt_MaterialInfo.Position = containerbindingDTO.Position;
dt_MaterialInfo.Carmodel = containerbindingDTO.Carmodel;
- string s = App.User.UserName;
- await BaseDal.AddDataAsync(dt_MaterialInfo);
+ dt_MaterialInfo.Region = dt_StationManager.StationArea;
+
// 2. 鎵ц涓�瀹氫細鎶ラ敊鐨勪唬鐮侊細闄や互闆�
//int a = 1;
//int b = 0;
//int result = a / b; // 杩欓噷浼氭姏鍑� DivideByZeroException
- Dt_ContainerInfo containerInfo = await _ContainerInfoRepository.QueryFirstAsync(x => x.ContainerCode == containerbindingDTO.VehicleNumber);
+
if (containerInfo == null)
{
containerInfo = new Dt_ContainerInfo();
containerInfo.RequestId = Guid.NewGuid().ToString().Replace("-", "");
containerInfo.ContainerCode = containerbindingDTO.VehicleNumber;
+ dt_MaterialInfo.IsNew = true;
await _ContainerInfoRepository.AddDataAsync(containerInfo);
}
+ dt_StationManager.StationStatus = ((int)StationEnum.Thereisatask).ToString();
+
+ await _stationManagerRepository.UpdateDataAsync(dt_StationManager);
+ await BaseDal.AddDataAsync(dt_MaterialInfo);
_unitOfWorkManage.CommitTran();
- return content.OK();
+ return content.OK(message:"鐗╂枡缁戝畾鎴愬姛");
}
catch (Exception ex)
{
@@ -72,5 +115,91 @@
}
}
+ /// <summary>
+ /// 瀹瑰櫒鍑哄満
+ /// </summary>
+ /// <param name="PalletCode"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public async Task<WebResponseContent> DeleteGroupPlateAsync(string PalletCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+
+ ContainerOutDTO containerOutDTO = new ContainerOutDTO();
+ containerOutDTO.containerCode = PalletCode;
+ containerOutDTO.requestId = Guid.NewGuid().ToString().Replace("-", "");
+
+ WebResponseContent contentIn = AgvSendContainerOutDTO(containerOutDTO, APIEnum.AgvcontainerOut);
+ if (!content.Status)
+ throw new Exception(content.Message);
+
+ return content.OK(message: "鐗╂枡瑙g粦鎴愬姛");
+ }
+ // 鍒涘缓涓�涓娇鐢ㄥ皬椹煎嘲鍛藉悕娉曠殑搴忓垪鍖栬缃�
+ JsonSerializerSettings settings = new JsonSerializerSettings
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver()
+ };
+ /// <summary>
+ /// AGV瀹瑰櫒鍏ュ満
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent AgvSendContainerIn(ContainerInDTO containerInDTO, APIEnum Container = APIEnum.AgvcontainerIn)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == Container.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"鏈壘鍒板鍣ㄥ叆鍦烘帴鍙�,璇锋鏌ユ帴鍙i厤缃�");
+ string request = JsonConvert.SerializeObject(containerInDTO, settings);
+ string response = HttpHelper.Post(apiAddress, request);
+ WriteLog.Write_Log("AGV瀹瑰櫒鍏ュ満", "AGV瀹瑰櫒鍏ュ満涓嬪彂鎺ュ彛", "璇锋眰淇℃伅", $"璇锋眰锛歿request},鍥炰紶锛歿response}");
+ AgvResponseContent agvContent = response.DeserializeObject<AgvResponseContent>() ?? throw new Exception("AGV瀹瑰櫒鍏ュ満鏈繑鍥炵粨鏋�");
+ if (agvContent.Success)
+ {
+ content.OK();
+ }
+ else
+ {
+ content.Error(agvContent.Message);
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// AGV瀹瑰櫒鍑哄満
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent AgvSendContainerOutDTO(ContainerOutDTO containerOutDTO, APIEnum Container = APIEnum.AgvcontainerOut)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == Container.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"鏈壘鍒板鍣ㄥ叆鍦烘帴鍙�,璇锋鏌ユ帴鍙i厤缃�");
+ string request = JsonConvert.SerializeObject(containerOutDTO, settings);
+ string response = HttpHelper.Post(apiAddress, request);
+ WriteLog.Write_Log("AGV瀹瑰櫒鍑哄満", "AGV瀹瑰櫒鍑哄満涓嬪彂鎺ュ彛", "璇锋眰淇℃伅", $"璇锋眰锛歿request},鍥炰紶锛歿response}");
+ AgvResponseContent agvContent = response.DeserializeObject<AgvResponseContent>() ?? throw new Exception("AGV瀹瑰櫒鍑哄満鏈繑鍥炵粨鏋�");
+ if (agvContent.Success)
+ {
+ content.OK();
+ }
+ else
+ {
+ content.Error(agvContent.Message);
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
}
}
--
Gitblit v1.9.3