@@ -0,0 +1,44 @@ | |||
package com.tuoheng.api.controller; | |||
import com.tuoheng.api.entity.request.GoodsQuery; | |||
import com.tuoheng.api.service.IGoodsService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* 商品表 前端控制器 | |||
* | |||
* @author WangHaoran | |||
* @since 2023-11-03 | |||
*/ | |||
@RestController | |||
@RequestMapping("/goods") | |||
public class GoodsController { | |||
@Autowired | |||
IGoodsService goodsService; | |||
/** | |||
* 获取商品列表(分页) | |||
* | |||
* @param goodsQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(GoodsQuery goodsQuery) { | |||
return goodsService.queryPage(goodsQuery); | |||
} | |||
/** | |||
* 获取商铺信息 | |||
* | |||
* @param goodsQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/merchantInfo") | |||
public JsonResult merchantInfo(GoodsQuery goodsQuery) { | |||
return goodsService.merchantInfo(goodsQuery); | |||
} | |||
} |
@@ -0,0 +1,82 @@ | |||
package com.tuoheng.api.entity.domain; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
import java.io.Serializable; | |||
/** | |||
* 商品表 | |||
* | |||
* @author WangHaoran | |||
* @since 2023-11-06 | |||
*/ | |||
@Data | |||
@Accessors(chain = true) | |||
@TableName("th_goods") | |||
public class Goods extends BaseEntity implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 租户ID | |||
*/ | |||
private Integer tenantId; | |||
/** | |||
* 商户ID | |||
*/ | |||
private Integer merchantId; | |||
/** | |||
* 商品名称 | |||
*/ | |||
private String goodsName; | |||
/** | |||
* 商品图片 | |||
*/ | |||
private String goodsImage; | |||
/** | |||
* 商品类型id | |||
*/ | |||
private Integer goodsTypeId; | |||
/** | |||
* 商品类型名称 | |||
*/ | |||
@TableField(exist = false) | |||
private String goodsTypeName; | |||
/** | |||
* 商品规格 | |||
*/ | |||
private String goodsSpec; | |||
/** | |||
* 商品积分 | |||
*/ | |||
private Integer goodsPoints; | |||
/** | |||
* 商品详情图片 | |||
*/ | |||
private String goodsDetailImage; | |||
/** | |||
* 商品状态:0下架 1正常 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 商铺信息 | |||
*/ | |||
@TableField(exist = false) | |||
private Merchant merchant; | |||
} |
@@ -0,0 +1,33 @@ | |||
package com.tuoheng.api.entity.request; | |||
import com.tuoheng.common.common.BaseQuery; | |||
import lombok.Data; | |||
@Data | |||
public class GoodsQuery extends BaseQuery { | |||
/** | |||
* 商户ID | |||
*/ | |||
private Integer merchantId; | |||
/** | |||
* 商品名称 | |||
*/ | |||
private String goodsName; | |||
/** | |||
* 商品类型id | |||
*/ | |||
private Integer goodsTypeId; | |||
/** | |||
* 租户ID | |||
*/ | |||
private Integer tenantId; | |||
/** | |||
* 用户openid | |||
*/ | |||
private String openid; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.api.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.api.entity.domain.Goods; | |||
/** | |||
* 商品表 | |||
* | |||
* @author WangHaoran | |||
* @since 2023-11-07 | |||
*/ | |||
public interface GoodsMapper extends BaseMapper<Goods> { | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.api.service; | |||
import com.tuoheng.api.entity.domain.Goods; | |||
import com.tuoheng.api.entity.request.GoodsQuery; | |||
import com.tuoheng.common.common.IBaseService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
public interface IGoodsService extends IBaseService<Goods> { | |||
JsonResult queryPage(GoodsQuery goodsQuery); | |||
JsonResult merchantInfo(GoodsQuery goodsQuery); | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.tuoheng.api.service.impl; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.api.entity.domain.Goods; | |||
import com.tuoheng.api.entity.domain.Merchant; | |||
import com.tuoheng.api.entity.request.GoodsQuery; | |||
import com.tuoheng.api.mapper.GoodsMapper; | |||
import com.tuoheng.api.mapper.MerchantMapper; | |||
import com.tuoheng.api.service.IGoodsService; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
import com.tuoheng.common.utils.CommonUtils; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
@Slf4j | |||
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService { | |||
@Autowired | |||
private GoodsMapper goodsMapper; | |||
@Autowired | |||
private MerchantMapper merchantMapper; | |||
@Override | |||
public JsonResult queryPage(GoodsQuery goodsQuery) { | |||
if (null == goodsQuery.getPage() || null == goodsQuery.getLimit()) { | |||
return JsonResult.error("参数为空!"); | |||
} | |||
if(null == goodsQuery.getTenantId()){ | |||
return JsonResult.error("租户ID为空!"); | |||
} | |||
// 获取分页数据 | |||
IPage<Goods> page = new Page<>(goodsQuery.getPage(), goodsQuery.getLimit()); | |||
IPage<Goods> pageData = goodsMapper.selectPage(page, new LambdaQueryWrapper<Goods>() | |||
.eq(Goods::getMark, 1) | |||
.eq(Goods::getStatus, 1) | |||
.eq(Goods::getTenantId, goodsQuery.getTenantId()) | |||
.like(StringUtils.isNotEmpty(goodsQuery.getGoodsName()), Goods::getGoodsName, goodsQuery.getGoodsName()) | |||
.orderByDesc(Goods::getCreateTime)); | |||
for (Goods record : pageData.getRecords()) { | |||
if(StringUtils.isNotEmpty(record.getGoodsImage())){ | |||
record.setGoodsImage(CommonUtils.getMultipleUrl(record.getGoodsImage())); | |||
} | |||
if(StringUtils.isNotEmpty(record.getGoodsDetailImage())){ | |||
record.setGoodsDetailImage(CommonUtils.getMultipleUrl(record.getGoodsDetailImage())); | |||
} | |||
} | |||
return JsonResult.success(pageData); | |||
} | |||
@Override | |||
public JsonResult merchantInfo(GoodsQuery goodsQuery) { | |||
if(null == goodsQuery.getMerchantId()){ | |||
return JsonResult.error("商户ID为空!"); | |||
} | |||
Merchant merchant = merchantMapper.selectById(goodsQuery.getMerchantId()); | |||
if(ObjectUtil.isNull(merchant)){ | |||
return JsonResult.error("商户信息为空!"); | |||
} | |||
if(StringUtils.isNotEmpty(merchant.getShopsImage())){ | |||
merchant.setShopsImage(CommonUtils.getImageURL(merchant.getShopsImage())); | |||
} | |||
return JsonResult.success(merchant); | |||
} | |||
} |