diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-controller/src/main/java/org/hswebframework/web/controller/organizational/DistrictController.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-controller/src/main/java/org/hswebframework/web/controller/organizational/DistrictController.java index c188d370e..5b40ffc56 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-controller/src/main/java/org/hswebframework/web/controller/organizational/DistrictController.java +++ b/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 { 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 getByCode(@PathVariable String code) { + return ResponseMessage.ok(districtService.selectByCode(code)); + } + + @PatchMapping("/all") + @Authorize(action = Permission.ACTION_QUERY) + @AccessLogger("获取全部行政区划") + public ResponseMessage> all() { + return ResponseMessage.ok(districtService.select()); + } + + @PatchMapping("/batch") + @Authorize(action = Permission.ACTION_UPDATE) + @AccessLogger("批量修改数据") + public ResponseMessage updateBatch(@RequestBody List batch) { + districtService.updateBatch(batch); + return ResponseMessage.ok(); + } + + @PutMapping("/{id}/disable") + @Authorize(action = Permission.ACTION_DISABLE) + @AccessLogger("禁用机构") + public ResponseMessage disable(@PathVariable String id) { + districtService.disable(id); + return ResponseMessage.ok(); + } + + @PutMapping("/{id}/enable") + @Authorize(action = Permission.ACTION_ENABLE) + @AccessLogger("启用机构") + public ResponseMessage enable(@PathVariable String id) { + districtService.enable(id); + return ResponseMessage.ok(); + } } diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-api/src/main/java/org/hswebframework/web/service/organizational/DistrictService.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-api/src/main/java/org/hswebframework/web/service/organizational/DistrictService.java index ed7da08d3..ad01f69ac 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-api/src/main/java/org/hswebframework/web/service/organizational/DistrictService.java +++ b/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 { +public interface DistrictService extends TreeService,CrudService { + void disable(String id); + void enable(String id); + + DistrictEntity selectByCode(String code); } diff --git a/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 b/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 index 7935f32c2..c8bace1ec 100644 --- a/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 +++ b/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 +@CacheConfig(cacheNames = "district") +public class SimpleDistrictService extends AbstractTreeSortService implements DistrictService { @Autowired private DistrictDao districtDao; - @Override + + @Override protected IDGenerator 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 selectByPk(List 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 data) { + return super.updateBatch(data); + } + + @Override + @Cacheable(key = "'all'") + public List select() { + return super.select(); + } + + @Override + @CacheEvict(allEntries = true) + public int updateByPk(List 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(); + } }