[BO] 임산물현황, 은행자동이체 내역 - 숫자값 0 입력에 대한 유효성 검사 추가

This commit is contained in:
kangsunlee
2025-07-28 11:38:13 +09:00
parent c7e3210093
commit 0e9e41bbfe
5 changed files with 141 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
package app.module.admin.usecase.household.tab.bankAutoTransfer.saveBankAutoTransferExpense.adapters.web.validator;
import app.module.admin.usecase.household.tab.bankAutoTransfer.saveBankAutoTransferExpense.adapters.web.model.SaveBankAutoTransferExpenseReqVO;
import app.module.core.config.constants.CommonConstants;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
@@ -33,6 +34,13 @@ public class SaveBankAutoTransferExpenseValidator implements Validator {
return;
}
// 수량 0 이상 입력
if (StringUtils.hasText(vo.getCount()) && Integer.parseInt(vo.getCount()) == 0) {
errors.rejectValue(
"count", CommonConstants.VALID_CODE_INVALID_ZERO,
"수량은 0 이상 입력해 주세요.");
}
// 수량 입력 O, 단위 선택 X
if (StringUtils.hasText(vo.getCount()) && !StringUtils.hasText(vo.getUnitCode())) {
errors.rejectValue("unitCode", "error.unitCode",
@@ -59,5 +67,11 @@ public class SaveBankAutoTransferExpenseValidator implements Validator {
errors.rejectValue("price", "error.price",
"현금(원)을 입력해주세요.");
}
if (vo.getPrice() != null && vo.getPrice() == 0) {
errors.rejectValue(
"price", CommonConstants.VALID_CODE_INVALID_ZERO,
"현금(원)은 0 이상 입력해 주세요.");
}
}
}

View File

@@ -1,6 +1,7 @@
package app.module.admin.usecase.household.tab.bankAutoTransfer.saveBankAutoTransferIncome.adapters.web.validator;
import app.module.admin.usecase.household.tab.bankAutoTransfer.saveBankAutoTransferIncome.adapters.web.model.SaveBankAutoTransferIncomeReqVO;
import app.module.core.config.constants.CommonConstants;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
@@ -42,6 +43,13 @@ public class SaveBankAutoTransferIncomeValidator implements Validator {
"수입의 종류를 입력해주세요.");
}
// 수량 0 이상 입력
if (StringUtils.hasText(vo.getCount()) && Integer.parseInt(vo.getCount()) == 0) {
errors.rejectValue(
"count", CommonConstants.VALID_CODE_INVALID_ZERO,
"수량은 0 이상 입력해 주세요.");
}
// 수량 입력 O, 단위 선택 X
if (StringUtils.hasText(vo.getCount()) && !StringUtils.hasText(vo.getUnitCode())) {
errors.rejectValue("unitCode", "error.unitCode",
@@ -68,5 +76,11 @@ public class SaveBankAutoTransferIncomeValidator implements Validator {
errors.rejectValue("price", "error.price",
"현금(원)을 입력해주세요.");
}
if (vo.getPrice() != null && vo.getPrice() == 0) {
errors.rejectValue(
"price", CommonConstants.VALID_CODE_INVALID_ZERO,
"현금(원)은 0 이상 입력해 주세요.");
}
}
}

View File

@@ -18,18 +18,18 @@ public class SaveForestProductReqVO {
private String landType;
private String town;
private String cropName;
private String landArea;
private String availableArea;
private String mainYield;
private String mainYieldUnitCode;
private String mainYieldUnit;
private String mainSaleAmount;
private String mainSaleUnitCode;
private String mainSaleUnit;
private String subYield;
private String subYieldUnitCode;
private String subYieldUnit;
private String subSaleAmount;
private String subSaleUnitCode;
private String subSaleUnit;
private String landArea; // 면적(평)
private String availableArea; // 가능면적(평)
private String mainYield; // 주생산물 수확량
private String mainYieldUnitCode; // 주생산물 수확량 단위 (select)
private String mainYieldUnit; // 주생산물 수확량 직접입력 단위
private String mainSaleAmount; // 주생산물 판매량
private String mainSaleUnitCode; // 주생산물 판매량 단위 (select)
private String mainSaleUnit; // 주생산물 판매량 직접입력 단위
private String subYield; // 부생산물 수확량
private String subYieldUnitCode; // 부생산물 수확량 단위 (select)
private String subYieldUnit; // 부생산물 수확량 직접입력 단위
private String subSaleAmount; // 부생산물 판매량
private String subSaleUnitCode; // 부생산물 판매량 단위 (select)
private String subSaleUnit; // 부생산물 판매량 직접입력 단위
}

View File

