CustomSyncData.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Threading.Tasks;
  2. using ZhonTai.Admin.Domain.DictType;
  3. using ZhonTai.Admin.Domain.Dict;
  4. using ZhonTai.Admin.Domain.Api;
  5. using ZhonTai.Admin.Domain.Permission;
  6. using ZhonTai.Admin.Domain.User;
  7. using ZhonTai.Admin.Domain.Role;
  8. using ZhonTai.Admin.Domain.UserRole;
  9. using ZhonTai.Admin.Domain.RolePermission;
  10. using ZhonTai.Admin.Domain.Tenant;
  11. using ZhonTai.Admin.Domain.TenantPermission;
  12. using ZhonTai.Admin.Domain.PermissionApi;
  13. using ZhonTai.Admin.Domain.View;
  14. using ZhonTai.Admin.Core.Configs;
  15. using ZhonTai.Admin.Domain.Org;
  16. using ZhonTai.Admin.Domain.UserStaff;
  17. using ZhonTai.Admin.Core.Db.Data;
  18. using ZhonTai.Admin.Domain.UserOrg;
  19. using System.Linq;
  20. using ZhonTai.Common.Extensions;
  21. namespace ZhonTai.Admin.Repositories;
  22. public class CustomSyncData : SyncData, ISyncData
  23. {
  24. public virtual async Task SyncDataAsync(IFreeSql db, DbConfig dbConfig = null, AppConfig appConfig = null)
  25. {
  26. using var uow = db.CreateUnitOfWork();
  27. using var tran = uow.GetOrBeginTransaction();
  28. var isTenant = appConfig.Tenant;
  29. var dictionaryTypes = GetData<DictTypeEntity>(path: dbConfig.SyncDataPath);
  30. await InitDataAsync(db, uow, tran, dictionaryTypes, dbConfig);
  31. var dictionaries = GetData<DictEntity>(path: dbConfig.SyncDataPath);
  32. await InitDataAsync(db, uow, tran, dictionaries, dbConfig);
  33. var users = GetData<UserEntity>(isTenant, dbConfig.SyncDataPath);
  34. await InitDataAsync(db, uow, tran, users, dbConfig);
  35. var staffs = GetData<UserStaffEntity>(isTenant, dbConfig.SyncDataPath);
  36. await InitDataAsync(db, uow, tran, staffs, dbConfig);
  37. var orgTree = GetData<OrgEntity>(isTenant, dbConfig.SyncDataPath);
  38. await InitDataAsync(db, uow, tran, orgTree.ToList().ToPlainList((a) => a.Childs).ToArray(), dbConfig);
  39. var roles = GetData<RoleEntity>(isTenant, dbConfig.SyncDataPath);
  40. await InitDataAsync(db, uow, tran, roles, dbConfig);
  41. var apiTree = GetData<ApiEntity>(path: dbConfig.SyncDataPath);
  42. await InitDataAsync(db, uow, tran, apiTree.ToList().ToPlainList((a) => a.Childs).ToArray(), dbConfig);
  43. var viewTree = GetData<ViewEntity>(path: dbConfig.SyncDataPath);
  44. await InitDataAsync(db, uow, tran, viewTree.ToList().ToPlainList((a) => a.Childs).ToArray(), dbConfig);
  45. var permissionTree = GetData<PermissionEntity>(path: dbConfig.SyncDataPath);
  46. await InitDataAsync(db, uow, tran, permissionTree.ToList().ToPlainList((a) => a.Childs).ToArray(), dbConfig);
  47. var userRoles = GetData<UserRoleEntity>(path: dbConfig.SyncDataPath);
  48. await InitDataAsync(db, uow, tran, userRoles, dbConfig);
  49. var userOrgs = GetData<UserOrgEntity>(path: dbConfig.SyncDataPath);
  50. await InitDataAsync(db, uow, tran, userOrgs, dbConfig);
  51. var rolePermissions = GetData<RolePermissionEntity>(path: dbConfig.SyncDataPath);
  52. await InitDataAsync(db, uow, tran, rolePermissions, dbConfig);
  53. var tenants = GetData<TenantEntity>(path: dbConfig.SyncDataPath);
  54. await InitDataAsync(db, uow, tran, tenants, dbConfig);
  55. var tenantPermissions = GetData<TenantPermissionEntity>(path: dbConfig.SyncDataPath);
  56. await InitDataAsync(db, uow, tran, tenantPermissions, dbConfig);
  57. var permissionApis = GetData<PermissionApiEntity>(path: dbConfig.SyncDataPath);
  58. await InitDataAsync(db, uow, tran, permissionApis, dbConfig);
  59. uow.Commit();
  60. }
  61. }