inisialisasi kembali

This commit is contained in:
tias
2024-06-15 17:04:28 +07:00
parent 3e97011f66
commit 0f99b87e47
151 changed files with 9074 additions and 224 deletions

View File

@@ -0,0 +1,9 @@
package org.sadigit.repository.entity.auth;
import org.sadigit.entity.AppUser;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
public interface AuthRepository extends PanacheRepository<AppUser> {
}

View File

@@ -0,0 +1,147 @@
package org.sadigit.repository.entity.auth;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class AuthRepositoryImpl implements AuthRepository {
// @Inject
// Session session;
// Long idRegu;
// @Transactional
// public AppUserDTO sign(AuthCmd cmd) {
// String username = cmd.username();
// String password = cmd.password();
// try {
// String hashed = hashToMD5(password);
// AppUser entity = AppUser
// .find("select a from AppUser a WHERE username = ?1 and password = ?2 and isActive =?3",
// username,
// hashed, "1")
// .singleResult();
// if (entity == null) {
// return new AppUserDTO(false, "Username or password is incorrect", null);
// } else {
// Regional regional = entity.getRegional();
// Posko posko = entity.getPosko();
// Uid uid = entity.getUid();
// Ulp ulp = entity.getUlp();
// Up3 up3 = entity.getUp3();
// Integer level = 0;
// if (posko != null && ulp == null && up3 == null && uid == null && regional == null) {
// level = 5;
// } else if (posko == null && ulp != null && up3 == null && uid == null && regional == null) {
// level = 4;
// } else if (posko == null && ulp == null && up3 != null && uid == null && regional == null) {
// level = 3;
// } else if (posko == null && ulp == null && up3 == null && uid != null && regional == null) {
// level = 2;
// } else if (posko == null && ulp == null && up3 == null && uid == null && regional != null) {
// level = 1;
// }
// if (level == 5) {
// System.out.println("Level 5");
// posko = entity.getPosko();
// ulp = entity.getPosko().getUlp();
// up3 = entity.getPosko().getUlp().getUp3();
// uid = entity.getPosko().getUlp().getUp3().getUid();
// regional = entity.getPosko().getUlp().getUp3().getUid().getRegional();
// } else if (level == 4) {
// System.out.println("Level 4");
// posko = new Posko();
// posko.setId(0L);
// posko.setNama("");
// ulp = entity.getUlp();
// up3 = entity.getUlp().getUp3();
// uid = entity.getUlp().getUp3().getUid();
// regional = entity.getUlp().getUp3().getUid().getRegional();
// } else if (level == 3) {
// System.out.println("Level 3");
// posko = new Posko();
// posko.setId(0L);
// posko.setNama("");
// ulp = new Ulp();
// ulp.setId(0L);
// ulp.setNama("");
// up3 = entity.getUp3();
// uid = entity.getUp3().getUid();
// regional = entity.getUp3().getUid().getRegional();
// } else if (level == 2) {
// System.out.println("Level 2");
// posko = new Posko();
// posko.setId(0L);
// posko.setNama("");
// ulp = new Ulp();
// ulp.setId(0L);
// ulp.setNama("");
// up3 = new Up3();
// up3.setId(0L);
// up3.setNama("");
// uid = entity.getUid();
// regional = entity.getUid().getRegional();
// } else if (level == 1) {
// System.out.println("Level 1");
// posko = new Posko();
// posko.setId(0L);
// posko.setNama("");
// ulp = new Ulp();
// ulp.setId(0L);
// ulp.setNama("");
// up3 = new Up3();
// up3.setId(0L);
// up3.setNama("");
// uid = new Uid();
// uid.setId(0L);
// uid.setNama("");
// regional = entity.getRegional();
// }
// AppUser.update("isLogin", 1);
// UserDTO userDTO = new UserDTO(entity.getUserId(),
// entity.getUsername(), entity.getEmployeeName(),
// entity.getNip(), entity.getAddress(),
// entity.getPhone(), entity.getMobile(),
// entity.getEmail(),
// entity.getPosition().getNama(), entity.getUnitId(),
// entity.getIsActive(), entity.getPicture(),
// null,
// posko.getId(), posko.getNama(),
// up3.getId(), up3.getNama(),
// uid.getId(), uid.getNama(),
// ulp.getId(), ulp.getNama(),
// regional.getId(), regional.getNama());
// return new AppUserDTO(true, "Login success", userDTO);
// }
// } catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// System.out.println("Error: " + e.getMessage());
// return new AppUserDTO(false, "Error: " + e.getMessage(), null);
// }
// }
// public String hashToMD5(String password) throws NoSuchAlgorithmException {
// try {
// MessageDigest md = MessageDigest.getInstance("MD5");
// // Update message digest with input string
// md.update(password.getBytes());
// // Generate MD5 hash bytes
// byte[] hashBytes = md.digest();
// // Encode MD5 hash bytes to Base64
// String base64Hash = Base64.getEncoder().encodeToString(hashBytes);
// return base64Hash;
// } catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// return null;
// }
// }
}

