调查表工作流审批通过(调用方)InvestigateHeaderController
org.srm.supplier.api.controller.v1.InvestigateHeaderController#approveWork
org.srm.supplier.api.controller.v1.InvestigateHeaderController#approveWork
@ApiOperation(value = "调查表工作流审批通过")
@ApiImplicitParams({
@ApiImplicitParam(name = "organizationId", value = "租户ID", paramType = "path", required = true),
@ApiImplicitParam(name = "investigateHeaderId", value = "调查表ID", paramType = "path", required = true)
})
@Permission(level = ResourceLevel.ORGANIZATION)
@PostMapping("/approve/work/{investgHeaderId}")
public ResponseEntity approveWork(@PathVariable("organizationId") Long tenantId,
@Encrypt @PathVariable("investgHeaderId") Long investigateHeaderId) {
return Results.success(investigateHeaderService.wflApproveInvestigate(tenantId, investigateHeaderId));
}
调查表工作流审批通过(调用方 InvestigateHeaderServiceImpl)
org.srm.supplier.app.service.impl.InvestigateHeaderServiceImpl#wflApproveInvestigate
@Override
@Transactional(rollbackFor = Exception.class)
@SagaStart
public InvestigateHeader wflApproveInvestigate(Long tenantId, Long investigateHeaderId) {
return approveInvestigate(tenantId, investigateHeaderId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public InvestigateHeader approveInvestigate(Long tenantId, Long investigateHeaderId) {
InvestigateHeader investigateHeader = investigateHeaderRepository.selectInvestigateHeaderByHeaderId(investigateHeaderId);
Assert.notNull(investigateHeader, DATA_NOT_EXISTS);
investigateHeader.setProcessDate(new Date());
investigateHeader.setProcessStatus(SslmConstants.InvestigateStatus.INVESTIGATE_STATUS_APPROVE);
investigateHeaderRepository.updateOptional(investigateHeader, InvestigateHeader.FIELD_PROCESS_DATE, InvestigateHeader.FIELD_PROCESS_STATUS);
// 审批结束后回调结果
if (InvestigateHeader.TRIGGER_BY_INVITE.equals(investigateHeader.getTriggerByCode())) {
// 2020.1.16,修改合作邀约触发调查表未生成对应子公司的导入erp行信息及生命周期信息缺陷。平台增加返回数据lifeCycleParamList
String sagaKey = SagaClient.getSagaKey();
ResponseEntity<PartnerInviteVO> partnerInviteVOResponseEntity = spfmRemoteService.approveInviteSaga(sagaKey,investigateHeader.getTenantId(),
investigateHeader.getTriggerById());
Assert.notNull(partnerInviteVOResponseEntity.getBody().getInviteId(), SslmConstants.ErrorCode.SPFM_APPROVE_INVITE_FAIL);
} else if (InvestigateHeader.TRIGGER_BY_LIFE_CYCLE.equals(investigateHeader.getTriggerByCode())) {
//生命周期触发调查表
lifeCycleService.approvedStageChange(investigateHeader.getTriggerById());
}
}
feign调用SPFM服务
org.srm.supplier.infra.feign.SpfmRemoteService#approveInviteSaga
/**
* 合作邀约:接受邀约(Saga)
*
* @param tenantId 租户ID
* @param inviteId 邀请ID
* @return PartnerVO 合作伙伴
*/
@PostMapping("/{organizationId}/approve/saga/{inviteId}")
ResponseEntity<PartnerInviteVO> approveInviteSaga(
@RequestParam(name = "sagaKey") String sagaKey,
@ApiParam(value = "租户id", required = true) @PathVariable(name = "organizationId") Long tenantId,
@ApiParam(value = "合作伙伴邀约id", required = true) @PathVariable(name = "inviteId") Long inviteId);
@Override
public ResponseEntity<PartnerInviteVO> approveInviteSaga(String sagaKey,Long tenantId, Long inviteId) {
logger.error("Saga Batch UnLink srm-platform partner failed = {}.", tenantId, inviteId);
throw new CommonException(SslmConstants.ErrorCode.INVESTIGATE_WRITEBACK_ERROR);
}
公司级或者集团级接受邀约(被调用方)PartnerInviteController
org.srm.platform.api.controller.v1.PartnerInviteController#approveInviteSaga
@ApiOperation(value = "公司级或者集团级接受邀约")
@Permission(level = ResourceLevel.ORGANIZATION)
@PostMapping(value = "/approve/saga/{inviteId}")
public ResponseEntity<PartnerInvite> approveInviteSaga(@RequestParam("sagaKey") String sagaKey,
@ApiParam(value = "租户id", required = true) @PathVariable(name = "organizationId") Long tenantId,
@Encrypt @ApiParam(value = "合作伙伴邀约id", required = true) @PathVariable Long inviteId) {
PartnerInvite partnerInvite = partnerInviteService.approveLevelInvite(sagaKey,tenantId, inviteId);
//发消息 批量初始化供应商生命周期数据
//消息改成一直都发,执不执行在处理方法中判断
eventSender.fireEvent(SSLM_LIFECYCLESYNC, SSLM_LIFECYCLESYNC,
SpfmConstants.Default.DEFAULT_TENANT_ID, SSLM_LIFECYCLESYNC_CONFIG, partnerInvite.getLifeCycleParamList());
return Results.success(partnerInvite);
}
公司级或者集团级接受邀约(被调用方)PartnerInviteServiceImpl
org.srm.platform.app.service.impl.PartnerInviteServiceImpl#approveLevelInvite
public static final String methedName = "SPFM-PARTNERINVITESERVICEIMPL-APPROVELEVELINVITE";
public static final String noSagaKey = "noSagaKey";
@Override
@Transactional(rollbackFor = Exception.class)
@Compensable(compensationMethod="approveLevelInviteRollBack")
public PartnerInvite approveLevelInvite(String sagaKey,Long tenantId, Long inviteId) {
return approveLevelInviteCommon(sagaKey,tenantId, inviteId);
}
@Transactional(rollbackFor = Exception.class)
public PartnerInvite approveLevelInviteCommon(String sagaKey,Long tenantId, Long inviteId) {
// (2) 幂等检查
if(SagaClient.checkSagaKeyExist(sagaKey, methedName)&&!sagaKey.equals(noSagaKey)) {
PartnerInvite partnerInvite = partnerInviteRepository.selectByPrimaryKey(inviteId);
return partnerInvite;
}else {
SagaClient.putInitSagaData(sagaKey, methedName);
}
Map<String, String> sagaMap = new HashMap<>();
CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
//根据邀请id查出合作邀约信息
PartnerInvite partnerInvite = partnerInviteRepository.selectByPrimaryKey(inviteId);
String updatePartnerInviteOne = "UPDATE-PARTNERINVITE-1";
try {
String beforeUpdatePartnerInvite = objectMapper.writeValueAsString(partnerInvite);
sagaMap.put(updatePartnerInviteOne,beforeUpdatePartnerInvite);
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new CommonException("序列化partner-invite异常");
}
SagaClient.putSagaData(sagaKey,methedName,sagaMap);
return partnerInvite;
}
@SagaCompensate(methodKey =methedName )
public PartnerInvite approveLevelInviteRollBack(String sagaKey,Long tenantId, Long inviteId) {
Map<String, String> sagaData = SagaClient.getSagaData(sagaKey, methedName);
String updatePartnerInvite = sagaData.get("UPDATE-PARTNERINVITE-1");
if(null!=updatePartnerInvite){
try {
PartnerInvite partnerInvite = objectMapper.readValue(updatePartnerInvite, PartnerInvite.class);
partnerInvite.setObjectVersionNumber(partnerInviteRepository.selectByPrimaryKey(partnerInvite).getObjectVersionNumber());
partnerInviteRepository.updateByPrimaryKey(partnerInvite);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}