修复WorksServiceImpl:添加缺失的updateWorksStatus方法实现
- 实现updateWorksStatus方法用于上架/下架作品 - 添加状态值验证(只能是0或1) - 添加作品存在性检查 - 添加日志记录 - 修复编译错误
This commit is contained in:
parent
1258c0f1fd
commit
fb1b493fc5
|
|
@ -299,6 +299,34 @@ public class WorksServiceImpl extends ServiceImpl<WorksDao, Works> implements Wo
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateWorksStatus(Long worksId, Integer status) {
|
||||
// 验证状态值
|
||||
if (status != 0 && status != 1) {
|
||||
throw new CrmebException("状态值无效,只能是0(下架)或1(上架)");
|
||||
}
|
||||
|
||||
// 查询作品
|
||||
Works works = getById(worksId);
|
||||
if (works == null || works.getIsDeleted() == 1) {
|
||||
throw new CrmebException("作品不存在");
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
LambdaUpdateWrapper<Works> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(Works::getId, worksId)
|
||||
.set(Works::getStatus, status);
|
||||
|
||||
boolean updated = update(updateWrapper);
|
||||
if (!updated) {
|
||||
throw new CrmebException("更新作品状态失败");
|
||||
}
|
||||
|
||||
log.info("更新作品状态成功,作品ID:{},新状态:{}", worksId, status == 1 ? "上架" : "下架");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorksResponse getWorksDetail(Long worksId, Integer userId) {
|
||||
log.info("=== 获取作品详情 === worksId={}, userId={}", worksId, userId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user