@@ -1,6 +1,7 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.validator;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.model.SaveForestProductReqVO;
import app.module.core.config.constants.CommonConstants;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
@@ -21,5 +22,93 @@ public class SaveForestProductValidator implements Validator {
if (!StringUtils.hasText(vo.getCropName())) {
errors.rejectValue("cropName", "error.cropName", "재배 작물명을 입력해주세요.");
}
if (StringUtils.hasText(vo.getLandArea()) && Integer.parseInt(vo.getLandArea()) == 0) {
errors.rejectValue(
"landArea", CommonConstants.VALID_CODE_INVALID_ZERO,
"면적(평)은 0 이상 입력해 주세요.");
}
if (StringUtils.hasText(vo.getAvailableArea()) && Integer.parseInt(vo.getAvailableArea()) == 0) {
errors.rejectValue(
"availableArea", CommonConstants.VALID_CODE_INVALID_ZERO,
"가능면적(평)은 0 이상 입력해 주세요.");
}
// 주생산물 수확량
if (StringUtils.hasText(vo.getMainYield()) && Integer.parseInt(vo.getMainYield()) == 0) {
errors.rejectValue(
"mainYield", CommonConstants.VALID_CODE_INVALID_ZERO,
"주생산물 수확량은 0 이상 입력해 주세요.");
}
if (StringUtils.hasText(vo.getMainYield()) && !StringUtils.hasText(vo.getMainYieldUnitCode())) {
errors.rejectValue(
"mainYieldUnitCode", CommonConstants.VALID_CODE_NOTBLANK,
"주생산물 수확량의 단위를 선택해 주세요.");
}
if (CommonConstants.UNIT_CODE_SELF.equals(vo.getMainYieldUnitCode()) && !StringUtils.hasText(vo.getMainYieldUnit())) {
errors.rejectValue(
"mainYieldUnit", CommonConstants.VALID_CODE_NOTBLANK,
"주생산물 수확량 단위를 입력해 주세요.");
}
// 주생산물 판매량
if (StringUtils.hasText(vo.getMainSaleAmount()) && Integer.parseInt(vo.getMainSaleAmount()) == 0) {
errors.rejectValue(
"mainSaleAmount", CommonConstants.VALID_CODE_INVALID_ZERO,
"주생산물 판매량은 0 이상 입력해 주세요.");
}
if (StringUtils.hasText(vo.getMainSaleAmount()) && !StringUtils.hasText(vo.getMainSaleUnitCode())) {
errors.rejectValue(
"mainSaleUnitCode", CommonConstants.VALID_CODE_NOTBLANK,
"주생산물 판매량의 단위를 선택해 주세요.");
}
if (CommonConstants.UNIT_CODE_SELF.equals(vo.getMainSaleUnitCode()) && !StringUtils.hasText(vo.getMainSaleUnit())) {
errors.rejectValue(
"mainSaleUnit", CommonConstants.VALID_CODE_NOTBLANK,
"주생산물 판매량 단위를 입력해 주세요.");
}
// 부생산물 수확량
if (StringUtils.hasText(vo.getSubYield()) && Integer.parseInt(vo.getSubYield()) == 0) {
errors.rejectValue(
"subYield", CommonConstants.VALID_CODE_INVALID_ZERO,
"부생산물 수확량은 0 이상 입력해 주세요.");
}
if (StringUtils.hasText(vo.getSubYield()) && !StringUtils.hasText(vo.getSubYieldUnitCode())) {
errors.rejectValue(
"subYieldUnitCode", CommonConstants.VALID_CODE_NOTBLANK,
"부생산물 수확량의 단위를 선택해 주세요.");
}
if (CommonConstants.UNIT_CODE_SELF.equals(vo.getSubYieldUnitCode()) && !StringUtils.hasText(vo.getSubYieldUnit())) {
errors.rejectValue(
"subYieldUnit", CommonConstants.VALID_CODE_NOTBLANK,
"부생산물 수확량 단위를 입력해 주세요.");
}
// 부생산물 판매량
if (StringUtils.hasText(vo.getSubSaleAmount()) && Integer.parseInt(vo.getSubSaleAmount()) == 0) {
errors.rejectValue(
"subSaleAmount", CommonConstants.VALID_CODE_INVALID_ZERO,
"부생산물 판매량은 0 이상 입력해 주세요.");
}
if (StringUtils.hasText(vo.getSubSaleAmount()) && !StringUtils.hasText(vo.getSubSaleUnitCode())) {
errors.rejectValue(
"subSaleUnitCode", CommonConstants.VALID_CODE_NOTBLANK,
"부생산물 판매량의 단위를 선택해 주세요.");
}
if (CommonConstants.UNIT_CODE_SELF.equals(vo.getSubSaleUnitCode()) && !StringUtils.hasText(vo.getSubSaleUnit())) {
errors.rejectValue(
"subSaleUnit", CommonConstants.VALID_CODE_NOTBLANK,
"부생산물 판매량 단위를 입력해 주세요.");
}
}
}
}

View File

@@ -179,8 +179,9 @@
form.sourcePurpose.value = data.sourcePurpose ?? '';
form.transferCategoryCode.value = data.transferCategoryCode ?? '';
toggleSelfInput(form.expenseCode.value, form.transferCategory);
toggleSelfInput(form.unitCode.value, form.unit);
// 초기 상태 업데이트
toggleExpenseSelfInput(form.transferCategoryCode);
selectedSelf(form.unitCode);
}
</script>
@@ -255,11 +256,15 @@
f.expenseCode.value = codeValue;
const tr = el.closest('tr');
toggleExpenseSelfInput(el);
}
const toggleExpenseSelfInput = (selectElement) => {
const tr = selectElement.closest('tr');
const selfArea = tr.querySelector('.self-input');
const selfInput = tr.querySelector('.self-input input');
if (el.value?.endsWith('.self')) {
if (selectElement.value?.endsWith('.self')) {
selfInput.disabled = false;
selfArea.classList.remove('input-disabled');
} else {