Kaynağa Gözat

增加删除限制

zhou-hao 7 yıl önce
ebeveyn
işleme
187021fa0b

+ 17 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDepartmentService.java

@@ -16,10 +16,14 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.dao.organizational.DepartmentDao;
+import org.hswebframework.web.dao.organizational.PositionDao;
 import org.hswebframework.web.entity.organizational.DepartmentEntity;
+import org.hswebframework.web.entity.organizational.PositionEntity;
 import org.hswebframework.web.id.IDGenerator;
 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.service.organizational.DepartmentService;
@@ -45,6 +49,9 @@ public class SimpleDepartmentService
     @Autowired
     private DepartmentDao departmentDao;
 
+    @Autowired
+    protected PositionDao positionDao;
+
     @Override
     public DepartmentDao getDao() {
         return departmentDao;
@@ -72,4 +79,14 @@ public class SimpleDepartmentService
     public DepartmentEntity selectByCode(String code) {
         return createQuery().where(DepartmentEntity.code, code).single();
     }
+
+    @Override
+    public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(positionDao)
+                .where(PositionEntity.departmentId, id)
+                .total() > 0) {
+            throw new BusinessException("部门下存在职位信息,无法删除!");
+        }
+        return super.deleteByPk(id);
+    }
 }

+ 14 - 1
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,11 +1,14 @@
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.commons.entity.Entity;
 import org.hswebframework.web.dao.organizational.DistrictDao;
+import org.hswebframework.web.dao.organizational.OrganizationalDao;
 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.GenericEntityService;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.organizational.DistrictService;
@@ -20,6 +23,8 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 
+import static org.hswebframework.web.service.DefaultDSLQueryService.*;
+
 /**
  * 默认的服务实现
  *
@@ -32,6 +37,9 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Autowired
     private DistrictDao districtDao;
 
+    @Autowired
+    private OrganizationalDao organizationalDao;
+
     @Override
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
@@ -69,6 +77,11 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Override
     @CacheEvict(allEntries = true)
     public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(organizationalDao)
+                .where(OrganizationalEntity.orgId, id)
+                .total() > 0) {
+            throw new BusinessException("行政区域下存在机构信息,无法删除!");
+        }
         return super.deleteByPk(id);
     }
 
@@ -87,7 +100,7 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Override
     @Cacheable(key = "'all'")
     public List<DistrictEntity> select() {
-        return  createQuery().where().orderByAsc(DistrictEntity.sortIndex).listNoPaging();
+        return createQuery().where().orderByAsc(DistrictEntity.sortIndex).listNoPaging();
     }
 
     @Override

+ 18 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleOrganizationalService.java

@@ -16,10 +16,14 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.commons.entity.DataStatus;
+import org.hswebframework.web.dao.organizational.DepartmentDao;
 import org.hswebframework.web.dao.organizational.OrganizationalDao;
+import org.hswebframework.web.entity.organizational.DepartmentEntity;
 import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.id.IDGenerator;
+import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.EnableCacheAllEvictTreeSortService;
 import org.hswebframework.web.service.organizational.OrganizationalService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +48,9 @@ public class SimpleOrganizationalService extends EnableCacheAllEvictTreeSortServ
     @Autowired
     private OrganizationalDao organizationalDao;
 
+    @Autowired
+    private DepartmentDao departmentDao;
+
     @Override
     public OrganizationalDao getDao() {
         return organizationalDao;
@@ -54,6 +61,17 @@ public class SimpleOrganizationalService extends EnableCacheAllEvictTreeSortServ
         return IDGenerator.MD5;
     }
 
+    @Override
+    public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(departmentDao)
+                .where(DepartmentEntity.orgId, id)
+                .total() > 0) {
+            throw new BusinessException("机构下存在部门信息,无法删除");
+        }
+
+        return super.deleteByPk(id);
+    }
+
     @Override
     @CacheEvict(allEntries = true)
     public String insert(OrganizationalEntity entity) {

+ 14 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimplePositionService.java

@@ -16,6 +16,8 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
+import org.hswebframework.web.dao.organizational.PersonDao;
 import org.hswebframework.web.dao.organizational.PositionDao;
 import org.hswebframework.web.entity.organizational.PositionEntity;
 import org.hswebframework.web.id.IDGenerator;
@@ -23,6 +25,7 @@ import org.hswebframework.web.service.AbstractTreeSortService;
 import org.hswebframework.web.service.organizational.PositionService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 默认的服务实现
@@ -35,6 +38,9 @@ public class SimplePositionService extends AbstractTreeSortService<PositionEntit
     @Autowired
     private PositionDao positionDao;
 
+    @Autowired
+    private PersonDao personDao;
+
     @Override
     public PositionDao getDao() {
         return positionDao;
@@ -44,4 +50,12 @@ public class SimplePositionService extends AbstractTreeSortService<PositionEntit
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
     }
+
+    @Override
+    public int deleteByPk(String id) {
+        if(!CollectionUtils.isEmpty(personDao.selectByPositionId(id))){
+            throw new BusinessException("岗位中还有人员,无法删除!");
+        }
+        return super.deleteByPk(id);
+    }
 }