支持上传附件
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
@ -113,7 +115,7 @@ public class LarkActiveController extends BaseController {
*
*/
@PostMapping("/queryComment")
public ResponseVo<Map<String,List<LarkActiveCommentVo>>> queryComment(@RequestBody LarkActiveUserRelationRequest request) {
public ResponseVo<Map<String, List<LarkActiveCommentVo>>> queryComment(@RequestBody LarkActiveUserRelationRequest request) {
return larkUserActiveCommentService.queryComment(request);
}
@ -141,7 +143,7 @@ public class LarkActiveController extends BaseController {
@PostMapping("/inviteUser")
public ResponseVo<LarkInviteVo> inviteUser(@RequestBody LarkUserActiveInviteRelatoin request) {
ResponseVo responseVo = new ResponseVo();
if (request.getUserName().equals(request.getInviteUserName())){
if (request.getUserName().equals(request.getInviteUserName())) {
return responseVo;
}
larkUserActiveInviteRelatoinService.create(request);
@ -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";
@ -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());

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