|
|
|
@ -1,18 +1,22 @@
|
|
|
|
|
package com.ruoyi.flyingbook.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.lark.oapi.service.contact.v3.model.GetUserRespBody;
|
|
|
|
|
import com.ruoyi.common.enums.FlagStatus;
|
|
|
|
|
import com.ruoyi.common.enums.LarkActiveEnum;
|
|
|
|
|
import com.ruoyi.common.enums.LarkActiveStageEnum;
|
|
|
|
|
import com.ruoyi.common.enums.LarkUserTypeEnum;
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.flyingbook.CosHelper.CosHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkActive;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkLoginLog;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkUserActiveImage;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkUserActiveRelatoin;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.edi.ResponseVo;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.lark.LarkUserRequest;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveCountVo;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveImportVo;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveUserRelationRequest;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveVo;
|
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkActiveMapper;
|
|
|
|
@ -21,6 +25,7 @@ import com.ruoyi.flyingbook.mapper.LarkUserActiveImageMapper;
|
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkUserActiveRelatoinMapper;
|
|
|
|
|
import com.ruoyi.flyingbook.service.ILarkUserActiveInviteRelatoinService;
|
|
|
|
|
import com.ruoyi.flyingbook.service.ILarkUserActiveRelatoinService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
@ -32,10 +37,8 @@ import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -44,6 +47,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
* @date 2023-08-16
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoinService {
|
|
|
|
|
@Autowired
|
|
|
|
@ -58,7 +62,8 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
private LarkLoginLogMapper larkLoginLogMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ILarkUserActiveInviteRelatoinService larkUserActiveInviteRelatoinService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private LarkUserHelper larkUserHelper;
|
|
|
|
|
|
|
|
|
|
private static final String BUCKET_NAME = "ruoyi-1308275795";
|
|
|
|
|
|
|
|
|
@ -232,19 +237,59 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ResponseVo<LarkUserActiveRelatoin> submit(LarkActiveUserRelationRequest request) {
|
|
|
|
|
List<LarkActive> larkActives = larkActiveMapper.selectLarkActiveByName(request.getLarkActiveName(), FlagStatus.OK.getCode());
|
|
|
|
|
if (CollectionUtils.isEmpty(larkActives)){
|
|
|
|
|
return new ResponseVo();
|
|
|
|
|
public void submit(List<LarkActiveImportVo> list, String appId, String appSecret) {
|
|
|
|
|
LarkUserRequest larkUserRequest = new LarkUserRequest(appId, appSecret);
|
|
|
|
|
Set<String> openIdSet = new HashSet<>();
|
|
|
|
|
for (LarkActiveImportVo larkActiveImportVo : list) {
|
|
|
|
|
if (StringUtils.isNotBlank(larkActiveImportVo.getUserId())) {
|
|
|
|
|
try {
|
|
|
|
|
larkUserRequest.setOpenId(larkActiveImportVo.getUserId());
|
|
|
|
|
GetUserRespBody userInfoDetail = larkUserHelper.getUserInfo(larkUserRequest);
|
|
|
|
|
openIdSet.add(userInfoDetail.getUser().getOpenId());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("import file error userId:{}", larkActiveImportVo.getUserId(), e);
|
|
|
|
|
}
|
|
|
|
|
LarkActive active = larkActives.get(0);
|
|
|
|
|
LarkUserActiveRelatoin relatoin = queryUserActiveRelation(request.getCompanyName(),request.getUserName(), active.getId());
|
|
|
|
|
if (relatoin == null) {
|
|
|
|
|
return new ResponseVo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isEmpty(openIdSet)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<LarkLoginLog> larkLoginLogs = larkLoginLogMapper.queryByOpenId(new ArrayList<>(openIdSet));
|
|
|
|
|
List<String> openIdList = larkLoginLogs.stream()
|
|
|
|
|
.filter(r -> {
|
|
|
|
|
return StringUtils.isNotBlank(r.getOpenId());
|
|
|
|
|
})
|
|
|
|
|
.map(LarkLoginLog::getOpenId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(openIdList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//todo yxy 任务id
|
|
|
|
|
Long activeId = null;
|
|
|
|
|
Map<String, LarkUserActiveRelatoin> relationMap = larkUserActiveRelatoinMapper.queryByOpenIdList(openIdList,activeId).stream()
|
|
|
|
|
.collect(Collectors.toMap(LarkUserActiveRelatoin::getUserName, Function.identity(),(k1,k2)->k1));
|
|
|
|
|
List<Long> waitUpdateList = new ArrayList<>();
|
|
|
|
|
for (LarkLoginLog larkLoginLog : larkLoginLogs) {
|
|
|
|
|
LarkUserActiveRelatoin activeRelatoin = relationMap.get(larkLoginLog.getOpenId());
|
|
|
|
|
if (activeRelatoin == null){
|
|
|
|
|
LarkUserActiveRelatoin relatoin = new LarkUserActiveRelatoin();
|
|
|
|
|
relatoin.setCreateTime(new Date());
|
|
|
|
|
relatoin.setCreateBy("system");
|
|
|
|
|
relatoin.setActiveStage(LarkActiveStageEnum.ADJUST.getCode());
|
|
|
|
|
larkUserActiveRelatoinMapper.updateLarkUserActiveRelatoin(relatoin);
|
|
|
|
|
return new ResponseVo();
|
|
|
|
|
relatoin.setFlag(FlagStatus.OK.getCode());
|
|
|
|
|
relatoin.setActiveId(activeId);
|
|
|
|
|
relatoin.setUserName(larkLoginLog.getOpenId());
|
|
|
|
|
relatoin.setCompanyName(larkLoginLog.getCompanyName());
|
|
|
|
|
larkUserActiveRelatoinMapper.insertLarkUserActiveRelatoin(relatoin);
|
|
|
|
|
}else {
|
|
|
|
|
if (!LarkActiveStageEnum.ADJUST.getCode().equals(activeRelatoin.getActiveStage())){
|
|
|
|
|
waitUpdateList.add(activeRelatoin.getActiveId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(waitUpdateList)){
|
|
|
|
|
larkUserActiveRelatoinMapper.updateByIdList(waitUpdateList,LarkActiveStageEnum.ADJUST.getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buildUserActiveImage(LarkUserActiveRelatoin relatoin, String key, String remark) {
|
|
|
|
|