Compare commits
No commits in common. "dbbc9e82dbbcd6b26e8fff1bbdffae8d4257cb7b" and "8d6fa0b244b9a6a110681d777a067c6fc04e25ba" have entirely different histories.
dbbc9e82db
...
8d6fa0b244
@ -1,130 +0,0 @@
|
||||
package com.zsc.edu.gateway.common.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @Description: 树操作方法工具类
|
||||
* @Copyright: Copyright (c) 赵侠客
|
||||
* @Date: 2024-07-22 10:42
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class TreeUtil {
|
||||
|
||||
/**
|
||||
* 将list合成树
|
||||
*
|
||||
* @param list 需要合成树的List
|
||||
* @param rootCheck 判断E中为根节点的条件,如:x->x.getPId()==-1L , x->x.getParentId()==null,x->x.getParentMenuId()==0
|
||||
* @param parentCheck 判断E中为父节点条件,如:(x,y)->x.getId().equals(y.getPId())
|
||||
* @param setSubChildren E中设置下级数据方法,如:Menu::setSubMenus
|
||||
* @param <E> 泛型实体对象
|
||||
* @return 合成好的树
|
||||
*/
|
||||
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||
return list.stream().filter(rootCheck).peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将树打平成tree
|
||||
*
|
||||
* @param tree 需要打平的树
|
||||
* @param getSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param setSubChildren 将下级数据置空方法,如:x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
* @return 打平后的数据
|
||||
*/
|
||||
public static <E> List<E> flat(List<E> tree, Function<E, List<E>> getSubChildren, Consumer<E> setSubChildren) {
|
||||
List<E> res = new ArrayList<>();
|
||||
forPostOrder(tree, item -> {
|
||||
setSubChildren.accept(item);
|
||||
res.add(item);
|
||||
}, getSubChildren);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forPreOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
for (E l : tree) {
|
||||
consumer.accept(l);
|
||||
List<E> es = setSubChildren.apply(l);
|
||||
if (es != null && es.size() > 0) {
|
||||
forPreOrder(es, consumer, setSubChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 层序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forLevelOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
Queue<E> queue = new LinkedList<>(tree);
|
||||
while (!queue.isEmpty()) {
|
||||
E item = queue.poll();
|
||||
consumer.accept(item);
|
||||
List<E> childList = setSubChildren.apply(item);
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
queue.addAll(childList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后序遍历
|
||||
*
|
||||
* @param tree 需要遍历的树
|
||||
* @param consumer 遍历后对单个元素的处理方法,如:x-> System.out.println(x)、 System.out::println打印元素
|
||||
* @param setSubChildren 设置下级数据方法,如:Menu::getSubMenus,x->x.setSubMenus(null)
|
||||
* @param <E> 泛型实体对象
|
||||
*/
|
||||
public static <E> void forPostOrder(List<E> tree, Consumer<E> consumer, Function<E, List<E>> setSubChildren) {
|
||||
for (E item : tree) {
|
||||
List<E> childList = setSubChildren.apply(item);
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
forPostOrder(childList, consumer, setSubChildren);
|
||||
}
|
||||
consumer.accept(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对树所有子节点按comparator排序
|
||||
*
|
||||
* @param tree 需要排序的树
|
||||
* @param comparator 排序规则Comparator,如:Comparator.comparing(MenuVo::getRank)按Rank正序 ,(x,y)->y.getRank().compareTo(x.getRank()),按Rank倒序
|
||||
* @param getChildren 获取下级数据方法,如:MenuVo::getSubMenus
|
||||
* @param <E> 泛型实体对象
|
||||
* @return 排序好的树
|
||||
*/
|
||||
public static <E> List<E> sort(List<E> tree, Comparator<? super E> comparator, Function<E, List<E>> getChildren) {
|
||||
for (E item : tree) {
|
||||
List<E> childList = getChildren.apply(item);
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
sort(childList, comparator, getChildren);
|
||||
}
|
||||
}
|
||||
tree.sort(comparator);
|
||||
return tree;
|
||||
}
|
||||
|
||||
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> children) {
|
||||
return allData.stream().filter(x -> parentCheck.apply(parent, x)).peek(x -> children.accept(x, makeChildren(x, allData, parentCheck, children))).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -65,11 +65,10 @@ public class ApiExceptionHandler {
|
||||
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
//TODO 跟全局security 冲突
|
||||
// @ExceptionHandler(value = {Exception.class})
|
||||
// public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
|
||||
// log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
|
||||
// return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
// }
|
||||
@ExceptionHandler(value = {Exception.class})
|
||||
public ResponseEntity<Object> handleException(Exception ex) throws JsonProcessingException {
|
||||
log.error("Exception: {}", objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())));
|
||||
return new ResponseEntity<>(objectMapper.writeValueAsString(Map.of("msg", ex.getMessage())), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.zsc.edu.gateway.framework;
|
||||
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
import com.zsc.edu.gateway.modules.system.vo.UserTree;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Component
|
||||
public class DeptTreeUtil {
|
||||
|
||||
public static <E> List<E> makeTree(List<E> list, Predicate<E> rootCheck, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||
return list.stream()
|
||||
.filter(rootCheck)
|
||||
.peek(x -> setSubChildren.accept(x, makeChildren(x, list, parentCheck, setSubChildren)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static <E> List<E> makeChildren(E parent, List<E> allData, BiFunction<E, E, Boolean> parentCheck, BiConsumer<E, List<E>> setSubChildren) {
|
||||
return allData.stream()
|
||||
.filter(x -> parentCheck.apply(parent, x))
|
||||
.peek(x -> setSubChildren.accept(x, makeChildren(x, allData, parentCheck, setSubChildren)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<DeptTree> buildDeptTree(List<Dept> depots, Map<Long, List<User>> userMap) {
|
||||
List<DeptTree> deptTrees = depots.stream()
|
||||
.map(DeptTreeUtil::convertToDeptTree)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
deptTrees.forEach(deptTree -> {
|
||||
List<User> users = userMap.getOrDefault(deptTree.getId(), Collections.emptyList());
|
||||
deptTree.setMembers(users.stream()
|
||||
.map(DeptTreeUtil::convertToUserTree)
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return makeTree(
|
||||
deptTrees,
|
||||
deptTree -> deptTree.getPid() == null || deptTree.getPid() == 0L,
|
||||
(parent, child) -> parent.getId().equals(child.getPid()),
|
||||
DeptTree::setChildren
|
||||
);
|
||||
}
|
||||
|
||||
private static DeptTree convertToDeptTree(Dept dept) {
|
||||
DeptTree deptTree = new DeptTree();
|
||||
deptTree.setId(dept.getId());
|
||||
deptTree.setPid(dept.getPid());
|
||||
deptTree.setName(dept.getName());
|
||||
return deptTree;
|
||||
}
|
||||
|
||||
private static UserTree convertToUserTree(User user) {
|
||||
UserTree userTree = new UserTree();
|
||||
userTree.setId(user.getId());
|
||||
userTree.setName(user.getName());
|
||||
return userTree;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.zsc.edu.gateway.framework;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author harry yao
|
||||
*/
|
||||
public class JsonExceptionUtil {
|
||||
public static Map<String, Object> jsonExceptionResult(HttpStatus code, String message, String path) {
|
||||
Map<String, Object> exceptionMap = new LinkedHashMap<>();
|
||||
exceptionMap.put("timestamp", Calendar.getInstance().getTime());
|
||||
exceptionMap.put("message", message);
|
||||
exceptionMap.put("path", path);
|
||||
exceptionMap.put("code", code.value());
|
||||
return exceptionMap;
|
||||
}
|
||||
}
|
@ -95,11 +95,11 @@ public class EmailSender {
|
||||
} else {
|
||||
helper.setText(message.content);
|
||||
}
|
||||
// if (Objects.nonNull(message.attachments)) {
|
||||
// for (Attachment attachment : message.attachments) {
|
||||
// helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
||||
// }
|
||||
// }
|
||||
if (Objects.nonNull(message.attachments)) {
|
||||
for (Attachment attachment : message.attachments) {
|
||||
helper.addAttachment(attachment.fileName, attachmentService.loadAsResource(attachment.id), attachment.mimeType);
|
||||
}
|
||||
}
|
||||
sender.send(mimeMessage);
|
||||
} catch (MessagingException | IOException | TemplateException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -8,7 +8,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.ProviderManager;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.core.session.SessionRegistry;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@ -24,8 +23,6 @@ import javax.sql.DataSource;
|
||||
* @author harry_yao
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@EnableMethodSecurity
|
||||
//TODO 加入全局注解会报错
|
||||
@Configuration
|
||||
public class SpringSecurityConfig {
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:29/1/2024 上午9:55
|
||||
* 描述: TODO
|
||||
*/
|
||||
public interface AttachmentRepository extends BaseMapper<Attachment>{
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentVo {
|
||||
public Long attachmentId;
|
||||
public String fileName;
|
||||
public String url;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class BulletinController {
|
||||
* @return 公告
|
||||
*/
|
||||
@GetMapping("/self/{id}")
|
||||
public BulletinVo selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
public List<BulletinVo> selfDetail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.detail(userDetails,id, Bulletin.State.publish);
|
||||
}
|
||||
|
||||
@ -45,9 +45,10 @@ public class BulletinController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<BulletinVo> getBulletins(Page<BulletinVo> pageParam, BulletinQuery query) {
|
||||
public IPage<BulletinVo> getBulletins( BulletinQuery query) {
|
||||
query.setState(Bulletin.State.publish);
|
||||
return service.selectPageByConditions(pageParam, query);
|
||||
Page<BulletinVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.selectPageByConditions(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +59,7 @@ public class BulletinController {
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('BULLETIN_QUERY')")
|
||||
public BulletinVo detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
public List<BulletinVo> detail(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable("id") Long id) {
|
||||
return service.detail(userDetails,id, null);
|
||||
}
|
||||
|
||||
@ -152,4 +153,12 @@ public class BulletinController {
|
||||
return service.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*为公告添加附件
|
||||
*/
|
||||
@PostMapping("/{id}/add")
|
||||
@PreAuthorize("hasAuthority('BULLETIN_CREATE')")
|
||||
public Boolean insertInto(@PathVariable Long id,@RequestBody Set<String> attachments){
|
||||
return service.insertInto(id, attachments);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ 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.entity.MessageSetting;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -48,10 +47,11 @@ public class UserMessageController {
|
||||
* @return 分页数据
|
||||
*/
|
||||
@GetMapping("/self")
|
||||
public IPage<UserMessageVo> selfPage(Page<UserMessageVo> pageParam, @AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||
public IPage<UserMessageVo> selfPage(@AuthenticationPrincipal UserDetailsImpl userDetails, UserMessageQuery query) {
|
||||
query.userId = userDetails.id;
|
||||
query.name = null;
|
||||
return service.page(pageParam, query);
|
||||
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,13 +80,14 @@ public class UserMessageController {
|
||||
/**
|
||||
* 管理查询消息详情
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param messageId 消息ID
|
||||
* @return 用户消息详情
|
||||
*/
|
||||
@GetMapping("/{userId}/{messageId}")
|
||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public UserMessageVo detail(@PathVariable("userId") Long userId, @PathVariable("messageId") Long messageId) {
|
||||
return service.detail(userId, messageId);
|
||||
return service.detail(messageId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,8 +98,9 @@ public class UserMessageController {
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('MESSAGE_QUERY')")
|
||||
public IPage<AdminMessageVo> page(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
return service.getAdminMessagePage(page, query);
|
||||
public IPage<UserMessageVo> page(UserMessageQuery query) {
|
||||
Page<UserMessageVo> page = new Page<>(query.getPageNum(), query.getPageSize());
|
||||
return service.page(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,4 +114,41 @@ public class UserMessageController {
|
||||
public Boolean create(@RequestBody UserMessageDto dto) {
|
||||
return service.createByAdmin(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员为消息添加附件
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @param attachmentIds 附件ID集合
|
||||
* @return 消息列表
|
||||
*/
|
||||
@PostMapping("/attachment/{messageId}")
|
||||
@PreAuthorize("hasAuthority('MESSAGE_CREATE')")
|
||||
public Boolean insertInto(@PathVariable("messageId") Long messageId, @RequestBody List<String> attachmentIds) {
|
||||
return service.insertInto(messageId, attachmentIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息推送方式
|
||||
*
|
||||
* @return 消息推送方式列表
|
||||
*/
|
||||
@GetMapping("/setting")
|
||||
@PreAuthorize("hasAuthority('MESSAGE_SETTING')")
|
||||
public List<MessageSetting> getSetting() {
|
||||
return service.getSetting();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置消息推送方式
|
||||
*
|
||||
* @param settings 表单数据
|
||||
* @return 消息设置
|
||||
*/
|
||||
@PatchMapping("/setting")
|
||||
@PreAuthorize("hasAuthority('MESSAGE_SETTING')")
|
||||
public List<MessageSetting> saveSetting(@RequestBody List<MessageSetting> settings) {
|
||||
return service.saveSetting(settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class BulletinDto {
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
public Boolean top;
|
||||
public boolean top;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
@ -36,9 +36,9 @@ public class BulletinDto {
|
||||
* 备注
|
||||
*/
|
||||
public String remark;
|
||||
|
||||
/**
|
||||
* 附件ID集合
|
||||
*/
|
||||
private List<String> attachmentIds;
|
||||
//
|
||||
// /**
|
||||
// * 附件ID集合
|
||||
// */
|
||||
// private List<String> attachmentIds;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class Message extends BaseEntity {
|
||||
/**
|
||||
* 是否系统生成
|
||||
*/
|
||||
public Boolean system = false;
|
||||
public Boolean system;
|
||||
|
||||
/**
|
||||
* 是否需要发送邮件
|
||||
@ -57,4 +57,9 @@ public class Message extends BaseEntity {
|
||||
*/
|
||||
public String content;
|
||||
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
public List<Attachment> attachments;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.zsc.edu.gateway.modules.notice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* 消息设置
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_message_setting")
|
||||
public class MessageSetting {
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
@TableId
|
||||
public Long id;
|
||||
|
||||
/**
|
||||
* 是否发送邮件
|
||||
*/
|
||||
public Boolean email;
|
||||
|
||||
/**
|
||||
* 是否发送短信
|
||||
*/
|
||||
public Boolean sms;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MessageSetting that = (MessageSetting) o;
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.zsc.edu.gateway.modules.notice.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 org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface BulletinAttachmentMapper extends BaseMapper<BulletinAttachmentDto, BulletinAttachment> {
|
||||
|
||||
}
|
@ -57,13 +57,16 @@ public class UserMessageQuery {
|
||||
/**
|
||||
* 消息创建时间区间起始
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
public LocalDateTime createAtBegin;
|
||||
|
||||
/**
|
||||
* 消息创建时间区间终止
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
public LocalDateTime createAtEnd;
|
||||
|
||||
private Integer pageNum = 1;
|
||||
private Integer pageSize = 10;
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||
public interface BulletinRepository extends BaseMapper<Bulletin> {
|
||||
|
||||
|
||||
BulletinVo selectByBulletinId(@Param("bulletinId") Long bulletinId);
|
||||
List<BulletinVo> selectByBulletinId(@Param("bulletinId") Long bulletinId);
|
||||
|
||||
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, @Param("query") BulletinQuery query);
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.notice.repo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息设置Repo
|
||||
*
|
||||
* @author harry_yao
|
||||
*/
|
||||
public interface MessageSettingRepository extends BaseMapper<MessageSetting> {
|
||||
@Select("select * from sys_message_setting")
|
||||
List<MessageSetting> findAll();
|
||||
}
|
@ -4,9 +4,9 @@ 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.BulletinQuery;
|
||||
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.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -19,7 +19,5 @@ 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);
|
||||
IPage<UserMessageVo> query(Page<UserMessageVo> page, @Param("query") UserMessageQuery query);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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.dto.PageDto;
|
||||
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;
|
||||
@ -20,7 +21,7 @@ import java.util.Set;
|
||||
|
||||
public interface BulletinService extends IService<Bulletin> {
|
||||
|
||||
BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state);
|
||||
List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state);
|
||||
|
||||
Bulletin create(UserDetailsImpl userDetails, BulletinDto dto);
|
||||
|
||||
@ -32,5 +33,7 @@ public interface BulletinService extends IService<Bulletin> {
|
||||
|
||||
Boolean close(UserDetailsImpl userDetails,Long id);
|
||||
|
||||
Boolean insertInto(Long bulletinId, Set<String> attachmentIds);
|
||||
|
||||
IPage<BulletinVo> selectPageByConditions(Page<BulletinVo> page, BulletinQuery query);
|
||||
}
|
||||
|
@ -5,13 +5,18 @@ 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.MessagePayload;
|
||||
import com.zsc.edu.gateway.modules.notice.entity.MessageSetting;
|
||||
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.BulletinQuery;
|
||||
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.BulletinVo;
|
||||
import com.zsc.edu.gateway.modules.notice.vo.UserMessageVo;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户消息Service
|
||||
@ -24,12 +29,17 @@ public interface UserMessageService extends IService<UserMessage> {
|
||||
|
||||
UserMessageVo detail(Long messageId, Long userId);
|
||||
|
||||
Boolean insertInto(Long messageId, List<String> attachmentIds);
|
||||
|
||||
List<MessageSetting> getSetting();
|
||||
|
||||
IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query);
|
||||
|
||||
Integer countUnread(UserDetailsImpl userDetails);
|
||||
|
||||
Integer markAsRead(UserDetailsImpl userDetails, List<Long> messageIds);
|
||||
|
||||
@Transactional
|
||||
List<MessageSetting> saveSetting(List<MessageSetting> settings);
|
||||
|
||||
IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query);
|
||||
}
|
||||
|
@ -47,29 +47,21 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
* @return 公告详情
|
||||
*/
|
||||
@Override
|
||||
public BulletinVo detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
|
||||
// List<BulletinVo> bulletins = repo.selectByBulletinId(id);
|
||||
// if (bulletins.isEmpty()) {
|
||||
// return Collections.emptyList();
|
||||
// }
|
||||
// for (BulletinVo bulletin : bulletins) {
|
||||
// if (state != null) {
|
||||
// bulletin.getState().checkStatus(state);
|
||||
// }
|
||||
// bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
|
||||
// bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
|
||||
// bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
|
||||
// }
|
||||
//
|
||||
// return bulletins;
|
||||
BulletinVo bulletinVo = repo.selectByBulletinId(id);
|
||||
if (state != null) {
|
||||
bulletinVo.getState().checkStatus(state);
|
||||
public List<BulletinVo> detail(UserDetailsImpl userDetails, Long id, Bulletin.State state) {
|
||||
List<BulletinVo> bulletins = repo.selectByBulletinId(id);
|
||||
if (bulletins.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
bulletinVo.setEditUsername(userRepository.selectNameById(bulletinVo.getEditUserId()));
|
||||
bulletinVo.setPublishUsername(userRepository.selectNameById(bulletinVo.getPublishUserId()));
|
||||
bulletinVo.setCloseUsername(userRepository.selectNameById(bulletinVo.getCloseUserId()));
|
||||
return bulletinVo;
|
||||
for (BulletinVo bulletin : bulletins) {
|
||||
if (state != null) {
|
||||
bulletin.getState().checkStatus(state);
|
||||
}
|
||||
bulletin.setEditUsername(userRepository.selectNameById(bulletin.getEditUserId()));
|
||||
bulletin.setPublishUsername(userRepository.selectNameById(bulletin.getPublishUserId()));
|
||||
bulletin.setCloseUsername(userRepository.selectNameById(bulletin.getCloseUserId()));
|
||||
}
|
||||
|
||||
return bulletins;
|
||||
}
|
||||
/**
|
||||
* 新建公告
|
||||
@ -90,9 +82,6 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
bulletin.setCreateBy(userDetails.getName());
|
||||
bulletin.setEditUserId(userDetails.getId());
|
||||
save(bulletin);
|
||||
if (dto.getAttachmentIds() != null) {
|
||||
insertInto(bulletin.getId(), dto.getAttachmentIds());
|
||||
}
|
||||
return bulletin;
|
||||
}
|
||||
/**
|
||||
@ -194,13 +183,15 @@ public class BulletinServiceImpl extends ServiceImpl<BulletinRepository, Bulleti
|
||||
* @param attachmentIds attachments
|
||||
* @return true
|
||||
*/
|
||||
public Boolean insertInto(Long bulletinId, List<String> attachmentIds) {
|
||||
@Override
|
||||
public Boolean insertInto(Long bulletinId, Set<String> attachmentIds) {
|
||||
List<BulletinAttachment> bulletinAttachments = attachmentIds.stream()
|
||||
.map(attachmentId -> new BulletinAttachment(bulletinId, attachmentId))
|
||||
.collect(Collectors.toList());
|
||||
return bulletinAttachmentService.saveBatch(bulletinAttachments);
|
||||
}
|
||||
|
||||
|
||||
private List<Bulletin> getBulletinsByIds(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.zsc.edu.gateway.modules.notice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -10,19 +9,18 @@ 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.attachment.service.AttachmentService;
|
||||
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.MessageSettingRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
|
||||
import com.zsc.edu.gateway.modules.notice.service.MessageAttachmentService;
|
||||
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.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import com.zsc.edu.gateway.modules.system.service.UserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -44,12 +42,13 @@ import java.util.stream.Collectors;
|
||||
public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, UserMessage> implements UserMessageService {
|
||||
|
||||
private final MessageRepository messageRepo;
|
||||
private final MessageSettingRepository messageSettingRepo;
|
||||
private final UserService userService;
|
||||
private final EmailSender emailSender;
|
||||
private final SmsSender smsSender;
|
||||
private final UserMessageRepository userMessageRepository;
|
||||
private final MessageAttachmentService messageAttachmentService;
|
||||
private final UserRepository userRepository;
|
||||
private final MessageMapper messageMapper;
|
||||
|
||||
/**
|
||||
* 查询消息详情
|
||||
*
|
||||
@ -64,7 +63,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
UserMessage userMessage = new UserMessage();
|
||||
userMessage.setUserId(userId);
|
||||
userMessage.setMessageId(messageId);
|
||||
userMessage.setIsRead(true);
|
||||
userMessage.setIsRead(false);
|
||||
userMessage.setReadTime(LocalDateTime.now());
|
||||
save(userMessage);
|
||||
}
|
||||
@ -80,7 +79,7 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
*/
|
||||
@Override
|
||||
public IPage<UserMessageVo> page(Page<UserMessageVo> page, UserMessageQuery query) {
|
||||
return userMessageRepository.page(page, query);
|
||||
return userMessageRepository.query(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,23 +109,12 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
}
|
||||
UpdateWrapper<UserMessage> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("user_id", userDetails.getId()).in("message_id", messageIds);
|
||||
updateWrapper.set("is_read", true);
|
||||
updateWrapper.set("is_read", false);
|
||||
updateWrapper.set("read_time", LocalDateTime.now());
|
||||
return userMessageRepository.update(updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员查询消息列表
|
||||
*
|
||||
* @return 消息设置列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<AdminMessageVo> getAdminMessagePage(Page<UserMessageVo> page, AdminMessageQuery query) {
|
||||
return userMessageRepository.pageAdmin(page, query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员手动创建用户消息并发送
|
||||
*
|
||||
@ -136,17 +124,72 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
@Transactional
|
||||
@Override
|
||||
public Boolean createByAdmin(UserMessageDto dto) {
|
||||
Set<User> users = new HashSet<>(userRepository.selectList(new LambdaQueryWrapper<User>().in(User::getId, dto.userIds)));
|
||||
Message message = messageMapper.toEntity(dto);
|
||||
Set<User> users = dto.userIds.stream()
|
||||
.map(userService::getById)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
if (users.isEmpty()) {
|
||||
throw new RuntimeException("No valid users found for the provided userIds.");
|
||||
}
|
||||
Message message = new Message(dto.type, false, dto.email, dto.sms, dto.html,
|
||||
dto.title, dto.content, null);
|
||||
messageRepo.insert(message);
|
||||
Set<UserMessage> userMessages = users.stream()
|
||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), true, null))
|
||||
.map(user -> new UserMessage(null, user.getId(), message.getId(), false, null))
|
||||
.collect(Collectors.toSet());
|
||||
send(users, message);
|
||||
return saveBatch(userMessages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将附件关联信息插入数据库
|
||||
*
|
||||
* @param messageId 消息ID,用于关联消息和附件
|
||||
* @param attachmentIds 附件ID列表,表示需要插入的附件
|
||||
* @return 返回一个布尔值,表示批量插入是否成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertInto(Long messageId, List<String> attachmentIds) {
|
||||
List<MessageAttachment> messageAttachments = attachmentIds.stream()
|
||||
.map(attachmentId -> new MessageAttachment(messageId, attachmentId))
|
||||
.collect(Collectors.toList());
|
||||
return messageAttachmentService.saveBatch(messageAttachments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有消息推送方式
|
||||
*
|
||||
* @return 消息设置列表
|
||||
*/
|
||||
@Override
|
||||
public List<MessageSetting> getSetting() {
|
||||
return messageSettingRepo.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置消息推送方式
|
||||
*
|
||||
* @param settings 消息设置集合
|
||||
* @return 消息设置列表
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public List<MessageSetting> saveSetting(List<MessageSetting> settings) {
|
||||
if (CollectionUtils.isEmpty(settings)) {
|
||||
throw new RuntimeException("settings is NULL!");
|
||||
}
|
||||
for (MessageSetting setting : settings) {
|
||||
try {
|
||||
messageSettingRepo.insert(setting);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("设置失败" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以邮件、短信等形式发送消息,只有非html格式的消息才能以短信方式发送
|
||||
*
|
||||
@ -174,15 +217,15 @@ public class UserMessageServiceImpl extends ServiceImpl<UserMessageRepository, U
|
||||
public Boolean createBySystem(Set<User> receivers, MessagePayload payload) {
|
||||
AtomicBoolean email = new AtomicBoolean(false);
|
||||
AtomicBoolean sms = new AtomicBoolean(false);
|
||||
Optional.of(messageRepo.selectById(payload.type)).ifPresent(message -> {
|
||||
email.set(message.email);
|
||||
sms.set(message.sms);
|
||||
Optional.of(messageSettingRepo.selectById(payload.type)).ifPresent(messageSetting -> {
|
||||
email.set(messageSetting.email);
|
||||
sms.set(messageSetting.sms);
|
||||
});
|
||||
Message message = new Message(payload.type, true, email.get(), sms.get(),
|
||||
payload.html, payload.type.name(), payload.content);
|
||||
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());
|
||||
new UserMessage(null, user.getId(), message.getId(), false, null)).collect(Collectors.toSet());
|
||||
send(receivers, message);
|
||||
return saveBatch(userMessages);
|
||||
}
|
||||
|
@ -11,92 +11,35 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class BulletinVo {
|
||||
/**
|
||||
* 公告id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 公告标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 公告属性
|
||||
*/
|
||||
private Bulletin.State state = Bulletin.State.edit;
|
||||
/**
|
||||
* 公告置顶状态
|
||||
*/
|
||||
private Boolean top;
|
||||
/**
|
||||
* 公告编辑者ID
|
||||
*/
|
||||
private Long editUserId;
|
||||
/**
|
||||
* 公告编辑者名称
|
||||
*/
|
||||
private String editUsername;
|
||||
/**
|
||||
* 公告编辑时间
|
||||
*/
|
||||
private LocalDateTime editTime;
|
||||
/**
|
||||
* 公告发布者ID
|
||||
*/
|
||||
private Long publishUserId;
|
||||
/**
|
||||
* 公告发布者名称
|
||||
*/
|
||||
private String publishUsername;
|
||||
/**
|
||||
* 公告发布时间
|
||||
*/
|
||||
private LocalDateTime publishTime;
|
||||
/**
|
||||
* 公告关闭者ID
|
||||
*/
|
||||
private Long closeUserId;
|
||||
/**
|
||||
* 公告关闭者名称
|
||||
*/
|
||||
private String closeUsername;
|
||||
/**
|
||||
* 公告关闭时间
|
||||
*/
|
||||
private LocalDateTime closeTime;
|
||||
/**
|
||||
* 公告内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||
private String updateBy;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
List<AttachmentVo> attachmentVos;
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,71 +18,31 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class UserMessageVo {
|
||||
/**
|
||||
* 用户消息id
|
||||
*/
|
||||
private Long messageId;
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
private Long id;
|
||||
public Boolean isRead;
|
||||
/**
|
||||
* 阅读时间
|
||||
*/
|
||||
public LocalDateTime readTime;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public String username;
|
||||
public String name;
|
||||
public String avatar;
|
||||
public String address;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
public MessageType type = MessageType.other;
|
||||
/**
|
||||
* 是否系统消息
|
||||
*/
|
||||
public Boolean system;
|
||||
/**
|
||||
* 是否邮件
|
||||
*/
|
||||
public Boolean email;
|
||||
/**
|
||||
* 是否短信
|
||||
*/
|
||||
public Boolean sms;
|
||||
/**
|
||||
* 是否html
|
||||
*/
|
||||
public Boolean html;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
public String title;
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
public String content;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(value = "create_by", fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
|
||||
private String updateBy;
|
||||
|
||||
public List<AttachmentVo> attachments;
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package com.zsc.edu.gateway.modules.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.query.DeptQuery;
|
||||
import com.zsc.edu.gateway.modules.system.service.DeptService;
|
||||
import com.zsc.edu.gateway.modules.system.service.UserService;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -28,12 +31,12 @@ public class DeptController {
|
||||
|
||||
/**
|
||||
* 返回管理部门列表 hasAuthority('DEPT_QUERY')
|
||||
* @param deptId 部门ID
|
||||
*
|
||||
* @return 部门列表
|
||||
*/
|
||||
@GetMapping("/{deptId}")
|
||||
public List<Dept> getDeptTree(@PathVariable Long deptId) {
|
||||
return service.getDeptTree(deptId);
|
||||
@GetMapping()
|
||||
public List<DeptTree> getDeptTree() {
|
||||
return service.getDeptTree();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@ package com.zsc.edu.gateway.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.gateway.modules.system.vo.UserVo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -48,9 +47,9 @@ public class Dept extends BaseEntity {
|
||||
private Boolean enabled = true;
|
||||
|
||||
@TableField(exist = false)
|
||||
public List<Dept> children = null;
|
||||
public List<Dept> children = new ArrayList<>(0);
|
||||
|
||||
@TableField(exist = false)
|
||||
public List<UserVo> members = null;
|
||||
public List<User> members = new ArrayList<>(0);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,11 @@ package com.zsc.edu.gateway.modules.system.repo;
|
||||
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import org.apache.ibatis.annotations.Many;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.Results;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -14,5 +19,6 @@ import java.util.List;
|
||||
* @since 2023-04-06
|
||||
*/
|
||||
public interface DeptRepository extends BaseMapper<Dept> {
|
||||
List<Dept> selectDeptTree();
|
||||
@Select("SELECT d.*, u.* FROM sys_dept d LEFT JOIN sys_user u ON d.id = u.dept_id")
|
||||
List<Dept> selectAllWithMembers();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.zsc.edu.gateway.modules.system.service;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -30,11 +31,13 @@ public interface DeptService extends IService<Dept> {
|
||||
Boolean edit(DeptDto dto, Long id);
|
||||
|
||||
Boolean toggle(Long id);
|
||||
//
|
||||
// /**
|
||||
// * 生成部门树结构
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
//// Dept listTree(Long id);
|
||||
|
||||
/**
|
||||
* 生成部门树结构
|
||||
*
|
||||
* @return Dept
|
||||
*/
|
||||
List<Dept> getDeptTree(Long deptId);
|
||||
List<DeptTree> getDeptTree();
|
||||
}
|
||||
|
@ -2,12 +2,10 @@ package com.zsc.edu.gateway.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.common.util.TreeUtil;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||
//import com.zsc.edu.gateway.modules.system.dto.RoleAuthorityDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Role;
|
||||
import com.zsc.edu.gateway.modules.system.mapper.AuthorityMapper;
|
||||
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
||||
@ -15,8 +13,6 @@ import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -2,19 +2,23 @@ package com.zsc.edu.gateway.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||
import com.zsc.edu.gateway.common.util.TreeUtil;
|
||||
import com.zsc.edu.gateway.framework.DeptTreeUtil;
|
||||
import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import com.zsc.edu.gateway.modules.system.mapper.DeptMapper;
|
||||
import com.zsc.edu.gateway.modules.system.repo.DeptRepository;
|
||||
import com.zsc.edu.gateway.modules.system.repo.UserRepository;
|
||||
import com.zsc.edu.gateway.modules.system.service.DeptService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zsc.edu.gateway.modules.system.vo.DeptTree;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -30,6 +34,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
||||
|
||||
private final DeptMapper mapper;
|
||||
private final DeptRepository repo;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public Dept create(DeptDto dto) {
|
||||
@ -59,25 +64,14 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dept> getDeptTree(Long deptId) {
|
||||
List<Dept> deptTrees = repo.selectDeptTree();
|
||||
List<Dept> deptTree = TreeUtil.makeTree(
|
||||
deptTrees,
|
||||
department -> department.getPid() == null || department.getPid() == -1L,
|
||||
(parent, child) -> parent.getId().equals(child.getPid()),
|
||||
Dept::setChildren
|
||||
);
|
||||
|
||||
if (Objects.nonNull(deptId)) {
|
||||
List<Dept> deptChildrenTree = new ArrayList<>();
|
||||
TreeUtil.forLevelOrder(deptTree, node -> {
|
||||
if (node.getId().equals(deptId)) {
|
||||
deptChildrenTree.add(node);
|
||||
}
|
||||
}, Dept::getChildren);
|
||||
return deptChildrenTree;
|
||||
public List<DeptTree> getDeptTree() {
|
||||
List<Dept> depots = repo.selectList(null);
|
||||
List<User> users = userRepository.selectList(null);
|
||||
Map<Long, List<User>> userMap = new HashMap<>();
|
||||
for (User user : users) {
|
||||
userMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
||||
}
|
||||
return deptTree;
|
||||
return DeptTreeUtil.buildDeptTree(depots, userMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleRepository, Role> implement
|
||||
@Override
|
||||
public RoleVo detail(Long id) {
|
||||
// Role role = getById(id);
|
||||
// // TODO 联表查询
|
||||
// // List<RoleAuthority> roleAuthorities = roleAuthService.list(new LambdaQueryWrapper<RoleAuthority>().eq(RoleAuthority::getRoleId, role.id));
|
||||
// role.authorities = authorityRepository.selectAuthoritiesByRoleId(role.id);
|
||||
return roleRepository.selectRoleById(id);
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.zsc.edu.gateway.modules.system.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.zsc.edu.gateway.modules.system.entity.User;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeptTree {
|
||||
|
||||
private Long id;
|
||||
@JsonIgnore
|
||||
private Long pid;
|
||||
private String name;
|
||||
List<DeptTree> children = new ArrayList<>();
|
||||
List<UserTree> members = new ArrayList<>();
|
||||
}
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:16/2/2024 下午6:20
|
||||
* 描述: TODO
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.zsc.edu.gateway.modules.system.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserTree {
|
||||
private Long id;
|
||||
private String name;
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
package com.zsc.edu.gateway.modules.system.vo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author zhuang
|
||||
*/
|
||||
@Data
|
||||
public class UserVo {
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
public Long userId;
|
||||
@TableId(type = IdType.AUTO)
|
||||
public Long id;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
@ -18,21 +18,29 @@
|
||||
<result column="edit_user_name" jdbcType="VARCHAR" property="editUsername"/>
|
||||
<result column="publish_user_name" jdbcType="VARCHAR" property="publishUsername"/>
|
||||
<result column="close_user_name" jdbcType="VARCHAR" property="closeUsername"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo"
|
||||
autoMapping="true" columnPrefix="attachment_">
|
||||
<id column="id" property="attachmentId"/>
|
||||
<collection property="attachmentVos" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="selectByBulletinId" resultMap="BulletinMap">
|
||||
//TODO 查询数据问题已经修改
|
||||
SELECT sb.*, a.id as attachment_id, a.file_name as attachment_file_name, a.url as attachment_url
|
||||
SELECT sb.id AS id,
|
||||
sb.state AS state,
|
||||
sb.content AS content,
|
||||
sb.title AS title,
|
||||
sb.top AS top,
|
||||
sb.remark AS remark,
|
||||
sb.close_time AS close_time,
|
||||
sb.close_user_id AS close_user_id,
|
||||
sb.create_by AS create_by,
|
||||
sb.create_time AS create_time,
|
||||
sb.edit_user_id AS edit_user_id,
|
||||
sb.publish_time AS publish_time,
|
||||
sb.publish_user_id AS publish_user_id,
|
||||
sb.update_by AS update_by,
|
||||
sb.update_time AS update_time,
|
||||
a.file_name AS file_name,
|
||||
a.url AS url
|
||||
FROM sys_bulletin sb
|
||||
LEFT JOIN
|
||||
sys_bulletin_attach sba ON sb.id = sba.bulletin_id
|
||||
@ -59,7 +67,6 @@
|
||||
sb.publish_user_id AS publish_user_id,
|
||||
sb.update_by AS update_by,
|
||||
sb.update_time AS update_time,
|
||||
a.id AS id,
|
||||
a.file_name AS file_name,
|
||||
a.url AS url
|
||||
FROM
|
||||
|
@ -4,10 +4,13 @@
|
||||
"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">
|
||||
<id column="message_id" jdbcType="BIGINT" property="messageId"/>
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="is_read" jdbcType="BOOLEAN" property="isRead"/>
|
||||
<result column="read_time" jdbcType="TIMESTAMP" property="readTime"/>
|
||||
<result column="username" jdbcType="VARCHAR" property="username"/>
|
||||
<result column="address" jdbcType="VARCHAR" property="address"/>
|
||||
<result column="avatar" jdbcType="VARCHAR" property="avatar"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||
@ -20,90 +23,55 @@
|
||||
<result column="create_time" jdbcType="DATE" property="createTime"/>
|
||||
<result column="update_time" jdbcType="DATE" property="updateTime"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="userMessageAdminMap" type="com.zsc.edu.gateway.modules.notice.vo.AdminMessageVo">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="system" jdbcType="BOOLEAN" property="system"/>
|
||||
<result column="email" jdbcType="BOOLEAN" property="email"/>
|
||||
<result column="sms" jdbcType="BOOLEAN" property="sms"/>
|
||||
<result column="html" jdbcType="BOOLEAN" property="html"/>
|
||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
||||
<result column="content" jdbcType="VARCHAR" property="content"/>
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
||||
<result column="user_count" jdbcType="INTEGER" property="userCount"/>
|
||||
<result column="read_count" jdbcType="INTEGER" property="readCount"/>
|
||||
<collection property="attachments" ofType="com.zsc.edu.gateway.modules.attachment.vo.AttachmentVo">
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
</collection>
|
||||
</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
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name,a.*
|
||||
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
|
||||
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}
|
||||
and su.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
|
||||
<select id="query" resultType="com.zsc.edu.gateway.modules.notice.vo.UserMessageVo" resultMap="userMessageMap">
|
||||
select sum.*,sm.*,su.username,su.address,su.avatar,su.name,a.*
|
||||
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
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sm.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null">
|
||||
AND sm.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}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND sum.is_read = #{query.isRead}
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
</where>
|
||||
left join sys_message_attachment sma on sm.id = sma.message_id
|
||||
left join attachment a on sma.attachment_id = a.id
|
||||
where 1=1
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sm.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null">
|
||||
AND sm.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}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND sum.is_read = #{query.isRead}
|
||||
</if>
|
||||
<if test="query.createAtBegin != null and query.createAtEnd != null">
|
||||
AND sm.create_time BETWEEN #{query.createAtBegin} AND #{query.createAtEnd}
|
||||
</if>
|
||||
ORDER BY
|
||||
sm.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="pageAdmin" resultMap="userMessageAdminMap">
|
||||
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 -- 统计已读数量
|
||||
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
|
||||
GROUP BY
|
||||
sm.id
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
AND sum.user_id = #{query.userId}
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND sm.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}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
@ -1,33 +1,9 @@
|
||||
<?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.system.repo.DeptRepository">
|
||||
|
||||
<resultMap id="deptMap" type="com.zsc.edu.gateway.modules.system.entity.Dept">
|
||||
<id column="id" property="id"/>
|
||||
<result column="sub_count" property="subCount"/>
|
||||
<result column="pid" property="pid"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="dept_sort" property="deptSort"/>
|
||||
<collection
|
||||
property="members"
|
||||
ofType="com.zsc.edu.gateway.modules.system.vo.UserVo"
|
||||
autoMapping="true"
|
||||
columnPrefix="members_"
|
||||
>
|
||||
<id column="id" jdbcType="BIGINT" property="userId"/>
|
||||
<result column="username" jdbcType="VARCHAR" property="username"/>
|
||||
<result column="email" jdbcType="VARCHAR" property="email"/>
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectDeptTree" resultMap="deptMap">
|
||||
SELECT sd.*,
|
||||
su.id as members_id,
|
||||
su.username as members_username,
|
||||
su.email as members_email,
|
||||
su.phone as members_phone
|
||||
FROM sys_dept sd
|
||||
left join sys_user su on sd.id = su.dept_id
|
||||
<select id="selectAllWithMembers" resultType="com.zsc.edu.gateway.modules.system.entity.Dept">
|
||||
SELECT d.*, u.*
|
||||
FROM sys_dept d
|
||||
LEFT JOIN sys_user u ON d.id = u.dept_id
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -78,8 +78,8 @@ public class BulletinServiceTest {
|
||||
assertEquals(bulletin.getTitle(), dto.getTitle());
|
||||
assertEquals(bulletin.getId(), bulletin2.id);
|
||||
// 不能改为其他已存在的同名同代码部门
|
||||
// assertThrows(ConstraintException.class,
|
||||
// () -> service.update(userDetails, new BulletinDto(bulletin1.getTitle(), true, null, null), bulletin2.id));
|
||||
assertThrows(ConstraintException.class,
|
||||
() -> service.update(userDetails, new BulletinDto(bulletin1.getTitle(), true, null, null), bulletin2.id));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -14,6 +14,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author ftz
|
||||
* 创建时间:29/12/2023 上午11:21
|
||||
* 描述: TODO
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class UserServiceTest {
|
||||
|
Loading…
Reference in New Issue
Block a user