1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 06:51:23 +08:00

nitice module modified query with mybatis plus linked table to xml

This commit is contained in:
cccccyb
2023-05-11 15:26:55 +08:00
parent 3c7fc85b9e
commit 1defd7ef4e
21 changed files with 498 additions and 151 deletions

View File

@@ -42,12 +42,12 @@ public class NoticeController {
//查询所有公告 //查询所有公告
@GetMapping @GetMapping
public ResponseResult selectAllNotice(String title, String type, String startTime,String endTime) { public ResponseResult selectAllNotice(String title, String type, String startTime, String endTime) {
List<Notice> noticeList; List<Notice> noticeList;
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) { if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
noticeList = noticeService.selectAllNotice(); noticeList = noticeService.selectAllNotice();
} else { } else {
noticeList = noticeService.selectByCond(title, type, startTime,endTime); noticeList = noticeService.selectByCond(title, type, startTime, endTime);
} }
int code = noticeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR; int code = noticeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
@@ -55,6 +55,14 @@ public class NoticeController {
return ResponseResult.build(code, msg, noticeList); return ResponseResult.build(code, msg, noticeList);
} }
//根据登录用户id查询所接收的公告
@GetMapping("/ByUserId")
public ResponseResult selectAllByUserId() {
List<Notice> noticesByUserId = noticeReceiveService.selectAllByUserId();
Integer code = noticesByUserId != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = noticesByUserId != null ? "" : "数据查询失败,请尝试!";
return ResponseResult.build(code, msg, noticesByUserId);
}
//更新公告 //更新公告
@PutMapping @PutMapping
@@ -67,19 +75,9 @@ public class NoticeController {
//添加公告 //添加公告
@PostMapping @PostMapping
public ResponseResult addNotice(@RequestBody Notice notice) { public ResponseResult addNotice(@RequestBody Notice notice) {
notice.setSenderId(WebUtil.getLoginUser().getUser().getId()); Boolean insertNotice = noticeService.addNotice(notice);
boolean insertNotice = noticeService.save(notice); String msg = insertNotice ? "" : "数据添加失败,请尝试!";
Long noticeId = notice.getId(); return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
boolean flag = false;
for (Long receiveId :
notice.getReceivers()) {
NoticeReceive noticeReceive = new NoticeReceive();
noticeReceive.setNoticeId(noticeId);
noticeReceive.setUserId(receiveId);
flag = noticeReceiveService.save(noticeReceive);
}
String msg = (insertNotice && flag) ? "" : "数据添加失败,请尝试!";
return ResponseResult.build((insertNotice && flag) ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, noticeId);
} }
//删除公告 //删除公告
@@ -88,6 +86,6 @@ public class NoticeController {
boolean removeById = noticeService.deleteById(nid); boolean removeById = noticeService.deleteById(nid);
String msg = removeById ? "" : "数据删除失败,请尝试!"; String msg = removeById ? "" : "数据删除失败,请尝试!";
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById); return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById);
} }
} }

View File

@@ -128,6 +128,9 @@ public class Notice implements Serializable {
@TableField("old") @TableField("old")
private Integer old; private Integer old;
@TableField(exist = false)
private Integer isRead;
@TableField("deleted") @TableField("deleted")
@TableLogic @TableLogic
private Integer deleted; private Integer deleted;

View File

@@ -4,6 +4,8 @@ import com.cfive.pinnacle.entity.Department;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* <p> * <p>
* 部门 Mapper 接口 * 部门 Mapper 接口
@@ -14,5 +16,5 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface DepartmentMapper extends BaseMapper<Department> { public interface DepartmentMapper extends BaseMapper<Department> {
List<Department> getDepartAndUser();
} }

View File

@@ -4,6 +4,7 @@ import com.cfive.pinnacle.entity.Notice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@@ -19,4 +20,6 @@ public interface NoticeMapper extends BaseMapper<Notice> {
Notice selectByNoticeId(Long nid); Notice selectByNoticeId(Long nid);
List<Notice> selectAllNotice(); List<Notice> selectAllNotice();
List<Notice> selectByCond(String title, String type, LocalDateTime startTime, LocalDateTime endTime);
} }

