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