关于(逻辑)删除接口java代码

/**
 * 删除接口(逻辑删除)
 */
@GetMapping("/deleteCategory")
public Result updateCategory(@RequestParam("id") Long id) {
    broadScopeService.updateCategory(id);
    return Result.success();
}

service

Result updateCategory(Long id);
/**
     * 删除分类(修改)
     *
     * @param id
     * @return
     */
    @Transactional
    @Override
    public Result updateCategory(Long id) {
        if (ObjectUtil.isNull(id)){
            throw new BusinessException(MessageConstant.ID_NULL);
        }
        //当用户点选的指令分类下没有任何指令时,才可删除
        long l = broadScopePromptMapper.countByCategoryId(id);
        if (l ==0){
            boolean b = broadScopeMapper.deleteCategory(id);
            if (ObjectUtil.isNull(b)){
                //删除失败
                throw new BusinessException(MessageConstant.DELETE_FAILED);
            }
        }else {
            //该分类下有指令,不能删除
            throw new BusinessException(MessageConstant.CATEGORY_DELETE);
        }
        return Result.success();
    }
broadScopePromptMapper

mapper:

/**
 * 根据id查询分类下有多少个指令
 * @param id
 * @return
 */
long countByCategoryId(Long id);

xml:


BroadScopeMapper

mapper:

boolean deleteCategory(Long id);

xml:



    update  broadscope_prompt_category
    
        
            status=0
        
    
    where id=#{id}

测试:

关于(逻辑)删除接口java代码_第1张图片

你可能感兴趣的:(java,开发语言)