增加消息模块 添加批量导入

master
bynt 3 years ago
parent f367d6866f
commit 50443e5ae8

@ -113,6 +113,17 @@
<artifactId>yauaa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,32 @@
package com.baiye.feign;
import com.baiye.constant.SecurityConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @author Enzo
* @date : 2022/1/4
*/
@Configuration
@Slf4j
public class FeignConfiguration implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
// HeaderConstants.TOKEN_HEADER_NAME 替换为自己的请求头名称,下同
String token = request.getHeader(SecurityConstants.AUTHORIZATION);
if(token == null){
log.info("--请求中未携带token.......");
return;
}
requestTemplate.header(SecurityConstants.AUTHORIZATION, token);
}
}

@ -3,7 +3,7 @@ server:
spring:
application:
name: ad-platform-gateways
name: @artifactId@
cloud:
nacos:
discovery:

@ -0,0 +1,38 @@
package com.baiye.model.dto;
import lombok.Data;
/**
* @author Enzo
* @date : 2022/1/6
*/
@Data
public class UserFavorOfExcel {
/**
*
*/
private String nickName;
/**
*
*/
private String email;
/**
*
*/
private String phone;
/**
*
*/
private String gender;
/**
*
*/
private String password;
}

@ -22,4 +22,12 @@ public interface SendMessageClient {
*/
@PostMapping(API_PREFIX + "/websocket/message")
CommonResponse<Object> sendWebSocket(@RequestBody SendWebSocketDTO sendWebSocketDTO);
/**
* websocket
* @param sendWebSocketDTO dto
* @return
*/
@PostMapping(API_PREFIX + "/websocket/save")
CommonResponse<Object> saveMessage(@RequestBody SendWebSocketDTO sendWebSocketDTO);
}

@ -14,4 +14,9 @@ public class SendMessageFallback implements SendMessageClient {
public CommonResponse<Object> sendWebSocket(SendWebSocketDTO sendWebSocketDTO) {
return null;
}
@Override
public CommonResponse<Object> saveMessage(SendWebSocketDTO sendWebSocketDTO) {
return null;
}
}

@ -122,12 +122,13 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/file/**").permitAll()
// 阿里巴巴 druid
.antMatchers("/druid/**").permitAll()
.antMatchers("/api/task/saveTask").permitAll()
// 放行OPTIONS请求
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.antMatchers( "/api/users/admin").permitAll()
.antMatchers( "/api/task/query").permitAll()
.antMatchers( "/api/organize/queryAll").permitAll()
// TODO 权限待测试 Enzo
/*.antMatchers("/api/task/saveTask").permitAll()
.antMatchers( "/api/users/admin").permitAll()
.antMatchers( "/api/task/query").permitAll()
.antMatchers( "/api/organize/queryAll").permitAll()*/
// 自定义匿名访问所有url放行允许匿名和带Token访问细腻化到每个 Request 类型
// GET
.antMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll()

