service
parent
e6343ce179
commit
a0cb4ae2ee
@ -0,0 +1,31 @@
|
|||||||
|
package com.service.ingresantes.controller;
|
||||||
|
|
||||||
|
import com.service.ingresantes.service.CalificacionCursoService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/calificacion")
|
||||||
|
public class CalificacionController {
|
||||||
|
|
||||||
|
private final CalificacionCursoService calificacionCursoService;
|
||||||
|
|
||||||
|
public CalificacionController(CalificacionCursoService calificacionCursoService) {
|
||||||
|
this.calificacionCursoService = calificacionCursoService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/calificar/{procesoId}")
|
||||||
|
public Map<String, Object> calificarCursos(@PathVariable Long procesoId) {
|
||||||
|
|
||||||
|
int registros = calificacionCursoService.calificarCursos(procesoId);
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("mensaje", "Calificación por asignaturas completada");
|
||||||
|
response.put("proceso", procesoId);
|
||||||
|
response.put("registros_generados", registros);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.service.ingresantes.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "resultado_asignatura")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ResultadoAsignatura {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// resultado del examen
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "resultado_examen_id", nullable = false)
|
||||||
|
private ResultadoExamen resultadoExamen;
|
||||||
|
|
||||||
|
// proceso
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "proceso_id", nullable = false)
|
||||||
|
private Proceso proceso;
|
||||||
|
|
||||||
|
// área
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "area_id", nullable = false)
|
||||||
|
private Area area;
|
||||||
|
|
||||||
|
// curso
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "asignatura_id", nullable = false)
|
||||||
|
private Asignatura asignatura;
|
||||||
|
|
||||||
|
// estadísticas
|
||||||
|
private Integer correctas;
|
||||||
|
private Integer incorrectas;
|
||||||
|
private Integer blanco;
|
||||||
|
|
||||||
|
private Double puntaje;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.service.ingresantes.repository;
|
||||||
|
|
||||||
|
import com.service.ingresantes.entity.ResultadoAsignatura;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface ResultadoAsignaturaRepository extends JpaRepository<ResultadoAsignatura, Long> {
|
||||||
|
|
||||||
|
boolean existsByProcesoId(Long procesoId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
package com.service.ingresantes.service;
|
||||||
|
|
||||||
|
import com.service.ingresantes.entity.*;
|
||||||
|
import com.service.ingresantes.repository.*;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class CalificacionCursoService {
|
||||||
|
|
||||||
|
private final ResultadoExamenRepository resultadoRepo;
|
||||||
|
private final ClaveExamenRepository claveRepo;
|
||||||
|
private final AsignaturaRepository asignaturaRepo;
|
||||||
|
private final ResultadoAsignaturaRepository resultadoAsignaturaRepo;
|
||||||
|
|
||||||
|
public CalificacionCursoService(
|
||||||
|
ResultadoExamenRepository resultadoRepo,
|
||||||
|
ClaveExamenRepository claveRepo,
|
||||||
|
AsignaturaRepository asignaturaRepo,
|
||||||
|
ResultadoAsignaturaRepository resultadoAsignaturaRepo) {
|
||||||
|
|
||||||
|
this.resultadoRepo = resultadoRepo;
|
||||||
|
this.claveRepo = claveRepo;
|
||||||
|
this.asignaturaRepo = asignaturaRepo;
|
||||||
|
this.resultadoAsignaturaRepo = resultadoAsignaturaRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calificarCursos(Long procesoId) {
|
||||||
|
|
||||||
|
|
||||||
|
if (resultadoAsignaturaRepo.existsByProcesoId(procesoId)) {
|
||||||
|
throw new RuntimeException("Este proceso ya fue calificado por cursos");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ResultadoExamen> resultados = resultadoRepo.findByProcesoId(procesoId);
|
||||||
|
|
||||||
|
List<ResultadoAsignatura> listaGuardar = new ArrayList<>();
|
||||||
|
|
||||||
|
for (ResultadoExamen resultado : resultados) {
|
||||||
|
|
||||||
|
String respuestas = resultado.getRespuestas();
|
||||||
|
|
||||||
|
if (respuestas == null || respuestas.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Long areaId = Long.parseLong(resultado.getIdExamen());
|
||||||
|
String tipo = resultado.getTipo();
|
||||||
|
|
||||||
|
Optional<ClaveExamen> claveOpt =
|
||||||
|
claveRepo.findByProcesoIdAndAreaIdAndTipo(
|
||||||
|
procesoId,
|
||||||
|
areaId,
|
||||||
|
tipo
|
||||||
|
);
|
||||||
|
|
||||||
|
if (claveOpt.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String clave = claveOpt.get().getClave();
|
||||||
|
|
||||||
|
List<Asignatura> asignaturas =
|
||||||
|
asignaturaRepo.findByAreaIdOrderByCodigo(areaId);
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
for (Asignatura asignatura : asignaturas) {
|
||||||
|
|
||||||
|
int preguntas = asignatura.getCantidadPreguntas();
|
||||||
|
int fin = pos + preguntas;
|
||||||
|
|
||||||
|
if (fin > respuestas.length())
|
||||||
|
break;
|
||||||
|
|
||||||
|
String resp = respuestas.substring(pos, fin);
|
||||||
|
String cla = clave.substring(pos, fin);
|
||||||
|
|
||||||
|
int correctas = 0;
|
||||||
|
int incorrectas = 0;
|
||||||
|
int blanco = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < resp.length(); i++) {
|
||||||
|
|
||||||
|
char r = resp.charAt(i);
|
||||||
|
char c = cla.charAt(i);
|
||||||
|
|
||||||
|
if (r == ' ' || r == '0') {
|
||||||
|
blanco++;
|
||||||
|
}
|
||||||
|
else if (r == c) {
|
||||||
|
correctas++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
incorrectas++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double ponderacion = asignatura.getPonderacion();
|
||||||
|
|
||||||
|
double puntaje =
|
||||||
|
(correctas * 10 * ponderacion) +
|
||||||
|
(blanco * 2 * ponderacion);
|
||||||
|
|
||||||
|
ResultadoAsignatura resultadoAsignatura = ResultadoAsignatura.builder()
|
||||||
|
.resultadoExamen(resultado)
|
||||||
|
.proceso(resultado.getProceso())
|
||||||
|
.area(asignatura.getArea())
|
||||||
|
.asignatura(asignatura)
|
||||||
|
.correctas(correctas)
|
||||||
|
.incorrectas(incorrectas)
|
||||||
|
.blanco(blanco)
|
||||||
|
.puntaje(puntaje)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
listaGuardar.add(resultadoAsignatura);
|
||||||
|
|
||||||
|
pos = fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultadoAsignaturaRepo.saveAll(listaGuardar);
|
||||||
|
|
||||||
|
return listaGuardar.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue