支持上传附件
continuous-integration/drone/push Build is passing Details

飞书小程序
YXY 1 year ago
parent 99edffd9e8
commit dc9a4bd689

@ -7,6 +7,7 @@ import com.lark.oapi.service.authen.v1.model.CreateAccessTokenReq;
import com.lark.oapi.service.authen.v1.model.CreateAccessTokenReqBody;
import com.lark.oapi.service.authen.v1.model.CreateAccessTokenRespBody;
import com.lark.oapi.service.contact.v3.enums.BatchGetIdUserUserIdTypeEnum;
import com.lark.oapi.service.contact.v3.enums.GetUserUserIdTypeEnum;
import com.lark.oapi.service.contact.v3.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest;
import com.ruoyi.flyingbook.domain.lark.LarkException;
@ -31,11 +32,13 @@ public class LarkUserHelper extends LarkHelper{
public static void main(String[] args) throws Exception {
LarkUserHelper bk = new LarkUserHelper();
GetUserRespBody userRespBody = bk.getUserInfoDetail(new LarkUserRequest(appId, secret, openId));
// GetUserRespBody userRespBody = bk.getUserInfoDetail(new LarkUserRequest(appId, secret, openId));
// userRespBody.getUser().getName();
System.out.println(userRespBody);
LarkSessionResponse larkSessionResponse = bk.tokenLoginValidate(new LarkUserRequest(appId, secret, openId, code));
System.out.println(larkSessionResponse);
// System.out.println(userRespBody);
// LarkSessionResponse larkSessionResponse = bk.tokenLoginValidate(new LarkUserRequest(appId, secret, openId, code));
// System.out.println(larkSessionResponse);
GetUserRespBody userRespBody = bk.getUserInfo(new LarkUserRequest("cli_a4504c9fe9f95013", "oWiLzl2Tkt68tvZHjQIfOb27rPQkTUhu", "85623f9d"));
System.out.println(JSONObject.toJSONString(userRespBody));
}
@ -56,6 +59,20 @@ public class LarkUserHelper extends LarkHelper{
}
}
public GetUserRespBody getUserInfo(LarkUserRequest request) {
GetUserResp getUserResp = null;
try {
getUserResp = buildClient(request).contact().user().get(GetUserReq.newBuilder().userId(request.getOpenId()).userIdType(GetUserUserIdTypeEnum.USER_ID).build());
} catch (Exception e) {
throw new RuntimeException(new LarkException("LarkUserHelper.getUserInfoDetail",e.getMessage(),request).getErrorMessageBody());
}
if (getUserResp != null && getUserResp.getCode() == 0){
return getUserResp.getData();
}else {
throw new RuntimeException(new LarkException("LarkUserHelper.getUserInfoDetail",getUserResp.getMsg(),request).getErrorMessageBody());
}
}
/**
* userToken
*/

@ -20,14 +20,16 @@ import com.ruoyi.flyingbook.domain.lark.LarkUserRequest;
import com.ruoyi.flyingbook.domain.larkactive.*;
import com.ruoyi.flyingbook.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@RestController
@ -180,7 +182,6 @@ public class LarkActiveController extends BaseController {
.head(LarkActiveCountVo.class)
.registerWriteHandler(new CustomMergeStrategy(LarkActiveCountVo.class))
.excelType(ExcelTypeEnum.XLSX)
.password("123456")
.autoCloseStream(Boolean.TRUE)
.sheet("sheetName")
.doWrite(Arrays.asList(larkActiveCountVo));
@ -189,5 +190,18 @@ public class LarkActiveController extends BaseController {
}
}
@PostMapping("/import")
public void importActive(@RequestPart("file") MultipartFile file) {
try {
List<LarkActiveImportVo> list = EasyExcel.read(file.getInputStream())
.head(LarkActiveImportVo.class)
.sheet()
.doReadSync();
larkUserActiveRelatoinService.submit(list,APP_ID,APP_SECRET);
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -17,6 +17,9 @@ public class LarkUserRequest extends LarkRequest{
private String openId;
//登录预授权码
private String code;
public LarkUserRequest(String appId, String appSecret) {
super(appId, appSecret);
}
public LarkUserRequest(String appId, String appSecret, String openId) {
super(appId, appSecret);

@ -0,0 +1,22 @@
package com.ruoyi.flyingbook.domain.larkactive;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.ruoyi.common.utils.excelStrategy.CustomMerge;
import lombok.Data;
/**
* lark_active
*
* @author ruoyi
* @date 2023-08-16
*/
@Data
public class LarkActiveImportVo {
@ExcelProperty("填写者ID")
private String userId;
}

@ -37,6 +37,8 @@ public interface LarkUserActiveRelatoinMapper {
public int queryUserCount(LarkUserActiveRelatoin larkUserActiveRelatoin);
public List<LarkActiveVo> queryUserCountGroupByActive(LarkUserActiveRelatoin larkUserActiveRelatoin);
public List<LarkUserActiveRelatoin> queryByIdList(@Param("idList") List<Long> idList);
public List<LarkUserActiveRelatoin> queryByOpenIdList(@Param("openIdList") List<String> openIdList,@Param("activeId") Long activeId);
public List<LarkUserActiveRelatoin> updateByIdList(@Param("idList") List<Long> idList,@Param("activeStage") String activeStage);
/**
*

@ -3,6 +3,7 @@ package com.ruoyi.flyingbook.service;
import com.ruoyi.flyingbook.domain.LarkUserActiveRelatoin;
import com.ruoyi.flyingbook.domain.edi.ResponseVo;
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveCountVo;
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveImportVo;
import com.ruoyi.flyingbook.domain.larkactive.LarkActiveUserRelationRequest;
import java.util.List;
@ -34,7 +35,7 @@ public interface ILarkUserActiveRelatoinService {
public ResponseVo<LarkUserActiveRelatoin> queryPage(LarkActiveUserRelationRequest request);
public ResponseVo<String> commitFile(LarkActiveUserRelationRequest request);
public ResponseVo<LarkUserActiveRelatoin> submit(LarkActiveUserRelationRequest request);
public void submit(List<LarkActiveImportVo> list,String appId,String appSecret);
/**
*

@ -117,6 +117,9 @@ public class LarkUserActiveCommentServiceImpl implements ILarkUserActiveCommentS
@Override
public ResponseVo<LarkUserActiveRelatoin> comment(LarkActiveUserRelationRequest request) {
if (StringUtils.isBlank(request.getComment())){
return new ResponseVo<>();
}
List<LarkActive> larkActives = larkActiveMapper.selectLarkActiveByName(request.getLarkActiveName(), FlagStatus.OK.getCode());
if (CollectionUtils.isEmpty(larkActives)) {
return new ResponseVo();

@ -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) {

@ -59,6 +59,23 @@
</foreach>
</select>
<select id="queryByOpenIdList"
resultMap="LarkUserActiveRelatoinResult">
<include refid="selectLarkUserActiveRelatoinVo"/>
where activeId = #{activeId} and userName in
<foreach collection="openIdList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<update id="updateByIdList">
update lark_user_active_relatoin set activeStage = #{activeStage}
where id in
<foreach collection="idList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</update>
<select id="queryPage" parameterType="com.ruoyi.flyingbook.domain.larkactive.LarkActiveUserRelationRequest"
resultMap="LarkUserActiveRelatoinResult">
<include refid="selectLarkUserActiveRelatoinVo"/>

Loading…
Cancel
Save