这里写自定义目录标题
接口全实现
接口
public interface AccountTransferService {
void calculate(DistributionMongoDTO distributionMongoDTO, List<SettlementFundtransferDetailInfoDTO> detailInfoDTOS);
}
实现
@Component
public class BenefitServiceImpl implements AccountTransferService {}
public class CashServiceImpl implements AccountTransferService {}
public class SellerServiceImpl implements AccountTransferService {}
public class SpecialServiceImpl implements AccountTransferService {}
调用
@Resource
private List<AccountTransferService> accountTransferServices;
accountTransferServices.forEach(service->{
service.calculate(distributionMongoDTO,detailInfoDTOS);
});
接口指定实现(重点在于@Service(“XXX”))
接口
public interface AccountComponent {
void saveMongo(SnapData<SettlementFundTransferInfoDTO> snapData);
SnapData<SettlementFundTransferInfoDTO> getMongoData(String originalKey);
}
实现
@Service("cashAccount")
public class CashAccountComponent implements AccountComponent {
@Resource
private YuGong yuGong;
@Resource
private DistributionFundTransferComponent distributionFundTransferComponent;
@DubboReference(version = WtiApiConstant.DUBBO_SERVICE_VERSION, protocol = WtiApiConstant.DUBBO_SERVICE_PROTOCOL)
private SettlementRetryService settlementRetryService;
@Autowired
SnapshotWrapperService<Inventory> cashAccountMongoService;
@Override
public void saveMongo(SnapData<SettlementFundTransferInfoDTO> snapData) {
distributionFundTransferComponent.saveProjectRelatedMongo(snapData);
MongoWriteRetryData<Inventory> build = MongoWriteRetryData.builder().collectionName("settlementCashAccount").inventory(null).snapData(snapData).build();
RetryPacket.RetryPacketBuilder<MongoWriteRetryData<Inventory>> builderMongo = RetryPacket.builder(settlementRetryService.serviceName(), RetryDefaultAction.DEFAULT_MONGO_WRITE_DATA_RETRY, build, null);
yuGong.collect(builderMongo.build());
}
@Override
public SnapData<SettlementFundTransferInfoDTO> getMongoData(String originalKey) {
return cashAccountMongoService.querySnapDataByOriginalKey(originalKey);
}
}
@Service("specialAccount")
public class SpecialAccountComponent implements AccountComponent {
@Resource
private YuGong yuGong;
@DubboReference(version = WtiApiConstant.DUBBO_SERVICE_VERSION, protocol = WtiApiConstant.DUBBO_SERVICE_PROTOCOL)
private SettlementRetryService settlementRetryService;
@Autowired
SnapshotWrapperService<Inventory> specialAccountMongoService;
@Resource
private DistributionFundTransferComponent distributionFundTransferComponent;
@Override
public void saveMongo(SnapData<SettlementFundTransferInfoDTO> snapData) {
distributionFundTransferComponent.saveProjectRelatedMongo(snapData);
MongoWriteRetryData<Inventory> build = MongoWriteRetryData.builder().collectionName("settlementSpecialAccount").inventory(null).snapData(snapData).build();
RetryPacket.RetryPacketBuilder<MongoWriteRetryData<Inventory>> builderMongo = RetryPacket.builder(settlementRetryService.serviceName(), RetryDefaultAction.DEFAULT_MONGO_WRITE_DATA_RETRY, build, null);
yuGong.collect(builderMongo.build());
}
@Override
public SnapData<SettlementFundTransferInfoDTO> getMongoData(String originalKey) {
return specialAccountMongoService.querySnapDataByOriginalKey(originalKey);
}
}
调用
@Resource
private Map<String, AccountComponent> map;
AccountComponent accountComponent = map.get(type);
//保存mongo
accountComponent.saveMongo(mongoData);
String type = reviewDTO.getType();
AccountComponent accountComponent = map.get(type);
SnapData<SettlementFundTransferInfoDTO> mongoData = accountComponent.getMongoData(reviewDTO.getParentOriginalKey());