- 调用修改和删除的方法
@AutoLog(value = "通知公告-编辑")
@ApiOperation(value="通知公告-编辑", notes="通知公告-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody NoticeEntity noticeEntity,HttpServletRequest request) {
LoginUser loginUser = getCurrentUser();
String userId = loginUser.getId();
log.debug("当前用户Id{}",userId);
String createUsernameId = noticeEntity.getPublisher();
if (userId == null){
return Result.error("检查当前用户");
}
if (createUsernameId == null){
return Result.error("通知发布者为空");
}
if (userId.equals(createUsernameId)){
NoticeEntity oldEntiry = noticeService.getById(noticeEntity.getId());
if (oldEntiry.getFilePath().equals("")&¬iceEntity.getFilePath().equals("")){
String fileName = oldEntiry.getFilePath().substring(oldEntiry.getFilePath().lastIndexOf("/") + 1);
noticeEntity.setFileName(fileName);
noticeEntity.setFilePath(oldEntiry.getFilePath());
}else{
String fileName = noticeEntity.getFilePath().substring(noticeEntity.getFilePath().lastIndexOf("/") + 1);
noticeEntity.setFileName(fileName);
}
noticeService.updateById(noticeEntity);
return Result.ok("编辑成功!");
}else{
return Result.error("只有发布者有权限修改信息");
}
}
@AutoLog(value = "通知公告-通过id删除")
@ApiOperation(value="通知公告-通过id删除", notes="通知公告-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id,HttpServletRequest request,NoticeEntity noticeEntity) {
String username = JwtUtil.getUserNameByToken(request);
LoginUser loginUser = getCurrentUser();
String userId = loginUser.getId();
NoticeEntity oldEntiry = noticeService.getById(id);
String createUsername = oldEntiry.getPublisher();
log.debug("当前登录用户{}",userId);
log.debug("创建用户{}",createUsername);
if (userId == null){
return Result.error("检查当前用户id");
}
if (username == null){
return Result.error("检查当前用户名");
}
if (userId.equals(createUsername) || username.equals("admin")){
log.debug("可以删除");
noticeService.removeById(id);
return Result.ok("删除成功!");
} else {
log.debug("只有发布者与管理员有权删除");
return Result.error("只有发布者与管理员有权删除");
}
}
我只想说:我是菜狗。
|