This commit is contained in:
oneao committed 2026-01-04 17:31:04 +08:00
1 parent fac3206497
commit dc885119a0
43 files changed
+927 -364

No files matched your search

@@ -1,22 +0,0 @@
package cn.link56.base.controller;
import cn.link56.base.model.vo.BaseDataVO;
import cn.link56.base.service.BaseDataService;
import cn.link56.common.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/base")
public class BaseDataController {
@Resource
private BaseDataService baseDataService;
@GetMapping("/init")
public Result<BaseDataVO> initBaseData() {
return Result.success(baseDataService.getBaseData());
}
}
@@ -1,35 +0,0 @@
package cn.link56.base.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseDataVO {
private List<Industry> industries;
private List<Area> areas;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Industry {
private Long id;
private Integer xh;
private String name;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Area {
private String id;
private Integer xh;
private String name;
private String fatherId;
private List<Area> children;
}
}
@@ -1,108 +0,0 @@
package cn.link56.base.service;
import cn.link56.base.mapper.AreaMapper;
import cn.link56.base.mapper.IndustryMapper;
import cn.link56.base.model.po.Area;
import cn.link56.base.model.po.Industry;
import cn.link56.base.model.vo.BaseDataVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class BaseDataService {
@Resource
private IndustryMapper IndustryMapper;
@Resource
private AreaMapper AreaMapper;
public BaseDataVO getBaseData() {
BaseDataVO baseDataVO = new BaseDataVO();
// 查询可用行业
List<BaseDataVO.Industry> industries = IndustryMapper.selectList(
new LambdaQueryWrapper<Industry>()
.eq(Industry::getCanuse, "1")
).stream()
.map(industry -> new BaseDataVO.Industry(
industry.getId(),
industry.getXh(),
industry.getName()
))
.collect(Collectors.toList());
baseDataVO.setIndustries(industries);
// 地区
List<Area> allAreas = AreaMapper.listAllArea();
List<BaseDataVO.Area> areaTree = buildAreaTree(allAreas);
baseDataVO.setAreas(areaTree);
return baseDataVO;
}
/**
* BArea → BaseDataVO.Area 树
*/
private List<BaseDataVO.Area> buildAreaTree(List<Area> areas) {
if (areas == null || areas.isEmpty()) {
return Collections.emptyList();
}
// id -> VO
Map<String, BaseDataVO.Area> map = new HashMap<>(areas.size());
// 1️⃣ 先全部转 VO
for (Area a : areas) {
BaseDataVO.Area vo = new BaseDataVO.Area(
a.getId(),
a.getXh(),
a.getName(),
a.getFatherId(),
new ArrayList<>()
);
map.put(vo.getId(), vo);
}
// 2️⃣ 组装父子关系
List<BaseDataVO.Area> roots = new ArrayList<>();
for (BaseDataVO.Area area : map.values()) {
String parentId = area.getFatherId();
if (parentId == null || parentId.isEmpty()) {
roots.add(area);
} else {
BaseDataVO.Area parent = map.get(parentId);
if (parent != null) {
parent.getChildren().add(area);
}
}
}
// 3️⃣ 可选排序
sortTree(roots);
return roots;
}
/**
* 按 xh 排序(如果你用 order,也可以换)
*/
private void sortTree(List<BaseDataVO.Area> nodes) {
if (nodes == null || nodes.isEmpty()) {
return;
}
nodes.sort(Comparator.comparing(
BaseDataVO.Area::getXh,
Comparator.nullsLast(Integer::compareTo)
));
for (BaseDataVO.Area node : nodes) {
sortTree(node.getChildren());
}
}
}
@@ -4,10 +4,7 @@ import cn.link56.common.BasePageVO;
import cn.link56.common.Result;
import cn.link56.company.model.dto.QueryCompanyDTO;
import cn.link56.company.model.dto.UpdateCompanyDTO;
import cn.link56.company.model.vo.CompanyDetailVO;
import cn.link56.company.model.vo.QueryCompanyVO;
import cn.link56.company.model.vo.RecommendCompanyVO;
import cn.link56.company.model.vo.RecommendHotCompanyVO;
import cn.link56.company.model.vo.*;
import cn.link56.company.service.CompanyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -61,4 +58,13 @@ public class CompanyController {
return Result.success();
}
@GetMapping("/area")
public Result<List<AreaVO>> listAreas(){
return Result.success(companyService.listAreas());
}
@GetMapping("/industry")
public Result<List<IndustryVO>> listIndustries(){
return Result.success(companyService.listIndustries());
}
}
@@ -2,6 +2,7 @@ package cn.link56.company.controller;
import cn.link56.common.BasePageVO;
import cn.link56.common.Result;
import cn.link56.common.context.UserContext;
import cn.link56.company.model.dto.AddCompanyUserDTO;
import cn.link56.company.model.dto.DeleteCompanyUserDTO;
import cn.link56.company.model.dto.QueryCompanyUserDTO;
@@ -29,32 +30,33 @@ public class CompanyUserController {
}
@PostMapping("/add")
public Result<Void> addCompanyUser(@RequestBody @Validated AddCompanyUserDTO companyUserDTO){
public Result<Void> addCompanyUser(@RequestBody @Validated AddCompanyUserDTO companyUserDTO) {
companyUserService.addCompanyUser(companyUserDTO);
return Result.success();
}
@PostMapping("/update")
public Result<Void> updateCompanyUser(@RequestBody @Validated UpdateCompanyUserDTO companyUserDTO){
public Result<Void> updateCompanyUser(@RequestBody @Validated UpdateCompanyUserDTO companyUserDTO) {
companyUserService.updateCompanyUser(companyUserDTO);
return Result.success();
}
@PostMapping("/delete")
public Result<Void> deleteCompanyUser(@RequestBody @Validated DeleteCompanyUserDTO deleteCompanyUserDTO){
public Result<Void> deleteCompanyUser(@RequestBody @Validated DeleteCompanyUserDTO deleteCompanyUserDTO) {
companyUserService.deleteCompanyUser(deleteCompanyUserDTO);
return Result.success();
}
@GetMapping("/chat/{companyId}")
public Result<List<ChatUserVO>> listCompanyChatUsers(@PathVariable("companyId") Long companyId){
public Result<List<ChatUserVO>> listCompanyChatUsers(@PathVariable("companyId") Long companyId) {
List<ChatUserVO> data = companyUserService.listCompanyChatUsers(companyId);
return Result.success(data);
}
@GetMapping("/profile/{userId}")
public Result<CompanyUserProfileVO> getCompanyUserProfile(@PathVariable("userId") Long userId){
public Result<CompanyUserProfileVO> getCompanyUserProfile(@PathVariable("userId") Long userId) {
CompanyUserProfileVO companyUserProfileVO =companyUserService.getCompanyUserProfile(userId);
return Result.success(companyUserProfileVO);
}
}
@@ -13,11 +13,5 @@ import java.util.List;
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);
}
@@ -0,0 +1,17 @@
package cn.link56.company.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AreaVO {
private String id;
private Integer xh;
private String name;
private String fatherId;
private List<AreaVO> children;
}
@@ -0,0 +1,14 @@
package cn.link56.company.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IndustryVO {
private Long id;
private Integer xh;
private String name;
}
@@ -1,5 +1,9 @@
package cn.link56.company.service;
import cn.link56.base.mapper.AreaMapper;
import cn.link56.base.mapper.IndustryMapper;
import cn.link56.base.model.po.Area;
import cn.link56.base.model.po.Industry;
import cn.link56.common.BasePageVO;
import cn.link56.common.context.UserContext;
import cn.link56.common.exception.BusinessException;
@@ -9,10 +13,7 @@ import cn.link56.company.model.dto.UpdateCompanyDTO;
import cn.link56.company.model.middle.RecommendCompanyRow;
import cn.link56.company.model.po.Company;
import cn.link56.company.model.po.CompanyUser;
import cn.link56.company.model.vo.CompanyDetailVO;
import cn.link56.company.model.vo.QueryCompanyVO;
import cn.link56.company.model.vo.RecommendCompanyVO;
import cn.link56.company.model.vo.RecommendHotCompanyVO;
import cn.link56.company.model.vo.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -23,8 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -33,6 +33,10 @@ public class CompanyService extends ServiceImpl<CompanyMapper, Company> {
private CompanyMapper companyMapper;
@Resource
private CompanyUserService companyUserService;
@Resource
private IndustryMapper industryMapper;
@Resource
private AreaMapper areaMapper;
public List<RecommendCompanyVO> listRecommend() {
List<RecommendCompanyRow> rows = companyMapper.listRecommend();
@@ -242,4 +246,86 @@ public class CompanyService extends ServiceImpl<CompanyMapper, Company> {
companyUserService.updateCompanyAvatar(company.getId(),company.getLogo());
}
public List<IndustryVO> listIndustries() {
LambdaQueryWrapper<Industry> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Industry::getCanuse,"1");
List<Industry> industries = industryMapper.selectList(queryWrapper);
return industries.stream()
.map(industry -> new IndustryVO(
industry.getId(),
industry.getXh(),
industry.getName()
))
.collect(Collectors.toList());
}
public List<AreaVO> listAreas() {
List<Area> allAreas = areaMapper.listAllArea();
return buildAreaTree(allAreas);
}
/**
* BArea → Area 树
*/
private List<AreaVO> buildAreaTree(List<Area> areas) {
if (areas == null || areas.isEmpty()) {
return Collections.emptyList();
}
// id -> VO
Map<String, AreaVO> map = new HashMap<>(areas.size());
// 1️⃣ 先全部转 VO
for (Area a : areas) {
AreaVO vo = new AreaVO(
a.getId(),
a.getXh(),
a.getName(),
a.getFatherId(),
new ArrayList<>()
);
map.put(vo.getId(), vo);
}
// 2️⃣ 组装父子关系
List<AreaVO> roots = new ArrayList<>();
for (AreaVO area : map.values()) {
String parentId = area.getFatherId();
if (parentId == null || parentId.isEmpty()) {
roots.add(area);
} else {
AreaVO parent = map.get(parentId);
if (parent != null) {
parent.getChildren().add(area);
}
}
}
// 3️⃣ 可选排序
sortTree(roots);
return roots;
}
/**
* 按 xh 排序(如果你用 order,也可以换)
*/
private void sortTree(List<AreaVO> nodes) {
if (nodes == null || nodes.isEmpty()) {
return;
}
nodes.sort(Comparator.comparing(
AreaVO::getXh,
Comparator.nullsLast(Integer::compareTo)
));
for (AreaVO node : nodes) {
sortTree(node.getChildren());
}
}
}
@@ -15,6 +15,9 @@ 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.mapper.ImFriendMapper;
import cn.link56.im.mapper.ImGroupMapper;
import cn.link56.im.mapper.ImGroupUserMapper;
import cn.link56.im.storage.SessionManager;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -330,13 +333,12 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
}
public CompanyUserProfileVO getCompanyUserProfile(Long userId) {
CompanyUser companyUserPO = companyUserMapper.selectById(userId);
if (companyUserPO == null) {
return null;
}
CompanyUserProfileVO cardVO = new CompanyUserProfileVO();
CompanyUserProfileVO profileVO = new CompanyUserProfileVO();
// ===== 用户(联系人)=====
CompanyUserProfileVO.User userVO = new CompanyUserProfileVO.User();
@@ -364,8 +366,9 @@ public class CompanyUserService extends ServiceImpl<CompanyUserMapper, CompanyUs
);
}
cardVO.setUser(userVO);
cardVO.setCompany(companyVO);
return cardVO;
profileVO.setUser(userVO);
profileVO.setCompany(companyVO);
return profileVO;
}
}
@@ -71,7 +71,7 @@ public class ImController {
@PostMapping("/private/update/unread")
public Result<Void> updatePrivateUnread(@RequestBody UpdatePrivateUnreadDTO dto){
Long userId = dto.getUserId();
Long userId = UserContext.getUserId();
Long friendId = dto.getFriendId();
imFriendService.decreaseUnreadCount(userId,friendId);
@@ -81,7 +81,7 @@ public class ImController {
@PostMapping("/group/update/unread")
public Result<Void> updateGroup(@RequestBody UpdateGroupUnreadDTO dto){
Long userId = dto.getUserId();
Long userId = UserContext.getUserId();
Long groupId = dto.getGroupId();
imGroupUserService.decreaseUnreadCount(groupId,userId);
@@ -103,4 +103,14 @@ public class ImController {
return Result.success(groupProfileVO);
}
@GetMapping("/unreadCount")
public Result<Long> getAllUnreadCount(){
Long userId = UserContext.getUserId();
Long friendUnread = imFriendService.getAllUnreadCount(userId);
Long groupUnread = imGroupUserService.getAllUnreadCount(userId);
return Result.success(friendUnread + groupUnread);
}
}
@@ -6,6 +6,7 @@ import cn.link56.im.model.vo.QueryFriendVO;
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;
@@ -41,4 +42,8 @@ public interface ImFriendMapper extends BaseMapper<ImFriend> {
@Param("userId") Long userId,
@Param("friendId") Long friendId
);
@Select("SELECT SUM(b_unread_count) FROM b_im_friend WHERE b_user_id = #{userId}")
Long selectAllUnreadCount(@Param("userId") Long userId);
}
@@ -6,6 +6,7 @@ import cn.link56.im.model.vo.QueryGroupVO;
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;
@@ -19,10 +20,14 @@ public interface ImGroupMapper extends BaseMapper<ImGroup> {
@Param("id") Long id
);
Long selectGroupTotal(@Param("userId") Long userId,
@Param("name") String name);
Long selectGroupTotal(
@Param("userId") Long userId,
@Param("name") String name
);
GroupProfileVO selectGroupProfile(
@Param("groupId") Long groupId,
@Param("userId") Long userId);
@Param("userId") Long userId
);
}
@@ -5,6 +5,7 @@ import cn.link56.im.model.vo.QueryGroupUserVO;
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;
@@ -14,4 +15,8 @@ public interface ImGroupUserMapper extends BaseMapper<ImGroupUser> {
@Param("groupId") Long groupId,
@Param("userName") String userName
);
@Select("SELECT SUM(b_unread_count) FROM b_im_group_user WHERE b_user_id = #{userId}")
Long selectAllUnreadCount(@Param("userId") Long userId);
}
@@ -9,5 +9,4 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class UpdateGroupUnreadDTO {
private Long groupId;
private Long userId;
}
@@ -8,6 +8,5 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class UpdatePrivateUnreadDTO {
private Long userId;
private Long friendId;
}
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@@ -11,5 +13,12 @@ public class FriendProfileVO {
private Long friendId;
private String friendName;
private String friendAvatar;
private Date lastMessageTime;
private Integer lastMessageType;
private String lastMessageContent;
private Integer unreadCount;
private Boolean isOnline;
}
@@ -25,7 +25,7 @@ public class ImFriendService extends ServiceImpl<ImFriendMapper, ImFriend> {
private ImFriendMapper imFriendMapper;
public void createFriend(Long userId,Long friendId){
// 先检查是否存在
// 先检查是否存在好友关系
LambdaQueryWrapper<ImFriend> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ImFriend::getUserId,userId)
.eq(ImFriend::getFriendId,friendId);
@@ -108,6 +108,14 @@ public class ImFriendService extends ServiceImpl<ImFriendMapper, ImFriend> {
public FriendProfileVO getFriendProfile(Long friendId) {
Long userId = UserContext.getUserId();
return imFriendMapper.selectFriendProfile(userId, friendId);
FriendProfileVO friendProfileVO = imFriendMapper.selectFriendProfile(userId, friendId);
friendProfileVO.setIsOnline(SessionManager.isOnline(friendId));
return friendProfileVO;
}
public Long getAllUnreadCount(Long userId){
return imFriendMapper.selectAllUnreadCount(userId);
}
}
@@ -50,4 +50,6 @@ public class ImGroupService extends ServiceImpl<ImGroupMapper, ImGroup>{
return imGroupMapper.selectGroupProfile(groupId,userId);
}
}
@@ -94,4 +94,7 @@ public class ImGroupUserService extends ServiceImpl<ImGroupUserMapper, ImGroupUs
imGroupUserMapper.update(updateWrapper);
}
public Long getAllUnreadCount(Long userId){
return imGroupUserMapper.selectAllUnreadCount(userId);
}
}
@@ -30,5 +30,21 @@
sheng.b_order ASC,
shi.b_order ASC
</select>
<select id="selectCompanyByUserId" resultType="cn.link56.company.model.po.Company">
SELECT
c.b_id as id,
c.b_name as name,
c.b_logo as logo,
c.b_profile as profile,
c.b_area as area,
c.b_industry as industry
FROM
b_company c
INNER JOIN b_company_user cu ON cu.b_company_id = c.b_id
WHERE
cu.b_id = #{userId}
</select>
</mapper>
@@ -13,7 +13,7 @@
u.b_name AS friendName,
u.b_avatar AS friendAvatar,
f.b_unread_count AS unreadCount,
m.b_send_time AS lastMessageTime,
m.b_send_time AS lastMessageTime,
m.b_type AS lastMessageType,
m.b_content AS lastMessageContent,
ROW_NUMBER() OVER (
@@ -64,12 +64,17 @@
<select id="selectFriendProfile" resultType="cn.link56.im.model.vo.FriendProfileVO">
SELECT
f.b_friend_id AS friendId,
u.b_name AS friendName,
u.b_avatar AS friendAvatar,
f.b_unread_count AS unreadCount
f.b_friend_id AS friendId,
u.b_name AS friendName,
u.b_avatar AS friendAvatar,
f.b_unread_count AS unreadCount,
m.b_send_time AS lastMessageTime,
m.b_type AS lastMessageType,
m.b_content AS lastMessageContent
FROM b_im_friend f
INNER JOIN b_company_user u ON f.b_friend_id = u.b_id
INNER JOIN b_company_user u ON f.b_friend_id = u.b_id
LEFT JOIN b_im_private_message m ON f.b_last_message_id = m.b_id
WHERE f.b_user_id = #{userId} AND f.b_friend_id = #{friendId}
</select>
</mapper>