Pad点餐后台配置接口
This commit is contained in:
@@ -4,18 +4,17 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.map.MapProxy;
|
import cn.hutool.core.map.MapProxy;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.ysk.cashier.dto.product.PadProductCategoryDTO;
|
import cn.ysk.cashier.dto.product.PadProductCategoryDTO;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbPadLayoutMapper;
|
import cn.ysk.cashier.mybatis.mapper.*;
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbPadProductCategoryDetailMapper;
|
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbPadProductCategoryMapper;
|
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbProductMapper;
|
|
||||||
import cn.ysk.cashier.mybatis.service.TbPadProductCategoryService;
|
import cn.ysk.cashier.mybatis.service.TbPadProductCategoryService;
|
||||||
import cn.ysk.cashier.pojo.product.TbPadLayout;
|
import cn.ysk.cashier.pojo.product.*;
|
||||||
import cn.ysk.cashier.pojo.product.TbPadProductCategory;
|
import cn.ysk.cashier.repository.product.TbProductSkuResultRepository;
|
||||||
import cn.ysk.cashier.pojo.product.TbPadProductCategoryDetail;
|
|
||||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
|
||||||
import cn.ysk.cashier.utils.PageUtil;
|
import cn.ysk.cashier.utils.PageUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -24,10 +23,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +42,10 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
private TbPadProductCategoryDetailMapper tbPadProductCategoryDetailMapper;
|
private TbPadProductCategoryDetailMapper tbPadProductCategoryDetailMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TbProductMapper tbProductMapper;
|
private TbProductMapper tbProductMapper;
|
||||||
|
@Resource
|
||||||
|
private TbProductSkuResultRepository productSkuResultRepository;
|
||||||
|
@Resource
|
||||||
|
private TbProducSkutMapper producSkutMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> findPage(Map<String, Object> params) {
|
public Map<String, Object> findPage(Map<String, Object> params) {
|
||||||
@@ -69,29 +69,107 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
if (padLayout == null) {
|
if (padLayout == null) {
|
||||||
throw new BadRequestException("引用的布局版式不存在");
|
throw new BadRequestException("引用的布局版式不存在");
|
||||||
}
|
}
|
||||||
Map<String,Object> params = new HashMap<>(2);
|
Map<String, Object> params = new HashMap<>(2);
|
||||||
params.put("id", id);
|
params.put("id", id);
|
||||||
params.put("shopId", entity.getShopId());
|
params.put("shopId", entity.getShopId());
|
||||||
List<PadProductCategoryDTO> list = baseMapper.findList(params);
|
List<PadProductCategoryDTO> list = baseMapper.findList(params);
|
||||||
PadProductCategoryDTO dto = list.get(0);
|
PadProductCategoryDTO dto = list.get(0);
|
||||||
if(entity.getProductCategoryId().longValue() == 0L){
|
if (entity.getProductCategoryId().longValue() == 0L) {
|
||||||
dto.setProductCategoryName("推荐菜");
|
dto.setProductCategoryName("推荐菜");
|
||||||
}
|
}
|
||||||
List<TbPadProductCategoryDetail> subList = tbPadProductCategoryDetailMapper.selectList(Wrappers.<TbPadProductCategoryDetail>lambdaQuery().eq(TbPadProductCategoryDetail::getPadProductCategoryId, entity.getId()));
|
List<TbPadProductCategoryDetail> subList = tbPadProductCategoryDetailMapper.selectList(Wrappers.<TbPadProductCategoryDetail>lambdaQuery().eq(TbPadProductCategoryDetail::getPadProductCategoryId, entity.getId()));
|
||||||
if(CollUtil.isNotEmpty(subList)){
|
if (CollUtil.isNotEmpty(subList)) {
|
||||||
List<Long> productIdList = subList.stream().map(TbPadProductCategoryDetail::getProductId).collect(Collectors.toList());
|
List<Long> productIdList = subList.stream().map(TbPadProductCategoryDetail::getProductId).collect(Collectors.toList());
|
||||||
dto.setProductIdList(productIdList);
|
dto.setProductIdList(productIdList);
|
||||||
List<List<Long>> splitIdList = CollUtil.split(productIdList, 10);
|
List<List<Long>> splitIdList = CollUtil.split(productIdList, 10);
|
||||||
List<TbProduct> productList = dto.getProductList();
|
List<TbProduct> productList = dto.getProductList();
|
||||||
for (List<Long> ids : splitIdList) {
|
for (List<Long> ids : splitIdList) {
|
||||||
List<TbProduct> splitList = tbProductMapper.selectList(Wrappers.<TbProduct>lambdaQuery().in(TbProduct::getId, ids));
|
List<TbProduct> splitList = tbProductMapper.selectList(Wrappers.<TbProduct>lambdaQuery().in(TbProduct::getId, ids));
|
||||||
productList.addAll(splitList);
|
for (TbProduct item : splitList) {
|
||||||
|
TbProductSkuResult skuResult = productSkuResultRepository.findById(item.getId()).orElse(null);
|
||||||
|
item.setSkuResult(skuResult);
|
||||||
|
List<Map<String, Object>> maps = buildSpecList(skuResult, item);
|
||||||
|
item.setSpecList(maps);
|
||||||
|
productList.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dto.setProductList(productList);
|
dto.setProductList(productList);
|
||||||
}
|
}
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> buildSpecList(TbProductSkuResult skuResult, TbProduct item) {
|
||||||
|
List<Map<String, Object>> specList = new ArrayList<>();
|
||||||
|
List<TbProductSku> tbProductSkus = producSkutMapper.selectList(new LambdaQueryWrapper<TbProductSku>().eq(TbProductSku::getIsDel, 0)
|
||||||
|
.eq(TbProductSku::getIsPauseSale, 0)
|
||||||
|
.eq(TbProductSku::getProductId, item.getId())
|
||||||
|
.eq(TbProductSku::getIsGrounding, 1)
|
||||||
|
.select(TbProductSku::getId, TbProductSku::getSpecSnap, TbProductSku::getStockNumber, TbProductSku::getSalePrice, TbProductSku::getSuit));
|
||||||
|
|
||||||
|
String tagSnap = null;
|
||||||
|
if (skuResult != null) {
|
||||||
|
tagSnap = skuResult.getTagSnap();
|
||||||
|
}
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(tagSnap)) {
|
||||||
|
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||||
|
List<List<String>> valuesList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 提取所有 value 的列表
|
||||||
|
for (int i = 0; i < tagSnaps.size(); i++) {
|
||||||
|
JSONObject jsonObject = tagSnaps.getJSONObject(i);
|
||||||
|
String[] values = jsonObject.getString("value").split(",");
|
||||||
|
valuesList.add(Arrays.asList(values));
|
||||||
|
}
|
||||||
|
// 生成所有可能的排列组合
|
||||||
|
generateCombinations(valuesList, 0, new ArrayList<>(), result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tbProductSkus.forEach(item2 -> {
|
||||||
|
Map<String, Object> itemMap = BeanUtil.beanToMap(item2, false, true);
|
||||||
|
|
||||||
|
itemMap.put("stockNumber", item.getStockNumber());
|
||||||
|
|
||||||
|
specList.add(itemMap);
|
||||||
|
});
|
||||||
|
|
||||||
|
ArrayList<HashMap<String, Object>> otherVal = new ArrayList<>();
|
||||||
|
for (String res : result) {
|
||||||
|
boolean found = false;
|
||||||
|
for (Map<String, Object> spec : specList) {
|
||||||
|
if (spec.get("specSnap") != null && res.equals(spec.get("specSnap").toString())) {
|
||||||
|
spec.put("isGrounding", true);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
HashMap<String, Object> itemMap = new HashMap<>();
|
||||||
|
itemMap.put("specSnap", res);
|
||||||
|
itemMap.put("skuId", null);
|
||||||
|
itemMap.put("isGrounding", false);
|
||||||
|
otherVal.add(itemMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
specList.addAll(otherVal);
|
||||||
|
return specList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateCombinations(List<List<String>> valuesList, int index, List<String> current, List<String> result) {
|
||||||
|
if (index == valuesList.size()) {
|
||||||
|
result.add(String.join(",", current));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String value : valuesList.get(index)) {
|
||||||
|
current.add(value);
|
||||||
|
generateCombinations(valuesList, index + 1, current, result);
|
||||||
|
current.remove(current.size() - 1); // 回溯
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(PadProductCategoryDTO dto) {
|
public void save(PadProductCategoryDTO dto) {
|
||||||
@@ -122,7 +200,7 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
if (padLayout == null) {
|
if (padLayout == null) {
|
||||||
throw new BadRequestException("引用的布局版式不存在");
|
throw new BadRequestException("引用的布局版式不存在");
|
||||||
}
|
}
|
||||||
if(padLayout.getDelFlag() == 1) {
|
if (padLayout.getDelFlag() == 1) {
|
||||||
throw new BadRequestException("引用的布局版式已停用");
|
throw new BadRequestException("引用的布局版式已停用");
|
||||||
}
|
}
|
||||||
Integer maximum = padLayout.getMaximum();
|
Integer maximum = padLayout.getMaximum();
|
||||||
@@ -177,7 +255,7 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
if (padLayout == null) {
|
if (padLayout == null) {
|
||||||
throw new BadRequestException("引用的布局版式不存在");
|
throw new BadRequestException("引用的布局版式不存在");
|
||||||
}
|
}
|
||||||
if(padLayout.getDelFlag() == 1) {
|
if (padLayout.getDelFlag() == 1) {
|
||||||
throw new BadRequestException("引用的布局版式已停用");
|
throw new BadRequestException("引用的布局版式已停用");
|
||||||
}
|
}
|
||||||
Integer maximum = padLayout.getMaximum();
|
Integer maximum = padLayout.getMaximum();
|
||||||
@@ -188,7 +266,7 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new BadRequestException("id对应的数据不存在");
|
throw new BadRequestException("id对应的数据不存在");
|
||||||
}
|
}
|
||||||
BeanUtil.copyProperties(dto, entity,"createTime");
|
BeanUtil.copyProperties(dto, entity, "createTime");
|
||||||
entity.setUpdateTime(new Date());
|
entity.setUpdateTime(new Date());
|
||||||
super.updateById(entity);
|
super.updateById(entity);
|
||||||
for (Long productId : productIdList) {
|
for (Long productId : productIdList) {
|
||||||
@@ -204,7 +282,7 @@ public class TbPadProductCategoryServiceImpl extends ServiceImpl<TbPadProductCat
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void sort(List<PadProductCategoryDTO> sortList) {
|
public void sort(List<PadProductCategoryDTO> sortList) {
|
||||||
if(CollUtil.isEmpty(sortList)) {
|
if (CollUtil.isEmpty(sortList)) {
|
||||||
throw new BadRequestException("排序列表不能为空");
|
throw new BadRequestException("排序列表不能为空");
|
||||||
}
|
}
|
||||||
for (PadProductCategoryDTO dto : sortList) {
|
for (PadProductCategoryDTO dto : sortList) {
|
||||||
|
|||||||
@@ -15,18 +15,21 @@
|
|||||||
*/
|
*/
|
||||||
package cn.ysk.cashier.pojo.product;
|
package cn.ysk.cashier.pojo.product;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
@@ -329,6 +332,14 @@ public class TbProduct implements Serializable {
|
|||||||
@ApiModelProperty("库存警戒线")
|
@ApiModelProperty("库存警戒线")
|
||||||
private Integer warnLine = 0;
|
private Integer warnLine = 0;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@TableField(exist = false)
|
||||||
|
private TbProductSkuResult skuResult;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Map<String, Object>> specList;
|
||||||
|
|
||||||
|
|
||||||
public void copy(TbProduct source){
|
public void copy(TbProduct source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
|||||||
Reference in New Issue
Block a user