|
|
|
@ -12,6 +12,7 @@ import com.lark.oapi.service.contact.v3.model.UserContactInfo;
|
|
|
|
|
import com.ruoyi.common.enums.*;
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.DataStructureHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
|
|
|
|
|
import com.ruoyi.flyingbook.domain.*;
|
|
|
|
@ -27,6 +28,7 @@ import org.apache.commons.collections4.MultiValuedMap;
|
|
|
|
|
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
|
|
|
@ -55,6 +57,12 @@ public class EdiOperateServiceImpl implements EdiOperateService {
|
|
|
|
|
private LarkUserHelper larkUserHelper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private LarkTableHelper larkTableHelper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private LarkRobotHelper larkRobotHelper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ErpLarkRelationMapper erpLarkRelationMapper;
|
|
|
|
|
@Value("${lark.robot.group}")
|
|
|
|
|
private String ROBOT_GROUP;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -86,6 +94,58 @@ public class EdiOperateServiceImpl implements EdiOperateService {
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void cjtCallback(CJTEdiCallbackRequestVo request) {
|
|
|
|
|
if (StringUtils.isBlank(request.getMsgType()) || StringUtils.isBlank(request.getVoucherCode())){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LarkCompanyRelation queryCompany = new LarkCompanyRelation();
|
|
|
|
|
queryCompany.setAppType(AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.getCode());
|
|
|
|
|
queryCompany.setFlag(FlagStatus.OK.getCode());
|
|
|
|
|
List<LarkCompanyRelation> larkCompanyRelations = larkCompanyRelationMapper.selectLarkCompanyRelationList(queryCompany);
|
|
|
|
|
if (CollectionUtils.isEmpty(larkCompanyRelations)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LarkCompanyRelation companyRelation = larkCompanyRelations.get(0);
|
|
|
|
|
LarkTableRelation queryTable = new LarkTableRelation();
|
|
|
|
|
queryTable.setLarkCompanyRelationId(companyRelation.getId());
|
|
|
|
|
queryTable.setFlag(FlagStatus.OK.getCode());
|
|
|
|
|
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(queryTable);
|
|
|
|
|
if (CollectionUtils.isEmpty(larkTableRelations)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LarkTableRelation tableRelation = larkTableRelations.get(0);
|
|
|
|
|
List<ErpLarkRelation> relationList = erpLarkRelationMapper.queryListByKey(request.getVoucherCode(), "https://openapi.chanjet.com/tplus/api/v2/SaleDispatchOpenApi/FindVoucherList");
|
|
|
|
|
List<String> larkKeyErrorList = new ArrayList<>();
|
|
|
|
|
List<Long> deleteIdList = new ArrayList<>();
|
|
|
|
|
for (ErpLarkRelation erpLarkRelation : relationList) {
|
|
|
|
|
LarkTableRequest deleteLarkRequest = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId(), erpLarkRelation.getLarkKey());
|
|
|
|
|
try {
|
|
|
|
|
larkTableHelper.deleteTableRecord(deleteLarkRequest);
|
|
|
|
|
deleteIdList.add(erpLarkRelation.getId());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("删除飞书记录失败 {}",JSONObject.toJSONString(deleteLarkRequest),e);
|
|
|
|
|
larkKeyErrorList.add(String.format("【%s,%s】",erpLarkRelation.getLarkKey(),e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(deleteIdList)){
|
|
|
|
|
erpLarkRelationMapper.deleteErpLarkRelationByIds(deleteIdList);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(larkKeyErrorList)){
|
|
|
|
|
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(companyRelation,tableRelation,larkKeyErrorList));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildRobotErrorCountMessage(LarkCompanyRelation companyRelation,LarkTableRelation tableRelation,List<String> larkKeyErrorList){
|
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
|
body.put("appId",companyRelation.getAppId());
|
|
|
|
|
body.put("secret",companyRelation.getSecret());
|
|
|
|
|
body.put("appToken",tableRelation.getToAppToken());
|
|
|
|
|
body.put("tableId",tableRelation.getToTableId());
|
|
|
|
|
body.put("codeList",String.join(",",larkKeyErrorList));
|
|
|
|
|
return body.toJSONString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建数据表
|
|
|
|
|
*/
|
|
|
|
|