Update LogAccService
Pembuatan service put data log ke db elasticsearch
This commit is contained in:
parent
eb475e66a8
commit
8a3b285e17
@ -1,11 +1,9 @@
|
|||||||
package com.jasamedika.medifirst2000.service;
|
package com.jasamedika.medifirst2000.service;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.jasamedika.medifirst2000.vo.HabsenVO;
|
||||||
|
|
||||||
import com.jasamedika.medifirst2000.vo.LogAccVO;
|
|
||||||
|
|
||||||
public interface LogAccService {
|
public interface LogAccService {
|
||||||
|
|
||||||
Map<String,Object> saveLogAcc(LogAccVO vo);
|
void putToLog(HabsenVO vo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,31 +1,95 @@
|
|||||||
package com.jasamedika.medifirst2000.service.impl;
|
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.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
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 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.service.LogAccService;
|
||||||
import com.jasamedika.medifirst2000.vo.LogAccVO;
|
import com.jasamedika.medifirst2000.util.CommonUtil;
|
||||||
|
import com.jasamedika.medifirst2000.vo.HabsenVO;
|
||||||
|
|
||||||
@Service("logAccService")
|
@Service("logAccService")
|
||||||
public class LogAccServiceImpl extends BaseVoServiceImpl implements LogAccService{
|
public class LogAccServiceImpl extends BaseVoServiceImpl implements LogAccService {
|
||||||
|
|
||||||
@Autowired
|
public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
|
||||||
private BaseConverterImpl<LogAccVO, LogAcc> logAccConverter;
|
Map<String, Object> retMap = new HashMap<String, Object>();
|
||||||
|
|
||||||
@Autowired
|
if (CommonUtil.isNotNullOrEmpty(json)) {
|
||||||
private LogAccDao logAccDao;
|
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
|
@Override
|
||||||
public Map<String, Object> saveLogAcc(LogAccVO vo) {
|
public void putToLog(HabsenVO vo) {
|
||||||
Map<String, Object> result = new HashMap<String, Object>();
|
try {
|
||||||
|
URL url = new URL("http://172.16.55.22:38080/logs/absensi");
|
||||||
return result;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,7 @@ import com.jasamedika.medifirst2000.service.KategoryTugasService;
|
|||||||
import com.jasamedika.medifirst2000.service.KedudukanService;
|
import com.jasamedika.medifirst2000.service.KedudukanService;
|
||||||
import com.jasamedika.medifirst2000.service.KelompokKompetensiService;
|
import com.jasamedika.medifirst2000.service.KelompokKompetensiService;
|
||||||
import com.jasamedika.medifirst2000.service.KompetensiService;
|
import com.jasamedika.medifirst2000.service.KompetensiService;
|
||||||
|
import com.jasamedika.medifirst2000.service.LogAccService;
|
||||||
import com.jasamedika.medifirst2000.service.MapJabatanProfesiService;
|
import com.jasamedika.medifirst2000.service.MapJabatanProfesiService;
|
||||||
import com.jasamedika.medifirst2000.service.MappingPegawaiToAtasanService;
|
import com.jasamedika.medifirst2000.service.MappingPegawaiToAtasanService;
|
||||||
import com.jasamedika.medifirst2000.service.MasterEvaluasiJabatanService;
|
import com.jasamedika.medifirst2000.service.MasterEvaluasiJabatanService;
|
||||||
@ -427,6 +428,9 @@ public class SdmController extends LocaleController<AkunVO> {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProfesiService profesiService;
|
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)
|
@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,
|
public ResponseEntity<Map<String, Object>> saveBerkasLamaran(@Valid @RequestBody CustomIndexKerjaVO vo,
|
||||||
HttpServletRequest request) throws ParseException {
|
HttpServletRequest request) throws ParseException {
|
||||||
@ -5612,9 +5616,12 @@ public class SdmController extends LocaleController<AkunVO> {
|
|||||||
vo.setClientIPAddress(getClientIpAddress(request));
|
vo.setClientIPAddress(getClientIpAddress(request));
|
||||||
|
|
||||||
Map<String, Object> result = absensiPegawaiService.saveHabsensiPegawai(vo);
|
Map<String, Object> result = absensiPegawaiService.saveHabsensiPegawai(vo);
|
||||||
if (null != result)
|
if (null != result) {
|
||||||
|
logService.putToLog(vo);
|
||||||
|
|
||||||
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
|
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
|
||||||
getMessage(MessageResource.LABEL_SUCCESS, request));
|
getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||||
|
}
|
||||||
return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
|
return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
|
||||||
} catch (ServiceVOException e) {
|
} catch (ServiceVOException e) {
|
||||||
LOGGER.error("Got exception {} when save presensi pegawai", e.getMessage());
|
LOGGER.error("Got exception {} when save presensi pegawai", e.getMessage());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user