Commit 5a2dace9 by XiaHou

权星相关接口修复

parent 42d4737d
......@@ -2,6 +2,7 @@ package com.macro.mall.portal.controller.quanxing;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsProductAttributeCategory;
import com.macro.mall.service.quanxing.PmsProductAttributeCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@Api(tags = "权星小程序_商品分类相关接口", description = "商品属性分类管理")
@RequestMapping("/pmsProductAttributeCategory")
......@@ -27,4 +30,12 @@ public class PmsProductAttributeCategoryController {
@ApiParam("非必传 不传父级id 则查所有分类") @RequestParam("parentId")Long parentId){
return CommonResult.success(this.productAttributeCategoryService.getAttributeCategoryList(page,size,parentId));
}
@ApiOperation("根据名称查询分类 一级名称返回一条数据 二级名称返回二条数据 三级名称返回三条数据")
@RequestMapping(value = "/getAttributeCategoryListByName", method = RequestMethod.GET)
@ResponseBody
public CommonResult<List<PmsProductAttributeCategory>> getAttributeCategoryListByName(@ApiParam("分类名称") @RequestParam("name")String name){
return CommonResult.success(this.productAttributeCategoryService.getAtributeCategoryListByName(name));
}
}
......@@ -35,4 +35,11 @@ public interface PmsProductAttributeCategoryService {
*/
List<PmsProductAttributeCategory> getAttributeCategoryList(Integer pageSize, Integer pageNum, Long parentId);
/**
* 根据名字查询商品分类 如果一级返回一条数据 两级返回两条数据 三级返回三条数据
* @param name
* @return
*/
List<PmsProductAttributeCategory> getAtributeCategoryListByName(String name);
}
......@@ -158,4 +158,34 @@ public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttribu
return productAttributeCategoryMapper.selectByExample(pmsProductAttributeCategoryExample);
}
@Override
public List<PmsProductAttributeCategory> getAtributeCategoryListByName(String name){
//返回集合数据
List<PmsProductAttributeCategory> dataList = new ArrayList<>();
//example对象
PmsProductAttributeCategoryExample example = new PmsProductAttributeCategoryExample();
PmsProductAttributeCategoryExample.Criteria criteria = example.createCriteria();
criteria.andDeleteStatusEqualTo(0);//删除标识0 未删除 1已删除
criteria.andNameEqualTo(name);//传入名称
List<PmsProductAttributeCategory> ppacList1 = this.productAttributeCategoryMapper.selectByExample(example);
return this.getRecursiongList(dataList,ppacList1.get(0));
}
private List<PmsProductAttributeCategory> getRecursiongList(List<PmsProductAttributeCategory> list ,PmsProductAttributeCategory ppac){
if( ppac != null && ppac.getId() != null && ppac.getParentId() != null){//将查询的结果判断 父级Id是否为0 如果为0 则是1级分类 否则继续下查
list.add(ppac);
if(ppac.getParentId() != null && ppac.getParentId() != 0 ){ //如果父级id不为空 并且不为0 则根据父级id查询
this.productAttributeCategoryMapper.selectByPrimaryKey(ppac.getParentId());
//还要继续判断 如果还存在 递归调用
this.getRecursiongList(list,ppac);
}else{
return list;
}
}
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment