package com.jasamedika.medifirst2000.controller; import com.jasamedika.medifirst2000.constants.Constants; import com.jasamedika.medifirst2000.constants.Master; import com.jasamedika.medifirst2000.constants.MessageResource; import com.jasamedika.medifirst2000.controller.base.LocaleController; import com.jasamedika.medifirst2000.core.web.WebConstants; import com.jasamedika.medifirst2000.dto.PegawaiJabatanDto; import com.jasamedika.medifirst2000.exception.ServiceVOException; import com.jasamedika.medifirst2000.service.MapPegawaiJabatanToUnitKerjaService; import com.jasamedika.medifirst2000.util.rest.RestUtil; import com.jasamedika.medifirst2000.vo.MapPegawaiJabatanToUnitKerjaVO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/map-pegawai-jabatan-unitkerja") public class MapPegawaiJabatanToUnitKerjaController extends LocaleController { @Autowired private MapPegawaiJabatanToUnitKerjaService mapPegawaiJabatanToUnitKerjaService; private static final Logger LOGGER = LoggerFactory.getLogger(MapPegawaiJabatanToUnitKerjaController.class); @RequestMapping(value = "/save-map", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> save(@Valid @RequestBody List vo, HttpServletRequest request) throws ParseException { try { Map result = mapPegawaiJabatanToUnitKerjaService.saveRev(vo); if (null != result && result.get("data").equals(Master.TIDAK_ADA_PERUBAHAN_DATA)) { mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS_OK, getMessage(MessageResource.LABEL_SUCCESS_OK, request)); return RestUtil.getJsonResponse(result, HttpStatus.NOT_MODIFIED, mapHeaderMessage); } else { mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); } } catch (ServiceVOException e) { LOGGER.error("Got exception {} when add mapping jabatan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when add mapping jabatan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/hapus-map", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> hapusMap(@Valid @RequestBody List vo, HttpServletRequest request) throws ParseException { Map mapHeaderMessage = new HashMap(); try { Map result = mapPegawaiJabatanToUnitKerjaService.save(vo); if (null != result) mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when add Map", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when add Map", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } /** * * API inisiasi awal jika data mapping sudah input tp histori belum, * dilakukan hanya satu kali */ @RequestMapping(value = "/get-all-map", method = RequestMethod.GET) public ResponseEntity> getAllMap(HttpServletRequest request) { Map result = null; try { result = mapPegawaiJabatanToUnitKerjaService.findAllMap(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); } catch (Exception e) { e.printStackTrace(); } return RestUtil.getJsonResponse(result, HttpStatus.OK); } @RequestMapping(value = "/get-map-by-pegawai/{id}", method = RequestMethod.GET) public ResponseEntity>> getMapByPegawai(@PathVariable("id") Integer id) { List> result = new ArrayList>(); try { result = mapPegawaiJabatanToUnitKerjaService.findAllDetailByPegawai(id); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get mapping jabatan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get mapping jabatan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-bawahan-level-jabatan", method = RequestMethod.GET) public ResponseEntity>> getBawahanByLevelJabatan(HttpServletRequest request, @RequestParam(value = "idPegawai", required = true) Integer idPegawai) { List> result = new ArrayList>(); try { result = mapPegawaiJabatanToUnitKerjaService.findAllDetailByLevelJabatan(idPegawai); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get bawahan by level jabatan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get bawahan by level jabatan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-undefined-bawahan", method = RequestMethod.GET) public ResponseEntity>> getUndefinedBawahan(HttpServletRequest request) { List> result = new ArrayList>(); try { result = mapPegawaiJabatanToUnitKerjaService.findAllUndefinedDetail(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get bawahan belum didefinisikan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get bawahan belum didefinisikan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-sub-unit-by-unit/{id}/{idUnit}", method = RequestMethod.GET) public ResponseEntity> getSubUnitByUnit(@PathVariable("id") Integer id, @PathVariable("idUnit") Integer idUnit) { return RestUtil.getJsonResponse(mapPegawaiJabatanToUnitKerjaService.findSubUnitByUnit(id, idUnit), HttpStatus.OK); } @RequestMapping(value = "/get-unit-by-pegawai/{id}", method = RequestMethod.GET) public ResponseEntity> getSubUnitByUnit(@PathVariable("id") Integer id) { return RestUtil.getJsonResponse(mapPegawaiJabatanToUnitKerjaService.findUnitByPgw(id), HttpStatus.OK); } @RequestMapping(value = "/get-unit-by-pegawai-jadwal/{id}", method = RequestMethod.GET) public ResponseEntity>> getSubUnitByUnitJadwal(@PathVariable("id") Integer id) { return RestUtil.getJsonResponse(mapPegawaiJabatanToUnitKerjaService.findUnitByPgwJadwal(id), HttpStatus.OK); } @RequestMapping(value = "/get-sub-unit-by-unit-jadwal/{id}/{idUnit}", method = RequestMethod.GET) public ResponseEntity>> getSubUnitByUnitJadwal(@PathVariable("id") Integer id, @PathVariable("idUnit") Integer idUnit) { return RestUtil.getJsonResponse(mapPegawaiJabatanToUnitKerjaService.findSubUnitByUnitJadwal(id, idUnit), HttpStatus.OK); } @RequestMapping(value = "/get-status-create-jadwal", method = RequestMethod.GET) public ResponseEntity> getStatusCreateJadwal( @RequestParam(value = "id", required = false) Integer id, HttpServletRequest request) { try { Map result = mapPegawaiJabatanToUnitKerjaService .getMapJabatanForMonitoringAbsensiByPegawai(id); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get status create jadwal", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get status create jadwal", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-drop-down-unit", method = RequestMethod.GET) public ResponseEntity> getDropDownUnitKerja( @RequestParam(value = "id", required = false) Integer id, HttpServletRequest request) { Map result = new HashMap<>(); try { result.put("data", mapPegawaiJabatanToUnitKerjaService.getMapUnitKerjaByPegawai(id)); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get drop down unit", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get drop down unit", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-drop-down-subunit", method = RequestMethod.GET) public ResponseEntity> getDropDownSubUnitKerja( @RequestParam(value = "id", required = false) Integer id, @RequestParam(value = "idUnit", required = false) Integer idUnit, HttpServletRequest request) { Map result = new HashMap<>(); try { result.put("data", mapPegawaiJabatanToUnitKerjaService.getMapSubunitKerjaByUnitPegawai(id, idUnit)); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get drop down subunit", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get drop down subunit", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/list-atasan-langsung-pegawai", method = RequestMethod.GET) public ResponseEntity> getAtasanLangsungPegawai( @RequestParam(value = "idPegawai", required = false) Integer idPegawai, HttpServletRequest request) { Map result = new HashMap<>(); try { result.put("data", mapPegawaiJabatanToUnitKerjaService.findAtasanLangsungPegawai(idPegawai)); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get drop down list atasan langsung", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get drop down list atasan langsung", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/list-pejabat-penilai-pegawai", method = RequestMethod.GET) public ResponseEntity> getAtasanPejabatPenilaiPegawai( @RequestParam(value = "idPegawai", required = false) Integer idPegawai, HttpServletRequest request) { Map result = new HashMap<>(); try { result.put("data", mapPegawaiJabatanToUnitKerjaService.findPejabatPenilaiPegawai(idPegawai)); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get drop down list atasan pejabat penilai", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get drop down list atasan pejabat penilai", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-formasi-jabatan", method = RequestMethod.GET) public ResponseEntity>> getFormasiJabatan(HttpServletRequest request) { List> result = new ArrayList>(); try { result = mapPegawaiJabatanToUnitKerjaService.findFormasiJabatan(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get formasi jabatan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get formasi jabatan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-jabatan-pegawai", method = RequestMethod.GET) public ResponseEntity>> getJabatanPegawai(HttpServletRequest request) { List> result = new ArrayList>(); try { result = mapPegawaiJabatanToUnitKerjaService.getJabatanPegawai(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get jabatan pegawai", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get jabatan pegawai", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-evaluasi-jabatan-pegawai-baru", method = RequestMethod.GET) public ResponseEntity> getEvaluasiJabatanPegawaiBaru( @RequestParam(value = "listJabatanId", required = false) List listIdJabatan, HttpServletRequest request) { Map result = new HashMap<>(); try { result.put("data", mapPegawaiJabatanToUnitKerjaService.getEvaluasiJabatanPegawaiBaru(listIdJabatan)); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get evaluasi jabatan pegawai baru", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get evaluasi jabatan pegawai baru", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/pegawai/{unitKerjaId}", method = RequestMethod.GET) public ResponseEntity>> getPegawaiByUnitKerja(@PathVariable Integer unitKerjaId, HttpServletRequest request) { try { List> result = mapPegawaiJabatanToUnitKerjaService .getlistPegawaiByUnitKerja(unitKerjaId); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when get jabatan pegawai", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when get jabatan pegawai", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/logbook-title/{idPegawai}", method = RequestMethod.GET) public ResponseEntity logbookTitle(@PathVariable("idPegawai") Integer idPegawai) { String jenisLogbook = mapPegawaiJabatanToUnitKerjaService.getJenisLogbook(idPegawai); return RestUtil.getJsonResponse(jenisLogbook, HttpStatus.OK); } @RequestMapping(value = "/jabatan/{idPegawai}", method = RequestMethod.GET) public ResponseEntity pegawaiJabatan(@PathVariable("idPegawai") Integer idPegawai) { PegawaiJabatanDto dataJabatan = mapPegawaiJabatanToUnitKerjaService.getDataJabatan(idPegawai); return RestUtil.getJsonResponse(dataJabatan, HttpStatus.OK); } }