lihao 4 years ago
parent
commit
2af6904cb3

+ 8 - 4
gx_api/GxPress/Repository/GxPress.Repository.Implement/MiddleRepository.cs

@@ -146,6 +146,7 @@ namespace GxPress.Repository.Implement
             var databaseType = _databaseTypeStr.ToEnum<DatabaseType>(DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);
             var connection = database.GetConnection();
+            var lastModifiedDate = DateTime.Now.ToString();
             if (middleFirst.Sort < middleSecond.Sort)
             {
                 //修改第一个排序
@@ -153,7 +154,7 @@ namespace GxPress.Repository.Implement
                     .Where(nameof(Middle.Id), request.MiddleIdFirst));
                 int sort = middleSecond.Sort;
                 var sql =
-                    $"update tede_middle set Sort=Sort-1 where UserId={middleFirst.UserId} and FolderType={middleFirst.FolderType} and Sort<={sort} and Id not in({middleFirst.Id}) and id>0";
+                    $"update tede_middle set Sort=Sort-1,LastModifiedDate='{lastModifiedDate}' where UserId={middleFirst.UserId} and FolderType={middleFirst.FolderType} and Sort<={sort} and Id not in({middleFirst.Id}) and id>0";
                 return await connection.ExecuteAsync(sql) > 0;
             }
             else
@@ -163,7 +164,7 @@ namespace GxPress.Repository.Implement
                     .Where(nameof(Middle.Id), request.MiddleIdFirst));
                 int sort = middleSecond.Sort;
                 var sql =
-                    $"update tede_middle set Sort=Sort+1 where UserId={middleFirst.UserId} and FolderType={middleFirst.FolderType} and Sort>={sort} and Id not in({middleFirst.Id}) and id>0";
+                    $"update tede_middle set Sort=Sort+1,LastModifiedDate='{lastModifiedDate}' where UserId={middleFirst.UserId} and FolderType={middleFirst.FolderType} and Sort>={sort} and Id not in({middleFirst.Id}) and id>0";
                 return await connection.ExecuteAsync(sql) > 0;
             }
         }
@@ -181,10 +182,13 @@ namespace GxPress.Repository.Implement
             var databaseType = _databaseTypeStr.ToEnum<DatabaseType>(DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);
             var connection = database.GetConnection();
-            if (middle.IsTop == false)
-                return await _repository.UpdateAsync(Q.Set(nameof(Middle.IsTop), true).Where(nameof(Middle.Id), id)) > 0;
             var isTop = middle.IsTop == true ? 0 : 1;
             var sql = $"update tede_middle set IsTop={isTop},LastModifiedDate='{middle.CreatedDate.ToString()}' where id={id}";
+            if (middle.IsTop == false)
+            {
+                sql = $"update tede_middle set IsTop={isTop},LastModifiedDate=CreatedDate where id={id}";
+                return await connection.ExecuteAsync(sql) > 0;
+            }
             return await connection.ExecuteAsync(sql) > 0;
         }