139 lines
7.0 KiB
Plaintext
Executable File
139 lines
7.0 KiB
Plaintext
Executable File
package com.fp.general.score.save;
|
|
|
|
import com.fp.dto.save.SaveRequest;
|
|
import com.fp.excel.ExcelToMap;
|
|
import com.fp.general.exception.GeneralException;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.commondb.helper.FormatDates;
|
|
import com.fp.persistence.pgeneral.score.TgeneScoreAdjustment;
|
|
import com.fp.persistence.pgeneral.score.TgeneScoreAdjustmentKey;
|
|
import com.fp.persistence.pgeneral.score.TgeneScoreHeader;
|
|
import com.fp.persistence.pgeneral.image.TgeneFilesDetail;
|
|
import com.fp.persistence.pgeneral.image.TgeneFilesDetailKey;
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.sql.Timestamp;
|
|
/**
|
|
* Clase que graba la data recibida de Excel en la tabla TGENESCOREADJUSTMENT
|
|
*
|
|
* @author BPTWPA
|
|
*/
|
|
public class FileScore {
|
|
|
|
/**
|
|
* Mètodo que graba en la base de datos las calificaciones de cartera subidas en excel
|
|
*
|
|
* @param tgeneScoreHeader Objeto TgeneScoreHeader
|
|
* @param excelMap Mapa obtenido del archivo de excel
|
|
* @throws Exception
|
|
*/
|
|
public List<TgeneScoreAdjustment> loadScore(TgeneScoreHeader tgeneScoreHeader, SaveRequest sr, Integer filecode) throws Exception {
|
|
List<TgeneScoreAdjustment> lTgeneScoreAdjustment = new ArrayList<TgeneScoreAdjustment>();
|
|
Map<String, Object> mapExcel = null;
|
|
TgeneFilesDetail filesDetail = TgeneFilesDetail.find(PersistenceHelper.getEntityManager(), new TgeneFilesDetailKey(filecode,
|
|
FormatDates.getDefaultExpiryTimestamp()));
|
|
if (tgeneScoreHeader != null && filesDetail != null) {
|
|
if (filesDetail.getExtension().equals("xls") || filesDetail.getExtension().equals("xlsx")) {
|
|
ExcelToMap excelMap = new ExcelToMap(filesDetail.getImage(), filesDetail.getExtension());
|
|
mapExcel = excelMap.getExcelMap();
|
|
if (mapExcel != null || !mapExcel.isEmpty()) {
|
|
Integer rows = (mapExcel.size() / 8)-1;
|
|
for (int i = 1; i <= rows ; i++) {
|
|
TgeneScoreAdjustment tgeneScoreAdjustment = new TgeneScoreAdjustment();
|
|
TgeneScoreAdjustmentKey key = new TgeneScoreAdjustmentKey();
|
|
for (int j = 0; j < 8; j++) {
|
|
String parameter = i + ":" + j;
|
|
Object value = null;
|
|
switch (j) {
|
|
case 0: //COMPANIA
|
|
if(!(tgeneScoreHeader.getPk().getScoredate().compareTo((Date) mapExcel.get(parameter)) == 0)){
|
|
throw new GeneralException("GENE-0043", "LA FECHA DEL ARCHIVO NO CONCUERDA CON LA SELECCIONADA");
|
|
}
|
|
|
|
this.contentParameter(parameter, mapExcel);
|
|
key.setScoredate(new Timestamp(tgeneScoreHeader.getPk().getScoredate().getTime()));
|
|
|
|
break;
|
|
case 1: //CUENTA
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
key.setAccount(String.valueOf(value));
|
|
tgeneScoreAdjustment.setPk(key);
|
|
break;
|
|
case 2: //MODULO
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setModulecode(String.valueOf(value));
|
|
break;
|
|
case 3: //PRODUCTO
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setProductcode(String.valueOf(value));
|
|
break;
|
|
case 4: //SUBPRODUCTO
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setSubproductcode(String.valueOf(value));
|
|
break;
|
|
case 5: //MONEDA
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setCurrencycode(String.valueOf(value));
|
|
break;
|
|
case 6: //PORCENTAJE PROVISION
|
|
this.contentParameter(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setManualprovisionpercent(new BigDecimal(value.getClass().getSimpleName().equals("BigDecimal") ? String.valueOf(value) : "0"));
|
|
break;
|
|
case 7: //TIPO AJUSTE, JOURNAL ID
|
|
this.contentParameter(parameter, mapExcel);
|
|
this.verifyFile(parameter, mapExcel);
|
|
value = mapExcel.get(parameter);
|
|
tgeneScoreAdjustment.setAdjustmenttype(String.valueOf(value));
|
|
tgeneScoreAdjustment.setJournalid(sr.getJournalId());
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
lTgeneScoreAdjustment.add(tgeneScoreAdjustment);
|
|
}
|
|
}
|
|
} else {
|
|
throw new GeneralException("GENE-0043", "El ARCHIVO NO ES EL CORRECTO - CALIFICACION CARTERA");
|
|
}
|
|
}
|
|
|
|
return lTgeneScoreAdjustment;
|
|
}
|
|
|
|
/**
|
|
* Método que valida que el valor que viene en el archivo sea el correcto
|
|
* @param parameter
|
|
* @param mapExcel
|
|
* @throws Exception
|
|
*/
|
|
private void contentParameter(String parameter, Map<String, Object> mapExcel) throws Exception {
|
|
if (!mapExcel.containsKey(parameter)) {
|
|
throw new GeneralException("GENE-0044", "PARÁMETRO NO ENCONTRADO");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Método que valida que el archivo sea el correcto
|
|
* @param parameter
|
|
* @param mapExcel
|
|
* @throws Exception
|
|
*/
|
|
private void verifyFile(String parameter, Map<String, Object> mapExcel) throws Exception {
|
|
this.contentParameter(parameter, mapExcel);
|
|
String value = (String) mapExcel.get(parameter); //Object
|
|
if (!(String.valueOf(value).compareTo("F") == 0)) {
|
|
throw new GeneralException("GENE-0043", "El ARCHIVO NO ES EL CORRECTO - CALIFICACION CARTERA");
|
|
}
|
|
}
|
|
}
|