๐ ์ฐธ๊ณ ํ์ด์ง_์์กด์ฑ
๐ ์ฐธ๊ณ ํ์ด์ง_querydslPredicateExcutor
์คํ๋ง ๋ถํธ ์ธ์๋ ์ฌ์ฉ๋๋์ง๋ ๋ชจ๋ฅด๊ฒ ์ผ๋ ์น๊ฐ๋ฐ์ ์งํํ๋ ํ ๊ณ์ ์ฌ์ฉํ ๊ฒ๊ฐ์โฆ
์ ๋ฒ ํ๋ก์ ํธ, ์ด๋ฒ ํ๋ก์ ํธ ๋ชจ๋ ์๋ฐ์ ์คํ๋ง๋ถํธ๋ก ๋ฐฑ์ค๋ ์์
์ ํ์๋๋ฐ ์ ๋ฒ MES ํ๋ก์ ํธ๋ ๊ฒ์ ์กฐ๊ฑด์ด ๋ง์ ๋๋ฌด ํ๋ค์์ธ ์ ์ด ์๋ค.
์กฐ๊ฑด์ด ํ๋ ์ถ๊ฐ๋ ์๋ก ์ดํ๋ฌธ์ด ์ผ๋ง๋ ๋์ด๋๋์งโฆ
์ด๋ ๊ฒ ํด์๋ ๋๋ ์๊ฒ ๋ค. ์๋ ๊ทธ๋ฌ๋ฉด ๋ค์ด๋ฒ ์ผํ๊ฐ์ ์์ฒญ๋ ๋ค์ค๊ฒ์์ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ๋๊ฑฐ์ง??? ๋ผ๋ ์๋ฌธ์ ๊ฐ๊ฒ ๋์๊ณ ์งฑ์ง๋ฏผ์๊ฒ ๊ณ ๋ฏผ์
์ด์ผ๊ธฐํ๋ ์ฟผ๋ฆฌ๋์์
์ด๋ผ๋๊ฒ์ด ์๋ค๋ ์ ๋ณด๋ฅผ ์ป๊ฒ ๋์๋ค. ๊ฐ์ฌํ๊ฒ๋ ๋ด๊ฐ ๋ฌป๊ธฐ ์ ์ ์งฑ์ง๋ฏผ๋ ๊ทธ๋ฐ ์๊ฐ์ ํ๊ณ ๊ตฌํ์ ํ ๋ค์ฌ์ ๋ง์ ๋์์ ์ป์๋ค.
QueryDSL์ด ๋ฒ์ ๋ ๋ค๋ฅด๊ณ ์ธํ
๋ฆฌ์ ์ด ๋ฒ์ ์ ๋ฐ๋ผ ๋ญ์ ๋ฐ๋ผ ์์กด์ฑ์ด ๋ฌ๋ผ์ ๋ธ๋ก๊ทธ๋ ์ฑ
์ ๋ค์ ธ์ ์์กด์ฑ์ ์ฃผ์
ํด๋ ์ ๋๋ก ์๋๋๊ฒ ํ๋ฐ์ด์๋๋ฐ ๊ฐ์ฌํ๊ฒ๋ ์์ ์ฐธ๊ณ ํ์ด์ง์ ๊ฒ์ํ ๋ธ๋ก๊ทธ์ ๋ฐฉ๋ฒ์ ๋ฐ๋ผํ๋ ํด๊ฒฐ๋์๋ค.

ํน์ compledQuerydsl์ ํ๋๋ฐ๋ Qํด๋์ค๋ค์ด ์๊ธฐ์ง ์๋๋ค๋ฉด ๊ทธ๋๋ค ์์ฒด๋ฅผ ๋ค์ ํ๋ฒ ๋ ๋น๋ํ๋ฉด ๋จ.

