dev798
parent
25ada3932d
commit
88de15ced1
|
@ -19,7 +19,7 @@ public class ProductSkuAttr extends BaseEntity {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@ApiModelProperty(value = "SKU ID")
|
@ApiModelProperty(value = "SKU ID")
|
||||||
private BigInteger skuId;
|
private long skuId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "属性ID")
|
@ApiModelProperty(value = "属性ID")
|
||||||
private Integer attrId;
|
private Integer attrId;
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ProductTypeAttrValue extends BaseEntity {
|
||||||
private Integer typeAttrId;
|
private Integer typeAttrId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "属性值详情")
|
@ApiModelProperty(value = "属性值详情")
|
||||||
private Integer typeAttrValue;
|
private String typeAttrValue;
|
||||||
|
|
||||||
@ApiModelProperty(value = "录入方式:0-自动,1-手动")
|
@ApiModelProperty(value = "录入方式:0-自动,1-手动")
|
||||||
private Integer inputMethod;
|
private Integer inputMethod;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.mapper;
|
||||||
import com.muyu.product.domain.DTO.ProductSku;
|
import com.muyu.product.domain.DTO.ProductSku;
|
||||||
import com.muyu.product.domain.DTO.ProductSkuAttr;
|
import com.muyu.product.domain.DTO.ProductSkuAttr;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,10 +13,11 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ProductSkuMapper {
|
public interface ProductSkuMapper {
|
||||||
void insertProductSku(List<ProductSku> productSkuList);
|
|
||||||
|
|
||||||
void insertProductSkuAttr(List<ProductSkuAttr> productSkuAttrs);
|
void insertProductSkuAttr(@Param("productSkuAttrs") List<ProductSkuAttr> productSkuAttrs);
|
||||||
|
|
||||||
Integer findSkuId(List<ProductSku> productSkus);
|
void insertProductSku(@Param("productSkus") List<ProductSku> productSkus, @Param("id") Integer id, @Param("createBy") String createBy);
|
||||||
|
|
||||||
|
Integer findSkuId(@Param("productSkus") List<ProductSku> productSkus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,23 +18,24 @@ import java.util.List;
|
||||||
public interface TypeMapper {
|
public interface TypeMapper {
|
||||||
|
|
||||||
|
|
||||||
List<ProductTypeResp> queryTypeAll();
|
|
||||||
|
|
||||||
List<ProductTypeAttr> queryType(@Param("flag") Integer flag, @Param("id") Integer id);
|
List<ProductTypeAttr> queryType(@Param("flag") Integer flag, @Param("id") Integer id);
|
||||||
|
|
||||||
|
List<ProductTypeResp> queryTypeAll();
|
||||||
|
|
||||||
Integer deleteType(@Param("typeId") Integer typeId, @Param("name") String name);
|
Integer deleteType(@Param("typeId") Integer typeId, @Param("name") String name);
|
||||||
|
|
||||||
void deleteTypeAttrValue(Integer typeId);
|
|
||||||
|
|
||||||
Integer deleteTypeAttr(Integer typeId);
|
|
||||||
|
|
||||||
Integer insertType(ProductType productType);
|
Integer insertType(ProductType productType);
|
||||||
|
|
||||||
Integer updateType(ProductType productType);
|
Integer updateType(ProductType productType);
|
||||||
|
|
||||||
Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq);
|
Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq);
|
||||||
|
|
||||||
void insertTypeValue(@Param("productTypeAttrValueList") List<ProductTypeAttrValue> productTypeAttrValueList);
|
|
||||||
|
Integer deleteTypeAttr(Integer id);
|
||||||
|
|
||||||
Integer updateAttr(ProductTypeAttrReq productTypeAttrReq);
|
Integer updateAttr(ProductTypeAttrReq productTypeAttrReq);
|
||||||
|
|
||||||
|
void deleteTypeAttrValue(Integer typeId);
|
||||||
|
|
||||||
|
void insertTypeValue(ProductTypeAttrValue productTypeAttrValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package com.muyu.product.service.impl;
|
package com.muyu.product.service.impl;
|
||||||
import com.alibaba.fastjson.JSONObject; // 导入 FastJSON 的 JSONObject 类
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.github.pagehelper.PageHelper; // 导入 PageHelper 类
|
import com.github.pagehelper.PageHelper; // 导入 PageHelper 类
|
||||||
import com.github.pagehelper.PageInfo; // 导入 PageInfo 类
|
import com.github.pagehelper.PageInfo; // 导入 PageInfo 类
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
@ -10,6 +10,7 @@ import com.muyu.product.domain.DTO.*;
|
||||||
import com.muyu.product.domain.DTO.Number;
|
import com.muyu.product.domain.DTO.Number;
|
||||||
import com.muyu.product.domain.Resp.ProductResp;
|
import com.muyu.product.domain.Resp.ProductResp;
|
||||||
import com.muyu.product.domain.req.ProductReq;
|
import com.muyu.product.domain.req.ProductReq;
|
||||||
|
import com.muyu.product.domain.req.ProductSkuNew;
|
||||||
import com.muyu.product.domain.req.QueryProductReq;
|
import com.muyu.product.domain.req.QueryProductReq;
|
||||||
import com.muyu.product.mapper.ProductMapper;
|
import com.muyu.product.mapper.ProductMapper;
|
||||||
import com.muyu.product.mapper.ProductSkuMapper;
|
import com.muyu.product.mapper.ProductSkuMapper;
|
||||||
|
@ -136,33 +137,33 @@ public class ProductServiceImpl implements ProductService {
|
||||||
|
|
||||||
private void insertProductSku(ProductReq productReq) {
|
private void insertProductSku(ProductReq productReq) {
|
||||||
List<ProductSku> productSkuList = productReq.getProductSkus();
|
List<ProductSku> productSkuList = productReq.getProductSkus();
|
||||||
int productId = productReq.getProduct().getId();
|
String createBy = SecurityUtils.getUsername();
|
||||||
|
//批量添加
|
||||||
// 设置商品ID
|
productSkuMapper.insertProductSku(productSkuList,productReq.getProduct().getId(),createBy);
|
||||||
productSkuList.forEach(productSku -> productSku.setProductId(productId));
|
//添加skuAttr除实体类以外的字段
|
||||||
|
ArrayList<ProductSkuAttr> productSkuAttrs = new ArrayList<>();
|
||||||
// 批量添加 productSku
|
productSkuList.forEach(productSkusReq -> {
|
||||||
productSkuMapper.insertProductSku(productSkuList);
|
//获取id
|
||||||
|
//productSkusReq.setProductId(productReq.getProduct().getId());
|
||||||
// 添加 skuAttr
|
//获取map的属性值
|
||||||
List<ProductSkuAttr> productSkuAttrs = new ArrayList<>();
|
ProductSkuNew productSkuNew = com.alibaba.fastjson2.JSONObject.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(productSkusReq), ProductSkuNew.class);
|
||||||
productSkuList.forEach(productSku -> {
|
HashMap hashMap = com.alibaba.fastjson2.JSONObject.parseObject(JSONObject.toJSONString(productSkuNew), HashMap.class);
|
||||||
// 获取 sku 的属性值
|
Set skuReq = productSkusReq.keySet();
|
||||||
Map<String, Integer> attributes = productSku.getAttributes();
|
Set sku = hashMap.keySet();
|
||||||
|
//添加一个新的set
|
||||||
// 构造 ProductSkuAttr 对象
|
Set set = skuReq;
|
||||||
attributes.forEach((key, value) -> {
|
//去重
|
||||||
|
set.removeAll(sku);
|
||||||
|
//格属性赋值
|
||||||
|
set.forEach(key ->{
|
||||||
ProductSkuAttr productSkuAttr = new ProductSkuAttr();
|
ProductSkuAttr productSkuAttr = new ProductSkuAttr();
|
||||||
productSkuAttr.setSkuId(productSku.getId());
|
productSkuAttr.setSkuId(productSkuNew.getId());
|
||||||
productSkuAttr.setAttrId(Integer.valueOf(key));
|
productSkuAttr.setAttrId(Integer.valueOf(key.toString()));
|
||||||
productSkuAttr.setAttrValueId(value);
|
productSkuAttr.setAttrValueId(Integer.valueOf(productSkusReq.get(key).toString()));
|
||||||
productSkuAttr.setFlag(Integer.valueOf(Number.zero.getValue()));
|
productSkuAttr.setFlag(Integer.valueOf(Number.zero.getValue()));
|
||||||
productSkuAttrs.add(productSkuAttr);
|
productSkuAttrs.add(productSkuAttr);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("productSkuAttrs 中的数据为:{}", JSONObject.toJSONString(productSkuAttrs));
|
|
||||||
|
|
||||||
//批量添加productSkuAttr
|
//批量添加productSkuAttr
|
||||||
productSkuMapper.insertProductSkuAttr(productSkuAttrs);
|
productSkuMapper.insertProductSkuAttr(productSkuAttrs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,13 +62,18 @@ public class TypeServiceImpl implements TypeService {
|
||||||
public Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq) {
|
public Integer insertTypeAttr(ProductTypeAttrReq productTypeAttrReq) {
|
||||||
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
|
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
|
||||||
Integer res = typeMapper.insertTypeAttr(productTypeAttrReq);
|
Integer res = typeMapper.insertTypeAttr(productTypeAttrReq);
|
||||||
if(res >0 && productTypeAttrReq.getProductTypeAttrValueList().size()>0){
|
|
||||||
|
String[] split = productTypeAttrReq.getProductTypeAttrValueList().split(",");
|
||||||
|
|
||||||
|
if (res > 0) {
|
||||||
Integer typeAttrId = productTypeAttrReq.getId();
|
Integer typeAttrId = productTypeAttrReq.getId();
|
||||||
for (ProductTypeAttrValue productTypeAttrValue : productTypeAttrReq.getProductTypeAttrValueList()) {
|
ProductTypeAttrValue productTypeAttrValue = new ProductTypeAttrValue();
|
||||||
|
for (String s : split) {
|
||||||
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
|
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
|
||||||
productTypeAttrValue.setTypeAttrId(typeAttrId);
|
productTypeAttrValue.setTypeAttrId(typeAttrId);
|
||||||
|
productTypeAttrValue.setTypeAttrValue(s);
|
||||||
|
typeMapper.insertTypeValue(productTypeAttrValue);
|
||||||
}
|
}
|
||||||
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -78,12 +83,16 @@ public class TypeServiceImpl implements TypeService {
|
||||||
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
|
productTypeAttrReq.setCreateBy(SecurityUtils.getUsername());
|
||||||
typeMapper.deleteTypeAttrValue(productTypeAttrReq.getId());
|
typeMapper.deleteTypeAttrValue(productTypeAttrReq.getId());
|
||||||
Integer res = typeMapper.updateAttr(productTypeAttrReq);
|
Integer res = typeMapper.updateAttr(productTypeAttrReq);
|
||||||
if(res >0 && productTypeAttrReq.getProductTypeAttrValueList().size()>0){
|
String[] split = productTypeAttrReq.getProductTypeAttrValueList().split(",");
|
||||||
for (ProductTypeAttrValue productTypeAttrValue : productTypeAttrReq.getProductTypeAttrValueList()) {
|
if (res > 0) {
|
||||||
|
Integer typeAttrId = productTypeAttrReq.getId();
|
||||||
|
ProductTypeAttrValue productTypeAttrValue = new ProductTypeAttrValue();
|
||||||
|
for (String s : split) {
|
||||||
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
|
productTypeAttrValue.setCreateBy(SecurityUtils.getUsername());
|
||||||
productTypeAttrValue.setTypeAttrId(productTypeAttrReq.getId());
|
productTypeAttrValue.setTypeAttrId(typeAttrId);
|
||||||
|
productTypeAttrValue.setTypeAttrValue(s);
|
||||||
|
typeMapper.insertTypeValue(productTypeAttrValue);
|
||||||
}
|
}
|
||||||
typeMapper.insertTypeValue(productTypeAttrReq.getProductTypeAttrValueList());
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue