🎨 通过 UserService 统一查询作者信息
This commit is contained in:
parent
8d431d5835
commit
686cbb925e
@ -8,12 +8,12 @@ import lombok.Data;
|
||||
@Data
|
||||
public class Author {
|
||||
|
||||
private String idUser;
|
||||
private Integer idUser;
|
||||
|
||||
private String userNickname;
|
||||
|
||||
private String userAvatarURL;
|
||||
|
||||
private Integer userArticleCount;
|
||||
private String userArticleCount;
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.rymcu.vertical.mapper;
|
||||
import com.rymcu.vertical.core.mapper.Mapper;
|
||||
import com.rymcu.vertical.dto.ArticleDTO;
|
||||
import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||
import com.rymcu.vertical.dto.Author;
|
||||
import com.rymcu.vertical.entity.Article;
|
||||
import com.rymcu.vertical.entity.ArticleContent;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -23,13 +22,6 @@ public interface ArticleMapper extends Mapper<Article> {
|
||||
*/
|
||||
List<ArticleDTO> selectArticles(@Param("searchText") String searchText, @Param("tag") String tag);
|
||||
|
||||
/**
|
||||
* 根据用户 ID 获取作者信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Author selectAuthor(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 根据文章 ID 查询文章
|
||||
* @param id
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.rymcu.vertical.mapper;
|
||||
|
||||
import com.rymcu.vertical.core.mapper.Mapper;
|
||||
import com.rymcu.vertical.dto.Author;
|
||||
import com.rymcu.vertical.dto.UserDTO;
|
||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
||||
import com.rymcu.vertical.entity.User;
|
||||
@ -106,4 +107,10 @@ public interface UserMapper extends Mapper<User> {
|
||||
* @return
|
||||
*/
|
||||
Integer checkNicknameByIdUser(@Param("idUser") Integer idUser, @Param("nickname") String nickname);
|
||||
/**
|
||||
* 根据用户 ID 获取作者信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Author selectAuthor(@Param("id") Integer id);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.rymcu.vertical.service;
|
||||
|
||||
import com.rymcu.vertical.core.service.Service;
|
||||
import com.rymcu.vertical.dto.Author;
|
||||
import com.rymcu.vertical.dto.UserDTO;
|
||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
||||
import com.rymcu.vertical.entity.User;
|
||||
@ -100,4 +101,11 @@ public interface UserService extends Service<User> {
|
||||
* @return
|
||||
*/
|
||||
Integer findRoleWeightsByUser(Integer idUser);
|
||||
|
||||
/**
|
||||
* 查询作者信息
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
Author selectAuthor(Integer idUser);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
}
|
||||
|
||||
private ArticleDTO genArticle(ArticleDTO article, Integer type) {
|
||||
Author author = articleMapper.selectAuthor(article.getArticleAuthorId());
|
||||
Author author = userService.selectAuthor(article.getArticleAuthorId());
|
||||
article.setArticleAuthor(author);
|
||||
article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime()));
|
||||
List<ArticleTagDTO> tags = articleMapper.selectTags(article.getIdArticle());
|
||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.service.impl;
|
||||
|
||||
import com.rymcu.vertical.core.service.AbstractService;
|
||||
import com.rymcu.vertical.core.service.redis.RedisService;
|
||||
import com.rymcu.vertical.dto.Author;
|
||||
import com.rymcu.vertical.dto.TokenUser;
|
||||
import com.rymcu.vertical.dto.UserDTO;
|
||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
||||
@ -207,4 +208,9 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
||||
public Integer findRoleWeightsByUser(Integer idUser) {
|
||||
return userMapper.selectRoleWeightsByUser(idUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Author selectAuthor(Integer idUser) {
|
||||
return userMapper.selectAuthor(idUser);
|
||||
}
|
||||
}
|
||||
|
@ -38,11 +38,6 @@
|
||||
<result column="article_status" property="articleStatus"></result>
|
||||
<result column="updated_time" property="updatedTime"></result>
|
||||
</resultMap>
|
||||
<resultMap id="AuthorResultMap" type="com.rymcu.vertical.dto.Author">
|
||||
<result column="id" property="idUser"/>
|
||||
<result column="nickname" property="userNickname"/>
|
||||
<result column="avatar_url" property="userAvatarURL"/>
|
||||
</resultMap>
|
||||
<resultMap id="ArticleContentResultMap" type="com.rymcu.vertical.entity.ArticleContent">
|
||||
<result column="id_article" property="idArticle"/>
|
||||
<result column="article_content" property="articleContent"/>
|
||||
@ -78,9 +73,6 @@
|
||||
<select id="selectArticles" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where article_status = '0' order by updated_time desc
|
||||
</select>
|
||||
<select id="selectAuthor" resultMap="AuthorResultMap">
|
||||
select * from vertical_user where id = #{id}
|
||||
</select>
|
||||
<select id="selectArticleDTOById" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where art.id = #{id}
|
||||
<if test="type == 1">
|
||||
|
@ -41,6 +41,11 @@
|
||||
<result column="avatar_url" property="avatarUrl"/>
|
||||
<result column="signature" property="signature"/>
|
||||
</resultMap>
|
||||
<resultMap id="AuthorResultMap" type="com.rymcu.vertical.dto.Author">
|
||||
<result column="id" property="idUser"/>
|
||||
<result column="nickname" property="userNickname"/>
|
||||
<result column="avatar_url" property="userAvatarURL"/>
|
||||
</resultMap>
|
||||
<insert id="insertUserRole">
|
||||
insert into vertical_user_role (id_user,id_role,created_time) values (#{idUser},#{idRole},sysdate())
|
||||
</insert>
|
||||
@ -82,5 +87,8 @@
|
||||
<select id="checkNicknameByIdUser" resultType="java.lang.Integer">
|
||||
select count(*) from vertical_user where nickname = #{nickname} and id != #{idUser}
|
||||
</select>
|
||||
<select id="selectAuthor" resultMap="AuthorResultMap">
|
||||
select * from vertical_user where id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user