提交发起

This commit is contained in:
Guava
2023-06-29 18:01:07 +08:00
parent ee9ace5d9c
commit e1fc23ba57
16 changed files with 431 additions and 25 deletions

View File

@@ -0,0 +1,85 @@
package com.xboe.api;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.xboe.api.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.IntStream;
@Service
@Slf4j
public class ThirdApi {
public static final ForkJoinPool REQUEST_TASK = new ForkJoinPool(100);
@Value("${orgTree.orgChildTreeList}")
private String orgChildTreeListUrl;
@Value("${audience.usersByAudienceList}")
private String usersByAudienceList;
@Value("${userBasic.searchUserList}")
private String searchUserListUrl;
public List<UserInfoList> getAllUserList(UserListParam userListParam, String token) {
log.info("获取用户");
String resp = Optional.ofNullable(HttpRequest.post(searchUserListUrl).body(JSONUtil.toJsonStr(userListParam)).header("token", token).execute().body()).orElseThrow(() -> new RuntimeException("token校验失败"));
System.out.println(resp);
return Opt.ofBlankAble(resp).map(t -> JSONUtil.toBean(resp, UserInfoListRootBean.class).success())
.map(UserInfoListRootBean::getResult)
.map(result -> Opt.ofEmptyAble(result.getUserInfoList()).peek(t -> nextPage(userListParam, token, t, result)).orElse(ListUtil.toList()))
.orElse(ListUtil.toList());
}
private void getAllUserList(UserListParam userListParam, String token, List<UserInfoList> userInfoLists) {
log.info("获取用户2");
String resp = Optional.ofNullable(HttpRequest.post(searchUserListUrl).body(JSONUtil.toJsonStr(userListParam)).header("token", token).execute().body()).orElseThrow(() -> new RuntimeException("token校验失败"));
System.out.println(resp);
Opt.ofBlankAble(resp).map(t -> JSONUtil.toBean(t, UserInfoListRootBean.class).success()).map(UserInfoListRootBean::getResult).map(UserInfoListRootBean.ResultData::getUserInfoList).stream().flatMap(Collection::stream).forEach(userInfoLists::add);
}
private void nextPage(UserListParam userListParam, String token, List<UserInfoList> userInfoLists, UserInfoListRootBean.ResultData t) {
System.out.println("获取用户--" + userListParam.getPage());
if (t.getTotalPage() > userListParam.getPage()) {
REQUEST_TASK.submit(() -> IntStream.range(userListParam.getPage(), t.getTotalPage()).parallel().forEach(i -> getAllUserList(userListParam.withPage(i + 1), token, userInfoLists))).join();
}
}
public List<OrgRootBean.ResultData> getOrgChildTree(String id, String token) {
log.info("getOrgChildTree");
String resp = Optional.ofNullable(HttpRequest.post(orgChildTreeListUrl).header("token", token).body(JSONUtil.toJsonStr(TreeSearchVo.builder().orgId(id).build())).execute().body()).orElseThrow(() -> new RuntimeException("token校验失败"));
return Opt.ofNullable(JSONUtil.toBean(resp, OrgRootBean.class).success()).map(OrgRootBean::getResult).orElse(ListUtil.empty());
}
public List<AuditList> getAllAudienceList(AuditListParam userListParam, String token) {
String resp = Optional.ofNullable(HttpRequest.post(usersByAudienceList).body(JSONUtil.toJsonStr(userListParam)).header("token", token).execute().body()).orElseThrow(() -> new RuntimeException("token校验失败"));
return Opt.ofBlankAble(resp).map(t -> JSONUtil.toBean(resp, AuditRootBean.class).success())
.map(AuditRootBean::getResult)
.map(result -> Opt.ofEmptyAble(result.getList()).peek(t -> nextPage(userListParam, t, result, token)).orElse(ListUtil.toList()))
.orElse(ListUtil.toList());
}
private void nextPage(AuditListParam userListParam, List<AuditList> t, Result result, String token) {
if (result.getTotalPage() > userListParam.getPage()) {
REQUEST_TASK.submit(() -> IntStream.range(userListParam.getPage(), result.getTotalPage()).parallel().forEach(i -> getAllAudienceList(userListParam.withPage(i + 1), t, token))).join();
}
}
private void getAllAudienceList(AuditListParam userListParam, List<AuditList> list, String token) {
String resp = Optional.ofNullable(HttpRequest.post(usersByAudienceList).body(JSONUtil.toJsonStr(userListParam)).header("token", token).execute().body()).orElseThrow(() -> new RuntimeException("token校验失败"));
Opt.ofBlankAble(resp).map(t -> JSONUtil.toBean(t, AuditRootBean.class).success()).map(AuditRootBean::getResult).map(Result::getList).stream().flatMap(Collection::stream).forEach(list::add);
}
}

View File

@@ -0,0 +1,24 @@
package com.xboe.api.vo; /**
* Copyright 2022 bejson.com
*/
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Auto-generated: 2022-12-10 14:3:18
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditList {
private long audienceId;
private long userId;
private long id;
}

View File

@@ -0,0 +1,14 @@
package com.xboe.api.vo;
import lombok.*;
@Data
@Builder
@With
@NoArgsConstructor
@AllArgsConstructor
public class AuditListParam implements Cloneable {
private String audienceId;
private Integer page;
private Integer pageSize;
}

View File

@@ -0,0 +1,41 @@
package com.xboe.api.vo; /**
* Copyright 2022 bejson.com
*/
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
/**
* Auto-generated: 2022-12-10 14:3:18
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
@Data
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditRootBean {
private String error;
private String message;
private String permissions;
private Result result;
private int status;
private Date timestamp;
public AuditRootBean success() {
if (this.status != 200) {
log.error("获取受众列表失败----{}", JSONUtil.toJsonPrettyStr(this));
return null;
}
return this;
}
}

View File

@@ -0,0 +1,63 @@
package com.xboe.api.vo;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
@Data
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrgRootBean {
private String error;
private String message;
private String permissions;
private List<ResultData> result;
private int status;
private Date timestamp;
public OrgRootBean success() {
if (this.status != 200) {
log.error("获取组织列表失败----{}", JSONUtil.toJsonPrettyStr(this));
return null;
}
return this;
}
@Data
public static class ResultData {
private String id;
private String parentId;
private String oldKid;
private String oldParentId;
private String name;
private String code;
private String namePath;
private int level;
private int status;
private String description;
private boolean isMakeOrg;
private boolean isServiceSite;
private String managerId;
private String hrbpId;
private Date createTime;
private String createBy;
private String oldOrgId;
private String oldOrgParentId;
private String companyId;
private String sassId;
private String orgRepository;
private String orgFactory;
private String directChildList;
private List<Result> treeChildList;
}
}

View File

@@ -0,0 +1,27 @@
package com.xboe.api.vo; /**
* Copyright 2022 bejson.com
*/
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Auto-generated: 2022-12-10 14:3:18
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result {
private int totalElement;
private int totalPage;
private List<AuditList> list;
}

View File

@@ -0,0 +1,15 @@
package com.xboe.api.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TreeSearchVo {
private String keyword;
private String orgId;
}

View File

@@ -0,0 +1,40 @@
package com.xboe.api.vo;
import lombok.Data;
@Data
public class UserInfoList {
private long id;
private String bandCode;
private String bandDesc;
private Boolean deleted;
private Long departId;
private String description;
private String domainId;
private String departName;
private String duty;
private int employeeStatus;
private String companyId;
private String orgName;
private Integer gender;
private String jobName;
private String kid;
private int learningDuration;
private String mobile;
private String realName;
private String oldDepartId;
private String orgNamePath;
private String orgTreeType;
private String payrollPlaceId;
private String payrollPlaceName;
private long personId;
private String positionMgrLevel;
private String rank;
private long sassId;
private int status;
private String telephoneNo;
private String userNo;
private String email;
private String avatar;
}

View File

@@ -0,0 +1,37 @@
package com.xboe.api.vo;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
@Data
@Slf4j
public class UserInfoListRootBean {
private String error;
private String message;
private String permissions;
private ResultData result;
private int status;
private Date timestamp;
public UserInfoListRootBean success() {
if (this.status != 200) {
log.error("获取学员列表失败----{}", JSONUtil.toJsonPrettyStr(this));
return null;
}
return this;
}
@Data
public static class ResultData {
private int totalElement;
private int totalPage;
private List<UserInfoList> userInfoList;
}
}

View File

@@ -0,0 +1,19 @@
package com.xboe.api.vo;
import lombok.*;
@Data
@Builder
@With
@NoArgsConstructor
@AllArgsConstructor
public class UserListParam {
private String id;
private String departId;
private String userNo;
private String realName;
@Builder.Default
private int page = 1;
@Builder.Default
private int pageSize = 10;
}

View File

@@ -32,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -179,7 +180,7 @@ public class CasesRecommendApi extends ApiBaseController {
* @return
*/
@PostMapping("/launch")
public JsonResponse<Boolean> excelImport(@RequestBody CasesRecommendLaunchVo casesRecommendLaunch) {
public JsonResponse<Boolean> launch(@RequestBody CasesRecommendLaunchVo casesRecommendLaunch, HttpServletRequest request) {
if (!CasesRecommendLaunchTypeEnum.COMMON.getLaunchType().equals(casesRecommendLaunch.getLaunchType()) && !CasesRecommendLaunchTypeEnum.IMPORT.getLaunchType().equals(casesRecommendLaunch.getLaunchType())) {
throw new RuntimeException("参数错误");
}
@@ -191,7 +192,12 @@ public class CasesRecommendApi extends ApiBaseController {
if (CollectionUtil.isEmpty(casesRecommendLaunch.getPushUserIdList())) {
throw new RuntimeException("参数错误");
}
return success(iCasesRecommendPushRecordService.launchPush(casesRecommendLaunch, getCurrent()));
String token = request.getHeader("Xboe-Access-Token");
if (StringUtils.isEmpty(token)) {
token = request.getHeader("token");
}
return success(iCasesRecommendPushRecordService.launchPush(casesRecommendLaunch, getCurrent(), token));
}
/**

View File

@@ -15,7 +15,7 @@ public interface ICasesRecommendPushRecordService {
* @param
* @return
*/
boolean launchPush(CasesRecommendLaunchVo casesRecommendLaunch, CurrentUser currentUser);
boolean launchPush(CasesRecommendLaunchVo casesRecommendLaunch, CurrentUser currentUser,String token);
/**
* 根据案例推荐ID查询案例推送列表信息

View File

@@ -2,6 +2,8 @@ package com.xboe.module.boecase.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.xboe.api.ThirdApi;
import com.xboe.api.vo.*;
import com.xboe.core.CurrentUser;
import com.xboe.core.event.IEventDataSender;
import com.xboe.core.orm.FieldFilters;
@@ -62,8 +64,11 @@ public class CasesRecommendPushRecordServiceImpl implements ICasesRecommendPushR
@Autowired(required = false)
private IEventDataSender eventDataSender;
@Resource
private ThirdApi thirdApi;
@Override
public boolean launchPush(CasesRecommendLaunchVo casesRecommendLaunch, CurrentUser currentUser) {
public boolean launchPush(CasesRecommendLaunchVo casesRecommendLaunch, CurrentUser currentUser, String token) {
CasesRecommend casesRecommend = new CasesRecommend();
@@ -85,12 +90,42 @@ public class CasesRecommendPushRecordServiceImpl implements ICasesRecommendPushR
List<String> caseIdList = importDataList.stream().filter(casesRecommendLaunchImportData -> casesRecommendLaunchImportData.getStatus() == 1).map(CasesRecommendLaunchImportData::getCaseId).collect(Collectors.toList());
caseIds.addAll(caseIdList);
}
List<String> userIds = new ArrayList<>();
if (CollectionUtil.isNotEmpty(casesRecommendLaunch.getPushUserIdList())) {
userIds.addAll(casesRecommendLaunch.getPushUserIdList());
}
// 组织
if (CollectionUtil.isNotEmpty(casesRecommendLaunch.getDeptIds())) {
for (String orgId : casesRecommendLaunch.getDeptIds()) {
List<OrgRootBean.ResultData> orgChildTree = thirdApi.getOrgChildTree(orgId, token);
if (CollectionUtil.isNotEmpty(orgChildTree)) {
for (OrgRootBean.ResultData result : orgChildTree) {
UserListParam build = UserListParam.builder().departId(result.getId()).pageSize(100).build();
List<UserInfoList> allUserList = thirdApi.getAllUserList(build, token);
if (CollectionUtil.isNotEmpty(allUserList)) {
for (UserInfoList userInfo : allUserList) {
userIds.add(String.valueOf(userInfo.getId()));
}
}
}
}
}
}
// 受众关联
if (CollectionUtil.isNotEmpty(casesRecommendLaunch.getGroupIds())) {
for (String groupId : casesRecommendLaunch.getGroupIds()) {
List<AuditList> allAudienceList = thirdApi.getAllAudienceList(AuditListParam.builder().audienceId(groupId).pageSize(100).page(1).build(), token);
if (CollectionUtil.isNotEmpty(allAudienceList)) {
allAudienceList.forEach(auditList -> userIds.add(String.valueOf(auditList.getUserId())));
}
}
}
for (String caseId : caseIds) {
Cases cases = casesDao.get(caseId);
List<CasesRecommendPushRecord> pushRecords = new ArrayList<>();
Map<String, Object> userMap = userDao.findMap("id", "name", FieldFilters.in("id", casesRecommendLaunch.getPushUserIdList()));
for (String userId : casesRecommendLaunch.getPushUserIdList()) {
for (String userId : userIds) {
CasesRecommendPushRecord casesRecommendPushRecord = new CasesRecommendPushRecord();
casesRecommendPushRecord.setRecommendId(casesRecommend.getId());
casesRecommendPushRecord.setCaseId(caseId);

View File

@@ -33,6 +33,17 @@ public class CasesRecommendLaunchVo {
*/
private List<String> pushUserIdList;
/**
* 组织列表
*/
private List<String> deptIds;
/**
* 受众列表
*/
private List<String> groupIds;
/**
* 推荐机构
*/