拼团后端添加对属性的操作
This commit is contained in:
@ -8,14 +8,19 @@ package co.yixiang.modules.activity.domain;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import co.yixiang.domain.BaseDomain;
|
||||
import co.yixiang.modules.product.service.dto.FromatDetailDto;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
@ -105,14 +110,6 @@ public class YxStoreCombination extends BaseDomain {
|
||||
private Integer merUse;
|
||||
|
||||
|
||||
/** 是否包邮1是0否 */
|
||||
private Integer isPostage;
|
||||
|
||||
|
||||
/** 邮费 */
|
||||
private BigDecimal postage;
|
||||
|
||||
|
||||
/** 拼团内容 */
|
||||
@NotBlank(message = "请填写详情")
|
||||
private String description;
|
||||
@ -145,10 +142,23 @@ public class YxStoreCombination extends BaseDomain {
|
||||
/** 单位名 */
|
||||
private String unitName;
|
||||
|
||||
private Integer specType;
|
||||
|
||||
/** 运费模板ID */
|
||||
@JsonProperty("temp_id")
|
||||
private Long tempId;
|
||||
//属性项目
|
||||
@TableField(exist = false)
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
//sku结果集
|
||||
@TableField(exist = false)
|
||||
private List<Map<String,Object>> attrs;
|
||||
|
||||
|
||||
|
||||
public void copy(YxStoreCombination source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -92,4 +92,6 @@ public interface YxStoreCombinationService extends BaseService<YxStoreCombinati
|
||||
* @param status ShopCommonEnum
|
||||
*/
|
||||
void onSale(Long id, Integer status);
|
||||
|
||||
boolean saveCombination(YxStoreCombinationDto resources);
|
||||
}
|
||||
|
@ -5,18 +5,28 @@
|
||||
*/
|
||||
package co.yixiang.modules.activity.service.dto;
|
||||
|
||||
import co.yixiang.modules.product.service.dto.FromatDetailDto;
|
||||
import co.yixiang.modules.product.service.dto.ProductFormatDto;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class YxStoreCombinationDto implements Serializable {
|
||||
|
||||
private Long id;
|
||||
@ -30,9 +40,12 @@ public class YxStoreCombinationDto implements Serializable {
|
||||
// 推荐图
|
||||
private String image;
|
||||
|
||||
// 轮播图
|
||||
private String images;
|
||||
|
||||
/** 轮播图 */
|
||||
@JsonProperty("slider_image")
|
||||
private List<String> sliderImage;
|
||||
|
||||
//参与人数
|
||||
private Integer countPeopleAll;
|
||||
|
||||
@ -45,9 +58,6 @@ public class YxStoreCombinationDto implements Serializable {
|
||||
// 活动标题
|
||||
private String title;
|
||||
|
||||
// 活动属性
|
||||
private String attr;
|
||||
|
||||
// 参团人数
|
||||
private Integer people;
|
||||
|
||||
@ -109,4 +119,15 @@ public class YxStoreCombinationDto implements Serializable {
|
||||
// 单位名
|
||||
private String unitName;
|
||||
|
||||
/** 规格 0单 1多 */
|
||||
@JsonProperty("spec_type")
|
||||
private Integer specType;
|
||||
|
||||
private ProductFormatDto attr;
|
||||
//属性项目
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
//sku结果集
|
||||
private List<Map<String,Object>> attrs;
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,15 @@
|
||||
*/
|
||||
package co.yixiang.modules.activity.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import co.yixiang.api.YshopException;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.enums.ShopCommonEnum;
|
||||
import co.yixiang.enums.SpecTypeEnum;
|
||||
import co.yixiang.modules.activity.domain.YxStoreCombination;
|
||||
import co.yixiang.modules.activity.domain.YxStorePink;
|
||||
import co.yixiang.modules.activity.domain.YxStoreVisit;
|
||||
@ -26,7 +30,13 @@ import co.yixiang.modules.activity.service.mapper.YxStorePinkMapper;
|
||||
import co.yixiang.modules.activity.service.mapper.YxStoreVisitMapper;
|
||||
import co.yixiang.modules.activity.vo.StoreCombinationVo;
|
||||
import co.yixiang.modules.activity.vo.YxStoreCombinationQueryVo;
|
||||
import co.yixiang.modules.product.domain.YxStoreProduct;
|
||||
import co.yixiang.modules.product.service.YxStoreProductAttrService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductAttrValueService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductReplyService;
|
||||
import co.yixiang.modules.product.service.dto.FromatDetailDto;
|
||||
import co.yixiang.modules.product.service.dto.ProductFormatDto;
|
||||
import co.yixiang.modules.product.service.dto.ProductResultDto;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -39,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -48,7 +59,7 @@ import java.util.*;
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
||||
public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombinationMapper, YxStoreCombination> implements YxStoreCombinationService {
|
||||
|
||||
@Autowired
|
||||
@ -65,6 +76,10 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
private YxStoreProductReplyService replyService;
|
||||
@Autowired
|
||||
private YxStorePinkService storePinkService;
|
||||
@Autowired
|
||||
private YxStoreProductAttrService yxStoreProductAttrService;
|
||||
@Autowired
|
||||
private YxStoreProductAttrValueService yxStoreProductAttrValueService;
|
||||
|
||||
|
||||
/**
|
||||
@ -213,7 +228,6 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
map.put("推荐图", yxStoreCombination.getImage());
|
||||
map.put("轮播图", yxStoreCombination.getImages());
|
||||
map.put("活动标题", yxStoreCombination.getTitle());
|
||||
map.put("活动属性", yxStoreCombination.getAttr());
|
||||
map.put("参团人数", yxStoreCombination.getPeople());
|
||||
map.put("简介", yxStoreCombination.getInfo());
|
||||
map.put("价格", yxStoreCombination.getPrice());
|
||||
@ -255,4 +269,99 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
yxStoreCombination.setId(id);
|
||||
this.saveOrUpdate(yxStoreCombination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveCombination(YxStoreCombinationDto resources) {
|
||||
ProductResultDto resultDTO = this.computedProduct(resources.getAttrs());
|
||||
|
||||
//添加商品
|
||||
YxStoreCombination yxStoreCombination = new YxStoreCombination();
|
||||
BeanUtil.copyProperties(resources,yxStoreCombination,"images");
|
||||
if(resources.getImages().isEmpty()) throw new YshopException("请上传轮播图");
|
||||
|
||||
yxStoreCombination.setPrice(BigDecimal.valueOf(resultDTO.getMinPrice()));
|
||||
yxStoreCombination.setCost(resultDTO.getMinCost().intValue());
|
||||
yxStoreCombination.setStock(resultDTO.getStock());
|
||||
yxStoreCombination.setImages(String.join(",", resources.getImages()));
|
||||
this.saveOrUpdate(yxStoreCombination);
|
||||
|
||||
//属性处理
|
||||
//处理单sKu
|
||||
if(SpecTypeEnum.TYPE_0.getValue().equals(resources.getSpecType())){
|
||||
FromatDetailDto fromatDetailDto = FromatDetailDto.builder()
|
||||
.value("规格")
|
||||
.detailValue("")
|
||||
.attrHidden("")
|
||||
.detail(ListUtil.toList("默认"))
|
||||
.build();
|
||||
List<Map<String,Object>> attrs = resources.getAttrs();
|
||||
Map<String,Object> map = attrs.get(0);
|
||||
map.put("value1","规格");
|
||||
map.put("detail", MapUtil.of(new String[][] {
|
||||
{"规格", "默认"}
|
||||
}));
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
|
||||
ListUtil.toList(map),resources.getProductId());
|
||||
}else{
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(),
|
||||
resources.getAttrs(),resources.getProductId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算产品数据
|
||||
* @param attrs attrs
|
||||
* @return ProductResultDto
|
||||
*/
|
||||
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
|
||||
//取最小价格
|
||||
Double minPrice = ListMapToListBean(attrs)
|
||||
.stream()
|
||||
.map(ProductFormatDto::getPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minOtPrice = ListMapToListBean(attrs)
|
||||
.stream()
|
||||
.map(ProductFormatDto::getOtPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minCost = ListMapToListBean(attrs)
|
||||
.stream()
|
||||
.map(ProductFormatDto::getCost)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
//计算库存
|
||||
Integer stock = ListMapToListBean(attrs)
|
||||
.stream()
|
||||
.map(ProductFormatDto::getStock)
|
||||
.reduce(Integer::sum)
|
||||
.orElse(0);
|
||||
|
||||
if(stock <= 0) throw new YshopException("库存不能低于0");
|
||||
|
||||
return ProductResultDto.builder()
|
||||
.minPrice(minPrice)
|
||||
.minOtPrice(minOtPrice)
|
||||
.minCost(minCost)
|
||||
.stock(stock)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* mapTobean
|
||||
* @param listMap listMap
|
||||
* @return list
|
||||
*/
|
||||
private List<ProductFormatDto> ListMapToListBean(List<Map<String, Object>> listMap){
|
||||
List<ProductFormatDto> list = new ArrayList<>();
|
||||
// 循环遍历出map对象
|
||||
for (Map<String, Object> m : listMap) {
|
||||
list.add(BeanUtil.mapToBean(m,ProductFormatDto.class,true));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,11 @@ public class YxStoreProductAttrValue implements Serializable {
|
||||
/** 属性对应的库存 */
|
||||
private Integer stock;
|
||||
|
||||
/** 拼团库存属性对应的库存 */
|
||||
private Integer pinkStock;
|
||||
|
||||
/** 秒杀库存属性对应的库存 */
|
||||
private Integer seckillStock;
|
||||
|
||||
/** 销量 */
|
||||
private Integer sales;
|
||||
@ -51,7 +56,11 @@ public class YxStoreProductAttrValue implements Serializable {
|
||||
/** 属性金额 */
|
||||
private BigDecimal price;
|
||||
|
||||
/** 拼团属性对应的金额 */
|
||||
private BigDecimal pinkPrice;
|
||||
|
||||
/** 秒杀属性对应的金额 */
|
||||
private BigDecimal seckillPrice;
|
||||
/** 图片 */
|
||||
private String image;
|
||||
|
||||
|
@ -126,7 +126,7 @@ public interface YxStoreProductService extends BaseService<YxStoreProduct>{
|
||||
* @param jsonStr jsonStr
|
||||
* @return map
|
||||
*/
|
||||
Map<String,Object> getFormatAttr(Long id, String jsonStr);
|
||||
Map<String,Object> getFormatAttr(Long id, String jsonStr,boolean isActivity);
|
||||
|
||||
|
||||
|
||||
|
@ -50,6 +50,14 @@ public class ProductFormatDto {
|
||||
|
||||
private Double weight = 0d;
|
||||
|
||||
private Double pinkPrice = 0d;
|
||||
|
||||
private Integer pinkStock = 0;
|
||||
|
||||
private Double seckillPrice = 0d;
|
||||
|
||||
private Integer seckillStock = 0;
|
||||
|
||||
private Map<String, String> detail;
|
||||
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
* @return map
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Object> getFormatAttr(Long id, String jsonStr) {
|
||||
public Map<String,Object> getFormatAttr(Long id, String jsonStr,boolean isActivity) {
|
||||
JSONObject jsonObject = JSON.parseObject(jsonStr);
|
||||
Map<String,Object> resultMap = new LinkedHashMap<>(3);
|
||||
|
||||
@ -588,7 +588,7 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
|
||||
}
|
||||
|
||||
this.addMap(headerMap,headerMapList,align);
|
||||
this.addMap(headerMap,headerMapList,align,isActivity);
|
||||
|
||||
|
||||
resultMap.put("attr",fromatDetailDTOList);
|
||||
@ -664,7 +664,7 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
* @param headerMapList headerMapList
|
||||
* @param align align
|
||||
*/
|
||||
private void addMap(Map<String,Object> headerMap,List<Map<String,Object>> headerMapList,String align){
|
||||
private void addMap(Map<String,Object> headerMap,List<Map<String,Object>> headerMapList,String align,boolean isActivity){
|
||||
headerMap.put("title","图片");
|
||||
headerMap.put("slot", "pic");
|
||||
headerMap.put("align",align);
|
||||
@ -711,7 +711,32 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
headerMap.put("slot", "volume");
|
||||
headerMap.put("align",align);
|
||||
headerMap.put("minWidth",140);
|
||||
headerMapList.add(ObjectUtil.clone(headerMap));
|
||||
|
||||
if(isActivity){
|
||||
headerMap.put("title","拼团价");
|
||||
headerMap.put("slot", "pinkPrice");
|
||||
headerMap.put("align",align);
|
||||
headerMap.put("minWidth",140);
|
||||
headerMapList.add(ObjectUtil.clone(headerMap));
|
||||
|
||||
headerMap.put("title","拼团活动库存");
|
||||
headerMap.put("slot", "pinkStock");
|
||||
headerMap.put("align",align);
|
||||
headerMap.put("minWidth",140);
|
||||
headerMapList.add(ObjectUtil.clone(headerMap));
|
||||
|
||||
headerMap.put("title","秒杀价");
|
||||
headerMap.put("slot", "seckillPrice");
|
||||
headerMap.put("align",align);
|
||||
headerMap.put("minWidth",140);
|
||||
headerMapList.add(ObjectUtil.clone(headerMap));
|
||||
|
||||
headerMap.put("title","秒杀活动库存");
|
||||
headerMap.put("slot", "seckillStock");
|
||||
headerMap.put("align",align);
|
||||
headerMap.put("minWidth",140);
|
||||
headerMapList.add(ObjectUtil.clone(headerMap));
|
||||
}
|
||||
|
||||
headerMap.put("title","操作");
|
||||
headerMap.put("slot", "action");
|
||||
|
Reference in New Issue
Block a user