Update NoticeController.java

cyj
pbvfus8to 8 months ago
parent 3d7ac2bd0d
commit 5e9728171e

@ -27,7 +27,7 @@ import java.util.Date;
/**
*
*
*
* @author hzm
* @date
*/
@ -36,30 +36,31 @@ import java.util.Date;
@RequestMapping("/shop/notice")
public class NoticeController {
// 通过构造函数注入NoticeService用于调用业务层方法来处理公告相关的业务逻辑
private final NoticeService noticeService;
/**
*
*
* @param page
* @param notice
* @return
*
*
* @param page
* @param notice
* @return ServerResponseEntity<IPage<Notice>>
*/
@GetMapping("/page")
public ServerResponseEntity<IPage<Notice>> getNoticePage(PageParam<Notice> page, Notice notice) {
// 使用MyBatis Plus的LambdaQueryWrapper构建查询条件根据传入的公告对象中的非空字段进行筛选
// 例如根据状态、是否置顶、标题等进行筛选,并按照更新时间降序排列
IPage<Notice> noticePage = noticeService.page(page, new LambdaQueryWrapper<Notice>()
.eq(notice.getStatus() != null, Notice::getStatus, notice.getStatus())
.eq(notice.getIsTop()!=null,Notice::getIsTop,notice.getIsTop())
.like(notice.getTitle() != null, Notice::getTitle, notice.getTitle()).orderByDesc(Notice::getUpdateTime));
.eq(notice.getStatus()!= null, Notice::getStatus, notice.getStatus())
.eq(notice.getIsTop()!= null, Notice::getIsTop, notice.getIsTop())
.like(notice.getTitle()!= null, Notice::getTitle, notice.getTitle()).orderByDesc(Notice::getUpdateTime));
return ServerResponseEntity.success(noticePage);
}
/**
* id
*
* @param id id
* @return
* id
* @param id id
* @return ServerResponseEntity<Notice>id
*/
@GetMapping("/info/{id}")
public ServerResponseEntity<Notice> getById(@PathVariable("id") Long id) {
@ -67,57 +68,65 @@ public class NoticeController {
}
/**
*
*
* @param notice
* @return
*
*
* @param notice
* @return ServerResponseEntity<Boolean>truefalse
*/
@SysLog("新增公告管理")
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:notice:save')")
// 使用 @PreAuthorize 注解进行权限校验,只有拥有'shop:notice:save'权限的用户才能访问该接口
public ServerResponseEntity<Boolean> save(@RequestBody @Valid Notice notice) {
// 设置公告所属店铺的id从当前登录用户信息中获取
notice.setShopId(SecurityUtils.getSysUser().getShopId());
if (notice.getStatus() == 1) {
// 如果公告状态为已发布1表示已发布则设置发布时间为当前时间
notice.setPublishTime(new Date());
}
notice.setUpdateTime(new Date());
// 调用业务层方法先移除相关的公告列表具体逻辑由业务层的removeNoticeList方法决定
noticeService.removeNoticeList();
return ServerResponseEntity.success(noticeService.save(notice));
}
/**
*
*
* @param notice
* @return
*
*
* @param notice
* @return ServerResponseEntity<Boolean>truefalse
*/
@SysLog("修改公告管理")
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:notice:update')")
// 使用 @PreAuthorize 注解进行权限校验,只有拥有'shop:notice:update'权限的用户才能访问该接口
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid Notice notice) {
Notice oldNotice = noticeService.getById(notice.getId());
if (oldNotice.getStatus() == 0 && notice.getStatus() == 1) {
// 如果原公告状态为未发布0表示未发布修改后变为已发布1表示已发布则设置发布时间为当前时间
notice.setPublishTime(new Date());
}
notice.setUpdateTime(new Date());
// 调用业务层方法先移除相关的公告列表具体逻辑由业务层的removeNoticeList方法决定
noticeService.removeNoticeList();
// 移除要修改的这条公告具体逻辑由业务层的removeNoticeById方法决定可能是缓存清除等相关操作
noticeService.removeNoticeById(notice.getId());
return ServerResponseEntity.success(noticeService.updateById(notice));
}
/**
* id
*
* @param id id
* @return
* id
* id
* @param id id
* @return ServerResponseEntity<Boolean>truefalse
*/
@SysLog("删除公告管理")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:notice:delete')")
// 使用 @PreAuthorize 注解进行权限校验,只有拥有'shop:notice:delete'权限的用户才能访问该接口
public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
noticeService.removeNoticeList();
noticeService.removeNoticeById(id);
return ServerResponseEntity.success(noticeService.removeById(id));
}
}
}
Loading…
Cancel
Save