|
@@ -1,5 +1,6 @@
|
|
|
package shop.alien.store.service.impl;
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -10,10 +11,15 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.result.R;
|
|
import shop.alien.entity.result.R;
|
|
|
|
|
+import shop.alien.entity.store.LawyerServiceArea;
|
|
|
import shop.alien.entity.store.LawyerUser;
|
|
import shop.alien.entity.store.LawyerUser;
|
|
|
import shop.alien.mapper.LawyerUserMapper;
|
|
import shop.alien.mapper.LawyerUserMapper;
|
|
|
|
|
+import shop.alien.store.service.LawyerServiceAreaService;
|
|
|
import shop.alien.store.service.LawyerUserService;
|
|
import shop.alien.store.service.LawyerUserService;
|
|
|
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 律师用户 服务实现类
|
|
* 律师用户 服务实现类
|
|
|
*
|
|
*
|
|
@@ -27,6 +33,7 @@ import shop.alien.store.service.LawyerUserService;
|
|
|
public class LawyerUserServiceImpl extends ServiceImpl<LawyerUserMapper, LawyerUser> implements LawyerUserService {
|
|
public class LawyerUserServiceImpl extends ServiceImpl<LawyerUserMapper, LawyerUser> implements LawyerUserService {
|
|
|
|
|
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
|
|
+ private final LawyerServiceAreaService lawyerServiceAreaService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public R<IPage<LawyerUser>> getLawyerUserList(int pageNum, int pageSize, String name, String phone, Integer status) {
|
|
public R<IPage<LawyerUser>> getLawyerUserList(int pageNum, int pageSize, String name, String phone, Integer status) {
|
|
@@ -77,5 +84,186 @@ public class LawyerUserServiceImpl extends ServiceImpl<LawyerUserMapper, LawyerU
|
|
|
}
|
|
}
|
|
|
return R.fail("删除失败");
|
|
return R.fail("删除失败");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<Map<String, Object>> getLawyerDetail(Integer lawyerId) {
|
|
|
|
|
+ log.info("LawyerUserServiceImpl.getLawyerDetail?lawyerId={}", lawyerId);
|
|
|
|
|
+
|
|
|
|
|
+ LawyerUser lawyer = this.getById(lawyerId);
|
|
|
|
|
+ if (lawyer == null || lawyer.getDeleteFlag() == 1) {
|
|
|
|
|
+ return R.fail("律师不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("id", lawyer.getId());
|
|
|
|
|
+ result.put("name", lawyer.getName());
|
|
|
|
|
+ result.put("avatar", lawyer.getHeadImg() != null ? lawyer.getHeadImg() : "");
|
|
|
|
|
+ result.put("intro", lawyer.getPersonalIntroduction() != null ? lawyer.getPersonalIntroduction() :
|
|
|
|
|
+ (lawyer.getAccountBlurb() != null ? lawyer.getAccountBlurb() : "Ta还没有个人业务介绍"));
|
|
|
|
|
+ result.put("field", lawyer.getSpecialtyFields() != null ? lawyer.getSpecialtyFields() : "");
|
|
|
|
|
+ result.put("experience", lawyer.getPracticeYears() != null ? lawyer.getPracticeYears() : 0);
|
|
|
|
|
+ result.put("lawFirm", lawyer.getLawFirm() != null ? lawyer.getLawFirm() : "");
|
|
|
|
|
+ result.put("online", lawyer.getIsOnline() != null && lawyer.getIsOnline() == 1);
|
|
|
|
|
+ result.put("price", lawyer.getConsultationFee() != null ? lawyer.getConsultationFee() / 100 : 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取服务标签
|
|
|
|
|
+ QueryWrapper<LawyerServiceArea> tagQuery = new QueryWrapper<>();
|
|
|
|
|
+ tagQuery.eq("lawyer_user_id", lawyer.getId())
|
|
|
|
|
+ .eq("delete_flag", 0)
|
|
|
|
|
+ .eq("status", 1)
|
|
|
|
|
+ .orderByAsc("sort_order");
|
|
|
|
|
+ List<LawyerServiceArea> serviceAreas = lawyerServiceAreaService.list(tagQuery);
|
|
|
|
|
+ result.put("serviceTags", new ArrayList<>()); // TODO: 需要关联查询问题场景名称
|
|
|
|
|
+
|
|
|
|
|
+ // 额外字段
|
|
|
|
|
+ result.put("education", lawyer.getEducationBackground() != null ? lawyer.getEducationBackground() : "");
|
|
|
|
|
+ result.put("credentials", new ArrayList<>()); // TODO: 需要查询资质证书
|
|
|
|
|
+ result.put("caseCount", lawyer.getServiceCount() != null ? lawyer.getServiceCount() : 0);
|
|
|
|
|
+ // 评分:服务评分转换为0-5星评分
|
|
|
|
|
+ result.put("rating", lawyer.getServiceScore() != null ? lawyer.getServiceScore() / 20.0 : 0.0);
|
|
|
|
|
+ result.put("reviewCount", lawyer.getGoodReviewCount() != null ?
|
|
|
|
|
+ (lawyer.getGoodReviewCount() + (lawyer.getMediumReviewCount() != null ? lawyer.getMediumReviewCount() : 0) +
|
|
|
|
|
+ (lawyer.getBadReviewCount() != null ? lawyer.getBadReviewCount() : 0)) : 0);
|
|
|
|
|
+
|
|
|
|
|
+ return R.data(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<Map<Integer, Boolean>> getLawyerOnlineStatus(String lawyerIds) {
|
|
|
|
|
+ log.info("LawyerUserServiceImpl.getLawyerOnlineStatus?lawyerIds={}", lawyerIds);
|
|
|
|
|
+
|
|
|
|
|
+ String[] ids = lawyerIds.split(",");
|
|
|
|
|
+ List<Integer> idList = Arrays.stream(ids)
|
|
|
|
|
+ .map(String::trim)
|
|
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
|
|
+ .map(Integer::parseInt)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (idList.isEmpty()) {
|
|
|
|
|
+ return R.data(new HashMap<>());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<LawyerUser> lawyers = new ArrayList<>(this.listByIds(idList));
|
|
|
|
|
+ Map<Integer, Boolean> result = new HashMap<>();
|
|
|
|
|
+ for (LawyerUser lawyer : lawyers) {
|
|
|
|
|
+ result.put(lawyer.getId(), lawyer.getIsOnline() != null && lawyer.getIsOnline() == 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.data(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<Map<String, Object>> getRecommendedLawyerList(int page, int pageSize, Integer categoryId, String keyword, String sortBy) {
|
|
|
|
|
+ log.info("LawyerUserServiceImpl.getRecommendedLawyerList?page={},pageSize={},categoryId={},keyword={},sortBy={}",
|
|
|
|
|
+ page, pageSize, categoryId, keyword, sortBy);
|
|
|
|
|
+
|
|
|
|
|
+ int pageNum = page > 0 ? page : 1;
|
|
|
|
|
+ int pageSizeNum = pageSize > 0 ? pageSize : 10;
|
|
|
|
|
+
|
|
|
|
|
+ // 构建查询条件
|
|
|
|
|
+ QueryWrapper<LawyerUser> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("delete_flag", 0)
|
|
|
|
|
+ .eq("status", 1) // 已启用
|
|
|
|
|
+ .eq("order_receiving_status", 1); // 接单中
|
|
|
|
|
+
|
|
|
|
|
+ // 关键词搜索(律师姓名)
|
|
|
|
|
+ if (StringUtils.hasText(keyword)) {
|
|
|
|
|
+ queryWrapper.like("name", keyword);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 分类筛选:通过律师服务领域关联表查询
|
|
|
|
|
+ if (categoryId != null) {
|
|
|
|
|
+ QueryWrapper<LawyerServiceArea> areaQuery = new QueryWrapper<>();
|
|
|
|
|
+ areaQuery.eq("problem_scenar_id", categoryId)
|
|
|
|
|
+ .eq("delete_flag", 0)
|
|
|
|
|
+ .eq("status", 1);
|
|
|
|
|
+ List<LawyerServiceArea> serviceAreas = lawyerServiceAreaService.list(areaQuery);
|
|
|
|
|
+ if (!serviceAreas.isEmpty()) {
|
|
|
|
|
+ List<Integer> lawyerIds = serviceAreas.stream()
|
|
|
|
|
+ .map(LawyerServiceArea::getLawyerUserId)
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (!lawyerIds.isEmpty()) {
|
|
|
|
|
+ queryWrapper.in("id", lawyerIds);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有匹配的律师,返回空结果
|
|
|
|
|
+ queryWrapper.eq("id", -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ queryWrapper.eq("id", -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 排序:优先推荐律师 -> 在线律师 -> 创建时间
|
|
|
|
|
+ // 基础排序:推荐状态(推荐的在前面)、在线状态(在线的在前面)、创建时间(最老的在前面)
|
|
|
|
|
+ queryWrapper.orderByDesc("is_recommended") // 优先推荐律师(1在前,0在后)
|
|
|
|
|
+ .orderByDesc("is_online") // 然后在线律师(1在前,0在后)
|
|
|
|
|
+ .orderByAsc("created_time"); // 最后按创建时间倒序(最新的在前)
|
|
|
|
|
+
|
|
|
|
|
+ // 根据sortBy参数添加额外排序
|
|
|
|
|
+ switch (sortBy) {
|
|
|
|
|
+ case "price":
|
|
|
|
|
+ queryWrapper.orderByAsc("consultation_fee"); // 价格升序
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "experience":
|
|
|
|
|
+ queryWrapper.orderByDesc("practice_years"); // 经验降序
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "recommend":
|
|
|
|
|
+ default:
|
|
|
|
|
+ // 推荐排序:推荐排序号(升序,数字小的在前)、服务评分(降序,分数高的在前)
|
|
|
|
|
+ queryWrapper.orderByAsc("recommend_sort")
|
|
|
|
|
+ .orderByDesc("service_score");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 分页查询
|
|
|
|
|
+ Page<LawyerUser> pageObj = new Page<>(pageNum, pageSizeNum);
|
|
|
|
|
+ IPage<LawyerUser> pageResult = this.page(pageObj, queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为前端需要的格式
|
|
|
|
|
+ List<Map<String, Object>> records = pageResult.getRecords().stream().map(lawyer -> {
|
|
|
|
|
+ Map<String, Object> lawyerMap = new HashMap<>();
|
|
|
|
|
+ lawyerMap.put("id", lawyer.getId());
|
|
|
|
|
+ lawyerMap.put("name", lawyer.getName());
|
|
|
|
|
+ lawyerMap.put("avatar", lawyer.getHeadImg() != null ? lawyer.getHeadImg() : "");
|
|
|
|
|
+ lawyerMap.put("intro", lawyer.getPersonalIntroduction() != null ? lawyer.getPersonalIntroduction() :
|
|
|
|
|
+ (lawyer.getAccountBlurb() != null ? lawyer.getAccountBlurb() : "Ta还没有个人业务介绍"));
|
|
|
|
|
+ lawyerMap.put("field", lawyer.getSpecialtyFields() != null ? lawyer.getSpecialtyFields() : "");
|
|
|
|
|
+ lawyerMap.put("experience", lawyer.getPracticeYears() != null ? lawyer.getPracticeYears() : 0);
|
|
|
|
|
+ lawyerMap.put("lawFirm", lawyer.getLawFirm() != null ? lawyer.getLawFirm() : "");
|
|
|
|
|
+ lawyerMap.put("online", lawyer.getIsOnline() != null && lawyer.getIsOnline() == 1);
|
|
|
|
|
+ // 咨询价格从分转换为元
|
|
|
|
|
+ lawyerMap.put("price", lawyer.getConsultationFee() != null ? lawyer.getConsultationFee() / 100 : 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取服务标签(通过律师服务领域关联表)
|
|
|
|
|
+ QueryWrapper<LawyerServiceArea> tagQuery = new QueryWrapper<>();
|
|
|
|
|
+ tagQuery.eq("lawyer_user_id", lawyer.getId())
|
|
|
|
|
+ .eq("delete_flag", 0)
|
|
|
|
|
+ .eq("status", 1)
|
|
|
|
|
+ .orderByAsc("sort_order");
|
|
|
|
|
+ List<LawyerServiceArea> serviceAreas = lawyerServiceAreaService.list(tagQuery);
|
|
|
|
|
+ // TODO: 这里需要关联查询问题场景名称,暂时返回空数组
|
|
|
|
|
+ lawyerMap.put("serviceTags", new ArrayList<>());
|
|
|
|
|
+
|
|
|
|
|
+ return lawyerMap;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("records", records);
|
|
|
|
|
+ result.put("total", pageResult.getTotal());
|
|
|
|
|
+ result.put("page", pageNum);
|
|
|
|
|
+ result.put("pageSize", pageSizeNum);
|
|
|
|
|
+
|
|
|
|
|
+ return R.data(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<Map<String, Object>> getRecommendedLawyersBySession(String sessionId, Integer messageId) {
|
|
|
|
|
+ log.info("LawyerUserServiceImpl.getRecommendedLawyersBySession?sessionId={},messageId={}", sessionId, messageId);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 根据会话ID查询AI交互日志,获取关联的问题场景ID,然后推荐相关律师
|
|
|
|
|
+ // 这里暂时返回推荐列表(可以复用上面的逻辑)
|
|
|
|
|
+ return getRecommendedLawyerList(1, 10, null, null, "recommend");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|