Create Timer Task Otomatisasi Kontrak

Pembuatan service otomatisasi pembuatan kontrak kinerja dokter
This commit is contained in:
salmanoersabhk 2022-08-26 17:41:15 +07:00
parent 63b8a7d519
commit 23efb8cf91
4 changed files with 160 additions and 0 deletions

View File

@ -55,6 +55,8 @@ public interface LogbookKinerjaService extends BaseVoService<LogbookKinerja, Log
Integer idPegawai) throws JpaSystemException;
public void autoVerifLogbookJamKerjaDokter(Date bulan);
public void autoVerifKontrakJamKerjaDokter(Date bulan);
public List<SkorDokterVO> hitungTargetSkorLogbookDokter(String tahun) throws ParseException;

View File

@ -2919,6 +2919,12 @@ public class LogbookKinerjaServiceImpl extends BaseVoServiceImpl implements Logb
this.autoVerify(vo);
}
}
@Override
public void autoVerifKontrakJamKerjaDokter(Date bulan) {
// TODO Auto-generated method stub
}
@Override
public List<SkorDokterVO> hitungTargetSkorLogbookDokter(String tahun) throws ParseException {

View File

@ -0,0 +1,62 @@
package com.jasamedika.medifirst2000.asynctask;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.jasamedika.medifirst2000.asynctask.timer.KontrakVerificationTimer;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.service.LogbookKinerjaService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.LogbookKinerjaVO;
@Component
public class AutoKontrakVerification extends LocaleController<LogbookKinerjaVO> {
private final static Logger LOGGER = LoggerFactory.getLogger(AutoKontrakVerification.class);
@Autowired
private LogbookKinerjaService logbookKinerjaService;
public AutoKontrakVerification() {
int day = 21;
int hour = 0;
int minute = 00;
KontrakVerificationTimer.schedule(new Runnable() {
@Override
public void run() {
try {
LOGGER.info("Task Kontrak Verification : Running Task Kontrak Verification");
autoKontrakVerification();
} catch (Exception ex) {
LOGGER.error("Task Kontrak Verification : Task Kontrak Verification " + ex.getMessage());
} finally {
LOGGER.info("Task Kontrak Verification : Finishing Task Kontrak Verification");
}
}
}, day, hour, minute);
}
@Async
public void autoKontrakVerification() {
try {
if (CommonUtil.isNotNullOrEmpty(logbookKinerjaService)) {
LOGGER.info("Task Kontrak Verification : Running Automatic Kontrak Verification");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, +1);
logbookKinerjaService.autoVerifKontrakJamKerjaDokter(cal.getTime());
} else {
LOGGER.warn("Task Kontrak Verification : Undefined service");
}
} catch (Exception ex) {
LOGGER.error("Task Kontrak Verification : Automatic Kontrak Verification " + ex.getMessage());
} finally {
LOGGER.info("Task Kontrak Verification : Finishing Automatic Kontrak Verification");
}
}
}

View File

@ -0,0 +1,90 @@
package com.jasamedika.medifirst2000.asynctask.timer;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class KontrakVerificationTimer {
private final static Logger LOGGER = LoggerFactory.getLogger(KontrakVerificationTimer.class);
// What to do
private final Runnable whatToDo;
// when
private final int dayOfMonth;
private final int hourOfDay;
private final int minuteOfHour;
// The current timer
private Timer current = new Timer();
public void cancelCurrent() {
LOGGER.info("KontrakVerificationTimer : Cancel current execution");
current.cancel();
LOGGER.info("KontrakVerificationTimer : Removes the timertask so it can be garbage collected");
current.purge();
}
public static KontrakVerificationTimer schedule(Runnable runnable, int dayOfMonth, int hourOfDay, int minuteOfHour) {
LOGGER.info("KontrakVerificationTimer : Create a new instance");
return new KontrakVerificationTimer(runnable, dayOfMonth, hourOfDay, minuteOfHour);
}
private KontrakVerificationTimer(Runnable runnable, int day, int hour, int minute) {
this.whatToDo = runnable;
this.dayOfMonth = day;
this.hourOfDay = hour;
this.minuteOfHour = minute;
schedule();
}
private void schedule() {
cancelCurrent();
LOGGER.info(
"KontrakVerificationTimer : Assigning a new instance of Timer, allow the previous Timer to be garbage collected");
current = new Timer();
current.schedule(new TimerTask() {
public void run() {
try {
LOGGER.info("KontrakVerificationTimer : Running schedule");
whatToDo.run();
} finally {
LOGGER.info("KontrakVerificationTimer : Schedule for the next month");
schedule();
}
}
}, nextDate());
}
private Date nextDate() {
Calendar curDate = Calendar.getInstance();
Calendar runDate = Calendar.getInstance();
// set_for_compare
runDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
runDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
runDate.set(Calendar.MINUTE, minuteOfHour);
runDate.set(Calendar.SECOND, 0);
runDate.set(Calendar.MILLISECOND, 0);
if (curDate.getTime().after(runDate.getTime())) {
runDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
runDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
runDate.set(Calendar.MINUTE, minuteOfHour);
runDate.set(Calendar.SECOND, 0);
runDate.set(Calendar.MILLISECOND, 0);
runDate.add(Calendar.MONTH, 1);
}
LOGGER.info("KontrakVerificationTimer : Set to next month " + runDate.getTime());
return runDate.getTime();
}
}