Merge branch 'dev'
This commit is contained in:
@@ -7,18 +7,31 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 데이터 복구(가져오기) 요청 — 엑셀 백업을 파싱한 결과.
|
* 데이터 복구(가져오기) 요청 — 엑셀 백업을 파싱한 결과.
|
||||||
* 참조는 이름 기준(계좌명·분류 대분류명·태그명). 서버에서 새 ID 로 재매핑한다.
|
* 계좌는 원본 ID(oldId) 기준으로 매핑(같은 이름 계좌가 있어도 정확). 분류·태그는 이름 기준(유니크).
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class RestoreRequest {
|
public class RestoreRequest {
|
||||||
|
|
||||||
private List<WalletRequest> wallets; // 계좌 (이름 참조 없음 → 요청 DTO 재사용)
|
private List<Wal> wallets;
|
||||||
private List<Cat> categories; // 분류 (parent = 대분류명)
|
private List<Cat> categories;
|
||||||
private List<String> tags; // 태그명
|
private List<String> tags;
|
||||||
private List<Entry> entries; // 내역
|
private List<Entry> entries;
|
||||||
private List<Recur> recurrings; // 고정지출
|
private List<Recur> recurrings;
|
||||||
private List<BudgetRequest> budgets; // 예산 (분류명 참조)
|
private List<BudgetRequest> budgets;
|
||||||
private List<Quick> quickEntries; // 자주 쓰는 내역
|
private List<Quick> quickEntries;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Wal {
|
||||||
|
private Long oldId; // 원본 계좌 id (매핑 키)
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String issuer;
|
||||||
|
private String accountNumber;
|
||||||
|
private String cardType;
|
||||||
|
private Long openingBalance;
|
||||||
|
private LocalDate openingDate;
|
||||||
|
private Long currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Cat {
|
public static class Cat {
|
||||||
@@ -34,10 +47,10 @@ public class RestoreRequest {
|
|||||||
private String category;
|
private String category;
|
||||||
private Long amount;
|
private Long amount;
|
||||||
private String memo;
|
private String memo;
|
||||||
private String wallet; // 계좌명
|
private Long walletId; // 원본 계좌 id
|
||||||
private String toWallet; // 입금 계좌명(이체)
|
private Long toWalletId; // 원본 입금 계좌 id(이체)
|
||||||
private Integer installmentMonths;
|
private Integer installmentMonths;
|
||||||
private List<String> tags; // 태그명
|
private List<String> tags; // 태그명
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -47,8 +60,8 @@ public class RestoreRequest {
|
|||||||
private Long amount;
|
private Long amount;
|
||||||
private String category;
|
private String category;
|
||||||
private String memo;
|
private String memo;
|
||||||
private String wallet;
|
private Long walletId;
|
||||||
private String toWallet;
|
private Long toWalletId;
|
||||||
private String frequency;
|
private String frequency;
|
||||||
private Integer dayOfMonth;
|
private Integer dayOfMonth;
|
||||||
private Integer dayOfWeek;
|
private Integer dayOfWeek;
|
||||||
@@ -65,6 +78,6 @@ public class RestoreRequest {
|
|||||||
private String category;
|
private String category;
|
||||||
private Long amount;
|
private Long amount;
|
||||||
private String memo;
|
private String memo;
|
||||||
private String wallet;
|
private Long walletId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,12 +57,22 @@ public class BackupService {
|
|||||||
backupMapper.deleteTags(memberId);
|
backupMapper.deleteTags(memberId);
|
||||||
backupMapper.deleteWallets(memberId);
|
backupMapper.deleteWallets(memberId);
|
||||||
|
|
||||||
// 2) 계좌 → 이름→새 ID
|
// 2) 계좌 → 원본 id(oldId) → 새 id (같은 이름 계좌가 있어도 정확)
|
||||||
Map<String, Long> walletMap = new HashMap<>();
|
Map<Long, Long> walletMap = new HashMap<>();
|
||||||
if (req.getWallets() != null) {
|
if (req.getWallets() != null) {
|
||||||
for (WalletRequest w : req.getWallets()) {
|
for (RestoreRequest.Wal w : req.getWallets()) {
|
||||||
if (w == null || w.getName() == null) continue;
|
if (w == null || w.getName() == null) continue;
|
||||||
walletMap.put(w.getName(), accountService.createWallet(w, memberId).getId());
|
WalletRequest wr = new WalletRequest();
|
||||||
|
wr.setType(w.getType());
|
||||||
|
wr.setName(w.getName());
|
||||||
|
wr.setIssuer(w.getIssuer());
|
||||||
|
wr.setAccountNumber(w.getAccountNumber());
|
||||||
|
wr.setCardType(w.getCardType());
|
||||||
|
wr.setOpeningBalance(w.getOpeningBalance());
|
||||||
|
wr.setOpeningDate(w.getOpeningDate());
|
||||||
|
wr.setCurrentValue(w.getCurrentValue());
|
||||||
|
Long newId = accountService.createWallet(wr, memberId).getId();
|
||||||
|
if (w.getOldId() != null) walletMap.put(w.getOldId(), newId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +111,17 @@ public class BackupService {
|
|||||||
if (req.getEntries() != null) {
|
if (req.getEntries() != null) {
|
||||||
for (RestoreRequest.Entry e : req.getEntries()) {
|
for (RestoreRequest.Entry e : req.getEntries()) {
|
||||||
if (e.getEntryDate() == null || e.getType() == null) continue;
|
if (e.getEntryDate() == null || e.getType() == null) continue;
|
||||||
|
Long wid = walletMap.get(e.getWalletId());
|
||||||
|
Long twid = walletMap.get(e.getToWalletId());
|
||||||
|
if (badTransfer(e.getType(), wid, twid)) continue; // 이체 계좌가 없거나 같으면 건너뜀
|
||||||
AccountEntryRequest er = new AccountEntryRequest();
|
AccountEntryRequest er = new AccountEntryRequest();
|
||||||
er.setEntryDate(e.getEntryDate());
|
er.setEntryDate(e.getEntryDate());
|
||||||
er.setType(e.getType());
|
er.setType(e.getType());
|
||||||
er.setCategory(e.getCategory());
|
er.setCategory(e.getCategory());
|
||||||
er.setAmount(e.getAmount());
|
er.setAmount(e.getAmount());
|
||||||
er.setMemo(e.getMemo());
|
er.setMemo(e.getMemo());
|
||||||
er.setWalletId(walletMap.get(e.getWallet()));
|
er.setWalletId(wid);
|
||||||
er.setToWalletId(walletMap.get(e.getToWallet()));
|
er.setToWalletId(twid);
|
||||||
er.setInstallmentMonths(e.getInstallmentMonths());
|
er.setInstallmentMonths(e.getInstallmentMonths());
|
||||||
if (e.getTags() != null) {
|
if (e.getTags() != null) {
|
||||||
er.setTagIds(e.getTags().stream().map(tagMap::get).filter(Objects::nonNull).toList());
|
er.setTagIds(e.getTags().stream().map(tagMap::get).filter(Objects::nonNull).toList());
|
||||||
@@ -121,14 +134,17 @@ public class BackupService {
|
|||||||
if (req.getRecurrings() != null) {
|
if (req.getRecurrings() != null) {
|
||||||
for (RestoreRequest.Recur r : req.getRecurrings()) {
|
for (RestoreRequest.Recur r : req.getRecurrings()) {
|
||||||
if (r.getTitle() == null) continue;
|
if (r.getTitle() == null) continue;
|
||||||
|
Long wid = walletMap.get(r.getWalletId());
|
||||||
|
Long twid = walletMap.get(r.getToWalletId());
|
||||||
|
if (badTransfer(r.getType(), wid, twid)) continue;
|
||||||
RecurringRequest rr = new RecurringRequest();
|
RecurringRequest rr = new RecurringRequest();
|
||||||
rr.setTitle(r.getTitle());
|
rr.setTitle(r.getTitle());
|
||||||
rr.setType(r.getType());
|
rr.setType(r.getType());
|
||||||
rr.setAmount(r.getAmount());
|
rr.setAmount(r.getAmount());
|
||||||
rr.setCategory(r.getCategory());
|
rr.setCategory(r.getCategory());
|
||||||
rr.setMemo(r.getMemo());
|
rr.setMemo(r.getMemo());
|
||||||
rr.setWalletId(walletMap.get(r.getWallet()));
|
rr.setWalletId(wid);
|
||||||
rr.setToWalletId(walletMap.get(r.getToWallet()));
|
rr.setToWalletId(twid);
|
||||||
rr.setFrequency(r.getFrequency());
|
rr.setFrequency(r.getFrequency());
|
||||||
rr.setDayOfMonth(r.getDayOfMonth());
|
rr.setDayOfMonth(r.getDayOfMonth());
|
||||||
rr.setDayOfWeek(r.getDayOfWeek());
|
rr.setDayOfWeek(r.getDayOfWeek());
|
||||||
@@ -158,7 +174,7 @@ public class BackupService {
|
|||||||
qr.setCategory(q.getCategory());
|
qr.setCategory(q.getCategory());
|
||||||
qr.setAmount(q.getAmount());
|
qr.setAmount(q.getAmount());
|
||||||
qr.setMemo(q.getMemo());
|
qr.setMemo(q.getMemo());
|
||||||
qr.setWalletId(walletMap.get(q.getWallet()));
|
qr.setWalletId(walletMap.get(q.getWalletId()));
|
||||||
quickEntryService.create(qr, memberId);
|
quickEntryService.create(qr, memberId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,6 +187,11 @@ public class BackupService {
|
|||||||
return type + "|" + name;
|
return type + "|" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 이체인데 출금/입금 계좌가 없거나 같으면 복구에서 제외(검증 오류로 전체 롤백 방지) */
|
||||||
|
private static boolean badTransfer(String type, Long walletId, Long toWalletId) {
|
||||||
|
return "TRANSFER".equals(type) && (walletId == null || toWalletId == null || walletId.equals(toWalletId));
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isEmpty(RestoreRequest r) {
|
private boolean isEmpty(RestoreRequest r) {
|
||||||
return empty(r.getWallets()) && empty(r.getCategories()) && empty(r.getTags())
|
return empty(r.getWallets()) && empty(r.getCategories()) && empty(r.getTags())
|
||||||
&& empty(r.getEntries()) && empty(r.getRecurrings()) && empty(r.getBudgets())
|
&& empty(r.getEntries()) && empty(r.getRecurrings()) && empty(r.getBudgets())
|
||||||
|
|||||||
Reference in New Issue
Block a user