View File

@@ -0,0 +1,24 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.Data;
import java.util.List;
import org.sadigit.entity.referensi.Material;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@Data
@ApplicationScoped
public class MaterialRepository implements PanacheRepository<Material> {
public List<Material> findAllMaterial() {
return Material.listAll();
}
public List<Material> findMaterialByPoskoId(Long poskoId) {
return Material.find("posko.id", poskoId).list();
}
}

View File

@@ -0,0 +1,17 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.referensi.Posko;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class PoskoRepository implements PanacheRepository<Posko> {
public List<Posko> findByIdUp3(Long idup3) {
return this.find("SELECT p.id,p.nama FROM Posko p WHERE p.ulp.idUp3 = ?1", idup3).list();
}
}

View File

@@ -0,0 +1,18 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.referensi.Pulau;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class PulauRepository implements PanacheRepository<Pulau> {
public List<Pulau> findAllPulau() {
return this.listAll();
}
}

View File

@@ -0,0 +1,17 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.Data;
import java.util.List;
import org.sadigit.entity.referensi.Regional;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@Data
@ApplicationScoped
public class RegionalRepository implements PanacheRepository<Regional> {
public List<Regional> findAllRegional() {
return this.listAll();
}
}

View File

@@ -0,0 +1,15 @@
package org.sadigit.repository.entity.referensi;
import java.util.List;
import org.sadigit.entity.referensi.SubFasilitas;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class SubFasilitasRepository implements PanacheRepository<SubFasilitas> {
public List<SubFasilitas> findSubFasilitasByFasilitasId(Long fasilitasId) {
return SubFasilitas.find("fasilitas.id", fasilitasId).list();
}
}

View File

@@ -0,0 +1,16 @@
package org.sadigit.repository.entity.referensi;
import java.util.List;
import org.sadigit.entity.referensi.Kelompok;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class SubKelompokRepository implements PanacheRepository<Kelompok> {
public List<Kelompok> findSubKelompokByIdKelompok(Long id_kelompok) {
return Kelompok.find("id_kelompok", id_kelompok).firstResult();
}
}

View File

@@ -0,0 +1,16 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.referensi.SubTipeKeluhan;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class SubTipeKeluhanRepository implements PanacheRepository<SubTipeKeluhan> {
public List<SubTipeKeluhan> getSubTipeKeluhanByTipeKeluhanId(Long issuedtypeid) {
return list("tipeKeluhan.issuetypeid", issuedtypeid);
}
}

View File

@@ -0,0 +1,23 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.Data;
import java.util.List;
import org.sadigit.entity.referensi.Uid;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@Data
@ApplicationScoped
public class UidRepository implements PanacheRepository<Uid>{
public List<Uid> findAllUid() {
return Uid.listAll();
}
public List<Uid> findByIdPulau(Long pulauId) {
return Uid.find("idPulau", pulauId).list();
}
}

View File

@@ -0,0 +1,17 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.referensi.Ulp;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class UlpRepository implements PanacheRepository<Ulp>{
public List<Ulp> findUlpByUp3(Long id_up3) {
return Ulp.find("idUp3", id_up3).list();
}
}

View File

@@ -0,0 +1,17 @@
package org.sadigit.repository.entity.referensi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.referensi.Up3;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class Up3Repository implements PanacheRepository<Up3>{
public List<Up3> findUp3ByUid(Long uid) {
return this.find("idUid", uid).list();
}
}

View File

@@ -0,0 +1,29 @@
package org.sadigit.repository.entity.saidisaifi.masterjaringan;
import java.util.List;
import org.sadigit.entity.referensi.SystemParameter;
import org.sadigit.entity.saidisaifi.masterJaringan.MasterGarduDistribusi;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class MasterGarduDistribusiRepository implements PanacheRepository<MasterGarduDistribusi>{
@SuppressWarnings("unchecked")
public List<MasterGarduDistribusi> findByGeomRadius(Double longitude, Double latitude) {
String nativeQuery = """
select *
from master_gardu_distribusi
where ST_DWithin(point\\:\\:geography, ST_SetSRID(POINT(:longitude :latitude)),4326)\\::geography, :radius)
where
""";
SystemParameter systemParameter = SystemParameter.find("id", 78).firstResult();
return this.getEntityManager().createNativeQuery(nativeQuery, MasterGarduDistribusi.class)
.setParameter("longitude", longitude)
.setParameter("latitude", latitude)
.setParameter("radius", systemParameter.getValue())
.getResultList();
}
}

View File

