| | |
| | | package com.hxzkoa.services; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.persistence.EntityManager; |
| | |
| | | import javax.persistence.Query; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.hxzkoa.json.User; |
| | | import com.hxzkoa.json.tb_achor; |
| | | import com.hxzkoa.json.tb_login; |
| | | import com.hxzkoa.json.tb_user; |
| | | import com.hxzkoa.json.tb_xunjianbaobiao; |
| | | import com.hxzkoa.util.Config; |
| | | import com.hxzkoa.util.ModifyConfig; |
| | | |
| | | @Service |
| | | public class LoginService { |
| | |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | @Transactional |
| | | public void login_add(tb_login login) { |
| | | String sql = null; |
| | | Query query = null; |
| | | sql = "INSERT tb_login (ip,username,time) VALUES (:ip,:username,now())"; |
| | | query = this.em.createNativeQuery(sql); |
| | | query.setParameter("ip", login.getIp()); |
| | | query.setParameter("username", login.getUsername()); |
| | | query.executeUpdate(); |
| | | } |
| | | |
| | | public List<tb_login> getloginManagement(int page) { |
| | | String sql = null; |
| | | Query query = null; |
| | | sql = "SELECT id,ip,username,time FROM (SELECT id,ip,username,time FROM tb_login ORDER BY id DESC) s LIMIT :start,:end"; |
| | | query = this.em.createNativeQuery(sql); |
| | | query.setParameter("start", (page - 1) * Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"))); |
| | | query.setParameter("end", Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"))); |
| | | List resultList = query.getResultList(); |
| | | List<tb_login> tb_loginlist = new ArrayList<tb_login>(); |
| | | if (resultList.size() > 0) { |
| | | for (int i = 0; i < resultList.size(); i++) { |
| | | tb_login login = new tb_login(); |
| | | Object[] obj = (Object[]) resultList.get(i); |
| | | login.setId((int) obj[0]); |
| | | login.setIp(obj[1] == null ? "" : obj[1].toString()); |
| | | login.setUsername(obj[2] == null ? "" : obj[2].toString()); |
| | | login.setTime(obj[3] == null ? "" : obj[3].toString()); |
| | | tb_loginlist.add(login); |
| | | } |
| | | } |
| | | return tb_loginlist; |
| | | } |
| | | |
| | | public List<tb_login> getloginid(String username) { |
| | | String sql = null; |
| | | Query query = null; |
| | | sql = "SELECT id,ip,username,time FROM tb_login WHERE username = :username"; |
| | | query = this.em.createNativeQuery(sql); |
| | | query.setParameter("username", username); |
| | | List resultList = query.getResultList(); |
| | | List<tb_login> tb_loginlist = new ArrayList<tb_login>(); |
| | | if (resultList.size() > 0) { |
| | | for (int i = 0; i < resultList.size(); i++) { |
| | | tb_login login = new tb_login(); |
| | | Object[] obj = (Object[]) resultList.get(i); |
| | | login.setId((int) obj[0]); |
| | | login.setIp(obj[1] == null ? "" : obj[1].toString()); |
| | | login.setUsername(obj[2] == null ? "" : obj[2].toString()); |
| | | login.setTime(obj[3] == null ? "" : obj[3].toString()); |
| | | tb_loginlist.add(login); |
| | | } |
| | | } |
| | | return tb_loginlist; |
| | | } |
| | | |
| | | public int getloginManagementCount() { |
| | | String sql = null; |
| | | Query query = null; |
| | | sql = "SELECT count(1) FROM tb_login"; |
| | | query = this.em.createNativeQuery(sql); |
| | | return Integer.parseInt(query.getSingleResult().toString()); |
| | | } |
| | | } |