lihao vor 4 Jahren
Ursprung
Commit
0a2eeb65ce

+ 3 - 1
gx_api/GxPress/Model/GxPress.Result/Notice/NoticeReadListResult.cs

@@ -1,3 +1,5 @@
+using System;
+
 namespace GxPress.Result.Notice
 {
     /// <summary>
@@ -30,6 +32,6 @@ namespace GxPress.Result.Notice
         /// 时间
         /// </summary>
         /// <value></value>
-        public string LastModifiedDate{get;set;}
+        public DateTime LastModifiedDate{get;set;}
     }
 }

+ 25 - 26
gx_api/GxPress/Repository/GxPress.Repository.Implement/AddresseeRepository.cs

@@ -96,31 +96,28 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<IEnumerable<NoticeReadListResult>> GetNoticeAddresseeByUserIdIdAsync(NoticeReadListRequest request)
         {
-            var sqlValue = "";
-            if (request.ReadType == 1)
-                sqlValue += " and a.IsRead=1";
-            else if (request.ReadType == 2)
-                sqlValue += " and a.IsRead=0";
-            if (request.SourceType > 0)
-                sqlValue += $" and a.SourceType={request.SourceType}";
-            if (!string.IsNullOrWhiteSpace(request.Key))
-                sqlValue += $" and b.Name like '%{request.Key}%'";
-            var sql = $"SELECT a.*,b.Name,b.AvatarUrl,c.Name FROM tede_addressee a inner join tede_user b on a.UserId=b.Id inner join tede_department c on c.Id=b.DepartmentId where a.SourceId={request.NoticeId} {sqlValue} order by a.LastModifiedDate desc";
-            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
-            var database = new Database(databaseType, _connectionString);
-            var connection = database.GetConnection();
-            var items = await connection
-                .QueryAsync<NoticeReadListResult, User, Department, NoticeReadListResult>(sql,
-                    (noticeReadListResult, user, department) =>
-                    {
-                        noticeReadListResult.Name = user != null ? user.Name : "";
-                        noticeReadListResult.AvatarUrl = user != null ? StringUtils.AddDomainMin(user.AvatarUrl) : "";
-                        noticeReadListResult.DepartmentName = department.Name;
-                        noticeReadListResult.LastModifiedDate = Convert.ToDateTime(noticeReadListResult.LastModifiedDate).ToString("yyyy-MM-dd HH:mm:ss");
-                        return noticeReadListResult;
-                    },
-                    splitOn: "Name,Name");
-            return items;
+           var query = new SqlKata.Query("tede_addressee");
+            query.Join("tede_user as b", "b.Id", "tede_addressee.UserId");
+            query.Where("tede_addressee.SourceId", request.NoticeId);
+            if (!string.IsNullOrEmpty(request.Key))
+                query.WhereLike("b.Name", $"%{request.Key}%");
+            if (request.ReadType > 0)
+                query.Where("tede_addressee.IsRead", request.ReadType == 1);
+            query.OrderByDesc("tede_addressee.LastModifiedDate");
+            var departmentNameQuery = new SqlKata.Query("tede_department");
+            var departmentIdsQuery = new SqlKata.Query("tede_department_user");
+            departmentIdsQuery.WhereColumns("tede_department_user.userId", "=", "tede_addressee.UserId");
+            departmentIdsQuery.Select("DepartmentId");
+            departmentNameQuery.WhereIn(nameof(Entity.Department.Id), departmentIdsQuery);
+            departmentNameQuery.Limit(1);
+            departmentNameQuery.Select("Name");
+            query.Select(departmentNameQuery, "DepartmentName");
+            query.Select("tede_addressee.{SourceId as NoticeId,LastModifiedDate,UserId}");
+            query.Select("b.{AvatarUrl,Name}");
+            var result = await _repository.GetAllAsync<NoticeReadListResult>(query);
+            foreach (var item in result)
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+            return result;
         }
         /// <summary>
         /// 获取收件人
@@ -167,9 +164,11 @@ namespace GxPress.Repository.Implement
             var query = new SqlKata.Query("tede_addressee");
             query.Join("tede_user as b", "b.Id", "tede_addressee.UserId");
             query.Where("tede_addressee.SourceId", request.MissiveId);
+            if (!string.IsNullOrEmpty(request.Key))
+                query.WhereLike("b.Name", $"%{request.Key}%");
             if (request.ReadType > 0)
                 query.Where("tede_addressee.IsRead", request.ReadType == 1);
-            //
+            query.OrderByDesc("tede_addressee.LastModifiedDate");
             var departmentNameQuery = new SqlKata.Query("tede_department");
             var departmentIdsQuery = new SqlKata.Query("tede_department_user");
             departmentIdsQuery.WhereColumns("tede_department_user.userId", "=", "tede_addressee.UserId");