@@ -0,0 +1,17 @@
package org.sadigit.repository.entity.transaksi;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import org.sadigit.entity.transaksi.GangguanFoto;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class GangguanFotoRepository implements PanacheRepository<GangguanFoto> {
public List<GangguanFoto> getGangguanFotoByNoLaporan(String noLaporan) {
return this.find("gangguan.no_laporan", noLaporan).list();
}
}

View File

@@ -0,0 +1,297 @@
package org.sadigit.repository.entity.transaksi;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.sadigit.control.exception.CustomException;
import org.sadigit.model.request.CreateGangguanRequest;
import org.sadigit.model.request.CreateGangguanV2Request;
import org.sadigit.model.response.CreateGangguanResponse;
import org.sadigit.model.response.base.ResponseModel;
import org.sadigit.entity.masterYantek.Unit;
import org.sadigit.entity.referensi.MasterKelurahan;
import org.sadigit.entity.referensi.Media;
import org.sadigit.entity.referensi.TipePermasalahan;
import org.sadigit.entity.referensi.Uid;
import org.sadigit.entity.transaksi.Gangguan;
import org.sadigit.entity.transaksi.GangguanLaporUlang;
import org.sadigit.entity.transaksi.GangguanTransaksi;
import org.sadigit.utils.GeomUtils;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class GangguanRepository implements PanacheRepository<Gangguan> {
@Inject
Session session;
private String generateNoLaporan(Long id_uid) {
// select unitcode from unit
Unit unit = Unit.find("unitid", id_uid).firstResult();
if (unit == null) {
throw new CustomException("Unit tidak ditemukan");
}
String unitCode = unit.getUnitcode();
String noLaporan = "";
String prefix = "G";
Gangguan gangguan = Gangguan.find("unit =?1 and date(created_date)=?2 order by created_date desc", id_uid, LocalDate.now())
.firstResult();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
if (gangguan != null) {
String lastNoLaporan = gangguan.getNo_laporan();
String currentDate = LocalDate.now().format(formatter);
String lastNoLaporanNumber = lastNoLaporan.substring(lastNoLaporan.length() - 4);
int lastNoLaporanNumberInt = Integer.parseInt(lastNoLaporanNumber);
int newNoLaporanNumber = lastNoLaporanNumberInt + 1;
String newNoLaporanNumberString = String.format("%05d", newNoLaporanNumber);
noLaporan = prefix + unitCode + currentDate + newNoLaporanNumberString;
System.out.println("Generated no laporan: " + noLaporan);
return noLaporan;
} else {
LocalDate date = LocalDate.now(); // Get current date directly
System.out.println("Parsed date: " + date);
// Format the LocalDate object to a string using the formatter
String formattedDate = date.format(formatter);
System.out.println("Formatted date: " + formattedDate);
noLaporan = prefix + unitCode + formattedDate + "0001";
System.out.println("Generated no laporan: " + noLaporan);
return noLaporan;
}
}
@Transactional
public CreateGangguanResponse create(CreateGangguanRequest prmt) {
if (prmt.getIn_idpel() != null) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime earlier = now.minusHours(3);
Gangguan gangguanExist = Gangguan.find("id_pelanggan_no_meter = ?1 and created_date between ?2 and ?3", prmt.getIn_idpel(), earlier, now).firstResult();
if (gangguanExist != null) {
var error = ResponseModel.builder()
.data(Map.of("msg", "Pengaduan anda sedang di proses. Anda dapat melakukan pengaduan ulang, 3 jam dari pengaduan sebelumnya."))
.build();
throw new CustomException(null, error);
}
}
try {
int sourceSrid = 4326;
Gangguan gangguan = new Gangguan();
Media media = Media.findById(10);
GangguanTransaksi gangguanTransaksi = new GangguanTransaksi();
String noLaporan = "";
Point point = null;
try {
point = GeomUtils.wktToPoint(prmt.getIn_long(), prmt.getIn_lat(), sourceSrid);
} catch (ParseException e) {
throw new CustomException("Invalid WKT format: " + e.getMessage());
}
MasterKelurahan kelurahan = MasterKelurahan.find("nama_kelurahan", prmt.getIn_kel()).firstResult();
TipePermasalahan tipePermasalahan = TipePermasalahan.findById(Long.valueOf(prmt.getIn_tipe_keluhan()));
Uid uid = Uid.findById(prmt.getIn_unitup());
if (uid == null) {
throw new CustomException("Unit tidak ditemukan");
}
if (tipePermasalahan == null) {
throw new CustomException("Tipe Permasalahan tidak ditemukan");
}
if (prmt.getIn_kel() != null && kelurahan == null) {
throw new CustomException("Kelurahan tidak ditemukan");
}
if (prmt.getIn_idpel() != null) {
gangguan.setId_pelanggan_no_meter(Long.valueOf(prmt.getIn_idpel()));
}
gangguan.setTipePermasalahan(tipePermasalahan);
gangguan.setMaster_kelurahan(kelurahan);
noLaporan = generateNoLaporan(Long.valueOf(prmt.getIn_unitup()));
gangguan.setNo_laporan(noLaporan);
gangguan.setNama_pelapor(prmt.getIn_nama());
gangguan.setTelepon_pelapor(prmt.getIn_hp());
gangguan.setHp_pelapor(prmt.getIn_hp());
gangguan.setAlamat_pelapor(prmt.getIn_alamat());
gangguan.setMedia(media.getKeterangan());
gangguan.setWaktu_lapor(LocalDateTime.now());
gangguan.setLokasi(point);
gangguan.setKeterangan(prmt.getIn_keterangan());
gangguan.setCreated_date(LocalDateTime.now());
gangguan.setCreated_by(99999L);
gangguan.setStatus_akhir("lapor");
gangguan.setUnit(Long.valueOf(prmt.getIn_unitup()));
gangguan.setPermasalahan(tipePermasalahan.getNama());
gangguan.setCreated_date(LocalDateTime.now());
gangguan.persist();
gangguanTransaksi.setGangguan(gangguan);
gangguanTransaksi.setJenis("lapor");
gangguanTransaksi.setWaktu(LocalDateTime.now());
gangguanTransaksi.setCreated_date(LocalDateTime.now());
gangguanTransaksi.setCreated_by(99999L);
GangguanTransaksi.persist(gangguanTransaksi);
if (!isPersistent(gangguan)) {
Gangguan.delete("no_laporan", gangguan.getNo_laporan());
throw new CustomException("Gangguan tidak berhasil disimpan");
}
return new CreateGangguanResponse(noLaporan);
} catch (HibernateException e) {
throw new CustomException("Terjadi kesalahan dalam proses menyimpan data : " + e.getMessage());
}
}
public CreateGangguanResponse createV2(CreateGangguanV2Request prmt) {
if (prmt.getIn_idpel() != null) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime earlier = now.minusHours(3);
Gangguan gangguanExist = Gangguan.find("id_pelanggan_no_meter = ?1 and created_date between ?2 and ?3", prmt.getIn_idpel(), earlier, now).firstResult();
if (gangguanExist != null) {
var error = ResponseModel.builder()
.data(Map.of(
"msg", "Pengaduan anda sedang di proses. Anda dapat melakukan pengaduan ulang, 3 jam dari pengaduan sebelumnya.",
"result", "0"
))
.build();
throw new CustomException(null, error);
}
}
try {
int sourceSrid = 4326;
Gangguan gangguan = new Gangguan();
Media media = Media.findById(10);
GangguanTransaksi gangguanTransaksi = new GangguanTransaksi();
String noLaporan = "";
try {
Point point = GeomUtils.wktToPoint(prmt.getIn_long(), prmt.getIn_lat(), sourceSrid);
MasterKelurahan kelurahan = MasterKelurahan.find("nama_kelurahan", prmt.getIn_kel()).firstResult();
TipePermasalahan tipePermasalahan = TipePermasalahan.findById(Long.valueOf(prmt.getIn_tipe_keluhan()));
noLaporan = generateNoLaporan(Long.valueOf(prmt.getIn_unitup()));
Uid uid = Uid.findById(prmt.getIn_unitup());
if (uid == null) {
throw new CustomException("Unit tidak ditemukan");
}
if (tipePermasalahan == null) {
throw new CustomException("Tipe Permasalahan tidak ditemukan");
}
if (kelurahan == null) {
throw new CustomException("Kelurahan tidak ditemukan");
}
if (prmt.getIn_idpel() != null) {
gangguan.setId_pelanggan_no_meter(Long.valueOf(prmt.getIn_idpel()));
}
gangguan.setTipePermasalahan(tipePermasalahan);
gangguan.setMaster_kelurahan(kelurahan);
if (prmt.getIn_laporanulang_ref() != null) {
Gangguan gangguanExist = Gangguan.find("no_laporan = ?1", prmt.getIn_laporanulang_ref()).firstResult();
if (gangguanExist == null) {
var error = ResponseModel.builder()
.data(Map.of(
"msg", "Referensi no laporan tidak ditemukan",
"result", "0"
))
.build();
throw new CustomException(null, error);
}
Long gangguanLaporUlang = GangguanLaporUlang.find("no_laporan_referensi", prmt.getIn_laporanulang_ref()).count();
GangguanLaporUlang newGangguanLaporUlang = new GangguanLaporUlang();
newGangguanLaporUlang.setLaporan_ke(gangguanLaporUlang);
newGangguanLaporUlang.setNo_laporan_referensi(prmt.getIn_laporanulang_ref());
newGangguanLaporUlang.setNo_laporan_baru(noLaporan);
newGangguanLaporUlang.setGangguan(gangguanExist);
GangguanLaporUlang.persist(newGangguanLaporUlang);
}
if (prmt.getIn_tgl_konfirmasi() != null) {
if (prmt.getIn_tgl_konfirmasi().length() < 12) {
var error = ResponseModel.builder()
.data(Map.of(
"msg", "Panjang tgl Konfirmasi kurang dari 12 karakter",
"result", "0"
)).build();
throw new CustomException(null, error);
}
int tahun = Integer.valueOf(prmt.getIn_tgl_konfirmasi().substring(0,4));
int bulan = Integer.valueOf(prmt.getIn_tgl_konfirmasi().substring(4,6));
int tanggal = Integer.valueOf(prmt.getIn_tgl_konfirmasi().substring(6,8));
int jam = Integer.valueOf(prmt.getIn_tgl_konfirmasi().substring(8, 10));
int menit = Integer.valueOf(prmt.getIn_tgl_konfirmasi().substring(10, 12));
LocalDateTime tglKonfirmasi = LocalDateTime.of(tahun, Month.of(bulan), tanggal, jam, menit);
gangguan.setWaktu_konfirmasi(tglKonfirmasi);
}
gangguan.setNo_laporan(noLaporan);
gangguan.setNama_pelapor(prmt.getIn_nama());
gangguan.setTelepon_pelapor(prmt.getIn_hp());
gangguan.setHp_pelapor(prmt.getIn_hp());
gangguan.setAlamat_pelapor(prmt.getIn_alamat());
gangguan.setMedia(media.getKeterangan());
gangguan.setWaktu_lapor(LocalDateTime.now());
gangguan.setLokasi(point);
gangguan.setKeterangan(prmt.getIn_keterangan());
gangguan.setCreated_date(LocalDateTime.now());
gangguan.setCreated_by(99999L);
gangguan.setStatus_akhir("LAPOR");
gangguan.setUnit(Long.valueOf(prmt.getIn_unitup()));
gangguan.setPermasalahan(tipePermasalahan.getNama());
gangguan.setCreated_date(LocalDateTime.now());
gangguan.persist();
gangguanTransaksi.setGangguan(gangguan);
gangguanTransaksi.setJenis("LAPOR");
gangguanTransaksi.setWaktu(LocalDateTime.now());
gangguanTransaksi.setCreated_date(LocalDateTime.now());
gangguanTransaksi.setCreated_by(99999L);
GangguanTransaksi.persist(gangguanTransaksi);
if (!isPersistent(gangguan)) {
Gangguan.delete("no_laporan", gangguan.getNo_laporan());
throw new CustomException("Gangguan tidak berhasil disimpan");
}
} catch (ParseException e) {
System.err.println("Invalid WKT format: " + e.getMessage());
throw new CustomException("Invalid WKT format: " + e.getMessage());
}
return new CreateGangguanResponse(noLaporan);
} catch (HibernateException e) {
throw new CustomException("Terjadi kesalahan dalam proses menyimpan data : " + e.getMessage());
}
}
}

