mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
nitice manage module compeled
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 前端控制器
|
||||
@@ -13,6 +22,17 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/department")
|
||||
@CrossOrigin
|
||||
public class DepartmentController {
|
||||
@Autowired
|
||||
IDepartmentService departmentService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getDepartAndUser(){
|
||||
List<Department> getDepartAndUser = departmentService.getDepartAndUser();
|
||||
Integer code = getDepartAndUser != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = getDepartAndUser != null ? "" : "数据查询失败,请尝试!";
|
||||
return ResponseResult.build(code, msg, getDepartAndUser);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.INoticeReceiveService;
|
||||
import com.cfive.pinnacle.service.INoticeService;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -25,7 +28,9 @@ import java.util.List;
|
||||
@CrossOrigin
|
||||
public class NoticeController {
|
||||
@Autowired
|
||||
INoticeService noticeService;
|
||||
private INoticeService noticeService;
|
||||
@Autowired
|
||||
private INoticeReceiveService noticeReceiveService;
|
||||
|
||||
//根据公告id查公告信息及发布人
|
||||
@GetMapping("/{nid}")
|
||||
@@ -36,16 +41,14 @@ public class NoticeController {
|
||||
return ResponseResult.build(code, msg, noticeById);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
//添加公告
|
||||
//查询所有公告
|
||||
@GetMapping
|
||||
public ResponseResult selectAllNotice(String title) {
|
||||
public ResponseResult selectAllNotice(String title, String type, String startTime,String endTime) {
|
||||
List<Notice> noticeList;
|
||||
if (title == null) {
|
||||
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
|
||||
noticeList = noticeService.selectAllNotice();
|
||||
} else {
|
||||
noticeList = noticeService.selectByTitle(title);
|
||||
noticeList = noticeService.selectByCond(title, type, startTime,endTime);
|
||||
}
|
||||
|
||||
int code = noticeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
@@ -54,22 +57,33 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping
|
||||
//更新公告
|
||||
@PutMapping
|
||||
public ResponseResult updateNotice(@RequestBody Notice notice) {
|
||||
notice.setId(null); //清除id,使新插入的数据id自增
|
||||
notice.setOriginId(notice.getId());
|
||||
boolean updateById = noticeService.save(notice);
|
||||
boolean updateById = noticeService.updateNotice(notice);
|
||||
String msg = updateById ? "" : "数据修改失败,请尝试!";
|
||||
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateById);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
//添加公告
|
||||
@PostMapping
|
||||
public ResponseResult addNotice(@RequestBody Notice notice) {
|
||||
notice.setSenderId(1654151877520973826L);
|
||||
boolean insertNotice = noticeService.save(notice);
|
||||
String msg = insertNotice ? "" : "数据添加失败,请尝试!";
|
||||
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
|
||||
Long noticeId = notice.getId();
|
||||
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);
|
||||
}
|
||||
|
||||
//删除公告
|
||||
@DeleteMapping("/{nid}")
|
||||
public ResponseResult deleteByNoticeId(@PathVariable Long nid) {
|
||||
boolean removeById = noticeService.deleteById(nid);
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.INoticeTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 公告类型 前端控制器
|
||||
@@ -13,6 +23,17 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/noticeType")
|
||||
@CrossOrigin
|
||||
public class NoticeTypeController {
|
||||
@Autowired
|
||||
INoticeTypeService noticeTypeService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult selectTypeList(){
|
||||
List<NoticeType> selectTypeName = noticeTypeService.selectTypeList();
|
||||
Integer code = selectTypeName != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = selectTypeName != null ? "" : "数据查询失败,请尝试!";
|
||||
return ResponseResult.build(code, msg, selectTypeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -56,4 +57,10 @@ public class Department implements Serializable {
|
||||
@TableField("version")
|
||||
@Version
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 部门成员
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<User> userList;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
@@ -77,18 +79,21 @@ public class Notice implements Serializable {
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
@TableField("send_time")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
|
||||
private LocalDateTime sendTime;
|
||||
|
||||
/**
|
||||
* 失效时间
|
||||
*/
|
||||
@TableField("end_time")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
@@ -107,6 +112,7 @@ public class Notice implements Serializable {
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("modify_time")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
|
||||
private LocalDateTime modifyTime;
|
||||
|
||||
/**
|
||||
@@ -130,5 +136,11 @@ public class Notice implements Serializable {
|
||||
@Version
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 公告接收者
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private List<Long> receivers;
|
||||
|
||||
}
|
||||
|
||||
@@ -41,11 +41,6 @@ public class NoticeReceive implements Serializable {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* 公告Id
|
||||
@@ -54,12 +49,6 @@ public class NoticeReceive implements Serializable {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long noticeId;
|
||||
|
||||
/**
|
||||
* 公告
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Notice notice;
|
||||
|
||||
/**
|
||||
* 已读
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 服务类
|
||||
@@ -12,5 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IDepartmentService extends IService<Department> {
|
||||
List<Department> getDepartAndUser();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ public interface INoticeService extends IService<Notice> {
|
||||
|
||||
List<Notice> selectAllNotice();
|
||||
|
||||
List<Notice> selectByTitle(String title);
|
||||
List<Notice> selectByCond(String title,String type,String startTime,String endTime);
|
||||
|
||||
Boolean deleteById(Long nid);
|
||||
|
||||
Boolean updateNotice(Notice notice);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 公告类型 服务类
|
||||
@@ -12,5 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface INoticeTypeService extends IService<NoticeType> {
|
||||
List<NoticeType> selectTypeList();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.cfive.pinnacle.mapper.DepartmentMapper;
|
||||
import com.cfive.pinnacle.mapper.UserMapper;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 服务实现类
|
||||
@@ -16,5 +23,19 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
|
||||
|
||||
@Autowired
|
||||
private DepartmentMapper departmentMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Override
|
||||
public List<Department> getDepartAndUser() {
|
||||
List<Department> departments = departmentMapper.selectList(null);
|
||||
for (Department department:
|
||||
departments) {
|
||||
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(User::getDepartmentId, department.getId());
|
||||
department.setUserList(userMapper.selectList(lqw));
|
||||
}
|
||||
return departments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
import com.cfive.pinnacle.mapper.NoticeMapper;
|
||||
import com.cfive.pinnacle.mapper.NoticeReceiveMapper;
|
||||
import com.cfive.pinnacle.mapper.NoticeTypeMapper;
|
||||
@@ -11,7 +13,11 @@ import com.cfive.pinnacle.service.INoticeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -40,14 +46,49 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
|
||||
@Override
|
||||
public List<Notice> selectAllNotice() {
|
||||
return noticeMapper.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notice> selectByTitle(String title) {
|
||||
LambdaQueryWrapper<Notice> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.like(Notice::getTitle, title);
|
||||
List<Notice> notices = noticeMapper.selectList(lqw);
|
||||
public List<Notice> selectByCond(String title, String type, String startTime,String endTime) {
|
||||
List<Notice> notices = new ArrayList<>();
|
||||
LocalDateTime start = null;
|
||||
LocalDateTime end = null;
|
||||
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) {
|
||||
startTime = null;
|
||||
endTime = 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()));
|
||||
@@ -68,4 +109,15 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
return noticeMapper.deleteById(nid) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateNotice(Notice notice) {
|
||||
noticeMapper.update(null, new UpdateWrapper<Notice>().eq("id", notice.getId()).set("old", 1)); //修改原始数据
|
||||
notice.setOriginId(notice.getId());
|
||||
notice.setId(null); //清除id,使新插入的数据id重新生成
|
||||
notice.setCreateTime(null);
|
||||
notice.setModifyTime(null);
|
||||
notice.setOld(0);
|
||||
return noticeMapper.insert(notice) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
import com.cfive.pinnacle.mapper.NoticeTypeMapper;
|
||||
import com.cfive.pinnacle.service.INoticeTypeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 公告类型 服务实现类
|
||||
@@ -16,5 +22,13 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class NoticeTypeServiceImpl extends ServiceImpl<NoticeTypeMapper, NoticeType> implements INoticeTypeService {
|
||||
|
||||
@Autowired
|
||||
NoticeTypeMapper noticeTypeMapper;
|
||||
@Override
|
||||
public List<NoticeType> selectTypeList() {
|
||||
LambdaQueryWrapper<NoticeType> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(NoticeType::getEnable, 1);
|
||||
List<NoticeType> noticeTypes = noticeTypeMapper.selectList(lqw);
|
||||
return noticeTypes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<?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">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.DepartmentMapper">
|
||||
|
||||
<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>
|
||||
<resultMap id="department" type="department" autoMapping="true">
|
||||
<id column="id" property="id"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
and type.id = n.type_id
|
||||
and n.deleted = 0
|
||||
and n.old = 0
|
||||
|
||||
order by create_time desc
|
||||
</select>
|
||||
<resultMap id="NoticeAllResultMap" type="notice" autoMapping="true">
|
||||
<id property="id" column="nid"/>
|
||||
@@ -70,4 +70,5 @@
|
||||
<result property="version" column="typeVe"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
<!-- 模糊查询-->
|
||||
</mapper>
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
package com.cfive.pinnacle.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.controller.NoticeController;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.entity.NoticeType;
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.cfive.pinnacle.entity.*;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
import com.cfive.pinnacle.service.INoticeReceiveService;
|
||||
import com.cfive.pinnacle.service.INoticeTypeService;
|
||||
import com.cfive.pinnacle.service.IUserService;
|
||||
import com.cfive.pinnacle.service.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class NoticeTest {
|
||||
@Autowired
|
||||
private NoticeController noticeController;
|
||||
@Autowired
|
||||
private INoticeService iNoticeService;
|
||||
@Autowired
|
||||
private INoticeTypeService iNoticeTypeService;
|
||||
@Autowired
|
||||
private IDepartmentService iDepartmentService;
|
||||
@@ -34,52 +33,87 @@ public class NoticeTest {
|
||||
@Test
|
||||
void selectByIdTest() {
|
||||
ResponseResult selectByNoticeId = noticeController.selectByNoticeId(21L);
|
||||
System.out.println(selectByNoticeId.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectAllTest() {
|
||||
ResponseResult noticeList = noticeController.selectAllNotice(null);
|
||||
System.out.println(noticeList.getData());
|
||||
ResponseResult noticeList = noticeController.selectAllNotice(null, null,null,null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTest() {
|
||||
ResponseResult notice = noticeController.selectByNoticeId(23L);
|
||||
ResponseResult updateNotice = noticeController.updateNotice((Notice) notice.getData());
|
||||
System.out.println(updateNotice.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertNoticeTest() {
|
||||
for (int i = 2; i < 20; i++) {
|
||||
for (int i = 20; i < 40; i++) {
|
||||
Notice notice = new Notice();
|
||||
notice.setTitle("title"+i);
|
||||
notice.setTypeId(1652684907554496514L);
|
||||
notice.setTitle("title" + i);
|
||||
notice.setTypeId(1654069011361476609L);
|
||||
notice.setSenderId(1652714496280469506L);
|
||||
LocalDateTime sendTime = LocalDateTime.parse("2023-05-11 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
LocalDateTime endTime = LocalDateTime.parse("2023-09-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
notice.setPriority(2);
|
||||
notice.setSendTime(sendTime);
|
||||
notice.setEndTime(endTime);
|
||||
notice.setContent("Content"+i);
|
||||
notice.setContent("Content" + i);
|
||||
noticeController.addNotice(notice);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertNoticeTypeTest(){
|
||||
NoticeType noticeType = new NoticeType();
|
||||
noticeType.setName("通知公告");
|
||||
iNoticeTypeService.save(noticeType);
|
||||
void insertNoticeTypeTest() {
|
||||
// NoticeType noticeType = new NoticeType();
|
||||
// noticeType.setName("调休公告");
|
||||
// iNoticeTypeService.save(noticeType);
|
||||
|
||||
// Department department=new Department();
|
||||
// department.setName("前端开发部");
|
||||
// department.setTel("123");
|
||||
// department.setAddress("潮州");
|
||||
// iDepartmentService.save(department);
|
||||
|
||||
User user = new User();
|
||||
user.setUsername("yrm");
|
||||
user.setPasswd("123");
|
||||
user.setDepartmentId(1654150127317569537L);
|
||||
user.setEnable(1);
|
||||
iUserService.save(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertNoticeRecTest(){
|
||||
void insertNoticeRecTest() {
|
||||
NoticeReceive receive = new NoticeReceive();
|
||||
receive.setNoticeId(1652734384348790786L);
|
||||
receive.setNoticeId(1654070031407886338L);
|
||||
receive.setUserId(1652714496280469506L);
|
||||
iNoticeReceiveService.save(receive);
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectByConde() {
|
||||
List<Notice> notices = new ArrayList<>();
|
||||
LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>();
|
||||
LambdaQueryWrapper<NoticeType> lqw_type = new LambdaQueryWrapper<>();
|
||||
lqw_type.like(NoticeType::getName, "活动");
|
||||
List<NoticeType> noticeTypes = iNoticeTypeService.list(lqw_type);
|
||||
if (noticeTypes.isEmpty()) {
|
||||
} else {
|
||||
for (NoticeType type : noticeTypes
|
||||
) {
|
||||
lqw_notice.clear();
|
||||
lqw_notice.eq(Notice::getTypeId, type.getId()).like(Notice::getTitle, "2");
|
||||
List<Notice> temp_notice = iNoticeService.list(lqw_notice);
|
||||
notices.addAll(temp_notice);
|
||||
}
|
||||
for (Notice n:notices
|
||||
) {
|
||||
n.setSender(iUserService.getById(n.getSenderId()));
|
||||
n.setNoticeType(iNoticeTypeService.getById(n.getTypeId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user