// ์์์ ๊ฒ ์ ์ฒด์กฐํ ๊ฒ์
public Map<String, Object> searchList(String spePart, String speFacility, LocalDateTime speStartDateTime,
LocalDateTime speEndDateTime, SpeStatus speComplete, String spePerson, String speEmpNum){
Map<String, Object> searchSpeList = new HashMap<>();
QSpecialInspection qSpecialInspection = QSpecialInspection.specialInspection;
BooleanBuilder builder = new BooleanBuilder();
if (spePart != null) {
builder.and(qSpecialInspection.spePart.eq(spePart));
}
if (speFacility != null) {
builder.and(qSpecialInspection.speFacility.eq(speFacility));
}
if (speStartDateTime != null && speEndDateTime != null) {
builder.and(qSpecialInspection.speDate.between(speStartDateTime, speEndDateTime));
}
if (speComplete != null) {
builder.and(qSpecialInspection.speComplete.eq(speComplete));
}
if (spePerson != null) {
builder.and(qSpecialInspection.spePerson.eq(spePerson));
}
if (speEmpNum != null) {
builder.and(qSpecialInspection.speEmpNum.eq(speEmpNum));
}
Sort sort = Sort.by(Sort.Direction.DESC, "speId");
List<SpecialInspection> searchSpeData = (List<SpecialInspection>) specialInspectionRepository.findAll(builder, sort);
List<SpeInsFormDTO> searchSpeDataDTOList = SpeInsFormDTO.of(searchSpeData);
searchSpeList.put("searchSpeDataDTOList", searchSpeDataDTOList);
return searchSpeList;
}
// ์์์ ๊ฒ ์ ์ฒดํํฉ ๊ฒ์
@GetMapping("/user/frequentinspection")
public ResponseEntity<?> speFullList(@RequestParam (value = "spePart", required = false) String spePart,
@RequestParam (value = "speFacility",required = false) String speFacility,
@RequestParam (value = "speStartDate",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate speStartDate,
@RequestParam (value = "speEndDate",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate speEndDate,
@RequestParam (value = "speComplete",required = false) SpeStatus speComplete,
@RequestParam (value = "spePerson",required = false) String spePerson,
@RequestParam (value = "speEmpNum",required = false) String speEmpNum
) {
Map<String, Object> responseData = new HashMap<>();
// ๋ ์ง ๋ณํ
LocalDateTime speStartDateTime = null;
LocalDateTime speEndDateTime = null;
if(speStartDate != null && speEndDate != null){
speStartDateTime = LocalDateTime.of(speStartDate, LocalTime.MIN);
speEndDateTime = LocalDateTime.of(speEndDate, LocalTime.MAX);
}
Map<String, Object> searchSpeList = specialInspectionService.searchList(spePart, speFacility, speStartDateTime, speEndDateTime, speComplete, spePerson, speEmpNum);
responseData.put("searchSpeList", searchSpeList);
Map<String, Object> searchPartAndFacList = specialInspectionService.getPartAndFacilityDataList();
responseData.put("searchPartAndFacList", searchPartAndFacList);
return new ResponseEntity<>(responseData, HttpStatus.OK);
}
์ฐ๋ฆฌ ๋๋น์ ๋ค์ด๊ฐ์๋ ๋ ์ง๋ LocalDateTime์ด์ด์ ํ๋ฉด์์๋ฐ์ LocalTime์ ๋ณํํด ์ค ํ์๊ฐ ์์ด์ ํด๋น ์ฝ๋ ์ถ๊ฐํ์ฌ ๋ณํํ ๋ค ๋๊ฒจ์ฃผ์๋ค.
์ฌ์ค ์ฟผ๋ฆฌ๋์์ ์ ํฐ ์ฅ์ ์
โ๏ธ ๋ฌธ์๊ฐ ์๋ (์๋ฐ)์ฝ๋๋ก ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ ์ ์์ด ์ปดํ์ผ ์์ ์ ๋ฌธ๋ฒ ์ค๋ฅ๋ฅผ ํ์ธํ ์ ์๋ค.
์ธ ๊ฒ ๊ฐ์๋ฐโฆ.. ๋ญ ์ด์จ๋ ๋๋ ๋ค์ค๊ฒ์์์ ๋์์ ๋ฐ์๋ค.