View File

@@ -1,9 +1,12 @@
package com.cfive.pinnacle.mapper; package com.cfive.pinnacle.mapper;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive; import com.cfive.pinnacle.entity.NoticeReceive;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* <p> * <p>
* 公告接收 Mapper 接口 * 公告接收 Mapper 接口
@@ -14,5 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface NoticeReceiveMapper extends BaseMapper<NoticeReceive> { public interface NoticeReceiveMapper extends BaseMapper<NoticeReceive> {
List<Notice> selectAllByUserId(Long userId);
} }

View File

@@ -1,8 +1,11 @@
package com.cfive.pinnacle.service; package com.cfive.pinnacle.service;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive; import com.cfive.pinnacle.entity.NoticeReceive;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* <p> * <p>
* 公告接收 服务类 * 公告接收 服务类
@@ -12,5 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2023-04-30 * @since 2023-04-30
*/ */
public interface INoticeReceiveService extends IService<NoticeReceive> { public interface INoticeReceiveService extends IService<NoticeReceive> {
List<Notice> selectAllByUserId();
} }

View File

@@ -23,4 +23,6 @@ public interface INoticeService extends IService<Notice> {
Boolean deleteById(Long nid); Boolean deleteById(Long nid);
Boolean updateNotice(Notice notice); Boolean updateNotice(Notice notice);
Boolean addNotice(Notice notice);
} }

View File

@@ -29,13 +29,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
private UserMapper userMapper; private UserMapper userMapper;
@Override @Override
public List<Department> getDepartAndUser() { public List<Department> getDepartAndUser() {
List<Department> departments = departmentMapper.selectList(null); return departmentMapper.getDepartAndUser();
for (Department department:
departments) {
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.eq(User::getDepartmentId, department.getId());
department.setUserList(userMapper.selectList(lqw));
}
return departments;
} }
} }

View File

@@ -1,11 +1,16 @@
package com.cfive.pinnacle.service.impl; package com.cfive.pinnacle.service.impl;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive; import com.cfive.pinnacle.entity.NoticeReceive;
import com.cfive.pinnacle.mapper.NoticeReceiveMapper; import com.cfive.pinnacle.mapper.NoticeReceiveMapper;
import com.cfive.pinnacle.service.INoticeReceiveService; import com.cfive.pinnacle.service.INoticeReceiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfive.pinnacle.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <p> * <p>
* 公告接收 服务实现类 * 公告接收 服务实现类
@@ -16,5 +21,11 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class NoticeReceiveServiceImpl extends ServiceImpl<NoticeReceiveMapper, NoticeReceive> implements INoticeReceiveService { public class NoticeReceiveServiceImpl extends ServiceImpl<NoticeReceiveMapper, NoticeReceive> implements INoticeReceiveService {
@Autowired
private NoticeReceiveMapper noticeReceiveMapper;
@Override
public List<Notice> selectAllByUserId() {
Long userId = WebUtil.getLoginUser().getUser().getId();
return noticeReceiveMapper.selectAllByUserId(userId);
}
} }

View File