View File

@@ -0,0 +1,72 @@
package org.sadigit.repository.entity.transaksi;
import java.util.List;
import org.sadigit.control.exception.CustomException;
import org.sadigit.entity.transaksi.GangguanTMTransaksi;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
@ApplicationScoped
@Slf4j
public class GangguanTMTransaksiRepository implements PanacheRepository<GangguanTMTransaksi> {
public List<GangguanTMTransaksi> getGangguanTMNotFlagged(Integer limit) {
String query = "(notif_flag = false or notif_flag is null) and jenis = 'Selesai' and cast(created_date as Date) = cast(CURRENT_DATE as Date)";
try {
return limit == null
? this.find(query).list()
: this.find(query).page(0, limit).list();
} catch (Exception e) {
log.info("Error: {}", e.getMessage());
throw new CustomException(e.getMessage());
}
}
@Transactional
public GangguanTMTransaksi flagTransaksi(String noLaporan) {
StringBuilder queryKe1 = new StringBuilder();
queryKe1.append("waktu_read = CURRENT_DATE and ")
.append("notif_flag = 1 where ")
.append("cast(created_date as Date) < cast(CURRENT_DATE as date) and ")
.append("waktu_read is null");
this.update(queryKe1.toString());
StringBuilder queryKe2 = new StringBuilder();
queryKe2.append("waktu_read = CURRENT_DATE and ")
.append("notif_flag = 1 where ")
.append("gangguanTm.noGangguanTm = ?1 and ")
.append("(flag = 0 or flag is null) and ")
.append("(waktu_read) in ")
.append("(select min(c.waktu_read) from GangguanTMTransaksi c where c.gangguanTm.noGangguanTm = ?1 and (c.notif_flag = 0 or c.notif_flag is null) and cast(c.created_date as Date) = cast(CURRENT_DATE as date))");
this.update(queryKe2.toString(), noLaporan);
return this.find("gangguanTm.noGangguanTm = ?1 and cast(created_date as Date) = cast(CURRENT_DATE as Date)", noLaporan).firstResult();
}
public List<GangguanTMTransaksi> getGangguanTMNotFlaggedNotSelesai(Integer limit) {
StringBuilder sb = new StringBuilder();
sb.append("jenis != 'Selesai' and ")
.append("(notif_flag = false or notif_flag is null) and ")
.append("cast(created_date as Date) = cast(CURRENT_DATE as Date) and ")
.append("(gangguanTm.noGangguanTm, created_date) in ")
.append("(select c.gangguanTm.noGangguanTm, min(c.created_date) from GangguanTMTransaksi c where c.jenis != 'Selesai' and (c.notif_flag = false or c.notif_flag is null) and cast(c.created_date as Date) = cast(current_date as Date) group by c.gangguanTm.noGangguanTm)");
try {
return limit == null
? this.find(sb.toString()).list()
: this.find(sb.toString()).page(0, limit).list();
} catch (Exception e) {
log.info("Error: {}", e.getMessage());
throw new CustomException(e.getMessage());
}
}
}

