cddcdcd
parent
1bfa6a6ade
commit
e6343ce179
@ -0,0 +1,44 @@
|
||||
package com.service.ingresantes.controller;
|
||||
|
||||
import com.service.ingresantes.service.CarpetaExamenService;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/examen")
|
||||
@CrossOrigin("*")
|
||||
public class CarpetaExamenController {
|
||||
|
||||
private final CarpetaExamenService carpetaService;
|
||||
|
||||
public CarpetaExamenController(CarpetaExamenService carpetaService) {
|
||||
this.carpetaService = carpetaService;
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity<?> subirArchivo(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("tipo") String tipo,
|
||||
@RequestParam("procesoId") Long procesoId,
|
||||
@RequestParam("areaId") Long areaId) {
|
||||
|
||||
try {
|
||||
|
||||
if (file.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("Archivo vacío");
|
||||
}
|
||||
|
||||
carpetaService.subirArchivo(file, tipo, procesoId, areaId);
|
||||
|
||||
return ResponseEntity.ok("Archivo .dat subido correctamente");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
return ResponseEntity
|
||||
.badRequest()
|
||||
.body("Error al subir archivo: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.service.ingresantes.controller;
|
||||
|
||||
import com.service.ingresantes.service.ClaveExamenService;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/claves")
|
||||
@CrossOrigin("*")
|
||||
public class ClaveExamenController {
|
||||
|
||||
private final ClaveExamenService claveService;
|
||||
|
||||
public ClaveExamenController(ClaveExamenService claveService) {
|
||||
this.claveService = claveService;
|
||||
}
|
||||
|
||||
@PostMapping("/procesar")
|
||||
public ResponseEntity<?> procesarClaves(
|
||||
@RequestParam("procesoId") Long procesoId,
|
||||
@RequestParam("areaId") Long areaId) {
|
||||
|
||||
try {
|
||||
int guardadas = claveService.procesarClaves(procesoId, areaId);
|
||||
return ResponseEntity.ok("Claves procesadas y guardadas correctamente: " + guardadas);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity
|
||||
.badRequest()
|
||||
.body("Error al procesar claves: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.service.ingresantes.controller;
|
||||
|
||||
import com.service.ingresantes.service.ExcelResultadoService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/excel")
|
||||
@CrossOrigin("*")
|
||||
public class ExcelResultadoController {
|
||||
|
||||
private final ExcelResultadoService excelResultadoService;
|
||||
|
||||
public ExcelResultadoController(ExcelResultadoService excelResultadoService) {
|
||||
this.excelResultadoService = excelResultadoService;
|
||||
}
|
||||
|
||||
@PostMapping("/upload-resultados")
|
||||
public ResponseEntity<String> uploadResultados(
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
|
||||
if (file.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("El archivo está vacío");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
excelResultadoService.importarExcelResultados(file);
|
||||
|
||||
return ResponseEntity.ok("Archivo de resultados procesado correctamente");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
return ResponseEntity
|
||||
.badRequest()
|
||||
.body("Error al procesar el archivo: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.service.ingresantes.controller;
|
||||
|
||||
import com.service.ingresantes.entity.ResultadoExamen;
|
||||
import com.service.ingresantes.service.ResultadoService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/resultados")
|
||||
@CrossOrigin("*")
|
||||
public class ResultadoController {
|
||||
|
||||
private final ResultadoService resultadoService;
|
||||
|
||||
public ResultadoController(ResultadoService resultadoService) {
|
||||
this.resultadoService = resultadoService;
|
||||
}
|
||||
|
||||
// Buscar resultado por DNI y proceso
|
||||
@GetMapping("/{dni}/{procesoId}")
|
||||
public ResponseEntity<?> obtenerResultado(
|
||||
@PathVariable String dni,
|
||||
@PathVariable Long procesoId) {
|
||||
|
||||
Optional<ResultadoExamen> resultado =
|
||||
resultadoService.obtenerResultado(dni, procesoId);
|
||||
|
||||
if (resultado.isEmpty()) {
|
||||
|
||||
return ResponseEntity
|
||||
.badRequest()
|
||||
.body("No se encontró resultado para ese DNI y proceso");
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(resultado.get());
|
||||
}
|
||||
|
||||
// Ranking del proceso
|
||||
@GetMapping("/ranking/{procesoId}")
|
||||
public ResponseEntity<List<ResultadoExamen>> ranking(
|
||||
@PathVariable Long procesoId) {
|
||||
|
||||
List<ResultadoExamen> ranking =
|
||||
resultadoService.obtenerRanking(procesoId);
|
||||
|
||||
return ResponseEntity.ok(ranking);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.service.ingresantes.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "clave_examen")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ClaveExamen {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "id_examen")
|
||||
private String idExamen;
|
||||
|
||||
private String tipo;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String clave;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "proceso_id")
|
||||
private Proceso proceso;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "area_id")
|
||||
private Area area;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.service.ingresantes.repository;
|
||||
|
||||
import com.service.ingresantes.entity.ClaveExamen;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ClaveExamenRepository extends JpaRepository<ClaveExamen, Long> {
|
||||
|
||||
// Busca una clave por proceso, área e idExamen
|
||||
Optional<ClaveExamen> findByProcesoIdAndAreaIdAndIdExamen(Long procesoId, Long areaId, String idExamen);
|
||||
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package com.service.ingresantes.service;
|
||||
|
||||
import com.service.ingresantes.entity.Area;
|
||||
import com.service.ingresantes.entity.CarpetaExamen;
|
||||
import com.service.ingresantes.entity.Proceso;
|
||||
import com.service.ingresantes.repository.AreaRepository;
|
||||
import com.service.ingresantes.repository.CarpetaExamenRepository;
|
||||
import com.service.ingresantes.repository.ProcesoRepository;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Service
|
||||
public class CarpetaExamenService {
|
||||
|
||||
private final CarpetaExamenRepository carpetaRepo;
|
||||
private final ProcesoRepository procesoRepo;
|
||||
private final AreaRepository areaRepo;
|
||||
|
||||
public CarpetaExamenService(
|
||||
CarpetaExamenRepository carpetaRepo,
|
||||
ProcesoRepository procesoRepo,
|
||||
AreaRepository areaRepo) {
|
||||
|
||||
this.carpetaRepo = carpetaRepo;
|
||||
this.procesoRepo = procesoRepo;
|
||||
this.areaRepo = areaRepo;
|
||||
}
|
||||
|
||||
public void subirArchivo(
|
||||
MultipartFile file,
|
||||
String tipo,
|
||||
Long procesoId,
|
||||
Long areaId) throws Exception {
|
||||
|
||||
Proceso proceso = procesoRepo.findById(procesoId)
|
||||
.orElseThrow(() -> new RuntimeException("Proceso no existe"));
|
||||
|
||||
Area area = areaRepo.findById(areaId)
|
||||
.orElseThrow(() -> new RuntimeException("Area no existe"));
|
||||
|
||||
String rutaBase = System.getProperty("user.dir") +
|
||||
"/examenes/" + procesoId + "/" + areaId + "/";
|
||||
|
||||
File carpeta = new File(rutaBase);
|
||||
|
||||
if (!carpeta.exists()) {
|
||||
carpeta.mkdirs();
|
||||
}
|
||||
|
||||
String nombreArchivo = file.getOriginalFilename();
|
||||
|
||||
File destino = new File(rutaBase + nombreArchivo);
|
||||
|
||||
file.transferTo(destino);
|
||||
|
||||
CarpetaExamen carpetaExamen = CarpetaExamen.builder()
|
||||
.tipo(tipo)
|
||||
.ruta(destino.getAbsolutePath())
|
||||
.proceso(proceso)
|
||||
.area(area)
|
||||
.build();
|
||||
|
||||
carpetaRepo.save(carpetaExamen);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,162 @@
|
||||
package com.service.ingresantes.service;
|
||||
|
||||
import com.service.ingresantes.entity.Inscripcion;
|
||||
import com.service.ingresantes.entity.ResultadoExamen;
|
||||
import com.service.ingresantes.repository.InscripcionRepository;
|
||||
import com.service.ingresantes.repository.ResultadoExamenRepository;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class ExcelResultadoService {
|
||||
|
||||
private final InscripcionRepository inscripcionRepo;
|
||||
private final ResultadoExamenRepository resultadoRepo;
|
||||
|
||||
public ExcelResultadoService(
|
||||
InscripcionRepository inscripcionRepo,
|
||||
ResultadoExamenRepository resultadoRepo) {
|
||||
|
||||
this.inscripcionRepo = inscripcionRepo;
|
||||
this.resultadoRepo = resultadoRepo;
|
||||
}
|
||||
|
||||
private String getCellString(Cell cell) {
|
||||
|
||||
if (cell == null) return "";
|
||||
|
||||
switch (cell.getCellType()) {
|
||||
|
||||
case STRING:
|
||||
return cell.getStringCellValue().trim();
|
||||
|
||||
case NUMERIC:
|
||||
return String.valueOf((long) cell.getNumericCellValue());
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private Double getCellDouble(Cell cell) {
|
||||
|
||||
if (cell == null) return null;
|
||||
|
||||
if (cell.getCellType() == CellType.NUMERIC) {
|
||||
return cell.getNumericCellValue();
|
||||
}
|
||||
|
||||
if (cell.getCellType() == CellType.STRING) {
|
||||
return Double.parseDouble(cell.getStringCellValue());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer getCellInteger(Cell cell) {
|
||||
|
||||
if (cell == null) return null;
|
||||
|
||||
if (cell.getCellType() == CellType.NUMERIC) {
|
||||
return (int) cell.getNumericCellValue();
|
||||
}
|
||||
|
||||
if (cell.getCellType() == CellType.STRING) {
|
||||
return Integer.parseInt(cell.getStringCellValue());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void importarExcelResultados(MultipartFile file) throws Exception {
|
||||
|
||||
InputStream is = file.getInputStream();
|
||||
Workbook workbook = WorkbookFactory.create(is);
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
for (Row row : sheet) {
|
||||
|
||||
if (row.getRowNum() == 0) continue;
|
||||
|
||||
try {
|
||||
|
||||
String dni = getCellString(row.getCell(0));
|
||||
String procesoStr = getCellString(row.getCell(1));
|
||||
|
||||
if (dni.isEmpty() || procesoStr.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Long procesoId = Long.parseLong(procesoStr);
|
||||
|
||||
Optional<Inscripcion> inscripcionOpt =
|
||||
inscripcionRepo.findByPostulanteDniAndProcesoId(dni, procesoId);
|
||||
|
||||
if (inscripcionOpt.isEmpty()) {
|
||||
|
||||
System.out.println("No existe inscripción -> DNI " + dni);
|
||||
continue;
|
||||
}
|
||||
|
||||
Inscripcion inscripcion = inscripcionOpt.get();
|
||||
|
||||
if (resultadoRepo.existsByInscripcionId(inscripcion.getId())) {
|
||||
|
||||
System.out.println("Resultado ya existe -> DNI " + dni);
|
||||
continue;
|
||||
}
|
||||
|
||||
Double puntaje = getCellDouble(row.getCell(2));
|
||||
String apto = getCellString(row.getCell(3));
|
||||
String obs = getCellString(row.getCell(4));
|
||||
|
||||
String idExamen = getCellString(row.getCell(5));
|
||||
String litho = getCellString(row.getCell(6));
|
||||
String numLectura = getCellString(row.getCell(7));
|
||||
String tipo = getCellString(row.getCell(8));
|
||||
String calificar = getCellString(row.getCell(9));
|
||||
String aula = getCellString(row.getCell(10));
|
||||
String respuestas = getCellString(row.getCell(11));
|
||||
|
||||
Integer puesto = getCellInteger(row.getCell(12));
|
||||
|
||||
ResultadoExamen resultado = new ResultadoExamen();
|
||||
|
||||
resultado.setInscripcion(inscripcion);
|
||||
resultado.setProceso(inscripcion.getProceso());
|
||||
|
||||
resultado.setPuntaje(puntaje);
|
||||
resultado.setApto(apto);
|
||||
resultado.setObs(obs);
|
||||
|
||||
resultado.setIdExamen(idExamen);
|
||||
resultado.setLitho(litho);
|
||||
resultado.setNumLectura(numLectura);
|
||||
resultado.setTipo(tipo);
|
||||
resultado.setCalificar(calificar);
|
||||
resultado.setAula(aula);
|
||||
resultado.setRespuestas(respuestas);
|
||||
|
||||
resultado.setPuesto(puesto);
|
||||
|
||||
resultadoRepo.save(resultado);
|
||||
|
||||
System.out.println("Resultado guardado -> DNI " + dni);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println("Error fila " + row.getRowNum() + " -> " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
workbook.close();
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.service.ingresantes.service;
|
||||
|
||||
import com.service.ingresantes.entity.ResultadoExamen;
|
||||
import com.service.ingresantes.repository.ResultadoExamenRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class ResultadoService {
|
||||
|
||||
private final ResultadoExamenRepository resultadoRepo;
|
||||
|
||||
public ResultadoService(ResultadoExamenRepository resultadoRepo) {
|
||||
this.resultadoRepo = resultadoRepo;
|
||||
}
|
||||
|
||||
// Buscar resultado por DNI y proceso
|
||||
public Optional<ResultadoExamen> obtenerResultado(String dni, Long procesoId) {
|
||||
|
||||
return resultadoRepo.findByDniAndProceso(dni, procesoId);
|
||||
}
|
||||
|
||||
// Ranking por proceso
|
||||
public List<ResultadoExamen> obtenerRanking(Long procesoId) {
|
||||
|
||||
return resultadoRepo.findRankingByProceso(procesoId);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue