106 lines
4.2 KiB
Plaintext
Executable File
106 lines
4.2 KiB
Plaintext
Executable File
package com.fp.general.rules.query.code;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import javax.persistence.Query;
|
||
|
||
import com.fp.common.helper.Constant;
|
||
import com.fp.dto.query.QueryBean;
|
||
import com.fp.dto.query.QueryRequest;
|
||
import com.fp.dto.rules.QueryRule;
|
||
import com.fp.general.exception.GeneralException;
|
||
import com.fp.persistence.commondb.GeneralQuery;
|
||
import com.fp.persistence.commondb.PersistenceHelper;
|
||
|
||
/**
|
||
* Clase que se encarga de enviar los datos necesarios de clientes
|
||
*
|
||
* @author jarias
|
||
*
|
||
*/
|
||
public class LovCustomerMulti extends QueryRule {
|
||
|
||
/**
|
||
*
|
||
*/
|
||
private static final long serialVersionUID = 1L;
|
||
|
||
/**
|
||
* JPQL que obtiene informacion de personas
|
||
*/
|
||
private static final String JPQL_CUSTOMER = "select t.personcode, persontypecatalog,identification,name,"
|
||
+ " (select cd.description from TgeneCatalogDetail cd " + " where cd.catalogcode = t.identificationcatalogcode "
|
||
+ " and cd.catalog = t.identificationcatalog " + " ) as identificationdesc, "
|
||
+ " (select photocode from TcustPeople tp" + " where tp.personcode = t.personcode "
|
||
+ " and tp.dateto = t.dateto " + " ) as photocode " + " from TcustPersonDetail t " + " where t.dateto = :dateto ";
|
||
|
||
/**
|
||
* Metodo que construye la respuesta solo con los datos necesarios
|
||
*
|
||
* @param pQueryRequest QueryRequest
|
||
* @return pQueryRequest QueryRequest
|
||
* @throws Exception
|
||
*/
|
||
@Override
|
||
public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
|
||
// TODO Auto-generated method stub
|
||
QueryBean qb = (QueryBean) pQueryRequest.get("TCUSTPERSONDETAILLOVMULTI");
|
||
List<Map<String, Object>> lfinalresult = new ArrayList<Map<String, Object>>();
|
||
lfinalresult = this.resultPersons(qb);
|
||
pQueryRequest.getResponse().put("TCUSTPERSONDETAILLOVMULTI", lfinalresult);
|
||
return pQueryRequest;
|
||
}
|
||
|
||
/**
|
||
* M<>todo que retorna la busqueda de las personas
|
||
*
|
||
* @param qb QueryBean
|
||
* @return lfinal lista que contiene los clienets consultados
|
||
* @throws Exception
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public List<Map<String, Object>> resultPersons(QueryBean qb) throws Exception {
|
||
String[] resp = CriteriaValidator.validatePercentage(qb);
|
||
if (resp[0].compareTo("0") == 0) {
|
||
throw new GeneralException("GENE-0043", "EL CRITERIO DE B<>SQUEDA --> {0} NO ES SUFICIENTE", resp[1]);
|
||
}
|
||
List<Map<String, Object>> lfinal = new ArrayList<Map<String, Object>>();
|
||
Map<String, Object> mcriteria = new HashMap<String, Object>();
|
||
StringBuilder jpql = new StringBuilder();
|
||
jpql.append(LovCustomerMulti.JPQL_CUSTOMER);
|
||
GeneralQuery.addParameters(qb, jpql, mcriteria, true);
|
||
Query qry = PersistenceHelper.getEntityManager().createNativeQuery(String.valueOf(jpql));
|
||
qry.setParameter("dateto", Constant.getDefaultExpiryTimestamp());
|
||
GeneralQuery.setParameters(qb, mcriteria, qry);
|
||
List<Object[]> ldata = qry.getResultList();
|
||
|
||
if ((ldata != null) && (!ldata.isEmpty())) {
|
||
for (Object[] obj : ldata) {
|
||
Map<String, Object> m = new HashMap<String, Object>();
|
||
m.put("pk_personcode", obj[0]);
|
||
m.put("persontypecatalog", obj[1]);
|
||
m.put("identification", obj[2]);
|
||
m.put("name", obj[3]);
|
||
m.put("identificationdesc", obj[4]);
|
||
m.put("photocode", obj[5]);
|
||
lfinal.add(m);
|
||
}
|
||
} else {
|
||
if (qb.getPage() == 1) {
|
||
Map<String, Object> m = new HashMap<String, Object>();
|
||
m.put("pk_personcode", null);
|
||
m.put("persontypecatalog", null);
|
||
m.put("identification", null);
|
||
m.put("name", null);
|
||
m.put("identificationdesc", null);
|
||
m.put("photocode", null);
|
||
lfinal.add(m);
|
||
}
|
||
}
|
||
return lfinal;
|
||
}
|
||
}
|