[FO] 일계부 등록 wip
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package app.module.front.usecase.daily.calendar.persistence;
|
||||
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordCalendarDto;
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.front.usecase.daily.calendar.web.model.RecordCalendarUIReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.UpdateDailyRecordStatusCmd;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RecordCalendarMapper {
|
||||
|
||||
List<DailyRecordCalendarDto> getCalendarByDailyRecord(RecordCalendarUIReqVO reqVO);
|
||||
|
||||
DailyRecordStatusDto getDailyRecordStatus(RecordCalendarUIReqVO reqVO);
|
||||
|
||||
int getStartDayByDailyGroupNo(@Param("groupNo") Integer groupNo);
|
||||
|
||||
/**
|
||||
* 일계부 등록 여부
|
||||
* @param householdSeq
|
||||
* @param recordMonth
|
||||
* @param dayGroupNo
|
||||
* @return
|
||||
*/
|
||||
Long getDailyRecordExistCount(@Param("householdSeq") Long householdSeq, @Param("recordMonth") String recordMonth, @Param("dayGroupNo") Integer dayGroupNo);
|
||||
|
||||
/**
|
||||
* 일계부 등록(생성)
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
Long createDailyRecord(CreateDailyRecordReqVO command);
|
||||
|
||||
/**
|
||||
* 일계부 상태 수정
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
int updateDailyRecordStatus(UpdateDailyRecordStatusCmd command);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.daily.calendar.persistence.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class DailyRecordCalendarDto {
|
||||
private String groupNo;
|
||||
private Integer startDay;
|
||||
private Integer endDay;
|
||||
private String startDate;
|
||||
private String dailyId;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.front.usecase.daily.calendar.persistence.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class DailyRecordStatusDto {
|
||||
/**
|
||||
* 일계부 일련번호
|
||||
*/
|
||||
private Long dailyId;
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
/**
|
||||
* 특정일 입력 상태 TODO enum
|
||||
*/
|
||||
private String allStatus;
|
||||
/**
|
||||
* 수입 입력 상태 TODO enum
|
||||
*/
|
||||
private String incomeStatus;
|
||||
/**
|
||||
* 수입 입력 개수
|
||||
*/
|
||||
private Integer incomeCount;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.front.usecase.daily.calendar.service;
|
||||
|
||||
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordCalendarDto;
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.front.usecase.daily.calendar.web.model.RecordCalendarUIReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RecordCalendarService {
|
||||
List<DailyRecordCalendarDto> getCalendarByDailyRecord(RecordCalendarUIReqVO reqVO);
|
||||
|
||||
DailyRecordStatusDto getDailyRecordStatus(RecordCalendarUIReqVO reqVO);
|
||||
|
||||
int getStartDayByDailyGroupNo(RecordCalendarUIReqVO reqVO);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.front.usecase.daily.calendar.service;
|
||||
|
||||
import app.module.front.usecase.daily.calendar.persistence.RecordCalendarMapper;
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordCalendarDto;
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.front.usecase.daily.calendar.web.model.RecordCalendarUIReqVO;
|
||||
import app.module.front.usecase.daily.record.persistence.DailyRecordMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RecordCalendarServiceImpl implements RecordCalendarService {
|
||||
private final RecordCalendarMapper recordCalendarMapper;
|
||||
|
||||
@Override
|
||||
public List<DailyRecordCalendarDto> getCalendarByDailyRecord(RecordCalendarUIReqVO reqVO) {
|
||||
int lastDay = reqVO.getSearchDate().withDayOfMonth(reqVO.getSearchDate().lengthOfMonth()).getDayOfMonth();
|
||||
|
||||
List<DailyRecordCalendarDto> list = recordCalendarMapper.getCalendarByDailyRecord(reqVO);
|
||||
|
||||
List<DailyRecordCalendarDto> refineList = new ArrayList<DailyRecordCalendarDto>();
|
||||
for (DailyRecordCalendarDto record : list) {
|
||||
record.setStartDate(reqVO.getSearchMonth() + String.format("%02d", record.getStartDay()));
|
||||
|
||||
if ((lastDay == 28 || lastDay == 30) && record.getStartDay() == lastDay) {
|
||||
record.setEndDay(lastDay);
|
||||
refineList.add(record);
|
||||
} else if (record.getStartDay() <= lastDay && record.getEndDay() <= lastDay) {
|
||||
refineList.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
return refineList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DailyRecordStatusDto getDailyRecordStatus(RecordCalendarUIReqVO reqVO) {
|
||||
return recordCalendarMapper.getDailyRecordStatus(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartDayByDailyGroupNo(RecordCalendarUIReqVO reqVO) {
|
||||
return recordCalendarMapper.getStartDayByDailyGroupNo(reqVO.getGroupNo());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package app.module.front.usecase.daily.calendar.web;
|
||||
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordCalendarDto;
|
||||
import app.module.front.usecase.daily.calendar.persistence.model.DailyRecordStatusDto;
|
||||
import app.module.front.usecase.daily.calendar.service.RecordCalendarService;
|
||||
import app.module.front.usecase.daily.calendar.web.model.RecordCalendarUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/record/calendar")
|
||||
public class RecordCalendarController {
|
||||
private final RecordCalendarService recordCalendarService;
|
||||
|
||||
@GetMapping(path = "")
|
||||
public String index(Model model, @RequestParam(value = "searchDay", required = false) String searchDay) {
|
||||
RecordCalendarUIReqVO reqVO = new RecordCalendarUIReqVO(searchDay, getAccessId());
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("calendarList", recordCalendarService.getCalendarByDailyRecord(reqVO));
|
||||
|
||||
return "record/calendar";
|
||||
}
|
||||
|
||||
@PostMapping(path = "/{searchMonth}/{groupNo}")
|
||||
public String detail(Model model
|
||||
, @PathVariable(required = true) String searchMonth
|
||||
, @PathVariable(required = true) String groupNo) {
|
||||
|
||||
RecordCalendarUIReqVO reqVO = new RecordCalendarUIReqVO();
|
||||
reqVO.setSearchMonth(searchMonth);
|
||||
reqVO.setGroupNo(Integer.parseInt(groupNo));
|
||||
reqVO.setHouseholdSeq(getAccessId());
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
DailyRecordStatusDto detail = recordCalendarService.getDailyRecordStatus(reqVO);
|
||||
if (detail == null) {
|
||||
int startDay = recordCalendarService.getStartDayByDailyGroupNo(reqVO);
|
||||
reqVO.setSearchDay(reqVO.getSearchMonth() + String.format("%02d", startDay));
|
||||
}
|
||||
|
||||
//uiCodeListPortIn.connect("code.pageable.rows");
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("detail", detail);
|
||||
|
||||
return "record/calendar-wrap";
|
||||
}
|
||||
|
||||
// TODO : 로그인 SEQ
|
||||
private Long getAccessId() {
|
||||
return 2L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package app.module.front.usecase.daily.calendar.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.apache.tika.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class RecordCalendarUIReqVO {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RecordCalendarUIReqVO.class);
|
||||
|
||||
public RecordCalendarUIReqVO() {
|
||||
}
|
||||
|
||||
public RecordCalendarUIReqVO(String searchDay, Long accessId) {
|
||||
if (StringUtils.isBlank(searchDay) || searchDay.length() != 8) {
|
||||
searchDay = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
}
|
||||
|
||||
try {
|
||||
SimpleDateFormat beforeSdf = new SimpleDateFormat("yyyyMMdd", Locale.KOREAN);
|
||||
SimpleDateFormat afterSdf = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREAN);
|
||||
SimpleDateFormat monthSdf = new SimpleDateFormat("yyyyMM", Locale.KOREAN);
|
||||
|
||||
Date formatDate = beforeSdf.parse(searchDay);
|
||||
|
||||
setSearchDate(LocalDate.parse(afterSdf.format(formatDate)));
|
||||
setSearchMonth(monthSdf.format(formatDate));
|
||||
setSearchDay(beforeSdf.format(formatDate));
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("[DateParse] target={}", searchDay, e);
|
||||
}
|
||||
|
||||
setHouseholdSeq(accessId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검색 일(yyyyMMdd)
|
||||
*/
|
||||
private String searchDay;
|
||||
|
||||
/**
|
||||
* 검색 월(yyyyMM)
|
||||
*/
|
||||
private String searchMonth;
|
||||
private Integer groupNo;
|
||||
|
||||
/**
|
||||
* 검색 일(yyyy-MM-dd)
|
||||
*/
|
||||
private LocalDate searchDate;
|
||||
|
||||
/**
|
||||
* 임가회원 일련번호
|
||||
*/
|
||||
private Long householdSeq;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package app.module.front.usecase.daily.income.web;
|
||||
|
||||
import app.module.front.usecase.daily.income.web.model.DailyIncomeUIReqVO;
|
||||
import app.module.front.usecase.daily.record.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyRecordUIReqVO;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/record/income")
|
||||
public class DailyIncomeController {
|
||||
|
||||
@GetMapping(path = "/{searchMonth}/{groupNo}")
|
||||
public String index(Model model
|
||||
, @PathVariable(required = true) String searchMonth
|
||||
, @PathVariable(required = true) String groupNo) {
|
||||
|
||||
DailyIncomeUIReqVO reqVO = new DailyIncomeUIReqVO();
|
||||
reqVO.setSearchMonth(searchMonth);
|
||||
reqVO.setGroupNo(Integer.parseInt(groupNo));
|
||||
reqVO.setHouseholdSeq(getAccessId());
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("detail", null);
|
||||
|
||||
return "record/income/index";
|
||||
}
|
||||
|
||||
// TODO : 로그인 SEQ
|
||||
private Long getAccessId() {
|
||||
return 2L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.front.usecase.daily.income.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class DailyIncomeUIReqVO {
|
||||
private String searchMonth;
|
||||
private Integer groupNo;
|
||||
private Long householdSeq;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package app.module.front.usecase.daily.record.persistence;
|
||||
|
||||
import app.module.front.usecase.daily.record.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyRecordUIReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.UpdateDailyRecordStatusCmd;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface DailyRecordMapper {
|
||||
|
||||
DailyRecordDto getDailyRecord(DailyRecordUIReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 일계부 등록 여부
|
||||
* @param householdSeq
|
||||
* @param recordMonth
|
||||
* @param dayGroupNo
|
||||
* @return
|
||||
*/
|
||||
Long getDailyRecordExistCount(@Param("householdSeq") Long householdSeq, @Param("recordMonth") String recordMonth, @Param("dayGroupNo") Integer dayGroupNo);
|
||||
|
||||
/**
|
||||
* 일계부 등록(생성)
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
Long createDailyRecord(CreateDailyRecordReqVO command);
|
||||
|
||||
/**
|
||||
* 일계부 상태 수정
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
int updateDailyRecordStatus(UpdateDailyRecordStatusCmd command);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package app.module.front.usecase.daily.record.persistence.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class DailyRecordDto {
|
||||
// household_seq, record_month, day_group_no, start_date, end_date
|
||||
// , all_status, income_status, work_status, expense_status, power_status, forestry_status
|
||||
// , created_at, created_by, is_deleted
|
||||
|
||||
private Integer groupNo;
|
||||
private Integer startDay;
|
||||
private Integer endDay;
|
||||
|
||||
private Long id;
|
||||
// TODO enum
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
private String allStatus;
|
||||
private String incomeStatus;
|
||||
|
||||
public boolean isUpdated() {
|
||||
boolean returnValue = false;
|
||||
if (id != null) {
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.daily.record.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,11 @@
|
||||
package app.module.front.usecase.daily.record.service;
|
||||
|
||||
import app.module.front.usecase.daily.record.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyRecordUIReqVO;
|
||||
|
||||
public interface DailyRecordService {
|
||||
DailyRecordDto getDailyRecord(DailyRecordUIReqVO reqVO);
|
||||
|
||||
void createDailyRecord(CreateDailyRecordReqVO command);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package app.module.front.usecase.daily.record.service;
|
||||
|
||||
import app.module.front.usecase.daily.record.persistence.DailyRecordMapper;
|
||||
import app.module.front.usecase.daily.record.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyRecordUIReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyStatus;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyTargetStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DailyRecordServiceImpl implements DailyRecordService {
|
||||
private final DailyRecordMapper dailyRecordMapper;
|
||||
|
||||
@Override
|
||||
public DailyRecordDto getDailyRecord(DailyRecordUIReqVO reqVO) {
|
||||
DailyRecordDto detail = dailyRecordMapper.getDailyRecord(reqVO);
|
||||
if (detail != null && !detail.isUpdated()) {
|
||||
try {
|
||||
SimpleDateFormat beforeSdf = new SimpleDateFormat("yyyyMMdd", Locale.KOREAN);
|
||||
SimpleDateFormat afterSdf = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREAN);
|
||||
|
||||
Date formatDate = beforeSdf.parse(reqVO.getSearchMonth() + String.format("%02d", detail.getStartDay()));
|
||||
detail.setStartDate(LocalDate.parse(afterSdf.format(formatDate)));
|
||||
|
||||
formatDate = beforeSdf.parse(reqVO.getSearchMonth() + String.format("%02d", detail.getEndDay()));
|
||||
detail.setEndDate(LocalDate.parse(afterSdf.format(formatDate)));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("[DateParse] target={}", detail.getStartDay(), e);
|
||||
}
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDailyRecord(CreateDailyRecordReqVO command) {
|
||||
|
||||
if ("Y".equals(command.getTodayNone())) {
|
||||
command.setAllStatus(DailyStatus.TODAY_NONE);
|
||||
} else {
|
||||
command.setAllStatus(DailyStatus.WAITING);
|
||||
|
||||
if (command.getIncomeStatus() == null) {
|
||||
command.setIncomeStatus(DailyTargetStatus.NONE);
|
||||
}
|
||||
if (command.getWorkStatus() == null) {
|
||||
command.setWorkStatus(DailyTargetStatus.NONE);
|
||||
}
|
||||
if (command.getExpenseStatus() == null) {
|
||||
command.setExpenseStatus(DailyTargetStatus.NONE);
|
||||
}
|
||||
if (command.getPowerStatus() == null) {
|
||||
command.setPowerStatus(DailyTargetStatus.NONE);
|
||||
}
|
||||
if (command.getForestryStatus() == null) {
|
||||
command.setForestryStatus(DailyTargetStatus.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
dailyRecordMapper.createDailyRecord(command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package app.module.front.usecase.daily.record.web;
|
||||
|
||||
import app.module.front.usecase.daily.calendar.service.RecordCalendarService;
|
||||
import app.module.front.usecase.daily.record.persistence.model.DailyRecordDto;
|
||||
import app.module.front.usecase.daily.record.service.DailyRecordService;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
import app.module.front.usecase.daily.record.web.model.DailyRecordUIReqVO;
|
||||
import app.module.front.usecase.daily.record.web.validator.CreateDailyRecordValidator;
|
||||
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.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/record/daily")
|
||||
public class DailyRecordController {
|
||||
private final RecordCalendarService recordCalendarService;
|
||||
private final DailyRecordService dailyRecordService;
|
||||
private final CreateDailyRecordValidator createDailyRecordValidator;;
|
||||
|
||||
@GetMapping(path = "/{searchMonth}/{groupNo}")
|
||||
public String createForm(Model model
|
||||
, @PathVariable(required = true) String searchMonth
|
||||
, @PathVariable(required = true) String groupNo) {
|
||||
|
||||
DailyRecordUIReqVO reqVO = new DailyRecordUIReqVO();
|
||||
reqVO.setSearchMonth(searchMonth);
|
||||
reqVO.setGroupNo(Integer.parseInt(groupNo));
|
||||
reqVO.setHouseholdSeq(getAccessId());
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
//uiCodeListPortIn.connect("code.pageable.rows");
|
||||
|
||||
DailyRecordDto detail = dailyRecordService.getDailyRecord(reqVO);
|
||||
|
||||
model.addAttribute("reqVO", reqVO);
|
||||
model.addAttribute("detail", detail);
|
||||
|
||||
return "record/daily";
|
||||
}
|
||||
|
||||
@PostMapping(path = "/{searchMonth}/{groupNo}")
|
||||
ResponseEntity<?> create(@PathVariable(required = true) String searchMonth
|
||||
, @PathVariable(required = true) String groupNo
|
||||
, @Valid @RequestBody CreateDailyRecordReqVO formVO, BindingResult bindingResult) {
|
||||
|
||||
createDailyRecordValidator.validate(formVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
DailyRecordUIReqVO reqVO = new DailyRecordUIReqVO();
|
||||
reqVO.setSearchMonth(searchMonth);
|
||||
reqVO.setGroupNo(Integer.parseInt(groupNo));
|
||||
reqVO.setHouseholdSeq(getAccessId());
|
||||
log.debug("reqVO: {}", reqVO);
|
||||
|
||||
//uiCodeListPortIn.connect("code.pageable.rows");
|
||||
|
||||
DailyRecordDto detail = dailyRecordService.getDailyRecord(reqVO);
|
||||
|
||||
formVO.setHouseholdSeq(reqVO.getHouseholdSeq());
|
||||
formVO.setRecordMonth(reqVO.getSearchMonth());
|
||||
formVO.setDayGroupNo(reqVO.getGroupNo());
|
||||
formVO.setStartDate(detail.getStartDate());
|
||||
formVO.setEndDate(detail.getEndDate());
|
||||
|
||||
log.debug("formVO: {}", formVO);
|
||||
dailyRecordService.createDailyRecord(formVO);
|
||||
log.debug("createDailyRecord: id-{}", formVO.getId());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
|
||||
// TODO : 로그인 SEQ
|
||||
private Long getAccessId() {
|
||||
return 2L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.front.usecase.daily.record.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class CreateDailyRecordReqVO {
|
||||
private Long id;
|
||||
private Long householdSeq;
|
||||
private String recordMonth;
|
||||
private int dayGroupNo;
|
||||
private LocalDate startDate;
|
||||
private LocalDate endDate;
|
||||
// TODO : 전체 상태값 정의 ING, DONE
|
||||
private String todayNone;
|
||||
private DailyStatus allStatus;
|
||||
// TODO : 개별 상태값 정의 WAITING, TYPING, TODAY_NONE, NONE, DONE
|
||||
private DailyTargetStatus incomeStatus;
|
||||
private DailyTargetStatus workStatus;
|
||||
private DailyTargetStatus expenseStatus;
|
||||
private DailyTargetStatus powerStatus;
|
||||
private DailyTargetStatus forestryStatus;
|
||||
// TODO : 무슨 데이터 넣을 것인가?
|
||||
private String createdBy;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.front.usecase.daily.record.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class DailyRecordUIReqVO {
|
||||
private String searchMonth;
|
||||
private Integer groupNo;
|
||||
private Long householdSeq;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package app.module.front.usecase.daily.record.web.model;
|
||||
|
||||
public enum DailyStatus {
|
||||
WAITING, TODAY_NONE, DONE;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package app.module.front.usecase.daily.record.web.model;
|
||||
|
||||
public enum DailyTargetStatus {
|
||||
WAITING, TODAY_NONE, NONE, DONE;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.front.usecase.daily.record.web.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UpdateDailyRecordStatusCmd {
|
||||
private Long id;
|
||||
private Long householdSeq;
|
||||
private String recordMonth;
|
||||
private int dayGroupNo;
|
||||
// TODO : 전체 상태값 정의 ING, DONE
|
||||
private String allStatus;
|
||||
// TODO : 개별 상태값 정의 WAITING, TYPING, TODAY_NONE, NONE, DONE
|
||||
private String targetType;
|
||||
private String targetStatus;
|
||||
// TODO : 무슨 데이터 넣을 것인가?
|
||||
private String updatedBy;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package app.module.front.usecase.daily.record.web.validator;
|
||||
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.front.usecase.daily.record.web.model.CreateDailyRecordReqVO;
|
||||
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 CreateDailyRecordValidator implements Validator {
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return CreateDailyRecordReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
CreateDailyRecordReqVO vo = (CreateDailyRecordReqVO) target;
|
||||
|
||||
if (StringUtils.isBlank(vo.getTodayNone())) {
|
||||
int noneCount = 0;
|
||||
if (vo.getIncomeStatus() != null) {
|
||||
noneCount++;
|
||||
}
|
||||
if (vo.getWorkStatus() != null) {
|
||||
noneCount++;
|
||||
}
|
||||
if (vo.getExpenseStatus() != null) {
|
||||
noneCount++;
|
||||
}
|
||||
if (vo.getPowerStatus() != null) {
|
||||
noneCount++;
|
||||
}
|
||||
if (vo.getForestryStatus() != null) {
|
||||
noneCount++;
|
||||
}
|
||||
|
||||
if (noneCount == 0) {
|
||||
errors.rejectValue(
|
||||
"incomeStatus", "valid.common.required",
|
||||
messageUtil.getMessage("valid.common.required"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user