在线点餐h5接口

This commit is contained in:
zjf committed 2025-01-07 15:16:27 +08:00
1 parent 7684b22c7c
commit 7fb6fbea0d
14 files changed
+458 -1

No files matched your search

@@ -0,0 +1,45 @@
/*
*
* Copyright (c) 2018-2025, pjcloud All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: pjcloud
*
*/
package com.bsd.pjcloud.canteen.api.feign;
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.core.util.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author zjf
* @date 2018/6/22
*/
@FeignClient(contextId = "remoteCanteenOnlineCategoryService", value = ServiceNameConstants.CANTEEN_SERVICE)
public interface RemoteCanteenOnlineCategoryService {
/**
* 查询所有的菜品分类
* @param merchantId 商户id
* @return R
*/
@GetMapping("/canteenOnlineCategory/app/getAllSimple")
R getAllSimple(@RequestParam(value = "merchantId")Long merchantId);
}
@@ -0,0 +1,67 @@
/*
*
* Copyright (c) 2018-2025, pjcloud All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: pjcloud
*
*/
package com.bsd.pjcloud.canteen.api.feign;
import com.bsd.pjcloud.canteen.dto.CanteenSpuUpdateStockReqDTO;
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.core.util.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @author zjf
* @date 2018/6/22
*/
@FeignClient(contextId = "remoteOnlineCanteenSpuService", value = ServiceNameConstants.CANTEEN_SERVICE)
public interface RemoteOnlineCanteenSpuService {
/**
* 获取菜品列表
* @param categoryId 不填默认查全部
* @return
*/
@GetMapping("/canteenOnlineSpu/app/getCanteenSpuList")
R getCanteenSpuList(@RequestParam(value = "categoryId",required = false)String categoryId);
/**
* 扣减菜品库存
* @param updateStockReqDTO
* @return
*/
@PostMapping("/canteenOnlineSpu/app/updateSkuStock")
R getAllSimple(@RequestBody CanteenSpuUpdateStockReqDTO updateStockReqDTO);
/**
* 根据ids查询菜品
* @return ids
*/
@PostMapping("/canteenOnlineSpu/app/getSpuListByIds")
R getSpuListByIds(@RequestBody List<Long> ids);
}
@@ -0,0 +1,47 @@
package com.bsd.pjcloud.canteen.dto;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 商品 SKU 更新库存 Request DTO
*
* @author LeeYan9
* @since 2022-08-26
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CanteenOnlineSpuUpdateStockReqDTO {
/**
* 商品 SKU
*/
@NotNull(message = "商品 SPU 不能为空")
private List<Item> items;
@Data
public static class Item {
/**
* 商品 SKU 编号
*/
@NotNull(message = "商品 SPU 编号不能为空")
private Long id;
/**
* 库存变化数量
*
* 正数:增加库存
* 负数:扣减库存
*/
@NotNull(message = "库存变化数量不能为空")
private Integer incrCount;
}
}
@@ -0,0 +1,129 @@
package com.bsd.pjcloud.canteen.vo;
import com.baomidou.mybatisplus.annotation.*;
import com.bsd.pjcloud.common.core.util.MoneyDeserializer;
import com.bsd.pjcloud.common.core.util.MoneySerializer;
import com.bsd.pjcloud.common.core.util.TenantTable;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 在线点餐spu
*
* @author zjf
* @date 2024-12-16 23:42:19
*/
@Data
@TenantTable
@Schema(description = "在线点餐vo")
public class APPOnlineSpuVO {
/**
* 商品 SPU 编号,自增
*/
@Schema(description="商品 SPU 编号,自增")
private Long id;
/**
* 商品名称
*/
@Schema(description="商品名称")
private String name;
/**
* 商品简介
*/
@Schema(description="商品简介")
private String introduction;
/**
* 商品详情
*/
@Schema(description="商品详情")
private String description;
/**
* 商品分类编号
*/
@Schema(description="商品分类编号")
private Long categoryId;
/**
* 商品封面图
*/
@Schema(description="商品封面图")
private String picUrl;
/**
* 商品轮播图地址
数组,以逗号分隔
最多上传15张
*/
@Schema(description="商品轮播图地址")
private String sliderPicUrls;
/**
* 排序字段
*/
@Schema(description="排序字段")
private Integer sort;
/**
* 商品价格,单位使用:分
*/
@Schema(description="商品价格")
@JsonSerialize(using = MoneySerializer.class) // 分 -> 元
@JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer price;
/**
* 市场价,单位使用:分
*/
@Schema(description="市场价")
@JsonSerialize(using = MoneySerializer.class) // 分 -> 元
@JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer marketPrice;
/**
* 库存
*/
@Schema(description="库存")
private Integer stock;
/**
* 商品销量
*/
@Schema(description="商品销量")
private Integer salesCount;
/**
* 商品点击量
*/
@Schema(description="商品点击量")
private Integer browseCount;
/**
* 商户编号
*/
@Schema(description="商户编号")
private Long merchantId;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
private LocalDateTime createTime;
}
@@ -123,6 +123,8 @@ public class CanteenCategoryController {
}
// -------------AD--------------------
/**
* 查询所有的菜品分类
* @param categoryType 餐段类型,1早餐 2中 3晚餐 不传默认所有
@@ -138,4 +140,8 @@ public class CanteenCategoryController {
List<CanteenCategoryEntity> list = canteenCategoryService.listScope(wrapper);
return R.ok(list);
}
}
@@ -6,10 +6,12 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.canteen.entity.CanteenCategoryEntity;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.canteen.entity.CanteenOnlineCategoryEntity;
import com.bsd.pjcloud.canteen.service.CanteenOnlineCategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -118,4 +120,24 @@ public class CanteenOnlineCategoryController {
public List<CanteenOnlineCategoryEntity> export(CanteenOnlineCategoryEntity canteenOnlineCategory,Long[] ids) {
return canteenOnlineCategoryService.list(Wrappers.lambdaQuery(canteenOnlineCategory).in(ArrayUtil.isNotEmpty(ids), CanteenOnlineCategoryEntity::getId, ids));
}
// ---------------APP---------------------
/**
* 查询菜品分类,根据商户id
* @return R
*/
@Operation(summary = "查询线上菜品分类,根据商户id" , description = "通过商户id查询" )
@GetMapping("/app/getAllSimple")
public R getAllSimple(@RequestParam(value = "merchantId")Long merchantId) {
LambdaQueryWrapper<CanteenOnlineCategoryEntity> wrapper = Wrappers.lambdaQuery();
wrapper.orderByAsc(CanteenOnlineCategoryEntity::getSort);
wrapper.eq(CanteenOnlineCategoryEntity::getMerchantId,merchantId);
// wrapper.apply(StringUtils.isNotEmpty(categoryType),"FIND_IN_SET({0}, your_column_name)",categoryType);
List<CanteenOnlineCategoryEntity> list = canteenOnlineCategoryService.list(wrapper);
return R.ok(list);
}
}
@@ -6,6 +6,9 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.canteen.dto.CanteenOnlineSpuUpdateStockReqDTO;
import com.bsd.pjcloud.canteen.dto.CanteenSpuUpdateStockReqDTO;
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
@@ -119,4 +122,40 @@ public class CanteenOnlineSpuController {
public List<CanteenOnlineSpuEntity> export(CanteenOnlineSpuEntity canteenOnlineSpu,Long[] ids) {
return canteenOnlineSpuService.list(Wrappers.lambdaQuery(canteenOnlineSpu).in(ArrayUtil.isNotEmpty(ids), CanteenOnlineSpuEntity::getId, ids));
}
// -------------APP---------------
/**
* 获取菜品列表
*
* @param categoryId 分类编号,不传默认查询全部
* @return
*/
@GetMapping("/app/getCanteenSpuList")
@Operation(summary = "获取在线点餐的菜品列表" , description = "1.通过分类id,可以不填,默认查全部,2.商户id,必传" )
public R getCanteenSpuList(@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "merchantId") String merchantId ) {
return canteenOnlineSpuService.getCanteenOnlineSpuList(categoryId,merchantId);
}
@PostMapping("/app/updateSkuStock")
@SysLog("更新菜品库存")
public R updateSkuStock(@RequestBody CanteenOnlineSpuUpdateStockReqDTO canteenOnlineSpuUpdateStockReqDTO) {
return canteenOnlineSpuService.updateOnlineSpuSkuStock(canteenOnlineSpuUpdateStockReqDTO);
}
/**
* 通过ids查询菜品spu
* @param ids ids
* @return R
*/
@Operation(summary = "通过ids查询" , description = "通过ids查询" )
@PostMapping("/ad/getSpuListByIds" )
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_view')" )
public R getByIds(@RequestBody List<Long> ids) {
return R.ok( canteenOnlineSpuService.list(new LambdaQueryWrapper<CanteenOnlineSpuEntity>().in(CanteenOnlineSpuEntity::getId,ids)));
}
}
@@ -133,7 +133,7 @@ public class CanteenSpuController {
}
// --------------APP-----------------
// --------------AD-----------------
/**
@@ -113,4 +113,10 @@ public class CanteenCategoryEntity extends Model<CanteenCategoryEntity> {
*/
@Schema(description="餐段类型")
private String categoryType;
/**
* 商家id
*/
@Schema(description = "商家id")
private Long merchantId;
}
@@ -106,4 +106,10 @@ public class CanteenOnlineCategoryEntity extends Model<CanteenOnlineCategoryEnti
*/
@Schema(description="租户编号")
private Long tenantId;
/**
* 商家id
*/
@Schema(description = "商家id")
private Long merchantId;
}
@@ -2,6 +2,10 @@ package com.bsd.pjcloud.canteen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.bsd.pjcloud.common.core.util.MoneyDeserializer;
import com.bsd.pjcloud.common.core.util.MoneySerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -83,12 +87,16 @@ public class CanteenOnlineSpuEntity extends Model<CanteenOnlineSpuEntity> {
* 商品价格,单位使用:分
*/
@Schema(description="商品价格,单位使用:分")
@JsonSerialize(using = MoneySerializer.class) // 分 -> 元
@JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer price;
/**
* 市场价,单位使用:分
*/
@Schema(description="市场价,单位使用:分")
@JsonSerialize(using = MoneySerializer.class) // 分 -> 元
@JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer marketPrice;
/**
@@ -1,5 +1,7 @@
package com.bsd.pjcloud.canteen.mapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
import org.apache.ibatis.annotations.Mapper;
@@ -8,4 +10,28 @@ import org.apache.ibatis.annotations.Mapper;
public interface CanteenOnlineSpuMapper extends PjcloudBaseMapper<CanteenOnlineSpuEntity> {
/**
* 更新商品 SPU 库存
*
* @param id 商品 SPU 编号
* @param incrCount 增加的库存数量
*/
default int updateStock(Long id, Integer incrCount) {
// 拼接 SQL
if (incrCount == 0) {
return 0;
}
String sql;
if (incrCount > 0) {
sql = " stock = stock + " + incrCount + ", sales_count = sales_count - " + incrCount;
} else {
sql = " stock = stock - " + Math.abs(incrCount) + ", sales_count = sales_count + " + Math.abs(incrCount);
}
// 执行更新
LambdaUpdateWrapper<CanteenOnlineSpuEntity> updateWrapper = new LambdaUpdateWrapper<CanteenOnlineSpuEntity>()
.setSql(sql)
.eq(CanteenOnlineSpuEntity::getId, id);
return update(null, updateWrapper);
}
}
@@ -1,8 +1,27 @@
package com.bsd.pjcloud.canteen.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.canteen.dto.CanteenOnlineSpuUpdateStockReqDTO;
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
import com.bsd.pjcloud.common.core.util.R;
public interface CanteenOnlineSpuService extends IService<CanteenOnlineSpuEntity> {
/**
* 根据分类id获取商品列表
* 根据商户id获取商品列表
* @param categoryId
* @param merchantId
* @return
*/
R getCanteenOnlineSpuList(String categoryId, String merchantId);
/**
* 修改商品库存
* @param canteenOnlineSpuUpdateStockReqDTO
* @return
*/
R updateOnlineSpuSkuStock(CanteenOnlineSpuUpdateStockReqDTO canteenOnlineSpuUpdateStockReqDTO);
}
@@ -1,10 +1,22 @@
package com.bsd.pjcloud.canteen.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.canteen.dto.CanteenOnlineSpuUpdateStockReqDTO;
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
import com.bsd.pjcloud.canteen.mapper.CanteenOnlineSpuMapper;
import com.bsd.pjcloud.canteen.service.CanteenOnlineSpuService;
import com.bsd.pjcloud.canteen.vo.ADCanteenSpuListVO;
import com.bsd.pjcloud.canteen.vo.APPOnlineSpuVO;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 在线点餐spu
*
@@ -13,4 +25,29 @@ import org.springframework.stereotype.Service;
*/
@Service
public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMapper, CanteenOnlineSpuEntity> implements CanteenOnlineSpuService {
@Override
public R getCanteenOnlineSpuList(String categoryId, String merchantId) {
LambdaQueryWrapper<CanteenOnlineSpuEntity> canteenOnlineSpuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
canteenOnlineSpuEntityLambdaQueryWrapper.eq(StringUtils.isNotEmpty(categoryId),CanteenOnlineSpuEntity::getCategoryId, categoryId);
canteenOnlineSpuEntityLambdaQueryWrapper.eq(CanteenOnlineSpuEntity::getMerchantId, merchantId);
List<CanteenOnlineSpuEntity> canteenSpuEntities = baseMapper.selectList(canteenOnlineSpuEntityLambdaQueryWrapper);
List<APPOnlineSpuVO> bean = BeanUtils.toBean(canteenSpuEntities, APPOnlineSpuVO.class);
return R.ok(bean);
}
@Override
public R updateOnlineSpuSkuStock(CanteenOnlineSpuUpdateStockReqDTO canteenOnlineSpuUpdateStockReqDTO) {
// 更新 SKU 库存
canteenOnlineSpuUpdateStockReqDTO.getItems().forEach(item -> {
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
if (item.getIncrCount() < 0) {
if (i == 0) {
R.failed("商品库存不足");
}
}
});
return R.ok();
}
}