| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using 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; |
| | |
| | | { |
| | | 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> |
| | | /// æ°å¢ç»çä¿¡æ¯ |
| | |
| | | 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) |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | /// <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: "ç©æè§£ç»æå"); |
| | | } |
| | | // å建ä¸ä¸ªä½¿ç¨å°é©¼å³°å½åæ³çåºåå设置 |
| | | 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($"æªæ¾å°å®¹å¨å
¥åºæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | 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($"æªæ¾å°å®¹å¨å
¥åºæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | 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; |
| | | } |
| | | } |
| | | } |