@@ -11,6 +11,7 @@ import com.cfive.pinnacle.mapper.NoticeTypeMapper;
import com.cfive.pinnacle.mapper.UserMapper; import com.cfive.pinnacle.mapper.UserMapper;
import com.cfive.pinnacle.service.INoticeService; import com.cfive.pinnacle.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfive.pinnacle.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -47,56 +48,59 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
@Override @Override
public List<Notice> selectAllNotice() { public List<Notice> selectAllNotice() {
List<Notice> notices = noticeMapper.selectAllNotice(); List<Notice> notices = noticeMapper.selectAllNotice();
if (null != notices) { // if (null != notices) {
for (Notice notice : // for (Notice notice :
notices) { // notices) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
lqw.eq(NoticeReceive::getNoticeId, notice.getId()); // lqw.eq(NoticeReceive::getNoticeId, notice.getId());
List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw); // List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw);
List<Long> receiverIdList = new ArrayList<>(); // List<Long> receiverIdList = new ArrayList<>();
for (NoticeReceive noticeReceive : // for (NoticeReceive noticeReceive :
noticeReceives) { // noticeReceives) {
receiverIdList.add(noticeReceive.getUserId()); // receiverIdList.add(noticeReceive.getUserId());
} // }
notice.setReceivers(receiverIdList); // notice.setReceivers(receiverIdList);
} // }
} // }
return notices; return notices;
} }
@Override @Override
public List<Notice> selectByCond(String title, String type, String startTime,String endTime) { public List<Notice> selectByCond(String title, String type, String startTime,String endTime) {
List<Notice> notices = new ArrayList<>(); LocalDateTime start;
LocalDateTime start = null; LocalDateTime end;
LocalDateTime end = null;
try { try {
start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (Exception e) { } catch (Exception e) {
startTime = null; start = null;
endTime = null; end = null;
}
LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>();
LambdaQueryWrapper<NoticeType> lqw_type = new LambdaQueryWrapper<>();
lqw_type.like(null != type, NoticeType::getName, type);
List<NoticeType> noticeTypes = noticeTypeMapper.selectList(lqw_type);
for (NoticeType noticeType : noticeTypes
) {
lqw_notice.clear();
lqw_notice.eq(!noticeTypes.isEmpty(), Notice::getTypeId, noticeType.getId()).like(null != title, Notice::getTitle, title);
lqw_notice.ge(StringUtils.hasText(startTime), Notice::getSendTime, start);
lqw_notice.le(StringUtils.hasText(endTime), Notice::getEndTime, end);
List<Notice> temp_notice = noticeMapper.selectList(lqw_notice);
notices.addAll(temp_notice);
}
for (Notice n : notices
) {
n.setSender(userMapper.selectById(n.getSenderId()));
n.setNoticeType(noticeTypeMapper.selectById(n.getTypeId()));
} }
// LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>();
// LambdaQueryWrapper<NoticeType> lqw_type = new LambdaQueryWrapper<>();
// lqw_type.like(null != type, NoticeType::getName, type);
// List<NoticeType> noticeTypes = noticeTypeMapper.selectList(lqw_type);
// for (NoticeType noticeType : noticeTypes
// ) {
// lqw_notice.clear();
// lqw_notice.eq(!noticeTypes.isEmpty(), Notice::getTypeId, noticeType.getId()).like(null != title, Notice::getTitle, title);
// lqw_notice.ge(StringUtils.hasText(startTime), Notice::getSendTime, start);
// lqw_notice.le(StringUtils.hasText(endTime), Notice::getEndTime, end);
// lqw_notice.eq(Notice::getOld, 0);
// List<Notice> temp_notice = noticeMapper.selectList(lqw_notice);
// notices.addAll(temp_notice);
// }
// for (Notice n : notices
// ) {
// n.setSender(userMapper.selectById(n.getSenderId()));
// n.setNoticeType(noticeTypeMapper.selectById(n.getTypeId()));
// }
List<Notice> notices=noticeMapper.selectByCond(title, type, start, end);
return notices; return notices;
} }
@Override @Override
public Boolean deleteById(Long nid) { public Boolean deleteById(Long nid) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
@@ -120,4 +124,24 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
return noticeMapper.insert(notice) > 0; return noticeMapper.insert(notice) > 0;
} }
@Override
public Boolean addNotice(Notice notice) {
Boolean noticeFlag,noticeRecFlag=false;
// notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
notice.setSenderId(1652714496280469506L);
noticeFlag = noticeMapper.insert(notice)>0;
Long noticeId = notice.getId();
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;
}
} }

View File

