refactor(module): 重构消息模块代码
- 重命名多个类和文件,将 notice 替换为 message - 更新包名和引用 - 删除部分未使用的代码 - 对menu的权限进行增加
This commit is contained in:
parent
2f04a305be
commit
b431bf1c08
@ -2,7 +2,6 @@ package com.zsc.edu.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
|
@ -1,15 +1,13 @@
|
||||
package com.zsc.edu.gateway.framework.message.email;
|
||||
|
||||
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -43,7 +41,7 @@ public class EmailSender {
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
@Async
|
||||
public void send(String email, Message message) {
|
||||
public void send(String email, Notice notice) {
|
||||
if (StringUtils.hasText(email)) {
|
||||
return;
|
||||
}
|
||||
@ -54,11 +52,11 @@ public class EmailSender {
|
||||
} catch (AddressException e) {
|
||||
return;
|
||||
}
|
||||
send(new InternetAddress[]{to}, message);
|
||||
send(new InternetAddress[]{to}, notice);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void send(Set<String> emails, Message message) {
|
||||
public void send(Set<String> emails, Notice notice) {
|
||||
InternetAddress[] to = emails.stream().filter(Objects::nonNull).map(email ->
|
||||
{
|
||||
try {
|
||||
@ -77,23 +75,23 @@ public class EmailSender {
|
||||
if (to.length == 0) {
|
||||
return;
|
||||
}
|
||||
send(to, message);
|
||||
send(to, notice);
|
||||
}
|
||||
|
||||
private void send(InternetAddress[] to, Message message) {
|
||||
private void send(InternetAddress[] to, Notice notice) {
|
||||
try {
|
||||
MimeMessage mimeMessage = sender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setTo(to);
|
||||
helper.setFrom(config.username);
|
||||
helper.setSubject(message.getTitle());
|
||||
if (message.html) {
|
||||
helper.setSubject(notice.getTitle());
|
||||
if (notice.html) {
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tp = freemarkerConfig.getTemplate(TEMPLATE, "UTF-8");
|
||||
tp.process(message, sw);
|
||||
tp.process(notice, sw);
|
||||
helper.setText(sw.toString(), true);
|
||||
} else {
|
||||
helper.setText(message.content);
|
||||
helper.setText(notice.content);
|
||||
}
|
||||
// if (Objects.nonNull(message.attachments)) {
|
||||
// for (Attachment attachment : message.attachments) {
|
||||
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.*;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
@ -49,7 +50,7 @@ public class Attachment implements Serializable {
|
||||
/**
|
||||
* 文件上传时间
|
||||
*/
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public LocalDateTime uploadTime;
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@ import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||
import com.zsc.edu.gateway.modules.iot.device.entity.DeviceDiff;
|
||||
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.device.service.DeviceService;
|
||||
import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
|
||||
@ -14,6 +13,7 @@ import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -34,6 +34,7 @@ public class DeviceController {
|
||||
* 创建设备
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('iot:device:create')")
|
||||
public Device create(@RequestBody DeviceDto deviceDto) {
|
||||
return service.create(deviceDto);
|
||||
}
|
||||
@ -43,6 +44,7 @@ public class DeviceController {
|
||||
* 批量创建设备
|
||||
*/
|
||||
@PostMapping("batch")
|
||||
@PreAuthorize("hasAuthority('iot:device:create')")
|
||||
public List<Device> batchCreate(@RequestBody BatchDeviceDto batchDeviceDto) {
|
||||
return service.batchCreate(batchDeviceDto);
|
||||
}
|
||||
@ -52,6 +54,7 @@ public class DeviceController {
|
||||
* 更新设备
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:device:update')")
|
||||
public Device update(@RequestBody DeviceDto deviceDto, @PathVariable("id") Long id) {
|
||||
return service.update(deviceDto, id);
|
||||
}
|
||||
@ -61,6 +64,7 @@ public class DeviceController {
|
||||
* 分页查询设备
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('iot:device:query')")
|
||||
public Page<Device> query(Page<Device> page, DeviceQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -69,6 +73,7 @@ public class DeviceController {
|
||||
* 删除设备
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:device:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
@ -78,6 +83,7 @@ public class DeviceController {
|
||||
* 查询详情
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:device:query')")
|
||||
public DeviceVo detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
@ -87,6 +93,7 @@ public class DeviceController {
|
||||
* 手动触发事件
|
||||
*/
|
||||
@PostMapping("serve")
|
||||
@PreAuthorize("hasAuthority('iot:device:create')")
|
||||
public ResponseEntity<String> serve(@RequestBody DeviceServeDto dto) {
|
||||
if (service.serve(dto)) {
|
||||
return ResponseEntity.ok("服务执行成功");
|
||||
@ -98,16 +105,9 @@ public class DeviceController {
|
||||
/**
|
||||
* 查询设备上报记录
|
||||
*/
|
||||
@GetMapping("record/photo")
|
||||
public List<RecordData> recordPhoto(String clientId) {
|
||||
return recordService.recordPhoto(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询
|
||||
*/
|
||||
@GetMapping("/query")
|
||||
public List<DeviceDiff> query(String name) {
|
||||
return service.queryByName(name);
|
||||
@GetMapping("record/data")
|
||||
@PreAuthorize("hasAuthority('iot:device:query')")
|
||||
public List<RecordData> recordData(String clientId) {
|
||||
return recordService.recordData(clientId);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,4 @@ public interface DeviceService extends IService<Device> {
|
||||
DeviceVo detail(Long id);
|
||||
|
||||
Boolean serve(DeviceServeDto dto);
|
||||
|
||||
List<DeviceDiff> queryByName(String name);
|
||||
}
|
||||
|
@ -157,11 +157,4 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceDiff> queryByName(String name) {
|
||||
LambdaQueryWrapper<Device> query = new LambdaQueryWrapper<>();
|
||||
query.like(StringUtils.hasText(name), Device::getName, name);
|
||||
List<Device> devices = baseMapper.selectList(query);
|
||||
return devices.stream().map(device -> new DeviceDiff(device.getId(), device.getName())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class ProductController {
|
||||
* @return 新的产品
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('iot:product:create')")
|
||||
public Product create(@RequestBody ProductDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -46,6 +47,7 @@ public class ProductController {
|
||||
* @return 更新后的产品
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:product:update')")
|
||||
public Product update(@RequestBody ProductDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -59,6 +61,7 @@ public class ProductController {
|
||||
* @return Page<Device> 产品分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('iot:product:query')")
|
||||
public Page<Product> page(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -70,9 +73,9 @@ public class ProductController {
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping("fuzzy")
|
||||
// @PreAuthorize("hasAnyAuthority('DEVICE_CREATE', 'DEVICE_UPDATE')")
|
||||
@PreAuthorize("hasAuthority('iot:product:query')")
|
||||
public Page<Product> fuzzyQuery(Page<Product> page, ProductQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
return service.page(page, query.fuzzyWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,6 +85,7 @@ public class ProductController {
|
||||
* @return 被删除的产品
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:product:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.delete(id);
|
||||
}
|
||||
@ -94,6 +98,7 @@ public class ProductController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:product:query')")
|
||||
public Product detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class ProductQuery {
|
||||
|
||||
public LambdaQueryWrapper<Product> wrapper() {
|
||||
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StringUtils.hasText(this.name), Product::getName, this.name);
|
||||
queryWrapper.like(StringUtils.hasText(this.name), Product::getName, this.name);
|
||||
queryWrapper.eq(StringUtils.hasText(this.type), Product::getProductType, this.type);
|
||||
if (Objects.nonNull(this.links) && !this.links.isEmpty()) {
|
||||
queryWrapper.in(Product::getLink, this.links);
|
||||
@ -38,5 +38,9 @@ public class ProductQuery {
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
public LambdaQueryWrapper<Product> fuzzyWrapper() {
|
||||
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(StringUtils.hasText(this.name), Product::getName, this.name);
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.framework.json.MapJsonTypeHandler;
|
||||
import lombok.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
@ -28,5 +29,6 @@ public class RecordData {
|
||||
@TableField(typeHandler = MapJsonTypeHandler.class)
|
||||
private Map<String, Object> content;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime recordTime;
|
||||
}
|
||||
|
@ -14,5 +14,5 @@ public interface RecordDataService extends IService<RecordData> {
|
||||
|
||||
List<RecordData> page(IPage<RecordData> page, String clientId);
|
||||
|
||||
List<RecordData> recordPhoto(String clientId);
|
||||
List<RecordData> recordData(String clientId);
|
||||
}
|
@ -11,6 +11,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -37,9 +38,9 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
|
||||
return baseMapper.selectList(page, queryWrapper);
|
||||
}
|
||||
|
||||
//TODO 使用Redis
|
||||
//TODO 上报数据
|
||||
@Override
|
||||
public List<RecordData> recordPhoto(String clientId) {
|
||||
public List<RecordData> recordData(String clientId) {
|
||||
LocalDateTime recordTime = LocalDateTime.parse(redisUtils.get("serve:sendTime:photograph:" + clientId));
|
||||
List<RecordData> records = baseMapper.selectList(new LambdaQueryWrapper<RecordData>()
|
||||
.eq(RecordData::getClientId, clientId).le(RecordData::getRecordTime, recordTime));
|
||||
|
@ -7,6 +7,7 @@ import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.EventQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.EventService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@ -27,6 +28,7 @@ public class EventController {
|
||||
* @param dto 创建的事件
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('iot:event:create')")
|
||||
public Event create(@RequestBody EventDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -38,6 +40,7 @@ public class EventController {
|
||||
* @return 更新后的事件
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:event:update')")
|
||||
public Event update(@RequestBody EventDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -51,6 +54,7 @@ public class EventController {
|
||||
* @return Page<Device> 事件分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('iot:event:query')")
|
||||
public Page<Event> page(Page<Event> page, EventQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -63,6 +67,7 @@ public class EventController {
|
||||
* @return 被删除的事件
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:event:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.delete(id);
|
||||
}
|
||||
@ -75,6 +80,7 @@ public class EventController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:event:delete')")
|
||||
public Event detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.PropertyQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.PropertyService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -28,6 +29,7 @@ public class PropertyController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('iot:property:create')")
|
||||
public Property create(@RequestBody PropertyDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -39,6 +41,7 @@ public class PropertyController {
|
||||
* @return 更新后的属性
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:property:update')")
|
||||
public Property update(@RequestBody PropertyDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -52,6 +55,7 @@ public class PropertyController {
|
||||
* @return Page<Device> 属性分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('iot:property:query')")
|
||||
public Page<Property> query(PropertyQuery query, Page<Property> page) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -62,6 +66,7 @@ public class PropertyController {
|
||||
* @return 被删除的属性
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:property:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
@ -74,6 +79,7 @@ public class PropertyController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('iot:property:query')")
|
||||
public Property detail(@PathVariable("id") Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.iot.tsl.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.query.ServeQuery;
|
||||
import com.zsc.edu.gateway.modules.iot.tsl.service.ServeService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ public class ServeController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('iot:server:create')")
|
||||
public Serve create(@RequestBody ServeDto dto) {
|
||||
return serveService.create(dto);
|
||||
}
|
||||
@ -39,6 +40,7 @@ public class ServeController {
|
||||
* @return 更新后的服务
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAnyAuthority('iot:server:update')")
|
||||
public Serve update(@RequestBody ServeDto dto, @PathVariable("id") Long id) {
|
||||
return serveService.update(dto, id);
|
||||
}
|
||||
@ -52,6 +54,7 @@ public class ServeController {
|
||||
* @return Page<Device> 服务分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('iot:server:query')")
|
||||
public Page<Serve> page(Page<Serve> page, ServeQuery query) {
|
||||
return serveService.page(page, query.wrapper());
|
||||
}
|
||||
@ -63,6 +66,7 @@ public class ServeController {
|
||||
* @return 被删除的服务
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAnyAuthority('iot:server:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return serveService.delete(id);
|
||||
}
|
||||
@ -75,6 +79,7 @@ public class ServeController {
|
||||
* @return 任务
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAnyAuthority('iot:server:query')")
|
||||
public Serve detail(@PathVariable("id") Long id) {
|
||||
return serveService.detail(id);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
* 新建物模型事件
|
||||
*/
|
||||
@Override
|
||||
|
||||
public Event create(EventDto dto) {
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
|
@ -1,20 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.notice.controller;
|
||||
package com.zsc.edu.gateway.modules.message.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.message.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.message.vo.BulletinVo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 公告Controller
|
||||
@ -57,7 +55,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_QUERY')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:query')")
|
||||
public BulletinVo detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.detail(userDetails,id, null);
|
||||
}
|
||||
@ -69,7 +67,7 @@ public class BulletinController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping()
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_QUERY')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:query')")
|
||||
public Page<Bulletin> query(Page<Bulletin> page, BulletinQuery query) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -82,7 +80,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@PostMapping
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_CREATE')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:create')")
|
||||
public Bulletin create(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody BulletinDto dto) {
|
||||
return service.create(userDetails, dto);
|
||||
}
|
||||
@ -96,7 +94,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@PatchMapping("/{id}")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_UPDATE')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:update')")
|
||||
public Boolean update(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody BulletinDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(userDetails, dto, id);
|
||||
}
|
||||
@ -108,7 +106,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@PatchMapping("/{id}/toggle-top")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_UPDATE')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:update')")
|
||||
public Boolean toggleTop(@PathVariable("id") Long id) {
|
||||
return service.toggleTop(id);
|
||||
}
|
||||
@ -121,7 +119,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@PatchMapping("/publish")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_PUBLISH')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:update')")
|
||||
public Boolean publish(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody List<Long> ids) {
|
||||
return service.publish(userDetails, ids);
|
||||
}
|
||||
@ -134,7 +132,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@PatchMapping("/{id}/toggleClose")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_CLOSE')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:update')")
|
||||
public Boolean toggleClose(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.close(userDetails, id);
|
||||
}
|
||||
@ -146,7 +144,7 @@ public class BulletinController {
|
||||
* @return 公
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
// @PreAuthorize("hasAuthority('BULLETIN_DELETE')")
|
||||
@PreAuthorize("hasAuthority('message:bulletin:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.delete(id);
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.notice.controller;
|
||||
package com.zsc.edu.gateway.modules.message.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.query.AdminNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.query.UserNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.service.UserNoticeService;
|
||||
import com.zsc.edu.gateway.modules.message.vo.AdminNoticeVo;
|
||||
import com.zsc.edu.gateway.modules.message.vo.UserNoticeVo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
@ -23,10 +23,10 @@ import java.util.List;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("api/rest/message")
|
||||
public class UserMessageController {
|
||||
@RequestMapping("api/rest/notice")
|
||||
public class UserNoticeController {
|
||||
|
||||
private final UserMessageService service;
|
||||
private final UserNoticeService service;
|
||||
|
||||
/**
|
||||
* 普通用户查看消息详情
|
||||
@ -35,8 +35,8 @@ public class UserMessageController {
|
||||
* @param messageId 消息ID
|
||||
* @return 用户消息详情
|
||||
*/
|
||||
@GetMapping("/self/{messageId}")
|
||||
public UserMessageVo selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("messageId") Long messageId) {
|
||||
@GetMapping("/self/{noticeId}")
|
||||
public UserNoticeVo selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("noticeId") Long messageId) {
|
||||
return service.detail(messageId, userDetails.getId());
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class UserMessageController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<UserMessageVo> selfPage(Page<UserMessageVo> pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||
public IPage<UserNoticeVo> selfPage(Page<UserNoticeVo> pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserNoticeQuery query) {
|
||||
query.userId = userDetails.id;
|
||||
query.name = null;
|
||||
return service.page(pageParam, query);
|
||||
@ -69,12 +69,12 @@ public class UserMessageController {
|
||||
* 普通用户确认消息已读,如果提交的已读消息ID集合为空,则将所有未读消息设为已读
|
||||
*
|
||||
* @param userDetails 操作用户
|
||||
* @param messageIds 已读消息ID集合
|
||||
* @param noticeIds 已读消息ID集合
|
||||
* @return 确认已读数量
|
||||
*/
|
||||
@PatchMapping("/read")
|
||||
public Boolean acknowledge(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody List<Long> messageIds) {
|
||||
return service.markAsRead(userDetails, messageIds);
|
||||
public Boolean acknowledge(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody List<Long> noticeIds) {
|
||||
return service.markAsRead(userDetails, noticeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,13 +91,13 @@ public class UserMessageController {
|
||||
/**
|
||||
* 管理查询消息详情
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @param noticeId 消息ID
|
||||
* @return 用户消息详情
|
||||
*/
|
||||
@GetMapping("/{userId}/{messageId}")
|
||||
// @PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public UserMessageVo detail(@PathVariable("userId") Long userId, @PathVariable("messageId") Long messageId) {
|
||||
return service.detail(messageId, userId);
|
||||
@GetMapping("/{userId}/{noticeId}")
|
||||
@PreAuthorize("hasAuthority('message:notice:query')")
|
||||
public UserNoticeVo detail(@PathVariable("userId") Long userId, @PathVariable("noticeId") Long noticeId) {
|
||||
return service.detail(noticeId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,9 +107,9 @@ public class UserMessageController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping
|
||||
// @PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public IPage<AdminMessageVo> page(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
return service.getAdminMessagePage(page, query);
|
||||
@PreAuthorize("hasAuthority('message:notice:query')")
|
||||
public IPage<AdminNoticeVo> page(Page<UserNoticeVo> page, AdminNoticeQuery query) {
|
||||
return service.getAdminNoticePage(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,8 +119,8 @@ public class UserMessageController {
|
||||
* @return 消息列表
|
||||
*/
|
||||
@PostMapping
|
||||
// @PreAuthorize("hasAuthority('MESSAGE_CREATE')")
|
||||
public Boolean create(@RequestBody UserMessageDto dto) {
|
||||
@PreAuthorize("hasAuthority('message:notice:create')")
|
||||
public Boolean create(@RequestBody UserNoticeDto dto) {
|
||||
return service.createByAdmin(dto);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.dto;
|
||||
package com.zsc.edu.gateway.modules.message.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.dto;
|
||||
package com.zsc.edu.gateway.modules.message.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.dto;
|
||||
package com.zsc.edu.gateway.modules.message.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.notice.dto;
|
||||
package com.zsc.edu.gateway.modules.message.dto;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -16,7 +16,7 @@ import java.util.Set;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserMessageDto {
|
||||
public class UserNoticeDto {
|
||||
|
||||
/**
|
||||
* 用户ID集合
|
||||
@ -28,7 +28,7 @@ public class UserMessageDto {
|
||||
* 消息类型
|
||||
*/
|
||||
@NotNull(message = "消息类型不能为空")
|
||||
public MessageType type;
|
||||
public NoticeType type;
|
||||
|
||||
/**
|
||||
* 是否需要发送邮件
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
@ -7,6 +7,7 @@ import com.zsc.edu.gateway.common.enums.IState;
|
||||
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import lombok.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -73,6 +74,7 @@ public class Bulletin extends BaseEntity {
|
||||
/**
|
||||
* 审核发布时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public LocalDateTime publishTime;
|
||||
|
||||
/**
|
||||
@ -89,6 +91,7 @@ public class Bulletin extends BaseEntity {
|
||||
/**
|
||||
* 关闭时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public LocalDateTime closeTime;
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
@ -1,15 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*
|
||||
@ -19,13 +16,13 @@ import java.util.List;
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_message")
|
||||
public class Message extends BaseEntity {
|
||||
@TableName("sys_notice")
|
||||
public class Notice extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
public MessageType type = MessageType.other;
|
||||
public NoticeType type = NoticeType.other;
|
||||
|
||||
/**
|
||||
* 是否系统生成
|
||||
@ -37,6 +34,7 @@ public class Message extends BaseEntity {
|
||||
*/
|
||||
public Boolean email;
|
||||
|
||||
|
||||
/**
|
||||
* 是否需要发送短信
|
||||
*/
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -8,20 +8,20 @@ import java.time.format.DateTimeFormatter;
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public abstract class MessagePayload {
|
||||
public abstract class NoticePayload {
|
||||
|
||||
public MessageType type;
|
||||
public NoticeType type;
|
||||
public String content;
|
||||
public Boolean html;
|
||||
|
||||
public static class Other extends MessagePayload {
|
||||
public static class Other extends NoticePayload {
|
||||
public Other(String content) {
|
||||
this.content = content;
|
||||
this.type = MessageType.other;
|
||||
this.type = NoticeType.other;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResetPassword extends MessagePayload {
|
||||
public static class ResetPassword extends NoticePayload {
|
||||
public String username;
|
||||
public String password;
|
||||
public LocalDateTime resetTime;
|
||||
@ -30,7 +30,7 @@ public abstract class MessagePayload {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.resetTime = resetTime;
|
||||
this.type =MessageType.resetThePassword;
|
||||
this.type = NoticeType.resetThePassword;
|
||||
this.content = String.format("尊敬的用户%s,您的密码已于%s被管理员重置,新密码为%s," +
|
||||
"请及时登录系统修改密码!", username, resetTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), password);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.zsc.edu.gateway.common.enums.IState;
|
||||
@ -8,14 +8,14 @@ import com.zsc.edu.gateway.common.enums.IState;
|
||||
*
|
||||
* @author zhuang
|
||||
*/
|
||||
public enum MessageType implements IEnum<Integer>, IState<MessageType> {
|
||||
public enum NoticeType implements IEnum<Integer>, IState<NoticeType> {
|
||||
other(1, "消息"),
|
||||
resetThePassword(2, "通知");
|
||||
|
||||
private final Integer value;
|
||||
private final String name;
|
||||
|
||||
MessageType(Integer value, String name) {
|
||||
NoticeType(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
package com.zsc.edu.gateway.modules.message.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import lombok.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
@ -17,8 +16,8 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_user_message")
|
||||
public class UserMessage implements Serializable {
|
||||
@TableName("sys_user_notice")
|
||||
public class UserNotice implements Serializable {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
@ -32,7 +31,7 @@ public class UserMessage implements Serializable {
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
public Long messageId;
|
||||
public Long noticeId;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,6 +42,7 @@ public class UserMessage implements Serializable {
|
||||
/**
|
||||
* 阅读时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public LocalDateTime readTime;
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
package com.zsc.edu.gateway.modules.message.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinAttachmentDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinAttachmentDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.BulletinAttachment;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
package com.zsc.edu.gateway.modules.message.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.message.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface NoticeMapper extends BaseMapper<UserNoticeDto, Notice> {
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.zsc.edu.gateway.modules.notice.query;
|
||||
package com.zsc.edu.gateway.modules.message.query;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -14,7 +13,7 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AdminMessageQuery {
|
||||
public class AdminNoticeQuery {
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
@ -1,9 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.notice.query;
|
||||
package com.zsc.edu.gateway.modules.message.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.notice.query;
|
||||
package com.zsc.edu.gateway.modules.message.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -15,12 +15,12 @@ import java.util.Set;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MessageQuery {
|
||||
Set<Long> messageIds;
|
||||
public class NoticeQuery {
|
||||
Set<Long> noticeIds;
|
||||
|
||||
public LambdaQueryWrapper<Message> wrapper() {
|
||||
LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StringUtils.hasText((CharSequence) this.messageIds), Message::getId, this.messageIds);
|
||||
public LambdaQueryWrapper<Notice> wrapper() {
|
||||
LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StringUtils.hasText((CharSequence) this.noticeIds), Notice::getId, this.noticeIds);
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
@ -1,18 +1,12 @@
|
||||
package com.zsc.edu.gateway.modules.notice.query;
|
||||
package com.zsc.edu.gateway.modules.message.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户消息Query
|
||||
@ -22,7 +16,7 @@ import java.util.Objects;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserMessageQuery {
|
||||
public class UserNoticeQuery {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
@ -37,7 +31,7 @@ public class UserMessageQuery {
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
public MessageType type;
|
||||
public NoticeType type;
|
||||
|
||||
/**
|
||||
* 用户名或真实姓名,用户名准确查询,姓名模糊查询
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
package com.zsc.edu.gateway.modules.message.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.message.entity.BulletinAttachment;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
@ -1,11 +1,11 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
package com.zsc.edu.gateway.modules.message.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.message.vo.BulletinVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.zsc.edu.gateway.modules.message.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
|
||||
/**
|
||||
* 消息Repo
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface NoticeRepository extends BaseMapper<Notice> {
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.zsc.edu.gateway.modules.message.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.message.entity.UserNotice;
|
||||
import com.zsc.edu.gateway.modules.message.query.AdminNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.query.UserNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.vo.AdminNoticeVo;
|
||||
import com.zsc.edu.gateway.modules.message.vo.UserNoticeVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 用户消息Repo
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserNoticeRepository extends BaseMapper<UserNotice> {
|
||||
|
||||
UserNoticeVo selectByNoticeIdAndUserId(@Param("noticeId") Long messageId, @Param("userId") Long userId);
|
||||
|
||||
IPage<UserNoticeVo> page(Page<UserNoticeVo> page, @Param("query") UserNoticeQuery query);
|
||||
|
||||
IPage<AdminNoticeVo> pageAdmin(Page<UserNoticeVo> page, @Param("query") AdminNoticeQuery query);
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service;
|
||||
package com.zsc.edu.gateway.modules.message.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.message.vo.BulletinVo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.zsc.edu.gateway.modules.message.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.UserNotice;
|
||||
import com.zsc.edu.gateway.modules.message.query.AdminNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.query.UserNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.vo.AdminNoticeVo;
|
||||
import com.zsc.edu.gateway.modules.message.vo.UserNoticeVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户消息Service
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserNoticeService extends IService<UserNotice> {
|
||||
|
||||
Boolean createByAdmin(UserNoticeDto dto);
|
||||
|
||||
UserNoticeVo detail(Long messageId, Long userId);
|
||||
|
||||
IPage<UserNoticeVo> page(Page<UserNoticeVo> page, UserNoticeQuery query);
|
||||
|
||||
Integer countUnread(UserDetailsImpl userDetails);
|
||||
|
||||
boolean markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
|
||||
|
||||
boolean markAllAsRead(UserDetailsImpl userDetails);
|
||||
|
||||
IPage<AdminNoticeVo> getAdminNoticePage(Page<UserNoticeVo> page, AdminNoticeQuery query);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
package com.zsc.edu.gateway.modules.message.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -6,15 +6,15 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.notice.mapper.BulletinMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinAttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.entity.BulletinAttachment;
|
||||
import com.zsc.edu.gateway.modules.message.mapper.BulletinMapper;
|
||||
import com.zsc.edu.gateway.modules.message.query.BulletinQuery;
|
||||
import com.zsc.edu.gateway.modules.message.repo.BulletinAttachmentRepository;
|
||||
import com.zsc.edu.gateway.modules.message.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.message.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.message.vo.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -23,7 +23,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zsc.edu.gateway.modules.notice.entity.Bulletin.State.*;
|
||||
import static com.zsc.edu.gateway.modules.message.entity.Bulletin.State.*;
|
||||
|
||||
/**
|
||||
* 系统公告Service
|
@ -1,4 +1,4 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
package com.zsc.edu.gateway.modules.message.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -8,16 +8,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.framework.message.email.EmailSender;
|
||||
import com.zsc.edu.gateway.framework.message.sms.SmsSender;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.*;
|
||||
import com.zsc.edu.gateway.modules.notice.mapper.MessageMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.MessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.*;
|
||||
import com.zsc.edu.gateway.modules.message.mapper.NoticeMapper;
|
||||
import com.zsc.edu.gateway.modules.message.query.AdminNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.query.UserNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.repo.NoticeRepository;
|
||||
import com.zsc.edu.gateway.modules.message.repo.UserNoticeRepository;
|
||||
import com.zsc.edu.gateway.modules.message.service.UserNoticeService;
|
||||
import com.zsc.edu.gateway.modules.message.vo.AdminNoticeVo;
|
||||
import com.zsc.edu.gateway.modules.message.vo.UserNoticeVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -38,30 +38,30 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, UserMessage> implements UserMessageService {
|
||||
public class UserNoticeServiceImpl extends ServiceImpl<UserNoticeRepository, UserNotice> implements UserNoticeService {
|
||||
|
||||
private final MessageRepository messageRepo;
|
||||
private final NoticeRepository noticeRepo;
|
||||
private final EmailSender emailSender;
|
||||
private final SmsSender smsSender;
|
||||
private final UserRepository userRepository;
|
||||
private final MessageMapper messageMapper;
|
||||
private final NoticeMapper noticeMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询消息详情
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @param noticeId 消息ID
|
||||
* @param userId 用户ID
|
||||
* @return 查询详情
|
||||
*/
|
||||
|
||||
@Override
|
||||
public UserMessageVo detail(Long messageId, Long userId) {
|
||||
UserMessageVo userMessageVo = baseMapper.selectByMessageIdAndUserId(messageId, userId);
|
||||
if (userMessageVo == null) {
|
||||
public UserNoticeVo detail(Long noticeId, Long userId) {
|
||||
UserNoticeVo userNoticeVo = baseMapper.selectByNoticeIdAndUserId(noticeId, userId);
|
||||
if (userNoticeVo == null) {
|
||||
throw new RuntimeException("您输入的信息有误,请检查输入ID信息是否正确");
|
||||
}
|
||||
return userMessageVo;
|
||||
return userNoticeVo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
* @return 页面数据
|
||||
*/
|
||||
@Override
|
||||
public IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query) {
|
||||
public IPage<UserNoticeVo> page(Page<UserNoticeVo> page, UserNoticeQuery query) {
|
||||
return baseMapper.page(page, query);
|
||||
}
|
||||
|
||||
@ -84,9 +84,9 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
*/
|
||||
@Override
|
||||
public Integer countUnread(UserDetailsImpl userDetails) {
|
||||
LambdaQueryWrapper<UserMessage> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserMessage::getUserId, userDetails.getId())
|
||||
.eq(UserMessage::getIsRead, true);
|
||||
LambdaQueryWrapper<UserNotice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserNotice::getUserId, userDetails.getId())
|
||||
.eq(UserNotice::getIsRead, true);
|
||||
return Math.toIntExact(baseMapper.selectCount(lambdaQueryWrapper));
|
||||
}
|
||||
|
||||
@ -102,10 +102,10 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
if (CollectionUtils.isEmpty(messageIds)) {
|
||||
throw new RuntimeException("您输入的集合为空");
|
||||
}
|
||||
return this.lambdaUpdate().eq(UserMessage::getUserId, userDetails.getId())
|
||||
.in(UserMessage::getMessageId, messageIds)
|
||||
.set(UserMessage::getIsRead, true)
|
||||
.set(UserMessage::getReadTime, LocalDateTime.now())
|
||||
return this.lambdaUpdate().eq(UserNotice::getUserId, userDetails.getId())
|
||||
.in(UserNotice::getNoticeId, messageIds)
|
||||
.set(UserNotice::getIsRead, true)
|
||||
.set(UserNotice::getReadTime, LocalDateTime.now())
|
||||
.update();
|
||||
}
|
||||
|
||||
@ -114,9 +114,9 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
*/
|
||||
@Override
|
||||
public boolean markAllAsRead(UserDetailsImpl userDetails) {
|
||||
return this.lambdaUpdate().eq(UserMessage::getUserId, userDetails.getId())
|
||||
.set(UserMessage::getIsRead, true)
|
||||
.set(UserMessage::getReadTime, LocalDateTime.now())
|
||||
return this.lambdaUpdate().eq(UserNotice::getUserId, userDetails.getId())
|
||||
.set(UserNotice::getIsRead, true)
|
||||
.set(UserNotice::getReadTime, LocalDateTime.now())
|
||||
.update();
|
||||
}
|
||||
|
||||
@ -126,12 +126,13 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
* @return 消息设置列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
public IPage<AdminNoticeVo> getAdminNoticePage(Page<UserNoticeVo> page, AdminNoticeQuery query) {
|
||||
return baseMapper.pageAdmin(page, query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 管理员手动创建用户消息并发送
|
||||
*
|
||||
* @param dto 表单数据
|
||||
@ -139,15 +140,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Boolean createByAdmin(UserMessageDto dto) {
|
||||
public Boolean createByAdmin(UserNoticeDto dto) {
|
||||
Set<User> users = new HashSet<>(userRepository.selectList(new LambdaQueryWrapper<User>().in(User::getId, dto.userIds)));
|
||||
Message message = messageMapper.toEntity(dto);
|
||||
messageRepo.insert(message);
|
||||
Set<UserMessage> userMessages = users.stream()
|
||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), true, null))
|
||||
Notice notice = noticeMapper.toEntity(dto);
|
||||
noticeRepo.insert(notice);
|
||||
Set<UserNotice> userNotices = users.stream()
|
||||
.map(user -> new UserNotice(null, user.getId(), notice.getId(), true, null))
|
||||
.collect(Collectors.toSet());
|
||||
send(users, message);
|
||||
return saveBatch(userMessages);
|
||||
send(users, notice);
|
||||
return saveBatch(userNotices);
|
||||
}
|
||||
|
||||
|
||||
@ -155,15 +156,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
* 以邮件、短信等形式发送消息,只有非html格式的消息才能以短信方式发送
|
||||
*
|
||||
* @param users 接收者
|
||||
* @param message 消息
|
||||
* @param notice 消息
|
||||
*/
|
||||
@Async
|
||||
void send(Set<User> users, Message message) {
|
||||
if (message.email) {
|
||||
emailSender.send(users.stream().map(User::getEmail).collect(Collectors.toSet()), message);
|
||||
void send(Set<User> users, Notice notice) {
|
||||
if (notice.email) {
|
||||
emailSender.send(users.stream().map(User::getEmail).collect(Collectors.toSet()), notice);
|
||||
}
|
||||
if (message.sms && !message.html) {
|
||||
smsSender.send(users.stream().map(User::getPhone).collect(Collectors.toSet()), message.content);
|
||||
if (notice.sms && !notice.html) {
|
||||
smsSender.send(users.stream().map(User::getPhone).collect(Collectors.toSet()), notice.content);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,20 +176,20 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
* @param payload 消息内容
|
||||
*/
|
||||
@Transactional
|
||||
public Boolean createBySystem(Set<User> receivers, MessagePayload payload) {
|
||||
public Boolean createBySystem(Set<User> receivers, NoticePayload payload) {
|
||||
AtomicBoolean email = new AtomicBoolean(false);
|
||||
AtomicBoolean sms = new AtomicBoolean(false);
|
||||
Optional.of(messageRepo.selectById(payload.type)).ifPresent(message -> {
|
||||
Optional.of(noticeRepo.selectById(payload.type)).ifPresent(message -> {
|
||||
email.set(message.email);
|
||||
sms.set(message.sms);
|
||||
});
|
||||
Message message = new Message(payload.type, true, email.get(), sms.get(),
|
||||
Notice notice = new Notice(payload.type, true, email.get(), sms.get(),
|
||||
payload.html, payload.type.name(), payload.content, null);
|
||||
messageRepo.insert(message);
|
||||
Set<UserMessage> userMessages = receivers.stream().map(user ->
|
||||
new UserMessage(null, user.getId(), message.getId(), true, null)).collect(Collectors.toSet());
|
||||
send(receivers, message);
|
||||
return saveBatch(userMessages);
|
||||
noticeRepo.insert(notice);
|
||||
Set<UserNotice> userNotices = receivers.stream().map(user ->
|
||||
new UserNotice(null, user.getId(), notice.getId(), true, null)).collect(Collectors.toSet());
|
||||
send(receivers, notice);
|
||||
return saveBatch(userNotices);
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package com.zsc.edu.gateway.modules.notice.vo;
|
||||
package com.zsc.edu.gateway.modules.message.vo;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class AdminMessageVo {
|
||||
public class AdminNoticeVo {
|
||||
/**
|
||||
* 用户消息id
|
||||
*/
|
||||
@ -23,7 +23,7 @@ public class AdminMessageVo {
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
public MessageType type = MessageType.other;
|
||||
public NoticeType type = NoticeType.other;
|
||||
/**
|
||||
* 是否系统消息
|
||||
*/
|
@ -1,8 +1,8 @@
|
||||
package com.zsc.edu.gateway.modules.notice.vo;
|
||||
package com.zsc.edu.gateway.modules.message.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway.modules.notice.vo;
|
||||
package com.zsc.edu.gateway.modules.message.vo;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -9,7 +9,7 @@ import java.time.LocalDateTime;
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class UserMessageVo {
|
||||
public class UserNoticeVo {
|
||||
/**
|
||||
* 用户消息id
|
||||
*/
|
||||
@ -31,7 +31,7 @@ public class UserMessageVo {
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
public MessageType type = MessageType.other;
|
||||
public NoticeType type = NoticeType.other;
|
||||
/**
|
||||
* 是否系统消息
|
||||
*/
|
@ -1,22 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_message_attachment")
|
||||
public class MessageAttachment {
|
||||
|
||||
private Long messageId;
|
||||
|
||||
private String attachmentId;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.mapper;
|
||||
|
||||
import com.zsc.edu.gateway.common.mapstruct.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface MessageMapper extends BaseMapper<UserMessageDto, Message> {
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
|
||||
/**
|
||||
* 消息Repo
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface MessageRepository extends BaseMapper<Message> {
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 用户消息Repo
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserMessageRepository extends BaseMapper<UserMessage> {
|
||||
|
||||
UserMessageVo selectByMessageIdAndUserId(@Param("messageId") Long messageId, @Param("userId") Long userId);
|
||||
|
||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||
|
||||
IPage<AdminMessageVo> pageAdmin(Page<UserMessageVo> page, @Param("query") AdminMessageQuery query);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.query.UserMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户消息Service
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface UserMessageService extends IService<UserMessage> {
|
||||
|
||||
Boolean createByAdmin(UserMessageDto dto);
|
||||
|
||||
UserMessageVo detail(Long messageId, Long userId);
|
||||
|
||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
|
||||
|
||||
Integer countUnread(UserDetailsImpl userDetails);
|
||||
|
||||
boolean markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
|
||||
|
||||
boolean markAllAsRead(UserDetailsImpl userDetails);
|
||||
|
||||
IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query);
|
||||
}
|
@ -35,7 +35,7 @@ public class DeptController {
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:QUERY')")
|
||||
@PreAuthorize("hasAuthority('system:dept:query')")
|
||||
public Page<Dept> query(DeptQuery query, Page<Dept> page) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class DeptController {
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:QUERY')")
|
||||
@PreAuthorize("hasAuthority('system:dept:query')")
|
||||
public List<Dept> tree(@RequestParam Long id) {
|
||||
return service.listTree(id);
|
||||
}
|
||||
@ -59,7 +59,7 @@ public class DeptController {
|
||||
* @return Dept 新建的管理部门
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:CREATE')")
|
||||
@PreAuthorize("hasAuthority('system:dept:create')")
|
||||
public Dept create(@RequestBody DeptDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class DeptController {
|
||||
* @return Dept 更新后的部门
|
||||
*/
|
||||
@PatchMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:UPDATE')")
|
||||
@PreAuthorize("hasAuthority('system:dept:update')")
|
||||
public Boolean update(@RequestBody DeptDto dto, @PathVariable("id") Long id) {
|
||||
return service.edit(dto, id);
|
||||
}
|
||||
@ -83,7 +83,7 @@ public class DeptController {
|
||||
* @return Boolean 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:DELETE')")
|
||||
@PreAuthorize("hasAuthority('system:dept:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
// 是否存在用户绑定此部门
|
||||
boolean hasUser = userService.count(new LambdaQueryWrapper<User>().eq(User::getDeptId, id)) > 0;
|
||||
@ -97,7 +97,7 @@ public class DeptController {
|
||||
* 更新管理部门状态
|
||||
* */
|
||||
@PatchMapping("/toggle/{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:TOGGLE')")
|
||||
@PreAuthorize("hasAuthority('system:dept:update')")
|
||||
public Boolean toggle(@PathVariable("id") Long id) {
|
||||
return service.toggle(id);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class RoleController {
|
||||
* @return 所有角色列表
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:QUERY')")
|
||||
@PreAuthorize("hasAuthority('system:role:query')")
|
||||
public Page<Role> query(RoleQuery query, Page<Role> page) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class RoleController {
|
||||
* @return Role 新建的角色
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:CREATE')")
|
||||
@PreAuthorize("hasAuthority('system:role:create')")
|
||||
public Boolean create(@RequestBody RoleDto dto) {
|
||||
Role role= service.create(dto);
|
||||
return role != null;
|
||||
@ -62,7 +62,7 @@ public class RoleController {
|
||||
* @return Role 更新后的角色
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:UPDATE')")
|
||||
@PreAuthorize("hasAuthority('system:role:update')")
|
||||
public Boolean update(@RequestBody RoleDto dto, @PathVariable("id") Long id) {
|
||||
// Role role = roleMapper.toEntity(dto);
|
||||
// role.setId(id);
|
||||
@ -76,7 +76,7 @@ public class RoleController {
|
||||
* @return Role 更新后的角色
|
||||
*/
|
||||
@PatchMapping("{id}/toggle")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:UPDATE')")
|
||||
@PreAuthorize("hasAuthority('system:role:update')")
|
||||
public Boolean toggle(@PathVariable("id") Long id) {
|
||||
return service.toggle(id);
|
||||
}
|
||||
@ -88,7 +88,7 @@ public class RoleController {
|
||||
* @return Role 角色详情
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:QUERY')")
|
||||
@PreAuthorize("hasAuthority('system:role:query')")
|
||||
public RoleVo detail(@PathVariable Long id) {
|
||||
return service.detail(id);
|
||||
}
|
||||
@ -100,7 +100,7 @@ public class RoleController {
|
||||
* @return Role 更新后的角色
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:DELETE')")
|
||||
@PreAuthorize("hasAuthority('system:role:delete')")
|
||||
public Boolean delete(@PathVariable Long id) {
|
||||
return service.delete(id);
|
||||
}
|
||||
@ -111,7 +111,7 @@ public class RoleController {
|
||||
* @return RoleAuthority 新的角色权限
|
||||
*/
|
||||
@PostMapping("/saveAuth/{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:ROLE:AUTHED')")
|
||||
@PreAuthorize("hasAuthority('system:role:create')")
|
||||
public Boolean addAuthed(@PathVariable Long id, @RequestBody Set<AuthorityCreateDto> authorities) {
|
||||
return service.saveRoleAuths(id,authorities);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class UserController {
|
||||
* @return 分页用户信息
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:QUERY')")
|
||||
@PreAuthorize("hasAuthority('system:user:query')")
|
||||
public Page<User> query(UserQuery query, Page<User> page) {
|
||||
return service.page(page, query.wrapper());
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class UserController {
|
||||
* @return 新建的用户信息
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:CREATE')")
|
||||
@PreAuthorize("hasAuthority('system:user:create')")
|
||||
public Boolean create(@RequestBody UserCreateDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
@ -138,7 +138,7 @@ public class UserController {
|
||||
* @return 更新后的用户
|
||||
*/
|
||||
@PatchMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:UPDATE')")
|
||||
@PreAuthorize("hasAuthority('system:user:update')")
|
||||
public Boolean update(@RequestBody UserUpdateDto dto, @PathVariable("id") Long id) {
|
||||
return service.update(dto, id);
|
||||
}
|
||||
@ -150,7 +150,7 @@ public class UserController {
|
||||
* @param password 新密码
|
||||
*/
|
||||
@PatchMapping("{id}/update-password")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:UPDATE')")
|
||||
@PreAuthorize("hasAuthority('system:user:update')")
|
||||
public Boolean updatePassword(@PathVariable("id") Long id, @RequestParam String password) {
|
||||
return service.updatePassword(password, id);
|
||||
}
|
||||
@ -162,7 +162,7 @@ public class UserController {
|
||||
* @return Dept 更新后的用户
|
||||
*/
|
||||
@PatchMapping("{id}/toggle")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:DELETE')")
|
||||
@PreAuthorize("hasAuthority('system:user:delete')")
|
||||
public Boolean toggle(@PathVariable("id") Long id) {
|
||||
return service.toggle(id);
|
||||
}
|
||||
@ -170,7 +170,7 @@ public class UserController {
|
||||
* 删除用户 hasAuthority('SYSTEM:USER:DELETE')
|
||||
* */
|
||||
@DeleteMapping("{id}")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:USER:DELETE')")
|
||||
@PreAuthorize("hasAuthority('system:user:delete')")
|
||||
public Boolean delete(@PathVariable("id") Long id) {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.BulletinRepository">
|
||||
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.notice.vo.BulletinVo">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.message.repo.BulletinRepository">
|
||||
<resultMap id="BulletinMap" type="com.zsc.edu.gateway.modules.message.vo.BulletinVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
||||
<result column="state" jdbcType="INTEGER" property="state"/>
|
||||
|
@ -1,13 +0,0 @@
|
||||
<?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.zsc.edu.gateway.modules.notice.repo.MessageRepository">
|
||||
<select id="selectById" resultType="com.zsc.edu.gateway.modules.notice.entity.Message">
|
||||
select *
|
||||
from sys_message sm
|
||||
left join sys_message_attachment sma on sm.id = sma.message_id
|
||||
left join attachment a on sma.attachment_id = a.id
|
||||
where sm.id = #{messageId}
|
||||
</select>
|
||||
</mapper>
|
6
src/main/resources/mappers/notice/NoticeMapper.xml
Normal file
6
src/main/resources/mappers/notice/NoticeMapper.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?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.zsc.edu.gateway.modules.message.repo.NoticeRepository">
|
||||
</mapper>
|
@ -2,8 +2,8 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository">
|
||||
<resultMap id="userMessageMap" type="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.message.repo.UserNoticeRepository">
|
||||
<resultMap id="userNoticeMap" type="com.zsc.edu.gateway.modules.message.vo.UserNoticeVo">
|
||||
<id column="message_id" jdbcType="BIGINT" property="messageId"/>
|
||||
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
|
||||
<result column="read_time" jdbcType="TIMESTAMP" property="readTime"/>
|
||||
@ -22,7 +22,7 @@
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="userMessageAdminMap" type="com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo">
|
||||
<resultMap id="AdminNoticeMap" type="com.zsc.edu.gateway.modules.message.vo.AdminNoticeVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||
@ -35,75 +35,74 @@
|
||||
<result column="user_count" jdbcType="INTEGER" property="userCount"/>
|
||||
<result column="read_count" jdbcType="INTEGER" property="readCount"/>
|
||||
</resultMap>
|
||||
<select id="selectByMessageIdAndUserId" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo"
|
||||
resultMap="userMessageMap">
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_id
|
||||
<select id="selectByNoticeIdAndUserId" resultType="com.zsc.edu.gateway.modules.message.vo.UserNoticeVo"
|
||||
resultMap="userNoticeMap">
|
||||
select sun.*,sn.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_notice sun
|
||||
left join sys_user su on sun.user_id = su.id
|
||||
left join sys_notice sn on sn.id = sun.notice_id
|
||||
<where>
|
||||
sum.message_id=#{messageId}
|
||||
and sum.user_id=#{userId}
|
||||
sun.notice_id=#{noticeId}
|
||||
and sun.user_id=#{userId}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="page" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_message sum
|
||||
left join sys_user su on sum.user_id = su.id
|
||||
left join sys_message sm on sm.id = sum.message_id
|
||||
<select id="page" resultType="com.zsc.edu.gateway.modules.message.vo.UserNoticeVo" resultMap="userNoticeMap">
|
||||
select sun.*,sn.*,su.username,su.address,su.avatar,su.name
|
||||
from sys_user_notice sun
|
||||
left join sys_user su on sun.user_id = su.id
|
||||
left join sys_notice sn on sn.id = sun.notice_id
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
AND sun.user_id = #{query.userId}
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sm.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
AND sn.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null">
|
||||
AND sm.type = #{query.type}
|
||||
AND sn.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.name != null and query.name != ''">
|
||||
AND su.username LIKE CONCAT('%', #{query.name}, '%')
|
||||
</if>
|
||||
<if test="query.system != null">
|
||||
AND sm.system = #{query.system}
|
||||
AND sn.system = #{query.system}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND sum.is_read = #{query.isRead}
|
||||
AND sun.is_read = #{query.isRead}
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
AND sn.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY
|
||||
sm.create_time DESC
|
||||
sn.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="pageAdmin" resultMap="userMessageAdminMap">
|
||||
<select id="pageAdmin" resultMap="userNoticeMap">
|
||||
SELECT
|
||||
sm.*, -- 获取消息详情
|
||||
COUNT(DISTINCT sum.user_id) AS user_count, -- 统计用户的关联数量
|
||||
SUM(CASE WHEN sum.is_read = true THEN 1 ELSE 0 END) AS read_count -- 统计已读数量
|
||||
sn.*, -- 获取消息详情
|
||||
COUNT(DISTINCT sun.user_id) AS user_count, -- 统计用户的关联数量
|
||||
SUM(CASE WHEN sun.is_read = true THEN 1 ELSE 0 END) AS read_count -- 统计已读数量
|
||||
FROM
|
||||
sys_user_message sum
|
||||
sys_user_notice sun
|
||||
LEFT JOIN
|
||||
sys_user su ON sum.user_id = su.id
|
||||
sys_user su ON sun.user_id = su.id
|
||||
LEFT JOIN
|
||||
sys_message sm ON sm.id = sum.message_id
|
||||
sys_notice sn ON sn.id = sun.notice_id
|
||||
GROUP BY
|
||||
sm.id
|
||||
sn.id
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
AND sun.user_id = #{query.userId}
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sm.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
AND sn.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
AND sn.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
@ -1,6 +1,6 @@
|
||||
package com.zsc.edu.gateway;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.message.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.zsc.edu.gateway.domain.notice;
|
||||
package com.zsc.edu.gateway.domain.message;
|
||||
|
||||
import com.zsc.edu.gateway.domain.system.BaseEntityBuilder;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
|
||||
public class BulletinBuilder extends BaseEntityBuilder {
|
||||
private String title;
|
@ -0,0 +1,37 @@
|
||||
package com.zsc.edu.gateway.domain.message;
|
||||
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
|
||||
public class NoticeBuilder {
|
||||
public NoticeType type;
|
||||
public String title;
|
||||
public String content;
|
||||
|
||||
public static NoticeBuilder bMessage() {
|
||||
return new NoticeBuilder();
|
||||
}
|
||||
|
||||
public NoticeBuilder type(NoticeType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoticeBuilder title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoticeBuilder content(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notice build() {
|
||||
Notice notice = new Notice();
|
||||
notice.setTitle(title);
|
||||
notice.setContent(content);
|
||||
notice.type = NoticeType.other;
|
||||
return notice;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.zsc.edu.gateway.domain.message;
|
||||
|
||||
|
||||
import com.zsc.edu.gateway.modules.message.entity.UserNotice;
|
||||
|
||||
public class UserNoticeBuilder {
|
||||
public Long userId;
|
||||
public Long noticeId;
|
||||
public Boolean isRead;
|
||||
|
||||
public static UserNoticeBuilder builder() {
|
||||
return new UserNoticeBuilder();
|
||||
}
|
||||
|
||||
public UserNoticeBuilder setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserNoticeBuilder setNoticeId(Long noticeId) {
|
||||
this.noticeId = noticeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserNoticeBuilder setIsRead(Boolean isRead) {
|
||||
this.isRead = isRead;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserNotice build() {
|
||||
UserNotice userNotice = new UserNotice();
|
||||
userNotice.setUserId(userId);
|
||||
userNotice.setNoticeId(noticeId);
|
||||
userNotice.setIsRead(isRead);
|
||||
return userNotice;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.zsc.edu.gateway.domain.notice;
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MessageBuilder {
|
||||
public MessageType type;
|
||||
public String title;
|
||||
public String content;
|
||||
|
||||
public static MessageBuilder bMessage() {
|
||||
return new MessageBuilder();
|
||||
}
|
||||
|
||||
public MessageBuilder type(MessageType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageBuilder title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageBuilder content(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message build() {
|
||||
Message message = new Message();
|
||||
message.setTitle(title);
|
||||
message.setContent(content);
|
||||
message.type = MessageType.other;
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.zsc.edu.gateway.domain.notice;
|
||||
|
||||
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
|
||||
public class UserMessageBuilder {
|
||||
public Long userId;
|
||||
public Long messageId;
|
||||
public Boolean isRead;
|
||||
|
||||
public static UserMessageBuilder builder() {
|
||||
return new UserMessageBuilder();
|
||||
}
|
||||
|
||||
public UserMessageBuilder setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserMessageBuilder setMessageId(Long messageId) {
|
||||
this.messageId = messageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserMessageBuilder setIsRead(Boolean isRead) {
|
||||
this.isRead = isRead;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserMessage build() {
|
||||
UserMessage userMessage = new UserMessage();
|
||||
userMessage.setUserId(userId);
|
||||
userMessage.setMessageId(messageId);
|
||||
userMessage.setIsRead(isRead);
|
||||
return userMessage;
|
||||
}
|
||||
}
|
@ -31,7 +31,8 @@ class MenuServiceImplTest {
|
||||
Menu system = new Menu(null, Menu.Type.PAGE, "System", "/system", "menu.system", "icon-computer", true, false, 2, "system", "");
|
||||
Menu user = new Menu(null, Menu.Type.PAGE, "User", "/user", "menu.user", "icon-user", true, false, 3, "user", "");
|
||||
Menu message = new Menu(null, Menu.Type.PAGE, "Message", "/message", "消息管理", "icon-message", true, false, 4, "message", "");
|
||||
menuService.saveBatch(List.of(dashboard, system, user, message));
|
||||
Menu iot = new Menu(null, Menu.Type.PAGE, "Iot", "/iot", "物联网管理", "icon-iot", true, false, 5, "iot", "");
|
||||
menuService.saveBatch(List.of(dashboard, system, user, message, iot));
|
||||
Menu workplace = new Menu(dashboard.getId(), Menu.Type.PAGE, "Workplace", "workplace", "工作台", "icon-dashboard", true, false, 1, "dashboard:workplace", "");
|
||||
Menu role = new Menu(system.getId(), Menu.Type.PAGE, "Role", "role", "角色管理", null, true, false, 1, "system:role", "");
|
||||
Menu dept = new Menu(system.getId(), Menu.Type.PAGE, "Dept", "dept", "部门管理", null, true, false, 2, "system:dept", "");
|
||||
@ -40,7 +41,10 @@ class MenuServiceImplTest {
|
||||
Menu menu = new Menu(system.getId(), Menu.Type.PAGE, "Menu", "menu", "菜单管理", null, true, false, 5, "system:menu", "");
|
||||
Menu notice = new Menu(message.getId(), Menu.Type.PAGE, "Notice", "notice", "通知管理", null, true, false, 1, "message:notice", "");
|
||||
Menu bulletin = new Menu(message.getId(), Menu.Type.PAGE, "Bulletin", "bulletin", "公告管理", null, true, false, 2, "message:bulletin", "");
|
||||
menuService.saveBatch(List.of(workplace, dept, users, authority, menu, notice, bulletin));
|
||||
Menu device = new Menu(iot.getId(), Menu.Type.PAGE, "Device", "device", "设备管理", null, true, false, 1, "iot:device", "");
|
||||
Menu product = new Menu(iot.getId(), Menu.Type.PAGE, "Product", "product", "产品管理", null, true, false, 2, "iot:product", "");
|
||||
Menu tsl = new Menu(product.getId(), Menu.Type.PAGE, "Tsl", "tsl", "物模型管理", null, true, true, 3, "iot:tsl", "");
|
||||
menuService.saveBatch(List.of(workplace, dept, users, authority, menu, notice, bulletin, device, product, tsl));
|
||||
Menu roleCreate = new Menu(role.getId(), Menu.Type.OPERATION, "roleCreate", null, "角色新增", null, true, false, 1, "system:role:create", "");
|
||||
Menu roleDelete = new Menu(role.getId(), Menu.Type.OPERATION, "roleDelete", null, "角色删除", null, true, false, 1, "system:role:delete", "");
|
||||
Menu roleUpdate = new Menu(role.getId(), Menu.Type.OPERATION, "roleUpdate", null, "角色修改", null, true, false, 1, "system:role:update", "");
|
||||
@ -57,7 +61,46 @@ class MenuServiceImplTest {
|
||||
Menu menuUpdate = new Menu(menu.getId(), Menu.Type.OPERATION, "menuUpdate", null, "菜单修改", null, true, false, 1, "system:menu:update", "");
|
||||
Menu menuQuery = new Menu(menu.getId(), Menu.Type.OPERATION, "menuQuery", null, "菜单查询", null, true, false, 1, "system:menu:query", "");
|
||||
Menu menuDelete = new Menu(menu.getId(), Menu.Type.OPERATION, "menuDelete", null, "菜单删除", null, true, false, 1, "system:menu:delete", "");
|
||||
menuService.saveBatch(List.of(roleCreate, roleDelete, roleUpdate, roleQuery, deptSave, deptUpdate, deptQuery, deptDelete, userSave, userUpdate, userQuery, userDelete, menuSave, menuUpdate, menuQuery, menuDelete));
|
||||
Menu noticeCreate = new Menu(notice.getId(), Menu.Type.OPERATION, "noticeCreate", null, "通知新增", null, true, false, 1, "message:notice:create", "");
|
||||
Menu noticeUpdate = new Menu(notice.getId(), Menu.Type.OPERATION, "noticeUpdate", null, "通知修改", null, true, false, 1, "message:notice:update", "");
|
||||
Menu noticeQuery = new Menu(notice.getId(), Menu.Type.OPERATION, "noticeQuery", null, "通知查询", null, true, false, 1, "message:notice:query", "");
|
||||
Menu noticeDelete = new Menu(notice.getId(), Menu.Type.OPERATION, "noticeDelete", null, "通知删除", null, true, false, 1, "message:notice:delete", "");
|
||||
Menu bulletinCreate = new Menu(bulletin.getId(), Menu.Type.OPERATION, "bulletinCreate", null, "公告新增", null, true, false, 1, "message:bulletin:create", "");
|
||||
Menu bulletinUpdate = new Menu(bulletin.getId(), Menu.Type.OPERATION, "bulletinUpdate", null, "公告修改", null, true, false, 1, "message:bulletin:update", "");
|
||||
Menu bulletinQuery = new Menu(bulletin.getId(), Menu.Type.OPERATION, "bulletinQuery", null, "公告查询", null, true, false, 1, "message:bulletin:query", "");
|
||||
Menu bulletinDelete = new Menu(bulletin.getId(), Menu.Type.OPERATION, "bulletinDelete", null, "公告删除", null, true, false, 1, "message:bulletin:delete", "");
|
||||
Menu deviceQuery = new Menu(device.getId(), Menu.Type.OPERATION, "deviceQuery", null, "设备查询", null, true, false, 1, "iot:device:query", "");
|
||||
Menu deviceCreate = new Menu(device.getId(), Menu.Type.OPERATION, "deviceCreate", null, "设备新增", null, true, false, 1, "iot:device:create", "");
|
||||
Menu deviceUpdate = new Menu(device.getId(), Menu.Type.OPERATION, "deviceUpdate", null, "设备修改", null, true, false, 1, "iot:device:update", "");
|
||||
Menu deviceDelete = new Menu(device.getId(), Menu.Type.OPERATION, "deviceDelete", null, "设备删除", null, true, false, 1, "iot:device:delete", "");
|
||||
Menu productQuery = new Menu(product.getId(), Menu.Type.OPERATION, "productQuery", null, "产品查询", null, true, false, 1, "iot:product:query", "");
|
||||
Menu productCreate = new Menu(product.getId(), Menu.Type.OPERATION, "productCreate", null, "产品新增", null, true, false, 1, "iot:product:create", "");
|
||||
Menu productUpdate = new Menu(product.getId(), Menu.Type.OPERATION, "productUpdate", null, "产品修改", null, true, false, 1, "iot:product:update", "");
|
||||
Menu productDelete = new Menu(product.getId(), Menu.Type.OPERATION, "productDelete", null, "产品删除", null, true, false, 1, "iot:product:delete", "");
|
||||
Menu eventQuery = new Menu(tsl.getId(), Menu.Type.OPERATION, "eventQuery", null, "事件查询", null, true, false, 1, "iot:event:query", "");
|
||||
Menu eventCreate = new Menu(tsl.getId(), Menu.Type.OPERATION, "eventCreate", null, "事件新增", null, true, false, 1, "iot:event:create", "");
|
||||
Menu eventUpdate = new Menu(tsl.getId(), Menu.Type.OPERATION, "eventUpdate", null, "事件修改", null, true, false, 1, "iot:event:update", "");
|
||||
Menu eventDelete = new Menu(tsl.getId(), Menu.Type.OPERATION, "eventDelete", null, "事件删除", null, true, false, 1, "iot:event:delete", "");
|
||||
Menu propertyQuery = new Menu(tsl.getId(), Menu.Type.OPERATION, "propertyQuery", null, "属性查询", null, true, false, 1, "iot:property:query", "");
|
||||
Menu propertyCreate = new Menu(tsl.getId(), Menu.Type.OPERATION, "propertyCreate", null, "属性新增", null, true, false, 1, "iot:property:create", "");
|
||||
Menu propertyUpdate = new Menu(tsl.getId(), Menu.Type.OPERATION, "propertyUpdate", null, "属性修改", null, true, false, 1, "iot:property:update", "");
|
||||
Menu propertyDelete = new Menu(tsl.getId(), Menu.Type.OPERATION, "propertyDelete", null, "属性删除", null, true, false, 1, "iot:property:delete", "");
|
||||
Menu serverQuery = new Menu(tsl.getId(), Menu.Type.OPERATION, "serverQuery", null, "服务查询", null, true, false, 1, "iot:server:query", "");
|
||||
Menu serverCreate = new Menu(tsl.getId(), Menu.Type.OPERATION, "serverCreate", null, "服务新增", null, true, false, 1, "iot:server:create", "");
|
||||
Menu serverUpdate = new Menu(tsl.getId(), Menu.Type.OPERATION, "serverUpdate", null, "服务修改", null, true, false, 1, "iot:server:update", "");
|
||||
Menu serverDelete = new Menu(tsl.getId(), Menu.Type.OPERATION, "serverDelete", null, "服务删除", null, true, false, 1, "iot:server:delete", "");
|
||||
menuService.saveBatch(List.of(roleCreate, roleDelete, roleUpdate, roleQuery,
|
||||
deptSave, deptUpdate, deptQuery, deptDelete,
|
||||
userSave, userUpdate, userQuery, userDelete,
|
||||
menuSave, menuUpdate, menuQuery, menuDelete,
|
||||
noticeCreate, noticeUpdate, noticeQuery, noticeDelete,
|
||||
bulletinCreate, bulletinUpdate, bulletinQuery, bulletinDelete,
|
||||
deviceQuery, deviceCreate, deviceUpdate, deviceDelete,
|
||||
productQuery, productCreate, productUpdate, productDelete,
|
||||
eventQuery, eventCreate, eventUpdate, eventDelete,
|
||||
propertyQuery, propertyCreate, propertyUpdate, propertyDelete,
|
||||
serverQuery, serverCreate, serverUpdate, serverDelete
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.zsc.edu.gateway.rest.notice;
|
||||
package com.zsc.edu.gateway.rest.message;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.MockMvcConfigBase;
|
||||
import com.zsc.edu.gateway.domain.notice.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.domain.message.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.controller.BulletinController;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.message.controller.BulletinController;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.service.BulletinService;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
@ -1,14 +1,14 @@
|
||||
package com.zsc.edu.gateway.rest.notice;
|
||||
package com.zsc.edu.gateway.rest.message;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.MockMvcConfigBase;
|
||||
import com.zsc.edu.gateway.domain.notice.UserMessageBuilder;
|
||||
import com.zsc.edu.gateway.modules.notice.controller.UserMessageController;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.UserMessage;
|
||||
import com.zsc.edu.gateway.modules.notice.query.AdminMessageQuery;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import com.zsc.edu.gateway.domain.message.UserNoticeBuilder;
|
||||
import com.zsc.edu.gateway.modules.message.controller.UserNoticeController;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import com.zsc.edu.gateway.modules.message.entity.UserNotice;
|
||||
import com.zsc.edu.gateway.modules.message.query.AdminNoticeQuery;
|
||||
import com.zsc.edu.gateway.modules.message.service.UserNoticeService;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -29,42 +29,42 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(UserMessageController.class)
|
||||
public class UserMessageControllerTest extends MockMvcConfigBase {
|
||||
@WebMvcTest(UserNoticeController.class)
|
||||
public class UserNoticeControllerTest extends MockMvcConfigBase {
|
||||
@Spy
|
||||
private static UserMessage userMessage1;
|
||||
private static UserMessage userMessage2;
|
||||
private static UserNotice userNotice1;
|
||||
private static UserNotice userNotice2;
|
||||
@MockBean
|
||||
private UserMessageService service;
|
||||
private UserNoticeService service;
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
userMessage1 = UserMessageBuilder.builder().setMessageId(1L).setUserId(1L).setIsRead(true).build();
|
||||
userMessage2 = UserMessageBuilder.builder().setMessageId(1L).setUserId(1L).setIsRead(false).build();
|
||||
userNotice1 = UserNoticeBuilder.builder().setNoticeId(1L).setUserId(1L).setIsRead(true).build();
|
||||
userNotice2 = UserNoticeBuilder.builder().setNoticeId(1L).setUserId(1L).setIsRead(false).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() throws Exception {
|
||||
List<UserMessage> userMessages = Lists.newArrayList(userMessage1, userMessage2);
|
||||
Page<UserMessage> pageResult = new Page<>();
|
||||
pageResult.setRecords(userMessages);
|
||||
pageResult.setTotal((long) userMessages.size());
|
||||
when(service.getAdminMessagePage(any(Page.class), any(AdminMessageQuery.class))).thenReturn(pageResult);
|
||||
List<UserNotice> userNotices = Lists.newArrayList(userNotice1, userNotice2);
|
||||
Page<UserNotice> pageResult = new Page<>();
|
||||
pageResult.setRecords(userNotices);
|
||||
pageResult.setTotal((long) userNotices.size());
|
||||
when(service.getAdminNoticePage(any(Page.class), any(AdminNoticeQuery.class))).thenReturn(pageResult);
|
||||
mockMvc.perform(get("/api/rest/message")
|
||||
.with(user(userDetails))
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andDo(print());
|
||||
verify(service).getAdminMessagePage(any(Page.class), any(AdminMessageQuery.class));
|
||||
verify(service).getAdminNoticePage(any(Page.class), any(AdminNoticeQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create() throws Exception {
|
||||
UserMessageDto dto = new UserMessageDto();
|
||||
UserNoticeDto dto = new UserNoticeDto();
|
||||
dto.setTitle("测试创建消息");
|
||||
dto.setContent("测试创建消息");
|
||||
dto.setType(MessageType.other);
|
||||
when(service.createByAdmin(any(UserMessageDto.class))).thenReturn(true);
|
||||
dto.setType(NoticeType.other);
|
||||
when(service.createByAdmin(any(UserNoticeDto.class))).thenReturn(true);
|
||||
mockMvc.perform(post("/api/rest/message")
|
||||
.with(csrf().asHeader())
|
||||
.with(user(userDetails))
|
||||
@ -73,6 +73,6 @@ public class UserMessageControllerTest extends MockMvcConfigBase {
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andDo(print());
|
||||
verify(service).createByAdmin(any(UserMessageDto.class));
|
||||
verify(service).createByAdmin(any(UserNoticeDto.class));
|
||||
}
|
||||
}
|
@ -2,20 +2,19 @@ package com.zsc.edu.gateway.service.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.gateway.domain.notice.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.domain.message.BulletinBuilder;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.BulletinService;
|
||||
import com.zsc.edu.gateway.modules.message.dto.BulletinDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Bulletin;
|
||||
import com.zsc.edu.gateway.modules.message.repo.BulletinRepository;
|
||||
import com.zsc.edu.gateway.modules.message.service.BulletinService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -1,67 +0,0 @@
|
||||
package com.zsc.edu.gateway.service.notice;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.gateway.domain.notice.MessageBuilder;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.MessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
public class MessageServiceTest {
|
||||
@Autowired
|
||||
public MessageRepository messageRepository;
|
||||
@Autowired
|
||||
public UserMessageRepository userMessageRepository;
|
||||
@Autowired
|
||||
public UserMessageService service;
|
||||
|
||||
private Message message1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
message1 = MessageBuilder.bMessage().type(MessageType.other).title("A测试消息1").build();
|
||||
messageRepository.insert(message1);
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
List<String> titlesToDelete = Arrays.asList("A测试消息1", "A测试消息3");
|
||||
messageRepository.delete(new QueryWrapper<Message>().in("title", titlesToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() {
|
||||
LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
|
||||
assertEquals(1, messageRepository.selectList(queryWrapper.like(Message::getTitle, "A测试")).size());
|
||||
assertEquals(1, messageRepository.selectList(queryWrapper.eq(Message::getTitle, message1.getTitle())).size());
|
||||
// assertEquals(2, messageRepository.selectList(null).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createMessage() {
|
||||
UserMessageDto dto = new UserMessageDto(new HashSet<>(Arrays.asList(1L, 2L)), MessageType.other, false, false, false, "A测试消息3", "测试测试");
|
||||
service.createByAdmin(dto);
|
||||
Message message = messageRepository.selectOne(new LambdaQueryWrapper<Message>().eq(Message::getTitle, dto.getTitle()));
|
||||
assertNotNull(message.getId());
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.zsc.edu.gateway.service.notice;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.gateway.domain.message.NoticeBuilder;
|
||||
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||
import com.zsc.edu.gateway.modules.message.dto.UserNoticeDto;
|
||||
import com.zsc.edu.gateway.modules.message.entity.Notice;
|
||||
import com.zsc.edu.gateway.modules.message.entity.NoticeType;
|
||||
import com.zsc.edu.gateway.modules.message.repo.NoticeRepository;
|
||||
import com.zsc.edu.gateway.modules.message.repo.UserNoticeRepository;
|
||||
import com.zsc.edu.gateway.modules.message.service.UserNoticeService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
public class NoticeServiceTest {
|
||||
@Autowired
|
||||
public NoticeRepository noticeRepository;
|
||||
@Autowired
|
||||
public UserNoticeRepository userNoticeRepository;
|
||||
@Autowired
|
||||
public UserNoticeService service;
|
||||
|
||||
private Notice notice1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||
userDetails.setUsername("admin");
|
||||
notice1 = NoticeBuilder.bMessage().type(NoticeType.other).title("A测试消息1").build();
|
||||
noticeRepository.insert(notice1);
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
List<String> titlesToDelete = Arrays.asList("A测试消息1", "A测试消息3");
|
||||
noticeRepository.delete(new QueryWrapper<Notice>().in("title", titlesToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() {
|
||||
LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<>();
|
||||
assertEquals(1, noticeRepository.selectList(queryWrapper.like(Notice::getTitle, "A测试")).size());
|
||||
assertEquals(1, noticeRepository.selectList(queryWrapper.eq(Notice::getTitle, notice1.getTitle())).size());
|
||||
// assertEquals(2, messageRepository.selectList(null).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createMessage() {
|
||||
UserNoticeDto dto = new UserNoticeDto(new HashSet<>(Arrays.asList(1L, 2L)), NoticeType.other, false, false, false, "A测试消息3", "测试测试");
|
||||
service.createByAdmin(dto);
|
||||
Notice notice = noticeRepository.selectOne(new LambdaQueryWrapper<Notice>().eq(Notice::getTitle, dto.getTitle()));
|
||||
assertNotNull(notice.getId());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user