123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package com.person.service.impl;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import com.person.dao.PersonDao;
- import com.person.dao.impl.PersonDaoImpl;
- import com.person.domain.PageBean;
- import com.person.domain.Person;
- import com.person.service.PersonService;
- public class PersonServiceImpl implements PersonService {
- //注册
- public int registerPerson(Person p) {
- //调用dao
- PersonDao dao = new PersonDaoImpl();
- //生成随机唯一值
- String pid = UUID.randomUUID().toString();
- p.setPid(pid);
- //判断用户名是否重复
- if(dao.panduanUsername(p)) {
- dao.register(p);
- }else {
- return -1;
- }
- return 1;
- }
- //登录
- public Person loginUser(Person p) {
- //调用dao
- PersonDao dao = new PersonDaoImpl();
- return dao.login(p);
- }
- //封装分页数据到pageBean对象里面
- public PageBean findAllPage(int current) {
- PageBean pageBean = new PageBean();
- //当前页
- pageBean.setCurrentPage(current);
- //总记录数
- PersonDao dao = new PersonDaoImpl();
- int totalCount = dao.findCount();
- pageBean.setTotalCount(totalCount);
-
- //每页显示记录数
- int pageSize = 3;
- //总页数
- int totalPage = 0;
- if(totalCount%pageSize==0) {
- totalPage = totalCount/pageSize;
- }else {
- totalPage = totalCount/pageSize + 1;
- }
- pageBean.setTotalPage(totalPage);
-
- //开始位置
- int begin = (current-1) * pageSize;
- pageBean.setBegin(begin);
-
- //每页数据list集合
- List<Person> list = dao.findAllPage(begin, pageSize);
- pageBean.setList(list);
-
- return pageBean;
- }
- public Person findOne(String pid) {
- PersonDao dao = new PersonDaoImpl();
- return dao.findOne(pid);
- }
- public void update(Person p) {
- //调用dao
- PersonDao dao = new PersonDaoImpl();
- dao.update(p);
-
- }
- public void delete(String pid) {
- //调用dao
- PersonDao dao = new PersonDaoImpl();
- dao.delete(pid);
-
- }
- public PageBean selectPerson(Person p, int current) {
- Map<String, String> map = new HashMap<String, String>();
- map.put("realname", p.getRealname());
- map.put("gender", p.getGender());
- map.put("education", p.getEducation());
- String resume = p.getResume();
-
- PageBean pageBean = new PageBean();
- pageBean.setRealname(p.getRealname());
- pageBean.setGender(p.getGender());
- pageBean.setEducation(p.getEducation());
- if(resume.equals("1")) {
- map.put("resume", "is not null");
- pageBean.setResume("1");
- }else if (resume.equals("2")) {
- map.put("resume", "is null");
- pageBean.setResume("2");
- }
- PersonDao dao = new PersonDaoImpl();
- //总记录数
- int totalCount = dao.selectCount(map);
- pageBean.setTotalCount(totalCount);
- //总记录数大于0,才给current赋值,当前页
- if(totalCount > 0) {
- pageBean.setCurrentPage(current);
- }else {
- pageBean.setCurrentPage(0);
- }
-
- //每页显示记录数
- int pageSize = 3;
- //总页数
- int totalPage = 0;
- if(totalCount%pageSize==0) {
- totalPage = totalCount/pageSize;
- }else {
- totalPage = totalCount/pageSize + 1;
- }
- pageBean.setTotalPage(totalPage);
-
- //开始位置
- int begin = (current-1) * pageSize;
- pageBean.setBegin(begin);
-
- //每页数据list集合
- List<Person> list = dao.selectPerson(map, begin, pageSize);
- pageBean.setList(list);
-
- return pageBean;
- }
- public void addPerson(Person p) {
- //调用dao
- PersonDao dao = new PersonDaoImpl();
- //生成随机唯一值
- String pid = UUID.randomUUID().toString();
- p.setPid(pid);
- dao.addPerson(p);
- }
- }
|