首页水果分页查询完善+购物车模块
This commit is contained in:
parent
0736256395
commit
4a2a77e59a
@ -8,7 +8,7 @@
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
//移动端商城API
|
||||
let domain = 'http://192.168.2.123:8084'
|
||||
let domain = 'http://192.168.2.192:8084'
|
||||
|
||||
module.exports = {
|
||||
// 请求域名 格式: https://您的域名
|
||||
|
||||
@ -31,12 +31,12 @@ spring:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
username: crmeb
|
||||
password: 111111
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
password:
|
||||
password: 111111
|
||||
timeout: 10000 # 连接超时时间(毫秒)
|
||||
database: 3 #默认数据库
|
||||
jedis:
|
||||
|
||||
@ -25,12 +25,12 @@ spring:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
username: crmeb
|
||||
password: 111111
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
password:
|
||||
password: 111111
|
||||
timeout: 10000 # 连接超时时间(毫秒)
|
||||
database: 10 #默认数据库
|
||||
jedis:
|
||||
|
||||
@ -25,12 +25,12 @@ spring:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
username: crmeb
|
||||
password: 1111111
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
password:
|
||||
password: 111111
|
||||
timeout: 10000 # 连接超时时间(毫秒)
|
||||
database: 15 #默认数据库
|
||||
jedis:
|
||||
|
||||
@ -7,7 +7,7 @@ crmeb:
|
||||
wechat-js-api-beta: true #微信js api是否是beta版本
|
||||
asyncConfig: false #是否同步config表数据到redis
|
||||
asyncWeChatProgramTempList: false #是否同步小程序公共模板库
|
||||
imagePath: /当前项目更根目录的素材文件(绝对路径)/crmebimage/ # 服务器图片路径配置 斜杠结尾
|
||||
imagePath: /idea/shopping2/crmeb_java/crmeb/crmeb/crmebimage/ # 服务器图片路径配置 斜杠结尾
|
||||
database: mysql
|
||||
|
||||
# 配置端口
|
||||
@ -41,7 +41,6 @@ spring:
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
|
||||
@ -52,10 +52,11 @@ public class CartController {
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name="isValid", value="类型,true-有效商品,false-无效商品", required = true),
|
||||
@ApiImplicitParam(name="page", value="页码", required = true),
|
||||
@ApiImplicitParam(name="limit", value="每页数量", required = true)
|
||||
@ApiImplicitParam(name="limit", value="每页数量", required = true),
|
||||
@ApiImplicitParam(name="keyword", value="搜索关键词", required = false)
|
||||
})
|
||||
public CommonResult<CommonPage<CartInfoResponse>> getList(@RequestParam Boolean isValid, @Validated PageParamRequest pageParamRequest) {
|
||||
CommonPage<CartInfoResponse> restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid));
|
||||
public CommonResult<CommonPage<CartInfoResponse>> getList(@RequestParam Boolean isValid, @RequestParam String keyword,@Validated PageParamRequest pageParamRequest) {
|
||||
CommonPage<CartInfoResponse> restPage = CommonPage.restPage(storeCartService.getList(pageParamRequest, isValid,keyword));
|
||||
return CommonResult.success(restPage);
|
||||
}
|
||||
|
||||
|
||||
@ -10,13 +10,11 @@ import com.zbkj.common.response.IndexProductResponse;
|
||||
import com.zbkj.front.service.IndexService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -68,9 +66,17 @@ public class IndexController {
|
||||
*/
|
||||
@ApiOperation(value = "首页水果列表")
|
||||
@RequestMapping(value = "/pagelist/product/{searchStatus}", method = RequestMethod.GET)
|
||||
@ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 团购结束 】", dataType = "String", required = true)
|
||||
public CommonResult<CommonPage<IndexProductResponse>> getProductList(@PathVariable(value = "searchStatus") String searchStatus, PageParamRequest pageParamRequest) {
|
||||
return CommonResult.success(indexService.findIndexFruitList(searchStatus, pageParamRequest));
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "searchStatus", value = "搜索类型 【0 售卖中 1 预售 2 结束】", dataType = "String", required = true),
|
||||
@ApiImplicitParam(name = "keyword", value = "搜索关键词", dataType = "String")
|
||||
})
|
||||
public CommonResult<List<IndexProductResponse>> getProductList(
|
||||
@PathVariable(value = "searchStatus") String searchStatus,
|
||||
@RequestParam(value = "keyword", required = false) String keyword,
|
||||
PageParamRequest pageParamRequest) {
|
||||
//分页
|
||||
CommonPage<IndexProductResponse> pageResult = indexService.findIndexFruitList(searchStatus, keyword, pageParamRequest);
|
||||
return CommonResult.success(pageResult.getList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -55,7 +55,7 @@ public interface IndexService{
|
||||
* @param pageParamRequest
|
||||
* @return
|
||||
*/
|
||||
CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest);
|
||||
CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, String keyword,PageParamRequest pageParamRequest);
|
||||
|
||||
/**
|
||||
* 获取颜色配置
|
||||
|
||||
@ -22,6 +22,7 @@ import com.zbkj.common.model.user.User;
|
||||
import com.zbkj.front.service.IndexService;
|
||||
import com.zbkj.service.delete.ProductUtils;
|
||||
import com.zbkj.service.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -43,6 +44,7 @@ import java.util.stream.Collectors;
|
||||
* | Author: CRMEB Team <admin@crmeb.com>
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IndexServiceImpl implements IndexService {
|
||||
|
||||
@ -197,24 +199,25 @@ public class IndexServiceImpl implements IndexService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, PageParamRequest pageParamRequest) {
|
||||
//在0,1,2搜索类型范围类
|
||||
public CommonPage<IndexProductResponse> findIndexFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) {
|
||||
// 验证searchStatus是否在允许的范围内
|
||||
if (!searchStatus.equals(Constants.INDEX_FRUIT_ONGOING)
|
||||
&& !searchStatus.equals(Constants.INDEX_FRUIT_BOOKING)
|
||||
&& !searchStatus.equals(Constants.INDEX_FRUIT_SETTLED)) {
|
||||
return CommonPage.restPage(new ArrayList<>());
|
||||
}
|
||||
//分页查询
|
||||
List<StoreProduct> fruitList = storeProductService.getFruitList(searchStatus, pageParamRequest);
|
||||
// 分页查询(传入keyword)
|
||||
List<StoreProduct> fruitList = storeProductService.getFruitList(searchStatus, keyword, pageParamRequest);
|
||||
log.info("fruitList: {}", fruitList);//crmebimage/public/maintain/2025/04/25/juzi.jpg
|
||||
// 查出来为空
|
||||
if(CollUtil.isEmpty(fruitList)) {
|
||||
return CommonPage.restPage(new ArrayList<>());
|
||||
}
|
||||
//转换为响应对象:将 List<StoreProduct> 转换为 List<IndexProductResponse>
|
||||
// 转换为响应对象
|
||||
List<IndexProductResponse> responseList = fruitList.stream()
|
||||
.map(this::convertToIndexProductResponse)
|
||||
.collect(Collectors.toList());
|
||||
// 4. 封装分页响应
|
||||
log.info("responseList: {}", responseList);
|
||||
return CommonPage.restPage(responseList);
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ spring:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_beta?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
password: 123456
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
|
||||
@ -15,7 +15,7 @@ spring:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java_dev?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
password: 123456
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
|
||||
@ -15,7 +15,7 @@ spring:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/crmeb_java?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
|
||||
username: root
|
||||
password: z2003m10L15
|
||||
password: 123456
|
||||
redis:
|
||||
host: 127.0.0.1 #地址
|
||||
port: 6379 #端口
|
||||
|
||||
@ -32,7 +32,7 @@ public interface StoreCartService extends IService<StoreCart> {
|
||||
* @param isValid 是否失效
|
||||
* @return 购物车列表
|
||||
*/
|
||||
PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid);
|
||||
PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid,String keyword);
|
||||
|
||||
/**
|
||||
* 获取当前购物车数量
|
||||
|
||||
@ -160,7 +160,7 @@ public interface StoreProductService extends IService<StoreProduct> {
|
||||
* @param pageParamRequest
|
||||
* @return
|
||||
*/
|
||||
List<StoreProduct> getFruitList(String searchStatus, PageParamRequest pageParamRequest);
|
||||
List<StoreProduct> getFruitList(String searchStatus,String keyword, PageParamRequest pageParamRequest);
|
||||
|
||||
/**
|
||||
* 获取商品移动端列表
|
||||
|
||||
@ -75,73 +75,67 @@ public class StoreCartServiceImpl extends ServiceImpl<StoreCartDao, StoreCart> i
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param pageParamRequest 分页类参数
|
||||
* @param isValid 是否失效
|
||||
* @return List<CartInfoResponse>
|
||||
* 购物车分页查询
|
||||
* @param pageParam
|
||||
* @param isValid
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageInfo<CartInfoResponse> getList(PageParamRequest pageParamRequest, boolean isValid) {
|
||||
public PageInfo<CartInfoResponse> getList(PageParamRequest pageParam, boolean isValid,String keyword) {
|
||||
// 1. 当前用户ID
|
||||
Integer userId = userService.getUserIdException();
|
||||
Page<StoreCart> page = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
||||
//带 StoreCart 类的多条件查询
|
||||
LambdaQueryWrapper<StoreCart> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(StoreCart::getUid, userId);
|
||||
lambdaQueryWrapper.eq(StoreCart::getStatus, isValid);
|
||||
lambdaQueryWrapper.eq(StoreCart::getIsNew, false);
|
||||
lambdaQueryWrapper.orderByDesc(StoreCart::getId);
|
||||
List<StoreCart> storeCarts = dao.selectList(lambdaQueryWrapper);
|
||||
if (CollUtil.isEmpty(storeCarts)) {
|
||||
return CommonPage.copyPageInfo(page, new ArrayList<>());
|
||||
// 2. 构建查询条件
|
||||
LambdaQueryWrapper<StoreCart> query = new LambdaQueryWrapper<StoreCart>()
|
||||
.eq(StoreCart::getUid, userId) //where userid = #{userid}
|
||||
.orderByDesc(StoreCart::getId);//购物车表里商品id
|
||||
// 3. 按有效性筛选(可选)
|
||||
// if (isValid != null) {
|
||||
// query.eq(StoreCart::getStatus, isValid);//筛选有效和失效商品
|
||||
// }
|
||||
// 4. 关键词搜索(支持商品名称模糊查询)
|
||||
if (StrUtil.isNotBlank(keyword)) {
|
||||
query.exists(
|
||||
"SELECT 1 FROM store_cart sc WHERE sc.product_id = id AND " +
|
||||
"(sc.product_id LIKE '%" + keyword + "%' OR " + // 按ID模糊查询
|
||||
"EXISTS (SELECT 1 FROM store_product sp WHERE sp.id = sc.product_id AND sp.store_name LIKE '%" + keyword + "%'))"
|
||||
);
|
||||
}
|
||||
|
||||
User user = userService.getInfo();
|
||||
SystemUserLevel userLevel = null;
|
||||
if (ObjectUtil.isNotNull(user) && user.getLevel() > 0) {
|
||||
userLevel = systemUserLevelService.getByLevelId(user.getLevel());
|
||||
// 5. 执行分页查询
|
||||
Page<StoreCart> page = PageHelper.startPage(pageParam.getPage(), pageParam.getLimit());
|
||||
List<StoreCart> cartItems = dao.selectList(query);
|
||||
// 6. 转换为响应对象
|
||||
List<CartInfoResponse> result = cartItems.stream().map(item -> {
|
||||
CartInfoResponse resp = new CartInfoResponse();
|
||||
BeanUtils.copyProperties(item, resp);
|
||||
// 设置商品基本信息
|
||||
StoreProduct product = storeProductService.getById(item.getProductId());
|
||||
if (product != null) {
|
||||
resp.setStoreName(product.getStoreName())
|
||||
.setImage(product.getImage());
|
||||
}
|
||||
|
||||
List<CartInfoResponse> response = new ArrayList<>();
|
||||
for (StoreCart storeCart : storeCarts) {
|
||||
CartInfoResponse cartInfoResponse = new CartInfoResponse();
|
||||
BeanUtils.copyProperties(storeCart, cartInfoResponse);
|
||||
// 获取商品信息
|
||||
StoreProduct storeProduct = storeProductService.getCartByProId(storeCart.getProductId());
|
||||
cartInfoResponse.setImage(storeProduct.getImage());
|
||||
cartInfoResponse.setStoreName(storeProduct.getStoreName());
|
||||
|
||||
if (!isValid) {// 失效商品直接掠过
|
||||
cartInfoResponse.setAttrStatus(false);
|
||||
response.add(cartInfoResponse);
|
||||
continue ;
|
||||
// 处理商品有效性
|
||||
if (Boolean.FALSE.equals(item.getStatus())) {
|
||||
resp.setAttrStatus(false); // 标记为失效商品
|
||||
return resp;
|
||||
}
|
||||
|
||||
// 获取对应的商品规格信息(只会有一条信息)
|
||||
List<StoreProductAttrValue> attrValueList = storeProductAttrValueService.getListByProductIdAndAttrId(storeCart.getProductId(),
|
||||
storeCart.getProductAttrUnique(), Constants.PRODUCT_TYPE_NORMAL);
|
||||
// 规格不存在即失效
|
||||
if (CollUtil.isEmpty(attrValueList)) {
|
||||
cartInfoResponse.setAttrStatus(false);
|
||||
response.add(cartInfoResponse);
|
||||
continue ;
|
||||
// 有效商品设置规格信息
|
||||
StoreProductAttrValue spec = storeProductAttrValueService.getOne(
|
||||
new LambdaQueryWrapper<StoreProductAttrValue>()
|
||||
.eq(StoreProductAttrValue::getProductId, item.getProductId())
|
||||
.eq(StoreProductAttrValue::getUnique, item.getProductAttrUnique())
|
||||
);
|
||||
if (spec != null) {
|
||||
resp.setAttrStatus(spec.getStock() > 0)
|
||||
.setStock(spec.getStock())
|
||||
.setPrice(spec.getPrice())
|
||||
.setSuk(spec.getSuk())
|
||||
.setImage(StrUtil.isBlank(spec.getImage()) ? resp.getImage() : spec.getImage());
|
||||
} else {
|
||||
resp.setAttrStatus(false); // 规格不存在则标记失效
|
||||
}
|
||||
StoreProductAttrValue attrValue = attrValueList.get(0);
|
||||
if (StrUtil.isNotBlank(attrValue.getImage())) {
|
||||
cartInfoResponse.setImage(attrValue.getImage());
|
||||
}
|
||||
cartInfoResponse.setAttrId(attrValue.getId());
|
||||
cartInfoResponse.setSuk(attrValue.getSuk());
|
||||
cartInfoResponse.setPrice(attrValue.getPrice());
|
||||
cartInfoResponse.setAttrId(attrValue.getId());
|
||||
cartInfoResponse.setAttrStatus(attrValue.getStock() > 0);
|
||||
cartInfoResponse.setStock(attrValue.getStock());
|
||||
if (ObjectUtil.isNotNull(userLevel)) {
|
||||
BigDecimal vipPrice = attrValue.getPrice().multiply(new BigDecimal(userLevel.getDiscount())).divide(new BigDecimal(100), 2 ,BigDecimal.ROUND_HALF_UP);
|
||||
cartInfoResponse.setVipPrice(vipPrice);
|
||||
}
|
||||
response.add(cartInfoResponse);
|
||||
}
|
||||
return CommonPage.copyPageInfo(page, response);
|
||||
return resp;
|
||||
}).collect(Collectors.toList());
|
||||
return CommonPage.copyPageInfo(page, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1156,15 +1156,21 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
|
||||
* @param pageParamRequest
|
||||
* @return
|
||||
*/
|
||||
public List<StoreProduct> getFruitList(String searchStatus, PageParamRequest pageParamRequest) {
|
||||
PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
||||
//使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。
|
||||
LambdaQueryWrapper<StoreProduct> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||
//选择返回字段,(其他字段不返回),减少数据传输量。
|
||||
public List<StoreProduct> getFruitList(String searchStatus, String keyword, PageParamRequest pageParamRequest) {
|
||||
PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());//分页
|
||||
LambdaQueryWrapper<StoreProduct> lambdaQueryWrapper = Wrappers.lambdaQuery();//使用 MyBatis-Plus 的 Lambda 表达式构建动态查询条件,避免硬编码字段名。
|
||||
// 选择返回字段(其他字段不返回),减少数据传输量。
|
||||
lambdaQueryWrapper.select(StoreProduct::getId, StoreProduct::getImage, StoreProduct::getStoreName,
|
||||
StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity,StoreProduct::getSize,StoreProduct::getDimensions);
|
||||
//根据 type 的值,添加不同的筛选条件(如 is_best=true 表示精品推荐商品)。
|
||||
StoreProduct::getPrice, StoreProduct::getOtPrice, StoreProduct::getActivity,
|
||||
StoreProduct::getSize, StoreProduct::getDimensions);
|
||||
// 基础条件:按searchStatus筛选
|
||||
lambdaQueryWrapper.eq(StoreProduct::getSearchStatus, searchStatus);//where searchStatus = ${searchStatus}
|
||||
// 添加关键词搜索条件(如果keyword不为空)
|
||||
if (StrUtil.isNotBlank(keyword)) {
|
||||
lambdaQueryWrapper.and(wrapper -> wrapper
|
||||
.like(StoreProduct::getStoreName, keyword) // 商品名称模糊匹配
|
||||
);
|
||||
}
|
||||
// 排序
|
||||
lambdaQueryWrapper.orderByDesc(StoreProduct::getBeginTime);
|
||||
return dao.selectList(lambdaQueryWrapper);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user