添加一种更新商品sku的方式。mysql replace into(先查找,如存在则删除,新增。如不存在新增)
This commit is contained in:
parent
f5718b4062
commit
f2b327c811
@ -2,6 +2,8 @@ package cn.lili.modules.goods.mapper;
|
|||||||
|
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -23,4 +25,78 @@ public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
|||||||
@Select("SELECT id FROM li_goods_sku WHERE goods_id = #{goodsId}")
|
@Select("SELECT id FROM li_goods_sku WHERE goods_id = #{goodsId}")
|
||||||
List<String> getGoodsSkuIdByGoodsId(String goodsId);
|
List<String> getGoodsSkuIdByGoodsId(String goodsId);
|
||||||
|
|
||||||
|
|
||||||
|
@Insert("replace into li_goods_sku (\n" +
|
||||||
|
"\tid,\n" +
|
||||||
|
"\tgoods_id,\n" +
|
||||||
|
"\tspecs,\n" +
|
||||||
|
"\tsimple_specs,\n" +
|
||||||
|
"\tfreight_template_id,\n" +
|
||||||
|
"\tgoods_name,\n" +
|
||||||
|
"\tsn,\n" +
|
||||||
|
"\tbrand_id,\n" +
|
||||||
|
"\tcategory_path,\n" +
|
||||||
|
"\tgoods_unit,\n" +
|
||||||
|
"\tselling_point,\n" +
|
||||||
|
"\tweight,\n" +
|
||||||
|
"\tmarket_enable,\n" +
|
||||||
|
"\tintro,\n" +
|
||||||
|
"\tprice,\n" +
|
||||||
|
"\tcost,\n" +
|
||||||
|
"\tquantity,\n" +
|
||||||
|
"\tgrade,\n" +
|
||||||
|
"\tthumbnail,\n" +
|
||||||
|
"\tsmall,\n" +
|
||||||
|
"\tstore_category_path,\n" +
|
||||||
|
"\tstore_id,\n" +
|
||||||
|
"\tstore_name,\n" +
|
||||||
|
"\tauth_flag,\n" +
|
||||||
|
"\tself_operated,\n" +
|
||||||
|
"\tmobile_intro,\n" +
|
||||||
|
"\trecommend,\n" +
|
||||||
|
"\tsales_model,\n" +
|
||||||
|
"\tgoods_type,\n" +
|
||||||
|
"\tcreate_by,\n" +
|
||||||
|
"\tcreate_time,\n" +
|
||||||
|
"\tupdate_time,\n" +
|
||||||
|
"\tdelete_flag \n" +
|
||||||
|
")\n" +
|
||||||
|
" VALUES\n" +
|
||||||
|
"(\n" +
|
||||||
|
"\t#{goodsSku.id},\n" +
|
||||||
|
"\t#{goodsSku.goodsId},\n" +
|
||||||
|
"\t#{goodsSku.specs},\n" +
|
||||||
|
"\t#{goodsSku.simpleSpecs},\n" +
|
||||||
|
"\t#{goodsSku.freightTemplateId},\n" +
|
||||||
|
"\t#{goodsSku.goodsName},\n" +
|
||||||
|
"\t#{goodsSku.sn},\n" +
|
||||||
|
"\t#{goodsSku.brandId},\n" +
|
||||||
|
"\t#{goodsSku.categoryPath},\n" +
|
||||||
|
"\t#{goodsSku.goodsUnit},\n" +
|
||||||
|
"\t#{goodsSku.sellingPoint},\n" +
|
||||||
|
"\t#{goodsSku.weight},\n" +
|
||||||
|
"\t#{goodsSku.marketEnable},\n" +
|
||||||
|
"\t#{goodsSku.intro},\n" +
|
||||||
|
"\t#{goodsSku.price},\n" +
|
||||||
|
"\t#{goodsSku.cost},\n" +
|
||||||
|
"\t#{goodsSku.quantity},\n" +
|
||||||
|
"\t#{goodsSku.grade},\n" +
|
||||||
|
"\t#{goodsSku.thumbnail},\n" +
|
||||||
|
"\t#{goodsSku.small},\n" +
|
||||||
|
"\t#{goodsSku.storeCategoryPath},\n" +
|
||||||
|
"\t#{goodsSku.storeId},\n" +
|
||||||
|
"\t#{goodsSku.storeName},\n" +
|
||||||
|
"\t#{goodsSku.authFlag},\n" +
|
||||||
|
"\t#{goodsSku.selfOperated},\n" +
|
||||||
|
"\t#{goodsSku.mobileIntro},\n" +
|
||||||
|
"\t#{goodsSku.recommend},\n" +
|
||||||
|
"\t#{goodsSku.salesModel},\n" +
|
||||||
|
"\t#{goodsSku.goodsType},\n" +
|
||||||
|
"\t#{goodsSku.createBy},\n" +
|
||||||
|
"\t#{goodsSku.createTime},\n" +
|
||||||
|
"\t#{goodsSku.updateTime},\n" +
|
||||||
|
"\t#{goodsSku.deleteFlag}\n" +
|
||||||
|
")")
|
||||||
|
int replaceGoodsSku(@Param("goodsSku") GoodsSku goodsSku);
|
||||||
|
|
||||||
}
|
}
|
@ -211,4 +211,6 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
|||||||
* @return 全部skuId的集合
|
* @return 全部skuId的集合
|
||||||
*/
|
*/
|
||||||
List<String> getSkuIdsByGoodsId(String goodsId);
|
List<String> getSkuIdsByGoodsId(String goodsId);
|
||||||
|
|
||||||
|
boolean deleteAndInsertGoodsSkus(List<GoodsSku> goodsSkus);
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ import cn.lili.common.enums.ResultCode;
|
|||||||
import cn.lili.common.exception.ServiceException;
|
import cn.lili.common.exception.ServiceException;
|
||||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
|
import cn.lili.common.utils.SnowFlake;
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
@ -149,9 +150,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
oldSkuIds.add(goodsSkuVO.getId());
|
oldSkuIds.add(goodsSkuVO.getId());
|
||||||
cache.remove(GoodsSkuService.getCacheKeys(goodsSkuVO.getId()));
|
cache.remove(GoodsSkuService.getCacheKeys(goodsSkuVO.getId()));
|
||||||
}
|
}
|
||||||
this.removeByIds(oldSkuIds);
|
|
||||||
|
this.remove(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goods.getId()));
|
||||||
//删除sku相册
|
//删除sku相册
|
||||||
goodsGalleryService.removeByGoodsId(goods.getId());
|
goodsGalleryService.removeByGoodsId(goods.getId());
|
||||||
|
getGoodsListByGoodsId(goods.getId());
|
||||||
// 添加商品sku
|
// 添加商品sku
|
||||||
newSkuList = this.addGoodsSku(skuList, goods);
|
newSkuList = this.addGoodsSku(skuList, goods);
|
||||||
|
|
||||||
@ -179,6 +182,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
this.clearCache(sku.getId());
|
this.clearCache(sku.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.remove(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goods.getId()));
|
||||||
this.saveOrUpdateBatch(newSkuList);
|
this.saveOrUpdateBatch(newSkuList);
|
||||||
}
|
}
|
||||||
this.updateStock(newSkuList);
|
this.updateStock(newSkuList);
|
||||||
@ -393,7 +397,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GoodsSkuVO> getGoodsListByGoodsId(String goodsId) {
|
public List<GoodsSkuVO> getGoodsListByGoodsId(String goodsId) {
|
||||||
List<GoodsSku> list = this.list(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goodsId));
|
List<GoodsSku> list = this.list(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goodsId).orderByAsc(GoodsSku::getGoodsName));
|
||||||
return this.getGoodsSkuVOList(list);
|
return this.getGoodsSkuVOList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,6 +601,19 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
applicationEventPublisher.publishEvent(new GeneratorEsGoodsIndexEvent("生成商品", GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(), goods.getId()));
|
applicationEventPublisher.publishEvent(new GeneratorEsGoodsIndexEvent("生成商品", GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(), goods.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteAndInsertGoodsSkus(List<GoodsSku> goodsSkus) {
|
||||||
|
int count = 0;
|
||||||
|
for (GoodsSku skus : goodsSkus) {
|
||||||
|
if (CharSequenceUtil.isEmpty(skus.getId())) {
|
||||||
|
skus.setId(SnowFlake.getIdStr());
|
||||||
|
}
|
||||||
|
count = this.baseMapper.replaceGoodsSku(skus);
|
||||||
|
}
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改库存
|
* 修改库存
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user