From 53c7de340f55ab0c917a03d54d883b4a8082f42d Mon Sep 17 00:00:00 2001
From: cdk <2441919651@qq.com>
Date: 星期四, 27 十一月 2025 09:47:48 +0800
Subject: [PATCH] 增加通过网址获取供应商评分数据的接口

---
 entity/MesSuppSc.cs                          |   24 ++++++++
 Controllers/Warehouse/MesSuppScController.cs |   45 +++++++++++++++
 service/Warehouse/MesSuppScManager.cs        |   88 +++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+), 0 deletions(-)

diff --git a/Controllers/Warehouse/MesSuppScController.cs b/Controllers/Warehouse/MesSuppScController.cs
new file mode 100644
index 0000000..1024447
--- /dev/null
+++ b/Controllers/Warehouse/MesSuppScController.cs
@@ -0,0 +1,45 @@
+锘縰sing MES.Service.service.Kingdee;
+using MES.Service.service.Warehouse;
+using Microsoft.AspNetCore.Mvc;
+using NewPdaSqlServer.entity;
+using NewPdaSqlServer.util;
+using System.Dynamic;
+
+
+namespace NewPdaSqlServer.Controllers.Warehouse;
+
+
+[ApiController]
+[Route("api/[controller]")]
+public class MesSuppScController : ControllerBase
+{
+    private readonly MesSuppScManager kc = new();
+    private readonly string METHOD = "POST";
+    private readonly string TableName = "MES_SUPPSCORE";
+    private readonly string URL = "http://localhost:10054/api/ErpKc/";
+
+
+    //
+    [HttpPost("Save")]
+    public async Task<ResponseResult> Save()
+    {
+        try
+        {
+            // 浠庤繙绔鍙栧苟淇濆瓨
+            var ok = await Task.Run(() => kc.FetchAndSaveFromUrl());
+            if (!ok)
+                throw new Exception("淇濆瓨澶辫触锛氭棤鏁版嵁鎴栨彃鍏ユ暟鎹簱澶辫触");
+
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = (object)null
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+}
\ No newline at end of file
diff --git a/entity/MesSuppSc.cs b/entity/MesSuppSc.cs
new file mode 100644
index 0000000..69f87b8
--- /dev/null
+++ b/entity/MesSuppSc.cs
@@ -0,0 +1,24 @@
+锘縰sing SqlSugar;
+
+namespace NewPdaSqlServer.entity;
+
+[SugarTable("MES_SUPPSCORE")]
+public class MesSuppSc
+{
+    /// <summary>
+    ///     榛樿鍊�: (newid())
+    /// </summary>
+    [SugarColumn(ColumnName = "ID", IsPrimaryKey = true)]
+    public Guid ID { get; set; }
+
+    [SugarColumn(ColumnName = "SuppDate")]
+    public string? SuppDate { get; set; }
+
+    [SugarColumn(ColumnName = "SuppName")]
+    public string? SuppName { get; set; }
+
+    [SugarColumn(ColumnName = "SuppNum")]
+    public decimal? SuppNum { get; set; }
+
+
+}
diff --git a/service/Warehouse/MesSuppScManager.cs b/service/Warehouse/MesSuppScManager.cs
new file mode 100644
index 0000000..20e7b6d
--- /dev/null
+++ b/service/Warehouse/MesSuppScManager.cs
@@ -0,0 +1,88 @@
+锘�
+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($"瑙f瀽 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锛圫qlSugarScope锛夋墽琛屽師瀛愭搷浣�
+            db.Deleteable<MesSuppSc>().ExecuteCommand();
+            var inserted = db.Insertable(list).ExecuteCommand();
+            return inserted > 0 ? 1 : 0;
+        }) > 0;
+
+        return result;
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3