|
@@ -5,7 +5,10 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.txz.mall.core.Result;
|
|
|
+import com.txz.mall.core.UserUtil;
|
|
|
import com.txz.mall.model.OtherNotice;
|
|
|
import com.txz.mall.service.NoticeService;
|
|
|
import com.txz.mall.service.OtherNoticeService;
|
|
@@ -16,6 +19,8 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
/**
|
|
|
* [后台]通知模板
|
|
|
*
|
|
@@ -36,9 +41,9 @@ public class NoticeController {
|
|
|
*/
|
|
|
@GetMapping("page")
|
|
|
public Result<Page<OtherNotice>> page(BasePageParam page, String queryStr) {
|
|
|
- Page queryPage = new Page(page.getPage(), page.getSize());
|
|
|
+ PageHelper.startPage(page.getPage(), page.getSize());
|
|
|
return Result.success(
|
|
|
- otherNoticeService.page(queryPage, Wrappers.<OtherNotice>lambdaQuery()
|
|
|
+ new PageInfo<>(otherNoticeService.list(Wrappers.<OtherNotice>lambdaQuery()
|
|
|
.and(StrUtil.isNotBlank(queryStr),
|
|
|
item -> item
|
|
|
.like(OtherNotice::getTitle, queryStr)
|
|
@@ -46,7 +51,8 @@ public class NoticeController {
|
|
|
.like(OtherNotice::getMessage, queryStr)
|
|
|
)
|
|
|
.eq(OtherNotice::getIsDelete, Boolean.FALSE)
|
|
|
- )
|
|
|
+ .orderByDesc(OtherNotice::getCreateTime)
|
|
|
+ ))
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -54,8 +60,9 @@ public class NoticeController {
|
|
|
* 新增
|
|
|
*/
|
|
|
@PostMapping("save")
|
|
|
- public Result save(@Validated({OtherNoticeRO.Add.class}) @RequestBody OtherNoticeRO ro) {
|
|
|
+ public Result save(@Validated({OtherNoticeRO.Add.class}) @RequestBody OtherNoticeRO ro, HttpServletRequest request) {
|
|
|
OtherNotice otherNotice = BeanUtil.copyProperties(ro, OtherNotice.class);
|
|
|
+ otherNotice.setCreateUserId(UserUtil.getAdminUserId(request));
|
|
|
otherNoticeService.save(otherNotice);
|
|
|
return Result.success();
|
|
|
}
|
|
@@ -66,7 +73,7 @@ public class NoticeController {
|
|
|
@GetMapping("info/{id:^\\d+$}")
|
|
|
public Result info(@PathVariable("id") Long id) {
|
|
|
OtherNotice info = otherNoticeService.getById(id);
|
|
|
- if (ObjectUtil.isEmpty(info)) {
|
|
|
+ if (ObjectUtil.isEmpty(info) || info.getIsDelete() == 1) {
|
|
|
return Result.fail("数据不存在");
|
|
|
}
|
|
|
return Result.success(info);
|
|
@@ -85,7 +92,7 @@ public class NoticeController {
|
|
|
* 更新
|
|
|
*/
|
|
|
@PatchMapping("update/{id:^\\d+$}")
|
|
|
- public Result update(@Validated({OtherNoticeRO.Update.class}) @RequestBody OtherNoticeRO ro, @PathVariable("id") Long id) {
|
|
|
+ public Result update(@Validated({OtherNoticeRO.Update.class}) @RequestBody OtherNoticeRO ro, @PathVariable("id") Long id, HttpServletRequest request) {
|
|
|
OtherNotice info = otherNoticeService.getById(id);
|
|
|
if (ObjectUtil.isEmpty(info)) {
|
|
|
return Result.fail("数据不存在");
|
|
@@ -94,6 +101,7 @@ public class NoticeController {
|
|
|
return Result.fail("数据已删除");
|
|
|
}
|
|
|
BeanUtil.copyProperties(ro, info);
|
|
|
+ info.setUpdateUserId(UserUtil.getAdminUserId(request));
|
|
|
otherNoticeService.updateById(info);
|
|
|
return Result.success();
|
|
|
}
|