在线商城

This commit is contained in:
zjf committed 2025-06-19 21:00:40 +08:00
1 parent fff39aba27
commit d5b84caca8
14 files changed
+225 -7

No files matched your search

@@ -0,0 +1,16 @@
package com.bsd.pjcloud.supermarket.vo;
import lombok.Data;
import java.util.List;
@Data
public class ShopCategoryTreeVo {
private Long id;
private String name;
private Long parentId;
private Integer level;
private Integer sort;
private Integer status;
private String picUrl;
private List<ShopCategoryTreeVo> children;
}
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.supermarket.vo.app;
import lombok.Data;
@Data
public class ShopSkuAppVo {
private Long id;
private String skuName;
private Integer price;
private Integer stock;
}
@@ -0,0 +1,16 @@
package com.bsd.pjcloud.supermarket.vo.app;
import lombok.Data;
import java.util.List;
@Data
public class ShopSpuDetailAppVo {
private Long id;
private String productName;
private String picUrl;
private String subTitle;
private String detail;
private Integer categoryId;
private Integer status;
private List<ShopSkuAppVo> skuList;
}
@@ -0,0 +1,15 @@
package com.bsd.pjcloud.supermarket.vo.app;
import lombok.Data;
@Data
public class ShopSpuListAppVo {
private Long id;
private String productName;
private String picUrl;
private String subTitle;
private Integer categoryId;
private Integer status;
private Integer sales;
private Integer price;
}
@@ -0,0 +1,44 @@
package com.bsd.pjcloud.supermarket.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.supermarket.entity.ShopCategoryEntity;
import com.bsd.pjcloud.supermarket.service.ShopCategoryService;
import com.bsd.pjcloud.supermarket.vo.ShopCategoryTreeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/app/shopCategory")
@Tag(name = "App分类", description = "移动端分类接口")
@RequiredArgsConstructor
public class AppShopCategoryController {
private final ShopCategoryService shopCategoryService;
@GetMapping("/list")
@Operation(summary = "APP分类列表", description = "移动端分类树")
public R<List<ShopCategoryTreeVo>> appCategoryList() {
List<ShopCategoryEntity> all = shopCategoryService.list(Wrappers.<ShopCategoryEntity>lambdaQuery()
.eq(ShopCategoryEntity::getStatus, 0)); // 只查启用
List<ShopCategoryTreeVo> tree = buildCategoryTree(all, 0L);
return R.ok(tree);
}
private List<ShopCategoryTreeVo> buildCategoryTree(List<ShopCategoryEntity> all, Long parentId) {
List<ShopCategoryTreeVo> result = new java.util.ArrayList<>();
for (ShopCategoryEntity cat : all) {
if (Objects.equals(cat.getParentId(), parentId)) {
ShopCategoryTreeVo vo = com.bsd.pjcloud.common.core.util.BeanUtils.toBean(cat, ShopCategoryTreeVo.class);
vo.setChildren(buildCategoryTree(all, cat.getId()));
result.add(vo);
}
}
return result;
}
}
@@ -0,0 +1,60 @@
package com.bsd.pjcloud.supermarket.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.supermarket.entity.ShopSpuEntity;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.service.ShopSpuService;
import com.bsd.pjcloud.supermarket.service.ShopSkuService;
import com.bsd.pjcloud.supermarket.vo.app.ShopSpuListAppVo;
import com.bsd.pjcloud.supermarket.vo.app.ShopSpuDetailAppVo;
import com.bsd.pjcloud.supermarket.vo.app.ShopSkuAppVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/app/shopSpu")
@Tag(name = "App商品", description = "移动端商品接口")
@RequiredArgsConstructor
public class AppShopSpuController {
private final ShopSpuService shopSpuService;
private final ShopSkuService shopSkuService;
@GetMapping("/page")
@Operation(summary = "APP商品分页", description = "移动端商品分页")
public R<IPage<ShopSpuListAppVo>> page(
@ParameterObject Page page,
@RequestParam(required = false) Integer categoryId,
@RequestParam(required = false) String keyword
) {
LambdaQueryWrapper<ShopSpuEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(categoryId != null, ShopSpuEntity::getCategoryId, categoryId);
wrapper.like(StrUtil.isNotBlank(keyword), ShopSpuEntity::getProductName, keyword);
wrapper.eq(ShopSpuEntity::getStatus, 0); // 只查上架
IPage<ShopSpuEntity> spuPage = shopSpuService.page(page, wrapper);
IPage<ShopSpuListAppVo> voPage = spuPage.convert(spu -> BeanUtils.toBean(spu, ShopSpuListAppVo.class));
return R.ok(voPage);
}
@GetMapping("/detail/{id}")
@Operation(summary = "APP商品详情", description = "移动端商品详情")
public R<ShopSpuDetailAppVo> detail(@PathVariable("id") Long id) {
ShopSpuEntity spu = shopSpuService.getByIdDeep(id);
if (spu == null) return R.failed("商品不存在");
ShopSpuDetailAppVo vo = BeanUtils.toBean(spu, ShopSpuDetailAppVo.class);
// 查询sku列表
List<ShopSkuEntity> skuList = shopSkuService.list(Wrappers.<ShopSkuEntity>lambdaQuery().eq(ShopSkuEntity::getSpuId, id));
vo.setSkuList(skuList.stream().map(sku -> BeanUtils.toBean(sku, ShopSkuAppVo.class)).collect(Collectors.toList()));
return R.ok(vo);
}
}
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.supermarket.entity.ShopCategoryEntity;
import com.bsd.pjcloud.supermarket.entity.SmErpSupplierEntity;
import com.bsd.pjcloud.supermarket.service.ShopCategoryService;
@@ -54,7 +55,7 @@ public class ShopCategoryController {
public R getShopCategoryPage(@ParameterObject Page page, @ParameterObject ShopCategoryEntity shopCategory) {
LambdaQueryWrapper<ShopCategoryEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(shopCategory.getName()),ShopCategoryEntity::getName,shopCategory.getName());
return R.ok(shopCategoryService.page(page, wrapper));
return R.ok(shopCategoryService.pageScope(page, wrapper));
}
@@ -80,6 +81,7 @@ public class ShopCategoryController {
@PostMapping
@PreAuthorize("@pms.hasPermission('supermarket_shopCategory_add')" )
public R save(@RequestBody ShopCategoryEntity shopCategory) {
shopCategory.setDeptId(SecurityUtils.getUser().getDeptId());
return R.ok(shopCategoryService.save(shopCategory));
}
@@ -129,12 +131,12 @@ public class ShopCategoryController {
@GetMapping("/tree")
@Operation(summary = "分类树", description = "获取所有分类的树结构")
public R<List<ShopCategoryTreeVo>> tree() {
List<ShopCategoryEntity> all = shopCategoryService.list();
List<ShopCategoryTreeVo> tree = buildCategoryTree(all, 0);
List<ShopCategoryEntity> all = shopCategoryService.listScope();
List<ShopCategoryTreeVo> tree = buildCategoryTree(all, 0L);
return R.ok(tree);
}
private List<ShopCategoryTreeVo> buildCategoryTree(List<ShopCategoryEntity> all, Integer parentId) {
private List<ShopCategoryTreeVo> buildCategoryTree(List<ShopCategoryEntity> all, Long parentId) {
List<ShopCategoryTreeVo> result = new java.util.ArrayList<>();
for (ShopCategoryEntity cat : all) {
if (Objects.equals(cat.getParentId(), parentId)) {
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.supermarket.entity.ShopSpuEntity;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.service.ShopSpuService;
@@ -50,7 +51,7 @@ public class ShopSpuController {
public R getShopSpuPage(@ParameterObject Page page, @ParameterObject ShopSpuEntity shopSpu) {
LambdaQueryWrapper<ShopSpuEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(shopSpu.getProductName()),ShopSpuEntity::getProductName,shopSpu.getProductName());
return R.ok(shopSpuService.page(page, wrapper));
return R.ok(shopSpuService.pageScope(page, wrapper));
}
/**
@@ -75,6 +76,7 @@ public class ShopSpuController {
@PostMapping
@PreAuthorize("@pms.hasPermission('supermarket_shopSpu_add')" )
public R save(@RequestBody ShopSpuEntity shopSpu) {
shopSpu.setDeptId(SecurityUtils.getUser().getDeptId());
return R.ok(shopSpuService.saveDeep(shopSpu));
}
@@ -27,13 +27,13 @@ public class ShopCategoryEntity extends Model<ShopCategoryEntity> {
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="id")
private Integer id;
private Long id;
/**
* 父级分类ID,0为顶级
*/
@Schema(description="父级分类ID,0为顶级")
private Integer parentId;
private Long parentId;
/**
* 分类名称
@@ -1,8 +1,27 @@
package com.bsd.pjcloud.supermarket.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.supermarket.entity.ShopCategoryEntity;
import java.util.List;
public interface ShopCategoryService extends IService<ShopCategoryEntity> {
/**
* 列表,条件当前权限
* @return
*/
List<ShopCategoryEntity> listScope();
/**
* 分页,条件当前权限
* @param page
* @param wrapper
* @return
*/
Object pageScope(Page page, LambdaQueryWrapper<ShopCategoryEntity> wrapper);
}
@@ -1,5 +1,7 @@
package com.bsd.pjcloud.supermarket.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.extension.mapping.base.MPJDeepService;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.entity.ShopSpuEntity;
@@ -13,4 +15,11 @@ public interface ShopSpuService extends MPJDeepService<ShopSpuEntity> {
Boolean removeChild(Long[] ids);
/**
* 分页查询
* @param page
* @param wrapper
* @return
*/
Object pageScope(Page page, LambdaQueryWrapper<ShopSpuEntity> wrapper);
}
@@ -1,10 +1,16 @@
package com.bsd.pjcloud.supermarket.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.supermarket.entity.ShopCategoryEntity;
import com.bsd.pjcloud.supermarket.mapper.ShopCategoryMapper;
import com.bsd.pjcloud.supermarket.service.ShopCategoryService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 在线商品分类
*
@@ -13,4 +19,14 @@ import org.springframework.stereotype.Service;
*/
@Service
public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, ShopCategoryEntity> implements ShopCategoryService {
@Override
public List<ShopCategoryEntity> listScope() {
return baseMapper.selectListByScope(null, DataScope.of());
}
@Override
public Object pageScope(Page page, LambdaQueryWrapper<ShopCategoryEntity> wrapper) {
return baseMapper.selectPageByScope(page, wrapper, DataScope.of());
}
}
@@ -1,6 +1,9 @@
package com.bsd.pjcloud.supermarket.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.supermarket.entity.ShopSpuEntity;
import com.bsd.pjcloud.supermarket.mapper.ShopSpuMapper;
import com.bsd.pjcloud.supermarket.service.ShopSpuService;
@@ -64,4 +67,9 @@ public class ShopSpuServiceImpl extends ServiceImpl<ShopSpuMapper, ShopSpuEntity
shopSkuMapper.deleteBatchIds(CollUtil.toList(ids));
return Boolean.TRUE;
}
@Override
public Object pageScope(Page page, LambdaQueryWrapper<ShopSpuEntity> wrapper) {
return baseMapper.selectPageByScope(page, wrapper, DataScope.of());
}
}