mirror of
https://github.com/valitydev/newway.git
synced 2024-11-06 09:25:22 +00:00
Change after review
This commit is contained in:
parent
1d55eab885
commit
ae51ed2e5e
@ -5,10 +5,14 @@ import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ContractDao extends GenericDao {
|
||||
Long save(Contract contract) throws DaoException;
|
||||
Optional<Long> save(Contract contract) throws DaoException;
|
||||
|
||||
Contract get(String partyId, String contractId) throws DaoException;
|
||||
void switchCurrent(String partyId, String contractId) throws DaoException;
|
||||
|
||||
void updateNotCurrent(Long contractId) throws DaoException;
|
||||
|
||||
List<Contract> getByPartyId(String partyId);
|
||||
}
|
||||
|
@ -5,10 +5,14 @@ import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ContractorDao extends GenericDao {
|
||||
Long save(Contractor contractor) throws DaoException;
|
||||
Optional<Long> save(Contractor contractor) throws DaoException;
|
||||
|
||||
Contractor get(String partyId, String contractorId) throws DaoException;
|
||||
void switchCurrent(String partyId, String contractorId) throws DaoException;
|
||||
|
||||
void updateNotCurrent(Long id) throws DaoException;
|
||||
|
||||
List<Contractor> getByPartyId(String partyId);
|
||||
}
|
||||
|
@ -4,8 +4,14 @@ import com.rbkmoney.dao.GenericDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PartyDao extends GenericDao {
|
||||
Long save(Party party) throws DaoException;
|
||||
Optional<Long> save(Party party) throws DaoException;
|
||||
|
||||
Party get(String partyId) throws DaoException;
|
||||
void switchCurrent(String partyId) throws DaoException;
|
||||
|
||||
void updateNotCurrent(Long partyId) throws DaoException;
|
||||
|
||||
void saveWithUpdateCurrent(Integer changeId, long sequenceId, String partyId, Party partySource, Long oldId, String eventName);
|
||||
}
|
||||
|
@ -5,10 +5,16 @@ import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ShopDao extends GenericDao {
|
||||
Long save(Shop shop) throws DaoException;
|
||||
Optional<Long> save(Shop shop) throws DaoException;
|
||||
|
||||
Shop get(String partyId, String shopId) throws DaoException;
|
||||
void switchCurrent(String partyId, String shopId) throws DaoException;
|
||||
|
||||
void updateNotCurrent(Long shopId) throws DaoException;
|
||||
|
||||
List<Shop> getByPartyId(String partyId);
|
||||
|
||||
void saveWithUpdateCurrent(String partyId, Integer changeId, Shop shopSource, String shopId, long sequenceId, Long oldEventId, String eventName);
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.records.ContractRecord;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import org.jooq.Query;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.rbkmoney.newway.domain.Tables.*;
|
||||
import static com.rbkmoney.newway.domain.Tables.PARTY;
|
||||
import static com.rbkmoney.newway.domain.Tables.CONTRACT;
|
||||
|
||||
@Component
|
||||
public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
|
||||
@ -29,15 +29,15 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long save(Contract contract) throws DaoException {
|
||||
public Optional<Long> save(Contract contract) throws DaoException {
|
||||
ContractRecord record = getDslContext().newRecord(CONTRACT, contract);
|
||||
Query query = getDslContext().insertInto(CONTRACT).set(record)
|
||||
.onConflict(CONTRACT.PARTY_ID, CONTRACT.SEQUENCE_ID, CONTRACT.CHANGE_ID)
|
||||
.doNothing()
|
||||
.returning(CONTRACT.ID);
|
||||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
executeOne(query, keyHolder);
|
||||
return keyHolder.getKey().longValue();
|
||||
execute(query, keyHolder);
|
||||
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,15 +45,18 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
|
||||
Query query = getDslContext().selectFrom(CONTRACT)
|
||||
.where(CONTRACT.PARTY_ID.eq(partyId).and(CONTRACT.CONTRACT_ID.eq(contractId)).and(CONTRACT.CURRENT));
|
||||
|
||||
return fetchOne(query, contractRowMapper);
|
||||
Contract contract = fetchOne(query, contractRowMapper);
|
||||
if (contract == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchCurrent(String partyId, String contractId) throws DaoException {
|
||||
this.getNamedParameterJdbcTemplate().update("update nw.contract set current = false where party_id =:party_id and contract_id =:contract_id and current;" +
|
||||
"update nw.contract set current = true where id = (select max(id) from nw.contract where party_id =:party_id and contract_id =:contract_id);",
|
||||
new MapSqlParameterSource("party_id", partyId)
|
||||
.addValue("contract_id", contractId));
|
||||
public void updateNotCurrent(Long contractId) throws DaoException {
|
||||
Query query = getDslContext().update(CONTRACT).set(CONTRACT.CURRENT, false)
|
||||
.where(CONTRACT.ID.eq(contractId));
|
||||
executeOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,17 +6,17 @@ import com.rbkmoney.newway.dao.party.iface.ContractorDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.domain.tables.records.ContractorRecord;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import org.jooq.Query;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.rbkmoney.newway.domain.Tables.CONTRACTOR;
|
||||
import static com.rbkmoney.newway.domain.Tables.PARTY;
|
||||
|
||||
@Component
|
||||
public class ContractorDaoImpl extends AbstractGenericDao implements ContractorDao {
|
||||
@ -29,31 +29,33 @@ public class ContractorDaoImpl extends AbstractGenericDao implements ContractorD
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long save(Contractor contractor) throws DaoException {
|
||||
public Optional<Long> save(Contractor contractor) throws DaoException {
|
||||
ContractorRecord record = getDslContext().newRecord(CONTRACTOR, contractor);
|
||||
Query query = getDslContext().insertInto(CONTRACTOR).set(record)
|
||||
.onConflict(CONTRACTOR.PARTY_ID, CONTRACTOR.SEQUENCE_ID, CONTRACTOR.CHANGE_ID)
|
||||
.doNothing()
|
||||
.returning(CONTRACTOR.ID);
|
||||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
executeOne(query, keyHolder);
|
||||
return keyHolder.getKey().longValue();
|
||||
execute(query, keyHolder);
|
||||
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contractor get(String partyId, String contractorId) throws DaoException {
|
||||
Query query = getDslContext().selectFrom(CONTRACTOR)
|
||||
.where(CONTRACTOR.PARTY_ID.eq(partyId).and(CONTRACTOR.CONTRACTOR_ID.eq(contractorId)).and(CONTRACTOR.CURRENT));
|
||||
|
||||
return fetchOne(query, contractorRowMapper);
|
||||
Contractor contractor = fetchOne(query, contractorRowMapper);
|
||||
if (contractor == null) {
|
||||
throw new NotFoundException(String.format("Contractor not found, contractorId='%s'", contractorId));
|
||||
}
|
||||
return contractor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchCurrent(String partyId, String contractorId) throws DaoException {
|
||||
this.getNamedParameterJdbcTemplate().update("update nw.contractor set current = false where party_id =:party_id and contractor_id =:contractor_id and current;" +
|
||||
"update nw.contractor set current = true where id = (select max(id) from nw.contractor where party_id =:party_id and contractor_id =:contractor_id);",
|
||||
new MapSqlParameterSource("party_id", partyId)
|
||||
.addValue("contractor_id", contractorId));
|
||||
public void updateNotCurrent(Long id) throws DaoException {
|
||||
Query query = getDslContext().update(CONTRACTOR).set(CONTRACTOR.CURRENT, false)
|
||||
.where(CONTRACTOR.ID.eq(id));
|
||||
executeOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,16 +6,19 @@ import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.domain.tables.records.PartyRecord;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jooq.Query;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.rbkmoney.newway.domain.Tables.PARTY;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PartyDaoImpl extends AbstractGenericDao implements PartyDao {
|
||||
|
||||
@ -27,15 +30,15 @@ public class PartyDaoImpl extends AbstractGenericDao implements PartyDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long save(Party party) throws DaoException {
|
||||
public Optional<Long> save(Party party) throws DaoException {
|
||||
PartyRecord record = getDslContext().newRecord(PARTY, party);
|
||||
Query query = getDslContext().insertInto(PARTY).set(record)
|
||||
.onConflict(PARTY.PARTY_ID, PARTY.SEQUENCE_ID, PARTY.CHANGE_ID)
|
||||
.doNothing()
|
||||
.returning(PARTY.ID);
|
||||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
executeOne(query, keyHolder);
|
||||
return keyHolder.getKey().longValue();
|
||||
execute(query, keyHolder);
|
||||
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,13 +46,30 @@ public class PartyDaoImpl extends AbstractGenericDao implements PartyDao {
|
||||
Query query = getDslContext().selectFrom(PARTY)
|
||||
.where(PARTY.PARTY_ID.eq(partyId).and(PARTY.CURRENT));
|
||||
|
||||
return fetchOne(query, partyRowMapper);
|
||||
Party party = fetchOne(query, partyRowMapper);
|
||||
|
||||
if (party == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
return party;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchCurrent(String partyId) throws DaoException {
|
||||
this.getNamedParameterJdbcTemplate().update("update nw.party set current = false where party_id =:party_id and current;" +
|
||||
"update nw.party set current = true where id = (select max(id) from nw.party where party_id =:party_id);",
|
||||
new MapSqlParameterSource("party_id", partyId));
|
||||
public void updateNotCurrent(Long id) throws DaoException {
|
||||
Query query = getDslContext().update(PARTY).set(PARTY.CURRENT, false)
|
||||
.where(PARTY.ID.eq(id));
|
||||
executeOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWithUpdateCurrent(Integer changeId, long sequenceId, String partyId, Party partySource, Long oldId, String eventName) {
|
||||
save(partySource)
|
||||
.ifPresentOrElse(
|
||||
saveResult -> {
|
||||
updateNotCurrent(oldId);
|
||||
log.info("Party {} has been saved, sequenceId={}, partyId={}, changeId={}", eventName, sequenceId, partyId, changeId);
|
||||
},
|
||||
() -> log.info("Party {} duplicated, sequenceId={}, partyId={}, changeId={}", eventName, sequenceId, partyId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,20 @@ import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.domain.tables.records.ShopRecord;
|
||||
import com.rbkmoney.newway.exception.DaoException;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jooq.Query;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.rbkmoney.newway.domain.Tables.SHOP;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
|
||||
|
||||
@ -28,30 +31,34 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long save(Shop shop) throws DaoException {
|
||||
public Optional<Long> save(Shop shop) throws DaoException {
|
||||
ShopRecord record = getDslContext().newRecord(SHOP, shop);
|
||||
Query query = getDslContext().insertInto(SHOP).set(record)
|
||||
.onConflict(SHOP.PARTY_ID, SHOP.SEQUENCE_ID, SHOP.CHANGE_ID)
|
||||
.doNothing()
|
||||
.returning(SHOP.ID);
|
||||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
executeOne(query, keyHolder);
|
||||
return keyHolder.getKey().longValue();
|
||||
execute(query, keyHolder);
|
||||
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop get(String partyId, String shopId) throws DaoException {
|
||||
Query query = getDslContext().selectFrom(SHOP)
|
||||
.where(SHOP.PARTY_ID.eq(partyId).and(SHOP.SHOP_ID.eq(shopId)).and(SHOP.CURRENT));
|
||||
return fetchOne(query, shopRowMapper);
|
||||
Shop shop = fetchOne(query, shopRowMapper);
|
||||
if (shop == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
return shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchCurrent(String partyId, String shopId) throws DaoException {
|
||||
this.getNamedParameterJdbcTemplate().update("update nw.shop set current = false where party_id =:party_id and shop_id =:shop_id and current;" +
|
||||
"update nw.shop set current = true where id = (select max(id) from nw.shop where party_id =:party_id and shop_id =:shop_id);",
|
||||
new MapSqlParameterSource("party_id", partyId)
|
||||
.addValue("shop_id", shopId));
|
||||
public void updateNotCurrent(Long shopId) throws DaoException {
|
||||
Query query = getDslContext()
|
||||
.update(SHOP).set(SHOP.CURRENT, false)
|
||||
.where(SHOP.ID.eq(shopId));
|
||||
executeOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,4 +67,17 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
|
||||
.where(SHOP.PARTY_ID.eq(partyId).and(SHOP.CURRENT));
|
||||
return fetch(query, shopRowMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWithUpdateCurrent(String partyId, Integer changeId, Shop shopSource, String shopId, long sequenceId, Long oldEventId, String eventName) {
|
||||
save(shopSource).ifPresentOrElse(
|
||||
aLong -> {
|
||||
updateNotCurrent(oldEventId);
|
||||
log.info("Shop {} has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
eventName, sequenceId, partyId, shopId, changeId);
|
||||
},
|
||||
() -> log.info("Shop {}} duplicated, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
eventName, sequenceId, partyId, shopId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,5 @@ public abstract class AbstractClaimChangedHandler extends AbstractPartyManagemen
|
||||
}
|
||||
return claimStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,4 +6,7 @@ import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.poller.event_stock.Handler;
|
||||
|
||||
public abstract class AbstractPartyManagementHandler implements Handler<PartyChange, MachineEvent> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
@ -10,7 +10,6 @@ import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -36,44 +35,49 @@ public class ContractAdjustmentCreatedHandler extends AbstractClaimChangedHandle
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetAdjustmentCreated()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.ContractAdjustment adjustmentCreated = contractEffectUnit.getEffect().getAdjustmentCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract adjustment created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
|
||||
List<ContractAdjustment> adjustments = new ArrayList<>(contractAdjustmentDao.getByCntrctId(contractSourceId));
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
adjustments.add(ContractUtil.convertContractAdjustment(adjustmentCreated, cntrctId));
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
|
||||
log.info("Contract adjustment has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetAdjustmentCreated())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.ContractAdjustment adjustmentCreated = contractEffectUnit.getEffect().getAdjustmentCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract adjustment created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
Long contractSourceId = contractSource.getId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
cntrctId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
updateContractReference(adjustmentCreated, contractSourceId, cntrctId);
|
||||
log.info("Contract adjustment has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract adjustment duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateContractReference(com.rbkmoney.damsel.domain.ContractAdjustment adjustmentCreated, Long contractSourceId, Long cntrctId) {
|
||||
List<ContractAdjustment> adjustments = new ArrayList<>(contractAdjustmentDao.getByCntrctId(contractSourceId));
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
adjustments.add(ContractUtil.convertContractAdjustment(adjustmentCreated, cntrctId));
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,76 +1,60 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
public class ContractContractorIDChangedHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetContractorChanged()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
String contractorChanged = contractEffectUnit.getEffect().getContractorChanged();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract contractorChanged changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
contractSource.setContractorId(contractorChanged);
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
|
||||
log.info("Contract contractorID has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetContractorChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
|
||||
String contractorChanged = contractEffectUnit.getEffect().getContractorChanged();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract contractorChanged changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
Long contractSourceId = contractSource.getId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
contractSource.setContractorId(contractorChanged);
|
||||
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
cntrctId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, cntrctId);
|
||||
log.info("Contract contractorChanged has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract contractorChanged duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TBaseUtil;
|
||||
@ -8,9 +9,8 @@ import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.*;
|
||||
import com.rbkmoney.newway.domain.enums.ContractStatus;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
@ -43,70 +43,80 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetCreated()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contract = new Contract();
|
||||
contract.setSequenceId(sequenceId);
|
||||
contract.setChangeId(changeId);
|
||||
contract.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
contract.setContractId(contractId);
|
||||
contract.setPartyId(partyId);
|
||||
if (contractCreated.isSetPaymentInstitution()) {
|
||||
contract.setPaymentInstitutionId(contractCreated.getPaymentInstitution().getId());
|
||||
}
|
||||
contract.setCreatedAt(TypeUtil.stringToLocalDateTime(contractCreated.getCreatedAt()));
|
||||
if (contractCreated.isSetValidSince()) {
|
||||
contract.setValidSince(TypeUtil.stringToLocalDateTime(contractCreated.getValidSince()));
|
||||
}
|
||||
if (contractCreated.isSetValidUntil()) {
|
||||
contract.setValidUntil(TypeUtil.stringToLocalDateTime(contractCreated.getValidUntil()));
|
||||
}
|
||||
contract.setStatus(TBaseUtil.unionFieldToEnum(contractCreated.getStatus(), ContractStatus.class));
|
||||
if (contractCreated.getStatus().isSetTerminated()) {
|
||||
contract.setStatusTerminatedAt(TypeUtil.stringToLocalDateTime(contractCreated.getStatus().getTerminated().getTerminatedAt()));
|
||||
}
|
||||
contract.setTermsId(contractCreated.getTerms().getId());
|
||||
if (contractCreated.isSetLegalAgreement()) {
|
||||
ContractUtil.fillContractLegalAgreementFields(contract, contractCreated.getLegalAgreement());
|
||||
}
|
||||
if (contractCreated.isSetReportPreferences() && contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
|
||||
ContractUtil.fillReportPreferences(contract, contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
|
||||
}
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetCreated())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
String contractorId = "";
|
||||
if (contractCreated.isSetContractorId()) {
|
||||
contractorId = contractCreated.getContractorId();
|
||||
} else if (contractCreated.isSetContractor()) {
|
||||
contractorId = UUID.randomUUID().toString();
|
||||
}
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contract = new Contract();
|
||||
contract.setSequenceId(sequenceId);
|
||||
contract.setChangeId(changeId);
|
||||
contract.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
partyDao.get(partyId); //check party is exist
|
||||
|
||||
contract.setContractorId(contractorId);
|
||||
contract.setCurrent(true);
|
||||
contract.setContractId(contractId);
|
||||
contract.setPartyId(partyId);
|
||||
if (contractCreated.isSetPaymentInstitution()) {
|
||||
contract.setPaymentInstitutionId(contractCreated.getPaymentInstitution().getId());
|
||||
}
|
||||
contract.setCreatedAt(TypeUtil.stringToLocalDateTime(contractCreated.getCreatedAt()));
|
||||
if (contractCreated.isSetValidSince()) {
|
||||
contract.setValidSince(TypeUtil.stringToLocalDateTime(contractCreated.getValidSince()));
|
||||
}
|
||||
if (contractCreated.isSetValidUntil()) {
|
||||
contract.setValidUntil(TypeUtil.stringToLocalDateTime(contractCreated.getValidUntil()));
|
||||
}
|
||||
contract.setStatus(TBaseUtil.unionFieldToEnum(contractCreated.getStatus(), ContractStatus.class));
|
||||
if (contractCreated.getStatus().isSetTerminated()) {
|
||||
contract.setStatusTerminatedAt(TypeUtil.stringToLocalDateTime(contractCreated.getStatus().getTerminated().getTerminatedAt()));
|
||||
}
|
||||
contract.setTermsId(contractCreated.getTerms().getId());
|
||||
if (contractCreated.isSetLegalAgreement()) {
|
||||
ContractUtil.fillContractLegalAgreementFields(contract, contractCreated.getLegalAgreement());
|
||||
}
|
||||
if (contractCreated.isSetReportPreferences() && contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
|
||||
ContractUtil.fillReportPreferences(contract, contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
|
||||
}
|
||||
|
||||
long cntrctId = contractDao.save(contract);
|
||||
String contractorId = initContractorId(contractCreated);
|
||||
contract.setContractorId(contractorId);
|
||||
|
||||
if (contractCreated.isSetContractor()) {
|
||||
Contractor contractor = ContractorUtil.convertContractor(sequenceId, event.getCreatedAt(), partyId, contractCreated.getContractor(), contractorId, changeId);
|
||||
contractorDao.save(contractor);
|
||||
}
|
||||
contractDao.save(contract).ifPresentOrElse(
|
||||
cntrctId -> updateContractReference(event, changeId, sequenceId, contractCreated, contractId, partyId, contractorId, cntrctId),
|
||||
() -> log.info("contract create duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
|
||||
);
|
||||
}
|
||||
|
||||
List<com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment> adjustments = ContractUtil.convertContractAdjustments(contractCreated, cntrctId);
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
private String initContractorId(com.rbkmoney.damsel.domain.Contract contractCreated) {
|
||||
String contractorId = "";
|
||||
if (contractCreated.isSetContractorId()) {
|
||||
contractorId = contractCreated.getContractorId();
|
||||
} else if (contractCreated.isSetContractor()) {
|
||||
contractorId = UUID.randomUUID().toString();
|
||||
}
|
||||
return contractorId;
|
||||
}
|
||||
|
||||
List<com.rbkmoney.newway.domain.tables.pojos.PayoutTool> payoutTools = ContractUtil.convertPayoutTools(contractCreated, cntrctId);
|
||||
payoutToolDao.save(payoutTools);
|
||||
private void updateContractReference(MachineEvent event, Integer changeId, long sequenceId, com.rbkmoney.damsel.domain.Contract contractCreated,
|
||||
String contractId, String partyId, String contractorId, Long cntrctId) {
|
||||
if (contractCreated.isSetContractor()) {
|
||||
Contractor contractor = ContractorUtil.convertContractor(sequenceId, event.getCreatedAt(), partyId, contractCreated.getContractor(), contractorId, changeId);
|
||||
contractorDao.save(contractor);
|
||||
}
|
||||
|
||||
log.info("Contract has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
List<ContractAdjustment> adjustments = ContractUtil.convertContractAdjustments(contractCreated, cntrctId);
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<com.rbkmoney.newway.domain.tables.pojos.PayoutTool> payoutTools = ContractUtil.convertPayoutTools(contractCreated, cntrctId);
|
||||
payoutToolDao.save(payoutTools);
|
||||
|
||||
log.info("Contract has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.domain.LegalAgreement;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -20,60 +16,45 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetLegalAgreementBound()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
LegalAgreement legalAgreementBound = contractEffectUnit.getEffect().getLegalAgreementBound();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
ContractUtil.fillContractLegalAgreementFields(contractSource, legalAgreementBound);
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetLegalAgreementBound())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
|
||||
LegalAgreement legalAgreementBound = contractEffectUnit.getEffect().getLegalAgreementBound();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
Long contractSourceId = contractSource.getId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
ContractUtil.fillContractLegalAgreementFields(contractSource, legalAgreementBound);
|
||||
|
||||
log.info("Contract legal agreement bound has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
dbContractId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, dbContractId);
|
||||
log.info("Contract legal agreement bound has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract legal agreement bound duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,13 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -19,61 +15,43 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ContractPayoutToolCreatedHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetPayoutToolCreated()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.PayoutTool payoutToolCreated = contractEffectUnit.getEffect().getPayoutToolCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract payouttool created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetPayoutToolCreated())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
|
||||
com.rbkmoney.damsel.domain.PayoutTool payoutToolCreated = contractEffectUnit.getEffect().getPayoutToolCreated();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract payout tool created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
Long contractSourceId = contractSource.getId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
|
||||
List<PayoutTool> payoutTools = new ArrayList<>(payoutToolDao.getByCntrctId(contractSourceId));
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutTools.add(ContractUtil.convertPayoutTool(payoutToolCreated, cntrctId));
|
||||
payoutToolDao.save(payoutTools);
|
||||
|
||||
log.info("Contract payouttool has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
dbContractId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, dbContractId);
|
||||
log.info("Contract contract payout tool created has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract contract payout tool created duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contract;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ReportPreferences;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -20,64 +16,50 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ContractReportPreferencesChangedHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractEffect() && e.getContractEffect().getEffect().isSetReportPreferencesChanged()).forEach(e -> {
|
||||
ContractEffectUnit contractEffectUnit = e.getContractEffect();
|
||||
ReportPreferences reportPreferencesChanged = contractEffectUnit.getEffect().getReportPreferencesChanged();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract report preferences changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
if (reportPreferencesChanged != null && reportPreferencesChanged.isSetServiceAcceptanceActPreferences()) {
|
||||
ContractUtil.fillReportPreferences(contractSource, reportPreferencesChanged.getServiceAcceptanceActPreferences());
|
||||
} else {
|
||||
ContractUtil.setNullReportPreferences(contractSource);
|
||||
}
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
.filter(claimEffect -> claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetReportPreferencesChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
|
||||
ReportPreferences reportPreferencesChanged = contractEffectUnit.getEffect().getReportPreferencesChanged();
|
||||
String contractId = contractEffectUnit.getContractId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contract report preferences changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
Long contractSourceId = contractSource.getId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
|
||||
log.info("Contract report preferences has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
});
|
||||
if (reportPreferencesChanged != null && reportPreferencesChanged.isSetServiceAcceptanceActPreferences()) {
|
||||
ContractUtil.fillReportPreferences(contractSource, reportPreferencesChanged.getServiceAcceptanceActPreferences());
|
||||
} else {
|
||||
ContractUtil.setNullReportPreferences(contractSource);
|
||||
}
|
||||
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
dbContractId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, dbContractId);
|
||||
log.info("Contract report preferences has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract report preferences duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,24 @@ import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TBaseUtil;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ContractStatusChangedHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
@ -43,37 +37,26 @@ public class ContractStatusChangedHandler extends AbstractClaimChangedHandler {
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contractSource status changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
||||
Contract contractSource = contractDao.get(partyId, contractId);
|
||||
if (contractSource == null) {
|
||||
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
|
||||
}
|
||||
Long contractSourceId = contractSource.getId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
|
||||
contractSource.setStatus(TBaseUtil.unionFieldToEnum(statusChanged, com.rbkmoney.newway.domain.enums.ContractStatus.class));
|
||||
if (statusChanged.isSetTerminated()) {
|
||||
contractSource.setStatusTerminatedAt(TypeUtil.stringToLocalDateTime(statusChanged.getTerminated().getTerminatedAt()));
|
||||
}
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
contractDao.save(contractSource).ifPresentOrElse(
|
||||
dbContractId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, dbContractId);
|
||||
log.info("Contract status has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
},
|
||||
() -> log.info("Contract status duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
|
||||
log.info("Contract status has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId);
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contractor;
|
||||
|
||||
import com.rbkmoney.damsel.domain.PartyContractor;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractorEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractorDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -33,24 +32,28 @@ public class ContractorCreatedHandler extends AbstractClaimChangedHandler {
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long eventId = event.getEventId();
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractorEffect() && e.getContractorEffect().getEffect().isSetCreated()).forEach(e -> {
|
||||
ContractorEffectUnit contractorEffect = e.getContractorEffect();
|
||||
PartyContractor partyContractor = contractorEffect.getEffect().getCreated();
|
||||
com.rbkmoney.damsel.domain.Contractor contractorCreated = partyContractor.getContractor();
|
||||
String contractorId = contractorEffect.getId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
Contractor contractor = ContractorUtil.convertContractor(eventId, event.getCreatedAt(), partyId, contractorCreated, contractorId, changeId);
|
||||
contractor.setIdentificationalLevel(partyContractor.getStatus().name());
|
||||
contractorDao.save(contractor);
|
||||
log.info("Contract contractor has been saved, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
|
||||
.filter(claimEffect -> claimEffect.isSetContractorEffect() && claimEffect.getContractorEffect().getEffect().isSetCreated())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, eventId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
});
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long eventId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractorEffectUnit contractorEffect = claimEffect.getContractorEffect();
|
||||
PartyContractor partyContractor = contractorEffect.getEffect().getCreated();
|
||||
com.rbkmoney.damsel.domain.Contractor contractorCreated = partyContractor.getContractor();
|
||||
String contractorId = contractorEffect.getId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
|
||||
partyDao.get(partyId); //check party is exist
|
||||
|
||||
Contractor contractor = ContractorUtil.convertContractor(eventId, event.getCreatedAt(), partyId, contractorCreated, contractorId, changeId);
|
||||
contractor.setIdentificationalLevel(partyContractor.getStatus().name());
|
||||
|
||||
contractorDao.save(contractor).ifPresentOrElse(
|
||||
cntrctId -> log.info("Contract contractor has been saved, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId),
|
||||
() -> log.info("contract contractor duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.contractor;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ContractorIdentificationLevel;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.ContractorEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractorDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -24,28 +24,31 @@ public class ContractorIdentificationalLevelChangedHandler extends AbstractClaim
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event) {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetContractorEffect() && e.getContractorEffect().getEffect().isSetIdentificationLevelChanged()).forEach(e -> {
|
||||
ContractorEffectUnit contractorEffect = e.getContractorEffect();
|
||||
ContractorIdentificationLevel identificationLevelChanged = contractorEffect.getEffect().getIdentificationLevelChanged();
|
||||
String contractorId = contractorEffect.getId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start identificational level changed handling, sequenceId={}, partyId={}, contractorId={}", sequenceId, partyId, contractorId);
|
||||
Contractor contractorSource = contractorDao.get(partyId, contractorId);
|
||||
if (contractorSource == null) {
|
||||
throw new NotFoundException(String.format("Contractor not found, contractorId='%s'", contractorId));
|
||||
}
|
||||
contractorSource.setId(null);
|
||||
contractorSource.setRevision(null);
|
||||
contractorSource.setWtime(null);
|
||||
contractorSource.setSequenceId(sequenceId);
|
||||
contractorSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
contractorSource.setIdentificationalLevel(identificationLevelChanged.name());
|
||||
contractorDao.switchCurrent(partyId, contractorId);
|
||||
contractorDao.save(contractorSource);
|
||||
log.info("Contract identificational level has been saved, sequenceId={}, contractorId={}", sequenceId, contractorId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetContractorEffect() && claimEffect.getContractorEffect().getEffect().isSetIdentificationLevelChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ContractorEffectUnit contractorEffect = claimEffect.getContractorEffect();
|
||||
ContractorIdentificationLevel identificationLevelChanged = contractorEffect.getEffect().getIdentificationLevelChanged();
|
||||
String contractorId = contractorEffect.getId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start identificational level changed handling, sequenceId={}, partyId={}, contractorId={}", sequenceId, partyId, contractorId);
|
||||
Contractor contractorSource = contractorDao.get(partyId, contractorId);
|
||||
Long oldId = contractorSource.getId();
|
||||
ContractorUtil.resetBaseFields(event, sequenceId, contractorSource);
|
||||
contractorSource.setIdentificationalLevel(identificationLevelChanged.name());
|
||||
|
||||
contractorDao.save(contractorSource)
|
||||
.ifPresentOrElse(
|
||||
saveResult -> {
|
||||
contractorDao.updateNotCurrent(oldId);
|
||||
log.info("Party identificational has been saved, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
},
|
||||
() -> log.info("Party identificational duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.util.PartyUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -26,8 +26,8 @@ public class PartyBlockingHandler extends AbstractPartyManagementHandler {
|
||||
|
||||
private final PartyDao partyDao;
|
||||
private final Filter filter = new PathConditionFilter(new PathConditionRule(
|
||||
"party_blocking",
|
||||
new IsNullCondition().not()));
|
||||
"party_blocking",
|
||||
new IsNullCondition().not()));
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
@ -37,15 +37,9 @@ public class PartyBlockingHandler extends AbstractPartyManagementHandler {
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
partySource.setId(null);
|
||||
partySource.setRevision(null);
|
||||
partySource.setWtime(null);
|
||||
partySource.setSequenceId(sequenceId);
|
||||
partySource.setChangeId(changeId);
|
||||
partySource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldId = partySource.getId();
|
||||
PartyUtil.resetBaseFields(event, changeId, sequenceId, partySource);
|
||||
|
||||
partySource.setBlocking(TBaseUtil.unionFieldToEnum(partyBlocking, com.rbkmoney.newway.domain.enums.Blocking.class));
|
||||
if (partyBlocking.isSetUnblocked()) {
|
||||
partySource.setBlockingUnblockedReason(partyBlocking.getUnblocked().getReason());
|
||||
@ -58,9 +52,8 @@ public class PartyBlockingHandler extends AbstractPartyManagementHandler {
|
||||
partySource.setBlockingBlockedReason(partyBlocking.getBlocked().getReason());
|
||||
partySource.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(partyBlocking.getBlocked().getSince()));
|
||||
}
|
||||
partyDao.save(partySource);
|
||||
partyDao.switchCurrent(partyId);
|
||||
log.info("Party blocking has been saved, eventId={}, partyId={}", sequenceId, partyId);
|
||||
|
||||
partyDao.saveWithUpdateCurrent(changeId, sequenceId, partyId, partySource, oldId, "blocking");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,9 +53,10 @@ public class PartyCreatedHandler extends AbstractPartyManagementHandler {
|
||||
party.setSuspensionActiveSince(partyCreatedAt);
|
||||
party.setRevision(0L);
|
||||
party.setRevisionChangedAt(partyCreatedAt);
|
||||
party.setCurrent(true);
|
||||
partyDao.save(party);
|
||||
log.info("Party has been saved, sequenceId={}, partyId={}", sequenceId, partyId);
|
||||
|
||||
partyDao.save(party).ifPresentOrElse(
|
||||
aLong -> log.info("Party has been saved, sequenceId={}, ppartyId={}, changeId={}", sequenceId, partyId, changeId),
|
||||
() -> log.info("Party create duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.party;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyMetaSet;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.geck.filter.Filter;
|
||||
import com.rbkmoney.geck.filter.PathConditionFilter;
|
||||
import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
@ -10,9 +9,9 @@ import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.util.JsonUtil;
|
||||
import com.rbkmoney.newway.util.PartyUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -37,21 +36,14 @@ public class PartyMetaSetHandler extends AbstractPartyManagementHandler {
|
||||
PartyMetaSet partyMetaSet = change.getPartyMetaSet();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start party metaset handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
partySource.setId(null);
|
||||
partySource.setRevision(null);
|
||||
partySource.setWtime(null);
|
||||
partySource.setSequenceId(sequenceId);
|
||||
partySource.setChangeId(changeId);
|
||||
partySource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldId = partySource.getId();
|
||||
PartyUtil.resetBaseFields(event, changeId, sequenceId, partySource);
|
||||
partySource.setPartyMetaSetNs(partyMetaSet.getNs());
|
||||
partySource.setPartyMetaSetDataJson(JsonUtil.tBaseToJsonString(partyMetaSet.getData()));
|
||||
partyDao.save(partySource);
|
||||
partyDao.switchCurrent(partyId);
|
||||
log.info("Party metaset has been saved, eventId={}, partyId={}", sequenceId, partyId);
|
||||
|
||||
partyDao.saveWithUpdateCurrent(changeId, sequenceId, partyId, partySource, oldId, "metaset");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,19 +9,19 @@ import com.rbkmoney.geck.filter.condition.IsNullCondition;
|
||||
import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.*;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.service.ContractReferenceService;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
import com.rbkmoney.newway.util.PartyUtil;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@ -33,6 +33,7 @@ public class PartyRevisionChangedHandler extends AbstractPartyManagementHandler
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
private final ContractorDao contractorDao;
|
||||
private final ShopDao shopDao;
|
||||
private final ContractReferenceService contractReferenceService;
|
||||
|
||||
private final Filter filter = new PathConditionFilter(new PathConditionRule(
|
||||
"revision_changed",
|
||||
@ -45,20 +46,26 @@ public class PartyRevisionChangedHandler extends AbstractPartyManagementHandler
|
||||
PartyRevisionChanged partyRevisionChanged = change.getRevisionChanged();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start partySource revision changed handling, eventId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
partySource.setId(null);
|
||||
partySource.setWtime(null);
|
||||
partySource.setSequenceId(sequenceId);
|
||||
partySource.setChangeId(changeId);
|
||||
partySource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldId = partySource.getId();
|
||||
PartyUtil.resetBaseFields(event, changeId, sequenceId, partySource);
|
||||
long revision = partyRevisionChanged.getRevision();
|
||||
partySource.setRevision(revision);
|
||||
partySource.setRevisionChangedAt(TypeUtil.stringToLocalDateTime(partyRevisionChanged.getTimestamp()));
|
||||
partyDao.save(partySource);
|
||||
partyDao.switchCurrent(partyId);
|
||||
|
||||
partyDao.save(partySource)
|
||||
.ifPresentOrElse(
|
||||
aLong -> {
|
||||
partyDao.updateNotCurrent(oldId);
|
||||
updatePartyReferences(event, changeId, sequenceId, partyId, revision);
|
||||
log.info("Party revision changed has been saved, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
},
|
||||
() -> log.info("Party revision changed duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
|
||||
);
|
||||
}
|
||||
|
||||
private void updatePartyReferences(MachineEvent event, Integer changeId, long sequenceId, String partyId, long revision) {
|
||||
updateContractorsRevision(event, partyId, revision, changeId);
|
||||
updateContractsRevision(event, partyId, revision, changeId);
|
||||
updateShopsRevision(event, partyId, revision, changeId);
|
||||
@ -68,30 +75,28 @@ public class PartyRevisionChangedHandler extends AbstractPartyManagementHandler
|
||||
private void updateShopsRevision(MachineEvent event, String partyId, long revision, Integer changeId) {
|
||||
shopDao.getByPartyId(partyId).forEach(shopSource -> {
|
||||
String shopId = shopSource.getShopId();
|
||||
shopSource.setId(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setSequenceId(event.getEventId());
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
long sequenceId = event.getEventId();
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
shopSource.setRevision(revision);
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop revision has been saved, eventId={}, partyId={}, shopId={}", event.getEventId(), partyId, shopId);
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "revision");
|
||||
});
|
||||
}
|
||||
|
||||
private void updateContractorsRevision(MachineEvent event, String partyId, long revision, Integer changeId) {
|
||||
contractorDao.getByPartyId(partyId).forEach(contractorSource -> {
|
||||
String contractorId = contractorSource.getContractorId();
|
||||
contractorSource.setId(null);
|
||||
contractorSource.setWtime(null);
|
||||
contractorSource.setSequenceId(event.getEventId());
|
||||
contractorSource.setChangeId(changeId);
|
||||
contractorSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldId = contractorSource.getId();
|
||||
long sequenceId = event.getEventId();
|
||||
ContractorUtil.resetBaseFields(event, sequenceId, contractorSource);
|
||||
contractorSource.setRevision(revision);
|
||||
contractorDao.switchCurrent(partyId, contractorId);
|
||||
contractorDao.save(contractorSource);
|
||||
log.info("Contractor revision has been saved, eventId={}, partyId={}, contractorId={}", event.getEventId(), partyId, contractorId);
|
||||
contractorDao.save(contractorSource)
|
||||
.ifPresentOrElse(
|
||||
saveResult -> {
|
||||
contractorDao.updateNotCurrent(oldId);
|
||||
log.info("Party revision has been saved, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
},
|
||||
() -> log.info("Party revision duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -99,29 +104,20 @@ public class PartyRevisionChangedHandler extends AbstractPartyManagementHandler
|
||||
contractDao.getByPartyId(partyId).forEach(contractSource -> {
|
||||
Long contractSourceId = contractSource.getId();
|
||||
String contractId = contractSource.getContractId();
|
||||
contractSource.setId(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(event.getEventId());
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
long sequenceId = event.getEventId();
|
||||
ContractUtil.resetBaseFields(event, changeId, sequenceId, contractSource);
|
||||
contractSource.setRevision(revision);
|
||||
contractDao.switchCurrent(partyId, contractId);
|
||||
long cntrctId = contractDao.save(contractSource);
|
||||
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(cntrctId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(cntrctId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
log.info("Contract revision has been saved, eventId={}, partyId={}, contractId={}", event.getEventId(), partyId, contractId);
|
||||
contractDao.save(contractSource)
|
||||
.ifPresentOrElse(
|
||||
dbContractId -> {
|
||||
contractDao.updateNotCurrent(contractSourceId);
|
||||
contractReferenceService.updateContractReference(contractSourceId, dbContractId);
|
||||
log.info("Contract revision has been saved, eventId={}, partyId={}, contractId={}", event.getEventId(), partyId, contractId);
|
||||
},
|
||||
() -> log.info("Contract revision duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
|
||||
sequenceId, partyId, contractId, changeId)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.util.PartyUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -22,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Component
|
||||
public class PartySuspensionHandler extends AbstractPartyManagementHandler {
|
||||
|
||||
public static final String PARTY_SUSPENSION = "party_suspension";
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final PartyDao partyDao;
|
||||
@ -31,7 +32,7 @@ public class PartySuspensionHandler extends AbstractPartyManagementHandler {
|
||||
public PartySuspensionHandler(PartyDao partyDao) {
|
||||
this.partyDao = partyDao;
|
||||
this.filter = new PathConditionFilter(new PathConditionRule(
|
||||
"party_suspension",
|
||||
PARTY_SUSPENSION,
|
||||
new IsNullCondition().not()));
|
||||
}
|
||||
|
||||
@ -41,17 +42,11 @@ public class PartySuspensionHandler extends AbstractPartyManagementHandler {
|
||||
long sequenceId = event.getEventId();
|
||||
Suspension partySuspension = change.getPartySuspension();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start party suspension handling, eventId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
|
||||
log.info("Start {} handling, eventId={}, partyId={}, changeId={}", PARTY_SUSPENSION, sequenceId, partyId, changeId);
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
partySource.setId(null);
|
||||
partySource.setRevision(null);
|
||||
partySource.setWtime(null);
|
||||
partySource.setSequenceId(sequenceId);
|
||||
partySource.setChangeId(changeId);
|
||||
partySource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldId = partySource.getId();
|
||||
PartyUtil.resetBaseFields(event, changeId, sequenceId, partySource);
|
||||
|
||||
partySource.setSuspension(TBaseUtil.unionFieldToEnum(partySuspension, com.rbkmoney.newway.domain.enums.Suspension.class));
|
||||
if (partySuspension.isSetActive()) {
|
||||
partySource.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(partySuspension.getActive().getSince()));
|
||||
@ -60,9 +55,8 @@ public class PartySuspensionHandler extends AbstractPartyManagementHandler {
|
||||
partySource.setSuspensionActiveSince(null);
|
||||
partySource.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(partySuspension.getSuspended().getSince()));
|
||||
}
|
||||
partyDao.save(partySource);
|
||||
partyDao.switchCurrent(partyId);
|
||||
log.info("Party suspension has been saved, eventId={}, partyId={}", sequenceId, partyId);
|
||||
|
||||
partyDao.saveWithUpdateCurrent(changeId, sequenceId, partyId, partySource, oldId, PARTY_SUSPENSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,12 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ShopAccount;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -28,29 +27,25 @@ public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetAccountCreated()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopAccount accountCreated = shopEffect.getEffect().getAccountCreated();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop accountCreated handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
ShopUtil.fillShopAccount(shopSource, accountCreated);
|
||||
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop accountCreated has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetAccountCreated())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopAccount accountCreated = shopEffect.getEffect().getAccountCreated();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop accountCreated handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
ShopUtil.fillShopAccount(shopSource, accountCreated);
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "accountCreated");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -38,16 +38,16 @@ public class ShopBlockingHandler extends AbstractPartyManagementHandler {
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop blocking handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
initBlockingFields(blocking, shopSource);
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "blocking");
|
||||
}
|
||||
|
||||
private void initBlockingFields(Blocking blocking, Shop shopSource) {
|
||||
shopSource.setBlocking(TBaseUtil.unionFieldToEnum(blocking, com.rbkmoney.newway.domain.enums.Blocking.class));
|
||||
if (blocking.isSetUnblocked()) {
|
||||
shopSource.setBlockingUnblockedReason(blocking.getUnblocked().getReason());
|
||||
@ -60,10 +60,6 @@ public class ShopBlockingHandler extends AbstractPartyManagementHandler {
|
||||
shopSource.setBlockingBlockedReason(blocking.getBlocked().getReason());
|
||||
shopSource.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(blocking.getBlocked().getSince()));
|
||||
}
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop blocking has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -26,28 +26,24 @@ public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetCategoryChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
int categoryId = shopEffect.getEffect().getCategoryChanged().getId();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop categoryId changed handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
shopSource.setCategoryId(categoryId);
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop categoryId has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetCategoryChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
int categoryId = shopEffect.getEffect().getCategoryChanged().getId();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop categoryId changed handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
|
||||
shopSource.setCategoryId(categoryId);
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "categoryId");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopContractChanged;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -27,29 +27,25 @@ public class ShopContractChangedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetContractChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopContractChanged contractChanged = shopEffect.getEffect().getContractChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop contractChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
shopSource.setContractId(contractChanged.getContractId());
|
||||
shopSource.setPayoutToolId(contractChanged.getPayoutToolId());
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop contractChanged has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetContractChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ShopEffectUnit shopEffect = claimEffect.getShopEffect();
|
||||
ShopContractChanged contractChanged = shopEffect.getEffect().getContractChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop contractChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
|
||||
shopSource.setContractId(contractChanged.getContractId());
|
||||
shopSource.setPayoutToolId(contractChanged.getPayoutToolId());
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "contractChanged");
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.domain.Shop;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TBaseUtil;
|
||||
@ -8,8 +9,6 @@ import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -34,59 +33,65 @@ public class ShopCreatedHandler extends AbstractClaimChangedHandler {
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetCreated()).forEach(e -> {
|
||||
long sequenceId = event.getEventId();
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
Shop shopCreated = shopEffect.getEffect().getCreated();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop created handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
com.rbkmoney.newway.domain.tables.pojos.Shop shop = new com.rbkmoney.newway.domain.tables.pojos.Shop();
|
||||
shop.setSequenceId(sequenceId);
|
||||
shop.setChangeId(changeId);
|
||||
shop.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
shop.setShopId(shopId);
|
||||
shop.setPartyId(partyId);
|
||||
shop.setCreatedAt(TypeUtil.stringToLocalDateTime(shopCreated.getCreatedAt()));
|
||||
shop.setBlocking(TBaseUtil.unionFieldToEnum(shopCreated.getBlocking(), com.rbkmoney.newway.domain.enums.Blocking.class));
|
||||
if (shopCreated.getBlocking().isSetUnblocked()) {
|
||||
shop.setBlockingUnblockedReason(shopCreated.getBlocking().getUnblocked().getReason());
|
||||
shop.setBlockingUnblockedSince(TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getUnblocked().getSince()));
|
||||
} else if (shopCreated.getBlocking().isSetBlocked()) {
|
||||
shop.setBlockingBlockedReason(shopCreated.getBlocking().getBlocked().getReason());
|
||||
shop.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getBlocked().getSince()));
|
||||
}
|
||||
shop.setSuspension(TBaseUtil.unionFieldToEnum(shopCreated.getSuspension(), com.rbkmoney.newway.domain.enums.Suspension.class));
|
||||
if (shopCreated.getSuspension().isSetActive()) {
|
||||
shop.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getActive().getSince()));
|
||||
} else if (shopCreated.getSuspension().isSetSuspended()) {
|
||||
shop.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getSuspended().getSince()));
|
||||
}
|
||||
shop.setDetailsName(shopCreated.getDetails().getName());
|
||||
shop.setDetailsDescription(shopCreated.getDetails().getDescription());
|
||||
if (shopCreated.getLocation().isSetUrl()) {
|
||||
shop.setLocationUrl(shopCreated.getLocation().getUrl());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal shop location " + shopCreated.getLocation());
|
||||
}
|
||||
shop.setCategoryId(shopCreated.getCategory().getId());
|
||||
if (shopCreated.isSetAccount()) {
|
||||
ShopUtil.fillShopAccount(shop, shopCreated.getAccount());
|
||||
}
|
||||
shop.setContractId(shopCreated.getContractId());
|
||||
shop.setPayoutToolId(shopCreated.getPayoutToolId());
|
||||
if (shopCreated.isSetPayoutSchedule()) {
|
||||
shop.setPayoutScheduleId(shopCreated.getPayoutSchedule().getId());
|
||||
}
|
||||
shop.setCurrent(true);
|
||||
shopDao.save(shop);
|
||||
log.info("Shop has been saved, sequenceId={}, ppartyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetCreated())
|
||||
.forEach(e -> handleEvent(event, changeId, e));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, ClaimEffect e) {
|
||||
long sequenceId = event.getEventId();
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
Shop shopCreated = shopEffect.getEffect().getCreated();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop created handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
partyDao.get(partyId); //check party is exist
|
||||
com.rbkmoney.newway.domain.tables.pojos.Shop shop = createShop(event, changeId, sequenceId, shopCreated, shopId, partyId);
|
||||
|
||||
shopDao.save(shop).ifPresentOrElse(
|
||||
aLong -> log.info("Shop has been saved, sequenceId={}, ppartyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId),
|
||||
() -> log.info("Shop create duplicated, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId));
|
||||
}
|
||||
|
||||
private com.rbkmoney.newway.domain.tables.pojos.Shop createShop(MachineEvent event, Integer changeId, long sequenceId, Shop shopCreated, String shopId, String partyId) {
|
||||
com.rbkmoney.newway.domain.tables.pojos.Shop shop = new com.rbkmoney.newway.domain.tables.pojos.Shop();
|
||||
shop.setSequenceId(sequenceId);
|
||||
shop.setChangeId(changeId);
|
||||
shop.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
shop.setShopId(shopId);
|
||||
shop.setPartyId(partyId);
|
||||
shop.setCreatedAt(TypeUtil.stringToLocalDateTime(shopCreated.getCreatedAt()));
|
||||
shop.setBlocking(TBaseUtil.unionFieldToEnum(shopCreated.getBlocking(), com.rbkmoney.newway.domain.enums.Blocking.class));
|
||||
if (shopCreated.getBlocking().isSetUnblocked()) {
|
||||
shop.setBlockingUnblockedReason(shopCreated.getBlocking().getUnblocked().getReason());
|
||||
shop.setBlockingUnblockedSince(TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getUnblocked().getSince()));
|
||||
} else if (shopCreated.getBlocking().isSetBlocked()) {
|
||||
shop.setBlockingBlockedReason(shopCreated.getBlocking().getBlocked().getReason());
|
||||
shop.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getBlocked().getSince()));
|
||||
}
|
||||
shop.setSuspension(TBaseUtil.unionFieldToEnum(shopCreated.getSuspension(), com.rbkmoney.newway.domain.enums.Suspension.class));
|
||||
if (shopCreated.getSuspension().isSetActive()) {
|
||||
shop.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getActive().getSince()));
|
||||
} else if (shopCreated.getSuspension().isSetSuspended()) {
|
||||
shop.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getSuspended().getSince()));
|
||||
}
|
||||
shop.setDetailsName(shopCreated.getDetails().getName());
|
||||
shop.setDetailsDescription(shopCreated.getDetails().getDescription());
|
||||
if (shopCreated.getLocation().isSetUrl()) {
|
||||
shop.setLocationUrl(shopCreated.getLocation().getUrl());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal shop location " + shopCreated.getLocation());
|
||||
}
|
||||
shop.setCategoryId(shopCreated.getCategory().getId());
|
||||
if (shopCreated.isSetAccount()) {
|
||||
ShopUtil.fillShopAccount(shop, shopCreated.getAccount());
|
||||
}
|
||||
shop.setContractId(shopCreated.getContractId());
|
||||
shop.setPayoutToolId(shopCreated.getPayoutToolId());
|
||||
if (shopCreated.isSetPayoutSchedule()) {
|
||||
shop.setPayoutScheduleId(shopCreated.getPayoutSchedule().getId());
|
||||
}
|
||||
return shop;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ShopDetails;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -27,29 +27,25 @@ public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetDetailsChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopDetails detailsChanged = shopEffect.getEffect().getDetailsChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop detailsChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
shopSource.setDetailsName(detailsChanged.getName());
|
||||
shopSource.setDetailsDescription(detailsChanged.getDescription());
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop detailsChanged has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetDetailsChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopDetails detailsChanged = shopEffect.getEffect().getDetailsChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop detailsChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
|
||||
shopSource.setDetailsName(detailsChanged.getName());
|
||||
shopSource.setDetailsDescription(detailsChanged.getDescription());
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "detailsChanged");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ShopLocation;
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -27,32 +27,27 @@ public class ShopLocationChangedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetLocationChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ShopLocation locationChanged = shopEffect.getEffect().getLocationChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop locationChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
if (locationChanged.isSetUrl()) {
|
||||
shopSource.setLocationUrl(locationChanged.getUrl());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal shop location " + locationChanged);
|
||||
}
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop locationChanged has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetLocationChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect) {
|
||||
ShopEffectUnit shopEffect = claimEffect.getShopEffect();
|
||||
ShopLocation locationChanged = shopEffect.getEffect().getLocationChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop locationChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
|
||||
if (locationChanged.isSetUrl()) {
|
||||
shopSource.setLocationUrl(locationChanged.getUrl());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal shop location " + locationChanged);
|
||||
}
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "locationChanged");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ScheduleChanged;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -27,32 +27,28 @@ public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandle
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetPayoutScheduleChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ScheduleChanged payoutScheduleChanged = shopEffect.getEffect().getPayoutScheduleChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
if (payoutScheduleChanged.isSetSchedule()) {
|
||||
shopSource.setPayoutScheduleId(payoutScheduleChanged.getSchedule().getId());
|
||||
} else {
|
||||
shopSource.setPayoutScheduleId(null);
|
||||
}
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop payoutScheduleChanged has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutScheduleChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
ScheduleChanged payoutScheduleChanged = shopEffect.getEffect().getPayoutScheduleChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
|
||||
if (payoutScheduleChanged.isSetSchedule()) {
|
||||
shopSource.setPayoutScheduleId(payoutScheduleChanged.getSchedule().getId());
|
||||
} else {
|
||||
shopSource.setPayoutScheduleId(null);
|
||||
}
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "payoutScheduleChanged");
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.shop;
|
||||
|
||||
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.damsel.payment_processing.ShopEffectUnit;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -26,28 +26,23 @@ public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler {
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
getClaimStatus(change).getAccepted().getEffects().stream()
|
||||
.filter(e -> e.isSetShopEffect() && e.getShopEffect().getEffect().isSetPayoutToolChanged()).forEach(e -> {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
String payoutToolChanged = shopEffect.getEffect().getPayoutToolChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
shopSource.setPayoutToolId(payoutToolChanged);
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop payoutToolChanged has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
});
|
||||
.filter(claimEffect -> claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutToolChanged())
|
||||
.forEach(claimEffect -> handleEvent(event, changeId, sequenceId, claimEffect));
|
||||
}
|
||||
|
||||
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
|
||||
ShopEffectUnit shopEffect = e.getShopEffect();
|
||||
String payoutToolChanged = shopEffect.getEffect().getPayoutToolChanged();
|
||||
String shopId = shopEffect.getShopId();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
shopSource.setPayoutToolId(payoutToolChanged);
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "payoutToolChanged");
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.rbkmoney.geck.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.dao.party.iface.ShopDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractPartyManagementHandler;
|
||||
import com.rbkmoney.newway.util.ShopUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -26,8 +26,8 @@ public class ShopSuspensionHandler extends AbstractPartyManagementHandler {
|
||||
|
||||
private final ShopDao shopDao;
|
||||
private final Filter filter = new PathConditionFilter(new PathConditionRule(
|
||||
"shop_suspension",
|
||||
new IsNullCondition().not()));
|
||||
"shop_suspension",
|
||||
new IsNullCondition().not()));
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
@ -38,16 +38,10 @@ public class ShopSuspensionHandler extends AbstractPartyManagementHandler {
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start shop suspension handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
Shop shopSource = shopDao.get(partyId, shopId);
|
||||
if (shopSource == null) {
|
||||
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
|
||||
}
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Long oldEventId = shopSource.getId();
|
||||
ShopUtil.resetBaseFields(event, changeId, sequenceId, shopSource);
|
||||
shopSource.setSuspension(TBaseUtil.unionFieldToEnum(suspension, com.rbkmoney.newway.domain.enums.Suspension.class));
|
||||
if (suspension.isSetActive()) {
|
||||
shopSource.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(suspension.getActive().getSince()));
|
||||
@ -56,10 +50,8 @@ public class ShopSuspensionHandler extends AbstractPartyManagementHandler {
|
||||
shopSource.setSuspensionActiveSince(null);
|
||||
shopSource.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(suspension.getSuspended().getSince()));
|
||||
}
|
||||
shopDao.save(shopSource);
|
||||
shopDao.switchCurrent(partyId, shopId);
|
||||
log.info("Shop suspension has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
|
||||
sequenceId, partyId, shopId, changeId);
|
||||
|
||||
shopDao.saveWithUpdateCurrent(partyId, changeId, shopSource, shopId, sequenceId, oldEventId, "suspension");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.rbkmoney.newway.service;
|
||||
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.PayoutTool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ContractReferenceService {
|
||||
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void updateContractReference(Long contractSourceId, Long contractId) {
|
||||
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);
|
||||
adjustments.forEach(a -> {
|
||||
a.setId(null);
|
||||
a.setCntrctId(contractId);
|
||||
});
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
List<PayoutTool> payoutTools = payoutToolDao.getByCntrctId(contractSourceId);
|
||||
payoutTools.forEach(pt -> {
|
||||
pt.setId(null);
|
||||
pt.setCntrctId(contractId);
|
||||
});
|
||||
payoutToolDao.save(payoutTools);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package com.rbkmoney.newway.util;
|
||||
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.domain.enums.PayoutToolInfo;
|
||||
import com.rbkmoney.newway.domain.enums.RepresentativeDocument;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment;
|
||||
@ -131,4 +132,13 @@ public class ContractUtil {
|
||||
contract.setReportActSignerDocPowerOfAttorneySignedAt(null);
|
||||
contract.setReportActSignerDocPowerOfAttorneyValidUntil(null);
|
||||
}
|
||||
|
||||
public static void resetBaseFields(MachineEvent event, Integer changeId, long sequenceId, com.rbkmoney.newway.domain.tables.pojos.Contract contractSource) {
|
||||
contractSource.setId(null);
|
||||
contractSource.setRevision(null);
|
||||
contractSource.setWtime(null);
|
||||
contractSource.setSequenceId(sequenceId);
|
||||
contractSource.setChangeId(changeId);
|
||||
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.rbkmoney.damsel.domain.RussianLegalEntity;
|
||||
import com.rbkmoney.damsel.domain.RussianPrivateEntity;
|
||||
import com.rbkmoney.geck.common.util.TBaseUtil;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.domain.enums.ContractorType;
|
||||
import com.rbkmoney.newway.domain.enums.LegalEntity;
|
||||
import com.rbkmoney.newway.domain.enums.PrivateEntity;
|
||||
@ -59,4 +60,13 @@ public class ContractorUtil {
|
||||
}
|
||||
return contractor;
|
||||
}
|
||||
|
||||
|
||||
public static void resetBaseFields(MachineEvent event, long sequenceId, Contractor contractorSource) {
|
||||
contractorSource.setId(null);
|
||||
contractorSource.setRevision(null);
|
||||
contractorSource.setWtime(null);
|
||||
contractorSource.setSequenceId(sequenceId);
|
||||
contractorSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
}
|
||||
}
|
||||
|
19
src/main/java/com/rbkmoney/newway/util/PartyUtil.java
Normal file
19
src/main/java/com/rbkmoney/newway/util/PartyUtil.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.rbkmoney.newway.util;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ShopAccount;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
|
||||
public class PartyUtil {
|
||||
|
||||
public static void resetBaseFields(MachineEvent event, Integer changeId, long sequenceId, Party partySource) {
|
||||
partySource.setId(null);
|
||||
partySource.setRevision(null);
|
||||
partySource.setWtime(null);
|
||||
partySource.setSequenceId(sequenceId);
|
||||
partySource.setChangeId(changeId);
|
||||
partySource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package com.rbkmoney.newway.util;
|
||||
|
||||
import com.rbkmoney.damsel.domain.ShopAccount;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.machinegun.eventsink.MachineEvent;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Shop;
|
||||
|
||||
public class ShopUtil {
|
||||
|
||||
@ -10,4 +13,13 @@ public class ShopUtil {
|
||||
shop.setAccountSettlement(shopAccount.getSettlement());
|
||||
shop.setAccountPayout(shopAccount.getPayout());
|
||||
}
|
||||
|
||||
public static void resetBaseFields(MachineEvent event, Integer changeId, long sequenceId, Shop shopSource) {
|
||||
shopSource.setId(null);
|
||||
shopSource.setRevision(null);
|
||||
shopSource.setWtime(null);
|
||||
shopSource.setSequenceId(sequenceId);
|
||||
shopSource.setChangeId(changeId);
|
||||
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,23 @@
|
||||
ALTER TABLE nw.party ADD COLUMN sequence_id BIGINT;
|
||||
ALTER TABLE nw.party ADD COLUMN change_id INT;
|
||||
DROP INDEX party_event_id;
|
||||
ALTER TABLE nw.party DROP COLUMN event_id;
|
||||
ALTER TABLE nw.party ADD CONSTRAINT party_uniq UNIQUE (party_id, sequence_id, change_id);
|
||||
|
||||
ALTER TABLE nw.shop ADD COLUMN sequence_id BIGINT;
|
||||
ALTER TABLE nw.shop ADD COLUMN change_id INT;
|
||||
DROP INDEX shop_event_id;
|
||||
ALTER TABLE nw.shop DROP COLUMN event_id;
|
||||
ALTER TABLE nw.shop ADD CONSTRAINT shop_uniq UNIQUE (party_id, sequence_id, change_id);
|
||||
|
||||
ALTER TABLE nw.contract ADD COLUMN sequence_id BIGINT;
|
||||
ALTER TABLE nw.contract ADD COLUMN change_id INT;
|
||||
DROP INDEX contract_event_id;
|
||||
ALTER TABLE nw.contract DROP COLUMN event_id;
|
||||
ALTER TABLE nw.contract ADD CONSTRAINT contract_uniq UNIQUE (party_id, sequence_id, change_id);
|
||||
|
||||
ALTER TABLE nw.contractor ADD COLUMN sequence_id BIGINT;
|
||||
ALTER TABLE nw.contractor ADD COLUMN change_id INT;
|
||||
DROP INDEX contractor_event_id;
|
||||
ALTER TABLE nw.contractor DROP COLUMN event_id;
|
||||
ALTER TABLE nw.contractor ADD CONSTRAINT contractor_uniq UNIQUE (party_id, sequence_id, change_id);
|
@ -446,7 +446,7 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
jdbcTemplate.execute("truncate table nw.contract cascade");
|
||||
Contract contract = random(Contract.class);
|
||||
contract.setCurrent(true);
|
||||
Long cntrctId = contractDao.save(contract);
|
||||
Long cntrctId = contractDao.save(contract).get();
|
||||
List<ContractAdjustment> contractAdjustments = randomListOf(10, ContractAdjustment.class);
|
||||
contractAdjustments.forEach(ca -> ca.setCntrctId(cntrctId));
|
||||
contractAdjustmentDao.save(contractAdjustments);
|
||||
@ -465,9 +465,6 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
List<Contract> contracts = contractDao.getByPartyId(contract.getPartyId());
|
||||
assertEquals(1, contracts.size());
|
||||
assertEquals(contract, contracts.get(0));
|
||||
contractDao.switchCurrent(contract.getPartyId(), contract.getContractId());
|
||||
assertEquals(1, contracts.size());
|
||||
assertEquals(contract, contracts.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -484,9 +481,10 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
|
||||
Integer changeId = contractor.getChangeId() + 1;
|
||||
contractor.setChangeId(changeId);
|
||||
Long oldId = contractor.getId();
|
||||
contractor.setId(contractor.getId() + 1);
|
||||
contractorDao.save(contractor);
|
||||
contractorDao.switchCurrent(contractor.getPartyId(), contractor.getContractorId());
|
||||
contractorDao.updateNotCurrent(oldId);
|
||||
|
||||
contractors = contractorDao.getByPartyId(contractor.getPartyId());
|
||||
assertEquals(1, contractors.size());
|
||||
@ -502,11 +500,12 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
Party partyGet = partyDao.get(party.getPartyId());
|
||||
assertEquals(party, partyGet);
|
||||
|
||||
Long oldId = party.getId();
|
||||
Integer changeId = party.getChangeId() + 1;
|
||||
party.setChangeId(changeId);
|
||||
party.setId(party.getId() + 1);
|
||||
partyDao.save(party);
|
||||
partyDao.switchCurrent(party.getPartyId());
|
||||
partyDao.updateNotCurrent(oldId);
|
||||
|
||||
partyGet = partyDao.get(party.getPartyId());
|
||||
assertEquals(changeId, partyGet.getChangeId());
|
||||
@ -518,7 +517,7 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
jdbcTemplate.execute("truncate table nw.payout_tool cascade");
|
||||
Contract contract = random(Contract.class);
|
||||
contract.setCurrent(true);
|
||||
Long cntrctId = contractDao.save(contract);
|
||||
Long cntrctId = contractDao.save(contract).get();
|
||||
List<PayoutTool> payoutTools = randomListOf(10, PayoutTool.class);
|
||||
payoutTools.forEach(pt -> pt.setCntrctId(cntrctId));
|
||||
payoutToolDao.save(payoutTools);
|
||||
@ -540,9 +539,10 @@ public class DaoTests extends AbstractAppDaoTests {
|
||||
|
||||
Integer changeId = shop.getChangeId() + 1;
|
||||
shop.setChangeId(changeId);
|
||||
shop.setId(shop.getId() + 1);
|
||||
Long id = shop.getId();
|
||||
shop.setId(id + 1);
|
||||
shopDao.save(shop);
|
||||
shopDao.switchCurrent(shop.getPartyId(), shop.getShopId());
|
||||
shopDao.updateNotCurrent(id);
|
||||
shops = shopDao.getByPartyId(shop.getPartyId());
|
||||
assertEquals(1, shops.size());
|
||||
assertEquals(changeId, shops.get(0).getChangeId());
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
@ -39,7 +40,7 @@ public class PartyManagementServiceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(partyDao.save(any())).thenReturn(1L);
|
||||
when(partyDao.save(any())).thenReturn(Optional.of(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user