@ -35,6 +35,8 @@ import java.sql.Timestamp;
@Table(name="tb_message_notification")
public class MessageNotification implements Serializable {
private static final long serialVersionUID = 5340902902914777841L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ -57,13 +59,17 @@ public class MessageNotification implements Serializable {
@ApiModelProperty(value = "是否使用")
private Boolean isEnable;
@Column(name = "start_time")
@ApiModelProperty(value = "开始时间")
private Timestamp startTime;
@Column(name = "is_top")
@ApiModelProperty(value = "是否使用")
private Boolean isTop;
@Column(name = "type")
@ApiModelProperty(value = "类型 1公告 2自提醒")
private Integer type;
@Column(name = "end_time")
@ApiModelProperty(value = "结束时间")
private Timestamp endTime;
@Column(name = "point_time")
@ApiModelProperty(value = "时间")
private Integer pointTime;
@Column(name = "create_by")
@ApiModelProperty(value = "创建者")

@ -47,6 +47,10 @@ public class UserMessage implements Serializable {
@ApiModelProperty(value = "消息id")
private Long messageId;
@Column(name = "type")
@ApiModelProperty(value = "消息状态")
private Integer type;
@Column(name = "is_read")
@ApiModelProperty(value = "是否已读")
private Boolean isRead = Boolean.TRUE;
@ -67,6 +71,10 @@ public class UserMessage implements Serializable {
@ApiModelProperty(value = "消息内容")
private String messageContext;
@Column(name = "is_top")
@ApiModelProperty(value = "是否置顶")
private Boolean isTop;
@Column(name = "level")
@ApiModelProperty(value = "消息等级")
private Integer level;

@ -18,6 +18,8 @@ package com.baiye.modules.system.repository;
import com.baiye.modules.system.domain.MessageNotification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://el-admin.vip
@ -25,4 +27,14 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2021-12-30
**/
public interface MessageNotificationRepository extends JpaRepository<MessageNotification, Long>, JpaSpecificationExecutor<MessageNotification> {
/**
*
* @param flag
* @param messageId
* @return
*/
@Modifying
@Query(value = "update MessageNotification set isEnable = ?1 where id = ?2")
int updateMessageEnableByMessage(Boolean flag, Long messageId);
}

@ -18,6 +18,8 @@ package com.baiye.modules.system.repository;
import com.baiye.modules.system.domain.UserMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://el-admin.vip
@ -25,4 +27,15 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2021-12-30
**/
public interface UserMessageRepository extends JpaRepository<UserMessage, Long>, JpaSpecificationExecutor<UserMessage> {
/**
*
*
* @param num
* @param messageId
* @return
*/
@Modifying
@Query(value = "update UserMessage set type = ?1 where messageId = ?1")
Boolean deleteUserMessageByMessageId(Integer num, Long messageId);
}

@ -63,6 +63,8 @@ public class MessageNotificationController {
return new ResponseEntity<>(messageNotificationService.create(messageNotificationDto),HttpStatus.CREATED);
}
@PutMapping
@ApiOperation("修改message")
public ResponseEntity<Object> update(@Validated @RequestBody MessageNotificationDto messageNotificationDto){
@ -76,4 +78,10 @@ public class MessageNotificationController {
messageNotificationService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/changeMessage")
@ApiOperation("撤销消息")
public ResponseEntity<Object> withdrawMessage(Boolean flag,Long messageId){
return new ResponseEntity<>(messageNotificationService.withdrawMessage(flag,messageId),HttpStatus.OK);
}
}

@ -15,10 +15,15 @@
*/
package com.baiye.modules.system.rest;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baiye.config.properties.RsaProperties;
import com.baiye.constant.RoleNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.model.dto.UserFavorOfExcel;
import com.baiye.modules.system.domain.Dept;
import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.domain.vo.UserPassVo;
@ -134,6 +139,26 @@ public class UserController {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@ApiOperation("导入用户")
@PostMapping(value = "importUsers")
public ResponseEntity<Object> indexConvert(@RequestParam("file") MultipartFile file) throws IOException {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<UserFavorOfExcel> list = reader.readAll(UserFavorOfExcel.class);
if (CollUtil.isNotEmpty(list)) {
User user;
for (UserFavorOfExcel userFavorOfExcel : list) {
user = new User();
BeanUtil.copyProperties(userFavorOfExcel, user);
if (user.getPassword() == null) {
user.setPassword(passwordEncoder.encode("123456"));
}
userService.create(user);
}
}
return new ResponseEntity<>(HttpStatus.OK);
}
@ApiOperation("删除用户")
@DeleteMapping
@PreAuthorize("@el.check('user:del')")

@ -1,9 +1,8 @@
package com.baiye.modules.system.rest;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.modules.system.domain.UserMessage;
import com.baiye.modules.system.service.UserMessageService;
import com.baiye.modules.system.service.dto.MessageNotificationDto;
import com.baiye.modules.system.service.dto.UserMessageDto;
import com.baiye.modules.system.service.dto.UserMessageQueryCriteria;
import com.baiye.util.SecurityUtils;
import io.swagger.annotations.Api;
@ -25,9 +24,11 @@ import org.springframework.web.bind.annotation.*;
public class UserMessageController {
private final UserMessageService userMessageService;
@ApiOperation("查询任务(分页)")
@GetMapping("/queryAll")
public ResponseEntity<Object> queryAll(UserMessageQueryCriteria criteria){
criteria.setType(DefaultNumberConstants.ONE_NUMBER);
criteria.setUserId(SecurityUtils.getCurrentUserId());
return new ResponseEntity<>(userMessageService.queryAll(criteria), HttpStatus.OK);
}
@ -39,4 +40,7 @@ public class UserMessageController {
userMessageService.update(userMessage);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

@ -80,4 +80,13 @@ public interface MessageNotificationService {
* @throws IOException /
*/
void download(List<MessageNotificationDto> all, HttpServletResponse response) throws IOException;
/**
*
*
* @param flag
* @param messageId
* @return
*/
Boolean withdrawMessage(Boolean flag, Long messageId);
}

@ -90,4 +90,14 @@ public interface UserMessageService {
* @return
*/
Boolean createUserMessage(List<Long> longList, MessageNotification messageNotification);
/**
*
*
* @param num
* @param messageId
* @return
*/
Boolean deleteAllByMessageId(Integer num, Long messageId);
}

@ -28,4 +28,7 @@ public class UserMessageQueryCriteria{
@Query
private Long userId;
@Query
private Integer type;
}

@ -91,11 +91,8 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic
Long userId = SecurityUtils.getCurrentUserId();
UserDto userDto = JSONUtil.toBean(SecurityUtils.getUser(), UserDto.class);
messageNotificationDto.setUserId(userId);
if (messageNotificationDto.getIsTop() != null
&& messageNotificationDto.getIsTop()) {
longList.add(userId);
messageNotificationDto.setLevel(DefaultNumberConstants.FOUR_NUMBER);
}
longList.add(userId);
messageNotificationDto.setLevel(DefaultNumberConstants.FOUR_NUMBER);
// 级别进行排序
if (Boolean.TRUE.equals(userDto.getIsGroup())) {
@ -152,8 +149,6 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic
map.put("消息内容", messageNotificationDto.getMessageContext());
map.put("0表示置顶 1超级管理员 2管理员 3组长消息", messageNotificationDto.getLevel());
map.put("是否使用", messageNotificationDto.getIsEnable());
map.put("开始时间", messageNotificationDto.getStartTime());
map.put("结束时间", messageNotificationDto.getEndTime());
map.put("创建者", messageNotificationDto.getCreateBy());
map.put("更新者", messageNotificationDto.getUpdateBy());
map.put("创建日期", messageNotificationDto.getCreateTime());
@ -162,4 +157,14 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic
}
FileUtil.downloadExcel(list, response);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean withdrawMessage(Boolean flag, Long messageId) {
messageNotificationRepository
.updateMessageEnableByMessage(flag, messageId);
return userMessageService.deleteAllByMessageId(Boolean.TRUE.equals(flag)
? DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.MINUS_ONE_NUMBER, messageId);
}
}

@ -72,6 +72,8 @@ public class UserMessageServiceImpl implements UserMessageService {
@Override
public List<UserMessageDto> queryAll(UserMessageQueryCriteria criteria){
Sort sort = Sort.by(Sort.Direction.ASC, "level").
and(Sort.by(Sort.Direction.DESC, "type")).
and(Sort.by(Sort.Direction.DESC, "isRead")).
and(Sort.by(Sort.Direction.DESC, "createTime"));
return userMessageMapper.toDto(userMessageRepository.findAll(
(root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), sort));
@ -135,10 +137,12 @@ public class UserMessageServiceImpl implements UserMessageService {
userMessage = new UserMessage();
BeanUtil.copyProperties(messageNotification, userMessage);
userMessage.setMessageId(messageNotification.getId());
userMessage.setType(DefaultNumberConstants.ONE_NUMBER);
userMessage.setUserId(aLong);
userMessageRepository.save(userMessage);
}
}
// TODO发送消息
SendWebSocketDTO sendWebSocketDTO = new SendWebSocketDTO();
sendWebSocketDTO.setUserIds(longList);
SendWebSocketDTO.SendMessage sendMessage = new SendWebSocketDTO.SendMessage();
@ -146,7 +150,13 @@ public class UserMessageServiceImpl implements UserMessageService {
sendMessage.setCode(DefaultNumberConstants.TEN_NUMBER);
sendMessage.setMessage(messageNotification.getMessageContext());
sendWebSocketDTO.setData(sendMessage);
sendMessageClient.sendWebSocket(sendWebSocketDTO);
sendMessageClient.saveMessage(sendWebSocketDTO);
return Boolean.TRUE;
}
@Override
public Boolean deleteAllByMessageId(Integer num, Long messageId) {
return userMessageRepository.deleteUserMessageByMessageId(num, messageId);
}
}

@ -8,6 +8,7 @@ import com.baiye.model.dto.DistributeResponseDTO;
import com.baiye.module.entity.ClueMiddle;
import com.baiye.module.service.ClueService;
import com.baiye.module.service.dto.ClueRecordCriteria;
import com.baiye.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

Loading…
Cancel
Save