| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Services.ApiServices.ArmtekApi; |
| | | 4 | | using Services.ApiServices.ApiSupplierRequestLog; |
| | | 5 | | |
| | | 6 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Консоль ручных вызовов Armtek Web-Services API — по одному GET-эндпоинту на каждый из |
| | | 10 | | /// 14 read-only методов <see cref="ArmtekDataManager"/>. Используется со страницы Index |
| | | 11 | | /// (AJAX-формы, JSON-результат отображается как есть) для проверки методов вживую без curl. |
| | | 12 | | /// </summary> |
| | | 13 | | [Authorize(Roles = "User,Admin")] |
| | | 14 | | [Area("Studio2")] |
| | | 15 | | [Route("Armtek/[action]")] |
| | | 16 | | public class ArmtekController : Controller |
| | | 17 | | { |
| | | 18 | | private readonly ArmtekDataManager _armtek; |
| | | 19 | | private readonly ApiSupplierRequestLogStore _logs; |
| | | 20 | | |
| | 0 | 21 | | public ArmtekController(ArmtekDataManager armtek, ApiSupplierRequestLogStore logs) |
| | | 22 | | { |
| | 0 | 23 | | _armtek = armtek; |
| | 0 | 24 | | _logs = logs; |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | [HttpGet] |
| | | 28 | | [Route("~/Armtek")] |
| | 0 | 29 | | public IActionResult Index() => View(); |
| | | 30 | | |
| | | 31 | | [HttpGet] |
| | 0 | 32 | | public IActionResult Logs() => Json(_logs.Get("Armtek")); |
| | | 33 | | |
| | | 34 | | // ---- ws_ping ---- |
| | | 35 | | |
| | | 36 | | [HttpGet] |
| | | 37 | | public async Task<IActionResult> Ping() |
| | | 38 | | { |
| | 0 | 39 | | try { return Json(await _armtek.PingAsync()); } |
| | 0 | 40 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | // ---- ws_user ---- |
| | | 44 | | |
| | | 45 | | [HttpGet] |
| | | 46 | | public async Task<IActionResult> GetUserVkorgList() |
| | | 47 | | { |
| | 0 | 48 | | try { return Json(await _armtek.GetUserVkorgListAsync()); } |
| | 0 | 49 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | [HttpGet] |
| | | 53 | | public async Task<IActionResult> GetUserInfo(string? vkorg, string? structure) |
| | | 54 | | { |
| | 0 | 55 | | try { return Json(await _armtek.GetUserInfoAsync(vkorg, ParseBool(structure) ?? true)); } |
| | 0 | 56 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | [HttpGet] |
| | | 60 | | public async Task<IActionResult> GetBrandList() |
| | | 61 | | { |
| | 0 | 62 | | try { return Json(await _armtek.GetBrandListAsync()); } |
| | 0 | 63 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | [HttpGet] |
| | | 67 | | public async Task<IActionResult> GetStoreList(string? vkorg) |
| | | 68 | | { |
| | 0 | 69 | | try { return Json(await _armtek.GetStoreListAsync(vkorg)); } |
| | 0 | 70 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 71 | | } |
| | | 72 | | |
| | | 73 | | // ---- ws_search ---- |
| | | 74 | | |
| | | 75 | | [HttpGet] |
| | | 76 | | public async Task<IActionResult> Search( |
| | | 77 | | string kunnrRg, string pin, string? brand, string? vkorg, |
| | | 78 | | string? queryType, string? program, string? kunnrZa, string? incoterms, string? vbeln) |
| | | 79 | | { |
| | | 80 | | try |
| | | 81 | | { |
| | 0 | 82 | | return Json(await _armtek.SearchAsync( |
| | 0 | 83 | | kunnrRg, pin, brand, vkorg, |
| | 0 | 84 | | ParseInt(queryType), program, kunnrZa, ParseBool(incoterms), vbeln)); |
| | | 85 | | } |
| | 0 | 86 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 87 | | } |
| | | 88 | | |
| | | 89 | | [HttpGet] |
| | | 90 | | public async Task<IActionResult> AssortmentSearch(string pin, string? vkorg, string? program) |
| | | 91 | | { |
| | 0 | 92 | | try { return Json(await _armtek.AssortmentSearchAsync(pin, vkorg, program)); } |
| | 0 | 93 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 94 | | } |
| | | 95 | | |
| | | 96 | | // ---- ws_order ---- |
| | | 97 | | |
| | | 98 | | [HttpGet] |
| | | 99 | | public async Task<IActionResult> GetOrder(string kunrg, string order, string? vkorg, string? edit) |
| | | 100 | | { |
| | 0 | 101 | | try { return Json(await _armtek.GetOrderAsync(kunrg, order, vkorg, ParseBool(edit))); } |
| | 0 | 102 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 103 | | } |
| | | 104 | | |
| | | 105 | | [HttpGet] |
| | | 106 | | public async Task<IActionResult> GetOrder2(string kunrg, string order, string? vkorg, string? detailedStatus) |
| | | 107 | | { |
| | 0 | 108 | | try { return Json(await _armtek.GetOrder2Async(kunrg, order, vkorg, ParseBool(detailedStatus) ?? true)); } |
| | 0 | 109 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 110 | | } |
| | | 111 | | |
| | | 112 | | [HttpGet] |
| | | 113 | | public async Task<IActionResult> GetRefund(string kunrg, string returnNumber, string? vkorg) |
| | | 114 | | { |
| | 0 | 115 | | try { return Json(await _armtek.GetRefundAsync(kunrg, returnNumber, vkorg)); } |
| | 0 | 116 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 117 | | } |
| | | 118 | | |
| | | 119 | | // ---- ws_invoice ---- |
| | | 120 | | |
| | | 121 | | [HttpGet] |
| | | 122 | | public async Task<IActionResult> GetInvoice( |
| | | 123 | | string kunrg, string? invoice, string? zzsf, string? vkorg, string? refundFlag, string? noCollapse) |
| | | 124 | | { |
| | | 125 | | try |
| | | 126 | | { |
| | 0 | 127 | | return Json(await _armtek.GetInvoiceAsync( |
| | 0 | 128 | | kunrg, invoice, zzsf, vkorg, ParseBool(refundFlag) ?? false, ParseBool(noCollapse))); |
| | | 129 | | } |
| | 0 | 130 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 131 | | } |
| | | 132 | | |
| | | 133 | | // ---- ws_reports ---- |
| | | 134 | | |
| | | 135 | | [HttpGet] |
| | | 136 | | public async Task<IActionResult> GetOrderReportByDate( |
| | | 137 | | string kunnrRg, string? vkorg, DateTime? createdFrom, DateTime? createdTo, |
| | | 138 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, string? currentL |
| | | 139 | | { |
| | | 140 | | try |
| | | 141 | | { |
| | 0 | 142 | | return Json(await _armtek.GetOrderReportByDateAsync( |
| | 0 | 143 | | kunnrRg, vkorg, createdFrom, createdTo, deliveryFrom, deliveryTo, |
| | 0 | 144 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly))); |
| | | 145 | | } |
| | 0 | 146 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 147 | | } |
| | | 148 | | |
| | | 149 | | [HttpGet] |
| | | 150 | | public async Task<IActionResult> GetOrderPositionsReportByDate( |
| | | 151 | | string kunnrRg, string? vkorg, DateTime? createdFrom, DateTime? createdTo, |
| | | 152 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, string? currentL |
| | | 153 | | { |
| | | 154 | | try |
| | | 155 | | { |
| | 0 | 156 | | return Json(await _armtek.GetOrderPositionsReportByDateAsync( |
| | 0 | 157 | | kunnrRg, vkorg, createdFrom, createdTo, deliveryFrom, deliveryTo, |
| | 0 | 158 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly))); |
| | | 159 | | } |
| | 0 | 160 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 161 | | } |
| | | 162 | | |
| | | 163 | | [HttpGet] |
| | | 164 | | public async Task<IActionResult> GetOrderPositionsReportByDate2( |
| | | 165 | | string kunnrRg, string? vkorg, DateTime? createdFrom, DateTime? createdTo, |
| | | 166 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, |
| | | 167 | | string? currentLoginOnly, string? rejectedOnly) |
| | | 168 | | { |
| | | 169 | | try |
| | | 170 | | { |
| | 0 | 171 | | return Json(await _armtek.GetOrderPositionsReportByDate2Async( |
| | 0 | 172 | | kunnrRg, vkorg, createdFrom, createdTo, deliveryFrom, deliveryTo, |
| | 0 | 173 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly), ParseBool(rejectedO |
| | | 174 | | } |
| | 0 | 175 | | catch (Exception ex) { return HandleError(ex); } |
| | 0 | 176 | | } |
| | | 177 | | |
| | | 178 | | // ---- helpers ---- |
| | | 179 | | |
| | | 180 | | private static bool? ParseBool(string? value) |
| | 0 | 181 | | => string.IsNullOrEmpty(value) ? null : value == "true"; |
| | | 182 | | |
| | | 183 | | private static int? ParseInt(string? value) |
| | 0 | 184 | | => int.TryParse(value, out var result) ? result : null; |
| | | 185 | | |
| | 0 | 186 | | private IActionResult HandleError(Exception ex) => ex switch |
| | 0 | 187 | | { |
| | 0 | 188 | | ArgumentException argEx => BadRequest(new { error = true, message = argEx.Message }), |
| | 0 | 189 | | ArmtekApiException apiEx => StatusCode(502, new { error = true, message = apiEx.Message, requestUri = apiEx. |
| | 0 | 190 | | _ => StatusCode(500, new { error = true, message = ex.Message }) |
| | 0 | 191 | | }; |
| | | 192 | | } |
| | | 193 | | } |