[BO] 임산물현황 등록 작업

This commit is contained in:
kangsunlee
2025-06-26 14:24:12 +09:00
parent 063c9018e4
commit f1aad02b70
21 changed files with 401 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import app.module.admin.usecase.household.tab.forestProduct.getForestProductsSta
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatus;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatusCmd;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatusResult;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetMonthlyForestProductsStatus;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
@@ -17,7 +18,7 @@ class GetForestProductsStatusDao implements GetForestProductsStatusPortOut {
public GetForestProductsStatusResult operate(GetForestProductsStatusCmd cmd) {
// 임산물 등록 상태 조회
String monthlyStatus = mapper.getMonthlyStatus(cmd);
GetMonthlyForestProductsStatus monthlyStatus = mapper.getMonthlyStatus(cmd);
// 임산물 목록 조회
List<GetForestProductsStatus> forestProducts = mapper.getForestProductsStatus(cmd);

View File

@@ -2,11 +2,12 @@ package app.module.admin.usecase.household.tab.forestProduct.getForestProductsSt
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatus;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatusCmd;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetMonthlyForestProductsStatus;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface GetForestProductsStatusMapper {
String getMonthlyStatus(GetForestProductsStatusCmd cmd);
GetMonthlyForestProductsStatus getMonthlyStatus(GetForestProductsStatusCmd cmd);
List<GetForestProductsStatus> getForestProductsStatus(GetForestProductsStatusCmd cmd);
}

View File

@@ -11,6 +11,6 @@ import lombok.Setter;
@AllArgsConstructor
@EqualsAndHashCode
public class GetForestProductsStatusResult {
private String monthlyStatus;
private GetMonthlyForestProductsStatus monthlyStatus;
private List<GetForestProductsStatus> forestProducts;
}

View File

@@ -0,0 +1,15 @@
package app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@EqualsAndHashCode
public class GetMonthlyForestProductsStatus {
private Long id;
private String forestStatus;
}

View File

@@ -0,0 +1,24 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.persistence;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.SaveForestProductPortOut;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
import app.module.core.config.application.util.AuditUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@RequiredArgsConstructor
class SaveForestProductDao implements SaveForestProductPortOut {
private final SaveForestProductMapper mapper;
@Override
@Transactional
public void operate(SaveForestProductCmd inCmd) {
if (inCmd.getForestProductId() == null) {
mapper.createForestProduct(AuditUtil.create(inCmd));
} else {
mapper.updateForestProduct(AuditUtil.update(inCmd));
}
}
}

View File

@@ -0,0 +1,10 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.persistence;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SaveForestProductMapper {
void createForestProduct(SaveForestProductCmd cmd);
void updateForestProduct(SaveForestProductCmd cmd);
}

View File

@@ -0,0 +1,61 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.SaveForestProductPortIn;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
import app.module.core.config.application.util.MessageUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.BindingResult;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.model.SaveForestProductReqVO;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.model.SaveForestProductResVO;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.validator.SaveForestProductValidator;
@RestController
@RequiredArgsConstructor
class SaveForestProductController {
private final SaveForestProductValidator validator;
private final SaveForestProductPortIn portIn;
private final MessageUtil messageUtil;
@PostMapping(path = "/api/forestProduct/save")
ResponseEntity<?> operate(@Valid @RequestBody SaveForestProductReqVO reqVO,
BindingResult bindingResult) {
validator.validate(reqVO, bindingResult);
if (bindingResult.hasErrors()) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
.body(bindingResult.getFieldErrors());
}
portIn.operate(new SaveForestProductCmd(
reqVO.getForestProductId(),
reqVO.getHouseholdSeq(),
reqVO.getMonthlyInputStatusId(),
reqVO.getRecordMonth(),
reqVO.getStreetNum(),
reqVO.getLandType(),
reqVO.getTown(),
reqVO.getCropName(),
reqVO.getLandArea(),
reqVO.getAvailableArea(),
reqVO.getMainYield(),
reqVO.getMainYieldUnitCode(),
reqVO.getMainYieldUnit(),
reqVO.getMainSaleAmount(),
reqVO.getMainSaleUnitCode(),
reqVO.getMainSaleUnit(),
reqVO.getSubYield(),
reqVO.getSubYieldUnitCode(),
reqVO.getSubYieldUnit(),
reqVO.getSubSaleAmount(),
reqVO.getSubSaleUnitCode(),
reqVO.getSubSaleUnit()));
return ResponseEntity.status(HttpStatus.OK).body(
new SaveForestProductResVO(messageUtil.getMessage("operation.common.save.done")));
}
}

View File

@@ -0,0 +1,37 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.model;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode
public class SaveForestProductReqVO {
private Long forestProductId;
private Long householdSeq;
private Long monthlyInputStatusId;
private String recordMonth;
private String streetNum;
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;
}

View File

@@ -0,0 +1,14 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.web.model;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@EqualsAndHashCode
public class SaveForestProductResVO {
private String message;
}

View File

@@ -0,0 +1,25 @@
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 org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
@Component
public class SaveForestProductValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
return SaveForestProductReqVO.class.equals(clazz);
}
@Override
public void validate(Object target, Errors errors) {
SaveForestProductReqVO vo = (SaveForestProductReqVO) target;
if (!StringUtils.hasText(vo.getCropName())) {
errors.rejectValue("cropName", "error.cropName", "재배 작물명을 입력해주세요.");
}
}
}

