kongzy
2024-09-14 f0f00e9ba8a755e4317e029d73b69a92ad9f9df1
exam-system/src/main/java/com/gkhy/exam/system/service/impl/SysCategoryServiceImpl.java
@@ -7,8 +7,11 @@
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.SysCategory;
import com.gkhy.exam.system.mapper.ExCourseMapper;
import com.gkhy.exam.system.mapper.ExQuestionBankMapper;
import com.gkhy.exam.system.mapper.SysCategoryMapper;
import com.gkhy.exam.system.service.SysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
@@ -26,6 +29,10 @@
 */
@Service
public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCategory> implements SysCategoryService {
    @Autowired
    private ExCourseMapper courseMapper;
    @Autowired
    private ExQuestionBankMapper questionBankMapper;
    @Override
    public List<SysCategory> selectCategoryList(SysCategory category) {
@@ -82,15 +89,15 @@
    public int deleteCategoryById(Long categoryId) {
        //校验课程分类是否存在课程或者题目
        checkUserAllowed();
        int courseCount=baseMapper.selectCountOfCoure(categoryId);
        int courseCount=courseMapper.selectCountByCategoryId(categoryId);
        if(courseCount>0){
            throw new ApiException("已绑定课程,无法删除");
        }
        int bankCount=baseMapper.selectCountOfBank(categoryId);
        int bankCount=questionBankMapper.selectCountByCategoryId(categoryId);
        if(bankCount>0){
            throw new ApiException("已绑定题库,无法删除");
        }
        int row=baseMapper.deleteById(categoryId);
        int row=baseMapper.deleteByCategoryId(categoryId);
        if(row<1){
            throw new ApiException("删除课程分类失败");
        }