하려고 하는 로직
select 를 해와서 해당하는 값이 있으면 그 값을 update 하는 것.
기존.
select를 하는 쿼리를 먼저 불러온다.
상태값이 C 인 데이터면 update를 한다.
변경된 쿼리.
서비스단도 변경했다.
public Map<String, Object> reservationTicketing(Map<String, Object> parameterMap) {
Map<String, Object> resultData = new LinkedHashMap<>();
String idkey = Optional.ofNullable(parameterMap.get("idkey")).map(s->(String)s).orElse("");
String gdSeq = Optional.ofNullable(parameterMap.get("gdSeq")).map(s->(String)s).orElse("");
String sdSeq = Optional.ofNullable(parameterMap.get("sdSeq")).map(s->(String)s).orElse("");
String singleInspectNo = Optional.ofNullable(parameterMap.get("singleInspectNo")).map(s->(String)s).orElse("");
String rsWinCd = Optional.ofNullable(parameterMap.get("rsWinCd")).map(s->(String)s).orElse("");
log.warn(">>>>>>>>>>>>> singleInspectNo :" + singleInspectNo.toString());
int singleInspectNoIDX = singleInspectNo.indexOf("-");
String rsSeqValue = singleInspectNo.substring(0, singleInspectNoIDX);
log.warn(">>>>>>>>>>>>> rsSeqValue :" + rsSeqValue.toString());
String rsSeq = Optional.ofNullable(parameterMap.put("rsSeq", rsSeqValue)).map(s->(String)s).orElse("");
//Map<String, Object> selectReservationTicketing = ticketingMapper.selectReservationTicketing(parameterMap);
//Map<String, Object> checkReservationTicketing = Optional.ofNullable(selectReservationTicketing).map(s->(Map<String, Object>)s).orElse(new HashMap<>());
int updateCnt = ticketingMapper.updateReservationTicketing(parameterMap);
if(updateCnt > 0) {
Map<String, Object> ticketingInfo = new HashMap<>();
ticketingInfo.put("ticketNumber", singleInspectNo); //RS000123-RD123-1 검표번호로 변경 시 rsSeq 이름 변경.
resultData.put("code","0000"); //0000 : 성공 , 0001 : 실패
resultData.put("message", "발권이 완료됐습니다.");
resultData.put("data", ticketingInfo);
}else{
resultData.put("code","0001"); //0000 : 성공 , 0001 : 실패
resultData.put("message", "발권을 실패했습니다.");
}
return resultData;
}
이전에는 컨트롤러에서 데이터를 내려줬다. (주석처리함.)
@RequestMapping(value = "/api/ticketing/reservationTicketing", method = RequestMethod.POST, headers="Accept=application/json", produces="application/json")
public ResponseEntity<?> reservationTicketing(@RequestBody Map<String,Object> parameterMap, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
/*Map<String, Object> resultData = new HashMap<>();
Map<String, Object> updateTicketings = ticketingService.reservationTicketing(parameterMap);
if(updateTicketings.size() > 0) {
resultData.put("code","0000"); //0000 : 성공 , 0001 : 실패
resultData.put("message", "발권이 완료됐습니다.");
}else{
resultData.put("code","0001"); //0000 : 성공 , 0001 : 실패
resultData.put("message", "업데이트 count : " + updateTicketings);
}*/
return new ResponseEntity<Map<String, Object>>(ticketingService.reservationTicketing(parameterMap), HttpStatus.OK);
}