商品新增只能选择2级的验证
This commit is contained in:
@ -49,4 +49,6 @@ public interface YxStoreCategoryService extends BaseService<YxStoreCategory>{
|
||||
|
||||
|
||||
boolean checkCategory(int pid);
|
||||
|
||||
boolean checkProductCategory(int id);
|
||||
}
|
||||
|
@ -143,6 +143,7 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<StoreCategoryMap
|
||||
* @param pid 父级id
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCategory(int pid){
|
||||
if(pid == 0) return true;
|
||||
YxStoreCategory yxStoreCategory = this.getOne(Wrappers.<YxStoreCategory>lambdaQuery()
|
||||
@ -152,13 +153,18 @@ public class YxStoreCategoryServiceImpl extends BaseServiceImpl<StoreCategoryMap
|
||||
return true;
|
||||
}
|
||||
|
||||
// public boolean checkCategory(int id,int pid){
|
||||
// YxStoreCategory yxStoreCategory = this.getOne(Wrappers.<YxStoreCategory>lambdaQuery()
|
||||
// .eq(YxStoreCategory::getPid,pid));
|
||||
//
|
||||
// // DateUtil.format()
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
/**
|
||||
* 检测商品分类必选选择二级
|
||||
* @param id 分类id
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean checkProductCategory(int id){
|
||||
YxStoreCategory yxStoreCategory = this.getOne(Wrappers.<YxStoreCategory>lambdaQuery()
|
||||
.eq(YxStoreCategory::getId,id));
|
||||
|
||||
if(yxStoreCategory.getPid() == 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -148,6 +148,9 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
if (storeProduct.getStoreCategory().getId() == null) {
|
||||
throw new BadRequestException("分类名称不能为空");
|
||||
}
|
||||
boolean check = yxStoreCategoryService
|
||||
.checkProductCategory(storeProduct.getStoreCategory().getId());
|
||||
if(!check) throw new BadRequestException("商品分类必选选择二级");
|
||||
storeProduct.setCateId(storeProduct.getStoreCategory().getId().toString());
|
||||
this.save(storeProduct);
|
||||
return storeProduct;
|
||||
@ -300,6 +303,9 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
@Override
|
||||
public void updateProduct(YxStoreProduct resources) {
|
||||
if(resources.getStoreCategory() == null || resources.getStoreCategory().getId() == null) throw new BadRequestException("请选择分类");
|
||||
boolean check = yxStoreCategoryService
|
||||
.checkProductCategory(resources.getStoreCategory().getId());
|
||||
if(!check) throw new BadRequestException("商品分类必选选择二级");
|
||||
resources.setCateId(resources.getStoreCategory().getId().toString());
|
||||
this.saveOrUpdate(resources);
|
||||
}
|
||||
|
Reference in New Issue
Block a user