ad菜品列表接口,库存扣减接口
This commit is contained in:
1 parent
b303ab26c0
commit
b0d8eb8694
10 files changed
+167
-22
No files matched your search
+42
@@ -0,0 +1,42 @@
|
||||
package com.bsd.pjcloud.canteen.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ADCanteenDailyMenuListVO {
|
||||
/**
|
||||
* 每日菜品id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* spuid
|
||||
*/
|
||||
private Long spuId;
|
||||
|
||||
/**
|
||||
* 菜品名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 商品价格,单位使用:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 菜品分类编号
|
||||
*/
|
||||
private Long categoryId;
|
||||
/**
|
||||
* 菜品封面图
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer stock;
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
private Integer hourType;
|
||||
}
|
||||
+10
@@ -171,4 +171,14 @@ public class CanteenDailyMenuController {
|
||||
}
|
||||
|
||||
|
||||
// ---------APP------------
|
||||
@GetMapping("/ad/getCanteenList")
|
||||
@SysLog("查询每日菜品列表")
|
||||
public R getCanteenList(@RequestParam("day") String day,
|
||||
@RequestParam(value = "hourType", required = false) Integer hourType,
|
||||
@RequestParam(value = "categoryId", required = false) Long categoryId) {
|
||||
|
||||
return R.ok(canteenDailyMenuService.getCanteenMenuList(day,hourType,categoryId));
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -128,10 +128,12 @@ public class CanteenSpuController {
|
||||
|
||||
|
||||
|
||||
@PostMapping("/updateSkuStock")
|
||||
@SysLog("更新库存")
|
||||
public R updateSkuStock(@RequestBody CanteenSpuUpdateStockReqDTO updateStockReqDTO){
|
||||
// --------------APP-----------------
|
||||
|
||||
|
||||
@PostMapping("/ad/updateSkuStock")
|
||||
@SysLog("更新菜品库存")
|
||||
public R updateSkuStock(@RequestBody CanteenSpuUpdateStockReqDTO updateStockReqDTO){
|
||||
return canteenSpuService.updateSkuStock(updateStockReqDTO);
|
||||
}
|
||||
}
|
||||
+11
@@ -15,4 +15,15 @@ public interface CanteenDailyMenuMapper extends PjcloudBaseMapper<CanteenDailyMe
|
||||
|
||||
List<DailyMenuVO> selectTimeFood(@Param("time") String time,@Param("merchantId") Long merchantId,
|
||||
@Param("categoryId") Long categoryId, DataScope dataScope);
|
||||
|
||||
|
||||
/**
|
||||
* ad查询菜品列表
|
||||
* @param day
|
||||
* @param hourType
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
Object getCanteenMenuList(@Param("day") String day,@Param("hourType") Integer hourType,
|
||||
@Param("categoryId") Long categoryId,DataScope dataScope);
|
||||
}
|
||||
+24
-3
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.canteen.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.bsd.pjcloud.canteen.dto.DailyMenuAll;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
@@ -12,7 +13,27 @@ import java.util.List;
|
||||
public interface CanteenSpuMapper extends PjcloudBaseMapper<CanteenSpuEntity> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新商品 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<CanteenSpuEntity> updateWrapper = new LambdaUpdateWrapper<CanteenSpuEntity>()
|
||||
.setSql(sql)
|
||||
.eq(CanteenSpuEntity::getId, id);
|
||||
return update(null, updateWrapper);
|
||||
}
|
||||
}
|
||||
+10
@@ -28,4 +28,14 @@ public interface CanteenDailyMenuService extends IService<CanteenDailyMenuEntity
|
||||
|
||||
|
||||
void saveToday(CanteenDailyMenuEntity canteenDailyMenu);
|
||||
|
||||
|
||||
/**
|
||||
* ad机获取每次菜品
|
||||
* @param day
|
||||
* @param hourType
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
Object getCanteenMenuList(String day, Integer hourType, Long categoryId);
|
||||
}
|
||||
+1
@@ -26,4 +26,5 @@ public interface CanteenSpuService extends IService<CanteenSpuEntity> {
|
||||
* @return
|
||||
*/
|
||||
R updateSkuStock(CanteenSpuUpdateStockReqDTO updateStockReqDTO);
|
||||
|
||||
}
|
||||
+7
@@ -88,4 +88,11 @@ public class CanteenDailyMenuServiceImpl extends ServiceImpl<CanteenDailyMenuMap
|
||||
// CookbookProductEvent productEvent = new CookbookProductEvent(this, eventDto);
|
||||
// eventPublisher.publishEvent(productEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Object getCanteenMenuList(String day, Integer hourType, Long categoryId) {
|
||||
return baseMapper.getCanteenMenuList(day, hourType, categoryId,DataScope.of());
|
||||
}
|
||||
}
|
||||
+19
-16
@@ -6,12 +6,16 @@ import com.bsd.pjcloud.canteen.dto.CanteenSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.canteen.dto.DailyMenuAll;
|
||||
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
|
||||
import com.bsd.pjcloud.canteen.mapper.CanteenSpuMapper;
|
||||
import com.bsd.pjcloud.canteen.service.CanteenDailyMenuService;
|
||||
import com.bsd.pjcloud.canteen.service.CanteenSpuService;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,32 +26,31 @@ import java.util.List;
|
||||
* @date 2024-12-10 12:51:53
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, CanteenSpuEntity> implements CanteenSpuService {
|
||||
|
||||
private final CanteenDailyMenuService coupleDailyMenuService;
|
||||
@Override
|
||||
public Object selectFoodList(LambdaQueryWrapper<CanteenSpuEntity> wrapper) {
|
||||
return baseMapper.selectListByScope(wrapper, DataScope.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public R updateSkuStock(CanteenSpuUpdateStockReqDTO updateStockReqDTO) {
|
||||
// 更新 SKU 库存
|
||||
// updateStockReqDTO.getItems().forEach(item -> {
|
||||
// int i = onlineFoodSpuMapper.updateStock(item.getId(), item.getIncrCount());
|
||||
// if (item.getIncrCount() < 0) {
|
||||
// if (i == 0) {
|
||||
// R.failed("商品库存不足");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // 更新 SPU 库存
|
||||
// List<OnlineFoodSkuDO> skus = onlineFoodSkuMapper.selectBatchIds(
|
||||
// convertSet(updateStockReqDTO.getItems(), OnlineFoodSkuUpdateStockReqDTO.Item::getId));
|
||||
// Map<Long, Integer> spuStockIncrCounts = FoodSkuConvert.INSTANCE.convertSpuStockMap(
|
||||
// updateStockReqDTO.getItems(), skus);
|
||||
// onlineFoodSpuService.updateSpuStock(spuStockIncrCounts);
|
||||
return null;
|
||||
updateStockReqDTO.getItems().forEach(item -> {
|
||||
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
|
||||
if (item.getIncrCount() < 0) {
|
||||
if (i == 0) {
|
||||
R.failed("商品库存不足");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+38
@@ -17,6 +17,18 @@
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="tenantId" column="tenant_id"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="adCanteenDailyMenuListVO" type="com.bsd.pjcloud.canteen.vo.ADCanteenDailyMenuListVO">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="spuId" column="spu_id"/>
|
||||
<result property="hourType" column="hour_type"/>
|
||||
<result property="price" column="price"/>
|
||||
<result property="categoryId" column="category_id"/>
|
||||
<result property="picUrl" column="pic_url"/>
|
||||
<result property="stock" column="stock"/>
|
||||
<result property="hourType" column="hour_type"/>
|
||||
</resultMap>
|
||||
<select id="selectTimeFood" resultType="com.bsd.pjcloud.canteen.vo.DailyMenuVO">
|
||||
SELECT
|
||||
sp.id,
|
||||
@@ -37,4 +49,30 @@
|
||||
And t.del_flag = 0
|
||||
</where>
|
||||
</select>
|
||||
<select id="getCanteenMenuList" resultType="java.lang.Object">
|
||||
SELECT
|
||||
sp.id as spuId,
|
||||
t.id,
|
||||
sp.name,
|
||||
sp.pic_url,
|
||||
t.hour_type,
|
||||
sp.price,
|
||||
sp.stock,
|
||||
sp.category_id
|
||||
FROM canteen_daily_menu t
|
||||
LEFT JOIN canteen_spu sp
|
||||
on t.spu_id=sp.id
|
||||
<where>
|
||||
sp.del_flag = 0 and t.del_flag = 0
|
||||
<if test="categoryId != null">
|
||||
AND sp.category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="hourType != null">
|
||||
AND t.hour_type = #{hourType}
|
||||
</if>
|
||||
<if test="day != null">
|
||||
AND t.start_time = #{day}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user