Sfoglia il codice sorgente

增加区域工具类

master
WendyYang 1 anno fa
parent
commit
77d85c9018
5 ha cambiato i file con 30 aggiunte e 17 eliminazioni
  1. +9
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java
  2. +8
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java
  3. +2
    -8
      pmapi/src/main/java/com/ningdatech/pmapi/common/model/RegionMapKey.java
  4. +1
    -3
      pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java
  5. +10
    -4
      pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IRegionServiceTest.java

+ 9
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java Vedi File

@@ -35,6 +35,15 @@ public interface RegionCacheHelper {
RegionDTO getByCodeAndLevel(String code, int level);

/**
* 获取区域名称
*
* @param code 区域编码
* @param level 区域层级
* @return 名称
*/
String getRegionName(String code, int level);

/**
* 根据传入的地区code与level获取所有上层地区集合
* 按照level升序排列
*


+ 8
- 2
pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java Vedi File

@@ -34,6 +34,11 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements
}

@Override
public String getRegionName(String code, int level) {
return getByCodeAndLevel(code, level).getRegionName();
}

@Override
public List<RegionDTO> all() {
return super.all();
}
@@ -101,12 +106,13 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements
}
StringBuilder builder = new StringBuilder();
List<String> regionCodes = StrUtils.split(region.getRegionCodePath());
for (int i = regionCodes.size() - 1; i > 0; i--) {
for (int i = regionCodes.size() - 2; i > 0; i--) {
if (level <= sLevel) {
break;
}
RegionDTO tmp = getByCodeAndLevel(regionCodes.get(i), --level);
builder.append(tmp.getRegionName()).append(StrPool.SLASH);
builder.insert(0, StrPool.SLASH);
builder.insert(0, tmp.getRegionName());
}
builder.append(region.getRegionName());
return builder.toString();


+ 2
- 8
pmapi/src/main/java/com/ningdatech/pmapi/common/model/RegionMapKey.java Vedi File

@@ -16,7 +16,6 @@ import java.util.Objects;
* @since 13:54 2023/3/1
*/
@Data
@Builder
@AllArgsConstructor
public class RegionMapKey {

@@ -24,11 +23,6 @@ public class RegionMapKey {
return new RegionMapKey(regionCode, regionLevel);
}


@Tolerate
public RegionMapKey() {
}

/**
* 区域码
*/
@@ -48,8 +42,8 @@ public class RegionMapKey {
return false;
}
RegionMapKey regionMapKey = (RegionMapKey) o;
return regionCode.equals(regionMapKey.getRegionCode()) &&
regionLevel.equals(regionMapKey.getRegionLevel());
return regionCode.equals(regionMapKey.getRegionCode())
&& regionLevel.equals(regionMapKey.getRegionLevel());
}

@Override


+ 1
- 3
pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java Vedi File

@@ -1,11 +1,9 @@
package com.ningdatech.pmapi.sys.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.sys.model.entity.Menu;
@@ -74,7 +72,7 @@ class IMenuServiceTest extends AppTests {
public void initMenu() {
// menuService.remove(null);
roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class)
.eq(RoleMenu::getRoleId,1));
.eq(RoleMenu::getRoleId, 1));
// String str = FileUtil.readString("/Users/wendy/Desktop/long_text_2023-02-13-15-28-42.txt", "UTF-8");
// List<JSONObject> obj = JSONUtil.toList(str, JSONObject.class);
// save(obj, 0);


+ 10
- 4
pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IRegionServiceTest.java Vedi File

@@ -5,9 +5,8 @@ import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.common.helper.RegionCacheHelper;
import com.ningdatech.pmapi.sys.model.entity.Region;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@@ -22,13 +21,15 @@ import java.util.concurrent.atomic.AtomicLong;
* @author WendyYang
* @since 16:57 2023/3/1
*/
public class IRegionServiceTest extends AppTests {
class IRegionServiceTest extends AppTests {

@Autowired
private RegionCacheHelper regionCacheHelper;
@Autowired
private IRegionService regionService;

@Test
public void init() {
public void test1() {
AtomicLong idIncr = new AtomicLong(1);
Map<Integer, List<Region>> map = CollUtils.group(regionService.list(), Region::getRegionLevel);
regionService.remove(null);
@@ -54,5 +55,10 @@ public class IRegionServiceTest extends AppTests {
});
}

@Test
public void test2() {
System.out.println(regionCacheHelper.getDisplayName("330100", 2));
System.out.println(regionCacheHelper.getFullDisplayName("330102", 3));
}

}

Loading…
Annulla
Salva