畅捷通监听事件回调
continuous-integration/drone/push Build is passing Details

沃森川job同步飞书
YXY 1 year ago
parent 1924aba43e
commit 8eed20a9c2

@ -7,6 +7,7 @@ import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.PdfUtils; import com.ruoyi.common.utils.PdfUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper; import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper;
import com.ruoyi.flyingbook.domain.EventLog; import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.edi.CJTEdiCallbackRequestVo;
import com.ruoyi.flyingbook.domain.edi.EdiResponseVo; import com.ruoyi.flyingbook.domain.edi.EdiResponseVo;
import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest; import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest;
import com.ruoyi.flyingbook.domain.edi.CJTEdiRequestVo; import com.ruoyi.flyingbook.domain.edi.CJTEdiRequestVo;
@ -41,6 +42,7 @@ public class EdiController extends BaseController {
private IEventLogService iEventLogService; private IEventLogService iEventLogService;
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
/** /**
* *
*/ */
@ -55,7 +57,7 @@ public class EdiController extends BaseController {
log1.setErrorMessage("asd"); log1.setErrorMessage("asd");
iEventLogService.insertEventLog(log1); iEventLogService.insertEventLog(log1);
EventLog log2 = new EventLog(); EventLog log2 = new EventLog();
iEventLogService.insertBatchEventLog(Arrays.asList(log1,log2)); iEventLogService.insertBatchEventLog(Arrays.asList(log1, log2));
} }
/** /**
@ -64,31 +66,48 @@ public class EdiController extends BaseController {
@PostMapping("/cjtTicket") @PostMapping("/cjtTicket")
public JSONObject receiveCjtTicket(@RequestBody CJTEdiRequestVo request) { public JSONObject receiveCjtTicket(@RequestBody CJTEdiRequestVo request) {
try { try {
log.error("receiveWscTicket request:{}",JSONObject.toJSONString(request)); log.error("receiveWscTicket request:{}", JSONObject.toJSONString(request));
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec("ND2ANZB8F7NplUqc".getBytes(StandardCharsets.UTF_8), "AES")); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec("ND2ANZB8F7NplUqc".getBytes(StandardCharsets.UTF_8), "AES"));
byte[] bytes = Base64.decodeBase64(request.getEncryptMsg()); byte[] bytes = Base64.decodeBase64(request.getEncryptMsg());
bytes = cipher.doFinal(bytes); bytes = cipher.doFinal(bytes);
String encryptMsg = new String(bytes, StandardCharsets.UTF_8); String encryptMsg = new String(bytes, StandardCharsets.UTF_8);
log.info("receiveWscTicket encryptMsg:{}",encryptMsg); log.info("receiveWscTicket encryptMsg:{}", encryptMsg);
JSONObject jsonObject = JSONObject.parseObject(encryptMsg); JSONObject jsonObject = JSONObject.parseObject(encryptMsg);
JSONObject bizContent = jsonObject.getJSONObject("bizContent"); execeuteByType(jsonObject);
} catch (Exception e) {
log.error("receiveWscTicket error request:{}", JSONObject.toJSONString(request), e);
}
JSONObject result = new JSONObject();
result.put("result", "success");
return result;
}
private void execeuteByType(JSONObject jsonObject) {
JSONObject bizContent = jsonObject.getJSONObject("bizContent");
String msgType = jsonObject.getString("msgType");
log.info("畅捷通回调接口 {}",msgType);
if ("APP_TICKET".equals(msgType)) {
log.info("同步畅捷通 ticket");
String appTicket = bizContent.getString("appTicket"); String appTicket = bizContent.getString("appTicket");
if (StringUtils.isNotBlank(appTicket)) { if (StringUtils.isNotBlank(appTicket)) {
String appKey = jsonObject.getString("appKey"); String appKey = jsonObject.getString("appKey");
redisCache.deleteObject(buildUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY,appKey)); redisCache.deleteObject(buildUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, appKey));
redisCache.setCacheObject(buildUniqueKey(RedisConstants.CJT_TICKET_CACHE_KEY,appKey),appTicket,10, TimeUnit.MINUTES); redisCache.setCacheObject(buildUniqueKey(RedisConstants.CJT_TICKET_CACHE_KEY, appKey), appTicket, 10, TimeUnit.MINUTES);
} }
}catch (Exception e){ }else if ("SaleDispatchVoucher_Delete".equals(msgType)){
log.error("receiveWscTicket error request:{}",JSONObject.toJSONString(request),e); log.info("畅捷通删除接口回调");
String voucherCode = bizContent.getString("voucherCode");
CJTEdiCallbackRequestVo cjtEdiCallbackRequestVo = new CJTEdiCallbackRequestVo(msgType, voucherCode);
ediOperateService.cjtCallback(cjtEdiCallbackRequestVo);
} }
JSONObject result = new JSONObject();
result.put("result","success");
return result;
} }
private String buildUniqueKey(String key,String appKey){ private String buildUniqueKey(String key, String appKey) {
return String.format("%s:%s",key,appKey); return String.format("%s:%s", key, appKey);
} }
} }

@ -0,0 +1,30 @@
package com.ruoyi.flyingbook.domain.edi;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author yuxiangyong
* @create 2023-03-12 16:00
*/
@Data
@NoArgsConstructor
public class CJTEdiCallbackRequestVo {
/**
*
* APP_TICKET ticket
* SaleDispatchVoucher_Delete
*
*/
private String msgType;
/**
*
*/
private String voucherCode;
public CJTEdiCallbackRequestVo(String msgType, String voucherCode) {
this.msgType = msgType;
this.voucherCode = voucherCode;
}
}

@ -1,5 +1,6 @@
package com.ruoyi.flyingbook.edi; package com.ruoyi.flyingbook.edi;
import com.ruoyi.flyingbook.domain.edi.CJTEdiCallbackRequestVo;
import com.ruoyi.flyingbook.domain.edi.EdiRequestVo; import com.ruoyi.flyingbook.domain.edi.EdiRequestVo;
import com.ruoyi.flyingbook.domain.edi.EdiResponseVo; import com.ruoyi.flyingbook.domain.edi.EdiResponseVo;
import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest; import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest;
@ -12,4 +13,9 @@ public interface EdiOperateService {
public EdiResponseVo sync2Table(SyncToTableRequest ediRequestVo); public EdiResponseVo sync2Table(SyncToTableRequest ediRequestVo);
/**
*
*/
public void cjtCallback(CJTEdiCallbackRequestVo request);
} }

@ -12,6 +12,7 @@ import com.lark.oapi.service.contact.v3.model.UserContactInfo;
import com.ruoyi.common.enums.*; import com.ruoyi.common.enums.*;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.LarkHelper.DataStructureHelper; import com.ruoyi.flyingbook.LarkHelper.DataStructureHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper; import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper; import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
import com.ruoyi.flyingbook.domain.*; 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.collections4.multimap.ArrayListValuedHashMap;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
@ -55,6 +57,12 @@ public class EdiOperateServiceImpl implements EdiOperateService {
private LarkUserHelper larkUserHelper; private LarkUserHelper larkUserHelper;
@Autowired @Autowired
private LarkTableHelper larkTableHelper; private LarkTableHelper larkTableHelper;
@Autowired
private LarkRobotHelper larkRobotHelper;
@Autowired
private ErpLarkRelationMapper erpLarkRelationMapper;
@Value("${lark.robot.group}")
private String ROBOT_GROUP;
@Override @Override
@ -86,6 +94,58 @@ public class EdiOperateServiceImpl implements EdiOperateService {
return vo; 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();
}
/** /**
* *
*/ */

@ -60,7 +60,7 @@ public interface ErpLarkRelationMapper
* @param ids ID * @param ids ID
* @return * @return
*/ */
public int deleteErpLarkRelationByIds(Long[] ids); public int deleteErpLarkRelationByIds(@Param("array") List<Long> array);
public List<ErpLarkRelation> queryListByKeyList(@Param("keyList") List<String> keyList,@Param("method") String method); public List<ErpLarkRelation> queryListByKeyList(@Param("keyList") List<String> keyList,@Param("method") String method);
@ -69,4 +69,6 @@ public interface ErpLarkRelationMapper
* *
*/ */
public int batchInsert(@Param("erpLarkRelationList") List<ErpLarkRelation> erpLarkRelationList); public int batchInsert(@Param("erpLarkRelationList") List<ErpLarkRelation> erpLarkRelationList);
public List<ErpLarkRelation> queryListByKey(@Param("key") String key,@Param("method") String method);
} }

@ -80,7 +80,8 @@ public class ErpLarkRelationServiceImpl implements IErpLarkRelationService
@Override @Override
public int deleteErpLarkRelationByIds(Long[] ids) public int deleteErpLarkRelationByIds(Long[] ids)
{ {
return erpLarkRelationMapper.deleteErpLarkRelationByIds(ids); return 0;
// return erpLarkRelationMapper.deleteErpLarkRelationByIds(ids);
} }
/** /**

@ -46,6 +46,12 @@
</foreach> </foreach>
</select> </select>
<select id="queryListByKey" resultMap="ErpLarkRelationResult">
select id,`key`, `method`,lark_key
from erp_lark_relation
where `method` = #{method} and `key` like CONCAT('%',#{key},'%')
</select>
<insert id="insertErpLarkRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation" <insert id="insertErpLarkRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation"
useGeneratedKeys="true" keyProperty="id"> useGeneratedKeys="true" keyProperty="id">
insert into erp_lark_relation insert into erp_lark_relation

Loading…
Cancel
Save