all
This commit is contained in:
@@ -0,0 +1,577 @@
|
||||
package id.co.iconpln.apkt.data309.boundary;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import id.co.iconpln.apkt.data309.dto.Data309;
|
||||
import id.co.iconpln.apkt.data309.dto.ReportData;
|
||||
import id.co.iconpln.apkt.data309.dto.ResponseModel;
|
||||
import id.co.iconpln.apkt.data309.dto.Row;
|
||||
import id.co.iconpln.apkt.data309.entity.SS309;
|
||||
import id.co.iconpln.apkt.data309.entity.Ulp;
|
||||
import id.co.iconpln.apkt.data309.service.Data309Service;
|
||||
import id.co.iconpln.apkt.data309.utils.XmlToJsonConverter;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalDate;
|
||||
// import java.nio.file.Files;
|
||||
// import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
// import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
@Path("/data309")
|
||||
public class DataII09Resource {
|
||||
@Inject
|
||||
EntityManager em;
|
||||
@Inject
|
||||
Data309Service data309Service;
|
||||
|
||||
@GET
|
||||
@Path("/getData")
|
||||
public ResponseModel<String> getDil(@QueryParam("unit") String unit, @QueryParam("thnbln") String thnbln)
|
||||
throws IOException {
|
||||
ResponseModel<String> response = new ResponseModel<>();
|
||||
try {
|
||||
// URL of the SOAP service
|
||||
URL url = new URL("http://10.72.35.15:7076/wsIntegPDPJ/WsIntegSimDisService");
|
||||
|
||||
// Open connection
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "text/xml");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
String xmlRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.iconpln.com/\">\n"
|
||||
+
|
||||
" <soapenv:Header/>\n" +
|
||||
" <soapenv:Body>\n" +
|
||||
" <ws:getData309>\n" +
|
||||
" <unit>" + unit + "</unit>\n" +
|
||||
" <thblrek>" + thnbln + "</thblrek>\n" +
|
||||
" </ws:getData309>\n" +
|
||||
" </soapenv:Body>\n" +
|
||||
"</soapenv:Envelope>";
|
||||
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream())) {
|
||||
writer.write(xmlRequest);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(connection.getInputStream()))) {
|
||||
StringBuilder newData = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
newData.append(line);
|
||||
}
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String json = XmlToJsonConverter.convertXmlToJson(newData.toString());
|
||||
|
||||
JsonNode rootNode = objectMapper.readTree(json);
|
||||
|
||||
// Get the 'item' array from JSON
|
||||
JsonNode itemNode = rootNode.path("Body")
|
||||
.path("getData309Response")
|
||||
.path("return")
|
||||
.path("item");
|
||||
// Process each item
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
Integer i = 0;
|
||||
for (JsonNode node : itemNode) {
|
||||
String itemValue = node.asText();
|
||||
System.out.println("Item value: " + itemValue);
|
||||
|
||||
// Check if the item is XML
|
||||
if (itemValue.startsWith("<?xml")) {
|
||||
// Process XML content separately
|
||||
// You may parse this XML or handle it accordingly
|
||||
String xmlContent = itemValue;
|
||||
i++;
|
||||
obj.put(i.toString(), XmlToJsonConverter
|
||||
.convertXmlToJson(xmlContent));
|
||||
}
|
||||
}
|
||||
|
||||
String jsonResult = objectMapper.writeValueAsString(obj);
|
||||
// Create ObjectMapper instance
|
||||
ObjectMapper mapperFromObjectNode = new ObjectMapper();
|
||||
|
||||
// Parse the JSON string into a JsonNode
|
||||
JsonNode jsonNode = mapperFromObjectNode.readTree(jsonResult);
|
||||
|
||||
// Retrieve the nested JSON string and remove unnecessary backslashes
|
||||
String cleanedJsonString = jsonNode.get("1").asText();
|
||||
|
||||
// Parse the cleaned JSON string back into a JsonNode to ensure it's valid
|
||||
JsonNode cleanedJsonNode = objectMapper.readTree(cleanedJsonString);
|
||||
|
||||
// Pretty print the cleaned JSON
|
||||
String prettyCleanedJsonString = objectMapper.writerWithDefaultPrettyPrinter()
|
||||
.writeValueAsString(cleanedJsonNode);
|
||||
response.setData(prettyCleanedJsonString.replace("\n", ""));
|
||||
|
||||
response.setMessage("Success");
|
||||
response.setStatus(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
response.setMessage("Failed : " + e.getMessage());
|
||||
response.setStatus(false);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// Handle IOException
|
||||
e.printStackTrace();
|
||||
response.setMessage("Failed : " + e.getMessage());
|
||||
response.setStatus(false);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
response.setMessage("Failed : " + e.getMessage());
|
||||
response.setStatus(false);
|
||||
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/pojo")
|
||||
@Transactional
|
||||
public Data309 getPojo(@QueryParam("unit") String unit, @QueryParam("thnbln") String thnbln)
|
||||
throws IOException, InterruptedException {
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://10.14.212.9:32184/data309/getData?unit=" + unit +
|
||||
"&thnbln=" + thnbln))
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
// get data from root path json.json
|
||||
// String jsonString = new String(Files.readAllBytes(Paths.get("json3.json")));
|
||||
// replace "null" with null
|
||||
String jsonString = response.body();
|
||||
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_TRAILING_TOKENS, true);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, true);
|
||||
ReportData reportData = objectMapper.readValue(jsonString, ReportData.class);
|
||||
String data = reportData.getData();
|
||||
Data309 data309 = objectMapper.readValue(data, Data309.class);
|
||||
if (data309.getRow() != null) {
|
||||
|
||||
for (Row newData : data309.getRow()) {
|
||||
Ulp ulp = Ulp.find("unit_ap2t = ?1", newData.getUnitup()).firstResult();
|
||||
SS309 ss309 = SS309
|
||||
.find("id_ulp = ?1 and thbllap = ?2 and no_baris = ?3",
|
||||
ulp.getId(),
|
||||
newData.getThbllap(), newData.getNoBaris())
|
||||
.firstResult();
|
||||
if (ss309 == null) {
|
||||
ss309 = new SS309();
|
||||
}
|
||||
ss309.setThbllap(!newData.getThbllap().equals("null") ? newData.getThbllap()
|
||||
: null);
|
||||
ss309.setJenislap(!newData.getJenislap().equals("null") ? newData.getJenislap()
|
||||
: null);
|
||||
ss309.setId_ulp(ulp == null ? null : ulp.getId());
|
||||
ss309.setNo_baris(
|
||||
!newData.getNoBaris().equals("null")
|
||||
? Integer.valueOf(newData.getNoBaris())
|
||||
: null);
|
||||
ss309.setGoltarif(!newData.getGoltarif().equals("null") ? newData.getGoltarif()
|
||||
: null);
|
||||
ss309.setTarif(!newData.getTarif().equals("null") ? newData.getTarif() : null);
|
||||
ss309.setDaya_min(
|
||||
!newData.getDayaMin().equals("null")
|
||||
? Integer.valueOf(newData.getDayaMin())
|
||||
: null);
|
||||
ss309.setDaya_max(
|
||||
!newData.getDayaMax().equals("null")
|
||||
? Integer.valueOf(newData.getDayaMax())
|
||||
: null);
|
||||
ss309.setLabel(!newData.getLabel().equals("null") ? newData.getLabel() : null);
|
||||
ss309.setLabel_asterik(
|
||||
!newData.getLabelAsterik().equals("null")
|
||||
? newData.getLabelAsterik()
|
||||
: null);
|
||||
ss309.setJmldaya(
|
||||
!newData.getJmldaya().equals("null")
|
||||
? new BigDecimal(newData.getJmldaya())
|
||||
: null);
|
||||
ss309.setJmlplg(
|
||||
!newData.getJmlplg().equals("null")
|
||||
? new BigDecimal(newData.getJmlplg())
|
||||
: null);
|
||||
ss309.setJmlkwh(!newData.getJmlkwh().equals("null")
|
||||
? new BigDecimal(newData.getJmlkwh())
|
||||
: null);
|
||||
ss309.setJmlplg(
|
||||
!newData.getJmlplg().equals("null")
|
||||
? new BigDecimal(newData.getJmlplg())
|
||||
: null);
|
||||
ss309.setKwhlwbp(
|
||||
!newData.getKwhlwbp().equals("null")
|
||||
? new BigDecimal(newData.getKwhlwbp())
|
||||
: null);
|
||||
ss309.setKwhwbp(!newData.getKwhwbp().equals("null")
|
||||
? new BigDecimal(newData.getKwhwbp())
|
||||
: null);
|
||||
ss309.setKelbkvarh(
|
||||
!newData.getKelbkvarh().equals("null")
|
||||
? new BigDecimal(newData.getKelbkvarh())
|
||||
: null);
|
||||
ss309.setRpbeban(
|
||||
!newData.getRpbeban().equals("null")
|
||||
? new BigDecimal(newData.getRpbeban())
|
||||
: null);
|
||||
ss309.setRpkwh(!newData.getRpkwh().equals("null")
|
||||
? new BigDecimal(newData.getRpkwh())
|
||||
: null);
|
||||
ss309.setRpkvarh(
|
||||
!newData.getRpkvarh().equals("null")
|
||||
? new BigDecimal(newData.getRpkvarh())
|
||||
: null);
|
||||
ss309.setRpptl(!newData.getRpptl().equals("null")
|
||||
? new BigDecimal(newData.getRpptl())
|
||||
: null);
|
||||
ss309.setRata_va_langganan(
|
||||
!newData.getRataVaLangganan().equals("null")
|
||||
? new BigDecimal(newData.getRataVaLangganan())
|
||||
: null);
|
||||
ss309.setRata_kwh_langganan(
|
||||
!newData.getRataKwhLangganan().equals("null")
|
||||
? new BigDecimal(newData.getRataKwhLangganan())
|
||||
: null);
|
||||
ss309.setRata_rp_kwh(
|
||||
!newData.getRataRpKwh().equals("null")
|
||||
? new BigDecimal(newData.getRataRpKwh())
|
||||
: null);
|
||||
ss309.setJam_nyala(
|
||||
!newData.getJamNyala().equals("null")
|
||||
? new BigDecimal(newData.getJamNyala())
|
||||
: null);
|
||||
ss309.setKwh_sd_bln_ini(
|
||||
!newData.getKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getKwhSdBlnIni())
|
||||
: null);
|
||||
ss309.setKvarh_sd_bln_ini(
|
||||
!newData.getKvarhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getKvarhSdBlnIni())
|
||||
: null);
|
||||
ss309.setR_beban_sd_bln_ini(
|
||||
!newData.getBBebanSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getBBebanSdBlnIni())
|
||||
: null);
|
||||
ss309.setB_kwh_sd_bln_ini(
|
||||
!newData.getBKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getBKwhSdBlnIni())
|
||||
: null);
|
||||
ss309.setB_kvarh_sd_bln_ini(
|
||||
!newData.getBKvarhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getBKvarhSdBlnIni())
|
||||
: null);
|
||||
ss309.setJumlah_sd_bln_ini(
|
||||
!newData.getJumlahSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getJumlahSdBlnIni())
|
||||
: null);
|
||||
ss309.setRp_kwh_sd_bln_ini(
|
||||
!newData.getRpKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData.getRpKwhSdBlnIni())
|
||||
: null);
|
||||
ss309.persist();
|
||||
}
|
||||
|
||||
}
|
||||
return data309;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null; // Or handle as needed
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/sinkron")
|
||||
@Transactional
|
||||
public void sinkron() throws IOException, InterruptedException {
|
||||
System.out.println("SINKRON DATA 309");
|
||||
String thnbln = String.valueOf(LocalDate.now().getYear())
|
||||
+ String.format("%02d", LocalDate.now().getMonthValue() - 1);
|
||||
// string pad left 0
|
||||
|
||||
if (LocalDate.now().getMonthValue() == 1) {
|
||||
thnbln = String.valueOf(LocalDate.now().getYear() - 1) + "12";
|
||||
}
|
||||
|
||||
List<Ulp> ulps = Ulp.find("unit_ap2t NOT IN ('PLN.PST') OR unit_ap2t is not null").list();
|
||||
for (Ulp getUlp : ulps) {
|
||||
|
||||
String unit = getUlp.getUnit_ap2t();
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://10.14.212.9:32184/data309/pojo?unit=" + unit +
|
||||
"&thnbln=" + thnbln))
|
||||
.GET()
|
||||
.build();
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
// data309Service.syncronize(unit, thnbln);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/manual")
|
||||
@Transactional
|
||||
public void manual(@QueryParam("thnbln") String thnbln) throws IOException, InterruptedException {
|
||||
List<Ulp> ulps = Ulp.find("unit_ap2t NOT IN ('PLN.PST') OR unit_ap2t is not null").list();
|
||||
for (Ulp getUlp : ulps) {
|
||||
|
||||
String unit = getUlp.getUnit_ap2t();
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://10.14.212.9:32184/data309/pojo?unit=" + unit +
|
||||
"&thnbln=" + thnbln))
|
||||
.GET()
|
||||
.build();
|
||||
client.send(request,
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
// data309Service.syncronize(unit, thnbln);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getAll")
|
||||
@Transactional
|
||||
public void getAll() {
|
||||
String thnbln = getThnbln();
|
||||
|
||||
List<Ulp> ulps = Ulp.find("unit_ap2t is not null OR unit_ap2t NOT IN ('PLN.PST')").list();
|
||||
for (Ulp getUlp : ulps) {
|
||||
String unit = getUlp.getUnit_ap2t();
|
||||
try {
|
||||
String jsonString = fetchJsonData(unit, thnbln);
|
||||
if (jsonString != null) {
|
||||
processJsonData(jsonString);
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// Log exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processJsonData(String jsonString) throws IOException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
ReportData reportData = objectMapper.readValue(jsonString, ReportData.class);
|
||||
if (reportData != null) {
|
||||
Data309 data309 = objectMapper.readValue(reportData.getData(), Data309.class);
|
||||
if (data309.getRow() != null) {
|
||||
for (Row newData : data309.getRow()) {
|
||||
persistSS309(newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void persistSS309(Row newData) {
|
||||
Ulp ulp = Ulp.find("unit_ap2t = ?1", newData.getUnitup()).firstResult();
|
||||
// Create or update SS309 based on newData
|
||||
SS309 ss309 = SS309.find("id_ulp = ?1 and thbllap = ?2 and no_baris = ?3",
|
||||
ulp.getId(), newData.getThbllap(), newData.getNoBaris()).firstResult();
|
||||
if (ss309 == null) {
|
||||
ss309 = new SS309();
|
||||
}
|
||||
// Set properties
|
||||
setSS309Properties(ss309, ulp, newData);
|
||||
ss309.persist();
|
||||
}
|
||||
|
||||
private void setSS309Properties(SS309 ss309, Ulp ulp, Row newData) {
|
||||
ss309.setThbllap(!newData.getThbllap().equals("null")
|
||||
? newData.getThbllap()
|
||||
: null);
|
||||
ss309.setJenislap(!newData.getJenislap().equals("null")
|
||||
? newData.getJenislap()
|
||||
: null);
|
||||
ss309.setId_ulp(ulp == null ? null : ulp.getId());
|
||||
ss309.setNo_baris(
|
||||
!newData.getNoBaris().equals("null")
|
||||
? Integer.valueOf(newData.getNoBaris())
|
||||
: null);
|
||||
ss309.setGoltarif(!newData.getGoltarif().equals("null")
|
||||
? newData.getGoltarif()
|
||||
: null);
|
||||
ss309.setTarif(!newData.getTarif().equals("null") ? newData.getTarif()
|
||||
: null);
|
||||
ss309.setDaya_min(
|
||||
!newData.getDayaMin().equals("null")
|
||||
? Integer.valueOf(newData.getDayaMin())
|
||||
: null);
|
||||
ss309.setDaya_max(
|
||||
!newData.getDayaMax().equals("null")
|
||||
? Integer.valueOf(newData.getDayaMax())
|
||||
: null);
|
||||
ss309.setLabel(!newData.getLabel().equals("null") ? newData.getLabel()
|
||||
: null);
|
||||
ss309.setLabel_asterik(
|
||||
!newData.getLabelAsterik().equals("null")
|
||||
? newData.getLabelAsterik()
|
||||
: null);
|
||||
ss309.setJmldaya(
|
||||
!newData.getJmldaya().equals("null")
|
||||
? new BigDecimal(newData.getJmldaya())
|
||||
: null);
|
||||
ss309.setJmlplg(
|
||||
!newData.getJmlplg().equals("null")
|
||||
? new BigDecimal(newData.getJmlplg())
|
||||
: null);
|
||||
ss309.setJmlkwh(!newData.getJmlkwh().equals("null")
|
||||
? new BigDecimal(newData.getJmlkwh())
|
||||
: null);
|
||||
ss309.setKwhlwbp(
|
||||
!newData.getKwhlwbp().equals("null")
|
||||
? new BigDecimal(newData.getKwhlwbp())
|
||||
: null);
|
||||
ss309.setKwhwbp(!newData.getKwhwbp().equals("null")
|
||||
? new BigDecimal(newData.getKwhwbp())
|
||||
: null);
|
||||
ss309.setKelbkvarh(
|
||||
!newData.getKelbkvarh().equals("null")
|
||||
? new BigDecimal(newData.getKelbkvarh())
|
||||
: null);
|
||||
ss309.setRpbeban(
|
||||
!newData.getRpbeban().equals("null")
|
||||
? new BigDecimal(newData.getRpbeban())
|
||||
: null);
|
||||
ss309.setRpkwh(!newData.getRpkwh().equals("null")
|
||||
? new BigDecimal(newData.getRpkwh())
|
||||
: null);
|
||||
ss309.setRpkvarh(
|
||||
!newData.getRpkvarh().equals("null")
|
||||
? new BigDecimal(newData.getRpkvarh())
|
||||
: null);
|
||||
ss309.setRpptl(!newData.getRpptl().equals("null")
|
||||
? new BigDecimal(newData.getRpptl())
|
||||
: null);
|
||||
ss309.setRata_va_langganan(
|
||||
!newData.getRataVaLangganan().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getRataVaLangganan())
|
||||
: null);
|
||||
ss309.setRata_kwh_langganan(
|
||||
!newData.getRataKwhLangganan().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getRataKwhLangganan())
|
||||
: null);
|
||||
ss309.setRata_rp_kwh(
|
||||
!newData.getRataRpKwh().equals("null")
|
||||
? new BigDecimal(newData.getRataRpKwh())
|
||||
: null);
|
||||
ss309.setJam_nyala(
|
||||
!newData.getJamNyala().equals("null")
|
||||
? new BigDecimal(newData.getJamNyala())
|
||||
: null);
|
||||
ss309.setKwh_sd_bln_ini(
|
||||
!newData.getKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getKwhSdBlnIni())
|
||||
: null);
|
||||
ss309.setKvarh_sd_bln_ini(
|
||||
!newData.getKvarhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getKvarhSdBlnIni())
|
||||
: null);
|
||||
ss309.setR_beban_sd_bln_ini(
|
||||
!newData.getBBebanSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getBBebanSdBlnIni())
|
||||
: null);
|
||||
ss309.setB_kwh_sd_bln_ini(
|
||||
!newData.getBKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getBKwhSdBlnIni())
|
||||
: null);
|
||||
ss309.setB_kvarh_sd_bln_ini(
|
||||
!newData.getBKvarhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getBKvarhSdBlnIni())
|
||||
: null);
|
||||
ss309.setJumlah_sd_bln_ini(
|
||||
!newData.getJumlahSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getJumlahSdBlnIni())
|
||||
: null);
|
||||
ss309.setRp_kwh_sd_bln_ini(
|
||||
!newData.getRpKwhSdBlnIni().equals("null")
|
||||
? new BigDecimal(newData
|
||||
.getRpKwhSdBlnIni())
|
||||
: null);
|
||||
}
|
||||
|
||||
private String getThnbln() {
|
||||
String thnbln = String.valueOf(LocalDate.now().getYear())
|
||||
+ String.format("%02d", LocalDate.now().getMonthValue() - 1);
|
||||
// string pad left 0
|
||||
|
||||
if (LocalDate.now().getMonthValue() == 1) {
|
||||
thnbln = String.valueOf(LocalDate.now().getYear() - 1) + "12";
|
||||
}
|
||||
|
||||
return thnbln;
|
||||
}
|
||||
|
||||
private String fetchJsonData(String unit, String thnbln) throws IOException, InterruptedException {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://10.14.212.9:32184/data309/getData?unit=" + unit + "&thnbln="
|
||||
+ thnbln))
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.body();
|
||||
}
|
||||
|
||||
public static String convertEntitiesToUnicode(String xmlString) {
|
||||
// Replace HTML entities with their corresponding characters
|
||||
String convertedXml = xmlString.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace("\"", """)
|
||||
.replace("'", "'");
|
||||
|
||||
return convertedXml;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user