فهرست منبع

增加行政区域逻辑

zhou-hao 7 سال پیش
والد
کامیت
9dcf240efe

+ 48 - 6
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-controller/src/main/java/org/hswebframework/web/controller/organizational/DistrictController.java

@@ -1,17 +1,21 @@
 package org.hswebframework.web.controller.organizational;
 
+import org.hswebframework.web.authorization.Permission;
 import org.hswebframework.web.authorization.annotation.Authorize;
 import org.hswebframework.web.commons.entity.param.QueryParamEntity;
 import org.hswebframework.web.controller.SimpleGenericEntityController;
+import org.hswebframework.web.controller.message.ResponseMessage;
 import org.hswebframework.web.entity.organizational.DistrictEntity;
+import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.logging.AccessLogger;
-import  org.hswebframework.web.service.organizational.DistrictService;
+import org.hswebframework.web.service.organizational.DistrictService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 /**
- *  表单发布日志
+ * 表单发布日志
  *
  * @author hsweb-generator-online
  */
@@ -22,14 +26,52 @@ import org.springframework.web.bind.annotation.RestController;
 public class DistrictController implements SimpleGenericEntityController<DistrictEntity, String, QueryParamEntity> {
 
     private DistrictService districtService;
-  
+
     @Autowired
     public void setDistrictService(DistrictService districtService) {
         this.districtService = districtService;
     }
-  
+
     @Override
     public DistrictService getService() {
         return districtService;
     }
+
+    @PatchMapping("/code/{code}")
+    @Authorize(action = Permission.ACTION_QUERY)
+    @AccessLogger("根据行政区划代码获取")
+    public ResponseMessage<DistrictEntity> getByCode(@PathVariable String code) {
+        return ResponseMessage.ok(districtService.selectByCode(code));
+    }
+
+    @PatchMapping("/all")
+    @Authorize(action = Permission.ACTION_QUERY)
+    @AccessLogger("获取全部行政区划")
+    public ResponseMessage<List<DistrictEntity>> all() {
+        return ResponseMessage.ok(districtService.select());
+    }
+
+    @PatchMapping("/batch")
+    @Authorize(action = Permission.ACTION_UPDATE)
+    @AccessLogger("批量修改数据")
+    public ResponseMessage<Void> updateBatch(@RequestBody List<DistrictEntity> batch) {
+        districtService.updateBatch(batch);
+        return ResponseMessage.ok();
+    }
+
+    @PutMapping("/{id}/disable")
+    @Authorize(action = Permission.ACTION_DISABLE)
+    @AccessLogger("禁用机构")
+    public ResponseMessage<Boolean> disable(@PathVariable String id) {
+        districtService.disable(id);
+        return ResponseMessage.ok();
+    }
+
+    @PutMapping("/{id}/enable")
+    @Authorize(action = Permission.ACTION_ENABLE)
+    @AccessLogger("启用机构")
+    public ResponseMessage<Boolean> enable(@PathVariable String id) {
+        districtService.enable(id);
+        return ResponseMessage.ok();
+    }
 }

+ 9 - 1
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-api/src/main/java/org/hswebframework/web/service/organizational/DistrictService.java

@@ -1,13 +1,21 @@
 package org.hswebframework.web.service.organizational;
 
 import org.hswebframework.web.entity.organizational.DistrictEntity;
+import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.service.CrudService;
+import org.hswebframework.web.service.TreeService;
+
+import java.util.List;
 
 /**
  *  表单发布日志 服务类
  *
  * @author hsweb-generator-online
  */
-public interface DistrictService extends CrudService<DistrictEntity, String> {
+public interface DistrictService extends TreeService<DistrictEntity, String>,CrudService<DistrictEntity, String> {
+    void disable(String id);
+
+    void enable(String id);
 
+    DistrictEntity selectByCode(String code);
 }

+ 89 - 2
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDistrictService.java

@@ -1,30 +1,117 @@
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.dao.organizational.DistrictDao;
 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.GenericEntityService;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.organizational.DistrictService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+
 /**
  * 默认的服务实现
  *
  * @author hsweb-generator-online
  */
 @Service("districtService")
-public class SimpleDistrictService extends GenericEntityService<DistrictEntity, String>
+@CacheConfig(cacheNames = "district")
+public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntity, String>
         implements DistrictService {
     @Autowired
     private DistrictDao districtDao;
-   @Override
+
+    @Override
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
     }
+
     @Override
     public DistrictDao getDao() {
         return districtDao;
     }
 
+    @Override
+    @CacheEvict(allEntries = true)
+    public String insert(DistrictEntity entity) {
+        return super.insert(entity);
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public int updateByPk(String id, DistrictEntity entity) {
+        return super.updateByPk(id, entity);
+    }
+
+    @Override
+    @Cacheable(key = "'ids:'+(#id==null?0:#id.hashCode())")
+    public List<DistrictEntity> selectByPk(List<String> id) {
+        return super.selectByPk(id);
+    }
+
+    @Override
+    @Cacheable(key = "'id:'+#id")
+    public DistrictEntity selectByPk(String id) {
+        return super.selectByPk(id);
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public int deleteByPk(String id) {
+        return super.deleteByPk(id);
+    }
+
+    @Override
+    @Cacheable(key = "'code:'+#code")
+    public DistrictEntity selectByCode(String code) {
+        return createQuery().where(DistrictEntity.code, code).single();
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public int updateBatch(Collection<DistrictEntity> data) {
+        return super.updateBatch(data);
+    }
+
+    @Override
+    @Cacheable(key = "'all'")
+    public List<DistrictEntity> select() {
+        return super.select();
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public int updateByPk(List<DistrictEntity> data) {
+        return super.updateByPk(data);
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public void disable(String id) {
+        Objects.requireNonNull(id);
+        createUpdate()
+                .set(DistrictEntity.status, DataStatus.STATUS_DISABLED)
+                .where(DistrictEntity.id, id)
+                .exec();
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public void enable(String id) {
+        Objects.requireNonNull(id);
+        createUpdate()
+                .set(DistrictEntity.status, DataStatus.STATUS_ENABLED)
+                .where(DistrictEntity.id, id)
+                .exec();
+    }
 }