热门类目接口开发

This commit is contained in:
donqi 2022-08-11 16:51:44 +08:00
parent aac50b92ef
commit 6742b6d51d
4 changed files with 65 additions and 2 deletions

View File

@ -6,21 +6,27 @@ import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.text.Convert;
import com.ghy.common.enums.BusinessType;
import com.ghy.common.enums.ImgType;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.ShiroUtils;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsImgs;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsImgsService;
import com.ghy.web.pojo.vo.AppCategoryRequest;
import com.ghy.web.pojo.vo.HotCategoryResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Controller
@RequestMapping("goods/deptcategory")
@ -31,6 +37,9 @@ public class GoodsDeptCategoryController extends BaseController {
@Resource
DeptGoodsCategoryService deptGoodsCategoryService;
@Autowired
private GoodsImgsService goodsImgsService;
@RequiresPermissions("goods:deptcategory:view")
@GetMapping()
public String deptGoodsCategory() {
@ -94,6 +103,39 @@ public class GoodsDeptCategoryController extends BaseController {
}
@PostMapping("/app/hot/category")
@ResponseBody
public AjaxResult appHotCategory(@RequestBody DeptGoodsCategory deptGoodsCategory) {
try {
deptGoodsCategory.setIsHot(1);
deptGoodsCategory.setStatus(0);
List<DeptGoodsCategory> hotCategories = deptGoodsCategoryService.list(deptGoodsCategory);
List<HotCategoryResponse> responses = new ArrayList<HotCategoryResponse>();
for (DeptGoodsCategory hotCategory: hotCategories) {
// 查询展示的图片
GoodsImgs qryImgsObj = new GoodsImgs();
qryImgsObj.setRemark(hotCategory.getDeptGoodsCategoryId().toString());
qryImgsObj.setImgType(ImgType.HOT_CATEGORY_IMG.getId());
qryImgsObj.setGoodsId(0l);
List<GoodsImgs> goodsImgs = goodsImgsService.qryGoodsImgs(qryImgsObj);
hotCategory.setHotCategoryImgs(goodsImgs.stream().map(GoodsImgs::getImgUrl).collect(Collectors.toList()));
HotCategoryResponse hotCategoryResponse = new HotCategoryResponse();
BeanUtils.copyProperties(hotCategory, hotCategoryResponse);
hotCategoryResponse.setId(hotCategory.getDeptGoodsCategoryId());
hotCategoryResponse.setName(hotCategory.getGoodsCategoryName());
hotCategoryResponse.setDesc(hotCategory.getRemark());
hotCategoryResponse.setImgs(hotCategory.getHotCategoryImgs());
responses.add(hotCategoryResponse);
}
return AjaxResult.success(responses);
} catch (Exception e) {
logger.error(e.getMessage());
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
}
}
@RequiresPermissions("goods:deptcategory:edit")
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap) {

View File

@ -0,0 +1,18 @@
package com.ghy.web.pojo.vo;
import com.ghy.goods.domain.DeptGoodsCategory;
import lombok.Data;
import java.util.List;
/**
* @author ydq
* @date : 2022-08-11 15:27
*/
@Data
public class HotCategoryResponse extends DeptGoodsCategory {
private Long id;
private String name;
private String desc;
private List<String> imgs;
}

View File

@ -9,7 +9,8 @@ package com.ghy.common.enums;
public enum ImgType {
SWIPER_IMG(0, "轮播图"),
DESC_IMG(1, "详情图"),
FINISH_IMG(2, "完单图");
FINISH_IMG(2, "完单图"),
HOT_CATEGORY_IMG(3, "热门类目图");
private Integer id;
private String name;

View File

@ -56,4 +56,6 @@ public class DeptGoodsCategory extends GoodsCategory {
private List<DeptGoodsCategory> child;
private Boolean isAllNode;
private List<String> hotCategoryImgs;
}