Criar serviço para trazer informações para login Agência Digital
bug#15882 dev:trevezani qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@98067 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
14235ada05
commit
57b034f7a7
|
@ -0,0 +1,27 @@
|
|||
package com.rjconsultores.ventaboletos.rest;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.rjconsultores.ventaboletos.rest.bean.ParamsLogin;
|
||||
import com.rjconsultores.ventaboletos.rest.service.LoginService;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||
|
||||
@Path("/logar")
|
||||
public class LoginRS {
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@RolesAllowed("EMBARCADA")
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response login(ParamsLogin params) {
|
||||
LoginService service = (LoginService) AppContext.getApplicationContext().getBean("loginService");
|
||||
return Response.ok(service.logar(params), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.rjconsultores.ventaboletos.rest.bean;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ParamsLogin {
|
||||
private String usuario;
|
||||
private String senha;
|
||||
|
||||
public ParamsLogin() {
|
||||
|
||||
}
|
||||
|
||||
public String getUsuario() {
|
||||
return usuario;
|
||||
}
|
||||
|
||||
public void setUsuario(String usuario) {
|
||||
this.usuario = usuario;
|
||||
}
|
||||
|
||||
public String getSenha() {
|
||||
return senha;
|
||||
}
|
||||
|
||||
public void setSenha(String senha) {
|
||||
this.senha = senha;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.rjconsultores.ventaboletos.rest.returns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginRetorno {
|
||||
private String status;
|
||||
private String mensagem;
|
||||
|
||||
private Integer usuarioId;
|
||||
private String nombusuario;
|
||||
private Integer puntoventaId;
|
||||
private List<Integer> empresasId = new ArrayList<Integer>(0);
|
||||
|
||||
public LoginRetorno() {
|
||||
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMensagem() {
|
||||
return mensagem;
|
||||
}
|
||||
|
||||
public void setMensagem(String mensagem) {
|
||||
this.mensagem = mensagem;
|
||||
}
|
||||
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
public String getNombusuario() {
|
||||
return nombusuario;
|
||||
}
|
||||
|
||||
public void setNombusuario(String nombusuario) {
|
||||
this.nombusuario = nombusuario;
|
||||
}
|
||||
|
||||
public Integer getPuntoventaId() {
|
||||
return puntoventaId;
|
||||
}
|
||||
|
||||
public void setPuntoventaId(Integer puntoventaId) {
|
||||
this.puntoventaId = puntoventaId;
|
||||
}
|
||||
|
||||
public List<Integer> getEmpresasId() {
|
||||
return empresasId;
|
||||
}
|
||||
|
||||
public void setEmpresasId(List<Integer> empresasId) {
|
||||
this.empresasId = empresasId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.rjconsultores.ventaboletos.rest.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.UsuarioDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||
import com.rjconsultores.ventaboletos.entidad.UsuarioEmpresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.UsuarioUbicacion;
|
||||
import com.rjconsultores.ventaboletos.rest.bean.ParamsLogin;
|
||||
import com.rjconsultores.ventaboletos.rest.returns.LoginRetorno;
|
||||
import com.rjconsultores.ventaboletos.service.UsuarioEmpresaService;
|
||||
import com.rjconsultores.ventaboletos.service.UsuarioUbicacionService;
|
||||
|
||||
@Service("loginService")
|
||||
public class LoginService {
|
||||
@Autowired
|
||||
private UsuarioDAO usuarioDAO;
|
||||
|
||||
@Autowired
|
||||
private UsuarioUbicacionService usuarioUbicacionService;
|
||||
|
||||
@Autowired
|
||||
private UsuarioEmpresaService usuarioEmpresaService;
|
||||
|
||||
@Transactional
|
||||
public LoginRetorno logar(ParamsLogin params) {
|
||||
LoginRetorno retorno = new LoginRetorno();
|
||||
retorno.setStatus("SUCCESS");
|
||||
|
||||
if (params.getUsuario() == null || params.getUsuario().isEmpty() ||
|
||||
params.getSenha() == null || params.getSenha().isEmpty()) {
|
||||
retorno.setStatus("ERROR");
|
||||
retorno.setMensagem("Parametros invalidos");
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
Usuario usuario = usuarioDAO.buscarPeloNomeSenha(params.getUsuario(), params.getSenha());
|
||||
|
||||
if (usuario == null) {
|
||||
retorno.setStatus("ERROR");
|
||||
retorno.setMensagem("Usuario/Senha invalido");
|
||||
} else {
|
||||
retorno.setUsuarioId(usuario.getUsuarioId());
|
||||
retorno.setNombusuario(usuario.getNombUsuarioCompleto());
|
||||
|
||||
List<UsuarioUbicacion> ubicacion = usuarioUbicacionService.buscarPorUsuario(usuario);
|
||||
|
||||
if (ubicacion != null && !ubicacion.isEmpty()) {
|
||||
retorno.setPuntoventaId(ubicacion.get(0).getPuntoVenta().getPuntoventaId());
|
||||
}
|
||||
|
||||
List<UsuarioEmpresa> empresas = usuarioEmpresaService.obtenerPorUsuario(usuario);
|
||||
|
||||
if (empresas != null) {
|
||||
for (UsuarioEmpresa empresa : empresas) {
|
||||
retorno.getEmpresasId().add(empresa.getEmpresa().getEmpresaId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue