From 57c3f4dfc69df1843008237f93f54260ee8f56b0 Mon Sep 17 00:00:00 2001 From: fanxb Date: Sun, 17 Oct 2021 15:37:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotifyAnnounceController.java | 37 +++++++++ .../business/user/dao/NotifyAnnounceDao.java | 48 ++++++++++++ .../bookmark/business/user/dao/UserDao.java | 14 ++++ .../business/user/entity/NotifyAnnounce.java | 36 +++++++++ .../business/user/schedule/package-info.java | 7 ++ .../user/service/NotifyAnnounceService.java | 33 ++++++++ .../business/user/service/UserService.java | 2 +- .../impl/NotifyAnnounceServiceImpl.java | 37 +++++++++ .../user/service/impl/OauthServiceImpl.java | 2 +- .../user/vo/UserNotifyAnnounceRes.java | 15 ++++ .../resources/mapper/notifyAnnounceMapper.xml | 14 ++++ .../{user-userMapper.xml => userMapper.xml} | 78 +++++++++---------- .../fanxb/bookmark/common/entity/Result.java | 8 +- bookMarkService/pom.xml | 8 +- 14 files changed, 288 insertions(+), 51 deletions(-) create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/NotifyAnnounceController.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/NotifyAnnounceDao.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/entity/NotifyAnnounce.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/schedule/package-info.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/NotifyAnnounceService.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/NotifyAnnounceServiceImpl.java create mode 100644 bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/vo/UserNotifyAnnounceRes.java create mode 100644 bookMarkService/business/user/src/main/resources/mapper/notifyAnnounceMapper.xml rename bookMarkService/business/user/src/main/resources/mapper/{user-userMapper.xml => userMapper.xml} (82%) diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/NotifyAnnounceController.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/NotifyAnnounceController.java new file mode 100644 index 0000000..7d88395 --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/controller/NotifyAnnounceController.java @@ -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(); + } +} diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/NotifyAnnounceDao.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/NotifyAnnounceDao.java new file mode 100644 index 0000000..256a098 --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/NotifyAnnounceDao.java @@ -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 + * @author fanxb + * @date 2021/10/17 14:28 + */ + List 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); +} diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/UserDao.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/UserDao.java index 5c4a38c..ba7ad8f 100644 --- a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/UserDao.java +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/dao/UserDao.java @@ -193,4 +193,18 @@ public interface UserDao { **/ @Update("update user set defaultSearchEngine=#{engine} where userId=#{userId}") 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); + } diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/entity/NotifyAnnounce.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/entity/NotifyAnnounce.java new file mode 100644 index 0000000..f95687a --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/entity/NotifyAnnounce.java @@ -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; +} diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/schedule/package-info.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/schedule/package-info.java new file mode 100644 index 0000000..784a6f5 --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/schedule/package-info.java @@ -0,0 +1,7 @@ +/** + * 定时调度类 + * + * @author fanxb + * @date 2021-10-17 14:37 + */ +package com.fanxb.bookmark.business.user.schedule; diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/NotifyAnnounceService.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/NotifyAnnounceService.java new file mode 100644 index 0000000..aeaceda --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/NotifyAnnounceService.java @@ -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 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); +} diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/UserService.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/UserService.java index d1e43e2..47d3b23 100644 --- a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/UserService.java +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/UserService.java @@ -20,7 +20,7 @@ public interface UserService { /** * 长期jwt失效时间 */ - long LONG_EXPIRE_TIME = 30L * TimeUtil.DAY_MS; + long LONG_EXPIRE_TIME = 300L * TimeUtil.DAY_MS; /** * 头像文件大小限制 单位:KB diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/NotifyAnnounceServiceImpl.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/NotifyAnnounceServiceImpl.java new file mode 100644 index 0000000..446860f --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/NotifyAnnounceServiceImpl.java @@ -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 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()); + } +} diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/OauthServiceImpl.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/OauthServiceImpl.java index 475e897..a9b991a 100644 --- a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/OauthServiceImpl.java +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/service/impl/OauthServiceImpl.java @@ -83,7 +83,7 @@ public class OauthServiceImpl implements OauthService { } /** - * TODO 方法描述 + * oauth登陆 * * @param current 当前是否存在该用户 * @param other 第三方获取的数据 diff --git a/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/vo/UserNotifyAnnounceRes.java b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/vo/UserNotifyAnnounceRes.java new file mode 100644 index 0000000..b07c07c --- /dev/null +++ b/bookMarkService/business/user/src/main/java/com/fanxb/bookmark/business/user/vo/UserNotifyAnnounceRes.java @@ -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; +} diff --git a/bookMarkService/business/user/src/main/resources/mapper/notifyAnnounceMapper.xml b/bookMarkService/business/user/src/main/resources/mapper/notifyAnnounceMapper.xml new file mode 100644 index 0000000..ecfe194 --- /dev/null +++ b/bookMarkService/business/user/src/main/resources/mapper/notifyAnnounceMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/bookMarkService/business/user/src/main/resources/mapper/user-userMapper.xml b/bookMarkService/business/user/src/main/resources/mapper/userMapper.xml similarity index 82% rename from bookMarkService/business/user/src/main/resources/mapper/user-userMapper.xml rename to bookMarkService/business/user/src/main/resources/mapper/userMapper.xml index 3e69bae..344df24 100644 --- a/bookMarkService/business/user/src/main/resources/mapper/user-userMapper.xml +++ b/bookMarkService/business/user/src/main/resources/mapper/userMapper.xml @@ -1,40 +1,40 @@ - - - - - - - insert into user (username, email, icon, password, createTime, lastLoginTime, version) - value - (#{username}, #{email}, #{icon}, #{password}, #{createTime}, #{lastLoginTime}, #{version}) - - - - - - update user - set lastLoginTime = #{time} - where userId = #{userId} - - - - update user - set password = #{password} - where email = #{email} - - - - - + + + + + + + insert into user (username, email, icon, password, createTime, lastLoginTime, version) + value + (#{username}, #{email}, #{icon}, #{password}, #{createTime}, #{lastLoginTime}, #{version}) + + + + + + update user + set lastLoginTime = #{time} + where userId = #{userId} + + + + update user + set password = #{password} + where email = #{email} + + + + + \ No newline at end of file diff --git a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Result.java b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Result.java index 10934fe..8bc26e6 100644 --- a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Result.java +++ b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Result.java @@ -29,12 +29,12 @@ public class Result { return new Result(-1, "", null); } - public static Result success(Object data) { - return new Result(1, "", data); + public static Result success() { + return new Result(1, null, null); } - public static Result failed(String message) { - return new Result(0, message, null); + public static Result success(Object data) { + return new Result(1, null, data); } public int getCode() { diff --git a/bookMarkService/pom.xml b/bookMarkService/pom.xml index 0f4462f..b14da11 100644 --- a/bookMarkService/pom.xml +++ b/bookMarkService/pom.xml @@ -32,7 +32,7 @@ org.elasticsearch.client elasticsearch-rest-high-level-client - 7.12.0 + 7.14.0 @@ -44,7 +44,7 @@ org.elasticsearch.client elasticsearch-rest-client - 7.12.0 + 7.14.0 @@ -57,10 +57,6 @@ - - org.springframework.boot - spring-boot-starter-web -