|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package cc.hiver.shop.controller; |
|
|
|
|
|
|
|
import cc.hiver.core.common.constant.CommonConstant; |
|
|
|
import cc.hiver.core.common.utils.ResultUtil; |
|
|
|
import cc.hiver.core.common.vo.Result; |
|
|
|
import cc.hiver.shop.entity.GoodsCategory; |
|
|
|
@ -9,10 +10,9 @@ import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@RestController |
|
|
|
@ -23,6 +23,14 @@ public class GoodsCategoryController { |
|
|
|
@Autowired |
|
|
|
private GoodsCategoryService goodsCategoryService; |
|
|
|
|
|
|
|
@RequestMapping(value = "/getByParentId/{parentId}", method = RequestMethod.GET) |
|
|
|
@ApiOperation(value = "通过parentId获取") |
|
|
|
public Result<List<GoodsCategory>> getByParentId(@PathVariable String parentId) { |
|
|
|
List<GoodsCategory> list = goodsCategoryService.findByParentIdOrderBySortOrder(parentId); |
|
|
|
setInfo(list); |
|
|
|
return new ResultUtil<List<GoodsCategory>>().setData(list); |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST) |
|
|
|
@ApiOperation(value = "保存数据") |
|
|
|
public Result<GoodsCategory> save(GoodsCategory entity) { |
|
|
|
@ -38,4 +46,16 @@ public class GoodsCategoryController { |
|
|
|
} |
|
|
|
return ResultUtil.success("批量通过id删除数据成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public void setInfo(List<GoodsCategory> list) { |
|
|
|
// lambda表达式
|
|
|
|
list.forEach(item -> { |
|
|
|
if (!CommonConstant.PARENT_ID.equals(item.getParentId())) { |
|
|
|
GoodsCategory parent = goodsCategoryService.get(item.getParentId()); |
|
|
|
item.setParentTitle(parent.getCategoryName()); |
|
|
|
} else { |
|
|
|
item.setParentTitle("一级分类"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|