This commit is contained in:
wangjinlei
2024-05-10 13:48:57 +08:00
parent 452a246875
commit 33e8f142d4
3 changed files with 23 additions and 5 deletions

View File

@@ -185,10 +185,12 @@ public class ShopProductController {
@RequestMapping("/bindProductAndCourse")
public R bindProductAndCourse(@RequestBody ShopProductCourseEntity shopProductCourseEntity){
shopProductService.bindProductAndCourse(shopProductCourseEntity);
return null;
return shopProductService.bindProductAndCourse(shopProductCourseEntity);
}
@RequestMapping("/unbindProductAndCourse")
public R unbindProductAndCourse(@RequestBody Map<String,Integer> map){
return shopProductService.unbindProductAndCourse(map.get("productId"),map.get("catalogueId"));
}
}

View File

@@ -53,5 +53,7 @@ public interface ShopProductService extends IService<ShopProduct> {
Map<String, Object> getCanBindProductAndCourse(ParamTo param);
void bindProductAndCourse(ShopProductCourseEntity shopProductCourseEntity);
R bindProductAndCourse(ShopProductCourseEntity shopProductCourseEntity);
R unbindProductAndCourse(int productId,int catalogueId);
}

View File

@@ -257,8 +257,22 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
}
@Override
public void bindProductAndCourse(ShopProductCourseEntity shopProductCourseEntity) {
public R bindProductAndCourse(ShopProductCourseEntity shopProductCourseEntity) {
Integer integer = shopProductCourseDao.selectCount(new LambdaQueryWrapper<ShopProductCourseEntity>().eq(ShopProductCourseEntity::getProductId, shopProductCourseEntity.getProductId()).eq(ShopProductCourseEntity::getCourseId, shopProductCourseEntity.getCourseId()));
if(integer>0){
return R.error("不可重复绑定");
}
CourseCatalogueEntity courseCatalogueEntity = courseCatalogueDao.selectById(shopProductCourseEntity.getCatalogueId());
shopProductCourseEntity.setCourseId(courseCatalogueEntity.getId());
shopProductCourseDao.insert(shopProductCourseEntity);
return R.ok();
}
@Override
public R unbindProductAndCourse(int productId, int catalogueId) {
shopProductCourseDao.delete(new LambdaQueryWrapper<ShopProductCourseEntity>().eq(ShopProductCourseEntity::getProductId,productId).eq(ShopProductCourseEntity::getCatalogueId,catalogueId));
return R.ok();
}
@Override