Explorar o código

新增项目,修改新增、删除品类

liliang4869 %!s(int64=7) %!d(string=hai) anos
pai
achega
6a50e2606e

+ 56 - 2
src/main/java/com/goafanti/business/controller/AdminJtBusinessController.java

@@ -15,6 +15,7 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.model.JtBusinessCategory;
+import com.goafanti.common.model.JtBusinessProject;
 
 import okhttp3.Request;
 
@@ -34,9 +35,13 @@ public class AdminJtBusinessController extends CertifyApiController{
 	@RequestMapping(value="/category/delete",method=RequestMethod.POST)
 	private Result deleteCetegoryById(String id) {
 		Result result=new Result();
-		if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
+		if(id==null) {result.getError().add(buildError(ErrorConstants.STATUS_ERROR,"","id"));
 		return result;} 
-		result.setData(jtBusinessService.deleteCategoryById(id));
+		int rc=jtBusinessService.deleteCategoryById(id);
+		result.setData(rc);
+		if(rc==-1) {
+			result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","请先删除子项目及子分类,"));
+		}
 		return result;
 		
 	}
@@ -117,5 +122,54 @@ public class AdminJtBusinessController extends CertifyApiController{
 		return ;
 	}
 	
+	/*
+	 * 
+	 * 新增项目
+	 * 
+	 * */
+	@RequestMapping(value="/project/apply",method=RequestMethod.POST)
+	private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
+		Result result=new Result();
+		disposeProjectParam(result, jtBusinessProject);
+		if(result.getError().size()<=0) {
+			result.setData(jtBusinessService.insertProject(jtBusinessProject));
+		}
+		return result;
+		
+	}
+	private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
+		if(jtBusinessProject.getName() == null) {
+			result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
+			return ;
+		}
+		if(jtBusinessProject.getCategoryId() == null) {
+			result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
+			return ;
+		}
+		//todo  判断品类是否存在
+		JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
+		if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
+			result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类找到"));
+			return ;
+		}
+		
+		if(jtBusinessProject.getProvince()==null)
+		{
+			result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
+			return ;
+		}
+	
+		if(jtBusinessProject.getCity()==null)
+		{
+			result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
+			return ;
+		}
+		if(jtBusinessProject.getPrice()==null)
+		{
+			result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
+			return ;
+		}
+		return ;
+	}
 	
 }

+ 1 - 0
src/main/java/com/goafanti/business/service/JtBusinessService.java

@@ -20,4 +20,5 @@ int insertCategory(JtBusinessCategory jtBusinessCategory);
 int deleteCategoryById(String id);
 JtBusinessCategory getCategoryById(String id);
 int updateCategory(JtBusinessCategory jtBusinessCategory);
+int insertProject(JtBusinessProject jtBusinessProject);
 }

+ 64 - 6
src/main/java/com/goafanti/business/service/impl/JtBusinessServiceImpl.java

@@ -6,6 +6,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.poi.poifs.property.Child;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -102,25 +103,39 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 		if(jtBusinessCategory.getSuperId()!=null && jtBusinessCategory.getLayer().intValue()==1)return -2;
 		String number="BC";
 		if(jtBusinessCategory.getLayer().intValue()==2) {
+			//2层,先加第一层
+			//找到当前品类父级品类
 			JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getSuperId());
 			if(sp==null || sp.getLayer()!=1) {
+				//找到的父级品类层数不是1 或者未找到
 				return -2;
 			}
-			//加前前层
+			//加前层
+			//父级品类层数为1的情况下 第一层编号为父级sort序号
 			int size1=sp.getSort();
-			if(size1>99)return -size1;
+			if(size1>99)return -1;
 			if(size1<10)number+="0";
 			number+=size1;
 		}
-		//加前层
+		
+		
+		//加层
+		int size2;
+		//通过父级id获取当前层列表
 		List<JtBusinessCategory>businessCategories =jtBusinessCategoryMapper.getBusinessCategoryBySuperId(jtBusinessCategory.getSuperId(), null);
-		int size2=businessCategories.size()+1;
+		//列表为0,当前层编号size2设置为1,大于0 设置为当前最大sort+1
+		if(businessCategories.size()>0)
+		 size2=businessCategories.get(businessCategories.size()-1).getSort()+1;
+		else size2=1;
+		//每层最多99个
 		if(size2>99)return -1;
+		//增加0
 		if(size2<10)number+="0";
+		//完成编号
 		number+=size2;
 		jtBusinessCategory.setNumber(number);
-		if(businessCategories==null )jtBusinessCategory.setSort(1);
-		else jtBusinessCategory.setSort(businessCategories.size()+1);
+		//设置sort序号
+		jtBusinessCategory.setSort(size2);
 		jtBusinessCategory.setCreateTime(new Date());
 		jtBusinessCategory.setId(UUID.randomUUID().toString());
 		return jtBusinessCategoryMapper.insertSelective(jtBusinessCategory);
@@ -129,6 +144,17 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 	@Override
 	public int deleteCategoryById(String id) {
 		// TODO Auto-generated method stub
+		//查找品类
+		JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(id);
+		//查找子品类 存在子品类不允许删除
+		List<JtBusinessCategory> chidren=jtBusinessCategoryMapper.getBusinessCategoryBySuperId(sp.getId(), null);
+		if(chidren.size()>0) {
+			return -1;
+		}
+		List<JtBusinessProject> childrenProject=jtBusinessProjectMapper.getBusinessProjectByCategoryId(id, 100);
+		if(childrenProject!= null && childrenProject.size()>0) {
+			return -1;
+		}
 		return jtBusinessCategoryMapper.deleteByPrimaryKey(id);
 	}
 
@@ -164,5 +190,37 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 		return params;
 	}
 
+	@Override
+	public int insertProject(JtBusinessProject jtBusinessProject) {
+		// TODO Auto-generated method stub
+		jtBusinessProject.setCreateTime(new Date());
+		jtBusinessProject.setId(UUID.randomUUID().toString());
+		List<JtBusinessProject>projects=jtBusinessProjectMapper.findProjectOrderByNumber();
+		int cSize = 1;
+		if(projects!=null && projects.size()>0)
+		{
+			String number=projects.get(projects.size()-1).getNumber();
+			if(number!=null && number.length()==6)
+			{
+				String nbString=number.substring(2);
+				try {
+				cSize=Integer.parseInt(nbString)+1;}catch (Exception e) {
+					// TODO: handle exception
+					return -1;
+				}
+			}
+			else cSize=1;
+		}
+		else cSize=1;
+	
+		String nbString="BP";
+		String sizeString="000"+cSize;
+		sizeString=sizeString.substring(sizeString.length()-4);
+		nbString+=sizeString;
+		jtBusinessProject.setNumber(nbString);
+		jtBusinessProjectMapper.insertSelective(jtBusinessProject);
+		return 1;
+	}
+
 	
 }

+ 2 - 0
src/main/java/com/goafanti/common/dao/JtBusinessProjectMapper.java

@@ -98,5 +98,7 @@ public interface JtBusinessProjectMapper {
     
      List<JtBusinessProject> getBusinessProjectByCategoryId(String id,Integer size);
      
+  List<JtBusinessProject> findProjectOrderByNumber();
+     
   
 }

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

@@ -528,4 +528,9 @@
  and jtbc.id=jtbp.category_id
   </if>
   </select>
+  
+  <select id="findProjectOrderByNumber" resultType="com.goafanti.common.model.JtBusinessProject">
+  select number,id
+  from jt_business_project order by number
+  </select>
 </mapper>