@@ -21,6 +21,8 @@ public interface SpuCategoryMapper {
List<Long> listLotIdsByCategoryIds(@Param("categoryIds") List<Long> categoryIds);
+ List<Long> selectCategoryIdsByNames(@Param("names") List<String> names);
+
void insertLotCategoryRelation(@Param("lotId") Long lotId, @Param("categoryIds") List<Long> categoryIds);
void deleteLotCategoryRelation(@Param("lotId") Long lotId);
@@ -381,16 +381,19 @@ public class LotServiceImpl extends ServiceImpl<LotMapper,Lot> implements ILotSe
}
private void saveLotCategoryRelation(Lot lot) {
- List<Long> categoryIds = new ArrayList<>();
+ List<String> names = new ArrayList<>();
if (StringUtils.isNotEmpty(lot.getCategory())) {
- categoryIds.add(Long.parseLong(lot.getCategory()));
+ names.add(lot.getCategory());
if (StringUtils.isNotEmpty(lot.getSubCategory())) {
- categoryIds.add(Long.parseLong(lot.getSubCategory()));
+ names.add(lot.getSubCategory());
- if (!categoryIds.isEmpty()) {
- spuCategoryMapper.deleteLotCategoryRelation(lot.getId());
- spuCategoryMapper.insertLotCategoryRelation(lot.getId(), categoryIds);
+ if (!names.isEmpty()) {
+ List<Long> categoryIds = spuCategoryMapper.selectCategoryIdsByNames(names);
+ if (!CollectionUtils.isEmpty(categoryIds)) {
+ spuCategoryMapper.deleteLotCategoryRelation(lot.getId());
+ spuCategoryMapper.insertLotCategoryRelation(lot.getId(), categoryIds);
+ }
@@ -88,6 +88,15 @@
</foreach>
</insert>
+ <select id="selectCategoryIdsByNames" resultType="java.lang.Long">
+ SELECT id FROM spu_category
+ WHERE category_name IN
+ <foreach collection="names" item="name" open="(" separator="," close=")">
+ #{name}
+ </foreach>
+ AND del_flag = 0 AND status = 1
+ </select>
<insert id="createCategory" parameterType="cn.hobbystocks.auc.domain.SpuCategory">
insert into spu_category (category_name,is_cascade,sub_label,sort,parent_id,icon_url,status,create_time,update_time)