【资源库-推荐管理】创客任务评审专家推荐
This commit is contained in:
parent
99952b884f
commit
79e05c109c
|
@ -30,9 +30,17 @@ public class TalentReferralController {
|
||||||
return AjaxResult.success(talentReferralService.doPRTalentReferral(prId, projectId));
|
return AjaxResult.success(talentReferralService.doPRTalentReferral(prId, projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/taskTalentReferral")
|
@GetMapping("/taskAchievementTalentReferral")
|
||||||
@ApiOperation(value = "任务推荐")
|
@ApiOperation(value = "任务成果推荐")
|
||||||
public AjaxResult taskTalentReferral(@RequestParam("taskId") Long taskId) {
|
public AjaxResult taskAchievementTalentReferral(@RequestParam("taskId") Long taskId) {
|
||||||
return AjaxResult.success(talentReferralService.taskTalentReferral(taskId));
|
return AjaxResult.success(talentReferralService.taskAchievementTalentReferral(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/taskExpertTalentReferral")
|
||||||
|
@ApiOperation(value = "任务专家推荐")
|
||||||
|
public AjaxResult taskExpertTalentReferral(@RequestParam("taskId") Long taskId) {
|
||||||
|
return AjaxResult.success(talentReferralService.taskExpertTalentReferral(taskId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package com.microservices.dms.referral.mapper;
|
package com.microservices.dms.referral.mapper;
|
||||||
|
|
||||||
import com.microservices.common.datasource.annotation.Slave;
|
import com.microservices.common.datasource.annotation.Slave;
|
||||||
|
import com.microservices.dms.achievementLibrary.domain.KeyValueVo;
|
||||||
|
import com.microservices.dms.referral.vo.ExpertVo;
|
||||||
import com.microservices.dms.referral.vo.IssuesVo;
|
import com.microservices.dms.referral.vo.IssuesVo;
|
||||||
import com.microservices.dms.referral.vo.PullRequestVo;
|
import com.microservices.dms.referral.vo.PullRequestVo;
|
||||||
import com.microservices.dms.referral.vo.TaskVo;
|
import com.microservices.dms.referral.vo.TaskVo;
|
||||||
|
import com.microservices.dms.resourceLibrary.domain.vo.KeyValVo;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -30,9 +33,13 @@ public interface TalentReferralMapper {
|
||||||
|
|
||||||
Long selectIdByLogin(@Param("login") String login);
|
Long selectIdByLogin(@Param("login") String login);
|
||||||
|
|
||||||
List<TaskVo> selectTaskByStatus();
|
List<TaskVo> selectTaskByStatus(@Param("statusIds") List<Integer> statusIds);
|
||||||
|
|
||||||
Map<String, Object> selectUsersById(@Param("id") Long id);
|
Map<String, Object> selectUsersById(@Param("id") Long id);
|
||||||
|
|
||||||
TaskVo selectTaskById(@Param("id") Long id);
|
TaskVo selectTaskById(@Param("id") Long id);
|
||||||
|
|
||||||
|
List<ExpertVo> selectExpertsBy(ExpertVo expertVo);
|
||||||
|
|
||||||
|
List<KeyValVo<Long,String>> allTaskWithExpertIds(@Param("type") String type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,20 @@ package com.microservices.dms.referral.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.microservices.common.core.exception.ServiceException;
|
import com.microservices.common.core.exception.ServiceException;
|
||||||
import com.microservices.common.core.utils.StringUtils;
|
import com.microservices.common.core.utils.StringUtils;
|
||||||
import com.microservices.dms.achievementLibrary.domain.Achievements;
|
import com.microservices.dms.achievementLibrary.domain.Achievements;
|
||||||
|
import com.microservices.dms.achievementLibrary.domain.KeyValueVo;
|
||||||
import com.microservices.dms.achievementLibrary.mapper.AchievementsMapper;
|
import com.microservices.dms.achievementLibrary.mapper.AchievementsMapper;
|
||||||
import com.microservices.dms.constant.ReferralConstant;
|
import com.microservices.dms.constant.ReferralConstant;
|
||||||
|
import com.microservices.dms.constant.TaskConstant;
|
||||||
import com.microservices.dms.referral.mapper.TalentReferralMapper;
|
import com.microservices.dms.referral.mapper.TalentReferralMapper;
|
||||||
|
import com.microservices.dms.referral.vo.ExpertVo;
|
||||||
import com.microservices.dms.referral.vo.IssueDto;
|
import com.microservices.dms.referral.vo.IssueDto;
|
||||||
import com.microservices.dms.referral.vo.IssuesVo;
|
import com.microservices.dms.referral.vo.IssuesVo;
|
||||||
import com.microservices.dms.referral.vo.TaskVo;
|
import com.microservices.dms.referral.vo.TaskVo;
|
||||||
import com.microservices.dms.resourceLibrary.domain.TaskResourceLibrary;
|
import com.microservices.dms.resourceLibrary.domain.vo.KeyValVo;
|
||||||
import com.microservices.dms.resourceLibrary.mapper.TaskResourceLibraryMapper;
|
|
||||||
import com.microservices.dms.utils.DmsGitLinkRequestUrl;
|
import com.microservices.dms.utils.DmsGitLinkRequestUrl;
|
||||||
import com.microservices.dms.utils.DmsRequestHelper;
|
import com.microservices.dms.utils.DmsRequestHelper;
|
||||||
import com.microservices.dms.utils.SimilarityService;
|
import com.microservices.dms.utils.SimilarityService;
|
||||||
|
@ -46,8 +49,7 @@ public class TalentReferralService {
|
||||||
// 获取项目贡献者数量
|
// 获取项目贡献者数量
|
||||||
JSONArray contributorsArray = dmsRequestHelper.getAllDataByPage(DmsGitLinkRequestUrl.CONTRIBUTORS(projectFullName), "list", "total_count");
|
JSONArray contributorsArray = dmsRequestHelper.getAllDataByPage(DmsGitLinkRequestUrl.CONTRIBUTORS(projectFullName), "list", "total_count");
|
||||||
|
|
||||||
return contributorsArray.stream().map(o -> (JSONObject) o).map(s -> s.getString("contributions")).filter(StringUtils::isNotBlank)
|
return contributorsArray.stream().map(o -> (JSONObject) o).map(s -> s.getString("contributions")).filter(StringUtils::isNotBlank).mapToLong(Long::parseLong).boxed().collect(Collectors.toSet());
|
||||||
.mapToLong(Long::parseLong).boxed().collect(Collectors.toSet());
|
|
||||||
|
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
logger.error("【{}】获取项目贡献者数量失败:{}", projectFullName, e.getMessage());
|
logger.error("【{}】获取项目贡献者数量失败:{}", projectFullName, e.getMessage());
|
||||||
|
@ -60,8 +62,7 @@ public class TalentReferralService {
|
||||||
// 获取项目成员者数量
|
// 获取项目成员者数量
|
||||||
JSONArray contributorsArray = dmsRequestHelper.getAllDataByPage(DmsGitLinkRequestUrl.QUERY_USER_FROM_PROJECT(projectFullName), "members", "total_count");
|
JSONArray contributorsArray = dmsRequestHelper.getAllDataByPage(DmsGitLinkRequestUrl.QUERY_USER_FROM_PROJECT(projectFullName), "members", "total_count");
|
||||||
|
|
||||||
return contributorsArray.stream().map(o -> (JSONObject) o).map(s -> s.getString("id"))
|
return contributorsArray.stream().map(o -> (JSONObject) o).map(s -> s.getString("id")).filter(StringUtils::isNotBlank).mapToLong(Long::parseLong).boxed().collect(Collectors.toSet());
|
||||||
.filter(StringUtils::isNotBlank).mapToLong(Long::parseLong).boxed().collect(Collectors.toSet());
|
|
||||||
|
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
logger.error("【{}】获取项目成员者数量失败:{}", projectFullName, e.getMessage());
|
logger.error("【{}】获取项目成员者数量失败:{}", projectFullName, e.getMessage());
|
||||||
|
@ -95,7 +96,7 @@ public class TalentReferralService {
|
||||||
|
|
||||||
public List<Map<String, Object>> doIssueTalentReferral(Long projectId, Long issueId) {
|
public List<Map<String, Object>> doIssueTalentReferral(Long projectId, Long issueId) {
|
||||||
List<Map.Entry<Long, Double>> entries = issueTalentReferral(projectId, issueId);
|
List<Map.Entry<Long, Double>> entries = issueTalentReferral(projectId, issueId);
|
||||||
return entries.stream().map(s->{
|
return entries.stream().map(s -> {
|
||||||
Map<String, Object> mm = talentReferralMapper.selectUsersById(s.getKey());
|
Map<String, Object> mm = talentReferralMapper.selectUsersById(s.getKey());
|
||||||
return mm;
|
return mm;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
@ -179,8 +180,7 @@ public class TalentReferralService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算每个负责人关闭的 PR数量
|
// 计算每个负责人关闭的 PR数量
|
||||||
closedPullRequests.stream().map(IssueDto::getReviewers).flatMap(List::stream)
|
closedPullRequests.stream().map(IssueDto::getReviewers).flatMap(List::stream).forEach(s -> userNameFractionMap.merge(s, 40.0D, Double::sum));
|
||||||
.forEach(s -> userNameFractionMap.merge(s, 40.0D, Double::sum));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ public class TalentReferralService {
|
||||||
|
|
||||||
public List<Map<String, Object>> doPRTalentReferral(Long projectId, Long prId) {
|
public List<Map<String, Object>> doPRTalentReferral(Long projectId, Long prId) {
|
||||||
List<Map.Entry<Long, Double>> entries = PRTalentReferral(projectId, prId);
|
List<Map.Entry<Long, Double>> entries = PRTalentReferral(projectId, prId);
|
||||||
return entries.stream().map(s->{
|
return entries.stream().map(s -> {
|
||||||
Map<String, Object> mm = talentReferralMapper.selectUsersById(s.getKey());
|
Map<String, Object> mm = talentReferralMapper.selectUsersById(s.getKey());
|
||||||
return mm;
|
return mm;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
@ -242,13 +242,10 @@ public class TalentReferralService {
|
||||||
|
|
||||||
public List<Map.Entry<Long, Double>> PRTalentReferral(Long projectId, Long prId) {
|
public List<Map.Entry<Long, Double>> PRTalentReferral(Long projectId, Long prId) {
|
||||||
List<IssueDto> openPullRequests = getPullRequests(projectId, "1");
|
List<IssueDto> openPullRequests = getPullRequests(projectId, "1");
|
||||||
openPullRequests = openPullRequests.stream().filter(e -> e.getReviewers().isEmpty())
|
openPullRequests = openPullRequests.stream().filter(e -> e.getReviewers().isEmpty()).collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (prId != null) {
|
if (prId != null) {
|
||||||
openPullRequests = openPullRequests.stream().filter(e -> Objects.equals((long) (e.getId()), prId))
|
openPullRequests = openPullRequests.stream().filter(e -> Objects.equals((long) (e.getId()), prId)).filter(e -> e.getReviewers().isEmpty()).collect(Collectors.toList());
|
||||||
.filter(e -> e.getReviewers().isEmpty())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
return PRTalentReferral(projectId, prId, openPullRequests);
|
return PRTalentReferral(projectId, prId, openPullRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +263,7 @@ public class TalentReferralService {
|
||||||
* 3、根据1中任务标题和任务正文 与数据仓库中名称和简介、详情比较 ;取前10获取对比计算分值大于0的结果
|
* 3、根据1中任务标题和任务正文 与数据仓库中名称和简介、详情比较 ;取前10获取对比计算分值大于0的结果
|
||||||
* 4、将2和3的结果相加,取前5个成果进行推荐
|
* 4、将2和3的结果相加,取前5个成果进行推荐
|
||||||
*/
|
*/
|
||||||
public List<Achievements> taskTalentReferral(Long taskId) {
|
public List<Achievements> taskAchievementTalentReferral(Long taskId) {
|
||||||
TaskVo task = talentReferralMapper.selectTaskById(taskId);
|
TaskVo task = talentReferralMapper.selectTaskById(taskId);
|
||||||
Achievements tCond = new Achievements();
|
Achievements tCond = new Achievements();
|
||||||
tCond.setSourceId(taskId);
|
tCond.setSourceId(taskId);
|
||||||
|
@ -276,9 +273,7 @@ public class TalentReferralService {
|
||||||
List<Achievements> result;
|
List<Achievements> result;
|
||||||
|
|
||||||
List<Long> trTaskIds = doTaskTalentReferral(task, taskAchievements);
|
List<Long> trTaskIds = doTaskTalentReferral(task, taskAchievements);
|
||||||
result = trTaskIds.stream().map(s -> taskAchievements.stream().filter(e -> e.getId().equals(s)).findFirst().orElse(null))
|
result = trTaskIds.stream().map(s -> taskAchievements.stream().filter(e -> e.getId().equals(s)).findFirst().orElse(null)).filter(Objects::nonNull).limit(5).collect(Collectors.toList());
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -302,6 +297,60 @@ public class TalentReferralService {
|
||||||
List<Map.Entry<Long, Double>> entryList = new ArrayList<>(step2Map.entrySet());
|
List<Map.Entry<Long, Double>> entryList = new ArrayList<>(step2Map.entrySet());
|
||||||
entryList.sort((entry1, entry2) -> Double.compare(entry2.getValue(), entry1.getValue()));
|
entryList.sort((entry1, entry2) -> Double.compare(entry2.getValue(), entry1.getValue()));
|
||||||
|
|
||||||
return entryList.stream().map(Map.Entry::getKey).limit(5).collect(Collectors.toList());
|
return entryList.stream().map(Map.Entry::getKey).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创客任务评审专家推荐
|
||||||
|
* 1、先查找创客任务状态未结束,并且已加入评审的数据,新增存储到数据表中
|
||||||
|
* 2、技术匹配度:系统中专家领域 与 任务是一样的领域 20%
|
||||||
|
* 3、根据1中任务标题和任务描述 与专家简介进行比较 ,匹配结果分数,取前10;30%
|
||||||
|
* 4、根据1中任务标题和任务描述 与已完成的任务标题与任务描述比较,匹配结果分数,取前3 ,前3个竞赛中对应的专家 分数*50%
|
||||||
|
*/
|
||||||
|
public Object taskExpertTalentReferral(Long taskId) {
|
||||||
|
TaskVo task = talentReferralMapper.selectTaskById(taskId);
|
||||||
|
List<KeyValueVo> categories = achievementsMapper.getAreasByName(null);
|
||||||
|
List<TaskVo> completedTasks = talentReferralMapper.selectTaskByStatus(Lists.newArrayList(TaskConstant.TASK_COMPLETE_STATUS));
|
||||||
|
List<ExpertVo> allExperts = talentReferralMapper.selectExpertsBy(new ExpertVo());
|
||||||
|
|
||||||
|
List<Long> expertIds = doTaskExpertTalentReferral(task, categories, completedTasks, allExperts);
|
||||||
|
return expertIds.stream().map(s -> allExperts.stream().filter(e -> e.getId().equals(s)).findFirst().orElse(null)).filter(Objects::nonNull).limit(3).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Long> doTaskExpertTalentReferral(TaskVo task, List<KeyValueVo> categories, List<TaskVo> completedTasks, List<ExpertVo> allExperts) {
|
||||||
|
|
||||||
|
Map<Long, String> v2k = categories.stream().collect(Collectors.toMap(KeyValueVo::getValue, KeyValueVo::getKey, (o, n) -> n));
|
||||||
|
|
||||||
|
String taskDomain = v2k.get(task.getCategoryId());
|
||||||
|
Map<Long, Double> step1Map = new TreeMap<>();
|
||||||
|
Map<Long, Double> step2Map = new TreeMap<>();
|
||||||
|
for (ExpertVo t1 : allExperts) {
|
||||||
|
if (Objects.equals(taskDomain, t1.getReviewAreaOne()) || Objects.equals(taskDomain, t1.getReviewAreaTwo()) || Objects.equals(taskDomain, t1.getReviewAreaThree())) {
|
||||||
|
step1Map.put(t1.getId(), 50.0D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<KeyValVo<Long, String>> allTaskWithExpertIds = talentReferralMapper.allTaskWithExpertIds("1");
|
||||||
|
Map<Long, String> t2e = allTaskWithExpertIds.stream().collect(Collectors.toMap(KeyValVo::getK, KeyValVo::getV, (o, n) -> n));
|
||||||
|
for (TaskVo t2 : completedTasks) {
|
||||||
|
double subjectFraction = SimilarityService.sentence(task.getName(), t2.getName());
|
||||||
|
double descFraction = SimilarityService.text(t2.getDescription(), task.getDescription());
|
||||||
|
|
||||||
|
String[] split = t2e.getOrDefault(t2.getId(), "").split(",");
|
||||||
|
for (String s : split) {
|
||||||
|
if (StringUtils.isNotBlank(s)) {
|
||||||
|
step2Map.put(Long.parseLong(s), (subjectFraction + descFraction) * 50.0D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
step1Map.forEach((k, v) -> step2Map.merge(k, v, Double::sum));
|
||||||
|
|
||||||
|
List<Map.Entry<Long, Double>> entryList = new ArrayList<>(step2Map.entrySet());
|
||||||
|
entryList.sort((entry1, entry2) -> Double.compare(entry2.getValue(), entry1.getValue()));
|
||||||
|
|
||||||
|
return entryList.stream().map(Map.Entry::getKey).collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.microservices.dms.referral.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ExpertVo {
|
||||||
|
Long id;
|
||||||
|
Long userId;
|
||||||
|
String expertName;
|
||||||
|
String nickname;
|
||||||
|
String reviewAreaOne;
|
||||||
|
String reviewAreaTwo;
|
||||||
|
String reviewAreaThree;
|
||||||
|
Integer status;
|
||||||
|
}
|
|
@ -70,7 +70,10 @@
|
||||||
select t.id,td.task_id, name, status, category_id, description
|
select t.id,td.task_id, name, status, category_id, description
|
||||||
from tasks t
|
from tasks t
|
||||||
join task_details td on t.id = td.task_id
|
join task_details td on t.id = td.task_id
|
||||||
where status in (3, 4)
|
where status in
|
||||||
|
<foreach collection="list" item="item" close=")" index="idx" open="(" separator=",">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUsersById" resultType="java.util.Map">
|
<select id="selectUsersById" resultType="java.util.Map">
|
||||||
|
@ -84,5 +87,21 @@
|
||||||
where t.id =#{id} and status in (3, 4)
|
where t.id =#{id} and status in (3, 4)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectExpertsBy" resultType="com.microservices.dms.referral.vo.ExpertVo">
|
||||||
|
select id,
|
||||||
|
user_id,
|
||||||
|
review_area_one,
|
||||||
|
review_area_two,
|
||||||
|
review_area_three,
|
||||||
|
(select IFNULL(nickname,login) from users u where u.id = e.user_id) as nickname
|
||||||
|
from experts e
|
||||||
|
where is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="allTaskWithExpertIds" resultType="com.microservices.dms.resourceLibrary.domain.vo.KeyValVo">
|
||||||
|
select container_id as 'k', group_concat(expert_id) as v from task_expert where container_type = #{type}
|
||||||
|
group by container_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue