Commit 125be791 by Walter Rosado Estrada

[FIXED] Usuarios: offset quitado en query listar usuario, reemplazado y solucionado

parent ad99244e
......@@ -14,7 +14,7 @@ import org.json.JSONObject;
*/
public interface UsuarioDAO {
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength) throws Exception;
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength, int draw) throws Exception;
public int cantidadRegistros(JSONObject datos) throws Exception;
......
......@@ -19,10 +19,10 @@ public class UsuarioService {
DAOFactory fabrica = DAOFactory.getDAOFactory(DAOFactory.SQLSERVER);
UsuarioDAO dao = fabrica.getUsuarioDAO();
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength) {
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength, int draw) {
JSONArray array = null;
try {
array = dao.listarUsuario(datos, vstart, vlength);
array = dao.listarUsuario(datos, vstart, vlength, draw);
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -119,7 +119,7 @@ public class UsuarioServlet extends HttpServlet {
String draw = request.getParameter("draw");
int vstart = Integer.parseInt(request.getParameter("start"));
int vlength = Integer.parseInt(request.getParameter("length"));
JSONArray json = srv.listarUsuario(filtro, vstart, vlength);
JSONArray json = srv.listarUsuario(filtro, vstart, vlength, Integer.parseInt(draw));
for (int i = 0; i < json.length(); i++) {
JSONObject objeto = new JSONObject();
JSONObject obj = json.getJSONObject(i);
......
......@@ -24,7 +24,7 @@ public class SqlServerDAOFactory extends DAOFactory {
Connection conexion = null;
if (base.equalsIgnoreCase("security")) {
String user = "###########";
String pwd = "##########";
String pwd = "########";
String url = "jdbc:sqlserver://172.16.0.6:1433;databaseName=security";
// String url = "jdbc:sqlserver://172.16.2.40:1433;databaseName=Security";
......
......@@ -21,7 +21,7 @@ import org.json.JSONObject;
public class UsuarioSqlServerDAO implements UsuarioDAO {
@Override
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength) throws Exception {
public JSONArray listarUsuario(JSONObject datos, int vstart, int vlength, int draw) throws Exception {
String base = "security";
Connection con = null;
PreparedStatement pst = null;
......@@ -29,6 +29,7 @@ public class UsuarioSqlServerDAO implements UsuarioDAO {
String query = "";
JSONArray lista = new JSONArray();
String busqueda01;
try {
switch (datos.getString("tipo")) {
case "1":
......@@ -49,15 +50,17 @@ public class UsuarioSqlServerDAO implements UsuarioDAO {
} else {
busqueda01 += " and a.est = 0 ";
}
query = " SELECT a.cod_usuario, a.cod_trabajador, a.usu, a.est FROM usuario AS a "
query = " WITH tablaOrdenada AS (SELECT a.cod_usuario, a.cod_trabajador, a.usu, a.est, ROW_NUMBER() OVER (ORDER BY a.cod_usuario) AS cantidad FROM usuario AS a "
+ " LEFT JOIN usuario_detalle AS ud ON ud.cod_usuario = a.cod_usuario "
+ " LEFT JOIN proyecto_detalle AS pd ON pd.cod_proyecto_detalle = ud.cod_proyecto_detalle "
+ " WHERE 1= 1 "
+ " " + busqueda01 + " "
+ " GROUP BY a.cod_usuario, a.cod_trabajador, a.usu, a.est "
+ " ORDER BY "
+ " a.usu ASC offset " + vstart + " ROWS FETCH NEXT " + vlength + " ROWS ONLY ";
+ " GROUP BY a.cod_usuario, a.cod_trabajador, a.usu, a.est) "
+ " select cod_usuario, cod_trabajador, usu, est, cantidad from tablaOrdenada "
+ " where cantidad BETWEEN "+vstart+" and "+vlength*draw
+ " ORDER BY usu ASC";
con = SqlServerDAOFactory.getConnectionSQL(base);
pst = con.prepareStatement(query);
rs = pst.executeQuery();
int conta = vstart + 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment