Update LogAccService

Pembuatan service put data log ke db elasticsearch
This commit is contained in:
salmanoersabhk 2022-07-12 07:58:12 +07:00
parent eb475e66a8
commit 8a3b285e17
3 changed files with 88 additions and 19 deletions

View File

@ -1,11 +1,9 @@
package com.jasamedika.medifirst2000.service;
import java.util.Map;
import com.jasamedika.medifirst2000.vo.LogAccVO;
import com.jasamedika.medifirst2000.vo.HabsenVO;
public interface LogAccService {
Map<String,Object> saveLogAcc(LogAccVO vo);
void putToLog(HabsenVO vo);
}

View File

@ -1,31 +1,95 @@
package com.jasamedika.medifirst2000.service.impl;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.LogAccDao;
import com.jasamedika.medifirst2000.entities.LogAcc;
import com.jasamedika.medifirst2000.service.LogAccService;
import com.jasamedika.medifirst2000.vo.LogAccVO;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.HabsenVO;
@Service("logAccService")
public class LogAccServiceImpl extends BaseVoServiceImpl implements LogAccService{
public class LogAccServiceImpl extends BaseVoServiceImpl implements LogAccService {
@Autowired
private BaseConverterImpl<LogAccVO, LogAcc> logAccConverter;
public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
Map<String, Object> retMap = new HashMap<String, Object>();
@Autowired
private LogAccDao logAccDao;
if (CommonUtil.isNotNullOrEmpty(json)) {
retMap = toMap(json);
}
return retMap;
}
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap<String, Object>();
Iterator<?> keysItr = object.keys();
while (keysItr.hasNext()) {
String key = keysItr.next().toString();
Object value = object.get(key);
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
} else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
map.put(key, value);
}
return map;
}
public static List<Object> toList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
Object value = array.get(i);
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
} else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
list.add(value);
}
return list;
}
@Override
public Map<String, Object> saveLogAcc(LogAccVO vo) {
Map<String, Object> result = new HashMap<String, Object>();
return result;
public void putToLog(HabsenVO vo) {
try {
URL url = new URL("http://172.16.55.22:38080/logs/absensi");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("PUT");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setDoInput(true);
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
String jsonOutputString = "{\"tr_no\":\"" + vo.getTr_no() + "\",\"empl_code\":" + vo.getEmpl_code()
+ ",\"ip_addr\":" + vo.getIp_addr() + ",\"client_ip_addr\":" + vo.getClientIPAddress() + "\"}";
byte[] requestBody = jsonOutputString.getBytes("UTF-8");
os.write(requestBody, 0, requestBody.length);
InputStream in = new BufferedInputStream(con.getInputStream());
os.close();
in.close();
con.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -78,6 +78,7 @@ import com.jasamedika.medifirst2000.service.KategoryTugasService;
import com.jasamedika.medifirst2000.service.KedudukanService;
import com.jasamedika.medifirst2000.service.KelompokKompetensiService;
import com.jasamedika.medifirst2000.service.KompetensiService;
import com.jasamedika.medifirst2000.service.LogAccService;
import com.jasamedika.medifirst2000.service.MapJabatanProfesiService;
import com.jasamedika.medifirst2000.service.MappingPegawaiToAtasanService;
import com.jasamedika.medifirst2000.service.MasterEvaluasiJabatanService;
@ -427,6 +428,9 @@ public class SdmController extends LocaleController<AkunVO> {
@Autowired
private ProfesiService profesiService;
@Autowired
private LogAccService logService;
@RequestMapping(value = "/save-custom-uraian-kerja", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> saveBerkasLamaran(@Valid @RequestBody CustomIndexKerjaVO vo,
HttpServletRequest request) throws ParseException {
@ -5612,9 +5616,12 @@ public class SdmController extends LocaleController<AkunVO> {
vo.setClientIPAddress(getClientIpAddress(request));
Map<String, Object> result = absensiPegawaiService.saveHabsensiPegawai(vo);
if (null != result)
if (null != result) {
logService.putToLog(vo);
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 save presensi pegawai", e.getMessage());