分类软删除

This commit is contained in:
hupeng
2020-04-07 16:58:29 +08:00
parent 43e450a060
commit e96f95e120
7 changed files with 22 additions and 6 deletions

View File

@ -23,3 +23,6 @@ ADD COLUMN `invite_code` varchar(50) NULL DEFAULT '' COMMENT '邀请码' AFTER `
ALTER TABLE `yx_store_seckill`
ADD COLUMN `time_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '时间段id' AFTER `start_time_date`
ALTER TABLE `yx_store_category`
ADD COLUMN `is_del` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '删除状态' AFTER `add_time`

View File

@ -52,7 +52,7 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<YxStoreCategoryM
@Override
public List<CateDTO> getList() {
QueryWrapper<YxStoreCategory> wrapper = new QueryWrapper<>();
wrapper.eq("is_show",1).orderByAsc("sort");
wrapper.eq("is_show",1).eq("is_del",0).orderByAsc("sort");
List<CateDTO> list = categoryMap.toDto(baseMapper.selectList(wrapper));
return TreeUtil.list2TreeConverter(list,0);
}
@ -64,7 +64,7 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<YxStoreCategoryM
List<CateDTO> list = categoryMap.toDto(baseMapper.selectList(wrapper));
System.out.println(TreeUtil.getChildList(list,new CateDTO()));
//System.out.println(TreeUtil.getChildList(list,new CateDTO()));
return null;
}
}

View File

@ -5,6 +5,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
@ -20,6 +21,7 @@ import java.util.Objects;
@Getter
@Setter
@Table(name="yx_store_category")
//@Where(clause = "is_del = 0")
public class YxStoreCategory implements Serializable {
// 商品分类表ID
@ -58,6 +60,9 @@ public class YxStoreCategory implements Serializable {
@Column(name = "add_time",nullable = false)
private Integer addTime;
@Column(name = "is_del",insertable = false)
private Integer isDel;
public void copy(YxStoreCategory source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}

View File

@ -3,6 +3,7 @@ package co.yixiang.modules.shop.repository;
import co.yixiang.modules.shop.domain.YxStoreCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
@ -13,6 +14,10 @@ public interface YxStoreCategoryRepository extends JpaRepository<YxStoreCategory
@Query(value = "select cate_name from yx_store_category where id = ?1",nativeQuery = true)
String findNameById(Integer id);
@Modifying
@Query("update YxStoreCategory s set s.isDel = 1 where s.id =:id")
void delCategory(Integer id);
YxStoreCategory findByPid(Integer pid);
}

View File

@ -22,5 +22,5 @@ public interface YxStoreProductRepository extends JpaRepository<YxStoreProduct,
@Query(value = "update yx_store_product set is_del = ?1 where id = ?2",nativeQuery = true)
void updateDel(int status, int id);
List<YxStoreProduct> findByStoreCategory(YxStoreCategory storeCategory);
List<YxStoreProduct> findByStoreCategoryAndIsDel(YxStoreCategory storeCategory,int isDel);
}

View File

@ -13,4 +13,7 @@ public class YxStoreCategoryQueryCriteria{
// 模糊
@Query(type = Query.Type.INNER_LIKE)
private String cateName;
@Query
private Integer isDel = 0;
}

View File

@ -111,11 +111,11 @@ public class YxStoreCategoryServiceImpl implements YxStoreCategoryService {
if(storeCategory != null) throw new BadRequestException("请先删除子类");
YxStoreCategory category = new YxStoreCategory();
category.setId(id);
List<YxStoreProduct> storeProduct = yxStoreProductRepository.findByStoreCategory(category);
List<YxStoreProduct> storeProduct = yxStoreProductRepository.findByStoreCategoryAndIsDel(category,0);
if(!storeProduct.isEmpty()) throw new BadRequestException("此分类下有商品,不能删除");
yxStoreCategoryRepository.deleteById(id);
yxStoreCategoryRepository.delCategory(id);
}