Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

wangh 1 year ago
parent
commit
b5b3d4d83d

+ 66 - 2
OASystem/OASystem.Api/Controllers/SmallFunController.cs

@@ -2,6 +2,8 @@
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
 using MySqlX.XDevAPI;
+using OASystem.API.OAMethodLib.ChatGPT;
+using OASystem.API.OAMethodLib.GoogleMapAPI;
 using OASystem.API.OAMethodLib.JuHeAPI;
 using OASystem.API.OAMethodLib.YouDaoAPI;
 using OASystem.Domain.Dtos.Groups;
@@ -13,6 +15,7 @@ using System.Buffers;
 using System.Collections.Generic;
 using System.Collections.Immutable;
 using System.Collections.Specialized;
+using System.Diagnostics;
 using System.Text.Json;
 using System.Text.Json.Nodes;
 using System.Transactions;
@@ -47,7 +50,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> GeRateCurrency()
+        public async Task<IActionResult> GetCurrencys()
         {
             var rateCurrencyData = AppSettingsHelper.Get<RateCurrencyModel>("RateCurrency");
 
@@ -61,7 +64,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> GeExchangeRate(ExchangeRateDto rateDto)
+        public async Task<IActionResult> GetCurrencyExchange(ExchangeRateDto rateDto)
         {
             #region 参数处理
             if (string.IsNullOrEmpty(rateDto.CurrencyCodePer) || string.IsNullOrEmpty(rateDto.CurrencyCodeSuf))
@@ -144,5 +147,66 @@ namespace OASystem.API.Controllers
 
         #endregion
 
+        #region googleMapApi 
+
+        /// <summary>
+        /// googleMapApi 获取距离And时间
+        /// </summary>
+        /// <param name="dto">
+        /// 请求参数默认值
+        /// origin:"FERİT RECAİ ERTUĞRUL CAD. NO: 18 ORAN / ANKARA,Turkey"; 
+        /// destination : "Dudullu Mh. Imes Sanayi Sitesi 504. Sk. No:4/B1 Umraniye/Istanbul";
+        /// </param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GetGooglMapForeignAndTime(GoogleMapDirectionsDto dto)
+        {
+            var data = await GoogleMapTools.GetForeignAndTime(dto.origin,dto.destination);
+
+            if (data == null || data.Code != 0)
+            {
+                return Ok(JsonView(false, data.Msg));
+            }
+
+            return Ok(JsonView(data.Data));
+        }
+
+        #endregion
+
+        #region ChatGPT
+
+        /// <summary>
+        /// ChatGPT 自动补全
+        /// </summary>
+        /// <param name="dto"> </param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> ChatGptCompletions(CompletionsDto dto)
+        {
+            if (string.IsNullOrEmpty(dto.Prompt)) 
+            {
+                return Ok(JsonView(false,"待自动补全的文本为空!"));
+            }
+
+            Stopwatch sw = new Stopwatch();
+            sw.Start();
+            Thread.Sleep(999);
+            Console.WriteLine($"程序耗时:{sw.ElapsedMilliseconds}ms.");
+
+            var data = await ChatGPTTools.Completions(dto.Prompt);
+
+            sw.Stop();
+            if (data == null || data.Code != 0)
+            {
+                return Ok(JsonView(false, data.Msg+"【耗时:"+ sw.ElapsedMilliseconds/1000+ "ms】"));
+            }
+
+            return Ok(JsonView(200,  "【耗时:"+ sw.ElapsedMilliseconds/1000 + "s】", data.Data));
+        }
+
+
+        #endregion
     }
 }

+ 74 - 0
OASystem/OASystem.Api/OAMethodLib/ChatGPT/ChatGPTTools.cs

