商品 添加称重商品 和 套餐商品

This commit is contained in:
wangw 2024-11-19 15:08:35 +08:00
parent e8dd3778ac
commit 53e7443817
6 changed files with 144 additions and 77 deletions

View File

@ -102,10 +102,13 @@ public class ListUtil {
}
public static<T> String listChangeString(List<T> listString){
return listString.stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
public static <T> String listToJsonString(List<T> list) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(list);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static String mapToString(Map<String, String> map) {

View File

@ -50,11 +50,6 @@ public class TbProduct implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
@Column(name = "`merchant_id`")
@ApiModelProperty(value = "商户Id")
private String merchantId = "PLANT_ID";
@Column(name = "`shop_id`")
@ApiModelProperty(value = "店铺id")
private String shopId;
@ -135,28 +130,16 @@ public class TbProduct implements Serializable {
private Integer isPauseSale = 0;
@Column(name = "`created_at`")
@ApiModelProperty(value = "createdAt")
@ApiModelProperty(value = "创建时间")
private Long createdAt;
@Column(name = "`updated_at`")
@ApiModelProperty(value = "updatedAt")
@ApiModelProperty(value = "更新时间")
private Long updatedAt;
@Column(name = "`furnish_meal`")
@ApiModelProperty(value = "支持堂食")
private Integer furnishMeal = 0;
@Column(name = "`furnish_express`")
@ApiModelProperty(value = "支持配送")
private Integer furnishExpress = 0;
@Column(name = "`furnish_draw`")
@ApiModelProperty(value = "支持自提")
private Integer furnishDraw = 0;
@Column(name = "`furnish_vir`")
@ApiModelProperty(value = "支持虚拟")
private Integer furnishVir = 0;
@Column(name = "`group_type`")
@ApiModelProperty(value = "套餐类型 0固定套餐 1可选套餐")
private Integer groupType;
@Column(name = "`group_snap`")
@ApiModelProperty(value = "套餐内容")
@ -194,6 +177,42 @@ public class TbProduct implements Serializable {
@ApiModelProperty("库存警戒线")
private Integer warnLine = 0;
@Column(name = "show_type")
@ApiModelProperty("堂食 table 自取 dine 配送 delivery 快递 express")
private String showType;
@Column(name = "weight")
@ApiModelProperty("称重 价格/千克")
private BigDecimal weight;
@Column(name = "is_temp_price")
@ApiModelProperty("是否允许临时改价")
private Integer isTempPrice = 0;
@Column(name = "day_limit")
@ApiModelProperty("日销售上限")
private Integer dayLimit = 0;
@Column(name = "single_order_limit")
@ApiModelProperty("每单销售上限")
private Integer singleOrderLimit = 0;
@Column(name = "single_people_limit")
@ApiModelProperty("每人销售上限")
private Integer singlePeopleLimit = 0;
@Column(name = "days")
@ApiModelProperty("周数组 周一,周二,周日")
private String days;
@Column(name = "start_time")
@ApiModelProperty("可用开始时间")
private String startTime;
@Column(name = "end_time")
@ApiModelProperty("可用结束时间")
private String endTime;
@Transient
@TableField(exist = false)
private TbProductSkuResult skuResult;

View File

@ -24,7 +24,7 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
@Query("SELECT product from TbProduct product where product.id in :productIds order by product.sort")
List<TbProduct> findByIds(List<Integer> productIds);
@Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true)
@Query(value = "update tb_product set status = -1 and is_del = 1 where id in :productIds",nativeQuery = true)
@Modifying
void updateByStatus(List<Integer> productIds);

View File

@ -2,6 +2,7 @@ package cn.ysk.cashier.service.impl.productimpl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.cons.domain.ViewConSku;
import cn.ysk.cashier.cons.repository.ViewConSkuRepository;
@ -29,6 +30,7 @@ import cn.ysk.cashier.service.TbPlatformDictService;
import cn.ysk.cashier.service.product.TbProductService;
import cn.ysk.cashier.service.shop.TbCouponCategoryService;
import cn.ysk.cashier.utils.*;
import cn.ysk.cashier.vo.ProductGroupVo;
import cn.ysk.cashier.vo.TbProductNewVo;
import cn.ysk.cashier.vo.TbProductVo;
import com.alibaba.fastjson.JSONArray;
@ -304,9 +306,6 @@ public class TbProductServiceImpl implements TbProductService {
public TbProductVo findByProductId(Integer id) throws Exception {
TbProduct tbProduct = tbProductRepository.findById(id).orElseGet(TbProduct::new);
//单位
// CompletableFuture<TbShopUnit> tbShopUnits = CompletableFuture.supplyAsync(() ->
// tbShopUnitRepository.searchUnit(Integer.valueOf(StringUtils.isEmpty(tbProduct.getUnitId()) ? null : tbProduct.getUnitId())));
//sku
CompletableFuture<List<TbProductSku>> tbProductSkus = CompletableFuture.supplyAsync(() ->
tbProductSkuRepository.searchSku(tbProduct.getId().toString()));
@ -314,24 +313,20 @@ public class TbProductServiceImpl implements TbProductService {
CompletableFuture<TbProductSpec> tbProductSpec = CompletableFuture.supplyAsync(() ->
tbProductSpecRepository.searchSpec(tbProduct.getSpecId()));
// Threads.call(tbShopUnits, tbProductSkus, tbProductSpec);
Threads.call(tbProductSkus, tbProductSpec);
//组装
TbProductVo tbProductVo = new TbProductVo();
// tbProductVo.setStockNumber(tbProduct.getStockNumber() == null ? 0.00 : tbProduct.getStockNumber());
tbProductVo.setCategoryId(StringUtils.isNotBlank(tbProduct.getCategoryId()) ? Integer.valueOf(tbProduct.getCategoryId()) : null);
//单位
// if (tbProduct.getUnitId() == null) {
// tbProductVo.setUnitId(null);
// tbProductVo.setUnitName(null);
// }
//套餐
if (tbProduct.getGroupSnap() == null) {
tbProductVo.setGroupSnap(new JSONArray());
} else {
tbProductVo.setGroupSnap(ListUtil.stringChangeList(tbProduct.getGroupSnap()));
}
BeanUtils.copyProperties(tbProduct, tbProductVo);
//套餐
if(tbProduct.getType().equals("package")){
if (tbProduct.getGroupSnap() == null) {
tbProductVo.setProGroupVo(null);
} else {
tbProductVo.setProGroupVo(JSONUtil.parseJSONStrTList(tbProduct.getGroupSnap(), ProductGroupVo.class));
}
}
tbProductVo.setStockNumber(Double.valueOf(tbProduct.getStockNumber()));
if (!org.apache.commons.lang3.StringUtils.isBlank(tbProduct.getImages())) {
tbProductVo.setImages(ListUtil.stringChangeList(tbProduct.getImages()));
@ -364,7 +359,7 @@ public class TbProductServiceImpl implements TbProductService {
Optional<TbProductSkuResult> skuResult = tbProductSkuResultRepository.findById(tbProductVo.getId());
tbProductVo.setSkuSnap(skuResult.get().getTagSnap());
}
if ("group".equals(tbProductVo.getTypeEnum())) {
if ("coupon".equals(tbProductVo.getType())) {
if (StringUtils.isNotBlank(tbProduct.getGroupCategoryId())) {
JSONArray objects = ListUtil.stringChangeList(tbProduct.getGroupCategoryId());
for (Object groupCategoryId : objects) {
@ -419,7 +414,7 @@ public class TbProductServiceImpl implements TbProductService {
if (CollectionUtils.isEmpty(resources.getSkuList())) {
throw new BadRequestException("商品规格不可为空");
}
if (!"group".equals(resources.getTypeEnum())) {
if (!"coupon".equals(resources.getType())) {
if (resources.getCategoryId() == null) {
throw new BadRequestException("必填内容未填写");
}
@ -437,11 +432,11 @@ public class TbProductServiceImpl implements TbProductService {
product.setUpdatedAt(Instant.now().toEpochMilli());
List<BigDecimal> lowPrice = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(lowPrice.get(0));
if ("group".equals(resources.getTypeEnum())) {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {
product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
}
if ("coupon".equals(resources.getType())) {
// //套餐内容
// if (!resources.getGroupSnap().isEmpty()) {
// product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
// }
if (!CollectionUtils.isEmpty(resources.getGroupCategoryId())) {
List<Integer> collect = resources.getGroupCategoryId().stream().map(TbCouponCategoryDto::getId).collect(Collectors.toList());
product.setGroupCategoryId(collect.toString());
@ -452,6 +447,12 @@ public class TbProductServiceImpl implements TbProductService {
}
}
}
if("package".equals(resources.getType())){
//套餐内容
if (!resources.getProGroupVo().isEmpty()) {
product.setGroupSnap(ListUtil.listToJsonString(resources.getProGroupVo()));
}
}
TbProduct save = tbProductRepository.save(product);
if (save.getId() == null) {
@ -478,7 +479,7 @@ public class TbProductServiceImpl implements TbProductService {
productSkuResult.setTagSnap(resources.getSkuSnap());
productSkuResult.setId(save.getId());
tbProductSkuResultRepository.save(productSkuResult);
} else if ("group".equals(resources.getTypeEnum())) {
} else if ("coupon".equals(resources.getType())) {
TbPurchaseNotice notices = resources.getNotices();
if (StringUtils.isBlank(notices.getDateUsed())
&& StringUtils.isBlank(notices.getAvailableTime())
@ -523,7 +524,7 @@ public class TbProductServiceImpl implements TbProductService {
throw new BadRequestException("规格数据异常");
}
}
if (!"group".equals(product.getTypeEnum())) {
if (!"coupon".equals(product.getType())) {
if (resources.getCategoryId() == null) throw new BadRequestException("商品分类不可为空");
product.setGroupSnap(null);
if (resources.getNotices() != null && resources.getNotices().getId() != null) {
@ -537,13 +538,13 @@ public class TbProductServiceImpl implements TbProductService {
product.setStockNumber(resources.getStockNumber().intValue());
List<BigDecimal> lowPrices = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(lowPrices.get(0));
if ("group".equals(resources.getTypeEnum())) {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {
product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
} else {
throw new BadRequestException("套餐内容不可为空");
}
if ("coupon".equals(resources.getType())) {
// //套餐内容
// if (!resources.getGroupSnap().isEmpty()) {
// product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
// } else {
// throw new BadRequestException("套餐内容不可为空");
// }
if (!CollectionUtils.isEmpty(resources.getGroupCategoryId())) {
List<Integer> collect = resources.getGroupCategoryId().stream().map(TbCouponCategoryDto::getId).collect(Collectors.toList());
product.setGroupCategoryId(collect.toString());
@ -558,6 +559,12 @@ public class TbProductServiceImpl implements TbProductService {
} else {
product.setCategoryId(resources.getCategoryId().toString());
}
if("package".equals(resources.getType())){
//套餐内容
if (CollectionUtil.isNotEmpty(resources.getProGroupVo())) {
product.setGroupSnap(ListUtil.listToJsonString(resources.getProGroupVo()));
}
}
TbProduct save = tbProductRepository.save(product);
//sku
@ -581,7 +588,7 @@ public class TbProductServiceImpl implements TbProductService {
tbProductSkuResultRepository.save(productSkuResult);
} else {
tbProductSkuResultRepository.deleteByIdN(save.getId());
if ("group".equals(resources.getTypeEnum())) {
if ("coupon".equals(resources.getType())) {
TbPurchaseNotice notices = resources.getNotices();
if (StringUtils.isBlank(notices.getDateUsed())
&& StringUtils.isBlank(notices.getAvailableTime())

View File

@ -0,0 +1,34 @@
package cn.ysk.cashier.vo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProductGroupVo {
private Integer count;
//选几个
private Integer number;
//类别
private String title;
//食物
private List<Food> goods=new ArrayList<>();
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Food {
private Integer proId;
private String proName;
private Integer skuId;
private String skuName;
private BigDecimal price;
private String number;
private String unitName;
}
}

View File

@ -25,8 +25,6 @@ public class TbProductVo {
private Integer id;
private String merchantId;
private String shopId;
private String name;
@ -47,24 +45,19 @@ public class TbProductVo {
private String shortTitle;
private BigDecimal lowMemberPrice;
private String shareImg;
private JSONArray images;
private Integer sort;
private Integer limitNumber;
private Integer status;
private String failMsg;
private Integer isHot;
private Integer isOnSale;
private String type;
private String typeEnum;
private Integer isDel;
@ -79,19 +72,11 @@ public class TbProductVo {
private Long updatedAt;
private Integer furnishMeal;
private Double realSalesNumber;
private Double stockNumber;
private Integer furnishExpress;
private Integer furnishDraw;
private Integer furnishVir;
private JSONArray groupSnap;
private Integer groupType;
private String unitName;
@ -115,9 +100,28 @@ public class TbProductVo {
private Integer warnLine = 0;
private String showType;
private BigDecimal weight;
private Integer isTempPrice = 0;
private Integer dayLimit = 0;
private Integer singleOrderLimit = 0;
private Integer singlePeopleLimit = 0;
private String days;
private String startTime;
private String endTime;
private List<ViewConSku> conInfos;
private TbPurchaseNotice notices=new TbPurchaseNotice();
private List<TbCouponCategoryDto> groupCategoryId = new ArrayList<>();
private List<TbPlatformDictDto> tags = new ArrayList<>();
private List<ProductGroupVo> proGroupVo;
}