|
|
|
@ -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";
|
|
|
|
|
|
|
|
|
@ -98,16 +103,16 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
Map<Long, Integer> activeCountMap = larkUserActiveRelatoinMapper.queryUserCountGroupByActive(larkUserActiveRelatoin).stream().collect(Collectors.toMap(LarkActiveVo::getId, LarkActiveVo::getQty, (k1, k2) -> k1));
|
|
|
|
|
for (LarkActive active : larkActives) {
|
|
|
|
|
Integer qty = activeCountMap.getOrDefault(active.getId(), 0);
|
|
|
|
|
fillCount(larkActiveCountVo,qty,active.getActiveDesc());
|
|
|
|
|
fillCount(larkActiveCountVo, qty, active.getActiveDesc());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return larkActiveCountVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillCount(LarkActiveCountVo larkActiveCountVo,Integer qty,String activeCode){
|
|
|
|
|
private void fillCount(LarkActiveCountVo larkActiveCountVo, Integer qty, String activeCode) {
|
|
|
|
|
qty = qty == null ? 0 : qty;
|
|
|
|
|
LarkActiveEnum activeEnum = LarkActiveEnum.getByCode(activeCode);
|
|
|
|
|
switch (activeEnum){
|
|
|
|
|
switch (activeEnum) {
|
|
|
|
|
case MOOC:
|
|
|
|
|
larkActiveCountVo.setMoccQty(qty);
|
|
|
|
|
break;
|
|
|
|
@ -156,26 +161,26 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
return new ResponseVo(request.getCurrentPage(), request.getPageSize(), null, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private File base642File(String base64){
|
|
|
|
|
private File base642File(String base64) {
|
|
|
|
|
File file = null;
|
|
|
|
|
if(base64.contains("data:image")){
|
|
|
|
|
base64 = base64.substring(base64.indexOf(",")+1);
|
|
|
|
|
if (base64.contains("data:image")) {
|
|
|
|
|
base64 = base64.substring(base64.indexOf(",") + 1);
|
|
|
|
|
}
|
|
|
|
|
BufferedOutputStream bos = null;
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
|
try {
|
|
|
|
|
base64 = base64.toString().replace("\r\n", "");
|
|
|
|
|
//创建文件目录
|
|
|
|
|
String prefix=".jpg";
|
|
|
|
|
String prefix = ".jpg";
|
|
|
|
|
file = File.createTempFile(IdUtil.randomUUID(), prefix);
|
|
|
|
|
|
|
|
|
|
byte[] bytes = Base64.decodeBase64(base64);
|
|
|
|
|
fos = new FileOutputStream(file);
|
|
|
|
|
bos = new BufferedOutputStream(fos);
|
|
|
|
|
bos.write(bytes);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
|
} finally {
|
|
|
|
|
if (bos != null) {
|
|
|
|
|
try {
|
|
|
|
|
bos.close();
|
|
|
|
@ -198,15 +203,15 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
public ResponseVo<String> commitFile(LarkActiveUserRelationRequest request) {
|
|
|
|
|
ResponseVo responseVo = new ResponseVo();
|
|
|
|
|
List<LarkActive> larkActives = larkActiveMapper.selectLarkActiveByName(request.getLarkActiveName(), FlagStatus.OK.getCode());
|
|
|
|
|
if (CollectionUtils.isEmpty(larkActives)){
|
|
|
|
|
if (CollectionUtils.isEmpty(larkActives)) {
|
|
|
|
|
return responseVo;
|
|
|
|
|
}
|
|
|
|
|
LarkActive active = larkActives.get(0);
|
|
|
|
|
LarkUserActiveRelatoin relatoin = queryUserActiveRelation(request.getCompanyName(),request.getUserName(), active.getId());
|
|
|
|
|
LarkUserActiveRelatoin relatoin = queryUserActiveRelation(request.getCompanyName(), request.getUserName(), active.getId());
|
|
|
|
|
if (relatoin == null) {
|
|
|
|
|
return responseVo;
|
|
|
|
|
}
|
|
|
|
|
Integer totalCount = userActiveCount(relatoin,request.getImageBase64()) + 1;
|
|
|
|
|
Integer totalCount = userActiveCount(relatoin, request.getImageBase64()) + 1;
|
|
|
|
|
LarkActive larkActive = larkActiveMapper.selectLarkActiveById(relatoin.getActiveId());
|
|
|
|
|
String url = null;
|
|
|
|
|
if (StringUtils.isNotBlank(request.getImageBase64())) {
|
|
|
|
@ -217,11 +222,11 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
split[0] = key;
|
|
|
|
|
key = String.join(".", split);
|
|
|
|
|
cosHelper.upload(BUCKET_NAME, key, file);
|
|
|
|
|
buildUserActiveImage(relatoin, key,null);
|
|
|
|
|
buildUserActiveImage(relatoin, key, null);
|
|
|
|
|
url = cosHelper.previewUrl(BUCKET_NAME, key);
|
|
|
|
|
responseVo.setData(url);
|
|
|
|
|
}else {
|
|
|
|
|
buildUserActiveImage(relatoin,null, request.getRemark());
|
|
|
|
|
} else {
|
|
|
|
|
buildUserActiveImage(relatoin, null, request.getRemark());
|
|
|
|
|
}
|
|
|
|
|
if (totalCount >= larkActive.getActiveImageCount()) {
|
|
|
|
|
relatoin.setActiveStage(LarkActiveStageEnum.ADJUST.getCode());
|
|
|
|
@ -232,22 +237,62 @@ 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());
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
relatoin.setActiveStage(LarkActiveStageEnum.ADJUST.getCode());
|
|
|
|
|
larkUserActiveRelatoinMapper.updateLarkUserActiveRelatoin(relatoin);
|
|
|
|
|
return new ResponseVo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buildUserActiveImage(LarkUserActiveRelatoin relatoin, String key,String remark) {
|
|
|
|
|
private void buildUserActiveImage(LarkUserActiveRelatoin relatoin, String key, String remark) {
|
|
|
|
|
LarkUserActiveImage larkUserActiveImage = new LarkUserActiveImage();
|
|
|
|
|
larkUserActiveImage.setCreateTime(new Date());
|
|
|
|
|
larkUserActiveImage.setCreateBy("System");
|
|
|
|
@ -256,20 +301,20 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
if (StringUtils.isNotBlank(key)) {
|
|
|
|
|
larkUserActiveImage.setBucketName(BUCKET_NAME);
|
|
|
|
|
larkUserActiveImage.setFileKey(key);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
larkUserActiveImage.setRemark(remark);
|
|
|
|
|
}
|
|
|
|
|
larkUserActiveImageMapper.insertLarkUserActiveImage(larkUserActiveImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer userActiveCount(LarkUserActiveRelatoin relatoin,String image) {
|
|
|
|
|
private Integer userActiveCount(LarkUserActiveRelatoin relatoin, String image) {
|
|
|
|
|
LarkUserActiveImage larkUserActiveImage = new LarkUserActiveImage();
|
|
|
|
|
larkUserActiveImage.setUserActiveRelatoin(relatoin.getId());
|
|
|
|
|
larkUserActiveImage.setFlag(FlagStatus.OK.getCode());
|
|
|
|
|
List<LarkUserActiveImage> larkUserActiveImages = larkUserActiveImageMapper.selectLarkUserActiveImageList(larkUserActiveImage);
|
|
|
|
|
if (StringUtils.isNotBlank(image)) {
|
|
|
|
|
return larkUserActiveImages.size();
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
List<String> collect = larkUserActiveImages.stream()
|
|
|
|
|
.filter(r -> {
|
|
|
|
|
return StringUtils.isNotBlank(r.getRemark());
|
|
|
|
@ -280,7 +325,7 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LarkUserActiveRelatoin queryUserActiveRelation(String companyName,String userName, Long activeId) {
|
|
|
|
|
private LarkUserActiveRelatoin queryUserActiveRelation(String companyName, String userName, Long activeId) {
|
|
|
|
|
LarkUserActiveRelatoin relatoin = new LarkUserActiveRelatoin();
|
|
|
|
|
relatoin.setUserName(userName);
|
|
|
|
|
relatoin.setActiveId(activeId);
|
|
|
|
@ -288,7 +333,7 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi
|
|
|
|
|
List<LarkUserActiveRelatoin> larkUserActiveRelatoins = larkUserActiveRelatoinMapper.selectLarkUserActiveRelatoinList(relatoin);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(larkUserActiveRelatoins)) {
|
|
|
|
|
return larkUserActiveRelatoins.get(0);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
relatoin.setCreateBy("System");
|
|
|
|
|
relatoin.setCreateTime(new Date());
|
|
|
|
|
relatoin.setActiveStage(LarkActiveStageEnum.SUBMIT.getCode());
|
|
|
|
|