@@ -0,0 +1,74 @@
+using Microsoft.AspNetCore.Http;
+using OASystem.Domain;
+using OpenAI.GPT3.Managers;
+using OpenAI.GPT3;
+using Org.BouncyCastle.Ocsp;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using OpenAI.GPT3.ObjectModels.RequestModels;
+using OpenAI.GPT3.ObjectModels;
+using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
+using System.IO;
+
+namespace OASystem.API.OAMethodLib.ChatGPT
+{
+    /// <summary>
+    /// ChatGPT 3.5
+    /// </summary>
+    public static class ChatGPTTools
+    {
+        private readonly static string _appKey = "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";
+        private readonly static HttpClient _httpClient = new HttpClient { BaseAddress = new Uri("https://api.openai.com") };
+
+
+        /// <summary>
+        /// ChatGPT - Completions 自动补全
+        /// </summary>
+        /// <param name="prompt">提示(问题)</param>
+        /// <returns></returns>
+        public static async Task<Result> Completions(string prompt)
+        {
+            var result = new Result();
+
+            string url = string.Format("{0}", "/v1/completions");
+            var reqData = new CompletionCreateRequest()
+            {
+                Prompt = prompt,     //提示(问题) 你向API提供的提示,即你提出的问题
+                Temperature = 0.3f,  //创新采样 取值范围0-1,当设置为0时,对于相同的问题,模型始终返回相同或者相近的结果,
+                                     //设置1则与上次的回答更加不同。默认1
+                TopP =1f,            //默认1。替代temperature使用,考虑了模型质量,0.1为生成结果的质量为10%,建议使用1。
+                N = 1,               //默认1。针对提示所生成结果的次数,会大量消耗令牌。
+                Stream = false,      //默认false。是否以流式返回部分进度,流完成后会发送终止消息data:[DONE]
+                Echo = false,        //默认false,在返回结果外,还显示用户给的问题
+                //Stop = "",           //最多四个序列,返回的文本不包括停止序列
+                MaxTokens = 1024,    //默认16,大多数模型支持最大为204
+            };
+
+            return await PostChatGPT(url, reqData);
+        }
+
+        /// <summary>
+        /// post 访问 
+        /// </summary>
+        /// <param name="url">接口路径</param>
+        /// <param name="formData">请求参数</param>
+        /// <returns></returns>
+        public static async Task<Result> PostChatGPT(string url, CompletionCreateRequest reqData)
+        {
+            Result result = new Result();
+
+            OpenAIService service = new OpenAIService(new OpenAiOptions() { ApiKey = _appKey });
+
+            var res = await service.Completions.CreateCompletion(reqData, Models.TextDavinciV3);
+
+            if (res.Successful)
+            {
+                result.Code = 0;
+                result.Data =  new { Text = res.Choices.FirstOrDefault().Text };
+            }
+            else result.Msg = "访问失败!";
+
+            return result;
+        }
+    }
+}

+ 73 - 0
OASystem/OASystem.Api/OAMethodLib/GoogleMapAPI/GoogleMapTools.cs

