mirror of
https://github.com/valitydev/daway.git
synced 2024-11-06 08:35:23 +00:00
Merge pull request #117 from rbkmoney/ft/sql-optim
Optimize shop contract and contractor batch update
This commit is contained in:
commit
e7ba8785a0
@ -84,11 +84,15 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
|
||||
|
||||
@Override
|
||||
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
|
||||
ids.forEach(id ->
|
||||
this.getNamedParameterJdbcTemplate()
|
||||
.update("update nw.contract set current = false where contract_id =:contract_id and party_id=:party_id and current;" +
|
||||
"update nw.contract set current = true where id = (select max(id) from nw.contract where contract_id =:contract_id and party_id=:party_id);",
|
||||
new MapSqlParameterSource(Map.of("contract_id", id, "party_id", partyId))));
|
||||
.update("update nw.contract set current = false where contract_id in(:contract_ids) and party_id=:party_id and current;" +
|
||||
"update nw.contract set current = true where id in(" +
|
||||
" SELECT max(id)" +
|
||||
" FROM nw.contract" +
|
||||
" where contract_id in (:contract_ids)" +
|
||||
" and party_id=:party_id" +
|
||||
" group by contract_id, party_id);",
|
||||
new MapSqlParameterSource(Map.of("contract_ids", ids, "party_id", partyId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,11 +83,15 @@ public class ContractorDaoImpl extends AbstractGenericDao implements ContractorD
|
||||
|
||||
@Override
|
||||
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
|
||||
ids.forEach(id ->
|
||||
this.getNamedParameterJdbcTemplate()
|
||||
.update("update nw.contractor set current = false where contractor_id =:contractor_id and party_id=:party_id and current;" +
|
||||
"update nw.contractor set current = true where id = (select max(id) from nw.contractor where contractor_id =:contractor_id and party_id=:party_id);",
|
||||
new MapSqlParameterSource(Map.of("contractor_id", id, "party_id", partyId))));
|
||||
.update("update nw.contractor set current = false where contractor_id in(:contractor_ids) and party_id=:party_id and current;" +
|
||||
"update nw.contractor set current = true where id in(" +
|
||||
" SELECT max(id)" +
|
||||
" FROM nw.contractor" +
|
||||
" where contractor_id in (:contractor_ids)" +
|
||||
" and party_id=:party_id" +
|
||||
" group by contractor_id, party_id);",
|
||||
new MapSqlParameterSource(Map.of("contractor_ids", ids, "party_id", partyId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,11 +85,15 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
|
||||
|
||||
@Override
|
||||
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
|
||||
ids.forEach(id ->
|
||||
this.getNamedParameterJdbcTemplate()
|
||||
.update("update nw.shop set current = false where shop_id =:shop_id and party_id=:party_id and current;" +
|
||||
"update nw.shop set current = true where id = (select max(id) from nw.shop where shop_id =:shop_id and party_id=:party_id);",
|
||||
new MapSqlParameterSource(Map.of("shop_id", id, "party_id", partyId))));
|
||||
.update("update nw.shop set current = false where shop_id in(:shop_ids) and party_id=:party_id and current;" +
|
||||
"update nw.shop set current = true where id in(" +
|
||||
" SELECT max(id)" +
|
||||
" FROM nw.shop" +
|
||||
" where shop_id in (:shop_ids)" +
|
||||
" and party_id=:party_id" +
|
||||
" group by shop_id, party_id);",
|
||||
new MapSqlParameterSource(Map.of("shop_ids", ids, "party_id", partyId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user