|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.ruoyi.flyingbook.strategy.operate;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.lark.oapi.service.approval.v4.model.GetInstanceRespBody;
|
|
|
|
|
import com.lark.oapi.service.bitable.v1.model.CreateAppTableRecordRespBody;
|
|
|
|
@ -54,8 +55,7 @@ public class ApprovalCallbackOperate extends LarkAbstract {
|
|
|
|
|
LarkTableRelation tableRelation = new LarkTableRelation();
|
|
|
|
|
|
|
|
|
|
tableRelation.setLarkCompanyRelationId(request.getCompanyRelationId());
|
|
|
|
|
//todo yxy 表关联关系 tableId取值
|
|
|
|
|
tableRelation.setFromTableId(request.getEvent().getTableId());
|
|
|
|
|
tableRelation.setFromTableId(request.getApproveName());
|
|
|
|
|
tableRelation.setFlag(FlagStatus.OK.getCode());
|
|
|
|
|
List<LarkTableRelation> larkTableRelations = iLarkTableRelationService.selectLarkTableRelationList(tableRelation);
|
|
|
|
|
if (CollectionUtils.isEmpty(larkTableRelations)) {
|
|
|
|
@ -76,9 +76,10 @@ public class ApprovalCallbackOperate extends LarkAbstract {
|
|
|
|
|
List<LarkTableRowRelation> larkTableRowRelations = iLarkTableRowRelationService.queryListByTableRelationIdList(tableRelationIdList);
|
|
|
|
|
Map<Long, Map<String, String>> tableColRelationMap = new HashMap<>();
|
|
|
|
|
for (LarkTableRowRelation larkTableRowRelation : larkTableRowRelations) {
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put(larkTableRowRelation.getFromId(), larkTableRowRelation.getToId());
|
|
|
|
|
|
|
|
|
|
if (TableDetailRelationTypeEnum.COL.getCode().equals(larkTableRowRelation.getType())) {
|
|
|
|
|
Map<String, String> map = tableColRelationMap.getOrDefault(larkTableRowRelation.getTableRelationId(), new HashMap<>());
|
|
|
|
|
map.put(larkTableRowRelation.getFromId(), larkTableRowRelation.getToId());
|
|
|
|
|
tableColRelationMap.put(larkTableRowRelation.getTableRelationId(), map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -96,65 +97,95 @@ public class ApprovalCallbackOperate extends LarkAbstract {
|
|
|
|
|
if (event == null) {
|
|
|
|
|
throw new RuntimeException("当前事件为空");
|
|
|
|
|
}
|
|
|
|
|
LarkCompanyRelation relation = larkCompanyRelationService.getByAppIdAndType(request.getEvent().getAppId(), AppType.APPROVAL.getCode());
|
|
|
|
|
LarkCompanyRelation relation = larkCompanyRelationService.getByAppIdAndType(request.getEvent().getAppId(), AppType.APPROVAL_TASK.getCode());
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
String errorMessage = String.format("获取app值为空 appId:{} appType:{}", request.getEvent().getAppId(), AppType.APPROVAL.getCode());
|
|
|
|
|
String errorMessage = String.format("获取app值为空 appId:{} appType:{}", request.getEvent().getAppId(), AppType.APPROVAL_TASK.getCode());
|
|
|
|
|
log.error("larkCompanyRelationService.getByCompanyName:{}", errorMessage);
|
|
|
|
|
throw new RuntimeException(errorMessage);
|
|
|
|
|
}
|
|
|
|
|
//用于后续追加row时候做关联关系
|
|
|
|
|
request.setCompanyRelationId(relation.getId());
|
|
|
|
|
//关联关系表填充
|
|
|
|
|
this.fillTableRelation(request);
|
|
|
|
|
request.setAppId(relation.getAppId());
|
|
|
|
|
request.setAppSecret(relation.getSecret());
|
|
|
|
|
LarkApprovalRequest detailRequest = new LarkApprovalRequest(request.getAppId(), request.getAppSecret(), event.getRecordId());
|
|
|
|
|
GetInstanceRespBody approvalInfoDetail = larkApprovalHelper.getApprovalInfoDetail(detailRequest);
|
|
|
|
|
request.setInstanceRespBody(approvalInfoDetail);
|
|
|
|
|
String approvalName = approvalInfoDetail.getApprovalName();
|
|
|
|
|
request.setApproveName(approvalName);
|
|
|
|
|
//关联关系表填充
|
|
|
|
|
this.fillTableRelation(request);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void businessProcessing(RequestVo request) {
|
|
|
|
|
LarkApprovalRequest detailRequest = new LarkApprovalRequest(request.getAppId(), request.getAppSecret(), request.getInstance());
|
|
|
|
|
GetInstanceRespBody approvalInfoDetail = larkApprovalHelper.getApprovalInfoDetail(detailRequest);
|
|
|
|
|
request.setInstanceRespBody(approvalInfoDetail);
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Long> entry : request.getTableRelationMap().entrySet()) {
|
|
|
|
|
String[] arr = entry.getKey().split("_");
|
|
|
|
|
request.setToAppToken(arr[0]);
|
|
|
|
|
request.setToTableId(arr[1]);
|
|
|
|
|
request.setTableRelationId(entry.getValue());
|
|
|
|
|
send( request);
|
|
|
|
|
send(request);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Map<String, Object> getBody(RequestVo request) {
|
|
|
|
|
Map<String , Object> result = new HashMap<>();
|
|
|
|
|
JSONObject record = request.getRecord();
|
|
|
|
|
String responseCode = record.getString("code");
|
|
|
|
|
if ("0".equals(responseCode)) {
|
|
|
|
|
result = parseMap(request);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
Map<String, JSONObject> bodyMap = new HashMap<>();
|
|
|
|
|
JSONArray paramList = JSONArray.parseArray(request.getInstanceRespBody().getForm());
|
|
|
|
|
for (int i = 0; i < paramList.size(); i++) {
|
|
|
|
|
JSONObject jsonObject = paramList.getJSONObject(i);
|
|
|
|
|
bodyMap.put(jsonObject.getString("name"), jsonObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> parseMap(RequestVo request) {
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
JSONObject record = request.getRecord();
|
|
|
|
|
Map<String, String> colRelation = request.getTableColRelationMap().getOrDefault(request.getTableRelationId(), new HashMap<>());
|
|
|
|
|
for (Map.Entry<String, String> entry : colRelation.entrySet()) {
|
|
|
|
|
result.put(entry.getValue(), recursiveValue(record,entry.getKey()));
|
|
|
|
|
result.put(entry.getValue(), recursiveValue(bodyMap.get(entry.getValue()), entry.getKey()));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object recursiveValue(JSONObject record,String key){
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 无前缀表示直接取值
|
|
|
|
|
* #前缀表示对象
|
|
|
|
|
* ##表示数组
|
|
|
|
|
*
|
|
|
|
|
* @param record
|
|
|
|
|
* @param key
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Object recursiveValue(JSONObject record, String key) {
|
|
|
|
|
String[] split = key.split(",");
|
|
|
|
|
for (int i = 0; i < split.length - 1; i++) {
|
|
|
|
|
String k = split[i];
|
|
|
|
|
if (key.startsWith("#")){
|
|
|
|
|
k = k.replace("#","");
|
|
|
|
|
record = record.getJSONArray(k).getJSONObject(0);
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (index = 0; index < split.length; index++) {
|
|
|
|
|
String k = split[index];
|
|
|
|
|
if (k.startsWith("##")) {
|
|
|
|
|
k = k.replace("##", "");
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
JSONArray jsonArray = record.getJSONArray(k);
|
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
|
Object object = jsonArray.get(i);
|
|
|
|
|
if (object instanceof String) {
|
|
|
|
|
list.add(String.valueOf(object));
|
|
|
|
|
} else {
|
|
|
|
|
List<String> keyList = new ArrayList<>();
|
|
|
|
|
for (int j = index+1; j < split.length; j++) {
|
|
|
|
|
keyList.add(split[j]);
|
|
|
|
|
}
|
|
|
|
|
Object o = recursiveValue(jsonArray.getJSONObject(i), String.join(",",keyList));
|
|
|
|
|
list.add(String.valueOf(o));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return String.join(",", list);
|
|
|
|
|
} else if (k.startsWith("#")) {
|
|
|
|
|
k = k.replace("#", "");
|
|
|
|
|
record = record.getJSONObject(k);
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return record.get(split[split.length-1]);
|
|
|
|
|
return record.get(split[index]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void send(RequestVo request) {
|
|
|
|
|