Update PasienTask.java
Penerapan penggunaan kdprofile dan penyesuaian scheduler untuk tengah malem
This commit is contained in:
parent
6d3a1ecc42
commit
ca1a915123
@ -9,7 +9,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -18,12 +17,12 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.springframework.http.HttpMethod.GET;
|
import static org.springframework.http.HttpMethod.GET;
|
||||||
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author salmanoe
|
* @author salmanoe
|
||||||
@ -43,7 +42,7 @@ public class PasienTask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PasienDao pasienDao;
|
private PasienDao pasienDao;
|
||||||
|
|
||||||
@Scheduled(fixedRate = 1000 * 60 * 60 * 24)
|
@Scheduled(cron = "0 0 0 * * *")
|
||||||
public void nikPesertaBpjs() {
|
public void nikPesertaBpjs() {
|
||||||
LOGGER.info("Task PasienTask.nikPesertaBpjs {}", LocalDateTime.now());
|
LOGGER.info("Task PasienTask.nikPesertaBpjs {}", LocalDateTime.now());
|
||||||
|
|
||||||
@ -52,26 +51,58 @@ public class PasienTask {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void adjustNikPesertaBpjs() {
|
private void adjustNikPesertaBpjs() {
|
||||||
try {
|
LOGGER.info("Adjusting NIK Peserta BPJS {}", LocalDateTime.now());
|
||||||
LOGGER.info("Adjusting NIK Peserta BPJS {}", LocalDateTime.now());
|
|
||||||
|
|
||||||
List<Pasien> listPasien = new ArrayList<>();
|
List<PesertaBpjsDto> listDtoUpdate = new ArrayList<>();
|
||||||
List<Pasien> pasienValidBpjs = pasienDao.findByValidBpjs();
|
List<PesertaBpjsDto> listDtoNotUpdate = new ArrayList<>();
|
||||||
for (Pasien pasien : pasienValidBpjs) {
|
List<Pasien> pasienValidBpjs = pasienDao.findByValidBpjs();
|
||||||
|
for (Pasien pasien : pasienValidBpjs) {
|
||||||
|
try {
|
||||||
PesertaBpjsDto pesertaBpjsDto = cekKepesertaan(pasien.getNoBpjs());
|
PesertaBpjsDto pesertaBpjsDto = cekKepesertaan(pasien.getNoBpjs());
|
||||||
if (pesertaBpjsDto != null) {
|
if (pesertaBpjsDto.getKdProfile() == 0)
|
||||||
Pasien pasien_ = new Pasien();
|
listDtoUpdate.add(pesertaBpjsDto);
|
||||||
pasien_.setId(pasien.getId());
|
if (pesertaBpjsDto.getKdProfile() == 1)
|
||||||
pasien_.setNoIdentitas(pesertaBpjsDto.getNik());
|
listDtoNotUpdate.add(pesertaBpjsDto);
|
||||||
listPasien.add(pasien_);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.sleep((long) (Math.random() * 1000 * 8));
|
Thread.sleep((long) (Math.random() * 1000 * 8));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Error adjusting NIK Peserta BPJS {} -> {}", pasien.getNoBpjs(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
List<String> listNoKartu = listDtoUpdate.stream().map(PesertaBpjsDto::getNoKartu)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Pasien> availableValid = pasienValidBpjs.stream()
|
||||||
|
.filter(pasien -> listNoKartu.contains(pasien.getNoBpjs())).collect(Collectors.toList());
|
||||||
|
availableValid.forEach(pasien -> {
|
||||||
|
Optional<PesertaBpjsDto> first = listDtoUpdate.stream()
|
||||||
|
.filter(dto -> pasien.getNoBpjs().equals(dto.getNoKartu())).findFirst();
|
||||||
|
first.ifPresent(dto -> {
|
||||||
|
pasien.setKdProfile(dto.getKdProfile());
|
||||||
|
pasien.setNoIdentitas(dto.getNik());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (CommonUtil.isNotNullOrEmpty(availableValid)) {
|
||||||
|
LOGGER.info("Save available valid data");
|
||||||
|
|
||||||
|
pasienDao.save(availableValid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
List<String> listNoKartu = listDtoNotUpdate.stream().map(PesertaBpjsDto::getNoKartu)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Pasien> availableValid = pasienValidBpjs.stream()
|
||||||
|
.filter(pasien -> listNoKartu.contains(pasien.getNoBpjs())).collect(Collectors.toList());
|
||||||
|
availableValid.forEach(pasien -> {
|
||||||
|
Optional<PesertaBpjsDto> first = listDtoNotUpdate.stream()
|
||||||
|
.filter(dto -> pasien.getNoBpjs().equals(dto.getNoKartu())).findFirst();
|
||||||
|
first.ifPresent(dto -> pasien.setKdProfile(dto.getKdProfile()));
|
||||||
|
});
|
||||||
|
if (CommonUtil.isNotNullOrEmpty(availableValid)) {
|
||||||
|
LOGGER.info("Flag kdProfile can not update");
|
||||||
|
|
||||||
|
pasienDao.save(availableValid);
|
||||||
}
|
}
|
||||||
if (CommonUtil.isNotNullOrEmpty(listPasien))
|
|
||||||
pasienDao.save(listPasien);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("Error adjusting NIK Peserta BPJS {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,20 +113,23 @@ public class PasienTask {
|
|||||||
URI uri = new URI("https://daftar.rsabhk.co.id/api/data/pasien/jaminan/bpjs/cek-kepesertaan/" + noKartu);
|
URI uri = new URI("https://daftar.rsabhk.co.id/api/data/pasien/jaminan/bpjs/cek-kepesertaan/" + noKartu);
|
||||||
HttpEntity<Object> request = new HttpEntity<>(null);
|
HttpEntity<Object> request = new HttpEntity<>(null);
|
||||||
ResponseEntity<Object> response = restTemplate.exchange(uri, GET, request, Object.class);
|
ResponseEntity<Object> response = restTemplate.exchange(uri, GET, request, Object.class);
|
||||||
if (HttpStatus.OK.equals(response.getStatusCode())) {
|
if (OK.equals(response.getStatusCode()) || CREATED.equals(response.getStatusCode())) {
|
||||||
Map<String, Object> responseBody = objectMapper.convertValue(response.getBody(), Map.class);
|
Map<String, Object> responseBody = objectMapper.convertValue(response.getBody(), Map.class);
|
||||||
Map<String, Object> responseMap = objectMapper.convertValue(responseBody.get("response"),
|
Map<String, Object> responseMap = objectMapper.convertValue(responseBody.get("response"),
|
||||||
HashMap.class);
|
HashMap.class);
|
||||||
Map<String, Object> responsePeserta = objectMapper.convertValue(responseMap.get("peserta"),
|
Map<String, Object> responsePeserta = objectMapper.convertValue(responseMap.get("peserta"),
|
||||||
HashMap.class);
|
HashMap.class);
|
||||||
return PesertaBpjsDto.builder().noKartu(responsePeserta.get("noKartu").toString())
|
return PesertaBpjsDto.builder().noKartu(responsePeserta.get("noKartu").toString())
|
||||||
.nik(responsePeserta.get("nik").toString()).build();
|
.nik(responsePeserta.get("nik").toString()).kdProfile((short) 0).build();
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Error handshake cek kepesertaan BPJS {}", response.getStatusCode().getReasonPhrase());
|
LOGGER.error("Error handshake cek kepesertaan BPJS {}", response.getStatusCode().getReasonPhrase());
|
||||||
|
|
||||||
|
return PesertaBpjsDto.builder().noKartu(noKartu).kdProfile((short) 1).build();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error cek kepesertaan BPJS {}", e.getMessage());
|
LOGGER.error("Error cek kepesertaan BPJS {}", e.getMessage());
|
||||||
|
|
||||||
|
return PesertaBpjsDto.builder().noKartu(noKartu).kdProfile((short) 1).build();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user