Kaynağa Gözat

流水接口访问。

tangdi 3 yıl önce
ebeveyn
işleme
5912f024bd

+ 20 - 77
MicroServices/Business/Business.Application/ResourceExamineManagement/SerialNumberAppService.cs

@@ -1,17 +1,21 @@
-using Bussiness.Model.SystemData;
+using Business.Core.Utilities;
+using Bussiness.Model.SystemData;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json.Linq;
 using System;
+using System.Configuration;
+using System.Net.Http;
 using System.Text.RegularExpressions;
 using Volo.Abp.Application.Services;
 using Volo.Abp.Domain.Repositories;
+using Volo.Abp.Modularity;
 
 namespace Business.ResourceExamineManagement
 {
     public class SerialNumberAppService : ApplicationService, ISerialNumberAppService
     {
-        private readonly IRepository<sys_serial_number, long> _sys_serial_number;
-
-        public SerialNumberAppService(IRepository<sys_serial_number, long> sys_serial_number) {
-            _sys_serial_number = sys_serial_number;
+        public SerialNumberAppService() {
         }
 
         /// <summary>
@@ -22,81 +26,20 @@ namespace Business.ResourceExamineManagement
         /// <exception cref="NotImplementedException"></exception>
         public string GetSerialNumber(long id)
         {
-            var model = Get(id);
-            if (model == null)
-            {
-                return string.Empty;
-            }
-            int max = model.current_number + 1;
-            var date = DateTime.Now;
-            var lastDate = model.last_time;
-            switch (model.number_type)
+            string sn = string.Empty;
+            if (id > long.MinValue)
             {
-                case 1: //年流水
-                    if (date.Year > lastDate.Year)
-                    {
-                        max = 1;
-                    }
-                    break;
-                case 2: //月流水
-                    if (date.Year > lastDate.Year || date.Month > lastDate.Month)
-                    {
-                        max = 1;
-                    }
-                    break;
-                case 3: //日流水
-                    if (date.Year > lastDate.Year || date.Month > lastDate.Month || date.Day > lastDate.Day)
-                    {
-                        max = 1;
-                    }
-                    break;
+                IConfiguration configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build();
+                var tfSite = configuration["appSettings:ThinkFlow"];
+                string url = tfSite + "/ThinkFlowApi/SerialNumber/GetMaxSerialNumber?id=" + id.ToString();
+                /*JObject jobect = new() {
+                    { "id", id }
+                };
+                string postJson = jobect.ToString();*/
+                string json = HttpHelper.HttpPost(url, "");
+                sn = json;
             }
-            model.last_time = date;
-            model.current_number = max;
-            string number = max.ToString().PadLeft(model.number_size, '0');
-            string sn = model.format;
-            sn = Replace(sn);
-            if (sn.Contains("{number}"))
-            {
-                sn = Regex.Replace(sn, "{number}", number);
-            }
-            Update(model);
             return sn;
         }
-
-        /// <summary>
-        /// 获取流水号规则配置信息
-        /// </summary>
-        /// <param name="id"></param>
-        /// <returns></returns>
-        private sys_serial_number Get(long id)
-        {
-            return _sys_serial_number.FindAsync(id).Result;
-        }
-
-        /// <summary>
-        /// 替换通配符
-        /// </summary>
-        private string Replace(string str)
-        {
-            if (str.Contains("{DateTime<"))
-            {
-                string key = str.Substring(str.IndexOf("{DateTime<") + 10);
-                string key1 = key.Substring(0, key.IndexOf(">}"));
-                if (!string.IsNullOrWhiteSpace(key1))
-                {
-                    string newChar = DateTime.Now.ToString(key1);
-                    string old = "{DateTime<" + key1 + ">}";
-                    return str.Replace(old, newChar);
-                }
-            }
-            return str;
-        }
-
-        public void Update(sys_serial_number model)
-        {
-            _sys_serial_number.UpdateAsync(model);
-        }
-
     }
 }

+ 59 - 0
MicroServices/Business/Business.Core/Utilities/HttpHelper.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Core.Utilities
+{
+    public class HttpHelper
+    {
+        public static string HttpGet(string url, Dictionary<string, string>? headers = null)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (var header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            try
+            {
+                byte[] resultBytes = client.GetByteArrayAsync(url).Result;
+                return Encoding.UTF8.GetString(resultBytes);
+            }
+            catch
+            {
+                return string.Empty;
+            }
+        }
+
+        public static string HttpPost(string url, string postData, Dictionary<string, string>? headers = null, string contentType = "", int timeout = 0, Encoding? encoding = null)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (var header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8);
+            if (!string.IsNullOrWhiteSpace(contentType))
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            try
+            {
+                using HttpResponseMessage responseMessage = client.PostAsync(url, content).Result;
+                byte[] resultBytes = responseMessage.Content.ReadAsByteArrayAsync().Result;
+                return Encoding.UTF8.GetString(resultBytes);
+            }
+            catch
+            {
+                return string.Empty;
+            }
+        }
+    }
+}

+ 0 - 1
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContext.cs

@@ -105,7 +105,6 @@ namespace Business.EntityFrameworkCore
         public DbSet<sys_shift_schedule> sys_shift_schedule { get; set; }
         public DbSet<sys_staff> sys_staff { get; set; }
         public DbSet<sys_upload> sys_upload { get; set; }
-        public DbSet<sys_serial_number> sys_serial_number { get; set; }
         #endregion
 
         #region Tech

+ 3 - 0
MicroServices/Business/Business.Host/appsettings.json

@@ -35,5 +35,8 @@
   "Hangfire": {
     "Login": "admin",
     "Password": "abc123"
+  },
+  "appSettings": {
+    "ThinkFlow": "http://localhost:21407"
   }
 }

+ 0 - 58
MicroServices/Business/Bussiness.Model/SystemData/sys_serial_number.cs

@@ -1,58 +0,0 @@
-using Business.Core.Attributes;
-using Business.Model;
-using Microsoft.EntityFrameworkCore;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Bussiness.Model.SystemData
-{
-    /// <summary>
-    /// 流水号配置管理表
-    /// </summary>
-    [CollectionName("dopbiz", "sys_serial_number")]
-    [Comment("采购订单明细详情")]
-    public class sys_serial_number : BaseEntity
-    {
-        /// <summary>
-		/// 标题
-		/// </summary>
-        [StringLength(80)]
-        [Comment("标题")]
-        public string? title { get; set; }
-
-        /// <summary>
-        /// 格式
-        /// </summary>
-        [StringLength(200)]
-        [Comment("格式")]
-        public string? format { get; set; }
-
-        /// <summary>
-        /// 位数
-        /// </summary>
-        [Comment("位数")]
-        public int number_size { get; set; }
-
-        /// <summary>
-        /// 当前值
-        /// </summary>
-        [Comment("当前值")]
-        public int current_number { get; set; }
-
-        /// <summary>
-        /// 类型 0:不重置 1:年流水 2:月流水 3:日流水
-        /// </summary>
-        [Comment("类型")]
-        public int number_type { get; set; }
-
-        /// <summary>
-        /// 最后更新日期
-        /// </summary>
-        [Comment("最后更新日期")]
-        public DateTime last_time { get; set; }
-    }
-}