175 lines
5.4 KiB
Plaintext
Executable File
175 lines
5.4 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.parametros;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.Filter;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.fun.TarmTotalPersona;
|
|
|
|
public class TotalPersonaController extends AbstractController<TarmTotalPersona> {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public TotalPersonaController() throws Exception {
|
|
super(TarmTotalPersona.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
private void init() {
|
|
try {
|
|
recperpage = 100; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "TOTALPERSONACONTROLLER";
|
|
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
|
|
if(this.getMfilelds().get("fechamaxima") != null){
|
|
Filter filter= new Filter();
|
|
filter.setSql(this.getMfilelds().get("fechamaxima").toString());
|
|
dto.addFiltro(filter);
|
|
}
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = this.callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = this.callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmTotalPersona>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmTotalPersona>) resp.get(beanalias);
|
|
if(!lrecord.isEmpty()){
|
|
Collections.sort(lrecord, new Comparator<TarmTotalPersona>() {
|
|
public int compare(TarmTotalPersona o1, TarmTotalPersona o2) {
|
|
return ((Date)(o1.getFecha())).after((Date)(o2.getFecha())) ? -1 : 1;
|
|
}
|
|
});
|
|
record=lrecord.get(0);
|
|
}
|
|
super.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
DtoSave dtosave = super.getDtoSave();
|
|
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos.
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
|
|
Request request = callerhelper.getRequest();
|
|
msave.put(beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, beanalias);
|
|
}
|
|
|
|
public void update(TarmTotalPersona bean) throws Exception {
|
|
record=bean;
|
|
super.update();
|
|
}
|
|
|
|
|
|
/**
|
|
* Busca el total de un arma para una persona
|
|
*/
|
|
public static TarmTotalPersona find(String clase, String tipoArmaEplosivo, String codigoPersona) {
|
|
try {
|
|
TotalPersonaController cc = new TotalPersonaController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("clase", clase);
|
|
cc.addFilter("tipoarmaexplosivo", tipoArmaEplosivo);
|
|
cc.addFilter("personcodigo", codigoPersona);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Busca el total de un arma para una persona
|
|
*/
|
|
public static TarmTotalPersona findMaxFecha(String clase, String tipoArmaEplosivo, String codigoPersona,String unidad) {
|
|
try {
|
|
TotalPersonaController cc = new TotalPersonaController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("clase", clase);
|
|
cc.addFilter("tipoarmaexplosivo", tipoArmaEplosivo);
|
|
cc.addFilter("personcodigo", codigoPersona);
|
|
cc.addField("fechamaxima", "t.fecha=(select max(o.fecha) from TarmTotalPersona o where o.clase='"+clase+"' and tipoarmaexplosivo='"+tipoArmaEplosivo+"' and o.personcodigo='"+codigoPersona+"')");
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|