Преглед изворни кода

品类更新,搜索,详情,删除

liliang4869 пре 7 година
родитељ
комит
193b8153ce

+ 64 - 0
src/main/java/com/goafanti/business/controller/AdminJtBusinessController.java

@@ -10,17 +10,52 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import com.goafanti.business.service.JtBusinessService;
 import com.goafanti.business.service.JtBusinessService;
+import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.model.JtBusinessCategory;
 import com.goafanti.common.model.JtBusinessCategory;
 
 
+import okhttp3.Request;
+
 @RestController
 @RestController
 @RequestMapping(value = "/api/admin/jtBusiness")
 @RequestMapping(value = "/api/admin/jtBusiness")
 public class AdminJtBusinessController extends CertifyApiController{
 public class AdminJtBusinessController extends CertifyApiController{
 	
 	
 	@Resource 
 	@Resource 
 	private JtBusinessService jtBusinessService;
 	private JtBusinessService jtBusinessService;
+	
+	@Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper;
+	
+	/*
+	 * 删除品类
+	 * 
+	 * */
+	@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"));
+		return result;} 
+		result.setData(jtBusinessService.deleteCategoryById(id));
+		return result;
+		
+	}
+
+	
+	/*
+	 * 
+	 * 品类详情
+	 * */
+	@RequestMapping(value="/category/detail",method=RequestMethod.GET)
+	private Result getCategoryDetailById(String id)
+	{
+		Result result=new Result();
+		if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
+		return result;}
+		
+		result.setData(jtBusinessService.getCategoryById(id));
+		return result;
+	}
 	/*
 	/*
 	 * 
 	 * 
 	 * 新增品類
 	 * 新增品類
@@ -36,6 +71,33 @@ public class AdminJtBusinessController extends CertifyApiController{
 		if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,"));
 		if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,"));
 		return result;
 		return result;
 	}
 	}
+	
+	/*
+	 * 修改
+	 * */
+	@RequestMapping(value="/category/update",method=RequestMethod.POST)
+	private Result updateCategory(JtBusinessCategory jtBusinessCategory) {
+		Result result=new Result();
+		//只允许修改3种字段
+		JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory();
+		jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl());
+		jtBusinessCategory2.setName(jtBusinessCategory.getName());
+		jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary());
+		 result.setData(jtBusinessService.updateCategory(jtBusinessCategory2));
+		 return result;
+	}
+	
+	/*
+	 * 查询品类
+	 * 
+	 * */
+	@RequestMapping(value="/category/list",method=RequestMethod.GET)
+	private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
+		Result result=new Result();
+	
+		 result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
+		 return result;
+	}
 	private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
 	private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
 		if(jtBusinessCategory.getName() == null) {
 		if(jtBusinessCategory.getName() == null) {
 			result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
 			result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
@@ -54,4 +116,6 @@ public class AdminJtBusinessController extends CertifyApiController{
 		
 		
 		return ;
 		return ;
 	}
 	}
+	
+	
 }
 }

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

@@ -17,4 +17,7 @@ JtBusinessCategoryTree getCategoryTree(String id);
 List<JtBusinessCategoryBo>getCategoryBoList();
 List<JtBusinessCategoryBo>getCategoryBoList();
 Pagination<JtBusinessProject>getProjects(String topId,String secondId,String name,Integer pageSize,Integer pageNo); 
 Pagination<JtBusinessProject>getProjects(String topId,String secondId,String name,Integer pageSize,Integer pageNo); 
 int insertCategory(JtBusinessCategory jtBusinessCategory);
 int insertCategory(JtBusinessCategory jtBusinessCategory);
+int deleteCategoryById(String id);
+JtBusinessCategory getCategoryById(String id);
+int updateCategory(JtBusinessCategory jtBusinessCategory);
 }
 }

+ 8 - 0
src/main/java/com/goafanti/business/service/JtBusinessServiceWithCategoryMapper.java

@@ -0,0 +1,8 @@
+package com.goafanti.business.service;
+
+import com.goafanti.common.model.JtBusinessCategory;
+import com.goafanti.core.mybatis.page.Pagination;
+
+public interface JtBusinessServiceWithCategoryMapper {
+	Pagination<JtBusinessCategory>getCategoryListByCondition(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize);
+}

+ 39 - 0
src/main/java/com/goafanti/business/service/impl/JtBusinessServiceImpl.java

@@ -125,5 +125,44 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 		jtBusinessCategory.setId(UUID.randomUUID().toString());
 		jtBusinessCategory.setId(UUID.randomUUID().toString());
 		return jtBusinessCategoryMapper.insertSelective(jtBusinessCategory);
 		return jtBusinessCategoryMapper.insertSelective(jtBusinessCategory);
 	}
 	}
