Update service absensi pegawai
Penerapan MinIO untuk penyimpanan object storage presensi pegawai
This commit is contained in:
parent
4ef46784b9
commit
337c4309f1
@ -283,6 +283,25 @@
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<!-- End Lukman -->
|
||||
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.0-jre</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<organization>
|
||||
<name>Jasa Medika</name>
|
||||
|
||||
@ -11,21 +11,25 @@ import com.jasamedika.medifirst2000.entities.AbsensiPegawai;
|
||||
import com.jasamedika.medifirst2000.entities.Habsen;
|
||||
import com.jasamedika.medifirst2000.entities.JadwalDokter;
|
||||
import com.jasamedika.medifirst2000.entities.ShiftKerja;
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
import com.jasamedika.medifirst2000.service.AbsensiPegawaiService;
|
||||
import com.jasamedika.medifirst2000.service.LogAccService;
|
||||
import com.jasamedika.medifirst2000.util.CommonUtil;
|
||||
import com.jasamedika.medifirst2000.util.ImageUtil;
|
||||
import com.jasamedika.medifirst2000.util.minio.MinioClientUtil;
|
||||
import com.jasamedika.medifirst2000.vo.AbsensiPegawaiVO;
|
||||
import com.jasamedika.medifirst2000.vo.HabsenVO;
|
||||
import io.minio.PutObjectArgs;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -65,7 +69,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveAbsensiPegawai(AbsensiPegawaiVO vo) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
AbsensiPegawai model = new AbsensiPegawai();
|
||||
model = absensiPegawaiConverter.transferVOToModel(vo, model);
|
||||
|
||||
@ -92,13 +96,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
|
||||
@Override
|
||||
public Map<String, Object> findByName(String nama) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try {
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,7 +112,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveHabsensiPegawai(HabsenVO vo) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
Habsen model = presensiConverter.transferVOToModel(vo, new Habsen());
|
||||
|
||||
@ -125,7 +123,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
model.setRemoteno(Master.PresensiPegawai.SMART_REMOTE_NO);
|
||||
model.setAcc_code(Master.PresensiPegawai.DEFAULT_ACC_CODE);
|
||||
|
||||
/**
|
||||
/*
|
||||
* automatic reverse geocoding was disabled due to too many request to
|
||||
* nominatim.openstreetmap.org
|
||||
*/
|
||||
@ -169,28 +167,35 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
}
|
||||
|
||||
public void uploadPhotoCapture(String imageURLData, String idFinger, Date trDate, Date trTime, Integer trNo) {
|
||||
DateFormat mf = new SimpleDateFormat("yyyyMM");
|
||||
byte[] imageData = Base64.decodeBase64(imageURLData.substring(imageURLData.indexOf(",") + 1));
|
||||
if (trDate.after(new Date(MinioClientUtil.CUTOFF_TIMESTAMP))) {
|
||||
uploadToMinio(imageData, idFinger, trDate, trTime, trNo);
|
||||
} else {
|
||||
try {
|
||||
DateFormat mf = new SimpleDateFormat("yyyyMM");
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
DateFormat tf = new SimpleDateFormat("HH.mm.ss");
|
||||
String directory = getDirPathPresensiPegawai(mf.format(trDate));
|
||||
String filename = directory + idFinger + "_" + df.format(trDate) + "_" + tf.format(trTime) + "#" + trNo
|
||||
+ ".jpg";
|
||||
File outputFile = new File(filename);
|
||||
OutputStream stream = Files.newOutputStream(outputFile.toPath());
|
||||
stream.write(imageData);
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
throw new ServiceVOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadToMinio(byte[] imageData, String idFinger, Date trDate, Date trTime, Integer trNo) {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageData);
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
DateFormat tf = new SimpleDateFormat("HH.mm.ss");
|
||||
|
||||
String directory = getDirPathPresensiPegawai(mf.format(trDate));
|
||||
String filename = directory + idFinger.toString() + "_" + df.format(trDate) + "_" + tf.format(trTime) + "#"
|
||||
+ trNo + ".jpg";
|
||||
|
||||
String str = imageURLData;
|
||||
|
||||
byte[] imagedata = Base64.decodeBase64(str.substring(str.indexOf(",") + 1));
|
||||
try {
|
||||
File dire = new File(directory);
|
||||
if (!dire.exists())
|
||||
dire.mkdirs();
|
||||
File outputFile = new File(filename);
|
||||
OutputStream stream = new FileOutputStream(outputFile);
|
||||
stream.write(imagedata);
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String filename = idFinger + "_" + df.format(trDate) + "_" + tf.format(trTime) + "#" + trNo + ".jpg";
|
||||
PutObjectArgs objectArgs = PutObjectArgs.builder().bucket("presensi-pegawai").object(filename)
|
||||
.stream(inputStream, imageData.length, -1).contentType("image/jpeg").build();
|
||||
MinioClientUtil.upload(objectArgs);
|
||||
}
|
||||
|
||||
private Double getDecimal(Double n) {
|
||||
@ -207,13 +212,13 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
nf.setMaximumFractionDigits(2);
|
||||
String latSecStr = nf.format(getDecimal(getDecimal(Math.abs(latitude)) * 60) * 60);
|
||||
|
||||
String latStr = "";
|
||||
String latStr;
|
||||
if (latitude < 0) {
|
||||
latStr = latDegStr + "\u00B0" + latMinStr + "\u2032" + latSecStr + "\u2033 LS";
|
||||
latStr = latDegStr + "°" + latMinStr + "′" + latSecStr + "″ LS";
|
||||
} else if (latitude > 0) {
|
||||
latStr = latDegStr + "\u00B0" + latMinStr + "\u2032" + latSecStr + "\u2033 LU";
|
||||
latStr = latDegStr + "°" + latMinStr + "′" + latSecStr + "″ LU";
|
||||
} else {
|
||||
latStr = latDegStr + "\u00B0" + latMinStr + "\u2032" + latSecStr + "\u2033";
|
||||
latStr = latDegStr + "°" + latMinStr + "′" + latSecStr + "″";
|
||||
}
|
||||
|
||||
nf.setMaximumFractionDigits(0);
|
||||
@ -223,13 +228,13 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
nf.setMaximumFractionDigits(2);
|
||||
String longSecStr = nf.format(getDecimal(getDecimal(Math.abs(longitude)) * 60) * 60);
|
||||
|
||||
String longStr = "";
|
||||
String longStr;
|
||||
if (longitude < 0) {
|
||||
longStr = longDegStr + "\u00B0" + longMinStr + "\u2032" + longSecStr + "\u2033 BB";
|
||||
longStr = longDegStr + "°" + longMinStr + "′" + longSecStr + "″ BB";
|
||||
} else if (longitude > 0) {
|
||||
longStr = longDegStr + "\u00B0" + longMinStr + "\u2032" + longSecStr + "\u2033 BT";
|
||||
longStr = longDegStr + "°" + longMinStr + "′" + longSecStr + "″ BT";
|
||||
} else {
|
||||
longStr = longDegStr + "\u00B0" + longMinStr + "\u2032" + longSecStr + "\u2033";
|
||||
longStr = longDegStr + "°" + longMinStr + "′" + longSecStr + "″";
|
||||
}
|
||||
|
||||
return latStr + ", " + longStr;
|
||||
@ -298,7 +303,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
|
||||
@Override
|
||||
public Map<String, Object> findJadwalPegawai(Integer idPegawai) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Map<String, Object> result;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String today = sdf.format(new Date());
|
||||
result = habsensiDao.getPegawai(idPegawai);
|
||||
@ -332,7 +337,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> findHistoriPresensi(Integer idPegawai) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
List<Map<String, Object>> result;
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String today = sdf.format(new Date());
|
||||
@ -348,7 +353,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
} else {
|
||||
map.put("processtatus", "WFO");
|
||||
}
|
||||
if (vpnIPList.contains(map.get("ip_addr"))) {
|
||||
if (vpnIPList.contains(map.get("ip_addr").toString())) {
|
||||
boolean isAksesLuar = false;
|
||||
for (String vpnIPX : vpnIPXList)
|
||||
if (map.get("client_ip_addr").toString().startsWith(vpnIPX)) {
|
||||
@ -361,7 +366,7 @@ public class AbsensiPegawaiServiceImpl extends BaseVoServiceImpl implements Abse
|
||||
map.put("ip_addr", "menggunakan jaringan internet RSAB");
|
||||
|
||||
} else {
|
||||
if (listIp.contains(map.get("ip_addr"))) {
|
||||
if (listIp.contains(map.get("ip_addr").toString())) {
|
||||
map.put("ip_addr", "menggunakan jaringan internet RSAB");
|
||||
} else if (CommonUtil.isNullOrEmpty(map.get("ip_addr"))) {
|
||||
map.put("ip_addr", "jaringan internet tidak terdeteksi");
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.jasamedika.medifirst2000.util.minio;
|
||||
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectArgs;
|
||||
import io.minio.errors.MinioException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 20/11/2024
|
||||
*/
|
||||
public final class MinioClientUtil {
|
||||
|
||||
public static final long CUTOFF_TIMESTAMP = 1732035599000L;
|
||||
|
||||
public static void upload(PutObjectArgs objectArgs) {
|
||||
MinioClient minioClient;
|
||||
try {
|
||||
minioClient = MinioClientWrapper.minioClient();
|
||||
minioClient.putObject(objectArgs);
|
||||
} catch (IOException | MinioException | InvalidKeyException | NoSuchAlgorithmException e) {
|
||||
throw new ServiceVOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.jasamedika.medifirst2000.util.minio;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 19/11/2024
|
||||
*/
|
||||
public class MinioClientWrapper {
|
||||
|
||||
private static final String ENDPOINT = "https://minio-2.rsabhk.co.id:90";
|
||||
private static final String ACCESS_KEY = "6QLQ3GNgQFf2ax8PJXuu";
|
||||
private static final String SECRET_KEY = "nPrfuFezKLd36mI2qqGJ5djLiKxhNExIrPr3j4oq";
|
||||
|
||||
public static MinioClient minioClient() throws IOException {
|
||||
return MinioClient.builder().endpoint(ENDPOINT).credentials(ACCESS_KEY, SECRET_KEY).build();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user