[CORE] daily.record core package 로 이동.
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
package app.module.core.usecase.daily.record.adapters.persistence;
|
||||
|
||||
import app.module.core.config.application.enums.DailyStatus;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import app.module.core.config.application.util.AuditUtil;
|
||||
import app.module.core.config.application.util.DailyUtil;
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.core.usecase.daily.record.ports.DailyRecordPortOut;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.CreateDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.GetDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.UpdateDailyRecordStatusCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class DailyRecordDao implements DailyRecordPortOut {
|
||||
private final DailyRecordMapper dailyRecordMapper;
|
||||
private final DailyUtil dailyUtil;
|
||||
|
||||
@Override
|
||||
public DailyRecordDto detail(GetDailyRecordCmd command) {
|
||||
DailyRecordDto detail = dailyRecordMapper.getDailyRecord(command);
|
||||
if (detail != null) {
|
||||
if (detail.getStartDate() == null) {
|
||||
detail.setStartDate(dailyUtil.getDayToLocalDate(command.getSearchMonth(), detail.getStartDay()));
|
||||
detail.setEndDate(dailyUtil.getDayToLocalDate(command.getSearchMonth(), detail.getEndDay()));
|
||||
if (detail.getStartDate().getMonth() != detail.getEndDate().getMonth()) {
|
||||
// 종료일의 달이 변경되면 시작일=종료일 처리
|
||||
detail.setEndDate(detail.getStartDate());
|
||||
}
|
||||
}
|
||||
|
||||
detail.setLastDay(dailyUtil.isLastDay(detail.getEndDate()));
|
||||
detail.setFarmingOpen(dailyUtil.isFarmingOpen(detail.getGroupNo(), detail.getEndDate()));
|
||||
detail.setRegistrable(dailyUtil.isRegisterPossible(detail.getStartDate(), detail.getEndDate()));
|
||||
detail.setModifiable(dailyUtil.isModifiable(detail.getStartDate(), detail.getEndDate()));
|
||||
}
|
||||
|
||||
log.debug("detail: {}", detail);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(GetDailyRecordCmd findCmd, CreateDailyRecordCmd command) {
|
||||
Integer existCount = dailyRecordMapper.getDailyRecordExistCount(findCmd);
|
||||
if (existCount == 0) {
|
||||
dailyRecordMapper.createDailyRecord(command);
|
||||
|
||||
log.debug("[CreateDailyRecord] record={}", command);
|
||||
} else {
|
||||
dailyRecordMapper.updateDailyRecord(command);
|
||||
|
||||
log.warn("[DailyRecordCreate] existCount={}, recordMonth={}, dayGroupNo={}", existCount, findCmd.getSearchMonth(), findCmd.getGroupNo());
|
||||
}
|
||||
|
||||
this.updateByAllStatus(findCmd.getSearchMonth(), findCmd.getGroupNo(), findCmd.getHouseholdSeq());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateByStatus(String recordMonth, Integer dayGroupNo, Long householdSeq, String targetType, String targetStatus) {
|
||||
UpdateDailyRecordStatusCmd command = AuditUtil.update(
|
||||
new UpdateDailyRecordStatusCmd(
|
||||
recordMonth,
|
||||
dayGroupNo,
|
||||
householdSeq,
|
||||
"ALL".equals(targetType) ? targetStatus : null,
|
||||
!"ALL".equals(targetType) ? targetType : null,
|
||||
!"ALL".equals(targetType) ? targetStatus : null
|
||||
)
|
||||
);
|
||||
|
||||
if ("ALL".equals(targetType)) {
|
||||
String allStatus = this.getUpdateAllStatus(recordMonth, dayGroupNo, householdSeq);
|
||||
if (allStatus != null) {
|
||||
command.setAllStatus(allStatus);
|
||||
|
||||
dailyRecordMapper.updateDailyRecordStatus(command);
|
||||
|
||||
} else {
|
||||
log.debug("[updateByAllStatus] do nothing. findCmd: {}", command);
|
||||
}
|
||||
|
||||
} else {
|
||||
dailyRecordMapper.updateDailyRecordStatus(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 일계부 전체 입력상태 변경
|
||||
*
|
||||
* @param searchMonth
|
||||
* @param dayGroupNo
|
||||
* @param householdSeq
|
||||
*/
|
||||
private void updateByAllStatus(String searchMonth, Integer dayGroupNo, Long householdSeq) {
|
||||
String allStatus = this.getUpdateAllStatus(searchMonth, dayGroupNo, householdSeq);
|
||||
if (allStatus != null) {
|
||||
UpdateDailyRecordStatusCmd command = AuditUtil.update(
|
||||
new UpdateDailyRecordStatusCmd(
|
||||
searchMonth,
|
||||
dayGroupNo,
|
||||
householdSeq,
|
||||
allStatus,
|
||||
null,
|
||||
null
|
||||
)
|
||||
);
|
||||
|
||||
dailyRecordMapper.updateDailyRecordStatus(command);
|
||||
|
||||
} else {
|
||||
log.debug("[updateByAllStatus] do nothing. findCmd: {}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 변경할 전체 입력상태 조회
|
||||
*
|
||||
* @param searchMonth
|
||||
* @param dayGroupNo
|
||||
* @param householdSeq
|
||||
* @return 변경할 전체 입력상태
|
||||
*/
|
||||
private String getUpdateAllStatus(String searchMonth, Integer dayGroupNo, Long householdSeq) {
|
||||
GetDailyRecordCmd findCmd = new GetDailyRecordCmd(searchMonth, dayGroupNo, householdSeq);
|
||||
|
||||
DailyRecordStatusDto statusDetail = null;
|
||||
List<DailyRecordStatusDto> statusList = dailyRecordMapper.getDailyRecordStatus(findCmd);
|
||||
if (statusList != null && !statusList.isEmpty()) {
|
||||
statusDetail = statusList.get(0);
|
||||
}
|
||||
|
||||
String allStatus = null;
|
||||
|
||||
if (statusDetail != null) {
|
||||
if (DailyStatus.TODAY_NONE.equals(statusDetail.getAllStatus())) {
|
||||
// 전체상태=금일없음, 항목=입력대상이 있는지 여부
|
||||
if (this.checkTarget(statusDetail.getIncomeStatus()) || this.checkTarget(statusDetail.getExpenseStatus())
|
||||
|| this.checkTarget(statusDetail.getWorkStatus()) || this.checkTarget(statusDetail.getPowerStatus())
|
||||
|| this.checkTarget(statusDetail.getForestryStatus()) || this.checkTarget(statusDetail.getFarmingStatus())) {
|
||||
allStatus = DailyStatus.WAITING.name();
|
||||
}
|
||||
} else if (DailyStatus.WAITING.equals(statusDetail.getAllStatus())) {
|
||||
// 전체상태=입력중, 항목 COUNT!=0 이 있는지 여부
|
||||
|
||||
int noneCheck = 0;
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getIncomeStatus(), statusDetail.getIncomeCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getExpenseStatus(), statusDetail.getExpenseCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getWorkStatus(), statusDetail.getWorkCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getPowerStatus(), statusDetail.getPowerCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getForestryStatus(), statusDetail.getForestryCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getFarmingStatus(), statusDetail.getFarmingCount()) ? 1 : 0);
|
||||
|
||||
if (noneCheck == 0) {
|
||||
allStatus = DailyStatus.DONE.name();
|
||||
}
|
||||
} else if (DailyStatus.DONE.equals(statusDetail.getAllStatus())) {
|
||||
// 전체상태=완료, 항목 COUNT=0 체크
|
||||
int noneCheck = 0;
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getIncomeStatus(), statusDetail.getIncomeCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getExpenseStatus(), statusDetail.getExpenseCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getWorkStatus(), statusDetail.getWorkCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getPowerStatus(), statusDetail.getPowerCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getForestryStatus(), statusDetail.getForestryCount()) ? 1 : 0);
|
||||
noneCheck = noneCheck + (this.checkTargetDataNone(statusDetail.getFarmingStatus(), statusDetail.getFarmingCount()) ? 1 : 0);
|
||||
|
||||
if (noneCheck != 0) {
|
||||
allStatus = DailyStatus.WAITING.name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 입력 대상 상태 조회
|
||||
*
|
||||
* @param status 조회 상태
|
||||
* @return true=입력 대상, false=금일 데이터 없음 또는 대상 아님
|
||||
*/
|
||||
private boolean checkTarget(DailyTargetStatus status) {
|
||||
// NONE 은 대상이 아니기 때문에 체크에서 제외
|
||||
return DailyTargetStatus.TARGET.equals(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 등록 대상인데 데이터가 없는 경우 조회
|
||||
*
|
||||
* @param status 조회 상태
|
||||
* @param count 조회 건수
|
||||
* @return true=입력대상인데 데이터가 없는 경우, false=입력대상 아니거나, 데이터가 있는 경우
|
||||
*/
|
||||
private boolean checkTargetDataNone(DailyTargetStatus status, Integer count) {
|
||||
return DailyTargetStatus.TARGET.equals(status) && count == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package app.module.core.usecase.daily.record.adapters.persistence;
|
||||
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.CreateDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.GetDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.UpdateDailyRecordStatusCmd;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DailyRecordMapper {
|
||||
/**
|
||||
* 일계부 항목 조회
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 항목 상세
|
||||
*/
|
||||
DailyRecordDto getDailyRecord(GetDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 특정일의 일계부 등록 상태 조회
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 일계부 등록 현황 목록
|
||||
*/
|
||||
List<DailyRecordStatusDto> getDailyRecordStatus(GetDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 항목 등록 여부
|
||||
*
|
||||
* @param command 검색 조건
|
||||
* @return 등록 여부
|
||||
*/
|
||||
Integer getDailyRecordExistCount(GetDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 항목 등록(생성)
|
||||
*
|
||||
* @param command 등록 데이터
|
||||
*/
|
||||
void createDailyRecord(CreateDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 항목 수정
|
||||
*
|
||||
* @param command 수정 데이터
|
||||
*/
|
||||
void updateDailyRecord(CreateDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 항목의 상태 수정
|
||||
*
|
||||
* @param command 수정 데이터
|
||||
*/
|
||||
void updateDailyRecordStatus(UpdateDailyRecordStatusCmd command);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package app.module.core.usecase.daily.record.adapters.persistence.model;
|
||||
|
||||
import app.module.core.config.application.enums.DailySort;
|
||||
import app.module.core.config.application.enums.DailyStatus;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
public class DailyRecordDto {
|
||||
private String recordMonth;
|
||||
private Integer groupNo;
|
||||
private Integer startDay;
|
||||
private Integer endDay;
|
||||
|
||||
private Long id;
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
private DailyStatus allStatus;
|
||||
private DailyTargetStatus incomeStatus;
|
||||
private DailyTargetStatus workStatus;
|
||||
private DailyTargetStatus expenseStatus;
|
||||
private DailyTargetStatus powerStatus;
|
||||
private DailyTargetStatus forestryStatus;
|
||||
private DailyTargetStatus farmingStatus;
|
||||
|
||||
/**
|
||||
* 마지막 일 여부
|
||||
*/
|
||||
private boolean lastDay;
|
||||
/**
|
||||
* 자가농업 항목 오픈 여부
|
||||
*/
|
||||
private boolean farmingOpen;
|
||||
/**
|
||||
* 데이터 등록 가능 여부
|
||||
*/
|
||||
private boolean registrable;
|
||||
/**
|
||||
* 데이터 수정 가능 여부
|
||||
*/
|
||||
private boolean modifiable;
|
||||
|
||||
/**
|
||||
* 현재 단계
|
||||
*/
|
||||
private DailySort currentStep;
|
||||
/**
|
||||
* 특정일의 데이터 등록 대상 항목
|
||||
*/
|
||||
private List<DailySort> targetList;
|
||||
/**
|
||||
* 다음 단계로 이동될 단계 대상 항목
|
||||
*/
|
||||
private List<DailySort> stepList;
|
||||
/**
|
||||
* 다음 단계로 이동될 단계 조회
|
||||
*
|
||||
* @return 다음 단계명
|
||||
*/
|
||||
public String getNextStep() {
|
||||
String returnValue = null;
|
||||
if (stepList != null) {
|
||||
int index = 0;
|
||||
int size = stepList.size();
|
||||
for (DailySort target : stepList) {
|
||||
if (target.equals(currentStep) && (index + 1) != size) {
|
||||
returnValue = stepList.get(index + 1).name();
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package app.module.core.usecase.daily.record.adapters.persistence.model;
|
||||
|
||||
import app.module.core.config.application.enums.DailyStatus;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class DailyRecordStatusDto {
|
||||
/**
|
||||
* 일계부 일련번호
|
||||
*/
|
||||
private Long dailyId;
|
||||
/**
|
||||
* 특정일의 그룹 번호
|
||||
*/
|
||||
private Integer dayGroupNo;
|
||||
/**
|
||||
* 시작일
|
||||
*/
|
||||
private LocalDate startDate;
|
||||
/**
|
||||
* 종료일
|
||||
*/
|
||||
private LocalDate endDate;
|
||||
/**
|
||||
* 특정일 입력 상태
|
||||
*/
|
||||
private DailyStatus allStatus;
|
||||
/**
|
||||
* 수입 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus incomeStatus;
|
||||
/**
|
||||
* 임업노동 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus workStatus;
|
||||
/**
|
||||
* 지출 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus expenseStatus;
|
||||
/**
|
||||
* 동력 사용시간 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus powerStatus;
|
||||
/**
|
||||
* 자가임업 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus forestryStatus;
|
||||
/**
|
||||
* 자가농업 입력 상태
|
||||
*/
|
||||
private DailyTargetStatus farmingStatus;
|
||||
/**
|
||||
* 수입 입력 개수
|
||||
*/
|
||||
private Integer incomeCount;
|
||||
/**
|
||||
* 임업노동 입력 개수
|
||||
*/
|
||||
private Integer workCount;
|
||||
/**
|
||||
* 지출 입력 개수
|
||||
*/
|
||||
private Integer expenseCount;
|
||||
/**
|
||||
* 동력 사용시간 입력 개수
|
||||
*/
|
||||
private Integer powerCount;
|
||||
/**
|
||||
* 자가임업 입력 개수
|
||||
*/
|
||||
private Integer forestryCount;
|
||||
/**
|
||||
* 자가농업 입력 개수
|
||||
*/
|
||||
private Integer farmingCount;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.core.usecase.daily.record.adapters.persistence.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UpdateDailyRecordDto {
|
||||
private String monthly;
|
||||
private String updatedBy;
|
||||
private String statusType;
|
||||
private String statusCode;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package app.module.core.usecase.daily.record.adapters.web.model;
|
||||
|
||||
import app.module.core.config.application.enums.DailyStatus;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class CreateDailyRecordReqVO {
|
||||
private Long id;
|
||||
private String recordMonth;
|
||||
private int dayGroupNo;
|
||||
private Long householdSeq;
|
||||
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
private String todayNone;
|
||||
private DailyStatus allStatus;
|
||||
private DailyTargetStatus incomeStatus;
|
||||
private DailyTargetStatus workStatus;
|
||||
private DailyTargetStatus expenseStatus;
|
||||
private DailyTargetStatus powerStatus;
|
||||
private DailyTargetStatus forestryStatus;
|
||||
private DailyTargetStatus farmingStatus;
|
||||
|
||||
/**
|
||||
* 금일 데이터 없음으로 각 항목 상태 일괄 변경
|
||||
*
|
||||
* @param todayNone 상태
|
||||
*/
|
||||
public void setTodayNone(String todayNone) {
|
||||
this.todayNone = todayNone;
|
||||
|
||||
if ("Y".equals(todayNone)) {
|
||||
this.allStatus = DailyStatus.TODAY_NONE;
|
||||
this.incomeStatus = DailyTargetStatus.TODAY_NONE;
|
||||
this.workStatus = DailyTargetStatus.TODAY_NONE;
|
||||
this.expenseStatus = DailyTargetStatus.TODAY_NONE;
|
||||
this.powerStatus = DailyTargetStatus.TODAY_NONE;
|
||||
this.forestryStatus = DailyTargetStatus.TODAY_NONE;
|
||||
} else {
|
||||
this.allStatus = DailyStatus.WAITING;
|
||||
|
||||
if (incomeStatus == null) {
|
||||
this.incomeStatus = DailyTargetStatus.TODAY_NONE;
|
||||
}
|
||||
if (workStatus == null) {
|
||||
this.workStatus = DailyTargetStatus.TODAY_NONE;
|
||||
}
|
||||
if (expenseStatus == null) {
|
||||
this.expenseStatus = DailyTargetStatus.TODAY_NONE;
|
||||
}
|
||||
if (powerStatus == null) {
|
||||
this.powerStatus = DailyTargetStatus.TODAY_NONE;
|
||||
}
|
||||
if (forestryStatus == null) {
|
||||
this.forestryStatus = DailyTargetStatus.TODAY_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 농업 생산물 입력 상태 변경
|
||||
*
|
||||
* @param isOpen 자가농업 항목 오픈 여부
|
||||
*/
|
||||
public void setFarming(boolean isOpen) {
|
||||
if (farmingStatus == null) {
|
||||
if (isOpen) {
|
||||
this.farmingStatus = DailyTargetStatus.TODAY_NONE;
|
||||
} else {
|
||||
this.farmingStatus = DailyTargetStatus.NONE;
|
||||
}
|
||||
} else {
|
||||
this.farmingStatus = DailyTargetStatus.TARGET;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package app.module.core.usecase.daily.record.adapters.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.apache.tika.utils.StringUtils;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class DailyUIReqVO {
|
||||
public DailyUIReqVO() {
|
||||
}
|
||||
|
||||
public DailyUIReqVO(String searchMonth, Integer groupNo, Long householdSeq) {
|
||||
this.householdSeq = householdSeq;
|
||||
this.searchMonth = searchMonth;
|
||||
this.groupNo = groupNo;
|
||||
}
|
||||
|
||||
public DailyUIReqVO(String searchMonth, String groupNo, Long householdSeq) {
|
||||
this.householdSeq = householdSeq;
|
||||
this.searchMonth = searchMonth;
|
||||
if (!StringUtils.isBlank(groupNo)) {
|
||||
this.groupNo = Integer.parseInt(groupNo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 검색 월(yyyyMM)
|
||||
*/
|
||||
private String searchMonth;
|
||||
/**
|
||||
* 검색 그룸번호
|
||||
*/
|
||||
private Integer groupNo;
|
||||
/**
|
||||
* 임가 일련번호
|
||||
*/
|
||||
private Long householdSeq;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.core.usecase.daily.record.ports;
|
||||
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.core.usecase.daily.record.adapters.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.core.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
|
||||
public interface DailyRecordPortIn {
|
||||
/**
|
||||
* 일계부 항목 조회
|
||||
*
|
||||
* @param reqVO 검색 조건
|
||||
* @return 항목 상세
|
||||
*/
|
||||
DailyRecordDto detail(String recordMonth, Integer dayGroupNo, Long householdSeq);
|
||||
|
||||
/**
|
||||
* 일계부 항목 등록
|
||||
*
|
||||
* @param formVO 입력 데이터
|
||||
*/
|
||||
void create(CreateDailyRecordReqVO formVO);
|
||||
|
||||
void updateByStatus(String recordMonth, Integer dayGroupNo, Long householdSeq, String targetType, String targetStatus);
|
||||
|
||||
void updateByAllStatus(String recordMonth, Integer dayGroupNo, Long householdSeq);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package app.module.core.usecase.daily.record.ports;
|
||||
|
||||
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.CreateDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.GetDailyRecordCmd;
|
||||
|
||||
public interface DailyRecordPortOut {
|
||||
/**
|
||||
* 일계부 항목 조회
|
||||
* @param command 검색 조건
|
||||
* @return 항목 상세
|
||||
*/
|
||||
DailyRecordDto detail(GetDailyRecordCmd command);
|
||||
|
||||
/**
|
||||
* 일계부 항목 등록
|
||||
*
|
||||
* @param findCmd 검색 조건
|
||||
* @param command 입력 데이터
|
||||
*/
|
||||
void create(GetDailyRecordCmd findCmd, CreateDailyRecordCmd command);
|
||||
|
||||
void updateByStatus(String recordMonth, Integer dayGroupNo, Long householdSeq, String targetType, String targetStatus);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package app.module.core.usecase.daily.record.ports.application;
|
||||
|
||||
import app.module.core.config.application.enums.DailySort;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import app.module.core.config.application.util.AuditUtil;
|
||||
import app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto;
|
||||
import app.module.core.usecase.daily.record.adapters.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.core.usecase.daily.record.adapters.web.model.DailyUIReqVO;
|
||||
import app.module.core.usecase.daily.record.ports.DailyRecordPortIn;
|
||||
import app.module.core.usecase.daily.record.ports.DailyRecordPortOut;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.CreateDailyRecordCmd;
|
||||
import app.module.core.usecase.daily.record.ports.application.domain.GetDailyRecordCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DailyRecordService implements DailyRecordPortIn {
|
||||
private final DailyRecordPortOut portOut;
|
||||
|
||||
@Override
|
||||
public DailyRecordDto detail(String recordMonth, Integer dayGroupNo, Long householdSeq) {
|
||||
DailyRecordDto dailyRecord = portOut.detail(new GetDailyRecordCmd(recordMonth, dayGroupNo, householdSeq));
|
||||
|
||||
if (dailyRecord != null) {
|
||||
List<DailySort> targetList = new ArrayList<>();
|
||||
if (this.isTarget(dailyRecord.getIncomeStatus())) {
|
||||
targetList.add(DailySort.INCOME);
|
||||
}
|
||||
if (this.isTarget(dailyRecord.getWorkStatus())) {
|
||||
targetList.add(DailySort.WORK);
|
||||
}
|
||||
if (this.isTarget(dailyRecord.getExpenseStatus())) {
|
||||
targetList.add(DailySort.EXPENSE);
|
||||
}
|
||||
if (this.isTarget(dailyRecord.getPowerStatus())) {
|
||||
targetList.add(DailySort.POWER);
|
||||
}
|
||||
if (this.isTarget(dailyRecord.getForestryStatus())) {
|
||||
targetList.add(DailySort.FORESTRY);
|
||||
}
|
||||
if (this.isTarget(dailyRecord.getFarmingStatus())) {
|
||||
targetList.add(DailySort.FARMING);
|
||||
}
|
||||
dailyRecord.setTargetList(targetList);
|
||||
}
|
||||
|
||||
return dailyRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터 등록 대상 여부
|
||||
*
|
||||
* @param status 상태
|
||||
* @return true=대상, false=대상 아님
|
||||
*/
|
||||
private boolean isTarget(DailyTargetStatus status) {
|
||||
return DailyTargetStatus.TARGET.equals(status) || DailyTargetStatus.TODAY_NONE.equals(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(CreateDailyRecordReqVO formVO) {
|
||||
GetDailyRecordCmd findCmd = new GetDailyRecordCmd(
|
||||
formVO.getRecordMonth(),
|
||||
formVO.getDayGroupNo(),
|
||||
formVO.getHouseholdSeq());
|
||||
|
||||
CreateDailyRecordCmd command = AuditUtil.create(
|
||||
new CreateDailyRecordCmd(
|
||||
null,
|
||||
formVO.getRecordMonth(),
|
||||
formVO.getDayGroupNo(),
|
||||
formVO.getHouseholdSeq(),
|
||||
formVO.getStartDate(),
|
||||
formVO.getEndDate(),
|
||||
formVO.getAllStatus(),
|
||||
formVO.getIncomeStatus(),
|
||||
formVO.getWorkStatus(),
|
||||
formVO.getExpenseStatus(),
|
||||
formVO.getPowerStatus(),
|
||||
formVO.getForestryStatus(),
|
||||
formVO.getFarmingStatus()));
|
||||
|
||||
portOut.create(findCmd, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateByStatus(String recordMonth, Integer dayGroupNo, Long householdSeq, String targetType, String targetStatus) {
|
||||
portOut.updateByStatus(recordMonth, dayGroupNo, householdSeq, targetType, targetStatus);
|
||||
portOut.updateByStatus(recordMonth, dayGroupNo, householdSeq, "ALL", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateByAllStatus(String recordMonth, Integer dayGroupNo, Long householdSeq) {
|
||||
portOut.updateByStatus(recordMonth, dayGroupNo, householdSeq, "ALL", null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.core.usecase.daily.record.ports.application.domain;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditCommand;
|
||||
import app.module.core.config.application.enums.DailyStatus;
|
||||
import app.module.core.config.application.enums.DailyTargetStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class CreateDailyRecordCmd extends AuditCommand {
|
||||
private Long id;
|
||||
private String recordMonth;
|
||||
private int dayGroupNo;
|
||||
private Long householdSeq;
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
private DailyStatus allStatus;
|
||||
private DailyTargetStatus incomeStatus;
|
||||
private DailyTargetStatus workStatus;
|
||||
private DailyTargetStatus expenseStatus;
|
||||
private DailyTargetStatus powerStatus;
|
||||
private DailyTargetStatus forestryStatus;
|
||||
private DailyTargetStatus farmingStatus;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package app.module.core.usecase.daily.record.ports.application.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class GetDailyRecordCmd {
|
||||
/**
|
||||
* 검색 월(yyyyMM)
|
||||
*/
|
||||
private String searchMonth;
|
||||
/**
|
||||
* 검색 그룸번호
|
||||
*/
|
||||
private Integer groupNo;
|
||||
/**
|
||||
* 임가 일련번호
|
||||
*/
|
||||
private Long householdSeq;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.usecase.daily.record.ports.application.domain;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditCommand;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class UpdateDailyRecordStatusCmd extends AuditCommand {
|
||||
private String recordMonth;
|
||||
private Integer dayGroupNo;
|
||||
private Long householdSeq;
|
||||
private String allStatus;
|
||||
private String targetType;
|
||||
private String targetStatus;
|
||||
}
|
||||
126
core/src/main/resources/mappers/daily/DailyRecordMapper.xml
Normal file
126
core/src/main/resources/mappers/daily/DailyRecordMapper.xml
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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.core.usecase.daily.record.adapters.persistence.DailyRecordMapper">
|
||||
|
||||
<select id="getDailyRecord"
|
||||
resultType="app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordDto">
|
||||
select ddg.group_no, ddg.start_day, ddg.end_day
|
||||
, dr.id, dr.record_month, dr.day_group_no, dr.start_date, dr.end_date
|
||||
, dr.all_status, dr.income_status, dr.work_status, dr.expense_status, dr.power_status, dr.forestry_status, dr.farming_status
|
||||
from daily_day_group ddg
|
||||
left join
|
||||
daily_record dr on dr.day_group_no = ddg.group_no and dr.is_deleted = false
|
||||
and dr.record_month = #{searchMonth}
|
||||
and dr.household_seq = #{householdSeq}
|
||||
where ddg.is_deleted = false
|
||||
and ddg.group_no = #{groupNo}
|
||||
</select>
|
||||
|
||||
<select id="getDailyRecordStatus"
|
||||
resultType="app.module.core.usecase.daily.record.adapters.persistence.model.DailyRecordStatusDto">
|
||||
select dr.id as daily_id
|
||||
, dr.day_group_no, dr.start_date, dr.end_date
|
||||
, dr.all_status
|
||||
, dr.income_status
|
||||
, dr.work_status
|
||||
, dr.expense_status
|
||||
, dr.power_status
|
||||
, dr.forestry_status
|
||||
, dr.farming_status
|
||||
, (select count(*) from daily_income di where di.daily_record_seq = dr.id and di.is_deleted = false) as income_count
|
||||
, (select count(*) from daily_work dw where dw.daily_record_seq = dr.id and dw.is_deleted = false) as work_count
|
||||
, (select count(*) from daily_expense de where de.daily_record_seq = dr.id and de.is_deleted = false) as expense_count
|
||||
, (select count(*) from daily_power dp where dp.daily_record_seq = dr.id and dp.is_deleted = false) as power_count
|
||||
, (select count(*) from daily_forestry df1 where df1.daily_record_seq = dr.id and df1.is_deleted = false) as forestry_count
|
||||
, (select count(*) from daily_farming df2 where df2.daily_record_seq = dr.id and df2.is_deleted = false) as farming_count
|
||||
from daily_record dr
|
||||
where dr.is_deleted = false
|
||||
and dr.household_seq = #{householdSeq}
|
||||
and dr.record_month = #{searchMonth}
|
||||
<if test="groupNo != null">
|
||||
and dr.day_group_no = #{groupNo}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getDailyRecordExistCount" resultType="int">
|
||||
select count(1) as exist
|
||||
from daily_record dr
|
||||
where dr.is_deleted = false
|
||||
and dr.household_seq = #{householdSeq}
|
||||
and dr.record_month = #{searchMonth}
|
||||
and dr.day_group_no = #{groupNo}
|
||||
</select>
|
||||
|
||||
<insert id="createDailyRecord" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into daily_record (
|
||||
household_seq, record_month, day_group_no, start_date, end_date
|
||||
, all_status, income_status, work_status, expense_status, power_status, forestry_status, farming_status
|
||||
, is_deleted
|
||||
, <include refid="common.fields.CreateUpdateBaseColumns"/>
|
||||
) values (
|
||||
#{householdSeq}
|
||||
, #{recordMonth}, #{dayGroupNo}, #{startDate}, #{endDate}
|
||||
, #{allStatus}, #{incomeStatus}, #{workStatus}, #{expenseStatus}, #{powerStatus}, #{forestryStatus}, #{farmingStatus}
|
||||
, false
|
||||
, <include refid="common.fields.CreateUpdateBaseValues"/>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateDailyRecord">
|
||||
update daily_record set <include refid="common.fields.UpdateBaseSet"/>
|
||||
, all_status = #{allStatus}
|
||||
, income_status = #{incomeStatus}
|
||||
, work_status = #{workStatus}
|
||||
, expense_status = #{expenseStatus}
|
||||
, power_status = #{powerStatus}
|
||||
, forestry_status = #{forestryStatus}
|
||||
, farming_status = #{farmingStatus}
|
||||
where is_deleted = false
|
||||
and record_month = #{recordMonth}
|
||||
and day_group_no = #{dayGroupNo}
|
||||
and household_seq = #{householdSeq}
|
||||
</update>
|
||||
|
||||
<update id="updateDailyRecordStatus">
|
||||
update daily_record set <include refid="common.fields.UpdateBaseSet"/>
|
||||
<if test="allStatus != null and allStatus != ''">
|
||||
, all_status = #{allStatus}
|
||||
</if>
|
||||
<if test="targetType != null and targetType != ''">
|
||||
/* TODO 개별 상태값 변경 */
|
||||
<choose>
|
||||
<when test="targetType eq 'INCOME'">
|
||||
, income_status = #{targetStatus}
|
||||
</when>
|
||||
<when test="targetType eq 'WORK'">
|
||||
, work_status = #{targetStatus}
|
||||
</when>
|
||||
<when test="targetType eq 'EXPENSE'">
|
||||
, expense_status = #{targetStatus}
|
||||
</when>
|
||||
<when test="targetType eq 'POWER'">
|
||||
, power_status = #{targetStatus}
|
||||
</when>
|
||||
<when test="targetType eq 'FORESTRY'">
|
||||
, forestry_status = #{targetStatus}
|
||||
</when>
|
||||
<when test="targetType eq 'FARMING'">
|
||||
, farming_status = #{targetStatus}
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
where is_deleted = false
|
||||
and household_seq = #{householdSeq}
|
||||
and record_month = #{recordMonth}
|
||||
and day_group_no = #{dayGroupNo}
|
||||
</update>
|
||||
|
||||
<sql id="InnerJoinByDailyRecord">
|
||||
inner join daily_record dr on
|
||||
dr.id = ds.daily_record_seq
|
||||
and dr.is_deleted = false
|
||||
and dr.record_month = #{searchMonth} and dr.day_group_no = #{groupNo}
|
||||
and dr.household_seq = #{householdSeq}
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user