feat: 添加获取未读消息数量接口
This commit is contained in:
parent
0fb0c19acf
commit
27018d0787
|
|
@ -88,7 +88,7 @@ public class MessageController extends ControllerBase {
|
||||||
@MethodInfoMark(value = "设置消息已读", menuName = "消息管理")
|
@MethodInfoMark(value = "设置消息已读", menuName = "消息管理")
|
||||||
@ApiMark(moduleName = "消息管理", apiName = "设置消息已读")
|
@ApiMark(moduleName = "消息管理", apiName = "设置消息已读")
|
||||||
public ApiResult<Void> setReaded(@Valid @RequestBody List<Integer> ids) {
|
public ApiResult<Void> setReaded(@Valid @RequestBody List<Integer> ids) {
|
||||||
adminMessageService.setReaded(ids);
|
adminMessageService.setReaded(AdminUserUtil.getUserId(),ids);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ public class MessageController extends ControllerBase {
|
||||||
@MethodInfoMark(value = "设置消息未读", menuName = "消息管理")
|
@MethodInfoMark(value = "设置消息未读", menuName = "消息管理")
|
||||||
@ApiMark(moduleName = "消息管理", apiName = "设置消息未读")
|
@ApiMark(moduleName = "消息管理", apiName = "设置消息未读")
|
||||||
public ApiResult<Void> setNotRead(@Valid @RequestBody List<Integer> ids) {
|
public ApiResult<Void> setNotRead(@Valid @RequestBody List<Integer> ids) {
|
||||||
adminMessageService.setNotRead(ids);
|
adminMessageService.setNotRead(AdminUserUtil.getUserId(),ids);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,10 +110,21 @@ public class MessageController extends ControllerBase {
|
||||||
* @return 未读消息列表
|
* @return 未读消息列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("getNotReadMessages")
|
@GetMapping("getNotReadMessages")
|
||||||
|
@ApiMark(moduleName = "消息管理", apiName = "获取未读消息")
|
||||||
public ApiResult<PageData<AdminMessageVO>> getNotReadMessages(@RequestParam(defaultValue = "10") Integer num) {
|
public ApiResult<PageData<AdminMessageVO>> getNotReadMessages(@RequestParam(defaultValue = "10") Integer num) {
|
||||||
return ApiResult.success(adminMessageService.getNotReadMessage(AdminUserUtil.getUserId(), num));
|
return ApiResult.success(adminMessageService.getNotReadMessage(AdminUserUtil.getUserId(), num));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未读消息数量
|
||||||
|
* @return 未读消息数量
|
||||||
|
*/
|
||||||
|
@GetMapping("getNotReadMessageCount")
|
||||||
|
@ApiMark(moduleName = "消息管理", apiName = "获取未读消息数量")
|
||||||
|
public ApiResult<Integer> getNotReadMessageCount(){
|
||||||
|
return ApiResult.success(adminMessageService.getNotReadMessageCount(AdminUserUtil.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息配置
|
* 获取消息配置
|
||||||
* @return 消息配置
|
* @return 消息配置
|
||||||
|
|
|
||||||
|
|
@ -50,18 +50,17 @@ public class MessageController extends ControllerBase {
|
||||||
*/
|
*/
|
||||||
@PostMapping("setReaded")
|
@PostMapping("setReaded")
|
||||||
public ApiResult<Void> setReaded(@Valid @RequestBody List<Integer> ids) {
|
public ApiResult<Void> setReaded(@Valid @RequestBody List<Integer> ids) {
|
||||||
appMessageService.setReaded(ids);
|
appMessageService.setReaded(AppUserUtil.getUserId(),ids);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置消息未读
|
* 设置消息未读
|
||||||
*
|
|
||||||
* @param ids 消息id列表
|
* @param ids 消息id列表
|
||||||
*/
|
*/
|
||||||
@PostMapping("setNotRead")
|
@PostMapping("setNotRead")
|
||||||
public ApiResult<Void> setNotRead(@Valid @RequestBody List<Integer> ids) {
|
public ApiResult<Void> setNotRead(@Valid @RequestBody List<Integer> ids) {
|
||||||
appMessageService.setNotRead(ids);
|
appMessageService.setNotRead(AppUserUtil.getUserId(),ids);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,6 +74,15 @@ public class MessageController extends ControllerBase {
|
||||||
return ApiResult.success(appMessageService.getNotReadMessage(AppUserUtil.getUserId(), num));
|
return ApiResult.success(appMessageService.getNotReadMessage(AppUserUtil.getUserId(), num));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未读消息数量
|
||||||
|
* @return 未读消息数量
|
||||||
|
*/
|
||||||
|
@GetMapping("getNotReadMessageCount")
|
||||||
|
public ApiResult<Integer> getNotReadMessageCount(){
|
||||||
|
return ApiResult.success(appMessageService.getNotReadMessageCount(AppUserUtil.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息配置
|
* 获取消息配置
|
||||||
* @return 消息配置
|
* @return 消息配置
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ public class Constant {
|
||||||
|
|
||||||
public static final String REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN = "admin:kaptcha:user:update:{}";
|
public static final String REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN = "admin:kaptcha:user:update:{}";
|
||||||
|
|
||||||
|
public static final String REDIS_KEY_MESSAGE_NOT_READ_COUNT_ADMIN = "admin:message:unread";
|
||||||
|
|
||||||
|
public static final String REDIS_KEY_MESSAGE_NOT_READ_COUNT_APP = "app:message:unread";
|
||||||
|
|
||||||
public static final String REDIS_KEY_MESSAGECONFIG_WX = "wxNotifyEnabled";
|
public static final String REDIS_KEY_MESSAGECONFIG_WX = "wxNotifyEnabled";
|
||||||
|
|
||||||
public static final String REDIS_KEY_MESSAGECONFIG_EMAIL = "emailNotifyEnabled";
|
public static final String REDIS_KEY_MESSAGECONFIG_EMAIL = "emailNotifyEnabled";
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@ public interface IAdminMessageService extends IService<AdminMessage> {
|
||||||
|
|
||||||
IPage<AdminMessageVO> search(Integer userId, AdminMessageSearchRequest request);
|
IPage<AdminMessageVO> search(Integer userId, AdminMessageSearchRequest request);
|
||||||
|
|
||||||
void setReaded(List<Integer> ids);
|
void setReaded(Integer userId,List<Integer> ids);
|
||||||
|
|
||||||
void setNotRead(List<Integer> ids);
|
void setNotRead(Integer userId,List<Integer> ids);
|
||||||
|
|
||||||
void add(AdminMessage message);
|
void add(AdminMessage message);
|
||||||
|
|
||||||
IPage<AdminMessageVO> getNotReadMessage(Integer userId, Integer num);
|
IPage<AdminMessageVO> getNotReadMessage(Integer userId, Integer num);
|
||||||
|
|
||||||
|
Integer getNotReadMessageCount(Integer userId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,11 @@ public interface IAppMessageService extends IService<AppMessage> {
|
||||||
|
|
||||||
IPage<AppMessageVO> search(Integer userId, AppMessageSearchRequest request);
|
IPage<AppMessageVO> search(Integer userId, AppMessageSearchRequest request);
|
||||||
|
|
||||||
void setReaded(List<Integer> ids);
|
void setReaded(Integer userId,List<Integer> ids);
|
||||||
|
|
||||||
void setNotRead(List<Integer> ids);
|
void setNotRead(Integer userId,List<Integer> ids);
|
||||||
|
|
||||||
void add(AppMessage message);
|
void add(AppMessage message);
|
||||||
|
|
||||||
|
Integer getNotReadMessageCount(Integer userId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nflg.mobilebroken.common.constant.Constant;
|
||||||
import com.nflg.mobilebroken.common.pojo.request.AdminMessageSearchRequest;
|
import com.nflg.mobilebroken.common.pojo.request.AdminMessageSearchRequest;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.AdminMessageVO;
|
import com.nflg.mobilebroken.common.pojo.vo.AdminMessageVO;
|
||||||
import com.nflg.mobilebroken.repository.entity.AdminMessage;
|
import com.nflg.mobilebroken.repository.entity.AdminMessage;
|
||||||
import com.nflg.mobilebroken.repository.mapper.AdminMessageMapper;
|
import com.nflg.mobilebroken.repository.mapper.AdminMessageMapper;
|
||||||
import com.nflg.mobilebroken.repository.service.IAdminMessageService;
|
import com.nflg.mobilebroken.repository.service.IAdminMessageService;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -25,25 +29,32 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class AdminMessageServiceImpl extends ServiceImpl<AdminMessageMapper, AdminMessage> implements IAdminMessageService {
|
public class AdminMessageServiceImpl extends ServiceImpl<AdminMessageMapper, AdminMessage> implements IAdminMessageService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<AdminMessageVO> search(Integer userId, AdminMessageSearchRequest request) {
|
public IPage<AdminMessageVO> search(Integer userId, AdminMessageSearchRequest request) {
|
||||||
return baseMapper.search(userId, request, new Page<>(request.getPage(), request.getPageSize()));
|
return baseMapper.search(userId, request, new Page<>(request.getPage(), request.getPageSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReaded(List<Integer> ids) {
|
public void setReaded(Integer userId, List<Integer> ids) {
|
||||||
lambdaUpdate()
|
lambdaUpdate()
|
||||||
.set(AdminMessage::getIsRead, true)
|
.set(AdminMessage::getIsRead, true)
|
||||||
|
.eq(AdminMessage::getUserId, userId)
|
||||||
.in(AdminMessage::getId, ids)
|
.in(AdminMessage::getId, ids)
|
||||||
.update();
|
.update();
|
||||||
|
setUnreadMessageCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNotRead(List<Integer> ids) {
|
public void setNotRead(Integer userId, List<Integer> ids) {
|
||||||
lambdaUpdate()
|
lambdaUpdate()
|
||||||
.set(AdminMessage::getIsRead, false)
|
.set(AdminMessage::getIsRead, false)
|
||||||
|
.eq(AdminMessage::getUserId, userId)
|
||||||
.in(AdminMessage::getId, ids)
|
.in(AdminMessage::getId, ids)
|
||||||
.update();
|
.update();
|
||||||
|
setUnreadMessageCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
@ -54,10 +65,24 @@ public class AdminMessageServiceImpl extends ServiceImpl<AdminMessageMapper, Adm
|
||||||
.eq(AdminMessage::getSourceId, message.getSourceId())
|
.eq(AdminMessage::getSourceId, message.getSourceId())
|
||||||
.eq(AdminMessage::getUserId, message.getUserId()));
|
.eq(AdminMessage::getUserId, message.getUserId()));
|
||||||
save(message);
|
save(message);
|
||||||
|
setUnreadMessageCount(message.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<AdminMessageVO> getNotReadMessage(Integer userId, Integer num) {
|
public IPage<AdminMessageVO> getNotReadMessage(Integer userId, Integer num) {
|
||||||
return baseMapper.getNotReadMessage(userId, num, new Page<>(1, num));
|
return baseMapper.getNotReadMessage(userId, num, new Page<>(1, num));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUnreadMessageCount(Integer userId){
|
||||||
|
Integer count= Math.toIntExact(lambdaQuery()
|
||||||
|
.eq(AdminMessage::getIsRead, false)
|
||||||
|
.eq(AdminMessage::getUserId, userId)
|
||||||
|
.count());
|
||||||
|
redisTemplate.opsForHash().put(Constant.REDIS_KEY_MESSAGE_NOT_READ_COUNT_ADMIN, userId, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getNotReadMessageCount(Integer userId) {
|
||||||
|
return Optional.ofNullable((Integer) redisTemplate.opsForHash().get(Constant.REDIS_KEY_MESSAGE_NOT_READ_COUNT_ADMIN, userId)).orElse(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nflg.mobilebroken.common.constant.Constant;
|
||||||
import com.nflg.mobilebroken.common.pojo.request.AppMessageSearchRequest;
|
import com.nflg.mobilebroken.common.pojo.request.AppMessageSearchRequest;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.AppMessageVO;
|
import com.nflg.mobilebroken.common.pojo.vo.AppMessageVO;
|
||||||
import com.nflg.mobilebroken.repository.entity.AppMessage;
|
import com.nflg.mobilebroken.repository.entity.AppMessage;
|
||||||
import com.nflg.mobilebroken.repository.mapper.AppMessageMapper;
|
import com.nflg.mobilebroken.repository.mapper.AppMessageMapper;
|
||||||
import com.nflg.mobilebroken.repository.service.IAdminUserService;
|
import com.nflg.mobilebroken.repository.service.IAdminUserService;
|
||||||
import com.nflg.mobilebroken.repository.service.IAppMessageService;
|
import com.nflg.mobilebroken.repository.service.IAppMessageService;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,6 +33,9 @@ public class AppMessageServiceImpl extends ServiceImpl<AppMessageMapper, AppMess
|
||||||
@Resource
|
@Resource
|
||||||
private IAdminUserService adminUserService;
|
private IAdminUserService adminUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<AppMessageVO> getNotReadMessage(Integer userId, Integer num) {
|
public IPage<AppMessageVO> getNotReadMessage(Integer userId, Integer num) {
|
||||||
return baseMapper.getNotReadMessage(userId, num, new Page<>(1, num));
|
return baseMapper.getNotReadMessage(userId, num, new Page<>(1, num));
|
||||||
|
|
@ -62,19 +64,23 @@ public class AppMessageServiceImpl extends ServiceImpl<AppMessageMapper, AppMess
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReaded(List<Integer> ids) {
|
public void setReaded(Integer userId,List<Integer> ids) {
|
||||||
lambdaUpdate()
|
lambdaUpdate()
|
||||||
.set(AppMessage::getIsRead, true)
|
.set(AppMessage::getIsRead, true)
|
||||||
|
.eq(AppMessage::getUserId, userId)
|
||||||
.in(AppMessage::getId, ids)
|
.in(AppMessage::getId, ids)
|
||||||
.update();
|
.update();
|
||||||
|
setUnreadMessageCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNotRead(List<Integer> ids) {
|
public void setNotRead(Integer userId,List<Integer> ids) {
|
||||||
lambdaUpdate()
|
lambdaUpdate()
|
||||||
.set(AppMessage::getIsRead, false)
|
.set(AppMessage::getIsRead, false)
|
||||||
|
.eq(AppMessage::getUserId, userId)
|
||||||
.in(AppMessage::getId, ids)
|
.in(AppMessage::getId, ids)
|
||||||
.update();
|
.update();
|
||||||
|
setUnreadMessageCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -84,5 +90,19 @@ public class AppMessageServiceImpl extends ServiceImpl<AppMessageMapper, AppMess
|
||||||
.eq(AppMessage::getSubType, message.getSubType())
|
.eq(AppMessage::getSubType, message.getSubType())
|
||||||
.eq(AppMessage::getUserId, message.getUserId()));
|
.eq(AppMessage::getUserId, message.getUserId()));
|
||||||
save(message);
|
save(message);
|
||||||
|
setUnreadMessageCount(message.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUnreadMessageCount(Integer userId){
|
||||||
|
Integer count= Math.toIntExact(lambdaQuery()
|
||||||
|
.eq(AppMessage::getIsRead, false)
|
||||||
|
.eq(AppMessage::getUserId, userId)
|
||||||
|
.count());
|
||||||
|
redisTemplate.opsForHash().put(Constant.REDIS_KEY_MESSAGE_NOT_READ_COUNT_APP, userId, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getNotReadMessageCount(Integer userId) {
|
||||||
|
return Optional.ofNullable((Integer) redisTemplate.opsForHash().get(Constant.REDIS_KEY_MESSAGE_NOT_READ_COUNT_APP, userId)).orElse(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue