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 | 123 ++++++++++++++++++++++++++++++++++++----
1 files changed, 110 insertions(+), 13 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 1edbe84..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,15 +1,22 @@
锘縰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;
@@ -24,13 +31,15 @@
private readonly IDt_MaterialInfo_HtyRepository _MaterialInfo_HtyRepository;
private readonly IMapper _mapper;
private readonly IDt_StationManagerRepository _stationManagerRepository;
- public Dt_MaterialInfoService(IDt_MaterialInfoRepository BaseDal, IDt_ContainerInfoRepository dt_ContainerInfoRepository, IUnitOfWorkManage unitOfWorkManage, IDt_MaterialInfo_HtyRepository materialInfo_HtyRepository,IMapper mapper, IDt_StationManagerRepository stationManagerRepository) : base(BaseDal)
+ 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>
/// 鏂板缁勭洏淇℃伅
@@ -52,7 +61,24 @@
x => x.StationLocation == containerbindingDTO.Position
&& x.StationStatus == ((int)StationEnum.Enable).ToString());
- if (dt_StationManager == null) return content.Error("褰撳墠绔欏彴鏈厤缃� 鎴栧凡鍋滅敤");
+ 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;
@@ -65,7 +91,7 @@
//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();
@@ -74,6 +100,9 @@
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(message:"鐗╂枡缁戝畾鎴愬姛");
@@ -86,23 +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();
- // 鍏堟煡璇㈢浉搴旂殑缁勭洏缁戝畾淇℃伅 濡傛灉娌℃湁鏁版嵁鍒欒繑鍥�
- Dt_MaterialInfo dt_MaterialInfo = await BaseDal.QueryFirstAsync(x => x.ContainerCode == PalletCode);
- if (dt_MaterialInfo == null) return content.Error("鏌ヨ涓嶅埌鐩稿叧鏁版嵁 鎴栬�呭凡缁忚В缁戯紒");
- // 杩欓噷闈㈣鍐欑墿鏂欑粍鐩樹俊鎭殑鐘舵�佹敼鍙樹緥濡傚凡瑙g粦
- dt_MaterialInfo.IsBind = false;
+ ContainerOutDTO containerOutDTO = new ContainerOutDTO();
+ containerOutDTO.containerCode = PalletCode;
+ containerOutDTO.requestId = Guid.NewGuid().ToString().Replace("-", "");
- Dt_MaterialInfo_Hty dt_MaterialInfo_Hty = _mapper.Map<Dt_MaterialInfo_Hty>(dt_MaterialInfo);
+ WebResponseContent contentIn = AgvSendContainerOutDTO(containerOutDTO, APIEnum.AgvcontainerOut);
+ if (!content.Status)
+ throw new Exception(content.Message);
- await _MaterialInfo_HtyRepository.AddDataAsync(dt_MaterialInfo_Hty);
- await BaseDal.DeleteDataAsync(dt_MaterialInfo);
-
- // 鍒犻櫎褰撳墠缁勭洏鏁版嵁娣诲姞杩涘叆鍘嗗彶璁板綍
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