| ¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using Kingdee.CDP.WebApi.SDK; |
| | | using MES.Service.Models; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto; |
| | | using NewPdaSqlServer.entity; |
| | | using NewPdaSqlServer.util; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using SqlSugar; |
| | | using System.Text; |
| | | |
| | | namespace MES.Service.service.Warehouse; |
| | | |
| | | |
| | | public class MesSuppScManager : Repository<MesSuppSc> |
| | | { |
| | | private const string SourceUrl = "https://qixizhaopin.modaniot.com:8443/wetchat/ToGSMesServlet?password=gsmes"; |
| | | |
| | | /// <summary> |
| | | /// 仿å®ç½å读å JSON æ°æ®å¹¶ä¿åå° MES_SUPPSCORE 表 |
| | | /// </summary> |
| | | public bool FetchAndSaveFromUrl() |
| | | { |
| | | string json; |
| | | try |
| | | { |
| | | using var http = new HttpClient(); |
| | | // 坿 ¹æ®éè¦è®¾ç½®è¶
æ¶ |
| | | http.Timeout = TimeSpan.FromSeconds(30); |
| | | json = http.GetStringAsync(SourceUrl).Result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"è·åè¿ç¨æ°æ®å¤±è´¥: {ex.Message}", ex); |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(json)) |
| | | throw new Exception("è¿ç¨è¿åå
容为空"); |
| | | |
| | | JToken root; |
| | | try |
| | | { |
| | | root = JToken.Parse(json); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"è§£æ JSON 失败: {ex.Message}"); |
| | | } |
| | | |
| | | var data = root["data"] as JArray; |
| | | if (data == null || data.Count == 0) |
| | | throw new Exception("JSON 䏿ªå
å« data æ data 为空"); |
| | | |
| | | var list = new List<MesSuppSc>(); |
| | | foreach (var item in data) |
| | | { |
| | | var rq = item["rq"]?.ToString(); |
| | | var gysmc = item["gysmc"]?.ToString(); |
| | | var zf = item["zf"]?.ToString(); |
| | | |
| | | decimal? zfDec = null; |
| | | if (!string.IsNullOrWhiteSpace(zf) && decimal.TryParse(zf, out var tmp)) |
| | | zfDec = tmp; |
| | | |
| | | list.Add(new MesSuppSc |
| | | { |
| | | ID = Guid.NewGuid(), |
| | | SuppDate = rq, |
| | | SuppName = gysmc, |
| | | SuppNum = zfDec |
| | | }); |
| | | } |
| | | |
| | | // åå
¥æ°æ®åºï¼å
æ¸
空表åæå
¥ï¼æåé»è¾ï¼ |
| | | var result = UseTransaction(db => |
| | | { |
| | | // 注æï¼è¿é使ç¨ä¼ å
¥ç dbï¼SqlSugarScopeï¼æ§è¡ååæä½ |
| | | db.Deleteable<MesSuppSc>().ExecuteCommand(); |
| | | var inserted = db.Insertable(list).ExecuteCommand(); |
| | | return inserted > 0 ? 1 : 0; |
| | | }) > 0; |
| | | |
| | | return result; |
| | | } |
| | | } |