Browse Source

添加行程单保存比较逻辑

yuanrf 1 week ago
parent
commit
b84224073e

+ 74 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -3,6 +3,7 @@ using Aspose.Cells.Charts;
 using Aspose.Words;
 using Aspose.Words.Drawing;
 using Aspose.Words.Tables;
+using DiffMatchPatch;
 using EyeSoft.Collections.Generic;
 using EyeSoft.IO;
 using Google.Protobuf.WellKnownTypes;
@@ -11327,6 +11328,10 @@ FROM
             {
                 try
                 {
+                    var travelList_DB = _sqlSugar.Queryable<Grp_TravelList>()
+                                                 .Where(x => dto.Arr.Select(x=>x.Id).Contains(x.Id))
+                                                 .ToList();
+
                     _sqlSugar.BeginTran();
                     foreach (var item in dto.Arr)
                     {
@@ -11335,6 +11340,15 @@ FROM
                             throw new Exception("请传入正确的Id");
                         }
 
+                        //比较上一次的差异
+                        var findTravel = travelList_DB.Find(x => x.Id == item.Id);
+                        if (findTravel != null)
+                        {
+                            item.Trip = item.Trip.Replace("[++]", string.Empty);
+                            findTravel.Trip = findTravel.Trip.Replace("[++]", string.Empty);
+                            item.Trip = CheckStr(findTravel.Trip,item.Trip);
+                        }
+
                         _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Id == item.Id)
                             .SetColumns(x => new Grp_TravelList
                             {
@@ -11358,6 +11372,63 @@ FROM
             return Ok(jw);
         }
 
+        private string CheckStr(string original, string changed)
+        {
+            // 创建diff_match_patch对象
+            var dmp = new diff_match_patch();
+
+            // 计算差异
+            List<Diff> diffs = dmp.diff_main(original, changed);
+
+            // 清理和合并差异
+            dmp.diff_cleanupSemantic(diffs);
+
+            // 使用StringBuilder构建最终的字符串
+            StringBuilder finalString = new StringBuilder();
+
+            // 输出差异结果,并构建变动后的字符串
+            foreach (Diff diff in diffs)
+            {
+                switch (diff.operation)
+                {
+                    case Operation.EQUAL:
+                        // 相等的部分,直接添加到最终字符串
+                        finalString.Append(diff.text);
+                        break;
+                    case Operation.INSERT:
+                        // 插入的部分,添加标记并添加到最终字符串
+                        finalString.Append("[++]" + diff.text + "[++]");
+                        break;
+                    case Operation.DELETE:
+                        // 删除的部分,不添加到最终字符串
+                        //finalString.Append("[++]" + diff.text + "[++]");
+                        break;
+                }
+            }
+
+            // 输出变动后的字符串
+            return finalString.ToString();
+        }
+
+        public class tagContent
+        {
+            public DateTime Date { get; set; }
+
+            public string StartTag { get; set; }
+
+            public string EndTag { get; set; }
+
+            public string Content { get; set; }
+
+            public static int tagLength { get { return 3; } }
+
+            public static Tuple<string, string> TagFormat { get { return new Tuple<string, string>("【#", "#】"); } }
+
+            public string QueryTag { get { return this.StartTag + this.EndTag; } }
+
+            public bool IsFinally { get; set; }
+
+        }
 
         /// <summary>
         /// 导出行程单
@@ -11430,6 +11501,9 @@ FROM
             //获取数据,放到datatable
             foreach (var item in _travelList)
             {
+
+                item.Trip = item.Trip.Replace(tagContent.TagFormat.Item1, string.Empty).Replace(tagContent.TagFormat.Item2, string.Empty);
+
                 DataRow dr = dtSource.NewRow();
                 dr["Days"] = item.Days;
                 dr["Date"] = item.Date;

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

@@ -36,6 +36,7 @@
     <PackageReference Include="CurlThin.Native" Version="0.0.8" />
     <PackageReference Include="EPPlus" Version="7.4.1" />
     <PackageReference Include="Flurl.Http" Version="3.2.4" />
+    <PackageReference Include="JsonDiffPatch.Net" Version="2.3.0" />
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />
     <PackageReference Include="NodaTime" Version="3.2.0" />
     <PackageReference Include="NPOI" Version="2.7.1" />