Browse Source

迁移一期报表

dev
zhuibobo 2 months ago
parent
commit
47bf3a78b0
  1. 48
      script/sql/zfjd-refactoring-v1/014-初始化角色.sql
  2. 91
      zdxt-web-server/zdxt-admin-web-server/src/test/java/com/zdxt/service/test/InitVirtualUnitV2Test.java

48
script/sql/zfjd-refactoring-v1/014-初始化角色.sql

@ -15,30 +15,30 @@ INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_s
VALUES (1001, '000000', '查看本级和下级业务数据角色', 'ViewFilterDataRole', 2, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', 'roleKey不可修改', null, '1', null, null, null, '1');
-- 各区查看全部数据角色
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1002, '000000', '查看福田区全部数据角色', 'ViewEFDataRole_Area:Area_FuTianQu', 3, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '福田区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1003, '000000', '查看罗湖区全部数据角色', 'ViewEFDataRole_Area:Area_LuoHuQu', 4, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '罗湖区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1004, '000000', '查看盐田区全部数据角色', 'ViewEFDataRole_Area:Area_YanTianQu', 5, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '盐田区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1005, '000000', '查看南山区全部数据角色', 'ViewEFDataRole_Area:Area_NanShanQu', 6, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '南山区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1006, '000000', '查看宝安区全部数据角色', 'ViewEFDataRole_Area:Area_BaoAnQu', 7, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '宝安区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1007, '000000', '查看龙岗区全部数据角色', 'ViewEFDataRole_Area:Area_LongGangQu', 8, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '龙岗区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1008, '000000', '查看龙华区全部数据角色', 'ViewEFDataRole_Area:Area_LongHuaQu', 9, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '龙华区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1009, '000000', '查看坪山区全部数据角色', 'ViewEFDataRole_Area:Area_PingsHanQu', 10, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '坪山区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1010, '000000', '查看光明区全部数据角色', 'ViewEFDataRole_Area:Area_GuangMingQu', 11, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '光明区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1011, '000000', '查看大鹏新区全部数据角色', 'ViewEFDataRole_Area:Area_DapengXinQu', 12, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '大鹏新区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1012, '000000', '查看深汕特别合作区全部数据角色', 'ViewEFDataRole_Area:Area_ShenShanTeBieHeZuoQu', 13, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '深汕特别合作区,roleKey不可修改', null, '1', null, null, null, '1');
INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
VALUES (1013, '000000', '查看深圳市直全部数据角色', 'ViewEFDataRole_Area:ShenZhen_ShiZhi', 14, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '深圳市直,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1002, '000000', '查看福田区全部数据角色', 'ViewEFDataRole_Area:Area_FuTianQu', 3, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '福田区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1003, '000000', '查看罗湖区全部数据角色', 'ViewEFDataRole_Area:Area_LuoHuQu', 4, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '罗湖区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1004, '000000', '查看盐田区全部数据角色', 'ViewEFDataRole_Area:Area_YanTianQu', 5, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '盐田区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1005, '000000', '查看南山区全部数据角色', 'ViewEFDataRole_Area:Area_NanShanQu', 6, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '南山区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1006, '000000', '查看宝安区全部数据角色', 'ViewEFDataRole_Area:Area_BaoAnQu', 7, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '宝安区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1007, '000000', '查看龙岗区全部数据角色', 'ViewEFDataRole_Area:Area_LongGangQu', 8, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '龙岗区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1008, '000000', '查看龙华区全部数据角色', 'ViewEFDataRole_Area:Area_LongHuaQu', 9, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '龙华区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1009, '000000', '查看坪山区全部数据角色', 'ViewEFDataRole_Area:Area_PingsHanQu', 10, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '坪山区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1010, '000000', '查看光明区全部数据角色', 'ViewEFDataRole_Area:Area_GuangMingQu', 11, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '光明区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1011, '000000', '查看大鹏新区全部数据角色', 'ViewEFDataRole_Area:Area_DapengXinQu', 12, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '大鹏新区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1012, '000000', '查看深汕特别合作区全部数据角色', 'ViewEFDataRole_Area:Area_ShenShanTeBieHeZuoQu', 13, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '深汕特别合作区,roleKey不可修改', null, '1', null, null, null, '1');
-- INSERT INTO sys_role (role_id, tenant_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_dept, create_by, create_time, update_by, update_time, remark, tenant_code, user_id, dept_id, sass_id, role_code, is_role_sys)
-- VALUES (1013, '000000', '查看深圳市直全部数据角色', 'ViewEFDataRole_Area:ShenZhen_ShiZhi', 14, '1', 1, 1, '0', '0', null, 0, '2025-01-10 15:08:12', 0, '2025-01-10 15:10:18', '深圳市直,roleKey不可修改', null, '1', null, null, null, '1');
-- 更新指定role_id的role_sort,从100开始递增排序
UPDATE sys_role SET role_sort = 100 WHERE role_id = 177;

91
zdxt-web-server/zdxt-admin-web-server/src/test/java/com/zdxt/service/test/InitVirtualUnitV2Test.java

@ -20,6 +20,7 @@ import org.dromara.system.domain.SysDept;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.mapper.SysDeptMapper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@ -388,4 +389,94 @@ public class InitVirtualUnitV2Test {
this.zone = zone;
}
}
@DisplayName("校验 efcode_virtual_unit 表 vir_id/vir_parent_id/vir_ancestors/vir_display_path 字段正确性")
@Test
public void testVirtualUnitTreeData() throws Exception {
// 1. 查询全部虚拟单位数据
List<EfcodeVirtualUnit> units = efcodeVirtualUnitMapper.selectList(Wrappers.lambdaQuery());
Assertions.assertFalse(CollUtil.isEmpty(units),
"efcode_virtual_unit 表无数据,请先执行 initVirtualUnitTreeV2 初始化");
System.out.println("待校验节点总数: " + units.size());
// 2. 建立 virId -> 节点索引,同时校验 vir_id 非空且唯一
Map<String, EfcodeVirtualUnit> unitMap = new HashMap<>();
for (EfcodeVirtualUnit u : units) {
Assertions.assertTrue(StringUtils.isNotEmpty(u.getVirId()), "存在 vir_id 为空的记录");
Assertions.assertNull(unitMap.put(u.getVirId(), u), "存在重复的 vir_id: " + u.getVirId());
}
List<String> errors = new ArrayList<>();
int rootCount = 0;
for (EfcodeVirtualUnit unit : units) {
String virId = unit.getVirId();
String parentId = unit.getVirParentId();
// 3. 校验 vir_parent_id:根节点父级为 _root_,其余父级必须存在于表中
if ("_root_".equals(parentId)) {
rootCount++;
} else if (parentId == null || !unitMap.containsKey(parentId)) {
errors.add(String.format("[%s] vir_parent_id=%s 在表中不存在", virId, parentId));
continue; // 父级缺失,无法继续校验 ancestors/displayPath
}
// 4. 向上追溯构建期望的祖级链(含自身),同时检测断裂与环
List<String> expectAncestorIds = new ArrayList<>();
Set<String> visited = new HashSet<>();
String pid = parentId;
boolean broken = false;
while (pid != null && !"_root_".equals(pid)) {
if (!visited.add(pid)) {
errors.add(String.format("[%s] 祖级链存在环: %s", virId, pid));
broken = true;
break;
}
EfcodeVirtualUnit p = unitMap.get(pid);
if (p == null) {
errors.add(String.format("[%s] 祖级链断裂,找不到节点: %s", virId, pid));
broken = true;
break;
}
expectAncestorIds.add(0, pid);
pid = p.getVirParentId();
}
if (broken) {
continue;
}
expectAncestorIds.add(virId);
// 5. 校验 vir_ancestors
String expectAncestors = String.join(",", expectAncestorIds);
if (!expectAncestors.equals(unit.getVirAncestors())) {
errors.add(String.format("[%s] vir_ancestors 不匹配: 期望[%s] 实际[%s]",
virId, expectAncestors, unit.getVirAncestors()));
}
// 6. 校验 vir_display_path(祖级链上各节点名称以 / 连接)
String expectPath = expectAncestorIds.stream()
.map(id -> {
EfcodeVirtualUnit e = unitMap.get(id);
return e != null && e.getVirName() != null ? e.getVirName() : "";
})
.collect(Collectors.joining("/"));
if (!expectPath.equals(unit.getVirDisplayPath())) {
errors.add(String.format("[%s] vir_display_path 不匹配: 期望[%s] 实际[%s]",
virId, expectPath, unit.getVirDisplayPath()));
}
}
// 7. 根节点数量校验(应存在且仅有一个 _root_ 直接子节点,即"深圳市")
System.out.println("根节点(vir_parent_id=_root_)数量: " + rootCount);
Assertions.assertTrue(rootCount >= 1, "未找到根节点(vir_parent_id=_root_)");
// 8. 汇总校验结果
if (!errors.isEmpty()) {
System.out.println("========== 校验失败,共 " + errors.size() + " 处 ==========");
errors.forEach(System.out::println);
Assertions.fail("efcode_virtual_unit 树结构字段校验失败,共 " + errors.size() + " 处,详见控制台输出");
}
System.out.println("========== 校验通过:所有节点的 vir_id/vir_parent_id/vir_ancestors/vir_display_path 均正确 ==========");
}
}

Loading…
Cancel
Save