1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-06 07:21:24 +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

@@ -29,13 +29,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
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;
return departmentMapper.getDepartAndUser();
}
}

View File

@@ -1,11 +1,16 @@
package com.cfive.pinnacle.service.impl;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive;
import com.cfive.pinnacle.mapper.NoticeReceiveMapper;
import com.cfive.pinnacle.service.INoticeReceiveService;
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 java.util.List;
/**
* <p>
* 公告接收 服务实现类
@@ -16,5 +21,11 @@ import org.springframework.stereotype.Service;
*/
@Service
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.service.INoticeService;
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.util.StringUtils;
@@ -47,56 +48,59 @@ 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);
}
}
// 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> selectByCond(String title, String type, String startTime,String endTime) {
List<Notice> notices = new ArrayList<>();
LocalDateTime start = null;
LocalDateTime end = null;
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) {
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()));
n.setNoticeType(noticeTypeMapper.selectById(n.getTypeId()));
start = 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);
// 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;
}
@Override
public Boolean deleteById(Long nid) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
@@ -120,4 +124,24 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
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;
}
}