[FO] 일계부 자가농업 CRUD, 공통 수정
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.persistence;
|
||||
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.ports.DailyFarmingPortOut;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.CreateDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.GetDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.RemoveDailyFarmingCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class DailyFarmingDao implements DailyFarmingPortOut {
|
||||
private final DailyFarmingMapper mapper;
|
||||
|
||||
@Override
|
||||
public List<DailyFarmingDto> list(GetDailyFarmingCmd command) {
|
||||
return mapper.getDailyFarmingList(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(GetDailyFarmingCmd findCmd, CreateDailyFarmingCmd command) {
|
||||
Integer existCount = mapper.getRecordExistCount(findCmd);
|
||||
if (existCount == 0) {
|
||||
mapper.createDailyFarming(command);
|
||||
|
||||
log.debug("[CreateDailyFarming] record={}", command);
|
||||
} else {
|
||||
mapper.updateDailyFarming(command);
|
||||
|
||||
log.debug("[UpdateDailyFarming] record={}", command);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(GetDailyFarmingCmd findCmd, RemoveDailyFarmingCmd command) {
|
||||
Integer existCount = mapper.getRecordExistCount(findCmd);
|
||||
if (existCount != 0) {
|
||||
mapper.removeDailyFarming(command);
|
||||
|
||||
log.debug("[RemoveDailyFarming] record={}", command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.persistence;
|
||||
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.CreateDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.GetDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.RemoveDailyFarmingCmd;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DailyFarmingMapper {
|
||||
/**
|
||||
* 일계부 자가농업 목록 조회
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 수입 목록
|
||||
*/
|
||||
List<DailyFarmingDto> getDailyFarmingList(GetDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 데이터 존재 여부
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 중복 개수
|
||||
*/
|
||||
Integer getRecordExistCount(GetDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 등록
|
||||
*
|
||||
* @param command 등록 데이터
|
||||
*/
|
||||
void createDailyFarming(CreateDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 수정
|
||||
*
|
||||
* @param command 수정 데이터
|
||||
*/
|
||||
void updateDailyFarming(CreateDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 삭제
|
||||
*
|
||||
* @param command 삭제 데이터
|
||||
*/
|
||||
void removeDailyFarming(RemoveDailyFarmingCmd command);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.persistence.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class DailyFarmingDto {
|
||||
private Long id;
|
||||
private Long dailyRecordSeq;
|
||||
private String productCode;
|
||||
private String productLabel;
|
||||
private String productSelf;
|
||||
private String usage;
|
||||
private String quantity;
|
||||
private String unitCode;
|
||||
private String unitLabel;
|
||||
private String unitSelf;
|
||||
private Integer estimatedValue;
|
||||
|
||||
/**
|
||||
* 수정 가능 여부
|
||||
* @return true=가능, false=불가능(등록 상태)
|
||||
*/
|
||||
public boolean isUpdated() {
|
||||
return this.id != null && this.id != 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web;
|
||||
|
||||
import app.module.core.config.application.exception.NoRecordDataException;
|
||||
import app.module.core.config.application.util.CoreUtil;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.CreateDailyFarmingReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.RemoveDailyFarmingReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.validator.CreateDailyFarmingValidator;
|
||||
import app.module.front.usecase.daily.farming.ports.application.DailyFarmingService;
|
||||
import app.module.front.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import app.module.front.usecase.daily.record.ports.DailyRecordPortIn;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/api/record/farming")
|
||||
public class DailyFarmingController {
|
||||
private final CoreUtil coreUtil;
|
||||
private final DailyRecordPortIn dailyRecordService;
|
||||
private final DailyFarmingService dailyFarmingPortIn;
|
||||
private final CreateDailyFarmingValidator createValidator;
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 등록 처리
|
||||
*
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
* @param id 수입 일련번호
|
||||
* @param formVO 입력 데이터
|
||||
* @param bindingResult BindingResult
|
||||
*/
|
||||
@PostMapping(path = "/{searchMonth}/{groupNo}/form/{id}")
|
||||
ResponseEntity<?> create(@PathVariable("searchMonth") String searchMonth, @PathVariable("groupNo") String groupNo
|
||||
, @PathVariable("id") String id
|
||||
, @Valid @RequestBody CreateDailyFarmingReqVO formVO, BindingResult bindingResult) {
|
||||
|
||||
createValidator.validate(formVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
|
||||
DailyRecordDto dailyRecord = this.vaildGetDailyRecord(searchMonth, groupNo);
|
||||
|
||||
formVO.setSearchMonth(searchMonth);
|
||||
formVO.setGroupNo(Integer.parseInt(groupNo));
|
||||
formVO.setId(Long.parseLong(id));
|
||||
formVO.setDailyRecordSeq(dailyRecord.getId());
|
||||
log.debug("formVO: {}", formVO);
|
||||
|
||||
dailyFarmingPortIn.create(formVO);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(formVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 삭제 처리
|
||||
*
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
* @param formVO 입력 데이터
|
||||
* @param bindingResult BindingResult
|
||||
*/
|
||||
@PostMapping(path = "/{searchMonth}/{groupNo}/remove")
|
||||
ResponseEntity<?> remove(@PathVariable("searchMonth") String searchMonth, @PathVariable("groupNo") String groupNo
|
||||
, @Valid @RequestBody RemoveDailyFarmingReqVO formVO, BindingResult bindingResult) {
|
||||
|
||||
log.debug("before formVO: {}", formVO);
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
DailyRecordDto dailyRecord = this.vaildGetDailyRecord(searchMonth, groupNo);
|
||||
|
||||
formVO.setSearchMonth(dailyRecord.getRecordMonth());
|
||||
formVO.setGroupNo(dailyRecord.getGroupNo());
|
||||
formVO.setDailyRecordSeq(dailyRecord.getId());
|
||||
log.debug("formVO: {}", formVO);
|
||||
|
||||
dailyFarmingPortIn.remove(formVO);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(formVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 전체 삭제 처리
|
||||
*
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
*/
|
||||
@PostMapping(path = "/{searchMonth}/{groupNo}/reset")
|
||||
ResponseEntity<?> removeAll(@PathVariable("searchMonth") String searchMonth, @PathVariable("groupNo") String groupNo) {
|
||||
|
||||
DailyRecordDto dailyRecord = this.vaildGetDailyRecord(searchMonth, groupNo);
|
||||
|
||||
RemoveDailyFarmingReqVO formVO = new RemoveDailyFarmingReqVO();
|
||||
formVO.setSearchMonth(dailyRecord.getRecordMonth());
|
||||
formVO.setGroupNo(dailyRecord.getGroupNo());
|
||||
formVO.setDailyRecordSeq(dailyRecord.getId());
|
||||
log.debug("formVO: {}", formVO);
|
||||
|
||||
dailyFarmingPortIn.remove(formVO);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(formVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 유효성 체크 및 데이터 조회
|
||||
*
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
*/
|
||||
private DailyRecordDto vaildGetDailyRecord(String searchMonth, String groupNo) {
|
||||
DailyUIReqVO reqVO = new DailyUIReqVO(searchMonth, groupNo);
|
||||
log.debug("getRecordUIReq: {}", reqVO);
|
||||
|
||||
DailyRecordDto dailyRecord = dailyRecordService.detail(reqVO);
|
||||
if (dailyRecord == null || dailyRecord.getId() == null) {
|
||||
throw new NoRecordDataException();
|
||||
}
|
||||
|
||||
return dailyRecord;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web;
|
||||
|
||||
import app.module.core.config.application.exception.NoRecordDataException;
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.DailyFarmingUIReqVO;
|
||||
import app.module.front.usecase.daily.farming.ports.application.DailyFarmingService;
|
||||
import app.module.front.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailySort;
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import app.module.front.usecase.daily.record.ports.DailyRecordPortIn;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/record/farming")
|
||||
public class DailyFarmingUIController {
|
||||
private final UICodeListPortIn uiCodeListPortIn;
|
||||
private final DailyRecordPortIn dailyRecordPortIn;
|
||||
private final DailyFarmingService dailyFarmingPortIn;
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 목록 화면
|
||||
*
|
||||
* @param model Model
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
* @param searchType 수정여부
|
||||
*/
|
||||
@GetMapping(path = "/{searchMonth}/{groupNo}")
|
||||
public String index(Model model, @PathVariable("searchMonth") String searchMonth, @PathVariable("groupNo") String groupNo
|
||||
, @RequestParam(name = "type", required = false) String searchType) {
|
||||
|
||||
DailyRecordDto dailyRecord = this.vaildGetDailyRecord(searchMonth, groupNo);
|
||||
|
||||
DailyFarmingUIReqVO reqVO = new DailyFarmingUIReqVO(searchMonth, groupNo);
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
List<DailyFarmingDto> farmingList = dailyFarmingPortIn.list(reqVO);
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("dailyRecord", dailyRecord);
|
||||
model.addAttribute("farmingList", farmingList);
|
||||
model.addAttribute("moveStep", !"update".equals(searchType));
|
||||
model.addAttribute("nextStep", dailyRecord.getNextStep(DailySort.FARMING));
|
||||
|
||||
return "record/farming/index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 등록 화면
|
||||
*
|
||||
* @param model Model
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
* @param id 수입 일련번호
|
||||
*/
|
||||
@GetMapping(path = "/{searchMonth}/{groupNo}/form/{id}")
|
||||
public String formBySelf(Model model, @PathVariable("searchMonth") String searchMonth, @PathVariable("groupNo") String groupNo
|
||||
, @PathVariable("id") String id) {
|
||||
|
||||
DailyFarmingUIReqVO reqVO = new DailyFarmingUIReqVO(searchMonth, groupNo);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
reqVO.setId(0L);
|
||||
} else {
|
||||
reqVO.setId(Long.parseLong(id));
|
||||
}
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
DailyFarmingDto detail = new DailyFarmingDto();
|
||||
if (reqVO.getId() != 0L) {
|
||||
detail = dailyFarmingPortIn.detail(reqVO);
|
||||
if (detail == null || !detail.isUpdated()) {
|
||||
throw new NoRecordDataException();
|
||||
}
|
||||
}
|
||||
|
||||
model.addAttribute("recordFarming", uiCodeListPortIn.connect("code.record.farming"));
|
||||
model.addAttribute("recordUnit", uiCodeListPortIn.connect("code.record.unit"));
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("detail", detail);
|
||||
|
||||
return "record/farming/form";
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 유효성 체크 및 데이터 조회
|
||||
*
|
||||
* @param searchMonth 검색 월(yyyyMM)
|
||||
* @param groupNo 검색 그룹
|
||||
*/
|
||||
private DailyRecordDto vaildGetDailyRecord(String searchMonth, String groupNo) {
|
||||
DailyUIReqVO reqVO = new DailyUIReqVO(searchMonth, groupNo);
|
||||
log.debug("getRecordUIReq: {}", reqVO);
|
||||
|
||||
DailyRecordDto dailyRecord = dailyRecordPortIn.detail(reqVO);
|
||||
if (dailyRecord == null || dailyRecord.getId() == null) {
|
||||
throw new NoRecordDataException();
|
||||
}
|
||||
|
||||
return dailyRecord;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web.model;
|
||||
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class CreateDailyFarmingReqVO extends DailyUIReqVO {
|
||||
/**
|
||||
* 자가농업 일련번호
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 일계부 일련번호
|
||||
*/
|
||||
private Long dailyRecordSeq;
|
||||
/**
|
||||
* 생산물
|
||||
*/
|
||||
@NotBlank(message = "생산물을 입력해 주세요.")
|
||||
private String productCode;
|
||||
/**
|
||||
* 생산물 직접 입력
|
||||
*/
|
||||
private String productSelf;
|
||||
/**
|
||||
* 용도
|
||||
*/
|
||||
private String usage;
|
||||
/**
|
||||
* 수량
|
||||
*/
|
||||
private Double quantity;
|
||||
/**
|
||||
* 단위 코드
|
||||
*/
|
||||
private String unitCode;
|
||||
/**
|
||||
* 단위 직접 입력
|
||||
*/
|
||||
private String unitSelf;
|
||||
/**
|
||||
* 현물평가액
|
||||
*/
|
||||
private Integer estimatedValue;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web.model;
|
||||
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.apache.tika.utils.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class DailyFarmingUIReqVO extends DailyUIReqVO {
|
||||
public DailyFarmingUIReqVO(String month, String no) {
|
||||
setSearchMonth(month);
|
||||
if (!StringUtils.isBlank(no)) {
|
||||
setGroupNo(Integer.parseInt(no));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 자가농업 일련번호
|
||||
*/
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web.model;
|
||||
|
||||
import app.module.front.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class RemoveDailyFarmingReqVO extends DailyUIReqVO {
|
||||
/**
|
||||
* 자가농업 일련번호
|
||||
*/
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String id;
|
||||
/**
|
||||
* 일계부 일련번호
|
||||
*/
|
||||
private Long dailyRecordSeq;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package app.module.front.usecase.daily.farming.adapters.web.validator;
|
||||
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.CreateDailyFarmingReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.tika.utils.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CreateDailyFarmingValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return CreateDailyFarmingReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
CreateDailyFarmingReqVO vo = (CreateDailyFarmingReqVO) target;
|
||||
|
||||
if ("SELF".equals(vo.getProductCode()) && StringUtils.isBlank(vo.getProductSelf())) {
|
||||
errors.rejectValue(
|
||||
"categorySelf", "valid.common.required",
|
||||
"생산물을 입력해 주세요.");
|
||||
}
|
||||
|
||||
if (vo.getEstimatedValue() == null) {
|
||||
errors.rejectValue(
|
||||
"estimatedValue", "valid.common.required",
|
||||
"현물평가액을 입력해 주세요.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package app.module.front.usecase.daily.farming.ports;
|
||||
|
||||
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.CreateDailyFarmingReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.DailyFarmingUIReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.RemoveDailyFarmingReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DailyFarmingPortIn {
|
||||
/**
|
||||
* 일계부 자가농업 조회
|
||||
*
|
||||
* @param reqVO 검색 조건
|
||||
* @return 자가농업 목록
|
||||
*/
|
||||
List<DailyFarmingDto> list(DailyFarmingUIReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 조회
|
||||
*
|
||||
* @param reqVO 검색 조건
|
||||
* @return 자가농업 상세
|
||||
*/
|
||||
DailyFarmingDto detail(DailyFarmingUIReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 등록
|
||||
*
|
||||
* @param formVO 입력 데이터
|
||||
*/
|
||||
void create(CreateDailyFarmingReqVO formVO);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 삭제
|
||||
*
|
||||
* @param formVO 삭제 검색 조건
|
||||
*/
|
||||
void remove(RemoveDailyFarmingReqVO formVO);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package app.module.front.usecase.daily.farming.ports;
|
||||
|
||||
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.CreateDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.GetDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.RemoveDailyFarmingCmd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DailyFarmingPortOut {
|
||||
/**
|
||||
* 일계부 자가농업 조회
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 자가농업 목록
|
||||
*/
|
||||
List<DailyFarmingDto> list(GetDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 등록
|
||||
*
|
||||
* @param findCmd 검색 조건
|
||||
* @param command 입력 데이터
|
||||
*/
|
||||
void create(GetDailyFarmingCmd findCmd, CreateDailyFarmingCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 자가농업 삭제
|
||||
*
|
||||
* @param findCmd 검색 조건
|
||||
* @param command 삭제 검색 조건
|
||||
*/
|
||||
void remove(GetDailyFarmingCmd findCmd, RemoveDailyFarmingCmd command);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package app.module.front.usecase.daily.farming.ports.application;
|
||||
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import app.module.core.usecase.uicode.list.ports.application.domain.UICodeElement;
|
||||
import app.module.front.config.application.util.AuditUtil;
|
||||
import app.module.front.config.constants.CommonConstants;
|
||||
import app.module.front.usecase.daily.farming.adapters.persistence.model.DailyFarmingDto;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.CreateDailyFarmingReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.DailyFarmingUIReqVO;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.RemoveDailyFarmingReqVO;
|
||||
import app.module.front.usecase.daily.farming.ports.DailyFarmingPortIn;
|
||||
import app.module.front.usecase.daily.farming.ports.DailyFarmingPortOut;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.CreateDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.GetDailyFarmingCmd;
|
||||
import app.module.front.usecase.daily.farming.ports.application.domain.RemoveDailyFarmingCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DailyFarmingService implements DailyFarmingPortIn {
|
||||
private final DailyFarmingPortOut portOut;
|
||||
private final UICodeListPortIn uiCodeListPortIn;
|
||||
|
||||
@Override
|
||||
public List<DailyFarmingDto> list(DailyFarmingUIReqVO reqVO) {
|
||||
return this.getRefineList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DailyFarmingDto detail(DailyFarmingUIReqVO reqVO) {
|
||||
List<DailyFarmingDto> list = this.getRefineList(reqVO);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 목록 데이터 조회
|
||||
*
|
||||
* @param reqVO 검색 조건
|
||||
* @return 공통 처리된 목록
|
||||
*/
|
||||
private List<DailyFarmingDto> getRefineList(DailyFarmingUIReqVO reqVO) {
|
||||
List<DailyFarmingDto> list = portOut.list(new GetDailyFarmingCmd(reqVO.getSearchMonth(),
|
||||
reqVO.getGroupNo(),
|
||||
reqVO.getHouseholdSeq(),
|
||||
reqVO.getId()));
|
||||
|
||||
List<UICodeElement> recordFarming = uiCodeListPortIn.connect("code.record.farming");
|
||||
List<UICodeElement> recordUnit = uiCodeListPortIn.connect("code.record.unit");
|
||||
|
||||
for (DailyFarmingDto dto : list) {
|
||||
if ("code.record.farming.self".equals(dto.getProductCode())) {
|
||||
dto.setProductLabel(dto.getProductSelf());
|
||||
} else {
|
||||
dto.setProductLabel(this.getCodeLabel(dto.getProductCode(), recordFarming));
|
||||
}
|
||||
|
||||
if (CommonConstants.UNIT_CODE_SELF.equals(dto.getUnitCode())) {
|
||||
dto.setUnitLabel(dto.getUnitSelf());
|
||||
} else {
|
||||
dto.setUnitLabel(this.getCodeLabel(dto.getUnitCode(), recordUnit));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드명 조회
|
||||
*
|
||||
* @param codeId 코드
|
||||
* @param codeList 공통 코드 목록
|
||||
* @return 코드명
|
||||
*/
|
||||
private String getCodeLabel(String codeId, List<UICodeElement> codeList) {
|
||||
String returnValue = null;
|
||||
for (UICodeElement codeSetup : codeList) {
|
||||
if (codeSetup.getId().equalsIgnoreCase(codeId)) {
|
||||
returnValue = codeSetup.getCodeText();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(CreateDailyFarmingReqVO formVO) {
|
||||
GetDailyFarmingCmd findCmd = new GetDailyFarmingCmd(
|
||||
formVO.getSearchMonth(),
|
||||
formVO.getGroupNo(),
|
||||
formVO.getHouseholdSeq(),
|
||||
formVO.getId());
|
||||
|
||||
String incomeMark = null;
|
||||
String expenseMark = null;
|
||||
if (!"code.record.farming.self".equals(formVO.getProductCode())) {
|
||||
List<UICodeElement> recordFarming = uiCodeListPortIn.connect("code.record.farming");
|
||||
String returnValue = null;
|
||||
for (UICodeElement codeSetup : recordFarming) {
|
||||
if (codeSetup.getId().equalsIgnoreCase(formVO.getProductCode())) {
|
||||
returnValue = codeSetup.getCodeValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (returnValue != null) {
|
||||
incomeMark = returnValue.split(",")[0];
|
||||
expenseMark = returnValue.split(",")[1];
|
||||
}
|
||||
}
|
||||
|
||||
CreateDailyFarmingCmd command = AuditUtil.create(
|
||||
new CreateDailyFarmingCmd(
|
||||
formVO.getId(),
|
||||
formVO.getDailyRecordSeq(),
|
||||
incomeMark,
|
||||
expenseMark,
|
||||
formVO.getProductCode(),
|
||||
formVO.getProductSelf(),
|
||||
formVO.getUsage(),
|
||||
formVO.getQuantity(),
|
||||
formVO.getUnitCode(),
|
||||
formVO.getUnitSelf(),
|
||||
formVO.getEstimatedValue()));
|
||||
|
||||
portOut.create(findCmd, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemoveDailyFarmingReqVO formVO) {
|
||||
Long id = formVO.getId() != null ? Long.parseLong(formVO.getId()) : null;
|
||||
|
||||
GetDailyFarmingCmd findCmd = new GetDailyFarmingCmd(
|
||||
formVO.getSearchMonth(),
|
||||
formVO.getGroupNo(),
|
||||
formVO.getHouseholdSeq(),
|
||||
id);
|
||||
|
||||
RemoveDailyFarmingCmd command = AuditUtil.delete(
|
||||
new RemoveDailyFarmingCmd(
|
||||
formVO.getSearchMonth(),
|
||||
formVO.getGroupNo(),
|
||||
id,
|
||||
formVO.getDailyRecordSeq()));
|
||||
|
||||
portOut.remove(findCmd, command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package app.module.front.usecase.daily.farming.ports.application.domain;
|
||||
|
||||
import app.module.front.config.adapters.persistence.component.FrontAuditCommand;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class CreateDailyFarmingCmd extends FrontAuditCommand {
|
||||
private Long id;
|
||||
private Long dailyRecordSeq;
|
||||
private String incomeMark;
|
||||
private String expenseMark;
|
||||
private String productCode;
|
||||
private String productSelf;
|
||||
private String usage;
|
||||
private Double quantity;
|
||||
private String unitCode;
|
||||
private String unitSelf;
|
||||
private Integer estimatedValue;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package app.module.front.usecase.daily.farming.ports.application.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class GetDailyFarmingCmd {
|
||||
/**
|
||||
* 검색 월(yyyyMM)
|
||||
*/
|
||||
private String searchMonth;
|
||||
/**
|
||||
* 검색 그룸번호
|
||||
*/
|
||||
private Integer groupNo;
|
||||
/**
|
||||
* 임가 일련번호
|
||||
*/
|
||||
private Long householdSeq;
|
||||
/**
|
||||
* 자가농업 일련번호
|
||||
*/
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package app.module.front.usecase.daily.farming.ports.application.domain;
|
||||
|
||||
import app.module.front.config.adapters.persistence.component.FrontAuditCommand;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class RemoveDailyFarmingCmd extends FrontAuditCommand {
|
||||
private String searchMonth;
|
||||
private Integer groupNo;
|
||||
private Long id;
|
||||
private Long dailyRecordSeq;
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package app.module.front.usecase.daily.record.adapters.web;
|
||||
import app.module.core.config.application.exception.NoMatchingURIException;
|
||||
import app.module.front.usecase.daily.expense.adapters.web.model.DailyExpenseUIReqVO;
|
||||
import app.module.front.usecase.daily.expense.ports.DailyExpensePortIn;
|
||||
import app.module.front.usecase.daily.farming.adapters.web.model.DailyFarmingUIReqVO;
|
||||
import app.module.front.usecase.daily.farming.ports.DailyFarmingPortIn;
|
||||
import app.module.front.usecase.daily.forestry.adapters.web.model.DailyForestryUIReqVO;
|
||||
import app.module.front.usecase.daily.forestry.ports.DailyForestryPortIn;
|
||||
import app.module.front.usecase.daily.income.adapters.persistence.model.DailyIncomeDto;
|
||||
@@ -38,6 +40,7 @@ public class DailyRecordUIController {
|
||||
private final DailyWorkPortIn dailyWorkPortIn;
|
||||
private final DailyPowerPortIn dailyPowerPortIn;
|
||||
private final DailyForestryPortIn dailyForestryPortIn;
|
||||
private final DailyFarmingPortIn dailyFarmingPortIn;
|
||||
|
||||
/**
|
||||
* 일계부 항목 등록 화면
|
||||
@@ -92,7 +95,7 @@ public class DailyRecordUIController {
|
||||
model.addAttribute("workList", dailyWorkPortIn.list(new DailyWorkUIReqVO(searchMonth, groupNo)));
|
||||
model.addAttribute("powerList", dailyPowerPortIn.list(new DailyPowerUIReqVO(searchMonth, groupNo)));
|
||||
model.addAttribute("forestryList", dailyForestryPortIn.list(new DailyForestryUIReqVO(searchMonth, groupNo)));
|
||||
model.addAttribute("farmingList", null); // TODO
|
||||
model.addAttribute("farmingList", dailyFarmingPortIn.list(new DailyFarmingUIReqVO(searchMonth, groupNo)));
|
||||
}
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
|
||||
Reference in New Issue
Block a user