@@ -2,9 +2,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cfive.pinnacle.mapper.DepartmentMapper"> <mapper namespace="com.cfive.pinnacle.mapper.DepartmentMapper">
<select id="getDepartAndUser" resultMap="department"> <select id="getDepartAndUser" resultMap="department">
select d.id,name,u.id,username from t_department d,t_user u where d.id=u.department_id and d.deleted=0 and u.deleted=0 select d.id did,name,u.id uid,username from t_department d,t_user u where d.id=u.department_id and d.deleted=0 and u.deleted=0
</select> </select>
<resultMap id="department" type="department" autoMapping="true"> <resultMap id="department" type="department" autoMapping="true">
<id column="id" property="id"/> <id column="did" property="id"/>
<collection property="userList" ofType="user" autoMapping="true">
<id column="uid" property="id"/>
<result column="uid" property="id"/>
</collection>
</resultMap> </resultMap>
</mapper> </mapper>

View File

@@ -8,10 +8,10 @@
t_notice n, t_notice n,
t_notice_type type t_notice_type type
where u.id = n.sender_id where u.id = n.sender_id
and type.id=n.type_id and type.id = n.type_id
and n.id = #{nid} and n.id = #{nid}
and n.deleted = 0 and n.deleted = 0
and n.old=0 and n.old = 0
</select> </select>
<resultMap id="NoticeByIdResultMap" type="notice" autoMapping="true"> <resultMap id="NoticeByIdResultMap" type="notice" autoMapping="true">
<association property="sender" javaType="user" autoMapping="true"/> <association property="sender" javaType="user" autoMapping="true"/>
@@ -20,13 +20,9 @@
<!-- 查询所有公告 --> <!-- 查询所有公告 -->
<select id="selectAllNotice" resultMap="NoticeAllResultMap"> <select id="selectAllNotice" resultMap="NoticeAllResultMap">
select u.id uid, select u.id uid,
username, username,
passwd, n.id nid,
department_id,
u.deleted ude,
u.version uve,
n.id nid,
title, title,
content, content,
type_id, type_id,
@@ -38,37 +34,62 @@
top, top,
modify_time, modify_time,
origin_id, origin_id,
old, type.id typeId,
n.deleted nde,
n.version nve,
type.id typeId,
name, name,
type.enable, type.enable
type.deleted typeDe, from t_notice n
type.version typeVe left join t_notice_type type on n.type_id = type.id
from t_user u, left join t_user u on n.sender_id = u.id
t_notice n, where n.deleted = 0
t_notice_type type
where u.id = n.sender_id
and type.id = n.type_id
and n.deleted = 0
and n.old = 0 and n.old = 0
order by create_time desc order by create_time desc
</select> </select>
<resultMap id="NoticeAllResultMap" type="notice" autoMapping="true"> <resultMap id="NoticeAllResultMap" type="notice" autoMapping="true">
<id property="id" column="nid"/> <id property="id" column="nid"/>
<result property="deleted" column="nde"/>
<result property="version" column="nve"/>
<association property="sender" javaType="user" autoMapping="true"> <association property="sender" javaType="user" autoMapping="true">
<id property="id" column="uid"/> <id property="id" column="uid"/>
<result property="deleted" column="ude"/>
<result property="version" column="uve"/>
</association> </association>
<association property="noticeType" javaType="noticeType" autoMapping="true"> <association property="noticeType" javaType="noticeType" autoMapping="true">
<id property="id" column="typeId"/> <id property="id" column="typeId"/>
<result property="deleted" column="typeDe"/>
<result property="version" column="typeVe"/>
</association> </association>
</resultMap> </resultMap>
<!-- 模糊查询--> <!-- 模糊查询-->
<select id="selectByCond" resultMap="NoticeAllResultMap">
select u.id uid,
username,
n.id nid,
title,
content,
type_id,
sender_id,
create_time,
send_time,
end_time,
priority,
top,
modify_time,
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})&gt;0
</if>
<if test="null!=type and type!=''">
and instr(type.name,#{type})&gt;0
</if>
<if test="null!=startTime">
and send_time &gt;= #{startTime}
</if>
<if test="null !=endTime">
and end_time &lt; #{endTime}
</if>
and n.deleted = 0
and n.old = 0
</where>
</select>
</mapper> </mapper>

View File

@@ -1,5 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cfive.pinnacle.mapper.NoticeReceiveMapper"> <mapper namespace="com.cfive.pinnacle.mapper.NoticeReceiveMapper">
<select id="selectAllByUserId" parameterType="Long" resultMap="selectAllMap">
select u.id uid,
username,
n.id nid,
title,
content,
type_id,
sender_id,
create_time,
send_time,
end_time,
priority,
top,
modify_time,
origin_id,
type.id typeId,
name,
type.enable,
notice_receive.id receiveId,
notice_receive.already_read receiveRead
from t_notice_receive notice_receive
left join t_notice n on n.id = notice_receive.notice_id
left join t_notice_type type on type.id = n.type_id
left join t_user u on n.sender_id = u.id
where notice_receive.user_id=#{userId}
</select>
<resultMap id="selectAllMap" type="notice" autoMapping="true">
<id property="id" column="nid"/>
<result property="isRead" column="receiveRead"/>
<association property="noticeType" javaType="noticeType" autoMapping="true">
<id property="id" column="typeId"/>
</association>
<association property="sender" javaType="user" autoMapping="true">
<id property="id" column="uid"/>
</association>
</resultMap>
</mapper> </mapper>

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cfive.pinnacle.controller.NoticeController; import com.cfive.pinnacle.controller.NoticeController;
import com.cfive.pinnacle.entity.*; import com.cfive.pinnacle.entity.*;
import com.cfive.pinnacle.entity.common.ResponseResult; import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.mapper.NoticeMapper;
import com.cfive.pinnacle.service.*; import com.cfive.pinnacle.service.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +20,8 @@ public class NoticeTest {
@Autowired @Autowired
private NoticeController noticeController; private NoticeController noticeController;
@Autowired @Autowired
private NoticeMapper noticeMapper;
@Autowired
private INoticeService iNoticeService; private INoticeService iNoticeService;
@Autowired @Autowired
private INoticeTypeService iNoticeTypeService; private INoticeTypeService iNoticeTypeService;
@@ -48,7 +51,7 @@ public class NoticeTest {
@Test @Test
void insertNoticeTest() { void insertNoticeTest() {
for (int i = 20; i < 40; i++) { for (int i = 11; i < 40; i++) {
Notice notice = new Notice(); Notice notice = new Notice();
notice.setTitle("title" + i); notice.setTitle("title" + i);
notice.setTypeId(1654069011361476609L); notice.setTypeId(1654069011361476609L);
@@ -59,7 +62,7 @@ public class NoticeTest {
notice.setSendTime(sendTime); notice.setSendTime(sendTime);
notice.setEndTime(endTime); notice.setEndTime(endTime);
notice.setContent("Content" + i); notice.setContent("Content" + i);
noticeController.addNotice(notice); noticeMapper.insert(notice);
} }
} }
@@ -86,7 +89,7 @@ public class NoticeTest {
@Test @Test
void insertNoticeRecTest() { void insertNoticeRecTest() {
NoticeReceive receive = new NoticeReceive(); NoticeReceive receive = new NoticeReceive();
receive.setNoticeId(1654070031407886338L); receive.setNoticeId(1655408487006437377L);
receive.setUserId(1652714496280469506L); receive.setUserId(1652714496280469506L);
iNoticeReceiveService.save(receive); iNoticeReceiveService.save(receive);
} }

View File

@@ -111,7 +111,7 @@ export default {
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' } { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
], ],
typeId: [ typeId: [
{ type:'array',required: true, message: '请选择公告类型', trigger: 'change' } { required: true, message: '请选择公告类型', trigger: 'change' }
], ],
sendTime: [ sendTime: [
{ type: 'date', required: true, message: '请选择生效时间', trigger: 'change' } { type: 'date', required: true, message: '请选择生效时间', trigger: 'change' }
@@ -167,12 +167,16 @@ export default {
} }
if (this.noticeEdit) { if (this.noticeEdit) {
this.addData = this.noticeEdit this.addData = this.noticeEdit
// 判断是否置顶
this.addData.top=this.noticeEdit.top===1;
console.log(this.addData) console.log(this.addData)
} }
}, },
updated() { updated() {
if (this.noticeEdit) { if (this.noticeEdit) {
this.addData = this.noticeEdit this.addData = this.noticeEdit
// 判断是否置顶
this.addData.top=this.noticeEdit.top===1;
console.log(this.addData) console.log(this.addData)
} }
}, },

View File

@@ -65,7 +65,6 @@ export default {
return SIZE_ICON_MD return SIZE_ICON_MD
}, },
selectByCondition() { selectByCondition() {
console.log(this.timeRang)
if (!_.isEmpty(this.timeRang)) { if (!_.isEmpty(this.timeRang)) {
this.search_info.startTime = this.handleDateFormatUTC(this.timeRang[0]) this.search_info.startTime = this.handleDateFormatUTC(this.timeRang[0])
this.search_info.endTime = this.handleDateFormatUTC(this.timeRang[1]) this.search_info.endTime = this.handleDateFormatUTC(this.timeRang[1])

View File

@@ -6,7 +6,7 @@
>清除筛选条件 >清除筛选条件
</el-button> </el-button>
<el-table <el-table
v-loading="getLoading" v-loading="loading"
element-loading-text="加载中..." element-loading-text="加载中..."
ref="tableRef" ref="tableRef"
:data="selectData" :data="selectData"
@@ -27,7 +27,7 @@
:formatter="formatter" :formatter="formatter"
show-overflow-tooltip show-overflow-tooltip
/> />
<el-table-column prop="noticeType.name" label="公告类别" width="180"> <el-table-column prop="noticeType.name" label="公告类别" width="150">
<template #default="scope"> <template #default="scope">
<el-tag <el-tag
size="default" size="default"
@@ -38,7 +38,7 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="priority" label="优先级" width="180" /> <el-table-column prop="priority" label="优先级" width="100" />
<el-table-column <el-table-column
prop="createTime" prop="createTime"
label="创建时间" label="创建时间"
@@ -77,7 +77,7 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作"> <el-table-column label="操作" width="200">
<template #default="scope"> <template #default="scope">
<el-button size="small" color="#626aef" @click="handleShow(scope.$index, scope.row)" <el-button size="small" color="#626aef" @click="handleShow(scope.$index, scope.row)"
>查看 >查看
@@ -124,7 +124,7 @@ export default {
getLoading: true getLoading: true
} }
}, },
props: ['noticeTypeList', 'selectData', 'departmentList', 'dialogUpdateVisible', 'getLoading'], props: ['noticeTypeList', 'selectData', 'departmentList', 'dialogUpdateVisible', 'loading'],
methods: { methods: {
clearFilter() { clearFilter() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
@@ -163,6 +163,7 @@ export default {
}, },
mounted() {}, mounted() {},
updated() { updated() {
this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = [] this.filterSenderName = []
const nameArray = [] const nameArray = []
for (let i = 0; i < this.selectData.length; i++) { for (let i = 0; i < this.selectData.length; i++) {

View File

@@ -0,0 +1,161 @@
<template>
<el-button
size="large"
@click="clearFilter"
style="background-color: rgba(71, 138, 173, 0.85); color: white"
>清除筛选条件
</el-button>
<el-table
v-loading="getLoading"
element-loading-text="加载中..."
ref="tableRef"
:data="selectData"
style="width: 100%"
border
highlight-current-row
:header-cell-style="{
background: 'darksalmon',
'text-align': 'center',
color: '#fff',
'font-size': '20px'
}"
>
<el-table-column
prop="title"
label="公告标题"
width="180"
:formatter="formatter"
show-overflow-tooltip
/>
<el-table-column prop="noticeType.name" label="公告类别" width="150">
<template #default="scope">
<el-tag
size="default"
:type="scope.row.noticeType.name === '通知公告' ? 'warning' : 'success'"
disable-transitions
>
{{ scope.row.noticeType.name }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="priority" label="优先级" width="100" />
<el-table-column prop="isRead" label="公告状态" width="180">
<template #default="scope">
<el-tag
size="large"
:type="scope.row.isRead === 0 ? 'danger' : 'success'"
disable-transitions
>
{{ scope.row.isRead === 0 ? '未读' : '已读' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="sendTime"
label="生效时间"
sortable
width="180"
:formatter="formatDate"
/>
<el-table-column
prop="endTime"
label="失效时间"
sortable
width="180"
:formatter="formatDate"
/>
<el-table-column
prop="sender.username"
label="发布人"
width="100"
column-key="senderName"
:filters="filterSenderName"
:filter-method="filterTag"
filter-placement="bottom-end"
>
<template #default="scope">
<el-tag
:type="scope.row.sender.username === 'cyb' ? '' : 'success'"
disable-transitions
>{{ scope.row.sender.username }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="200">
<template #default="scope">
<el-button size="small" color="#626aef" @click="handleShow(scope.$index, scope.row)"
>查看
</el-button>
<el-button size="small" type="danger" @click="modifyStatus(scope.row)"
>标记为{{ scope.row.isRead === 0 ? '已读' : '未读' }}
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 查看会话框-->
<el-dialog v-model="dialogShowVisible" center>
<template #header>
<h2 style="color: red">查看公告</h2>
</template>
<notice-show-dialog @showDialogVisible="showDialogVisible" :noticeShow="noticeShow" />
</el-dialog>
</template>
<script lang="ts">
export default {
data() {
return {
filterSenderName: [],
dialogShowVisible: false,
noticeShow: {}
}
},
props: ['selectData', 'getLoading'],
methods: {
clearFilter() {
this.$refs.tableRef.clearFilter(['senderName'])
this.$emit('clearFilter')
},
formatter(row, column) {
return row.title
},
filterTag(value, row) {
return row.sender.username === value
},
formatDate(row, column) {
// 获取单元格数据
const data = row[column.property]
if (data == null) return null
return new Date(data).toLocaleString()
},
modifyStatus(row) {},
handleShow(index, row) {
this.dialogShowVisible = true
this.noticeShow = row
},
showDialogVisible(visible) {
this.dialogShowVisible = visible
}
},
mounted() {},
updated() {
this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = []
const nameArray = []
for (let i = 0; i < this.selectData.length; i++) {
nameArray.push(this.selectData[i].sender.username)
}
const newArr = nameArray.filter((item, i, arr) => {
return arr.indexOf(item) === i
})
for (let j = 0; j < newArr.length; j++) {
const senderName = { text: '', value: '' }
senderName.text = newArr[j]
senderName.value = newArr[j]
this.filterSenderName.push(senderName)
}
}
}
</script>
<style scoped></style>

View File

@@ -1,40 +1,38 @@
<template> <template>
<div class="notice-home-layout"> <el-container>
<el-container> <el-header>
<el-header> <notice-head @selectByCond="selectByCond"></notice-head>
<notice-head @selectByCond="selectByCond"></notice-head> </el-header>
</el-header> <el-main>
<el-main> <el-button
<el-button size="large"
size="large" style="background-color: rgba(71, 138, 173, 0.85); color: white"
style="background-color: rgba(71, 138, 173, 0.85); color: white" @click="openAddNoticeDialog"
@click="dialogAddVisible = true" >发布公告</el-button
>发布公告</el-button >
> <!-- 添加公告对话框-->
<!-- 添加公告对话框--> <el-dialog v-model="dialogAddVisible" center>
<el-dialog v-model="dialogAddVisible" center> <template #header>
<template #header> <h2 style="color: red">发布公告</h2>
<h2 style="color: red">发布公告</h2> </template>
</template> <commitForm
<commitForm :noticeTypeList="this.noticeTypeList"
:noticeTypeList="this.noticeTypeList" :departmentList="this.departmentList"
:departmentList="this.departmentList" @handleAddNotice="handleAddNotice"
@handleAddNotice="handleAddNotice" ></commitForm>
></commitForm> </el-dialog>
</el-dialog> <notice-manage-table
<notice-table :selectData="selectData"
:selectData="selectData" :noticeTypeList="noticeTypeList"
:noticeTypeList="noticeTypeList" :departmentList="departmentList"
:departmentList="departmentList" :dialogUpdateVisible="dialogUpdateVisible"
:dialogUpdateVisible="dialogUpdateVisible" :loading="loading"
:getLoading="getLoading" @handleDelete="handleDelete"
@handleDelete="handleDelete" @clearFilter="clearFilter"
@clearFilter="clearFilter" @handleUpdateNotice="handleUpdateNotice"
@handleUpdateNotice="handleUpdateNotice" ></notice-manage-table>
></notice-table> </el-main>
</el-main> </el-container>
</el-container>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@@ -52,7 +50,7 @@ export default {
dialogAddVisible: false, dialogAddVisible: false,
dialogUpdateVisible: false, dialogUpdateVisible: false,
departmentList: [], departmentList: [],
getLoading: true loading: true
} }
}, },
methods: { methods: {
@@ -83,7 +81,7 @@ export default {
request.get('http://localhost:8621/notice').then((response) => { request.get('http://localhost:8621/notice').then((response) => {
this.selectData = response.data.data this.selectData = response.data.data
if (this.selectData) { if (this.selectData) {
this.getLoading = false this.loading = false
} }
}) })
}, },
@@ -122,6 +120,11 @@ export default {
this.departmentList = response.data.data this.departmentList = response.data.data
}) })
}, },
openAddNoticeDialog() {
this.dialogAddVisible = true
this.selectNoticeType()
this.selectDepartment()
},
handleAddNotice(addFormData) { handleAddNotice(addFormData) {
request.post('http://localhost:8621/notice', addFormData).then((response) => { request.post('http://localhost:8621/notice', addFormData).then((response) => {
if (response.data.code === 20022) { if (response.data.code === 20022) {
@@ -164,21 +167,16 @@ export default {
}, },
mounted() { mounted() {
this.selectAllNotice() this.selectAllNotice()
this.selectNoticeType()
this.selectDepartment()
} }
} }
</script> </script>
<style scoped> <style scoped>
.el-container {
}
.el-header { .el-header {
background-color: #fff; background-color: #fff;
//border: #9e9e9e solid 1px;
} }
.el-main { .el-main {
padding: 0px; padding: 0;
margin-top: 20px; margin-top: 20px;
} }
</style> </style>

View File

@@ -0,0 +1,56 @@
<template>
<el-container>
<el-header>
<notice-head></notice-head>
</el-header>
<el-main>
<el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
>
<el-menu-item index="1">所有公告</el-menu-item>
<el-menu-item index="2">已读</el-menu-item>
<el-menu-item index="3"><a href="#">未读</a></el-menu-item>
</el-menu>
<notice-view-table
:selectData="selectData"
:getLoading="getLoading"
></notice-view-table>
</el-main>
</el-container>
</template>
<script lang="ts">
import request from '@/services'
export default {
name: 'NoticeView',
data() {
return {
activeIndex: '1',
selectData: [],
getLoading: true
}
},
methods: {
handleSelect(key, keyPath) {
console.log(key, keyPath)
},
selectAllNoticeByUserId() {
request.get('http://localhost:8621/notice/ByUserId').then((response) => {
this.selectData = response.data.data
if (this.selectData) {
this.getLoading = false
}
})
}
},
mounted() {
this.selectAllNoticeByUserId()
}
}
</script>
<style scoped></style>

View File

@@ -180,7 +180,29 @@ const router = createRouter({
icon: shallowRef(IconPinnacleSetting), icon: shallowRef(IconPinnacleSetting),
requiresScrollbar: false, requiresScrollbar: false,
requiresPadding: true requiresPadding: true
} },
children: [
{
path: 'noticeManage',
component: async () => await import('@/pages/notice/NoticeManage.vue'),
name: 'noticeManage',
meta: {
title: '公告管理',
requiresScrollbar: false,
requiresPadding: true
}
},
{
path: 'noticeView',
component: async () => await import('@/pages/notice/NoticeView.vue'),
name: 'noticeView',
meta: {
title: '公告查看',
requiresScrollbar: false,
requiresPadding: true
}
}
]
} }
] ]
}, },