岗位与通知增删改查
This commit is contained in:
parent
c724387a16
commit
ccfdd18516
@ -29,7 +29,7 @@ public class SysNoticeController {
|
||||
/**
|
||||
* 获取通知公告列表
|
||||
*/
|
||||
@GetMapping
|
||||
@GetMapping("/list")
|
||||
public PageR<NoticeVO> list(NoticeQuery query) {
|
||||
PageR<NoticeVO> page = sysNoticeService.getNoticeList(query);
|
||||
return page;
|
||||
@ -57,7 +57,7 @@ public class SysNoticeController {
|
||||
/**
|
||||
* 新增通知公告
|
||||
*/
|
||||
@PostMapping
|
||||
@PostMapping("/create")
|
||||
public R<Void> add(@RequestBody NoticeAddDTO addDTO) {
|
||||
sysNoticeService.addNotice(addDTO);
|
||||
return R.ok();
|
||||
@ -66,7 +66,7 @@ public class SysNoticeController {
|
||||
/**
|
||||
* 修改通知公告
|
||||
*/
|
||||
@PutMapping("/{noticeId}")
|
||||
@PostMapping("/update/{noticeId}")
|
||||
public R<Void> edit(@PathVariable("noticeId") Long noticeId, @RequestBody NoticeUpdateDTO updateDTO) {
|
||||
updateDTO.setNoticeId(noticeId);
|
||||
sysNoticeService.updateNotice(updateDTO);
|
||||
@ -76,7 +76,7 @@ public class SysNoticeController {
|
||||
/**
|
||||
* 删除通知公告
|
||||
*/
|
||||
@DeleteMapping
|
||||
@PostMapping("/del")
|
||||
public R<Void> remove(@RequestBody List<Integer> noticeIds) {
|
||||
sysNoticeService.deleteNotice(noticeIds);
|
||||
return R.ok();
|
||||
|
||||
@ -15,19 +15,18 @@ import com.agileboot.system.notice.dto.NoticeVO;
|
||||
import com.agileboot.system.notice.entity.SysNotice;
|
||||
import com.agileboot.system.notice.mapper.SysNoticeMapper;
|
||||
import com.agileboot.system.notice.service.ISysNoticeService;
|
||||
import com.agileboot.system.user.mapper.SysUserMapper;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@ -38,21 +37,22 @@ public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice
|
||||
|
||||
@Override
|
||||
public PageR<NoticeVO> getNoticeList(NoticeQuery query) {
|
||||
Page<SysNotice> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
LambdaQueryWrapper<SysNotice> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.like(StrUtil.isNotBlank(query.getNoticeTitle()), SysNotice::getNoticeTitle, query.getNoticeTitle());
|
||||
lqw.like(StrUtil.isNotBlank(query.getNoticeType()), SysNotice::getNoticeType, query.getNoticeType());
|
||||
lqw.eq(StrUtil.isNotBlank(query.getNoticeType()), SysNotice::getNoticeType, query.getNoticeType());
|
||||
page(page, lqw);
|
||||
List<SysNotice> records = page.getRecords();
|
||||
List<NoticeVO> noticeVOList = records.stream().map(sysNotice -> {
|
||||
NoticeVO noticeVO = new NoticeVO(sysNotice);
|
||||
Long creatorId = sysNotice.getUpdateBy();
|
||||
String creatorName = userService.getUserByUserId(creatorId).getUsername();
|
||||
noticeVO.setCreatorName(creatorName);
|
||||
return noticeVO;
|
||||
}).toList();
|
||||
return new PageR<>(page, noticeVOList);
|
||||
QueryWrapper<SysNotice> queryWrapper = new QueryWrapper<SysNotice>()
|
||||
.like(StrUtil.isNotEmpty(query.getNoticeTitle()), "notice_title", query.getNoticeTitle())
|
||||
.eq(StrUtil.isNotEmpty(query.getNoticeType()), "notice_type", query.getNoticeType())
|
||||
.eq("n.deleted", 0)
|
||||
.like(StrUtil.isNotEmpty(query.getCreatorName()), "u.username", query.getCreatorName());
|
||||
Page<SysNotice> page = this.baseMapper.getNoticeList(query.toPage(), queryWrapper);
|
||||
|
||||
Set<Long> userIds = page.getRecords().stream().map(SysNotice::getCreateBy).collect(Collectors.toSet());
|
||||
Map<Long, String> idNameMap = userService.geIdNameByIds(userIds);
|
||||
page.getRecords().forEach(sysNotice -> {
|
||||
Long creatorId = sysNotice.getCreateBy();
|
||||
String creatorName = idNameMap.get(creatorId);
|
||||
sysNotice.setSearchValue(creatorName);
|
||||
});
|
||||
IPage<NoticeVO> convert = page.convert(NoticeVO::new);
|
||||
return new PageR<>(convert);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,36 +66,26 @@ public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice
|
||||
|
||||
@Override
|
||||
public void addNotice(NoticeAddDTO addDTO) {
|
||||
// 通知类型
|
||||
String type = addDTO.getNoticeType();
|
||||
String status = addDTO.getStatus();
|
||||
Preconditions.checkArgument(Objects.nonNull(type), "请选择通知类型");
|
||||
Preconditions.checkArgument(Objects.nonNull(status), "请选择通知状态");
|
||||
Integer noticeType = NoticeTypeEnum.getDescByValue(Integer.parseInt(type));
|
||||
Integer noticeStatus = StatusEnum.getDescByValue(Integer.parseInt(status));
|
||||
BasicEnumUtil.fromValue(NoticeTypeEnum.class, addDTO.getNoticeType());
|
||||
BasicEnumUtil.fromValue(StatusEnum.class, addDTO.getStatus());
|
||||
|
||||
SysNotice sysNotice = new SysNotice();
|
||||
sysNotice.setNoticeType(noticeType);
|
||||
sysNotice.setStatus(noticeStatus);
|
||||
BeanUtil.copyProperties(addDTO, sysNotice);
|
||||
super.save(sysNotice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotice(NoticeUpdateDTO updateDTO) {
|
||||
Long noticeId = updateDTO.getNoticeId();
|
||||
SysNotice notice = super.getById(noticeId);
|
||||
Preconditions.checkArgument(Objects.nonNull(notice), "通知公告不存在");
|
||||
// 通知类型
|
||||
// String type = updateDTO.getNoticeType();
|
||||
// String status = updateDTO.getStatus();
|
||||
// Preconditions.checkArgument(Objects.nonNull(type), "请选择通知类型");
|
||||
// Preconditions.checkArgument(Objects.nonNull(status), "请选择通知状态");
|
||||
// Integer noticeType = NoticeTypeEnum.getDescByValue(Integer.parseInt(type));
|
||||
// Integer noticeStatus = StatusEnum.getDescByValue(Integer.parseInt(status));
|
||||
SysNotice updateNotice = new SysNotice();
|
||||
BeanUtil.copyProperties(updateDTO, updateNotice);
|
||||
updateById(updateNotice);
|
||||
BasicEnumUtil.fromValue(NoticeTypeEnum.class, updateDTO.getNoticeType());
|
||||
BasicEnumUtil.fromValue(StatusEnum.class, updateDTO.getStatus());
|
||||
|
||||
Long noticeId = updateDTO.getNoticeId();
|
||||
SysNotice byId = super.getById(noticeId);
|
||||
if (byId == null) {
|
||||
throw new BizException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, noticeId, "通知公告");
|
||||
}
|
||||
BeanUtil.copyProperties(updateDTO, byId, "noticeId");
|
||||
super.updateById(byId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -72,7 +72,7 @@ public class SysPostController {
|
||||
/**
|
||||
* 修改岗位
|
||||
*/
|
||||
@PutMapping
|
||||
@PostMapping("/update")
|
||||
public R<Void> edit(@RequestBody UpdatePostDTO updateCommand) {
|
||||
sysPostService.updatePost(updateCommand);
|
||||
return R.ok();
|
||||
@ -81,7 +81,7 @@ public class SysPostController {
|
||||
/**
|
||||
* 删除岗位
|
||||
*/
|
||||
@DeleteMapping
|
||||
@PostMapping("/del")
|
||||
public R<Void> remove(@RequestBody @NotNull @NotEmpty List<Long> ids) {
|
||||
sysPostService.deletePost(ids);
|
||||
return R.ok();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.agileboot.system.post.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.exception.BizException;
|
||||
import com.agileboot.common.core.exception.error.ErrorCode;
|
||||
import com.agileboot.common.mybatis.core.page.PageR;
|
||||
@ -12,8 +11,7 @@ import com.agileboot.system.post.dto.UpdatePostDTO;
|
||||
import com.agileboot.system.post.entity.SysPost;
|
||||
import com.agileboot.system.post.mapper.SysPostMapper;
|
||||
import com.agileboot.system.post.service.ISysPostService;
|
||||
import com.agileboot.system.user.entity.SysUser;
|
||||
import com.agileboot.system.user.mapper.SysUserMapper;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@ -22,16 +20,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements ISysPostService {
|
||||
|
||||
@Resource
|
||||
private SysUserMapper sysUserMapper;
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public PostVO getPostInfo(Long postId) {
|
||||
@ -47,21 +43,9 @@ public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> impl
|
||||
*/
|
||||
@Override
|
||||
public PageR<PostVO> getPostList(PostQuery query) {
|
||||
String postCode = query.getPostCode();
|
||||
String postName = query.getPostName();
|
||||
LocalDate beginTime = query.getBeginTime();
|
||||
LocalDate endTime = query.getEndTime();
|
||||
LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.like(StrUtil.isNotBlank(postCode), SysPost::getPostCode, postCode);
|
||||
lqw.like(StrUtil.isNotBlank(postName), SysPost::getPostName, postName);
|
||||
lqw.eq(Objects.nonNull(query.getStatus()), SysPost::getStatus, query.getStatus());
|
||||
lqw.between(Objects.nonNull(beginTime) && Objects.nonNull(endTime), SysPost::getCreateTime, beginTime, endTime);
|
||||
Page<SysPost> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
page(page, lqw);
|
||||
List<SysPost> records = page.getRecords();
|
||||
List<PostVO> convert = records.stream().map(PostVO::new).collect(Collectors.toList());
|
||||
|
||||
return new PageR<>(page,convert);
|
||||
Page<SysPost> page = super.page(query.toPage(), query.toQueryWrapper());
|
||||
IPage<PostVO> convert = page.convert(PostVO::new);
|
||||
return new PageR<>(convert);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,11 +96,7 @@ public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> impl
|
||||
@Override
|
||||
public void deletePost(List<Long> ids) {
|
||||
// 检测职位是否分配给用户
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(SysUser.class)
|
||||
.in(SysUser::getPostId, ids);
|
||||
if (sysUserMapper.exists(queryWrapper)) {
|
||||
throw new BizException(ErrorCode.Business.POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED);
|
||||
}
|
||||
sysUserService.checkAnyPostIsAssignedToUser(ids);
|
||||
super.removeBatchByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ISysUserService {
|
||||
@ -40,4 +41,8 @@ public interface ISysUserService {
|
||||
void updateBatchRoleId(Long roleId, List<Long> userIds);
|
||||
|
||||
void deleteBatchRoleId(List<Long> userIds);
|
||||
|
||||
void checkAnyPostIsAssignedToUser(List<Long> ids);
|
||||
|
||||
Map<Long, String> geIdNameByIds(Set<Long> userIds);
|
||||
}
|
||||
|
||||
@ -25,8 +25,10 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
@ -202,4 +204,28 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
.in(SysUser::getUserId, userIds);
|
||||
super.update(updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测职位是否分配给用户
|
||||
*/
|
||||
@Override
|
||||
public void checkAnyPostIsAssignedToUser(List<Long> ids) {
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(SysUser.class)
|
||||
.in(SysUser::getPostId, ids);
|
||||
if (super.exists(queryWrapper)) {
|
||||
throw new BizException(ErrorCode.Business.POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> geIdNameByIds(Set<Long> userIds) {
|
||||
if (userIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return super.list(Wrappers.lambdaQuery(SysUser.class)
|
||||
.select(SysUser::getUserId, SysUser::getUsername)
|
||||
.in(SysUser::getUserId, userIds))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getUsername));
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ public class NoticeAddDTO {
|
||||
@Size(max = 50, message = "公告标题不能超过50个字符")
|
||||
protected String noticeTitle;
|
||||
|
||||
protected String noticeType;
|
||||
protected Integer noticeType;
|
||||
|
||||
/**
|
||||
* 想要支持富文本的话, 避免Xss过滤的话, 请加上@JsonDeserialize(using = StringDeserializer.class) 注解
|
||||
@ -26,6 +26,6 @@ public class NoticeAddDTO {
|
||||
@JsonDeserialize(using = StringDeserializer.class)
|
||||
protected String noticeContent;
|
||||
|
||||
protected String status;
|
||||
protected Integer status;
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ public class NoticeVO {
|
||||
this.noticeContent = entity.getNoticeContent();
|
||||
this.status = entity.getStatus();
|
||||
this.createTime = entity.getCreateTime();
|
||||
this.creatorName = entity.getSearchValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +32,6 @@ public class NoticeVO {
|
||||
private String noticeContent;
|
||||
|
||||
private Integer status;
|
||||
private String creator;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package com.agileboot.system.post.dto;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.mybatis.core.page.PageQuery;
|
||||
import com.agileboot.system.post.entity.SysPost;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author valarchie
|
||||
@ -21,6 +24,10 @@ public class PostQuery extends PageQuery<SysPost> {
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<SysPost> toQueryWrapper() {
|
||||
return null;
|
||||
return Wrappers.lambdaQuery(SysPost.class)
|
||||
.like(StrUtil.isNotBlank(postCode), SysPost::getPostCode, postCode)
|
||||
.like(StrUtil.isNotBlank(postName), SysPost::getPostName, postName)
|
||||
.eq(Objects.nonNull(status), SysPost::getStatus, status)
|
||||
.between(Objects.nonNull(beginTime) && Objects.nonNull(endTime), SysPost::getCreateTime, beginTime, endTime);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user