package com.jasamedika.medifirst2000.controller;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FilenameUtils;
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.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.entities.DokumenTemplate;
import com.jasamedika.medifirst2000.service.SuratMasukService;
import com.jasamedika.medifirst2000.util.StringUtil;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.DokumenTemplateVO;
import com.jasamedika.medifirst2000.vo.KirimDraftVO;
import com.jasamedika.medifirst2000.vo.SuratMasukDariExternalVO;
import com.jasamedika.medifirst2000.vo.SuratMasukInternalEksternalVO;
import com.jasamedika.medifirst2000.vo.SuratMasukKeEksternalVO;
import com.jasamedika.medifirst2000.vo.SuratMasukKeInternalVO;
import com.jasamedika.medifirst2000.vo.SuratMasukVO;
import com.jasamedika.medifirst2000.vo.VerbalKonsepVO;

@RestController
@RequestMapping("/surat-masuk")
public class SuratMasukController extends LocaleController<SuratMasukVO> {

	@Autowired
	private SuratMasukService service;

	private static final Logger LOGGER = LoggerFactory.getLogger(SuratMasukController.class);
	 
	//Adding by Lukman Hakim
	/*Function Name :
	 * Description : Upload Template Dokumen
	 * */
	@RequestMapping(value="/save-document-template", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> uploadTemplateSurat(
			@RequestBody DokumenTemplateVO dokumenTemplateVO,
			HttpServletRequest request) {
		String result = service.uploadDocumentTemplateSurat(dokumenTemplateVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}

	@RequestMapping(value="/download-dokumen-template/{id}", method = RequestMethod.GET)
    public void downloadFileDokumenTemplate(HttpServletResponse response, @PathVariable("id") Integer id) throws IOException {
		DokumenTemplate result= service.findById(id);
	    File file = new File(result.getFileLocation());
       System.out.println();
	    if(!file.exists()){
            String errorMessage = "Sorry. The file you are looking for does not exist";
            System.out.println(errorMessage);
            OutputStream outputStream = response.getOutputStream();
            outputStream.write(errorMessage.getBytes(Charset.forName("UTF-8")));
            outputStream.close();
            return;
        }
         
        String mimeType= URLConnection.guessContentTypeFromName(file.getName());
        if(mimeType==null){
            System.out.println("mimetype is not detectable, will take default");
            mimeType = "application/octet-stream";
        }
         
        System.out.println("mimetype : "+mimeType);
         
        response.setContentType(mimeType);
         
        /* "Content-Disposition : inline" will show viewable types [like images/text/pdf/anything viewable by browser] right on browser 
            while others(zip e.g) will be directly downloaded [may provide save as popup, based on your browser setting.]*/
        response.setHeader("Content-Disposition", String.format("inline; filename=\"" + result.getFileName() +"\""));
 
         
        /* "Content-Disposition : attachment" will be directly download, may provide save as popup, based on your browser setting*/
        //response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName()));
         
        response.setContentLength((int)file.length());
 
        InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
 
        //Copy bytes from source to destination(outputstream in this example), closes both streams.
        FileCopyUtils.copy(inputStream, response.getOutputStream());
    }
	@RequestMapping(value="/download-dokumen/{id}", method = RequestMethod.GET)
    public void downloadFileDokumen(HttpServletResponse response, @PathVariable("id") Integer id) throws IOException {
		Map<String,Object> result= service.findPathFileById(id);
	    File file = new File(result.get("pathFile").toString());
	    
	    
	    String fileName= result.get("namaJudulDokumen").toString()+"_"+StringUtil.formatNumber(result.get("noDokumen").toString(), 10)+"."+FilenameUtils.getExtension(result.get("pathFile").toString());
	    if(!file.exists()){
            String errorMessage = "Sorry. The file you are looking for does not exist";
            System.out.println(errorMessage);
            OutputStream outputStream = response.getOutputStream();
            outputStream.write(errorMessage.getBytes(Charset.forName("UTF-8")));
            outputStream.close();
            return;
        }
         
        String mimeType= URLConnection.guessContentTypeFromName(file.getName());
        if(mimeType==null){
            System.out.println("mimetype is not detectable, will take default");
            mimeType = "application/octet-stream";
        }
         
        System.out.println("mimetype : "+mimeType);
         
        response.setContentType(mimeType);
         
        /* "Content-Disposition : inline" will show viewable types [like images/text/pdf/anything viewable by browser] right on browser 
            while others(zip e.g) will be directly downloaded [may provide save as popup, based on your browser setting.]*/
        response.setHeader("Content-Disposition", String.format("inline; filename=\"" + fileName +"\""));
 
         
        /* "Content-Disposition : attachment" will be directly download, may provide save as popup, based on your browser setting*/
        //response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName()));
         
        response.setContentLength((int)file.length());
 
        InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
 
        //Copy bytes from source to destination(outputstream in this example), closes both streams.
        FileCopyUtils.copy(inputStream, response.getOutputStream());
    }
	@RequestMapping(value="/get-running-number/", method = RequestMethod.GET)
    public String getRunningNumber(HttpServletResponse response) throws IOException {
		String result= service.getRunningNumber();
		 return result;
    }
	@RequestMapping(value = "/daftar-dokumen-template", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public List<DokumenTemplate> getAllDokumenTemplate(
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
			@RequestParam(value = "sort", required = false, defaultValue = "namaSurat") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "dateStart", required = false) String dateStart,
			@RequestParam(value = "dateEnd", required = false) String dateEnd,
			@RequestParam(value = "id", required = false) Integer suratId) {
		List<DokumenTemplate> resultPageMap = service.getAllDokumenTemplate(page, limit, sort, dir, dateStart, dateEnd, suratId);

		return resultPageMap;
	}
	@RequestMapping(value="/save-draft-surat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveDraftSurat(
			@RequestBody DokumenTemplateVO dokumenTemplateVO,
			HttpServletRequest request) {
		
		String result = service.saveDraftSurat(dokumenTemplateVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value = "/get-draft-surat", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarDraftSuratByPeriode(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getAllDraftSuratByPeriode(dateStart, dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-draft-surat-by-ruangan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarDraftSuratByRuanganPeriode(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "idRuangan", required = true) Integer idRuangan,
			@RequestParam(value = "dateEnd", required = true) String dateEnd) {
		List<Map<String,Object>> resultPageMap = service.getAllDraftSuratByRuanganPeriode(dateStart, dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-draft-surat-by-ruangan-pembuat", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarDraftSuratByRuanganPeriode(
			@RequestParam(value = "idRuangan", required = true) Integer idRuangan
			) {
		List<Map<String,Object>> resultPageMap = service.getAllDraftSuratByRuangan(idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-draft-surat-by-id/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> getListDaftarDraftById(
			@PathVariable("id") Integer id) {
		Map<String,Object> resultPageMap = service.getDraftSuratById(id);
		List<Map<String,Object>> ruangans = service.findByDokumenTujuanByIdDokumen(id);
		resultPageMap.put("ruangans", ruangans);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	
	@RequestMapping(value="/save-kirim-draft-surat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> kirimDraftSurat(
			@RequestBody KirimDraftVO kirimDraftVO,
			HttpServletRequest request) {
		String result = service.saveKirimDraftSurat(kirimDraftVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	 
	@RequestMapping(value = "/get-draft-surat-by-id-and-ruangan/{id}/{idRuangan}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> getListDaftarDraftById(
			@PathVariable("id") Integer id,
			@PathVariable("idRuangan") Integer idRuangan) {
		Map<String,Object> resultPageMap = service.getDraftSuratByIdAndRuangan(id,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value="/save-draft-verbal-konsep", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveVerbalKonsep(
			@RequestBody VerbalKonsepVO verbalKonsepVO,
			HttpServletRequest request) {
		String result = service.saveVerbalKonsep(verbalKonsepVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value = "/get-verbal-konsep-by-id-dokumen/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> getVerbalKonsepByIdDokumen(
			@PathVariable("id") Integer id) {
		Map<String,Object> resultPageMap = service.getDraftSuratVerbalKonsepByIdDokumen(id);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	/* Function :
	 * Author :
	 * Description : Surat Masuk dari Eksternal
	 * */
	@RequestMapping(value="/save-surat-masuk-dari-external", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveSuratMasukDariExternal(
			@RequestBody SuratMasukDariExternalVO suratMasukDariExternalVO,
			HttpServletRequest request) {
		String result = service.saveSuratMasukDariExternal(suratMasukDariExternalVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
 
	@RequestMapping(value = "/get-surat-masuk-internal-eksternal-by-ruangan-periode/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarSuratMasukByRuangan(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getListDokumenMasukInternalExternal(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-surat-masuk-internal-eksternal-by-no-rec/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity< Map<String,Object>> getSuratMasukInternalEksternalBynoRec(
			 
			@RequestParam(value = "norec", required = false) String norec) {
		 Map<String,Object>  resultPageMap = service.getDokumenMasukInternalExternalBynoRec(norec);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-surat-masuk-internal-eksternal-by-id-dokumen/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity< Map<String,Object>> getSuratMasukInternalEksternalByidDokumen(
			 
			@RequestParam(value = "idDokumen", required = false) Integer idDokumen) {
		 Map<String,Object>  resultPageMap = service.getDokumenMasukInternalExternalByIdDokumen(idDokumen);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value="/save-kirim-distribusi-surat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> kirimDistribusiSurat(
			@RequestBody KirimDraftVO kirimDraftVO,
			HttpServletRequest request) {
		String result = service.saveKirimDistribusiSurat(kirimDraftVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value="/save-terima-surat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> terimaSuratMasuk(
			@RequestBody KirimDraftVO kirimDraftVO,
			HttpServletRequest request) {
		String result = service.saveTerimaSurat(kirimDraftVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	/*SURAT MASUK INTERNAL DAN EKSTERNAL*/
	@RequestMapping(value="/save-surat-masuk-to-internal-ekternal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> suratMasukKeInternalEksternal(
			@RequestBody SuratMasukInternalEksternalVO suratMasukInternalEksternalVO,
			HttpServletRequest request) {
		String result = service.saveSuratMasukKeInternalEksternal(suratMasukInternalEksternalVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value = "/get-surat-masuk-internal-eksternal-by-ruangan-periode-penomoran/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getAllSuratMasukPenomoranByPeriodeAndRuangan(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getAllSuratMasukPenomoranByPeriodeAndRuangan(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-daftar-distribusi-surat-by-ruangan-periode/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarDistribusiSurat(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getListDaftarDistribusiSurat(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	//Surat Masuk untuk penomoran
	@RequestMapping(value = "/get-surat-masuk-by-ruangan-periode-penomoran/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getAllSuratMasukPenomoranTatausahaByPeriodeAndRuangan(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getAllSuratMasukPenomoranByPeriodeAndRuanganTujuan(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-surat-masuk-internal-eksternal-penomoran-by-no-rec/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity< Map<String,Object>> getDokumenMasukKeluarBuatPenomoranByNoRec(
			 
			@RequestParam(value = "norec", required = false) String norec) {
		 Map<String,Object>  resultPageMap = service.getDokumenMasukKeluarBuatPenomoranByNoRec(norec);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	//Ruangan Tujuan Surat untuk didistribusikan
	@RequestMapping(value = "/get-daftar-distribusi-surat-by-ruangan-tujuan-periode/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListDaftarDistribusiSuratTujuan(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getListDaftarDistribusiSuratTujuan(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	
	@RequestMapping(value="/save-surat-masuk-ke-external-penomoran", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveSuratMasukKeExternalPenomoran(
			@RequestBody SuratMasukKeEksternalVO suratMasukKeEksternalVO,
			HttpServletRequest request) {
		String result = service.saveSuratMasukKeExternal(suratMasukKeEksternalVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value="/save-surat-masuk-ke-internal-penomoran", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveSuratMasukKeInternalPenomoran(
			@RequestBody SuratMasukKeInternalVO suratMasukKeInternalVO,
			HttpServletRequest request) {
		String result = service.saveSuratMasukKeInternal(suratMasukKeInternalVO);
		if (result != null) {
			if (!result.isEmpty()) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR, "Processing data error returns empty data");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		} else {
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}		
	}
	@RequestMapping(value = "/get-no-surat-ke-eksternal/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> getNoSuratKeEksternal(
			@RequestParam(value = "idUnitPemrakarsa", required = true) Integer idUnitPemrakarsa,
			@RequestParam(value = "idKlasifikasiArsip", required = true) Integer idKlasifikasiArsip,
			@RequestParam(value = "idSubKlasifikasiArsip", required = true) Integer idSubKlasifikasiArsip,
			@RequestParam(value = "tahun", required = false) Integer tahun) {
		String resultPageMap = service.getNoSuratKeEksternal(idUnitPemrakarsa,idKlasifikasiArsip,idSubKlasifikasiArsip,tahun);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-no-surat-ke-internal/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> getNoSuratKeInternal(
			@RequestParam(value = "idUnitPemrakarsa", required = true) Integer idUnitPemrakarsa,
			@RequestParam(value = "bulan", required = true) Integer bulan,
			@RequestParam(value = "tahun", required = false) Integer tahun) {
		String resultPageMap = service.getNoSuratKeInternal(idUnitPemrakarsa,bulan,tahun);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-daftar-surat-masuk-ke-eksternal/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListSuratMasukKeEksternal(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getListSuratMasukKeEksternal(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
	@RequestMapping(value = "/get-daftar-surat-masuk-jangka-waktu/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> getListSuratMasukJangkaWaktu(
			@RequestParam(value = "dateStart", required = true) String dateStart,
			@RequestParam(value = "dateEnd", required = true) String dateEnd,
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan) {
		List<Map<String,Object>> resultPageMap = service.getListSuratMasukJangkaWaktu(dateStart,dateEnd,idRuangan);
		 
		return RestUtil.getJsonResponse(resultPageMap, HttpStatus.OK, mapHeaderMessage);
	}
}