View File

@@ -0,0 +1,7 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
public interface SaveForestProductPortIn {
void operate(SaveForestProductCmd inCmd);
}

View File

@@ -0,0 +1,7 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
public interface SaveForestProductPortOut {
void operate(SaveForestProductCmd inCmd);
}

View File

@@ -0,0 +1,18 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.SaveForestProductPortIn;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.SaveForestProductPortOut;
import app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain.SaveForestProductCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
class SaveForestProductService implements SaveForestProductPortIn {
private final SaveForestProductPortOut portOut;
@Override
public void operate(SaveForestProductCmd cmd) {
portOut.operate(cmd);
}
}

View File

@@ -0,0 +1,35 @@
package app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.ports.application.domain;
import app.module.core.config.adapters.persistence.component.AuditCommand;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
public class SaveForestProductCmd extends AuditCommand {
private Long forestProductId;
private Long householdSeq;
private Long monthlyInputStatusId;
private String recordMonth;
private String streetNum;
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;
}

View File

@@ -30,7 +30,7 @@ class SaveHouseholdVisitInfoController {
if (bindingResult.hasErrors()) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
.body(bindingResult.getAllErrors().get(0).getDefaultMessage());
.body(bindingResult.getFieldErrors());
}
portIn.operate(new SaveHouseholdVisitInfoCmd(

View File

@@ -4,9 +4,10 @@
<mapper
namespace="app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.adapters.persistence.GetForestProductsStatusMapper">
<select id="getMonthlyStatus" resultType="java.lang.String">
<select id="getMonthlyStatus" resultType="app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetMonthlyForestProductsStatus">
/* getMonthlyStatus : 임산물 현황 등록 상태 조회 */
SELECT forest_product_status
SELECT id,
forest_product_status
FROM monthly_input_status mis
WHERE household_seq = #{householdSeq}
AND month = #{recordMonth}

View File

@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace="app.module.admin.usecase.household.tab.forestProduct.saveForestProduct.adapters.persistence.SaveForestProductMapper">
<insert id="createForestProduct">
/* createForestProduct : 임산물 현황 등록 */
INSERT INTO forest_product
(
household_seq,
month,
street_num,
land_type,
town,
crop_name,
land_area,
available_area,
main_yield,
main_yield_unit_code,
main_yield_unit,
main_sale_amount,
main_sale_unit_code,
main_sale_unit,
sub_yield,
sub_yield_unit_code,
sub_yield_unit,
sub_sale_amount,
sub_sale_unit_code,
sub_sale_unit,
monthly_input_status_id,
<include refid="common.fields.CreateUpdateBaseColumns"/>
)
VALUES
(
#{householdSeq},
#{recordMonth},
#{streetNum},
#{landType},
#{town},
#{cropName},
#{landArea},
#{availableArea},
#{mainYield},
#{mainYieldUnitCode},
#{mainYieldUnit},
#{mainSaleAmount},
#{mainSaleUnitCode},
#{mainSaleUnit},
#{subYield},
#{subYieldUnitCode},
#{subYieldUnit},
#{subSaleAmount},
#{subSaleUnitCode},
#{subSaleUnit},
#{monthlyInputStatusId},
<include refid="common.fields.CreateUpdateBaseValues"/>
)
</insert>
<update id="updateForestProduct">
/* updateForestProduct : 임산물 현황 수정 */
UPDATE forest_product
SET
household_seq = #{householdSeq},
street_num = #{streetNum},
land_type = #{landType},
town = #{town},
available_area = #{availableArea},
crop_name = #{cropName},
land_area = #{landArea},
month = #{recordMonth},
main_yield = #{mainYield},
main_yield_unit_code = #{mainYieldUnitCode},
main_yield_unit = #{mainYieldUnit},
main_sale_amount = #{mainSaleAmount},
main_sale_unit_code = #{mainSaleUnitCode},
main_sale_unit = #{mainSaleUnit},
sub_yield = #{subYield},
sub_yield_unit_code = #{subYieldUnitCode},
sub_yield_unit = #{subYieldUnit},
sub_sale_amount = #{subSaleAmount},
sub_sale_unit_code = #{subSaleUnitCode},
sub_sale_unit = #{subSaleUnit},
monthly_input_status_id = #{monthlyInputStatusId},
<include refid="common.fields.UpdateBaseSet"/>
WHERE id = #{forestProductId}
</update>
</mapper>

View File

@@ -8,6 +8,7 @@
<input type="hidden" name="forestProductId">
<input type="hidden" name="householdSeq" th:value="${seq}">
<input type="hidden" name="recordMonth">
<input type="hidden" name="monthlyInputStatusId">
<div class="component-modal mypage-wrap modal01 modal-forest-product" data-props-dimm-click="true" data-state="close">
<div class="modal-dimm"></div>
@@ -229,7 +230,7 @@
<div class="component-btns bottom-btn-group">
<div class="btns-row align-right">
<button type="button" class="btn btn-primary">
<button type="button" class="btn btn-primary" onclick="goForestProductSave();">
<span class="btn-txt">등록</span>
</button>
</div>
@@ -249,6 +250,7 @@
const showForestProductModal = (id) => {
const f = document.reqForestProductForm;
f.recordMonth.value = document.reqForm.recordMonth.value;
f.monthlyInputStatusId.value = document.reqForm.monthlyInputStatusId.value;
resetForestProductForm();
@@ -261,6 +263,8 @@
(response) => {
console.log("임산물현황 상세 응답값 : ", response);
setForestProductFormData(response);
document.querySelector(".modal-forest-product").ui.open();
},
function (code, rstData) {
console.log("error : ", code);
@@ -268,9 +272,9 @@
'get',
'json'
);
} else {
document.querySelector(".modal-forest-product").ui.open();
}
document.querySelector(".modal-forest-product").ui.open();
}
// 임산물현황등록 상세 값 set
@@ -332,21 +336,47 @@
const form = document.reqForestProductForm;
if (!form) return;
// 모든 input 초기화
form.querySelectorAll('input').forEach((input) => {
input.value = '';
const skipInputs = ['forestProductId', 'householdSeq', 'recordMonth', 'monthlyInputStatusId'];
// 단위 직접입력는 다시 비활성화하고 클래스 추가
if (input.closest('.unit-self-input')) {
input.disabled = true;
input.closest('.unit-self-input').classList.add('input-disabled');
form.querySelectorAll('input').forEach((el) => {
if (!skipInputs.includes(el.name)) {
el.value = '';
if (el.closest('.unit-self-input')) {
el.disabled = true;
el.closest('.unit-self-input').classList.add('input-disabled');
}
}
});
// 모든 select 초기화
form.querySelectorAll('select').forEach((select) => {
select.selectedIndex = 0;
});
form.querySelectorAll('select').forEach((el) => el.selectedIndex = 0);
}
</script>
<script>
// 임산물 현황 저장 및 수정
const goForestProductSave = () => {
const f = document.reqForestProductForm;
if (!f) return;
let dataOj = $(f).serializeObject();
console.log("dataOj", dataOj);
ajaxUtil._ajaxMethod(
'/api/forestProduct/save',
JSON.stringify(dataOj),
(response) => { // 성공
alert("등록이 완료되었습니다.");
document.querySelector(".modal-forest-product").ui.close();
getForestProductsStatus();
},
function (code, rstData) {
if(code == 422) alert(rstData.responseJSON[0].defaultMessage);
},
'post',
'json',
{ handle422Type: 'alert' }
);
}
</script>
</div>

View File

@@ -194,7 +194,7 @@
getVisitInfo();
},
function (code, rstData) {
if(code == 422) alert(rstData.responseText);
if(code == 422) alert(rstData.responseJSON[0].defaultMessage);
if(code == 400) alert(rstData.responseJSON.message); //임가번호 중복체크
},
'post',

View File

@@ -3,6 +3,8 @@
layout:decorate="~{layout/layout}">
<div class="layer-wrap" th:fragment="tabFragment">
<input type="hidden" name="monthlyInputStatusId">
<div class="tab-content forest-product" data-tab-value="tab2">
<div class="content-inner">
<section class="table-group">
@@ -68,12 +70,15 @@
},
(response) => { // 성공
console.log("임산물 현황 리스트 조회 : ", response);
// 임산물 현황 등록 상태 id set
f.monthlyInputStatusId.value = response.monthlyStatus.id;
const tbody = $('.tab-content.forest-product tbody');
tbody.empty();
if(response.forestProducts.length === 0) {
noDataMonthly(tbody, response.status, 15);
noDataMonthly(tbody, response.monthlyStatus.status, 15);
return;
}

View File

@@ -168,9 +168,6 @@
<button type="button" class="btn">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn">
<span class="btn-txt">인쇄 <i class="ico-print" aria-hidden="true"></i></span>
</button>
</div>
</div>
</div>