feat:后台新增通知查询功能
This commit is contained in:
parent
13bd71f0a7
commit
57c3f4dfc6
@ -0,0 +1,37 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.controller;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.business.user.service.NotifyAnnounceService;
|
||||||
|
import com.fanxb.bookmark.common.entity.Result;
|
||||||
|
import com.fanxb.bookmark.common.util.UserContextHolder;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:03
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/announce/user")
|
||||||
|
public class NotifyAnnounceController {
|
||||||
|
@Autowired
|
||||||
|
private NotifyAnnounceService notifyAnnounceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取站内信
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public Result getUserAnnounce(@RequestParam int status) {
|
||||||
|
return Result.success(notifyAnnounceService.getUserAnnounce(UserContextHolder.get().getUserId(), status));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记为已读
|
||||||
|
*/
|
||||||
|
@PostMapping("/read")
|
||||||
|
public Result readNotifyAnnounce(@RequestParam int notifyAnnounceId) {
|
||||||
|
notifyAnnounceService.markAsRead(UserContextHolder.get().getUserId(), notifyAnnounceId);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.dao;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.business.user.vo.UserNotifyAnnounceRes;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:19
|
||||||
|
*/
|
||||||
|
public interface NotifyAnnounceDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户站内信
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param status status
|
||||||
|
* @return java.util.List<com.fanxb.bookmark.business.user.vo.UserNotifyAnnounceRes>
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 14:28
|
||||||
|
*/
|
||||||
|
List<UserNotifyAnnounceRes> queryUserAnnounce(@Param("userId") int userId, @Param("status") int status, @Param("date") long date);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理某人的邮件
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 15:05
|
||||||
|
*/
|
||||||
|
@Insert("insert into user_notify_announce(userId,notifyAnnounceId,status) select #{userId},notifyAnnounceId,0 from notify_announce a where a.createdDate > (select lastSyncAnnounceDate from user where userId=#{userId})")
|
||||||
|
void dealNotifyAnnounceById(int userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记为已读
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param notifyAnnounceId notifyAnnounceId
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 15:26
|
||||||
|
*/
|
||||||
|
@Update("update user_notify_announce set status=1,readDate=#{readDate} where userId=#{userId} and notifyAnnounceId=#{notifyAnnounceId}")
|
||||||
|
void markAsRead(@Param("userId") int userId, @Param("notifyAnnounceId") int notifyAnnounceId, @Param("readDate") long readDate);
|
||||||
|
}
|
@ -193,4 +193,18 @@ public interface UserDao {
|
|||||||
**/
|
**/
|
||||||
@Update("update user set defaultSearchEngine=#{engine} where userId=#{userId}")
|
@Update("update user set defaultSearchEngine=#{engine} where userId=#{userId}")
|
||||||
void updateSearchEngine(@Param("userId") int userId, @Param("engine") String engine);
|
void updateSearchEngine(@Param("userId") int userId, @Param("engine") String engine);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新一个字段-一个条件
|
||||||
|
*
|
||||||
|
* @param column 字段名
|
||||||
|
* @param val 字段值
|
||||||
|
* @param termColumn 条件字段名
|
||||||
|
* @param termVal 条件字段值
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 15:03
|
||||||
|
*/
|
||||||
|
@Update("update user set ${column} = #{val} where ${termColumn} = #{termVal}")
|
||||||
|
void updateOneColumnByOneTerm(String column, Object val, String termColumn, Object termVal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:04
|
||||||
|
*/
|
||||||
|
public class NotifyAnnounce {
|
||||||
|
/**
|
||||||
|
* 通知id
|
||||||
|
*/
|
||||||
|
private int notifyAnnounceId;
|
||||||
|
/**
|
||||||
|
* 发送人id
|
||||||
|
*/
|
||||||
|
private int senderId;
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
/**
|
||||||
|
* 正文
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Long createdDate;
|
||||||
|
/**
|
||||||
|
* 通知开始时间
|
||||||
|
*/
|
||||||
|
private Long startDate;
|
||||||
|
/**
|
||||||
|
* 通知结束时间
|
||||||
|
*/
|
||||||
|
private Long endDate;
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* 定时调度类
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:37
|
||||||
|
*/
|
||||||
|
package com.fanxb.bookmark.business.user.schedule;
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.service;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.business.user.entity.NotifyAnnounce;
|
||||||
|
import com.fanxb.bookmark.business.user.vo.UserNotifyAnnounceRes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:07
|
||||||
|
*/
|
||||||
|
public interface NotifyAnnounceService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户通知
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param status 状态 0:未读,1:已读
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 14:14
|
||||||
|
*/
|
||||||
|
List<UserNotifyAnnounceRes> getUserAnnounce(int userId, int status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记为已读
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param notifyAnnounceId 通知id
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/10/17 14:14
|
||||||
|
*/
|
||||||
|
void markAsRead(int userId, int notifyAnnounceId);
|
||||||
|
}
|
@ -20,7 +20,7 @@ public interface UserService {
|
|||||||
/**
|
/**
|
||||||
* 长期jwt失效时间
|
* 长期jwt失效时间
|
||||||
*/
|
*/
|
||||||
long LONG_EXPIRE_TIME = 30L * TimeUtil.DAY_MS;
|
long LONG_EXPIRE_TIME = 300L * TimeUtil.DAY_MS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 头像文件大小限制 单位:KB
|
* 头像文件大小限制 单位:KB
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.service.impl;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.business.user.dao.NotifyAnnounceDao;
|
||||||
|
import com.fanxb.bookmark.business.user.dao.UserDao;
|
||||||
|
import com.fanxb.bookmark.business.user.entity.NotifyAnnounce;
|
||||||
|
import com.fanxb.bookmark.business.user.service.NotifyAnnounceService;
|
||||||
|
import com.fanxb.bookmark.business.user.vo.UserNotifyAnnounceRes;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:16
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class NotifyAnnounceServiceImpl implements NotifyAnnounceService {
|
||||||
|
@Autowired
|
||||||
|
private NotifyAnnounceDao notifyAnnounceDao;
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public List<UserNotifyAnnounceRes> getUserAnnounce(int userId, int status) {
|
||||||
|
notifyAnnounceDao.dealNotifyAnnounceById(userId);
|
||||||
|
userDao.updateOneColumnByOneTerm("lastSyncAnnounceDate", System.currentTimeMillis(), "userId", userId);
|
||||||
|
return notifyAnnounceDao.queryUserAnnounce(userId, status, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markAsRead(int userId, int notifyAnnounceId) {
|
||||||
|
notifyAnnounceDao.markAsRead(userId, notifyAnnounceId, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
@ -83,7 +83,7 @@ public class OauthServiceImpl implements OauthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO 方法描述
|
* oauth登陆
|
||||||
*
|
*
|
||||||
* @param current 当前是否存在该用户
|
* @param current 当前是否存在该用户
|
||||||
* @param other 第三方获取的数据
|
* @param other 第三方获取的数据
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-10-17 14:22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserNotifyAnnounceRes {
|
||||||
|
private int notifyAnnounceId;
|
||||||
|
private String title;
|
||||||
|
private String content;
|
||||||
|
private long readDate;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<?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.fanxb.bookmark.business.user.dao.NotifyAnnounceDao">
|
||||||
|
|
||||||
|
<select id="queryUserAnnounce" resultType="com.fanxb.bookmark.business.user.vo.UserNotifyAnnounceRes">
|
||||||
|
select b.notifyAnnounceId,b.title,b.content,a.readDate from user_notify_announce a inner join notify_announce b
|
||||||
|
on a.notifyAnnounceId=b.notifyAnnounceId where a.userId=#{userId} and a.status=#{status}
|
||||||
|
<if test="status == 0">
|
||||||
|
and b.startDate<#{date} and b.endDate>#{date}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
@ -1,40 +1,40 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.fanxb.bookmark.business.user.dao.UserDao">
|
<mapper namespace="com.fanxb.bookmark.business.user.dao.UserDao">
|
||||||
|
|
||||||
|
|
||||||
<insert id="addOne" useGeneratedKeys="true" keyColumn="userId" keyProperty="userId">
|
<insert id="addOne" useGeneratedKeys="true" keyColumn="userId" keyProperty="userId">
|
||||||
insert into user (username, email, icon, password, createTime, lastLoginTime, version)
|
insert into user (username, email, icon, password, createTime, lastLoginTime, version)
|
||||||
value
|
value
|
||||||
(#{username}, #{email}, #{icon}, #{password}, #{createTime}, #{lastLoginTime}, #{version})
|
(#{username}, #{email}, #{icon}, #{password}, #{createTime}, #{lastLoginTime}, #{version})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="selectByUsernameOrEmail" resultType="com.fanxb.bookmark.common.entity.User">
|
<select id="selectByUsernameOrEmail" resultType="com.fanxb.bookmark.common.entity.User">
|
||||||
select *
|
select *
|
||||||
from user
|
from user
|
||||||
where username = #{name}
|
where username = #{name}
|
||||||
or email = #{email}
|
or email = #{email}
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="updateLastLoginTime">
|
<update id="updateLastLoginTime">
|
||||||
update user
|
update user
|
||||||
set lastLoginTime = #{time}
|
set lastLoginTime = #{time}
|
||||||
where userId = #{userId}
|
where userId = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="resetPassword">
|
<update id="resetPassword">
|
||||||
update user
|
update user
|
||||||
set password = #{password}
|
set password = #{password}
|
||||||
where email = #{email}
|
where email = #{email}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<select id="selectByUserIdOrGithubId" resultType="com.fanxb.bookmark.common.entity.User">
|
<select id="selectByUserIdOrGithubId" resultType="com.fanxb.bookmark.common.entity.User">
|
||||||
select *
|
select *
|
||||||
from user
|
from user
|
||||||
where userId = #{userId}
|
where userId = #{userId}
|
||||||
or githubId = #{githubId}
|
or githubId = #{githubId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@ -29,12 +29,12 @@ public class Result {
|
|||||||
return new Result(-1, "", null);
|
return new Result(-1, "", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result success(Object data) {
|
public static Result success() {
|
||||||
return new Result(1, "", data);
|
return new Result(1, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result failed(String message) {
|
public static Result success(Object data) {
|
||||||
return new Result(0, message, null);
|
return new Result(1, null, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch.client</groupId>
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||||
<version>7.12.0</version>
|
<version>7.14.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
|
<!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch.client</groupId>
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
<artifactId>elasticsearch-rest-client</artifactId>
|
<artifactId>elasticsearch-rest-client</artifactId>
|
||||||
<version>7.12.0</version>
|
<version>7.14.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--减负依赖-->
|
<!--减负依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -57,10 +57,6 @@
|
|||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user