|
|
@@ -1,20 +1,25 @@
|
|
|
package com.jtzx.crm.test;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.jtzx.crm.JtzxCrmSysApplication;
|
|
|
-import cc.uncarbon.framework.core.constant.HelioConstant;
|
|
|
-import cc.uncarbon.framework.core.context.TenantContext;
|
|
|
-import cc.uncarbon.framework.core.context.TenantContextHolder;
|
|
|
-import cc.uncarbon.framework.core.context.UserContext;
|
|
|
-import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
-import com.jtzx.crm.module.sys.model.response.SysRoleBO;
|
|
|
-import com.jtzx.crm.module.sys.service.SysRoleService;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.jtzx.crm.module.sys.entity.DictAreaRegionEntity;
|
|
|
+import com.jtzx.crm.module.sys.entity.DictCityRegionEntity;
|
|
|
+import com.jtzx.crm.module.sys.entity.DictProvinceRegionEntity;
|
|
|
+import com.jtzx.crm.module.sys.mapper.DictAreaRegionMapper;
|
|
|
+import com.jtzx.crm.module.sys.mapper.DictCityRegionMapper;
|
|
|
+import com.jtzx.crm.module.sys.mapper.DictProvinceRegionMapper;
|
|
|
+import com.jtzx.crm.module.sys.model.response.DictAreaRegionBO;
|
|
|
+import com.jtzx.crm.module.sys.model.response.DictCityRegionBO;
|
|
|
+import com.jtzx.crm.module.sys.model.response.DictProvinceRegionBO;
|
|
|
import jakarta.annotation.Resource;
|
|
|
-import org.junit.jupiter.api.Assertions;
|
|
|
-import org.junit.jupiter.api.BeforeAll;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -26,31 +31,119 @@ import java.util.List;
|
|
|
class ExampleUnitTest {
|
|
|
|
|
|
@Resource
|
|
|
- private SysRoleService sysRoleService;
|
|
|
-
|
|
|
-
|
|
|
- @BeforeAll
|
|
|
- public static void init() {
|
|
|
- // 设置用户上下文
|
|
|
- UserContext userContext = new UserContext();
|
|
|
- userContext
|
|
|
- .setUserId(1L)
|
|
|
- .setUserName("超级管理员")
|
|
|
- // 用户类型, 根据单元测试需要修改
|
|
|
- .setUserTypeStr("ADMIN_USER");
|
|
|
- UserContextHolder.setUserContext(userContext);
|
|
|
-
|
|
|
- // 设置租户上下文
|
|
|
- TenantContext tenantContext = new TenantContext();
|
|
|
- tenantContext
|
|
|
- .setTenantId(HelioConstant.Tenant.DEFAULT_PRIVILEGED_TENANT_ID)
|
|
|
- .setTenantName("超级租户");
|
|
|
- TenantContextHolder.setTenantContext(tenantContext);
|
|
|
+ private DictProvinceRegionMapper dictProvinceRegionMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DictCityRegionMapper dictCityRegionMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DictAreaRegionMapper dictAreaRegionMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void initProvinceData() {
|
|
|
+
|
|
|
+ // 1. 指定本地文件路径(注意反斜杠需要双写转义)
|
|
|
+ File jsonFile = new File("/mnt/d/dev/region/json/01省.json");
|
|
|
+
|
|
|
+ // 2. 创建 Jackson 核心对象
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用 TypeReference 指定解析目标为 List<Region>
|
|
|
+ List<DictProvinceRegionBO> regions = objectMapper.readValue(jsonFile, new TypeReference<>() {
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打印验证
|
|
|
+ System.out.println("成功读取到 " + regions.size() + " 个省份数据:");
|
|
|
+ List<DictProvinceRegionEntity> regionEntityList = Lists.newArrayList();
|
|
|
+ regions.forEach(e -> {
|
|
|
+ DictProvinceRegionEntity region = DictProvinceRegionEntity.builder().build();
|
|
|
+ region.setCode(e.getCode());
|
|
|
+ region.setName(e.getName());
|
|
|
+ region.setParentCode(e.getParentCode());
|
|
|
+ region.setLevel(e.getLevel());
|
|
|
+ region.setUseStatus(0);
|
|
|
+ region.setRevision(0L);
|
|
|
+ region.setDelFlag(0);
|
|
|
+ region.setCreatedAt(LocalDateTime.now());
|
|
|
+ region.setUpdatedAt(LocalDateTime.now());
|
|
|
+ regionEntityList.add(region);
|
|
|
+ });
|
|
|
+ dictProvinceRegionMapper.insert(regionEntityList);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Test
|
|
|
- void exampleTest() {
|
|
|
- List<SysRoleBO> selectOptions = sysRoleService.adminSelectOptions();
|
|
|
- Assertions.assertTrue(CollUtil.isNotEmpty(selectOptions));
|
|
|
+ public void initCityData() {
|
|
|
+ // 1. 指定本地文件路径(注意反斜杠需要双写转义)
|
|
|
+ File jsonFile = new File("/mnt/d/dev/region/json/02市.json");
|
|
|
+
|
|
|
+ // 2. 创建 Jackson 核心对象
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用 TypeReference 指定解析目标为 List<Region>
|
|
|
+ List<DictCityRegionBO> regions = objectMapper.readValue(jsonFile, new TypeReference<>() {
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打印验证
|
|
|
+ System.out.println("成功读取到 " + regions.size() + " 个省份数据:");
|
|
|
+ List<DictCityRegionEntity> regionEntityList = Lists.newArrayList();
|
|
|
+ regions.forEach(e -> {
|
|
|
+ DictCityRegionEntity region = DictCityRegionEntity.builder().build();
|
|
|
+ region.setCode(e.getCode());
|
|
|
+ region.setName(e.getName());
|
|
|
+ region.setParentCode(e.getParentCode());
|
|
|
+ region.setLevel(e.getLevel());
|
|
|
+ region.setCreatedAt(LocalDateTime.now());
|
|
|
+ region.setUpdatedAt(LocalDateTime.now());
|
|
|
+ regionEntityList.add(region);
|
|
|
+ });
|
|
|
+ dictCityRegionMapper.insert(regionEntityList);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void initAreaData() {
|
|
|
+ // 1. 指定本地文件路径(注意反斜杠需要双写转义)
|
|
|
+ File jsonFile = new File("/mnt/d/dev/region/json/03区(县).json");
|
|
|
+
|
|
|
+ // 2. 创建 Jackson 核心对象
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用 TypeReference 指定解析目标为 List<Region>
|
|
|
+ List<DictAreaRegionBO> regions = objectMapper.readValue(jsonFile, new TypeReference<>() {
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打印验证
|
|
|
+ System.out.println("成功读取到 " + regions.size() + " 个省份数据:");
|
|
|
+ List<DictAreaRegionEntity> regionEntityList = Lists.newArrayList();
|
|
|
+ regions.forEach(e -> {
|
|
|
+ DictAreaRegionEntity region = DictAreaRegionEntity.builder().build();
|
|
|
+ region.setCode(e.getCode());
|
|
|
+ region.setName(e.getName());
|
|
|
+ region.setParentCode(e.getParentCode());
|
|
|
+ region.setLevel(e.getLevel());
|
|
|
+ region.setCreatedAt(LocalDateTime.now());
|
|
|
+ region.setUpdatedAt(LocalDateTime.now());
|
|
|
+ regionEntityList.add(region);
|
|
|
+ });
|
|
|
+ dictAreaRegionMapper.insert(regionEntityList);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|