mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 06:51:23 +08:00
use pinia to modify notice update function and add pagination to noticeManage page
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
@@ -40,7 +42,7 @@ public class NoticeController {
|
||||
return ResponseResult.build(code, msg, noticeById);
|
||||
}
|
||||
|
||||
//查询所有公告
|
||||
//查询所有公告或模糊查询
|
||||
@GetMapping
|
||||
public ResponseResult selectAllNotice(String title, String type, String startTime, String endTime) {
|
||||
List<Notice> noticeList;
|
||||
@@ -88,4 +90,27 @@ public class NoticeController {
|
||||
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById);
|
||||
}
|
||||
|
||||
//分页查询所有公告或分页模糊查询
|
||||
@GetMapping("/page")
|
||||
public ResponseResult selectPageAllNotice(Integer currentPage,Integer pageSize,String title, String type, String startTime, String endTime) {
|
||||
IPage<Notice> noticePageList;
|
||||
Page<?> page = new Page();
|
||||
if (null!=currentPage&&null!=pageSize){
|
||||
page.setCurrent(currentPage.intValue());
|
||||
page.setSize(pageSize.intValue());
|
||||
}else {
|
||||
// 不进行分页
|
||||
page.setCurrent(1);
|
||||
page.setSize(-1);
|
||||
}
|
||||
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
|
||||
noticePageList = noticeService.selectPageAllNotice(page);
|
||||
} else {
|
||||
noticePageList = noticeService.selectPageByCond(page,title, type, startTime, endTime);
|
||||
}
|
||||
int code = noticePageList.getRecords() != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = noticePageList.getRecords() != null ? String.valueOf(noticePageList.getTotal()) : "数据查询失败,请尝试!";
|
||||
return ResponseResult.build(code, msg, noticePageList.getRecords());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cfive.pinnacle.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -22,4 +23,8 @@ public interface NoticeMapper extends BaseMapper<Notice> {
|
||||
List<Notice> selectAllNotice();
|
||||
|
||||
List<Notice> selectByCond(String title, String type, LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
IPage<Notice> selectPageAllNotice(IPage<?> page);
|
||||
|
||||
IPage<Notice> selectPageByCond(IPage<?> page, String title, String type, LocalDateTime startTime, LocalDateTime endTime);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cfive.pinnacle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@@ -18,11 +19,15 @@ public interface INoticeService extends IService<Notice> {
|
||||
|
||||
List<Notice> selectAllNotice();
|
||||
|
||||
List<Notice> selectByCond(String title,String type,String startTime,String endTime);
|
||||
List<Notice> selectByCond(String title, String type, String startTime, String endTime);
|
||||
|
||||
Boolean deleteById(Long nid);
|
||||
|
||||
Boolean updateNotice(Notice notice);
|
||||
|
||||
Boolean addNotice(Notice notice);
|
||||
|
||||
IPage<Notice> selectPageAllNotice(IPage<?> page);
|
||||
|
||||
IPage<Notice> selectPageByCond(IPage<?> page, String title, String type, String startTime, String endTime);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
@@ -48,20 +49,6 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
@Override
|
||||
public List<Notice> selectAllNotice() {
|
||||
List<Notice> notices = noticeMapper.selectAllNotice();
|
||||
// if (null != notices) {
|
||||
// for (Notice notice :
|
||||
// notices) {
|
||||
// LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
|
||||
// lqw.eq(NoticeReceive::getNoticeId, notice.getId());
|
||||
// List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw);
|
||||
// List<Long> receiverIdList = new ArrayList<>();
|
||||
// for (NoticeReceive noticeReceive :
|
||||
// noticeReceives) {
|
||||
// receiverIdList.add(noticeReceive.getUserId());
|
||||
// }
|
||||
// notice.setReceivers(receiverIdList);
|
||||
// }
|
||||
// }
|
||||
return notices;
|
||||
}
|
||||
|
||||
@@ -105,8 +92,8 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
public Boolean deleteById(Long nid) {
|
||||
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(NoticeReceive::getNoticeId, nid);
|
||||
Boolean flag = noticeReceiveMapper.delete(lqw)>0;
|
||||
return flag&&(noticeMapper.deleteById(nid) > 0);
|
||||
Boolean flag=noticeReceiveMapper.delete(lqw)>0;
|
||||
return flag&¬iceMapper.deleteById(nid) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,21 +109,48 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
@Override
|
||||
public Boolean addNotice(Notice notice) {
|
||||
Boolean noticeFlag,noticeRecFlag=false;
|
||||
// notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
|
||||
notice.setSenderId(1652714496280469506L);
|
||||
notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
|
||||
// notice.setSenderId(1652714496280469506L);
|
||||
noticeFlag = noticeMapper.insert(notice)>0;
|
||||
Long noticeId = notice.getId();
|
||||
for (Long receiveId :
|
||||
notice.getReceivers()) {
|
||||
if (notice.getReceivers().size()==0){
|
||||
//该公告仅发布者自己可见
|
||||
NoticeReceive noticeReceive = new NoticeReceive();
|
||||
noticeReceive.setNoticeId(noticeId);
|
||||
noticeReceive.setUserId(receiveId);
|
||||
noticeReceive.setUserId(WebUtil.getLoginUser().getUser().getId());
|
||||
noticeRecFlag = noticeReceiveMapper.insert(noticeReceive)>0;
|
||||
if (!noticeRecFlag){
|
||||
break;
|
||||
}else {
|
||||
for (Long receiveId :
|
||||
notice.getReceivers()) {
|
||||
NoticeReceive noticeReceive = new NoticeReceive();
|
||||
noticeReceive.setNoticeId(noticeId);
|
||||
noticeReceive.setUserId(receiveId);
|
||||
noticeRecFlag = noticeReceiveMapper.insert(noticeReceive)>0;
|
||||
if (!noticeRecFlag){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return noticeFlag && noticeRecFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Notice> selectPageAllNotice(IPage<?> page) {
|
||||
return noticeMapper.selectPageAllNotice(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Notice> selectPageByCond(IPage<?> page, String title, String type, String startTime, String endTime) {
|
||||
LocalDateTime start;
|
||||
LocalDateTime end;
|
||||
try {
|
||||
start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
start = null;
|
||||
end = null;
|
||||
}
|
||||
return noticeMapper.selectPageByCond(page,title, type, start, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,21 +21,48 @@
|
||||
<!-- 查询所有公告 -->
|
||||
<select id="selectAllNotice" resultMap="NoticeAllResultMap">
|
||||
select u.id uid,
|
||||
username,
|
||||
u.username,
|
||||
n.id nid,
|
||||
title,
|
||||
content,
|
||||
type_id,
|
||||
sender_id,
|
||||
create_time,
|
||||
send_time,
|
||||
end_time,
|
||||
priority,
|
||||
top,
|
||||
modify_time,
|
||||
origin_id,
|
||||
n.title,
|
||||
n.content,
|
||||
n.type_id,
|
||||
n.sender_id,
|
||||
n.create_time,
|
||||
n.send_time,
|
||||
n.end_time,
|
||||
n.priority,
|
||||
n.top,
|
||||
n.modify_time,
|
||||
n.origin_id,
|
||||
type.id typeId,
|
||||
name,
|
||||
type.name,
|
||||
type.enable
|
||||
from t_notice n
|
||||
left join t_notice_type type on n.type_id = type.id
|
||||
left join t_user u on n.sender_id = u.id
|
||||
where n.deleted = 0
|
||||
and n.old = 0
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<!-- 分页查询所有公告 -->
|
||||
<select id="selectPageAllNotice" resultMap="NoticeAllResultMap" resultType="notice">
|
||||
select u.id uid,
|
||||
u.username,
|
||||
n.id nid,
|
||||
n.title,
|
||||
n.content,
|
||||
n.type_id,
|
||||
n.sender_id,
|
||||
n.create_time,
|
||||
n.send_time,
|
||||
n.end_time,
|
||||
n.priority,
|
||||
n.top,
|
||||
n.modify_time,
|
||||
n.origin_id,
|
||||
type.id typeId,
|
||||
type.name,
|
||||
type.enable
|
||||
from t_notice n
|
||||
left join t_notice_type type on n.type_id = type.id
|
||||
@@ -53,22 +80,62 @@
|
||||
<id property="id" column="typeId"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
<!-- 模糊查询-->
|
||||
<!-- 模糊查询公告-->
|
||||
<select id="selectByCond" resultMap="NoticeAllResultMap">
|
||||
select u.id uid,
|
||||
username,
|
||||
u.username,
|
||||
n.id nid,
|
||||
title,
|
||||
content,
|
||||
type_id,
|
||||
sender_id,
|
||||
create_time,
|
||||
send_time,
|
||||
end_time,
|
||||
priority,
|
||||
top,
|
||||
modify_time,
|
||||
origin_id,
|
||||
n.title,
|
||||
n.content,
|
||||
n.type_id,
|
||||
n.sender_id,
|
||||
n.create_time,
|
||||
n.send_time,
|
||||
n.end_time,
|
||||
n.priority,
|
||||
n.top,
|
||||
n.modify_time,
|
||||
n.origin_id,
|
||||
type.id typeId,
|
||||
type.name,
|
||||
type.enable
|
||||
from t_notice n
|
||||
left join t_notice_type type on n.type_id = type.id
|
||||
left join t_user u on n.sender_id = u.id
|
||||
<where>
|
||||
<if test="null!=title and title!=''">
|
||||
and instr(title,#{title})>0
|
||||
</if>
|
||||
<if test="null!=type and type!=''">
|
||||
and instr(type.name,#{type})>0
|
||||
</if>
|
||||
<if test="null!=startTime">
|
||||
and send_time >= #{startTime}
|
||||
</if>
|
||||
<if test="null !=endTime">
|
||||
and end_time < #{endTime}
|
||||
</if>
|
||||
and n.deleted = 0
|
||||
and n.old = 0
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 模糊查询公告-->
|
||||
<select id="selectPageByCond" resultMap="NoticeAllResultMap" resultType="notice">
|
||||
select u.id uid,
|
||||
u.username,
|
||||
n.id nid,
|
||||
n.title,
|
||||
n.content,
|
||||
n.type_id,
|
||||
n.sender_id,
|
||||
n.create_time,
|
||||
n.send_time,
|
||||
n.end_time,
|
||||
n.priority,
|
||||
n.top,
|
||||
n.modify_time,
|
||||
n.origin_id,
|
||||
type.id typeId,
|
||||
type.name,
|
||||
type.enable
|
||||
|
||||
Reference in New Issue
Block a user