+
+	@Override
+	public int deleteCategoryById(String id) {
+		// TODO Auto-generated method stub
+		return jtBusinessCategoryMapper.deleteByPrimaryKey(id);
+	}
+
+	@Override
+	public JtBusinessCategory getCategoryById(String id) {
+		// TODO Auto-generated method stub
+		return jtBusinessCategoryMapper.selectByPrimaryKey(id);
+	}
+
+	@Override
+	public int updateCategory(JtBusinessCategory jtBusinessCategory) {
+		// TODO Auto-generated method stub
+		return jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
+	}
+
+	
+	
+	private Map<String, Object> disposeCategoryParams(String name,Integer layer ) {
+		Map<String, Object> params = new HashMap<>();
+
+		if (layer!=null) {
+			params.put("layer", layer);
+		}
+
+	
+
+	
+		if (StringUtils.isNotBlank(name)) {
+			params.put("name", name);
+		}
+
+		
+		return params;
+	}
+
 	
 	
 }
 }

+ 46 - 0
src/main/java/com/goafanti/business/service/impl/JtBusinessServiceWithCategoryMapperImpl.java

@@ -0,0 +1,46 @@
+package com.goafanti.business.service.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.stereotype.Service;
+
+import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper;
+import com.goafanti.common.dao.JtBusinessCategoryMapper;
+import com.goafanti.common.model.JtBusinessCategory;
+import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
+
+@Service
+public class JtBusinessServiceWithCategoryMapperImpl   extends BaseMybatisDao<JtBusinessCategoryMapper> implements JtBusinessServiceWithCategoryMapper{
+		@SuppressWarnings("unchecked")
+		@Override
+		public Pagination<JtBusinessCategory> getCategoryListByCondition(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
+			
+			Map<String, Object>params=disposeCategoryParams(jtBusinessCategory.getName(), jtBusinessCategory.getLayer());
+			if(pageNo==null ||pageNo<1)pageNo=1;
+			if(pageSize==null ||pageSize<1)pageSize=10;
+			// TODO Auto-generated method stub
+			return (Pagination<JtBusinessCategory>)findPage("getCategoryListByCondition", "getCategoryCountByCondition", params, pageNo, pageSize);
+		}
+		
+		private Map<String, Object> disposeCategoryParams(String name,Integer layer ) {
+			Map<String, Object> params = new HashMap<>();
+
+			if (layer!=null) {
+				params.put("layer", layer);
+			}
+
+		
+
+		
+			if (StringUtils.isNotBlank(name)) {
+				params.put("name", name);
+			}
+
+			
+			return params;
+		}
+
+}

+ 30 - 0
src/main/java/com/goafanti/common/mapper/JtBusinessCategoryMapper.xml

@@ -430,4 +430,34 @@ sort=sort+1
 where sort > #{1}
 where sort > #{1}
 and layer=#{0}
 and layer=#{0}
   </update>
   </update>
+  
+    <select id="getCategoryListByCondition" resultType="com.goafanti.common.model.JtBusinessCategoryResult">
+   select bc1.id,bc1.sort,bc1.number,bc1.name,bc1.super_id as superId,bc1.layer,bc2.name as superName
+    from jt_business_category bc1
+    left join jt_business_category bc2 on bc2.id=bc1.super_id
+    where 
+    1=1 
+    <if test="layer!=null">
+    and bc1.layer=#{layer,jdbcType=INTEGER}</if>
+    <if test="name!=null">
+    and bc1.name like concat("%",#{name,jdbcType=VARCHAR},"%")
+    </if>
+   <if test="page_sql!=null">
+		${page_sql}
+	</if>
+    </select>
+    
+    <select id="getCategoryCountByCondition" resultType="java.lang.Integer">
+    select
+    count(0)
+      from jt_business_category bc1
+    left join jt_business_category bc2 on bc2.id=bc1.super_id
+    where 
+    1=1 
+    <if test="layer!=null">
+    and bc1.layer=#{layer,jdbcType=INTEGER}</if>
+    <if test="name!=null">
+    and bc1.name like concat("%",#{name,jdbcType=VARCHAR},"%")
+    </if>
+    </select>
 </mapper>
 </mapper>

+ 30 - 0
src/main/java/com/goafanti/common/model/JtBusinessCategoryResult.java

@@ -0,0 +1,30 @@
+package com.goafanti.common.model;
+
+public class JtBusinessCategoryResult extends JtBusinessCategory {
+String superName;
+String layerName;
+public String getSuperName() {
+	return superName;
+}
+public void setSuperName(String superName) {
+	this.superName = superName;
+}
+public String getLayerName() {
+	return layerName;
+}
+public void setLayerName(String layerName) {
+	this.layerName = layerName;
+}
+@Override
+	public void setLayer(Integer layer) {
+		// TODO Auto-generated method stub
+		super.setLayer(layer);
+		if(layer==1) {
+			setLayerName("一级");
+		}
+		else if(layer==2)
+		{
+			setLayerName("二级");
+		}
+	}
+}