u
This commit is contained in:
1 parent
c26d1b3c81
commit
fac3206497
24 files changed
+364
-284
No files matched your search
+7
-1
@@ -7,9 +7,9 @@ import cn.link56.company.model.dto.DeleteCompanyUserDTO;
|
||||
import cn.link56.company.model.dto.QueryCompanyUserDTO;
|
||||
import cn.link56.company.model.dto.UpdateCompanyUserDTO;
|
||||
import cn.link56.company.model.vo.ChatUserVO;
|
||||
import cn.link56.company.model.vo.CompanyUserProfileVO;
|
||||
import cn.link56.company.model.vo.QueryCompanyUserVO;
|
||||
import cn.link56.company.service.CompanyUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -51,4 +51,10 @@ public class CompanyUserController {
|
||||
List<ChatUserVO> data = companyUserService.listCompanyChatUsers(companyId);
|
||||
return Result.success(data);
|
||||
}
|
||||
|
||||
@GetMapping("/profile/{userId}")
|
||||
public Result<CompanyUserProfileVO> getCompanyUserProfile(@PathVariable("userId") Long userId){
|
||||
CompanyUserProfileVO companyUserProfileVO =companyUserService.getCompanyUserProfile(userId);
|
||||
return Result.success(companyUserProfileVO);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,20 @@ import cn.link56.company.model.middle.RecommendCompanyRow;
|
||||
import cn.link56.company.model.po.Company;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CompanyMapper extends BaseMapper<Company> {
|
||||
List<RecommendCompanyRow> listRecommend();
|
||||
|
||||
@Select(
|
||||
"SELECT c.* " +
|
||||
"FROM b_company c " +
|
||||
"INNER JOIN b_company_user cu ON cu.company_id = c.id " +
|
||||
"WHERE cu.user_id = #{userId} "
|
||||
)
|
||||
Company selectCompanyByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package cn.link56.company.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CompanyUserProfileVO {
|
||||
private Company company;
|
||||
private User user;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class Company{
|
||||
private Long id;
|
||||
private String name;
|
||||
private String logo;
|
||||
private String profile;
|
||||
private List<String> areas;
|
||||
private List<String> industries;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class User{
|
||||
private Long id;
|
||||
private String name;
|
||||
private String avatar;
|
||||
private String position;
|
||||
private String email;
|
||||
private String phone;
|
||||
private Boolean isOnline;
|
||||
}
|
||||
}
|
||||
+41
@@ -13,6 +13,7 @@ import cn.link56.company.model.dto.UpdateCompanyUserDTO;
|
||||
import cn.link56.company.model.po.Company;
|
||||
import cn.link56.company.model.po.CompanyUser;
|
||||
import cn.link56.company.model.vo.ChatUserVO;
|
||||
import cn.link56.company.model.vo.CompanyUserProfileVO;
|
||||
import cn.link56.company.model.vo.QueryCompanyUserVO;
|
||||
import cn.link56.im.storage.SessionManager;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -327,4 +329,43 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
|
||||
return result;
|
||||
}
|
||||
|
||||
public CompanyUserProfileVO getCompanyUserProfile(Long userId) {
|
||||
|
||||
CompanyUser companyUserPO = companyUserMapper.selectById(userId);
|
||||
if (companyUserPO == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CompanyUserProfileVO cardVO = new CompanyUserProfileVO();
|
||||
|
||||
// ===== 用户(联系人)=====
|
||||
CompanyUserProfileVO.User userVO = new CompanyUserProfileVO.User();
|
||||
BeanUtils.copyProperties(companyUserPO, userVO);
|
||||
userVO.setIsOnline(SessionManager.isOnline(userId));
|
||||
|
||||
// ===== 公司(主体)=====
|
||||
Company companyPO = companyMapper.selectCompanyByUserId(userId);
|
||||
CompanyUserProfileVO.Company companyVO = new CompanyUserProfileVO.Company();
|
||||
BeanUtils.copyProperties(companyPO, companyVO);
|
||||
|
||||
if (companyPO.getIndustry() != null) {
|
||||
companyVO.setIndustries(
|
||||
Arrays.stream(companyPO.getIndustry().split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
if (companyPO.getArea() != null) {
|
||||
companyVO.setAreas(
|
||||
Arrays.stream(companyPO.getArea().split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
cardVO.setUser(userVO);
|
||||
cardVO.setCompany(companyVO);
|
||||
return cardVO;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import cn.link56.post.model.vo.QueryPublicPostVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,4 +48,7 @@ public interface PostMapper extends BaseMapper<Post> {
|
||||
@Param("title") String title,
|
||||
@Param("tag") String tag
|
||||
);
|
||||
|
||||
@Update("UPDATE b_post SET b_active_time = GETDATE() WHERE b_id = #{postId}")
|
||||
int updateActiveTime(@Param("postId") Long postId);
|
||||
}
|
||||
@@ -59,4 +59,9 @@ public class Post {
|
||||
fill = FieldFill.INSERT_UPDATE
|
||||
)
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(
|
||||
value = "b_active_time"
|
||||
)
|
||||
private Date activeTime;
|
||||
}
|
||||
+6
@@ -2,6 +2,7 @@ package cn.link56.post.service;
|
||||
|
||||
import cn.link56.common.utils.snowflake.idgen.IdGenerator;
|
||||
import cn.link56.post.mapper.PostCommentMapper;
|
||||
import cn.link56.post.mapper.PostMapper;
|
||||
import cn.link56.post.model.dto.CreatePostCommentDTO;
|
||||
import cn.link56.post.model.po.PostComment;
|
||||
import cn.link56.post.model.po.PostView;
|
||||
@@ -30,6 +31,9 @@ public class PostCommentService extends ServiceImpl<PostCommentMapper, PostComme
|
||||
@Resource
|
||||
private PostStatService postStatService;
|
||||
|
||||
@Resource
|
||||
private PostMapper postMapper;
|
||||
|
||||
/**
|
||||
* 根据文章 id 获取浏览总数
|
||||
*/
|
||||
@@ -134,6 +138,8 @@ public class PostCommentService extends ServiceImpl<PostCommentMapper, PostComme
|
||||
CreatePostCommentVO commentVO = new CreatePostCommentVO();
|
||||
BeanUtils.copyProperties(postComment,commentVO);
|
||||
|
||||
// 更新活跃数量
|
||||
postMapper.updateActiveTime(postComment.getPostId());
|
||||
return commentVO;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import cn.link56.post.model.po.Post;
|
||||
import cn.link56.post.model.po.PostComment;
|
||||
import cn.link56.post.model.vo.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -47,6 +48,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
post.setId(IdGenerator.nextId());
|
||||
post.setCompanyId(UserContext.getCompanyId());
|
||||
post.setTag(joinTags(dto.getTags()));
|
||||
post.setActiveTime(new Date());
|
||||
|
||||
handleUpdatePublishTime(post, dto.getStatus());
|
||||
|
||||
@@ -71,6 +73,10 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
handleUpdatePublishTime(post, dto.getStatus());
|
||||
|
||||
postMapper.updateById(post);
|
||||
|
||||
// 更新活跃时间
|
||||
postMapper.updateActiveTime(post.getId());
|
||||
|
||||
return buildEditPostVO(post);
|
||||
}
|
||||
|
||||
@@ -250,7 +256,6 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
List<QueryPublicPostVO> queryEditorPostVOS = postMapper.selectPublicPostPage(offset, limit, title, tag);
|
||||
Long total = postMapper.selectPublicPostTotal(title, tag);
|
||||
|
||||
|
||||
return new BasePageVO<QueryPublicPostVO>(total, queryEditorPostVOS);
|
||||
}
|
||||
|
||||
@@ -275,14 +280,6 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
postVO.setViewCount(viewTotal);
|
||||
postVO.setCommentCount(commentTotal);
|
||||
|
||||
PostComment latestCommentByPostId = postCommentService.getLatestCommentByPostId(id);
|
||||
|
||||
if (latestCommentByPostId == null){
|
||||
postVO.setActiveTime(post.getUpdateTime());
|
||||
} else {
|
||||
postVO.setActiveTime(latestCommentByPostId.getCreateTime());
|
||||
}
|
||||
|
||||
return postVO;
|
||||
}
|
||||
|
||||
@@ -300,4 +297,5 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
|
||||
return postCompanyVO;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-25
@@ -163,41 +163,28 @@
|
||||
t.commentCount,
|
||||
t.activeTime
|
||||
FROM (
|
||||
SELECT
|
||||
SELECT
|
||||
p.b_id AS id,
|
||||
p.b_title AS title,
|
||||
p.b_tag AS tagsString,
|
||||
p.b_company_id AS companyId,
|
||||
bc.b_name AS companyName,
|
||||
|
||||
ISNULL(pv.viewCount, 0) AS viewCount,
|
||||
ISNULL(pc.commentCount, 0) AS commentCount,
|
||||
ISNULL(ps.b_view_count, 0) AS viewCount,
|
||||
ISNULL(ps.b_comment_count, 0) AS commentCount,
|
||||
|
||||
-- 活跃时间:最后评论时间优先
|
||||
ISNULL(pc.lastCommentTime, p.b_update_time) AS activeTime,
|
||||
p.b_active_time AS activeTime,
|
||||
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY ISNULL(pc.lastCommentTime, p.b_update_time) DESC
|
||||
) AS rn
|
||||
ORDER BY p.b_update_time DESC
|
||||
) AS rn
|
||||
FROM b_post p
|
||||
LEFT JOIN b_company bc ON bc.b_id = p.b_company_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS viewCount
|
||||
FROM b_post_view
|
||||
GROUP BY b_post_id
|
||||
) pv ON pv.b_post_id = p.b_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS commentCount,
|
||||
MAX(b_create_time) AS lastCommentTime
|
||||
FROM b_post_comment
|
||||
GROUP BY b_post_id
|
||||
) pc ON pc.b_post_id = p.b_id
|
||||
LEFT JOIN b_company bc
|
||||
ON bc.b_id = p.b_company_id
|
||||
LEFT JOIN b_post_stat ps
|
||||
ON ps.b_post_id = p.b_id
|
||||
<where>
|
||||
AND p.b_status = 1
|
||||
p.b_status = 1
|
||||
<if test="title != null and title != ''">
|
||||
AND p.b_title LIKE '%' + #{title} + '%'
|
||||
</if>
|
||||
@@ -205,10 +192,11 @@
|
||||
AND p.b_tag LIKE '%' + #{tag} + '%'
|
||||
</if>
|
||||
</where>
|
||||
) t
|
||||
) t
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectPublicPostTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM b_post p
|
||||
|
||||
Reference in new issue
Block a user