View File

@@ -0,0 +1,279 @@
package org.sadigit.repository.entity.transaksi;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import org.hibernate.HibernateException;
import org.sadigit.control.exception.CustomException;
import org.sadigit.model.request.CreateKeluhanRequest;
import org.sadigit.model.request.CreateKeluhanV2Request;
import org.sadigit.model.response.base.ResponseModel;
import org.sadigit.entity.masterYantek.Unit;
import org.sadigit.entity.referensi.MasterKelurahan;
import org.sadigit.entity.referensi.Media;
import org.sadigit.entity.referensi.SubTipeKeluhan;
import org.sadigit.entity.referensi.TipeKeluhan;
import org.sadigit.entity.referensi.Uid;
import org.sadigit.entity.transaksi.Keluhan;
import org.sadigit.entity.transaksi.KeluhanLaporUlang;
import org.sadigit.entity.transaksi.KeluhanTransaksi;
import org.sadigit.utils.GeomUtils;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
@ApplicationScoped
public class KeluhanRepository implements PanacheRepository<Keluhan> {
private String generateNoLaporan(Long id_uid) {
// select unitcode from unit
Unit unit = Unit.find("unitid", id_uid).firstResult();
if (unit == null) {
throw new CustomException("Unit tidak ditemukan");
}
String unitCode = unit.getUnitcode();
String noLaporan = "";
String prefix = "K";
Keluhan keluhan = Keluhan.find("unit =?1 and date(created_date)=?2 order by created_date desc", id_uid, LocalDate.now())
.firstResult();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
if (keluhan != null) {
String lastNoLaporan = keluhan.getNo_laporan();
String currentDate = LocalDate.now().format(formatter);
String lastNoLaporanNumber = lastNoLaporan.substring(lastNoLaporan.length() - 4);
int lastNoLaporanNumberInt = Integer.parseInt(lastNoLaporanNumber);
int newNoLaporanNumber = lastNoLaporanNumberInt + 1;
String newNoLaporanNumberString = String.format("%05d", newNoLaporanNumber);
noLaporan = prefix + unitCode + currentDate + newNoLaporanNumberString;
System.out.println("Generated no laporan: " + noLaporan);
return noLaporan;
} else {
LocalDate date = LocalDate.now(); // Get current date directly
System.out.println("Parsed date: " + date);
// Format the LocalDate object to a string using the formatter
String formattedDate = date.format(formatter);
System.out.println("Formatted date: " + formattedDate);
noLaporan = prefix + unitCode + formattedDate + "0001";
System.out.println("Generated no laporan: " + noLaporan);
return noLaporan;
}
}
@Transactional
public ResponseModel<Map<String,String>> create(CreateKeluhanRequest prms) {
if (prms.getIn_idpel() != null) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime earlier = now.minusHours(3);
Keluhan keluhanExist = Keluhan.find("id_pelanggan_no_meter = ?1 and created_date between ?2 and ?3", prms.getIn_idpel(), earlier, now).firstResult();
if (keluhanExist != null) {
var error = ResponseModel.builder()
.data(Map.of("msg", "Pengaduan anda sedang di proses. Anda dapat melakukan pengaduan ulang, 3 jam dari pengaduan sebelumnya."))
.build();
throw new CustomException(null, error);
}
}
try {
int sourceSrid = 4326;
Keluhan keluhan = new Keluhan();
KeluhanTransaksi keluhanTransaksi = new KeluhanTransaksi();
Media media = Media.findById(10);
String noLaporan = "";
try {
Point point = GeomUtils.wktToPoint(prms.getIn_long(), prms.getIn_lat(), sourceSrid);
Uid uid = Uid.findById(prms.getIn_unitup());
MasterKelurahan kelurahan = MasterKelurahan.find("nama_kelurahan", prms.getIn_kel()).firstResult();
TipeKeluhan tipeKeluhan = TipeKeluhan.findById(prms.getIn_tipe_keluhan());
SubTipeKeluhan subTipeKeluhan = SubTipeKeluhan.findById(prms.getIn_subtipe_keluhan());
if (uid == null) {
throw new CustomException("Unit tidak ditemukan");
}
if (tipeKeluhan == null) {
throw new CustomException("Tipe Keluhan tidak ditemukan");
}
if (subTipeKeluhan == null) {
throw new CustomException("Sub Tipe Keluhan tidak ditemukan");
}
if (kelurahan == null) {
throw new CustomException("Kelurahan tidak ditemukan");
}
if (prms.getIn_idpel() != null) {
keluhan.setId_pelanggan_no_meter(Long.valueOf(prms.getIn_idpel()));
}
keluhan.setKelurahan(kelurahan);
noLaporan = generateNoLaporan(Long.valueOf(prms.getIn_unitup()));
keluhan.setNo_laporan(noLaporan);
keluhan.setNama_pelapor(prms.getIn_nama());
keluhan.setTelepon_pelapor(prms.getIn_hp());
keluhan.setHp_pelapor(prms.getIn_hp());
keluhan.setAlamat_pelapor(prms.getIn_alamat());
keluhan.setMedia(media.getKeterangan());
keluhan.setLokasi(point);
keluhan.setKeterangan(prms.getIn_keterangan());
keluhan.setCreated_date(LocalDateTime.now());
keluhan.setCreated_by(99999L);
keluhan.setStatus_akhir("Lapor");
keluhan.setUnit(Long.valueOf(prms.getIn_unitup()));
keluhan.setTipe_keluhan(tipeKeluhan.getIssuetypeid());
keluhan.setTipe_sub_keluhan(subTipeKeluhan.getSubissuetypeid());
keluhan.setPermasalahan(tipeKeluhan.getIssuetypename());
keluhan.setCreated_date(LocalDateTime.now());
keluhan.setKelurahan(kelurahan);
keluhan.persist();
keluhanTransaksi.setKeluhan(keluhan);
keluhanTransaksi.setJenis("Lapor");
keluhanTransaksi.setWaktu(LocalDateTime.now());
keluhanTransaksi.setCreated_date(LocalDateTime.now());
keluhanTransaksi.setCreated_by(99999L);
KeluhanTransaksi.persist(keluhanTransaksi);
if (!isPersistent(keluhan)) {
Keluhan.delete("no_laporan", keluhan.getNo_laporan());
throw new CustomException("keluhan tidak berhasil disimpan");
}
} catch (ParseException e) {
System.err.println("Invalid WKT format: " + e.getMessage());
throw new CustomException("Invalid WKT format: " + e.getMessage());
}
ResponseModel<Map<String,String>> responseModel = new ResponseModel<>();
responseModel.setData(Map.of("reportnumber", noLaporan));
return responseModel;
} catch (HibernateException e) {
throw new CustomException("Terjadi kesalahan dalam proses menyimpan data : " + e.getMessage());
}
}
@Transactional
public ResponseModel<Map<String,String>> createV2(CreateKeluhanV2Request prms) {
if (prms.getIn_idpel() != null) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime earlier = now.minusHours(3);
Keluhan keluhanExist = Keluhan.find("id_pelanggan_no_meter = ?1 and created_date between ?2 and ?3", prms.getIn_idpel(), earlier, now).firstResult();
if (keluhanExist != null) {
var error = ResponseModel.builder()
.data(Map.of("msg", "Pengaduan anda sedang di proses. Anda dapat melakukan pengaduan ulang, 3 jam dari pengaduan sebelumnya."))
.build();
throw new CustomException(null, error);
}
}
try {
int sourceSrid = 4326;
Keluhan keluhan = new Keluhan();
KeluhanTransaksi keluhanTransaksi = new KeluhanTransaksi();
Media media = Media.findById(10);
String noLaporan = "";
try {
Point point = GeomUtils.wktToPoint(prms.getIn_long(), prms.getIn_lat(), sourceSrid);
Uid uid = Uid.findById(prms.getIn_unitup());
MasterKelurahan kelurahan = MasterKelurahan.find("nama_kelurahan", prms.getIn_kel()).firstResult();
TipeKeluhan tipeKeluhan = TipeKeluhan.findById(prms.getIn_tipe_keluhan());
SubTipeKeluhan subTipeKeluhan = SubTipeKeluhan.findById(prms.getIn_subtipe_keluhan());
if (uid == null) {
throw new CustomException("Unit tidak ditemukan");
}
if (tipeKeluhan == null) {
throw new CustomException("Tipe Keluhan tidak ditemukan");
}
if (subTipeKeluhan == null) {
throw new CustomException("Sub Tipe Keluhan tidak ditemukan");
}
if (kelurahan == null) {
throw new CustomException("Kelurahan tidak ditemukan");
}
if (prms.getIn_idpel() != null) {
keluhan.setId_pelanggan_no_meter(Long.valueOf(prms.getIn_idpel()));
}
if (prms.getIn_laporanulang_ref() != null) {
Keluhan gangguanExist = Keluhan.find("no_laporan = ?1", prms.getIn_laporanulang_ref()).firstResult();
if (gangguanExist == null) {
var error = ResponseModel.builder()
.data(Map.of(
"msg", "Referensi no laporan tidak ditemukan",
"result", "0"
))
.build();
throw new CustomException(null, error);
}
Long jumlahLaporUlang = KeluhanLaporUlang.find("no_laporan_referensi", prms.getIn_laporanulang_ref()).count();
KeluhanLaporUlang newKeluhanLaporUlang = new KeluhanLaporUlang();
newKeluhanLaporUlang.setLaporan_ke(jumlahLaporUlang);
newKeluhanLaporUlang.setNo_laporan_referensi(prms.getIn_laporanulang_ref());
newKeluhanLaporUlang.setNo_laporan_baru(noLaporan);
newKeluhanLaporUlang.setKeluhan(gangguanExist);
KeluhanLaporUlang.persist(newKeluhanLaporUlang);
}
keluhan.setKelurahan(kelurahan);
noLaporan = generateNoLaporan(Long.valueOf(prms.getIn_unitup()));
keluhan.setNo_laporan(noLaporan);
keluhan.setNama_pelapor(prms.getIn_nama());
keluhan.setTelepon_pelapor(prms.getIn_hp());
keluhan.setHp_pelapor(prms.getIn_hp());
keluhan.setAlamat_pelapor(prms.getIn_alamat());
keluhan.setMedia(media.getKeterangan());
keluhan.setLokasi(point);
keluhan.setKeterangan(prms.getIn_keterangan());
keluhan.setCreated_date(LocalDateTime.now());
keluhan.setCreated_by(99999L);
keluhan.setStatus_akhir("LAPOR");
keluhan.setUnit(Long.valueOf(prms.getIn_unitup()));
keluhan.setTipe_keluhan(tipeKeluhan.getIssuetypeid());
keluhan.setTipe_sub_keluhan(subTipeKeluhan.getSubissuetypeid());
keluhan.setPermasalahan(tipeKeluhan.getIssuetypename());
keluhan.setCreated_date(LocalDateTime.now());
keluhan.setKelurahan(kelurahan);
keluhan.persist();
keluhanTransaksi.setKeluhan(keluhan);
keluhanTransaksi.setJenis("LAPOR");
keluhanTransaksi.setWaktu(LocalDateTime.now());
keluhanTransaksi.setCreated_date(LocalDateTime.now());
keluhanTransaksi.setCreated_by(99999L);
KeluhanTransaksi.persist(keluhanTransaksi);
if (!isPersistent(keluhan)) {
Keluhan.delete("no_laporan", keluhan.getNo_laporan());
throw new CustomException("keluhan tidak berhasil disimpan");
}
} catch (ParseException e) {
System.err.println("Invalid WKT format: " + e.getMessage());
throw new CustomException("Invalid WKT format: " + e.getMessage());
}
ResponseModel<Map<String,String>> responseModel = new ResponseModel<>();
responseModel.setData(Map.of("reportnumber", noLaporan));
return responseModel;
} catch (HibernateException e) {
throw new CustomException("Terjadi kesalahan dalam proses menyimpan data : " + e.getMessage());
}
}
}

