Browse Source

更改品类删除时如果品类下有项目也不允许删除

anderx 8 years ago
parent
commit
a5b3d9fbad

+ 8 - 1
src/main/java/com/goafanti/admin/controller/AdminVarietiesApiController.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 
 import com.goafanti.admin.service.AdminVarietiesService;
+import com.goafanti.admin.service.BusinessProjectService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 
@@ -20,6 +21,8 @@ import com.goafanti.common.utils.StringUtils;
 public class AdminVarietiesApiController extends CertifyApiController{
 	@Resource
 	private AdminVarietiesService adminVarietiesService;
+	@Resource
+	BusinessProjectService businessprojectService;
 	
 	/**
 	 * 新增品类
@@ -118,7 +121,11 @@ public class AdminVarietiesApiController extends CertifyApiController{
 	public Result deleteState(String id){
 		Result res=new Result();
 		if (adminVarietiesService.getCountSon(id)>0) {
-			res.getError().add(buildError("品类下存在子品类", "品类存在子品类"));
+			res.getError().add(buildError("品类下存在子品类", "品类存在子品类不允许删除"));
+			return res;
+		}
+		if (businessprojectService.checkProject(id)) {
+			res.getError().add(buildError("品类下存在项目", "品类存在项目不允许删除"));
 			return res;
 		}
 		res.setData(adminVarietiesService.deleteState(id));

+ 2 - 0
src/main/java/com/goafanti/admin/service/BusinessProjectService.java

@@ -55,5 +55,7 @@ public interface BusinessProjectService {
 
 	Pagination<ProjectBo> recommendProjectList(Integer pNo, Integer pSize);
 
+	boolean checkProject(String id);
+
 	
 }

+ 7 - 0
src/main/java/com/goafanti/admin/service/impl/BusinessProjectServiceImpl.java

@@ -411,6 +411,13 @@ public class BusinessProjectServiceImpl extends BaseMybatisDao<BusinessProjectMa
 		}
 		return p;
 	}
+	@Override
+	public boolean checkProject(String id) {
+		if (businessProjectMapper.checkProject(id)>0) {
+			return true;
+		}
+		return false;
+	}
 	
 	
 }

+ 1 - 1
src/main/java/com/goafanti/common/dao/BusinessProjectMapper.java

@@ -86,7 +86,7 @@ public interface BusinessProjectMapper {
 
 	ProjectDetailBo selectAppProjectDetail(String id);
 
-	
+	int checkProject(String id);
 
 	
 }

+ 5 - 0
src/main/java/com/goafanti/common/mapper/BusinessProjectMapper.xml

@@ -744,4 +744,9 @@
 from business_project p 
 where id=#{id,jdbcType=VARCHAR}
   </select>
+  
+  <select id="checkProject" resultType="Integer">
+  select count(0) from business_project
+ where  cid=#{id,jdbcType=VARCHAR}
+ </select>
 </mapper>