用户id转名称

于相涌/mail
YXY 2 years ago committed by bob
parent 06168385be
commit e67ab948ef

@ -0,0 +1,47 @@
package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.service.approval.v4.model.GetInstanceRespBody;
import com.lark.oapi.service.contact.v3.model.GetUserReq;
import com.lark.oapi.service.contact.v3.model.GetUserResp;
import com.lark.oapi.service.contact.v3.model.GetUserRespBody;
import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest;
import com.ruoyi.flyingbook.domain.lark.LarkUserRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author yuxiangyong
* @create 2023-03-12 18:10
*/
@Slf4j
@Component
public class LarkUserHelper extends LarkHelper{
static String openId = "ou_cd09481727e91fce1f12b7b0ed1500d2";
public static void main(String[] args) throws Exception {
LarkUserHelper bk = new LarkUserHelper();
GetUserRespBody userRespBody = bk.getUserInfoDetail(new LarkUserRequest(appId, secret, openId));
// userRespBody.getUser().getName();
System.out.println(userRespBody);
}
/**
*
* @return
*/
public GetUserRespBody getUserInfoDetail(LarkUserRequest request) {
try {
GetUserResp getUserResp = buildClient(request).contact().user().get(GetUserReq.newBuilder().userId(request.getOpenId()).build());
if (getUserResp.getCode() == 0){
return getUserResp.getData();
}else {
throw new RuntimeException(getUserResp.getMsg());
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}

@ -0,0 +1,21 @@
package com.ruoyi.flyingbook.domain.lark;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author yuxiangyong
* @create 2023-03-18 1:05
*/
@Data
@NoArgsConstructor
public class LarkUserRequest extends LarkRequest{
private String openId;
public LarkUserRequest(String appId, String appSecret, String openId) {
super(appId, appSecret);
this.openId = openId;
}
}

@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.service.approval.v4.model.GetInstanceRespBody; import com.lark.oapi.service.approval.v4.model.GetInstanceRespBody;
import com.lark.oapi.service.bitable.v1.model.CreateAppTableRecordRespBody; import com.lark.oapi.service.bitable.v1.model.CreateAppTableRecordRespBody;
import com.lark.oapi.service.contact.v3.model.GetUserRespBody;
import com.ruoyi.common.enums.*; import com.ruoyi.common.enums.*;
import com.ruoyi.flyingbook.LarkHelper.LarkApprovalHelper; import com.ruoyi.flyingbook.LarkHelper.LarkApprovalHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper; import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
import com.ruoyi.flyingbook.domain.*; import com.ruoyi.flyingbook.domain.*;
import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest; import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import com.ruoyi.flyingbook.domain.lark.LarkUserRequest;
import com.ruoyi.flyingbook.service.*; import com.ruoyi.flyingbook.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@ -33,6 +36,8 @@ import java.util.Map;
@Component("ApprovalCallbackOperate") @Component("ApprovalCallbackOperate")
public class ApprovalCallbackOperate extends LarkAbstract { public class ApprovalCallbackOperate extends LarkAbstract {
@Autowired
protected LarkUserHelper larkUserHelper;
@Autowired @Autowired
protected LarkTableHelper larkTableHelper; protected LarkTableHelper larkTableHelper;
@Autowired @Autowired
@ -150,7 +155,7 @@ public class ApprovalCallbackOperate extends LarkAbstract {
String[] split = entry.getKey().split("@"); String[] split = entry.getKey().split("@");
String toColName = split[0]; String toColName = split[0];
String path = split[1]; String path = split[1];
result.put(entry.getValue(), recursiveValue(bodyMap.get(toColName), path)); result.put(entry.getValue(), recursiveValue(bodyMap.get(toColName), path,request));
} }
return result; return result;
} }
@ -165,11 +170,25 @@ public class ApprovalCallbackOperate extends LarkAbstract {
* @param key * @param key
* @return * @return
*/ */
private Object recursiveValue(JSONObject record, String key) { private Object recursiveValue(JSONObject record, String key,RequestVo request) {
if (record == null){
return null;
}
String[] split = key.split(","); String[] split = key.split(",");
int index = 0; int index = 0;
for (index = 0; index < split.length; index++) { for (index = 0; index < split.length; index++) {
String k = split[index]; String k = split[index].trim();
if (k.startsWith("##") && k.endsWith("${user}")) {
k = k.replace("##", "").replace("${user}", "");
List<String> list = new ArrayList<>();
JSONArray jsonArray = record.getJSONArray(k);
for (int i = 0; i < jsonArray.size(); i++) {
String openId = jsonArray.getString(i);
GetUserRespBody userInfoDetail = larkUserHelper.getUserInfoDetail(new LarkUserRequest(request.getAppId(), request.getAppSecret(), openId));
list.add(userInfoDetail.getUser().getName());
}
return String.join(",", list);
}
if (k.startsWith("##")) { if (k.startsWith("##")) {
k = k.replace("##", ""); k = k.replace("##", "");
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
@ -183,7 +202,7 @@ public class ApprovalCallbackOperate extends LarkAbstract {
for (int j = index + 1; j < split.length; j++) { for (int j = index + 1; j < split.length; j++) {
keyList.add(split[j]); keyList.add(split[j]);
} }
Object o = recursiveValue(jsonArray.getJSONObject(i), String.join(",", keyList)); Object o = recursiveValue(jsonArray.getJSONObject(i), String.join(",", keyList),request);
list.add(String.valueOf(o)); list.add(String.valueOf(o));
} }
} }
@ -195,7 +214,7 @@ public class ApprovalCallbackOperate extends LarkAbstract {
break; break;
} }
} }
return record.get(split[index]); return record.getString(split[index].trim());
} }
protected void send(RequestVo request) { protected void send(RequestVo request) {

Loading…
Cancel
Save