| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.RGV.FOURBOT; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | |
| | |
| | | { |
| | | public class ApiInfoService : ServiceBase<Dt_ApiInfo, IRepository<Dt_ApiInfo>>, IApiInfoService |
| | | { |
| | | public ApiInfoService(IRepository<Dt_ApiInfo> BaseDal) : base(BaseDal) |
| | | private readonly IInterfaceLogService _interfaceLogService; |
| | | public ApiInfoService(IRepository<Dt_ApiInfo> BaseDal, IInterfaceLogService interfaceLogService) : base(BaseDal) |
| | | { |
| | | _interfaceLogService = interfaceLogService; |
| | | } |
| | | |
| | | public IRepository<Dt_ApiInfo> Repository => BaseDal; |
| | | |
| | | /// <summary> |
| | | /// Postæ¥å£è¯·æ± |
| | | /// </summary> |
| | | /// <param name="apiCode">æ¥å£ç¼å·</param> |
| | | /// <param name="requestParameters">请æ±å
容</param> |
| | | /// <param name="remark">夿³¨</param> |
| | | /// <param name="isAdd">æ¯å¦æ·»å æ¥å¿</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent PostInterfaceRequest(string apiCode, string requestParameters, string remark, bool isAdd = true) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string response = string.Empty; |
| | | Dt_ApiInfo? apiInfo = null; |
| | | try |
| | | { |
| | | apiInfo = BaseDal.QueryFirst(x => x.ApiCode == apiCode) ?? throw new Exception($"æªæ¾å°{remark}æ¥å£é
置信æ¯ï¼è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | response = HttpHelper.Post(apiInfo.ApiAddress, requestParameters); |
| | | if (apiInfo.Remark.Contains("åå车")) |
| | | { |
| | | FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>(); |
| | | if (fOURBOTReturn == null) throw new Exception($"{apiInfo.Remark}ååºå
容转æ¢å®ä½å¤±è´¥ï¼"); |
| | | if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg); |
| | | content.Data = fOURBOTReturn; |
| | | } |
| | | else if (apiInfo.Remark.Contains("å¯ä¹å£«")) |
| | | { |
| | | |
| | | } |
| | | else if (apiInfo.Remark.Contains("海康")) |
| | | { |
| | | |
| | | } |
| | | else if (apiInfo.Remark.Contains("WMS")) |
| | | { |
| | | |
| | | } |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | if (isAdd && !string.IsNullOrEmpty(response) && apiInfo != null) |
| | | { |
| | | Dt_InterfaceLog interfaceLog = new Dt_InterfaceLog() |
| | | { |
| | | ApiCode = apiCode, |
| | | RequestParameters = requestParameters, |
| | | ApiAddress = apiInfo.ApiAddress, |
| | | ApiName = apiInfo.ApiName, |
| | | PushFrequency = 1, |
| | | PushState = content.Status ? 1 : 2, |
| | | Requestor = "WCS", |
| | | Recipient = apiInfo.Remark, |
| | | ResponseParameters = response, |
| | | Creater = "System", |
| | | Remark = content.Status ? remark : content.Message, |
| | | }; |
| | | _interfaceLogService.Repository.AddData(interfaceLog); |
| | | } |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |