商品分类新增最多只能添加2级的验证
This commit is contained in:
@ -14,6 +14,7 @@ import co.yixiang.modules.shop.service.YxStoreCategoryService;
|
||||
import co.yixiang.modules.shop.service.dto.YxStoreCategoryDto;
|
||||
import co.yixiang.modules.shop.service.dto.YxStoreCategoryQueryCriteria;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -33,6 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.sql.Wrapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -82,6 +84,12 @@ public class StoreCategoryController {
|
||||
throw new BadRequestException("子分类图片必传");
|
||||
}
|
||||
|
||||
|
||||
boolean checkResult = yxStoreCategoryService.checkCategory(resources.getPid());
|
||||
|
||||
if(!checkResult) throw new BadRequestException("分类最多能添加2级哦");
|
||||
|
||||
|
||||
resources.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
return new ResponseEntity(yxStoreCategoryService.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
@ -96,6 +104,10 @@ public class StoreCategoryController {
|
||||
if(resources.getPid() > 0 && StrUtil.isBlank(resources.getPic())) {
|
||||
throw new BadRequestException("子分类图片必传");
|
||||
}
|
||||
boolean checkResult = yxStoreCategoryService.checkCategory(resources.getPid());
|
||||
|
||||
if(!checkResult) throw new BadRequestException("分类最多能添加2级哦");
|
||||
|
||||
yxStoreCategoryService.saveOrUpdate(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
@ -46,4 +46,7 @@ public interface YxStoreCategoryService extends BaseService<YxStoreCategory>{
|
||||
void download(List<YxStoreCategoryDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
Object buildTree(List<YxStoreCategoryDto> categoryDTOList);
|
||||
|
||||
|
||||
boolean checkCategory(int pid);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package co.yixiang.modules.shop.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
@ -14,6 +15,7 @@ import co.yixiang.modules.shop.service.dto.YxStoreCategoryDto;
|
||||
import co.yixiang.modules.shop.service.dto.YxStoreCategoryQueryCriteria;
|
||||
import co.yixiang.modules.shop.service.mapper.StoreCategoryMapper;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@ -134,4 +136,29 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<StoreCategoryMap
|
||||
map.put("content",CollectionUtils.isEmpty(trees)?categoryDTOS:trees);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检测分类是否操过二级
|
||||
* @param pid 父级id
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean checkCategory(int pid){
|
||||
if(pid == 0) return true;
|
||||
YxStoreCategory yxStoreCategory = this.getOne(Wrappers.<YxStoreCategory>lambdaQuery()
|
||||
.eq(YxStoreCategory::getId,pid));
|
||||
if(yxStoreCategory.getPid() > 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// public boolean checkCategory(int id,int pid){
|
||||
// YxStoreCategory yxStoreCategory = this.getOne(Wrappers.<YxStoreCategory>lambdaQuery()
|
||||
// .eq(YxStoreCategory::getPid,pid));
|
||||
//
|
||||
// // DateUtil.format()
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user