mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
增加系统通知接口
This commit is contained in:
@@ -3,11 +3,17 @@ package cn.lihongjie.coal.base.service;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.base.entity.BaseEntity;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseService<
|
||||
@@ -20,11 +26,14 @@ public abstract class BaseService<
|
||||
return dao.get(id);
|
||||
}
|
||||
|
||||
public void save(Entity entity) {
|
||||
public Entity save(Entity entity) {
|
||||
|
||||
dao.save(entity);
|
||||
return dao.save(entity);
|
||||
}
|
||||
public List<Entity> saveAll(Iterable<Entity> entities) {
|
||||
|
||||
return dao.saveAll(entities);
|
||||
}
|
||||
public void delete(String id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
@@ -45,6 +54,19 @@ public abstract class BaseService<
|
||||
return dao.findAll();
|
||||
}
|
||||
|
||||
public List<Entity> findAllByIds(Iterable<String> ids) {
|
||||
if (ids == null){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return dao.findAll(new Specification<Entity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Entity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return root.get("id").in(ids);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Long count(Specification<Entity> spec) {
|
||||
return dao.count(spec);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.lihongjie.coal.notice.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.notice.dto.CreateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.NoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.UpdateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.service.NoticeService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/notice")
|
||||
@SysLog(
|
||||
module = "通知管理"
|
||||
)
|
||||
@Slf4j
|
||||
public class NoticeController {
|
||||
@Autowired
|
||||
private NoticeService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public NoticeDto create(@RequestBody CreateNoticeDto request) {
|
||||
return this.service.create(request)
|
||||
;
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public NoticeDto update(@RequestBody UpdateNoticeDto request) {
|
||||
return this.service.update(request)
|
||||
;
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true
|
||||
;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public NoticeDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId())
|
||||
;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<NoticeDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.lihongjie.coal.notice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateNoticeDto extends CommonDto {
|
||||
@Comment("标题")
|
||||
private String title;
|
||||
|
||||
|
||||
@Comment("内容类型 0 html 1 markdown")
|
||||
private String contentType;
|
||||
|
||||
|
||||
|
||||
@Comment("内容")
|
||||
private String content;
|
||||
|
||||
private List<String> receivers;
|
||||
|
||||
@Comment("是否全体")
|
||||
private Boolean all;
|
||||
}
|
||||
34
src/main/java/cn/lihongjie/coal/notice/dto/NoticeDto.java
Normal file
34
src/main/java/cn/lihongjie/coal/notice/dto/NoticeDto.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package cn.lihongjie.coal.notice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
public class NoticeDto extends CommonDto {
|
||||
@Comment("标题")
|
||||
private String title;
|
||||
|
||||
|
||||
@Comment("内容类型 0 html 1 markdown")
|
||||
private String contentType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'notebook.contentType'\n"
|
||||
+ " and i.code = content_type)")
|
||||
private String contentTypeName;
|
||||
|
||||
@Comment("内容")
|
||||
private String content;
|
||||
|
||||
|
||||
@Comment("是否全体")
|
||||
private Boolean all;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.notice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateNoticeDto extends CommonDto {
|
||||
@Comment("标题")
|
||||
private String title;
|
||||
|
||||
|
||||
@Comment("内容类型 0 html 1 markdown")
|
||||
private String contentType;
|
||||
|
||||
|
||||
|
||||
@Comment("内容")
|
||||
private String content;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.lihongjie.coal.notice.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.CommonEntity;
|
||||
import cn.lihongjie.coal.noticeStatus.entity.NoticeStatusEntity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class NoticeEntity extends CommonEntity {
|
||||
@Comment("标题")
|
||||
private String title;
|
||||
|
||||
|
||||
@Comment("内容类型 0 html 1 markdown")
|
||||
private String contentType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'notebook.contentType'\n"
|
||||
+ " and i.code = content_type)")
|
||||
private String contentTypeName;
|
||||
|
||||
@Comment("内容")
|
||||
private String content;
|
||||
|
||||
|
||||
@Comment("是否全体")
|
||||
private Boolean all;
|
||||
|
||||
|
||||
@OneToMany(cascade = CascadeType.REMOVE)
|
||||
private List<NoticeStatusEntity> noticeStatus;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.notice.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.notice.dto.CreateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.NoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.UpdateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.entity.NoticeEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class},
|
||||
mappingControl = DeepClone.class
|
||||
)
|
||||
public interface NoticeMapper extends BaseMapper<NoticeEntity, NoticeDto, CreateNoticeDto, UpdateNoticeDto> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.notice.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.notice.entity.NoticeEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface NoticeRepository extends BaseRepository<NoticeEntity> {
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package cn.lihongjie.coal.notice.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.notice.dto.CreateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.NoticeDto;
|
||||
import cn.lihongjie.coal.notice.dto.UpdateNoticeDto;
|
||||
import cn.lihongjie.coal.notice.entity.NoticeEntity;
|
||||
import cn.lihongjie.coal.notice.mapper.NoticeMapper;
|
||||
import cn.lihongjie.coal.notice.repository.NoticeRepository;
|
||||
import cn.lihongjie.coal.noticeStatus.entity.NoticeStatusEntity;
|
||||
import cn.lihongjie.coal.noticeStatus.service.NoticeStatusService;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
import cn.lihongjie.coal.user.service.UserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class NoticeService extends BaseService<NoticeEntity, NoticeRepository> {
|
||||
@Autowired UserService userService;
|
||||
@Autowired NoticeStatusService noticeStatusService;
|
||||
@Autowired private NoticeRepository repository;
|
||||
@Autowired private NoticeMapper mapper;
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
public NoticeDto create(CreateNoticeDto request) {
|
||||
NoticeEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
UserEntity sender = this.userService.get(Ctx.getUserId());
|
||||
|
||||
List<UserEntity> users = new ArrayList<>();
|
||||
if (BooleanUtils.isTrue(request.getAll())) {
|
||||
|
||||
users = userService.findAll();
|
||||
}else if (request.getReceivers() != null) {
|
||||
|
||||
users = userService.findAllByIds(request.getReceivers());
|
||||
}
|
||||
|
||||
if (users.isEmpty()){
|
||||
throw new BizException("收件人不能为空");
|
||||
}
|
||||
|
||||
List<NoticeStatusEntity> statusList = users.stream()
|
||||
.map(
|
||||
|
||||
ue -> {
|
||||
NoticeStatusEntity status = new NoticeStatusEntity();
|
||||
|
||||
status.setNotice(entity);
|
||||
status.setSender(sender);
|
||||
status.setRead(false);
|
||||
status.setDelete(false);
|
||||
status.setSendTime(LocalDateTime.now());
|
||||
status.setUser(ue);
|
||||
return status;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
this.noticeStatusService.saveAll(statusList);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public NoticeDto update(UpdateNoticeDto request) {
|
||||
NoticeEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public NoticeDto getById(String id) {
|
||||
NoticeEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<NoticeDto> list(CommonQuery query) {
|
||||
Page<NoticeEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.lihongjie.coal.noticeStatus.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.CreateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.NoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.UpdateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.service.NoticeStatusService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/noticeStatus")
|
||||
@SysLog(module = "消息通知状态")
|
||||
@Slf4j
|
||||
public class NoticeStatusController {
|
||||
@Autowired private NoticeStatusService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public NoticeStatusDto create(@RequestBody CreateNoticeStatusDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public NoticeStatusDto update(@RequestBody UpdateNoticeStatusDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/read")
|
||||
public Object read(@RequestBody IdRequest request) {
|
||||
this.service.read(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的消息数量
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getMyNoticeCount")
|
||||
public Object getMyNoticeCount() {
|
||||
return this.service.getMyNoticeCount();
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public NoticeStatusDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<NoticeStatusDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.noticeStatus.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateNoticeStatusDto extends CommonDto {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.noticeStatus.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class MyNoticeStatusDto {
|
||||
|
||||
private Integer allCount;
|
||||
private Integer readCount;
|
||||
private Integer unReadCount;
|
||||
private Integer deleteCount;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.lihongjie.coal.noticeStatus.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.notice.dto.NoticeDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class NoticeStatusDto extends CommonDto {
|
||||
@ManyToOne
|
||||
private UserDto sender;
|
||||
|
||||
@ManyToOne
|
||||
private UserDto user;
|
||||
|
||||
private NoticeDto notice;
|
||||
|
||||
private Boolean read;
|
||||
|
||||
private Boolean delete;
|
||||
|
||||
|
||||
private LocalDateTime readTime;
|
||||
private LocalDateTime sendTime;
|
||||
private LocalDateTime deleteTime;
|
||||
|
||||
@Data
|
||||
public class UserDto extends OrgCommonDto {
|
||||
@Comment("用户名")
|
||||
private String username;
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Comment("会话ID")
|
||||
private String sessionId;
|
||||
|
||||
@Comment("机构管理员标识")
|
||||
private Boolean orgAdmin;
|
||||
|
||||
@Comment("系统管理员标识")
|
||||
private Boolean sysAdmin;
|
||||
|
||||
private String organizationName;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.noticeStatus.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateNoticeStatusDto extends CommonDto {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.noticeStatus.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.CommonEntity;
|
||||
import cn.lihongjie.coal.notice.entity.NoticeEntity;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class NoticeStatusEntity extends CommonEntity {
|
||||
|
||||
@ManyToOne
|
||||
private UserEntity sender;
|
||||
|
||||
@ManyToOne
|
||||
private UserEntity user;
|
||||
@ManyToOne()
|
||||
private NoticeEntity notice;
|
||||
|
||||
private Boolean read;
|
||||
|
||||
private Boolean delete;
|
||||
|
||||
|
||||
private LocalDateTime readTime;
|
||||
private LocalDateTime sendTime;
|
||||
private LocalDateTime deleteTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.noticeStatus.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.CreateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.NoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.UpdateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.entity.NoticeStatusEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class},
|
||||
mappingControl = DeepClone.class
|
||||
)
|
||||
public interface NoticeStatusMapper extends BaseMapper<NoticeStatusEntity, NoticeStatusDto, CreateNoticeStatusDto, UpdateNoticeStatusDto> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.noticeStatus.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.MyNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.entity.NoticeStatusEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface NoticeStatusRepository extends BaseRepository<NoticeStatusEntity> {
|
||||
@Query("""
|
||||
select count(1) as allCount,
|
||||
sum(case when t.read then 1 else 0 end) as readCount,
|
||||
sum(case when t.read then 0 else 1 end) as unReadCount,
|
||||
sum(case when t.delete then 1 else 0 end) as deleteCount
|
||||
from NoticeStatusEntity t where t.user.id = ?1
|
||||
""")
|
||||
MyNoticeStatusDto userNoticeCount(String userId);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package cn.lihongjie.coal.noticeStatus.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.CreateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.MyNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.NoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.dto.UpdateNoticeStatusDto;
|
||||
import cn.lihongjie.coal.noticeStatus.entity.NoticeStatusEntity;
|
||||
import cn.lihongjie.coal.noticeStatus.mapper.NoticeStatusMapper;
|
||||
import cn.lihongjie.coal.noticeStatus.repository.NoticeStatusRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class NoticeStatusService extends BaseService<NoticeStatusEntity, NoticeStatusRepository> {
|
||||
@Autowired private NoticeStatusRepository repository;
|
||||
|
||||
@Autowired private NoticeStatusMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
public NoticeStatusDto create(CreateNoticeStatusDto request) {
|
||||
NoticeStatusEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public NoticeStatusDto update(UpdateNoticeStatusDto request) {
|
||||
NoticeStatusEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
List<NoticeStatusEntity> allById = this.repository.findAllById(request.getIds());
|
||||
allById.forEach(x -> {
|
||||
x.setDelete(true);
|
||||
x.setDeleteTime(LocalDateTime.now());
|
||||
|
||||
});
|
||||
|
||||
this.repository.saveAll(allById);
|
||||
}
|
||||
|
||||
public NoticeStatusDto getById(String id) {
|
||||
NoticeStatusEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<NoticeStatusDto> list(CommonQuery query) {
|
||||
Page<NoticeStatusEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public MyNoticeStatusDto getMyNoticeCount() {
|
||||
MyNoticeStatusDto entity = repository.userNoticeCount(Ctx.getUserId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void read(IdRequest request) {
|
||||
|
||||
|
||||
List<NoticeStatusEntity> allById = this.repository.findAllById(request.getIds());
|
||||
allById.forEach(x -> {
|
||||
x.setRead(true);
|
||||
x.setReadTime(LocalDateTime.now());
|
||||
|
||||
});
|
||||
|
||||
this.repository.saveAll(allById);
|
||||
}
|
||||
}
|
||||
@@ -68,9 +68,10 @@ class SysLogService extends BaseService<SysLogEntity, SysLogRepository> {
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void save(SysLogEntity entity) {
|
||||
public SysLogEntity save(SysLogEntity entity) {
|
||||
|
||||
super.save(entity);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Page<SysLogDto> list(CommonQuery query) {
|
||||
|
||||
Reference in New Issue
Block a user