Update service log catatan kinerja harian

Perbaikan update rekap capaian logbook setelah hapus catatan kinerja sudah verifikasi
This commit is contained in:
Salman Manoe 2024-11-07 13:23:09 +07:00
parent 402fe4d024
commit 471164c649
11 changed files with 51 additions and 277 deletions

View File

@ -9,10 +9,13 @@ import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Repository("logbookKinerjaDao")
public interface LogbookKinerjaDao extends JpaRepository<LogbookKinerja, String> {
Optional<LogbookKinerja> findByNoRec(String noRec);
@Query("select new Map(lk.noRec as noRec," + "pg.id as pegawaiId,pg.namaLengkap as namaPegawai,"
+ "jb.id as jabatanId,jb.namaJabatan as namaJabatan,"
+ "ik.id as indikatorId,ik.namaIndikator as namaIndikator,"

View File

@ -2,12 +2,11 @@ package com.jasamedika.medifirst2000.dao;
import com.jasamedika.medifirst2000.entities.LogbookKinerjaDetailLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author salmanoe
* @version 1.0.0
* @since 31/10/2024
*/
public interface LogbookKinerjaDetailLogDao extends JpaRepository<LogbookKinerjaDetailLog, String>, JpaSpecificationExecutor<LogbookKinerjaDetailLog> {
public interface LogbookKinerjaDetailLogDao extends JpaRepository<LogbookKinerjaDetailLog, String> {
}

View File

@ -27,6 +27,7 @@ import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import static com.jasamedika.medifirst2000.constants.Master.SatuanIndikator.PERCENTAGE;
import static com.jasamedika.medifirst2000.enums.JenisLog.HAPUS;
@Service("LogbookKinerjaDetailService")
@ -61,8 +62,8 @@ public class LogbookKinerjaDetailServiceImpl extends BaseVoServiceImpl implement
* menghitung capaian indikator satuan yang harus dihitung secara
* akumulatif
*/
List<Map<String, Object>> dataSatuanJumlah = logbookKinerjaDetailDao.findSumCapaianByKontrak(
vo.getLogbookKinerja().getNoRec(), Arrays.asList(Master.SatuanIndikator.PERCENTAGE));
List<Map<String, Object>> dataSatuanJumlah = logbookKinerjaDetailDao
.findSumCapaianByKontrak(vo.getLogbookKinerja().getNoRec(), Arrays.asList(PERCENTAGE));
if (CommonUtil.isNotNullOrEmpty(dataSatuanJumlah)) {
List<LogbookKinerja> models = new ArrayList<>();
for (Map<String, Object> map : dataSatuanJumlah) {
@ -76,8 +77,8 @@ public class LogbookKinerjaDetailServiceImpl extends BaseVoServiceImpl implement
* menghitung capaian indikator satuan yang harus dihitung secara
* rata-rata
*/
List<Map<String, Object>> dataSatuanRatarata = logbookKinerjaDetailDao.findAvgCapaianByKontrak(
vo.getLogbookKinerja().getNoRec(), Arrays.asList(Master.SatuanIndikator.PERCENTAGE));
List<Map<String, Object>> dataSatuanRatarata = logbookKinerjaDetailDao
.findAvgCapaianByKontrak(vo.getLogbookKinerja().getNoRec(), Arrays.asList(PERCENTAGE));
if (CommonUtil.isNotNullOrEmpty(dataSatuanRatarata)) {
List<LogbookKinerja> models = new ArrayList<>();
for (Map<String, Object> map : dataSatuanRatarata) {
@ -106,8 +107,8 @@ public class LogbookKinerjaDetailServiceImpl extends BaseVoServiceImpl implement
* menghitung capaian indikator satuan yang harus dihitung secara
* akumulatif
*/
List<Map<String, Object>> dataSatuanJumlah = logbookKinerjaDetailDao.findSumCapaianByKontrak(
vo.getLogbookKinerja().getNoRec(), Arrays.asList(Master.SatuanIndikator.PERCENTAGE));
List<Map<String, Object>> dataSatuanJumlah = logbookKinerjaDetailDao
.findSumCapaianByKontrak(vo.getLogbookKinerja().getNoRec(), Arrays.asList(PERCENTAGE));
if (CommonUtil.isNotNullOrEmpty(dataSatuanJumlah)) {
List<LogbookKinerja> models = new ArrayList<>();
for (Map<String, Object> map : dataSatuanJumlah) {
@ -121,8 +122,8 @@ public class LogbookKinerjaDetailServiceImpl extends BaseVoServiceImpl implement
* menghitung capaian indikator satuan yang harus dihitung secara
* rata-rata
*/
List<Map<String, Object>> dataSatuanRatarata = logbookKinerjaDetailDao.findAvgCapaianByKontrak(
vo.getLogbookKinerja().getNoRec(), Arrays.asList(Master.SatuanIndikator.PERCENTAGE));
List<Map<String, Object>> dataSatuanRatarata = logbookKinerjaDetailDao
.findAvgCapaianByKontrak(vo.getLogbookKinerja().getNoRec(), Arrays.asList(PERCENTAGE));
if (CommonUtil.isNotNullOrEmpty(dataSatuanRatarata)) {
List<LogbookKinerja> models = new ArrayList<>();
for (Map<String, Object> map : dataSatuanRatarata) {
@ -303,14 +304,40 @@ public class LogbookKinerjaDetailServiceImpl extends BaseVoServiceImpl implement
@Override
public void hapusCatatanKinerja(String norec) {
Optional<LogbookKinerjaDetail> byNoRec = logbookKinerjaDetailDao.findByNoRec(norec);
byNoRec.ifPresent(d -> {
d.setStatusVerifikasi(false);
d.setStatusEnabled(false);
LogbookKinerjaDetailLogReqDto.LogbookKinerjaDetailLogReqDtoBuilder dtoBuilder = LogbookKinerjaDetailLogReqDto
.builder();
LogbookKinerjaDetailLogReqDto reqDto = dtoBuilder.catatanKinerjaId(norec).jenisLog(HAPUS).build();
logbookKinerjaDetailDao.save(d);
logCatatanKinerjaService.save(reqDto);
byNoRec.ifPresent(catatanKinerja -> {
{
catatanKinerja.setStatusVerifikasi(false);
catatanKinerja.setStatusEnabled(false);
logbookKinerjaDetailDao.save(catatanKinerja);
}
{
Optional<LogbookKinerja> byIdLogbook = logbookKinerjaDao
.findByNoRec(catatanKinerja.getLogbookKinerjaId());
byIdLogbook.ifPresent(logbookKinerja -> {
if (Arrays.asList(PERCENTAGE)
.contains(logbookKinerja.getIndikatorKinerja().getSatuanIndikatorId())) {
List<Map<String, Object>> listCatatan = logbookKinerjaDetailDao
.findAvgCapaianByKontrak(logbookKinerja.getNoRec(), Arrays.asList(PERCENTAGE));
Optional<Map<String, Object>> catatan = listCatatan.stream()
.filter(c -> logbookKinerja.getNoRec().equals(c.get("logbookId"))).findFirst();
catatan.ifPresent(
c -> logbookKinerja.setCapaian(Double.parseDouble(c.get("avgCapaian").toString())));
} else {
List<Map<String, Object>> listCatatan = logbookKinerjaDetailDao
.findSumCapaianByKontrak(logbookKinerja.getNoRec(), Arrays.asList(PERCENTAGE));
Optional<Map<String, Object>> catatan = listCatatan.stream()
.filter(c -> logbookKinerja.getNoRec().equals(c.get("logbookId"))).findFirst();
catatan.ifPresent(
c -> logbookKinerja.setCapaian(Double.parseDouble(c.get("sumCapaian").toString())));
}
logbookKinerjaDao.save(logbookKinerja);
});
}
{
LogbookKinerjaDetailLogReqDto reqDto = LogbookKinerjaDetailLogReqDto.builder().catatanKinerjaId(norec)
.jenisLog(HAPUS).build();
logCatatanKinerjaService.save(reqDto);
}
});
}

View File

@ -76,13 +76,6 @@
<artifactId>itextpdf</artifactId>
<version>5.5.9</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${project.lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<organization>
<name>Jasa Medika</name>

View File

@ -1,30 +0,0 @@
package com.jasamedika.medifirst2000.search;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author salmanoe
* @version 1.0.0
* @since 06/11/2024
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SearchCriteria {
private String filterKey;
private Object value;
private String operation;
private String dataOption;
public SearchCriteria(String filterKey, String operation, Object value) {
super();
this.filterKey = filterKey;
this.operation = operation;
this.value = value;
}
}

View File

@ -1,21 +0,0 @@
package com.jasamedika.medifirst2000.search;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author salmanoe
* @version 1.0.0
* @since 06/11/2024
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SearchDto {
private List<SearchCriteria> searchCriteria;
private String dataOption;
}

View File

@ -1,57 +0,0 @@
package com.jasamedika.medifirst2000.search;
/**
* @author salmanoe
* @version 1.0.0
* @since 06/11/2024
*/
public enum SearchOperation {
CONTAINS, DOES_NOT_CONTAIN, EQUAL, NOT_EQUAL, BEGINS_WITH, DOES_NOT_BEGIN_WITH, ENDS_WITH, DOES_NOT_END_WITH,
NULL, NOT_NULL, GREATER_THAN, GREATER_THAN_EQUAL, LESS_THAN, LESS_THAN_EQUAL, ANY, ALL;
public static SearchOperation getDataOption(final String dataOption) {
switch (dataOption) {
case "all":
return ALL;
case "any":
return ANY;
default:
return null;
}
}
public static SearchOperation getSimpleOperation(final String input) {
switch (input) {
case "cn":
return CONTAINS;
case "nc":
return DOES_NOT_CONTAIN;
case "eq":
return EQUAL;
case "ne":
return NOT_EQUAL;
case "bw":
return BEGINS_WITH;
case "bn":
return DOES_NOT_BEGIN_WITH;
case "ew":
return ENDS_WITH;
case "en":
return DOES_NOT_END_WITH;
case "nu":
return NULL;
case "nn":
return NOT_NULL;
case "gt":
return GREATER_THAN;
case "ge":
return GREATER_THAN_EQUAL;
case "lt":
return LESS_THAN;
case "le":
return LESS_THAN_EQUAL;
default:
return null;
}
}
}

View File

@ -9,8 +9,6 @@ import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static javax.persistence.FetchType.LAZY;
@Getter
@Setter
@Entity
@ -40,7 +38,7 @@ public class LogbookKinerja extends BaseTransaction {
@Caption(value = "Status Verifikasi")
private Boolean statusVerifikasi;
@ManyToOne(fetch = LAZY)
@ManyToOne
@NotNull(message = "Pegawai tidak boleh kosong")
@JoinColumn(name = "objectpegawaifk")
@Caption(value = "Pegawai")
@ -49,7 +47,7 @@ public class LogbookKinerja extends BaseTransaction {
@Column(name = "objectpegawaifk", insertable = false, updatable = false)
private Integer pegawaiId;
@ManyToOne(fetch = LAZY)
@ManyToOne
@NotNull(message = "Jabatan tidak boleh kosong")
@JoinColumn(name = "objectjabatanfk")
@Caption(value = "Jabatan")
@ -58,7 +56,7 @@ public class LogbookKinerja extends BaseTransaction {
@Column(name = "objectjabatanfk", insertable = false, updatable = false)
private Integer jabatanId;
@ManyToOne(fetch = LAZY)
@ManyToOne
@NotNull(message = "Indikator kinerja tidak boleh kosong")
@JoinColumn(name = "objectindikatorkinerjafk")
@Caption(value = "Indikator Kinerja")

View File

@ -9,8 +9,6 @@ import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static javax.persistence.FetchType.LAZY;
@Getter
@Setter
@Entity
@ -40,7 +38,7 @@ public class LogbookKinerjaDetail extends BaseTransaction {
@Caption(value = "Status Verifikasi")
private Boolean statusVerifikasi;
@ManyToOne(fetch = LAZY)
@ManyToOne
@NotNull(message = "Indikator kinerja tidak boleh kosong")
@JoinColumn(name = "objectlogbookkinerjafk")
@Caption(value = "Logbook Kinerja")

View File

@ -1,90 +0,0 @@
package com.jasamedika.medifirst2000.entities.spec;
import com.jasamedika.medifirst2000.entities.LogbookKinerjaDetailLog;
import com.jasamedika.medifirst2000.search.SearchCriteria;
import com.jasamedika.medifirst2000.search.SearchOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.Objects;
/**
* @author salmanoe
* @version 1.0.0
* @since 06/11/2024
*/
@RequiredArgsConstructor
public class LogbookKinerjaDetailLogSpec implements Specification<LogbookKinerjaDetailLog> {
@Autowired
private SearchCriteria searchCriteria;
@Override
public Predicate toPredicate(Root<LogbookKinerjaDetailLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
String strToSearch = searchCriteria.getValue().toString().toLowerCase();
switch (Objects.requireNonNull(SearchOperation.getSimpleOperation(searchCriteria.getOperation()))) {
case CONTAINS:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch + "%");
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch + "%");
case DOES_NOT_CONTAIN:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch + "%");
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch + "%");
case BEGINS_WITH:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), strToSearch + "%");
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), strToSearch + "%");
case DOES_NOT_BEGIN_WITH:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), strToSearch + "%");
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), strToSearch + "%");
case ENDS_WITH:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch);
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.like(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch);
case DOES_NOT_END_WITH:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch);
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.notLike(cb.lower(root.get(searchCriteria.getFilterKey())), "%" + strToSearch);
case EQUAL:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.equal(cb.lower(root.get(searchCriteria.getFilterKey())), searchCriteria.getValue());
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.equal(cb.lower(root.get(searchCriteria.getFilterKey())), searchCriteria.getValue());
case NOT_EQUAL:
if (searchCriteria.getFilterKey().equals("unitCode"))
return cb.notEqual(cb.lower(root.get(searchCriteria.getFilterKey())), searchCriteria.getValue());
if (searchCriteria.getFilterKey().equals("unitName"))
return cb.notEqual(cb.lower(root.get(searchCriteria.getFilterKey())), searchCriteria.getValue());
case NULL:
return cb.isNull(root.get(searchCriteria.getFilterKey()));
case NOT_NULL:
return cb.isNotNull(root.get(searchCriteria.getFilterKey()));
case GREATER_THAN:
return cb.greaterThan(root
.get(searchCriteria.getFilterKey()), searchCriteria.getValue().toString());
case GREATER_THAN_EQUAL:
return cb.greaterThanOrEqualTo(root
.get(searchCriteria.getFilterKey()), searchCriteria.getValue().toString());
case LESS_THAN:
return cb.lessThan(root
.get(searchCriteria.getFilterKey()), searchCriteria.getValue().toString());
case LESS_THAN_EQUAL:
return cb.lessThanOrEqualTo(root
.get(searchCriteria.getFilterKey()), searchCriteria.getValue().toString());
}
return null;
}
}

View File

@ -1,46 +0,0 @@
package com.jasamedika.medifirst2000.entities.spec;
import com.jasamedika.medifirst2000.entities.LogbookKinerjaDetailLog;
import com.jasamedika.medifirst2000.search.SearchCriteria;
import com.jasamedika.medifirst2000.search.SearchOperation;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
import java.util.ArrayList;
import java.util.List;
/**
* @author salmanoe
* @version 1.0.0
* @since 06/11/2024
*/
public class LogbookKinerjaDetailLogSpecBuilder {
private final List<SearchCriteria> params;
public LogbookKinerjaDetailLogSpecBuilder() {
this.params = new ArrayList<>();
}
public final LogbookKinerjaDetailLogSpecBuilder with(String key, String operation, Object value) {
params.add(new SearchCriteria(key, operation, value));
return this;
}
public final LogbookKinerjaDetailLogSpecBuilder with(SearchCriteria searchCriteria) {
params.add(searchCriteria);
return this;
}
public Specifications<LogbookKinerjaDetailLog> build() {
if (params.isEmpty())
return null;
Specification<LogbookKinerjaDetailLog> result = new LogbookKinerjaDetailLogSpec(params.get(0));
for (int idx = 1; idx < params.size(); idx++) {
SearchCriteria criteria = params.get(idx);
result = SearchOperation.getDataOption(criteria.getDataOption()) == SearchOperation.ALL
? Specification.where(result).and(new LogbookKinerjaDetailLogSpec(criteria))
: Specification.where(result).or(new LogbookKinerjaDetailLogSpec(criteria));
}
return result;
}
}