@@ -0,0 +1,73 @@
+using OASystem.Domain.ViewModels.JuHeExchangeRate;
+using OASystem.Domain.ViewModels.SmallFun;
+using System.Text.Json;
+
+namespace OASystem.API.OAMethodLib.GoogleMapAPI
+{
+    /// <summary>
+    /// 谷歌地图API
+    /// </summary>
+    public static class GoogleMapTools
+    {
+        private static string _appKey = "AIzaSyBdLf8u8DinXQWVPLEkdrxOJpClXSqEnho"; //谷歌地图AppKey
+        private static readonly HttpClient _httpClient = new HttpClient { BaseAddress = new Uri("https://maps.googleapis.com") };
+
+        /// <summary>
+        /// googleMapApi 获取距离And时间
+        /// </summary>
+        /// <param name="origin"></param>
+        /// <param name="destination"></param>
+        /// <returns></returns>
+        public static async Task<Result> GetForeignAndTime(string origin, string destination) 
+        {
+            var result = new Result() { Code = -2, Msg = "未知错误" };
+            if (string.IsNullOrEmpty(origin) || string.IsNullOrEmpty(destination))
+            {
+                result.Msg= "起始地或目的地为空";
+                return result;
+            }
+
+            string url = string.Format(@"/maps/api/directions/json?origin={0}&destination={1}&key={2}", origin, destination,_appKey);
+
+            var req = await _httpClient.GetAsync(url);
+
+            if (req.IsSuccessStatusCode) {
+                var strResponse = await req.Content.ReadAsStringAsync();
+                var resultData = System.Text.Json.JsonSerializer.Deserialize<GoogleMapResultView>(strResponse,
+                        new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
+
+                if (resultData.Status == "OK") 
+                {
+                    if (resultData.Routes == null)
+                    {
+                        result.Msg = resultData.Status;
+                        return result;
+                    }
+
+                    var data =  JsonConvert.DeserializeObject<dynamic>( resultData.Routes.ToJson());
+
+                    var dataView = new DistanceAndTimeView {
+                        DistanceText = data[0]["legs"][0]["distance"]["text"].ToString(),
+                        DistanceValue = data[0]["legs"][0]["distance"]["value"],
+                        DurationText = data[0]["legs"][0]["duration"]["text"].ToString(),
+                        DurationValue = data[0]["legs"][0]["duration"]["value"],
+                    };
+
+
+                    result.Code = 0;
+                    result.Data = dataView;
+                }
+                else
+                {
+                    result.Msg = resultData.Status;
+                }
+
+            }
+            else
+            {
+                result.Msg = "GoogleMapApi接口网络异常链接超时";
+            }
+            return result;
+        }
+    }
+}

+ 1 - 1
OASystem/OASystem.Api/OASystem.API.csproj

@@ -24,7 +24,7 @@
     <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
     <PackageReference Include="AutoMapper" Version="12.0.0" />
     <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
-    <PackageReference Include="Betalgo.OpenAI.GPT3" Version="6.6.7" />
+    <PackageReference Include="Betalgo.OpenAI.GPT3" Version="6.8.3" />
     <PackageReference Include="BouncyCastle.NetCore" Version="1.8.8" />
     <PackageReference Include="Flurl.Http" Version="3.2.4" />
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />

+ 19 - 0
OASystem/OASystem.Domain/Dtos/SmallFun/ChatGptDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.SmallFun
+{
+    /// <summary>
+    /// ChatGPT 自动补全 请求dto
+    /// </summary>
+    public class CompletionsDto
+    {
+        /// <summary>
+        /// 提示(问题)
+        /// </summary>
+        public string? Prompt { get; set; }
+    }
+}

+ 31 - 0
OASystem/OASystem.Domain/Dtos/SmallFun/GoogleMapApiDto.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.SmallFun
+{
+    /// <summary>
+    /// googleMapApi
+    /// </summary>
+    internal class GoogleMapApiDto
+    {
+    }
+
+    /// <summary>
+    /// google 路线查询
+    /// </summary>
+    public class GoogleMapDirectionsDto
+    {
+        /// <summary>
+        /// 起始地
+        /// </summary>
+        public string? origin { get; set; } = "FERİT RECAİ ERTUĞRUL CAD. NO: 18 ORAN / ANKARA,Turkey"; //默认值 
+
+        /// <summary>
+        /// 目的地
+        /// </summary>
+        public string? destination { get; set; } = "Dudullu Mh. Imes Sanayi Sitesi 504. Sk. No:4/B1 Umraniye/Istanbul";
+    }
+}

+ 233 - 0
OASystem/OASystem.Domain/ViewModels/SmallFun/GoogleMapResultView.cs

@@ -0,0 +1,233 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.SmallFun
+{
+    /// <summary>
+    /// googleMapApi 返回试图
+    /// </summary>
+    public class GoogleMapResultView
+    {
+        /// <summary>
+        /// 地理编码路径点
+        /// </summary>
+        public object? Geocoded_waypoints { get; set; }
+
+        /// <summary>
+        /// 返回数据源
+        /// </summary>
+        public object? Routes { get; set; }
+
+        /// <summary>
+        /// 状态
+        /// </summary>
+        public string? Status { get; set; }
+    }
+
+    /// <summary>
+    /// 途径
+    /// </summary>
+    public class Routes
+    {
+        /// <summary>
+        /// 界标
+        /// </summary>
+        public Bounds? Bounds { get; set; }
+
+        /// <summary>
+        /// 版权保护
+        /// </summary>
+        public string? CopyRights { get; set; }
+    }
+
+    #region bounds 界标
+
+    /// <summary>
+    /// 界标
+    /// </summary>
+    public class Bounds {
+
+        /// <summary>
+        /// 东北方
+        /// </summary>
+        public Northeast? Northeast { get; set; }
+
+        /// <summary>
+        /// 西南方
+        /// </summary>
+        public Southwest? Southwest { get; set; }
+
+    }
+
+    /// <summary>
+    /// 东北方
+    /// </summary>
+    public class Northeast
+    {
+        /// <summary>
+        /// 纬度
+        /// </summary>
+        public string? Lat { get; set; }
+
+        /// <summary>
+        /// 经度
+        /// </summary>
+        public string Lng { get; set; }
+    }
+
+    /// <summary>
+    /// 西南方
+    /// </summary>
+    public class Southwest
+    {
+        /// <summary>
+        /// 纬度
+        /// </summary>
+        public string? Lat { get; set; }
+
+        /// <summary>
+        /// 经度
+        /// </summary>
+        public string Lng { get; set; }
+    }
+    #endregion
+
+    #region leg
+   
+    /// <summary>
+    /// Leg
+    /// </summary>
+    public class Leg
+    {
+        /// <summary>
+        /// 距离
+        /// </summary>
+        public TextValue? Distance { get; set; }
+
+        /// <summary>
+        /// 时长
+        /// </summary>
+        public TextValue? Duration { get; set; }
+
+        /// <summary>
+        /// 结束地址
+        /// </summary>
+        public string? End_address { get; set; }
+
+        /// <summary>
+        /// 结束地址经纬度
+        /// </summary>
+        public LatLng? End_location { get; set; }
+
+        /// <summary>
+        /// 开始地址
+        /// </summary>
+        public string? Start_address { get; set; }
+
+        /// <summary>
+        /// 开始地址经纬度
+        /// </summary>
+        public LatLng? Start_location { get; set; }
+        
+        /// <summary>
+        /// Step
+        /// </summary>
+        public List<Step>? Steps { get; set; }
+
+
+    }
+
+
+    /// <summary>
+    /// Step
+    /// </summary>
+    public class Step
+    {
+        /// <summary>
+        /// 距离
+        /// </summary>
+        public TextValue? Distance { get; set; }
+
+        /// <summary>
+        /// 耗时
+        /// </summary>
+        public TextValue? Duration { get; set; }
+
+        /// <summary>
+        /// 结束经纬度
+        /// </summary>
+        public LatLng? End_location { get; set; }
+
+        /// <summary>
+        /// html指令
+        /// </summary>
+        public string? Html_instructions { get; set; }
+
+        /// <summary>
+        /// 多线
+        /// </summary>
+        public Polyline? Polyline { get; set; }
+
+        /// <summary>
+        /// 开始经纬度
+        /// </summary>
+        public LatLng? Start_location { get; set; }
+
+        /// <summary>
+        /// 出行方式
+        /// </summary>
+        public string? Travel_mode { get; set; }
+    }
+
+
+    /// <summary>
+    /// 多线
+    /// </summary>
+    public class Polyline 
+    {
+        /// <summary>
+        /// 目的
+        /// </summary>
+        public string? Points { get; set; }
+    }
+
+    /// <summary>
+    /// 文本值
+    /// </summary>
+    public class TextValue
+    {
+        /// <summary>
+        /// 文本
+        /// </summary>
+        public string? Text { get; set; }
+
+        /// <summary>
+        /// 值
+        /// </summary>
+        public int Value { get; set; }
+    }
+
+    /// <summary>
+    /// 经纬度值
+    /// </summary>
+    public class LatLng 
+    {
+        /// <summary>
+        /// 纬度
+        /// </summary>
+        public string? Lat { get; set; }
+
+        /// <summary>
+        /// 经度
+        /// </summary>
+        public string Lng { get; set; }
+    }
+    
+    
+    
+    
+    #endregion
+}

+ 34 - 0
OASystem/OASystem.Domain/ViewModels/SmallFun/GoogleMapView.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.SmallFun
+{
+    /// <summary>
+    /// google地图 返回 时间and距离 View
+    /// </summary>
+    public class DistanceAndTimeView
+    {
+        /// <summary>
+        /// 时间文本
+        /// </summary>
+        public string? DurationText { get; set; }
+
+        /// <summary>
+        /// 时间值
+        /// </summary>
+        public int? DurationValue { get; set; }
+
+        /// <summary>
+        /// 距离文本
+        /// </summary>
+        public string? DistanceText { get; set; }
+
+        /// <summary>
+        /// 距离值
+        /// </summary>
+        public int? DistanceValue { get; set; }
+    }
+}

+ 1 - 1
OASystem/_Doc/OA2023数据字典.docx

@@ -531,7 +531,7 @@ Null
 是否由职位模板导入
 是否由职位模板导入
 
-9) 岗位权限表:Sys_JobPostAuthority(新增)
+9) 岗位权限表:(新增)
                                    字段名
                                  类型长度
                                  字段属性