新增商城端-热门商品接口

This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-06-07 10:33:11 +08:00
parent 87d81b0547
commit d0626c36b5
6 changed files with 65 additions and 4 deletions

View File

@ -17,10 +17,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@ -64,6 +61,32 @@ public class GoodsController extends BaseController {
return getDataTable(list);
}
@PostMapping("/hot/list")
@ResponseBody
public TableDataInfo hotList(Goods goods) {
DeptGoodsCategory deptGoodsCategory = new DeptGoodsCategory();
deptGoodsCategory.setDeptId(goods.getDeptId());
deptGoodsCategory.setIsHot(1);
deptGoodsCategory.setLevel(2);
List<DeptGoodsCategory> categoryList = deptGoodsCategoryService.list(deptGoodsCategory);
Collection<Long> ids = new ArrayList<>();
categoryList.forEach(category->{
ids.add(category.getGoodsCategoryId());
});
startPage();
List<Goods> list = goodsService.selectByCategoryIds(ids);
list.forEach(one->{
// 补全商品
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
one.setGoodsAreaList(goodsAreas);
// 补全商品类别
List<GoodsStandard> goodsStandards = goodsStandardService.selectByGoodsId(one.getGoodsId());
one.setGoodsStandardList(goodsStandards);
});
return getDataTable(list);
}
@PostMapping("/addGoods")
@ResponseBody

View File

@ -88,4 +88,12 @@ public interface GoodsMapper {
* @param ids 商品ID
*/
List<Goods> selectByIds(Collection<Long> ids);
/**
* 用类目ID批量查询
*
* @param ids 第三级类目ID
*/
List<Goods> selectByCategoryIds(Collection<Long> ids);
}

View File

@ -85,4 +85,12 @@ public interface GoodsService {
* @param ids 商品ID
*/
List<Goods> selectByIds(Collection<Long> ids);
/**
* 用第三级类目ID批量查询
*
* @param ids 类目ID
*/
List<Goods> selectByCategoryIds(Collection<Long> ids);
}

View File

@ -141,6 +141,11 @@ public class GoodsServiceImpl implements GoodsService {
return goodsMapper.selectByIds(ids);
}
@Override
public List<Goods> selectByCategoryIds(Collection<Long> ids) {
return goodsMapper.selectByCategoryIds(ids);
}
public int countUserGoodsById(Goods goods) {
//TODO 校验商品是否上架

View File

@ -130,6 +130,12 @@
<if test="status != null and status != ''">
AND gc.status = #{status}
</if>
<if test="level != null">
AND gc.level = #{level}
</if>
<if test="isHot != null">
AND dgc.is_hot = #{isHot}
</if>
</where>
</select>

View File

@ -85,6 +85,9 @@
<if test="goodsCode != null and goodsCode != ''">
AND goods_code like concat('%', #{goodsCode}, '%')
</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != ''">
AND dept_goods_category_id = #{deptGoodsCategoryId}
</if>
</where>
</select>
@ -126,4 +129,12 @@
#{ids}
</foreach>
</select>
<select id="selectByCategoryIds" resultMap="GoodsResult">
<include refid="selectGoods"/>
where dept_goods_category_id IN
<foreach collection="collection" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
</select>
</mapper>