package com.jasamedika.medifirst2000.controller; import com.jasamedika.medifirst2000.constants.MessageResource; import com.jasamedika.medifirst2000.controller.base.LocaleController; import com.jasamedika.medifirst2000.exception.ServiceVOException; import com.jasamedika.medifirst2000.service.IpsrsPemakaianMesinService; import com.jasamedika.medifirst2000.vo.IpsrsPemakaianMesinVO; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.util.Map; import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; import static org.slf4j.LoggerFactory.getLogger; import static org.springframework.http.HttpStatus.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.web.bind.annotation.RequestMethod.GET; import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/ipsrs-pemakaian-mesin") public class IpsrsPemakaianMesinController extends LocaleController { private static final Logger LOGGER = getLogger(IpsrsPemakaianMesinController.class); @Autowired private IpsrsPemakaianMesinService service; @RequestMapping(value = "/get-login-user/", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getLoginUser(HttpServletRequest request) { try { Map result = service.getUserLogin(); if (null != result) { mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, OK, mapHeaderMessage); } else { return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when getUserLogin", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when getUserLogin", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-jenis-mesin", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getJenisMesin(HttpServletRequest request) { try { Map result = service.getJenisMesin(); if (null != result) { mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, OK, mapHeaderMessage); } else { return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when getJenisMesin", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when getJenisMesin", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-data-mesin", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getDataMesin(@RequestParam(value = "id") Integer id, HttpServletRequest request) { try { Map result = service.getDataMesin(id); if (null != result) { mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, OK, mapHeaderMessage); } else { return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when getDataMesin", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when getDataMesin", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-all-pemakaian-boiler", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getAllPemakaianBoiler(HttpServletRequest request) { try { Map result = service.getAllPemakaianBoiler(); if (null != result) { mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, OK, mapHeaderMessage); } else { return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when getAllPemakaianBoiler", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when getAllPemakaianBoiler", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-all-pemakaian-genset", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getAllPemakaianGenset(HttpServletRequest request) { try { Map result = service.getAllPemakaianGenset(); if (null != result) { mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, OK, mapHeaderMessage); } else { return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when getAllPemakaianGenset", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when getAllPemakaianGenset", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/save-pemakaian-mesin", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) public ResponseEntity> savePemakaianMesin(@Valid @RequestBody IpsrsPemakaianMesinVO vo, HttpServletRequest request) { try { Map result = service.savePemakaianMesin(vo); if (null != result) mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when savePemakaianMesin", e.getMessage()); addHeaderMessage(ERROR_MESSAGE, e.getMessage()); return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when savePemakaianMesin", jse.getMessage()); addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/pemakaian-mesin-boiler") public Map pemakaianMesinBoiler( @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "take", required = false, defaultValue = "100") Integer limit, @RequestParam(value = "sort", required = false, defaultValue = "noRec") String sort, @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir, @RequestParam(value = "tanggalAwal", required = false) String tanggalAwal, @RequestParam(value = "tanggalAhir", required = false) String tanggalAhir) { return service.pemakaianBoiler(page, limit, sort, dir, tanggalAwal, tanggalAhir); } @RequestMapping(value = "/pemakaian-mesin-genset") public Map pemakaianMesinGenset( @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "take", required = false, defaultValue = "100") Integer limit, @RequestParam(value = "sort", required = false, defaultValue = "noRec") String sort, @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir, @RequestParam(value = "tanggalAwal", required = false) String tanggalAwal, @RequestParam(value = "tanggalAhir", required = false) String tanggalAhir) { return service.pemakaianGenset(page, limit, sort, dir, tanggalAwal, tanggalAhir); } }