feat:商品提交

This commit is contained in:
有来技术 2021-08-07 23:59:36 +08:00
parent 442521127c
commit a4f985a7be
6 changed files with 29 additions and 27 deletions

View File

@ -14,6 +14,7 @@ public class GoodsFormDTO {
private String name;
private Long categoryId;
private Long brandId;
private Long originPrice;
private Long price;
private String picUrl;
private List<String> subPicUrls;

View File

@ -16,6 +16,6 @@ public interface PmsConstants {
String PRODUCT_REDIS_BLOOM_FILTER = "product:redis:bloom:filter";
String TEMP_ID_PREFIX = "temp-";
String TEMP_ID_PREFIX = "tid_";
}

View File

@ -70,8 +70,8 @@ public class GoodsController {
@ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}")
public Result delete(@PathVariable String ids) {
iPmsSpuService.removeBySpuIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
return Result.success();
boolean result = iPmsSpuService.removeByGoodsIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
return Result.judge(result);
}
@ApiOperation(value = "选择性修改商品")

View File

@ -16,7 +16,7 @@ public interface IPmsSpuService extends IService<PmsSpu> {
boolean addGoods(GoodsFormDTO goodsFormDTO);
boolean removeBySpuIds(List<Long> spuIds);
boolean removeByGoodsIds(List<Long> spuIds);
boolean updateGoods(GoodsFormDTO goodsFormDTO);

View File

@ -19,16 +19,13 @@ import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.pojo.vo.admin.GoodsDetailVO;
import com.youlai.mall.pms.service.IPmsAttributeService;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsSpuAttributeValueService;
import com.youlai.mall.pms.service.IPmsSpuService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
@ -41,7 +38,6 @@ import java.util.stream.Collectors;
public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements IPmsSpuService {
private final IPmsSkuService iPmsSkuService;
private final IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
private final IPmsAttributeService attributeService;
private final BloomRedisService bloomRedisService;
@Override
@ -133,7 +129,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 新增/修改SKU
List<PmsSku> pmsSkuList = skuList.stream().map(sku -> {
// 临时规格ID转换
String specIds = Arrays.asList(sku.getSpecIds().split("_")).stream()
String specIds = Arrays.asList(sku.getSpecIds().split("\\|")).stream()
.map(specId ->
specId.startsWith(PmsConstants.TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId
)
@ -277,22 +273,21 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
return goodsDetailVO;
}
@Override
public boolean removeBySpuIds(List<Long> spuIds) {
Optional.ofNullable(spuIds).ifPresent(
ids -> ids.forEach(spuId -> {
// sku
iPmsSkuService.remove(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
// 规格
iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getId, spuId));
// 属性
iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, spuId));
// spu
this.removeById(spuId);
})
);
return true;
public boolean removeByGoodsIds(List<Long> goodsIds) {
boolean result = true;
for (Long goodsId : goodsIds) {
// sku
iPmsSkuService.remove(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, goodsId));
// 规格
iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getId, goodsId));
// 属性
iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, goodsId));
// spu
result = this.removeById(goodsId);
}
return result;
}
}

View File

@ -21,7 +21,8 @@
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
<result property="categoryName" column="categoryName" jdbcType="VARCHAR"/>
<result property="brandName" column="brandName" jdbcType="VARCHAR"/>
<collection property="skuList" ofType="com.youlai.mall.pms.pojo.entity.PmsSku" javaType="list">
<!-- Mybatis Plus 分页有BUG -->
<!--<collection property="skuList" ofType="com.youlai.mall.pms.pojo.entity.PmsSku" javaType="list">
<id property="id" column="skuId" jdbcType="BIGINT"/>
<result property="name" column="skuName" jdbcType="VARCHAR"/>
<result property="sn" column="sn" jdbcType="VARCHAR"/>
@ -30,7 +31,10 @@
<result property="price" column="skuPrice" jdbcType="BIGINT"/>
<result property="stock" column="stock" jdbcType="INTEGER"/>
<result property="lockedStock" column="locked_stock" jdbcType="INTEGER"/>
</collection>
</collection>-->
</resultMap>
<sql id="Base_Column_List">
@ -42,7 +46,9 @@
status,gmt_create,gmt_modified
</sql>
<select id="list" resultMap="BaseResultMap">
SELECT t1.*,
SELECT t1.name,
t1.pic_url,
t3.NAME categoryName,
t4.NAME brandName,
t2.id skuId,