feat(手机端): 搜索模块

添加商品搜索功能
master
hequan_waynaqua 4 years ago
parent 078ea5977b
commit b96a4e7356

@ -0,0 +1,20 @@
package com.wayn.common.core.domain.vo;
import lombok.Data;
/**
* VO
*/
@Data
public class SearchVO {
private String keyword;
private Integer categoryId;
private Integer brandId;
private Boolean isNew;
private Boolean isHot;
}

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.core.domain.vo.SearchVO;
import java.util.List;
@ -20,4 +21,6 @@ public interface GoodsMapper extends BaseMapper<Goods> {
IPage<Goods> selectGoodsListPage(Page<Goods> page,Goods goods);
IPage<Goods> selectGoodsListPageByl2CateId(Page<Goods> page, List<Long> cateList);
List<Goods> searchResult(Page<SearchVO> page, SearchVO searchVO);
}

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.core.domain.vo.GoodsSaveRelatedVO;
import com.wayn.common.core.domain.vo.SearchVO;
import com.wayn.common.util.R;
import java.util.List;
@ -76,4 +77,6 @@ public interface IGoodsService extends IService<Goods> {
* @return r
*/
R selectListPageByCateIds(Page<Goods> page, List<Long> l2cateList);
List<Goods> searchResult(Page<SearchVO> page, SearchVO searchVO);
}

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wayn.common.constant.SysConstants;
import com.wayn.common.core.domain.shop.*;
import com.wayn.common.core.domain.vo.GoodsSaveRelatedVO;
import com.wayn.common.core.domain.vo.SearchVO;
import com.wayn.common.core.mapper.shop.GoodsMapper;
import com.wayn.common.core.service.shop.*;
import com.wayn.common.util.R;
@ -16,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
@ -86,7 +86,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
BigDecimal retailPrice = new BigDecimal(Integer.MAX_VALUE);
for (GoodsProduct product : products) {
BigDecimal productPrice = product.getPrice();
if (retailPrice.compareTo(productPrice) == 1) {
if (retailPrice.compareTo(productPrice) > 0) {
retailPrice = productPrice;
}
}
@ -109,7 +109,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
goodsProduct.setCreateTime(new Date());
}
// 判断启用默认选中的规格是否超过一个
if (Arrays.stream(products).filter(GoodsProduct::getDefaultSelected).collect(Collectors.toList()).size() > 1) {
if (Arrays.stream(products).filter(GoodsProduct::getDefaultSelected).count() > 1) {
return R.error("商品规格只能选择一个启用默认选中");
}
@ -155,7 +155,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
BigDecimal retailPrice = new BigDecimal(Integer.MAX_VALUE);
for (GoodsProduct product : products) {
BigDecimal productPrice = product.getPrice();
if (retailPrice.compareTo(productPrice) == 1) {
if (retailPrice.compareTo(productPrice) > 0) {
retailPrice = productPrice;
}
}
@ -175,7 +175,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
goodsProduct.setUpdateTime(new Date());
}
// 判断启用默认选中的规格是否超过一个
if (Arrays.stream(products).filter(GoodsProduct::getDefaultSelected).collect(Collectors.toList()).size() > 1) {
if (Arrays.stream(products).filter(GoodsProduct::getDefaultSelected).count() > 1) {
return R.error("商品规格只能选择一个启用默认选中");
}
@ -192,4 +192,9 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
public R selectListPageByCateIds(Page<Goods> page, List<Long> l2cateList) {
return R.success().add("goods", goodsMapper.selectGoodsListPageByl2CateId(page, l2cateList).getRecords());
}
@Override
public List<Goods> searchResult(Page<SearchVO> page, SearchVO searchVO) {
return goodsMapper.searchResult(page, searchVO);
}
}

@ -70,4 +70,20 @@
order by create_time desc
</where>
</select>
<select id="searchResult" resultMap="ShopGoodsResult">
<include refid="selectGoodsVo"/>
<where>
del_flag = 0
<if test="searchVO.keyword != null and searchVO.keyword != ''">
AND name like concat('%', #{searchVO.keyword}, '%')
</if>
<if test="searchVO.isNew != null and searchVO.isNew == true">
order by is_new desc
</if>
<if test="searchVO.isHot != null and searchVO.isHot == true">
order by is_hot desc
</if>
</where>
</select>
</mapper>

@ -0,0 +1,59 @@
package com.wayn.mobile.api.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.BaseController;
import com.wayn.common.core.domain.shop.Goods;
import com.wayn.common.core.domain.vo.SearchVO;
import com.wayn.common.core.service.shop.IGoodsService;
import com.wayn.common.util.R;
import com.wayn.mobile.api.domain.SearchHistory;
import com.wayn.mobile.api.service.ISearchHistoryService;
import com.wayn.mobile.framework.security.util.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author wayn
* @since 2020-09-23
*/
@RestController
@RequestMapping("search")
public class SearchController extends BaseController {
@Autowired
private IGoodsService iGoodsService;
@Autowired
private ISearchHistoryService iSearchHistoryService;
@GetMapping("result")
public R list(SearchVO searchVO) {
Long memberId = SecurityUtils.getUserId();
String keyword = searchVO.getKeyword();
Integer categoryId = searchVO.getCategoryId();
Boolean isHot = searchVO.getIsHot();
Boolean isNew = searchVO.getIsNew();
if (memberId != null && StringUtils.isNotEmpty(keyword)) {
SearchHistory searchHistory = new SearchHistory();
searchHistory.setCreateTime(LocalDateTime.now());
searchHistory.setUserId(memberId);
searchHistory.setKeyword(keyword);
iSearchHistoryService.save(searchHistory);
}
Page<SearchVO> page = getPage();
List<Goods> goods = iGoodsService.searchResult(page, searchVO);
return R.success().add("goods", goods);
}
}

@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*;
* @since 2020-09-23
*/
@RestController
@RequestMapping("search")
@RequestMapping("searchHistory")
public class SearchHistoryController extends BaseController {
@Autowired

Loading…
Cancel
Save