Browse Source

增强草稿数据导入验证及权限处理

在 `GroupsController.cs` 中,添加了对草稿数据创建者的验证,确保只有当草稿和正式数据的创建者相同时,才能将草稿数据导入正式数据。同时,增加了对 `Grp_EnterExitCostPermission` 的删除操作,以确保在导入新数据之前,相关权限数据被标记为删除。此外,添加了对权限和新数据的插入操作,确保在导入过程中处理所有相关数据。

在 `EnterExitCostDraftRepository.cs` 和 `EnterExitCostRepository.cs` 中,更新了查询条件,确保只选择未被删除的草稿和权限数据,以提高数据的准确性和一致性。
LEIYI 1 week ago
parent
commit
68a86c08d6

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

@@ -8834,6 +8834,39 @@ FROM
                     _sqlSugar.RollbackTran();
                     return Ok(JsonView(false, "草稿数据为空,不可导入!"));
                 }
+
+                //验证可覆盖已有数据 两边创建人需为同一人;
+                int draftCreateUserId = draftDatas.CreateUserId,
+                    formalCreateUserId = 0;
+
+                var formalData = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
+                if (formalData != null)
+                {
+                    formalCreateUserId = formalData.CreateUserId;
+
+                    if (draftCreateUserId != formalCreateUserId)
+                    {
+                        _sqlSugar.RollbackTran();
+                        return Ok(JsonView(false, "由草稿数据到入至正式数据,两边创建人为同一人才可导入正式版!"));
+                    }
+                }
+
+
+                var permissionUsers = await _enterExitCostRep.PermissionViewUsersAsync();
+                var userIds = permissionUsers.Select(x => x.Id).ToList();
+                var permissions = new List<Grp_EnterExitCostPermission>();
+                if (userIds.Any())
+                {
+                    foreach (var userId in userIds)
+                    {
+                        permissions.Add(new Grp_EnterExitCostPermission() { 
+                            GroupId = groupId,
+                            UserId = userId,
+                            CreateUserId = dto.UserId
+                        });
+                    }
+                }
+
                 var dayDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
                 var otherDatas = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
 
@@ -8867,6 +8900,11 @@ FROM
                        .SetColumns(x => new Grp_DayOtherPrice() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
                        .Where(x => x.Diid == groupId)
                        .ExecuteCommand();
+
+                    _sqlSugar.Updateable<Grp_EnterExitCostPermission>()
+                       .SetColumns(x => new Grp_EnterExitCostPermission() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
+                       .Where(x => x.GroupId == groupId)
+                       .ExecuteCommand();
                 }
 
                 //执行insert
@@ -8877,6 +8915,8 @@ FROM
                     return Ok(JsonView(false, "草稿数据导入失败!"));
                 }
 
+                if (permissions.Any()) _sqlSugar.Insertable(permissions).ExecuteCommand();
+
                 if (newDayDatas.Any()) _sqlSugar.Insertable(newDayDatas).ExecuteCommand();
 
                 if (newOtherDatas.Any()) _sqlSugar.Insertable(newOtherDatas).ExecuteCommand();

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostDraftRepository.cs

@@ -106,7 +106,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                     enterExitCostInfoView.ViewUsers = await _sqlSugar
                         .Queryable<Grp_EnterExitCostDraftPermission>()
-                        .Where(x => x.DraftId == id)
+                        .Where(x => x.IsDel == 0 && x.DraftId == id)
                         .Select(x => x.UserId)
                         .ToArrayAsync();
 

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostRepository.cs

@@ -139,7 +139,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                     enterExitCostInfoView.ViewUsers = await _sqlSugar
                         .Queryable<Grp_EnterExitCostPermission>()
-                        .Where(x => x.GroupId == dto.DiId)
+                        .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
                         .Select(x => x.UserId)
                         .ToArrayAsync();