View File

@@ -0,0 +1,61 @@
package org.sadigit.repository.service;
import java.util.List;
import org.hibernate.Session;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.Tuple;
@ApplicationScoped
public class PlnMobileServiceRepository {
@Inject
Session session;
public List<Tuple> get10PengaduanTerbaruByIdPel(String idpel) {
// log.info("idpel: {}", idpel);
String query = """
(
select
g.id_pelanggan_no_meter as idpel,
g.no_laporan as noLaporan,
g.alamat_pelapor as alamatPelapor,
g.created_date as createdDate,
g.nama_pelapor as namaPelapor,
r1.nama as namaRegu,
g.keterangan as keterangan
from
Gangguan g
left join MasterRegu r1 on g.regu.id = r1.id
where
g.id_pelanggan_no_meter = :idpel and
g.created_date is not null
union all
select
k.id_pelanggan_no_meter as idpel,
k.no_laporan as noLaporan,
k.alamat_pelapor as alamatPelapor,
k.created_date as createdDate,
k.nama_pelapor as namaPelapor,
r2.nama as namaRegu,
k.keterangan as keterangan
from
Keluhan k
left join MasterRegu r2 on k.regu.id = r2.id
where
k.id_pelanggan_no_meter = :idpel and
k.created_date is not null
)
order by createdDate asc
""";
return session.createQuery(query, Tuple.class)
.setParameter("idpel", idpel)
.setMaxResults(10)
.getResultList();
}
}