| | |
| | | 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_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> |
| | | /// æ°å¢ç»çä¿¡æ¯ |
| | |
| | | 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; |
| | |
| | | //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(); |
| | |
| | | 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:"ç©æç»å®æå"); |
| | |
| | | } |
| | | |
| | | } |
| | | /// <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("æ¥è¯¢ä¸å°ç¸å
³æ°æ® æè
å·²ç»è§£ç»ï¼"); |
| | | |
| | | // è¿éé¢è¦åç©æç»çä¿¡æ¯çç¶ææ¹åä¾å¦å·²è§£ç» |
| | | 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: "ç©æè§£ç»æå"); |
| | | } |
| | | // å建ä¸ä¸ªä½¿ç¨å°é©¼å³°å½åæ³çåºåå设置 |
| | | 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; |
| | | } |
| | | } |
| | | } |