分类软删除
This commit is contained in:
@ -22,4 +22,7 @@ ADD COLUMN `uid` int(0) UNSIGNED NULL DEFAULT 0 COMMENT '用户id' AFTER `module
|
|||||||
ADD COLUMN `invite_code` varchar(50) NULL DEFAULT '' COMMENT '邀请码' AFTER `uid`
|
ADD COLUMN `invite_code` varchar(50) NULL DEFAULT '' COMMENT '邀请码' AFTER `uid`
|
||||||
|
|
||||||
ALTER TABLE `yx_store_seckill`
|
ALTER TABLE `yx_store_seckill`
|
||||||
ADD COLUMN `time_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '时间段id' AFTER `start_time_date`
|
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`
|
@ -52,7 +52,7 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<YxStoreCategoryM
|
|||||||
@Override
|
@Override
|
||||||
public List<CateDTO> getList() {
|
public List<CateDTO> getList() {
|
||||||
QueryWrapper<YxStoreCategory> wrapper = new QueryWrapper<>();
|
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));
|
List<CateDTO> list = categoryMap.toDto(baseMapper.selectList(wrapper));
|
||||||
return TreeUtil.list2TreeConverter(list,0);
|
return TreeUtil.list2TreeConverter(list,0);
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<YxStoreCategoryM
|
|||||||
|
|
||||||
List<CateDTO> list = categoryMap.toDto(baseMapper.selectList(wrapper));
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
@ -20,6 +21,7 @@ import java.util.Objects;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Table(name="yx_store_category")
|
@Table(name="yx_store_category")
|
||||||
|
//@Where(clause = "is_del = 0")
|
||||||
public class YxStoreCategory implements Serializable {
|
public class YxStoreCategory implements Serializable {
|
||||||
|
|
||||||
// 商品分类表ID
|
// 商品分类表ID
|
||||||
@ -58,6 +60,9 @@ public class YxStoreCategory implements Serializable {
|
|||||||
@Column(name = "add_time",nullable = false)
|
@Column(name = "add_time",nullable = false)
|
||||||
private Integer addTime;
|
private Integer addTime;
|
||||||
|
|
||||||
|
@Column(name = "is_del",insertable = false)
|
||||||
|
private Integer isDel;
|
||||||
|
|
||||||
public void copy(YxStoreCategory source){
|
public void copy(YxStoreCategory source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package co.yixiang.modules.shop.repository;
|
|||||||
import co.yixiang.modules.shop.domain.YxStoreCategory;
|
import co.yixiang.modules.shop.domain.YxStoreCategory;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
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)
|
@Query(value = "select cate_name from yx_store_category where id = ?1",nativeQuery = true)
|
||||||
String findNameById(Integer id);
|
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);
|
YxStoreCategory findByPid(Integer pid);
|
||||||
|
|
||||||
}
|
}
|
@ -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)
|
@Query(value = "update yx_store_product set is_del = ?1 where id = ?2",nativeQuery = true)
|
||||||
void updateDel(int status, int id);
|
void updateDel(int status, int id);
|
||||||
|
|
||||||
List<YxStoreProduct> findByStoreCategory(YxStoreCategory storeCategory);
|
List<YxStoreProduct> findByStoreCategoryAndIsDel(YxStoreCategory storeCategory,int isDel);
|
||||||
}
|
}
|
@ -13,4 +13,7 @@ public class YxStoreCategoryQueryCriteria{
|
|||||||
// 模糊
|
// 模糊
|
||||||
@Query(type = Query.Type.INNER_LIKE)
|
@Query(type = Query.Type.INNER_LIKE)
|
||||||
private String cateName;
|
private String cateName;
|
||||||
|
|
||||||
|
@Query
|
||||||
|
private Integer isDel = 0;
|
||||||
}
|
}
|
@ -111,11 +111,11 @@ public class YxStoreCategoryServiceImpl implements YxStoreCategoryService {
|
|||||||
if(storeCategory != null) throw new BadRequestException("请先删除子类");
|
if(storeCategory != null) throw new BadRequestException("请先删除子类");
|
||||||
YxStoreCategory category = new YxStoreCategory();
|
YxStoreCategory category = new YxStoreCategory();
|
||||||
category.setId(id);
|
category.setId(id);
|
||||||
List<YxStoreProduct> storeProduct = yxStoreProductRepository.findByStoreCategory(category);
|
List<YxStoreProduct> storeProduct = yxStoreProductRepository.findByStoreCategoryAndIsDel(category,0);
|
||||||
|
|
||||||
if(!storeProduct.isEmpty()) throw new BadRequestException("此分类下有商品,不能删除");
|
if(!storeProduct.isEmpty()) throw new BadRequestException("此分类下有商品,不能删除");
|
||||||
|
|
||||||
yxStoreCategoryRepository.deleteById(id);
|
yxStoreCategoryRepository.delCategory(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user