|
@@ -69,16 +69,19 @@ public class GoodsCategoryController {
|
|
|
@ApiOperation("分类列表,获取当前分类的下级分类,0代表获取所有1级分类")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "categoryId", value = "分类Id", required = true, paramType = "query"),
|
|
|
+ @ApiImplicitParam(name = "webSite", value = "站点", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "isSort", value = "是否排序:true-排序,false-不显示", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = "20", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "current", value = "当前页面位置", defaultValue = "1", paramType = "query")
|
|
|
})
|
|
|
@GetMapping("list")
|
|
|
public JsonResult<PageVO<GoodsCategoryListVO>> getList(HttpServletRequest request, @RequestParam(value = "categoryId") Integer categoryId,
|
|
|
+ @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite,
|
|
|
@RequestParam(value = "isSort", defaultValue = "false", required = false) Boolean isSort) {
|
|
|
PagerInfo pager = WebUtil.handlerPagerInfo(request);
|
|
|
GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
|
|
|
goodsCategoryExample.setPid(categoryId);
|
|
|
+ goodsCategoryExample.setWebSite(webSite);
|
|
|
if (isSort) {
|
|
|
goodsCategoryExample.setOrderBy("sort asc, create_time desc");
|
|
|
}
|
|
@@ -124,8 +127,12 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("二级商品分类列表")
|
|
|
@GetMapping("getSecondGoodsCategory")
|
|
|
- public JsonResult<List<FrontGoodsCategoryVO>> getSecondGoodsCategory(HttpServletRequest request){
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "webSite", value = "站点", paramType = "query")
|
|
|
+ })
|
|
|
+ public JsonResult<List<FrontGoodsCategoryVO>> getSecondGoodsCategory(HttpServletRequest request, @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
|
|
|
GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
|
|
|
+ goodsCategoryExample.setWebSite(webSite);
|
|
|
goodsCategoryExample.setGrade(GoodsCategoryConst.CATEGORY_GRADE_2);
|
|
|
List<GoodsCategory> goodsCategoryList = goodsCategoryModel.getGoodsCategoryList(goodsCategoryExample, null);
|
|
|
List<FrontGoodsCategoryVO> vos = new ArrayList<>();
|
|
@@ -148,8 +155,12 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("商品分类列表")
|
|
|
@GetMapping("newList")
|
|
|
- public JsonResult<List<FrontGoodsCategoryVO>> getNewList(HttpServletRequest request) {
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "webSite", value = "站点", paramType = "query")
|
|
|
+ })
|
|
|
+ public JsonResult<List<FrontGoodsCategoryVO>> getNewList(HttpServletRequest request,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
|
|
|
GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
|
|
|
+ goodsCategoryExample.setWebSite(webSite);
|
|
|
List<GoodsCategory> goodsCategoryList = goodsCategoryModel.getGoodsCategoryList(goodsCategoryExample, null);
|
|
|
List<FrontGoodsCategoryVO> vos = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(goodsCategoryList)) {
|
|
@@ -166,29 +177,33 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("获取商品分类树接口")
|
|
|
@ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "webSite", value = "站点", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "pId", value = "父分类id", paramType = "query", required = true),
|
|
|
@ApiImplicitParam(name = "grade", value = "查询层数", paramType = "query"),
|
|
|
})
|
|
|
@GetMapping("getCateTree")
|
|
|
public JsonResult<List<GoodsCategoryListVO>> getCateTree(HttpServletRequest request,
|
|
|
+ @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite,
|
|
|
@RequestParam(value = "pId") Integer pId,
|
|
|
@RequestParam(value = "grade") Integer grade) {
|
|
|
- return SldResponse.success(this.getGoodsCategoryTree(pId, grade));
|
|
|
+ return SldResponse.success(this.getGoodsCategoryTree(webSite, pId, grade));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品分类树
|
|
|
*
|
|
|
+ * @param webSite 站点
|
|
|
* @param pId 父id
|
|
|
* @param grade 获取级别,比如 pid=0,grade=3时,获取1、2、3级分类;pid=0,grade=2时,获取1、2级分类;pid=0,grade=1时,获取1级分类;
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<GoodsCategoryListVO> getGoodsCategoryTree(Integer pId, Integer grade) {
|
|
|
+ private List<GoodsCategoryListVO> getGoodsCategoryTree(String webSite, Integer pId, Integer grade) {
|
|
|
if (grade == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
|
|
|
goodsCategoryExample.setPid(pId);
|
|
|
+ goodsCategoryExample.setWebSite(webSite);
|
|
|
List<GoodsCategory> goodsCategoryList = goodsCategoryModel.getGoodsCategoryList(goodsCategoryExample, null);
|
|
|
if (CollectionUtils.isEmpty(goodsCategoryList)) {
|
|
|
return new ArrayList<>();
|
|
@@ -213,7 +228,7 @@ public class GoodsCategoryController {
|
|
|
//查询在售商品数
|
|
|
example.setState(GoodsConst.GOODS_STATE_UPPER);
|
|
|
vo.setOnSaleGoodsNum(goodsModel.getGoodsCount(example));
|
|
|
- vo.setChildren(getGoodsCategoryTree(goodsCategory.getCategoryId(), grade - 1));
|
|
|
+ vo.setChildren(getGoodsCategoryTree(webSite,goodsCategory.getCategoryId(), grade - 1));
|
|
|
this.dealGoodsCategoryBindBrandAndAttribute(vo);
|
|
|
vos.add(vo);
|
|
|
});
|
|
@@ -418,8 +433,9 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("获取商品分类列表接口")
|
|
|
@GetMapping("categoryList")
|
|
|
- public JsonResult<List<RankGoodsCategoryVO>> getCateTree(HttpServletRequest request) {
|
|
|
- return SldResponse.success(this.getGoodsCategoryList(0, 3));
|
|
|
+ @ApiImplicitParams(@ApiImplicitParam(name = "webSite", value = "站点", paramType = "query"))
|
|
|
+ public JsonResult<List<RankGoodsCategoryVO>> getCateTree(HttpServletRequest request,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
|
|
|
+ return SldResponse.success(this.getGoodsCategoryList(webSite, 0, 3));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -429,10 +445,11 @@ public class GoodsCategoryController {
|
|
|
* @param grade 获取级别,比如 pid=0,grade=3时,获取1、2、3级分类;pid=0,grade=2时,获取1、2级分类;pid=0,grade=1时,获取1级分类;
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<RankGoodsCategoryVO> getGoodsCategoryList(Integer pId, Integer grade) {
|
|
|
+ private List<RankGoodsCategoryVO> getGoodsCategoryList(String webSite,Integer pId, Integer grade) {
|
|
|
List<RankGoodsCategoryVO> vos = new ArrayList<>();
|
|
|
GoodsCategoryExample example = new GoodsCategoryExample();
|
|
|
example.setPid(pId);
|
|
|
+ example.setWebSite(webSite);
|
|
|
example.setQueryGrade(grade);
|
|
|
example.setOrderBy("sort asc, create_time desc");
|
|
|
List<GoodsCategory> goodsCategoryList = goodsCategoryModel.getGoodsCategoryList(example, null);
|
|
@@ -441,7 +458,7 @@ public class GoodsCategoryController {
|
|
|
}
|
|
|
goodsCategoryList.forEach(goodsCategory -> {
|
|
|
RankGoodsCategoryVO vo = new RankGoodsCategoryVO(goodsCategory);
|
|
|
- vo.setChildren(getGoodsCategoryList(goodsCategory.getCategoryId(), grade - 1));
|
|
|
+ vo.setChildren(getGoodsCategoryList(webSite,goodsCategory.getCategoryId(), grade - 1));
|
|
|
vos.add(vo);
|
|
|
});
|
|
|
return vos;
|
|
@@ -449,13 +466,15 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("初始化分类缓存")
|
|
|
@OperationLogger(option = "初始化分类缓存")
|
|
|
+ @ApiImplicitParams(@ApiImplicitParam(name = "webSite", value = "站点", paramType = "query"))
|
|
|
@GetMapping("categoryInit")
|
|
|
- public JsonResult categoryInit(HttpServletRequest request) {
|
|
|
+ public JsonResult categoryInit(HttpServletRequest request, @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
|
|
|
Admin admin = UserUtil.getUser(request, Admin.class);
|
|
|
|
|
|
//缓存一级分类信息
|
|
|
GoodsCategoryExample example = new GoodsCategoryExample();
|
|
|
example.setPid(0);
|
|
|
+ example.setWebSite(webSite);
|
|
|
example.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
example.setOrderBy("sort asc, create_time desc");
|
|
|
List<GoodsCategory> list = goodsCategoryModel.getGoodsCategoryList(example, null);
|
|
@@ -472,7 +491,7 @@ public class GoodsCategoryController {
|
|
|
vos.add(new FrontGoodsCategoryVO(goodsCategory));
|
|
|
}
|
|
|
//更新缓存中的数据
|
|
|
- stringRedisTemplate.opsForValue().set(RedisConst.GOODS_CATEGORY, JSONArray.toJSONString(vos));
|
|
|
+ stringRedisTemplate.opsForValue().set(RedisConst.GOODS_CATEGORY + "_" + webSite, JSONArray.toJSONString(vos));
|
|
|
}
|
|
|
|
|
|
//缓存全部分类信息
|
|
@@ -486,7 +505,7 @@ public class GoodsCategoryController {
|
|
|
}
|
|
|
vos.add(tree);
|
|
|
}
|
|
|
- stringRedisTemplate.opsForValue().set(RedisConst.FRONT_GOODS_CATEGORY, JSONArray.toJSONString(vos));
|
|
|
+ stringRedisTemplate.opsForValue().set(RedisConst.FRONT_GOODS_CATEGORY + "_" + webSite, JSONArray.toJSONString(vos));
|
|
|
}
|
|
|
return SldResponse.success("缓存更新成功");
|
|
|
}
|
|
@@ -553,14 +572,15 @@ public class GoodsCategoryController {
|
|
|
|
|
|
@ApiOperation("根据一级分类id获取二三级分类")
|
|
|
@ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "categoryId1", value = "一级分类Id", required = true)
|
|
|
+ @ApiImplicitParam(name = "categoryId1", value = "一级分类Id", required = true),
|
|
|
+ @ApiImplicitParam(name = "webSite", value = "站点")
|
|
|
})
|
|
|
@GetMapping("bottomCategory")
|
|
|
- public JsonResult<List<FrontGoodsCategoryVO>> bottomCategory(HttpServletRequest request, Integer categoryId1) {
|
|
|
+ public JsonResult<List<FrontGoodsCategoryVO>> bottomCategory(HttpServletRequest request, Integer categoryId1, @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
|
|
|
List<FrontGoodsCategoryVO> vos = new ArrayList<>();
|
|
|
|
|
|
//查询redis缓存
|
|
|
- String dataJson = stringRedisTemplate.opsForValue().get(RedisConst.FRONT_GOODS_CATEGORY);
|
|
|
+ String dataJson = stringRedisTemplate.opsForValue().get(RedisConst.FRONT_GOODS_CATEGORY + "_" + webSite);
|
|
|
if (!StringUtils.isEmpty(dataJson)) {
|
|
|
JSONArray jsonArray = JSONArray.parseArray(dataJson);
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
@@ -572,6 +592,7 @@ public class GoodsCategoryController {
|
|
|
for (int j = 0; j < array2.size(); j++) {
|
|
|
JSONObject object = array2.getJSONObject(j);
|
|
|
FrontGoodsCategoryVO categoryVO = new FrontGoodsCategoryVO();
|
|
|
+ categoryVO.setWebSite(object.getString("webSite"));
|
|
|
categoryVO.setCategoryId(object.getInteger("categoryId"));
|
|
|
categoryVO.setCategoryName(object.getString("categoryName"));
|
|
|
categoryVO.setPid(object.getInteger("pid"));
|