zhouhao преди 7 години
родител
ревизия
82488cf8a3

+ 2 - 4
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractTreeSortService.java

@@ -81,7 +81,7 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
             entity.setParentId(createParentIdOnExists());
             entity.setPath(RandomUtil.randomChar(4));
         } else {
-            if (entity.getSortIndex() == null&&parent.getSortIndex()!=null)
+            if (entity.getSortIndex() == null && parent.getSortIndex() != null)
                 entity.setSortIndex(parent.getSortIndex() * 10);
             entity.setPath(parent.getPath() + "-" + RandomUtil.randomChar(4));
         }
@@ -119,13 +119,11 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
         assertNotNull(entity);
         List<E> childrenList = new ArrayList<>();
         TreeSupportEntity.expandTree2List(entity, childrenList, getIDGenerator());
-//        this.saveOrUpdateForSingle(entity);
-//        childrenList.remove(entity);
         childrenList.forEach(this::saveOrUpdateForSingle);
         return childrenList.size() + 1;
     }
 
-    public PK saveOrUpdateForSingle(E entity) {
+    protected PK saveOrUpdateForSingle(E entity) {
         assertNotNull(entity);
         PK id = entity.getId();
         if (null == id || this.selectByPk(id) == null) {

+ 12 - 0
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/EnableCacheAllEvictTreeSortService.java

@@ -14,6 +14,18 @@ import java.util.List;
 public abstract class EnableCacheAllEvictTreeSortService<E extends TreeSortSupportEntity<PK>, PK>
         extends AbstractTreeSortService<E, PK> {
 
+    @Override
+    @Cacheable(key = "'chidlren:'+#parentId")
+    public List<E> selectChildNode(PK parentId) {
+        return super.selectChildNode(parentId);
+    }
+
+    @Override
+    @Cacheable(key = "'all-chidlren:'+#parentId")
+    public List<E> selectAllChildNode(PK parentId) {
+        return super.selectAllChildNode(parentId);
+    }
+
     @Override
     @CacheEvict(allEntries = true)
     public int updateBatch(Collection<E> data) {

+ 3 - 4
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDistrictService.java

@@ -9,6 +9,7 @@ import org.hswebframework.web.entity.organizational.DistrictEntity;
 import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.service.AbstractTreeSortService;
 import org.hswebframework.web.service.DefaultDSLQueryService;
+import org.hswebframework.web.service.EnableCacheAllEvictTreeSortService;
 import org.hswebframework.web.service.GenericEntityService;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.organizational.DistrictService;
@@ -34,7 +35,7 @@ import static org.hswebframework.web.service.DefaultDSLQueryService.*;
  */
 @Service("districtService")
 @CacheConfig(cacheNames = "district")
-public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntity, String>
+public class SimpleDistrictService extends EnableCacheAllEvictTreeSortService<DistrictEntity, String>
         implements DistrictService {
     @Autowired
     private DistrictDao districtDao;
@@ -84,9 +85,7 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Override
     @CacheEvict(allEntries = true)
     public int deleteByPk(String id) {
-        if (DefaultDSLQueryService.createQuery(organizationalDao)
-                .where(OrganizationalEntity.districtId, id)
-                .total() > 0) {
+        if (DefaultDSLQueryService.createQuery(organizationalDao).where(OrganizationalEntity.districtId, id).total() > 0) {
             throw new BusinessException("行政区域下存在机构信息,无法删除!");
         }
         publisher.publishEvent(new ClearPersonCacheEvent());

+ 18 - 4
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-web/src/main/java/org/hswebframework/web/controller/organizational/DistrictController.java

@@ -17,14 +17,14 @@ import org.springframework.web.bind.annotation.*;
 import java.util.List;
 
 /**
- * 表单发布日志
+ * 行政区划管理
  *
  * @author hsweb-generator-online
  */
 @RestController
 @RequestMapping("${hsweb.web.mappings.district:district}")
 @Authorize(permission = "district", description = "行政区划管理")
-@Api(value = "行政区划管理",tags = "组织架构-行政区划管理")
+@Api(value = "行政区划管理", tags = "组织架构-行政区划管理")
 public class DistrictController implements SimpleGenericEntityController<DistrictEntity, String, QueryParamEntity> {
 
     private DistrictService districtService;
@@ -46,6 +46,20 @@ public class DistrictController implements SimpleGenericEntityController<Distric
         return ResponseMessage.ok(districtService.selectByCode(code));
     }
 
+    @GetMapping("/children/{parentId}")
+    @Authorize(action = Permission.ACTION_QUERY)
+    @ApiOperation("获取子级行政区划")
+    public ResponseMessage<List<DistrictEntity>> getByParentId(@PathVariable String parentId) {
+        return ResponseMessage.ok(districtService.selectChildNode(parentId));
+    }
+
+    @GetMapping("/children/{parentId}/all")
+    @Authorize(action = Permission.ACTION_QUERY)
+    @ApiOperation("获取所有子级行政区划")
+    public ResponseMessage<List<DistrictEntity>> getAllByParentId(@PathVariable String parentId) {
+        return ResponseMessage.ok(districtService.selectAllChildNode(parentId));
+    }
+
     @GetMapping("/all")
     @Authorize(action = Permission.ACTION_QUERY)
     @ApiOperation("获取全部行政区划")
@@ -63,7 +77,7 @@ public class DistrictController implements SimpleGenericEntityController<Distric
 
     @PutMapping("/{id}/disable")
     @Authorize(action = Permission.ACTION_DISABLE)
-    @ApiOperation("禁用机构")
+    @ApiOperation("禁用行政区划")
     public ResponseMessage<Boolean> disable(@PathVariable String id) {
         districtService.disable(id);
         return ResponseMessage.ok();
@@ -71,7 +85,7 @@ public class DistrictController implements SimpleGenericEntityController<Distric
 
     @PutMapping("/{id}/enable")
     @Authorize(action = Permission.ACTION_ENABLE)
-    @ApiOperation("启用机构")
+    @ApiOperation("启用行政区划")
     public ResponseMessage<Boolean> enable(@PathVariable String id) {
         districtService.enable(id);
         return ResponseMessage.ok();