Explorar o código

上传文件至 'src/com/person/service/impl'

1801010606 %!s(int64=6) %!d(string=hai) anos
pai
achega
f0d12007e7
Modificáronse 1 ficheiros con 149 adicións e 0 borrados
  1. 149 0
      src/com/person/service/impl/PersonServiceImpl.java

+ 149 - 0
src/com/person/service/impl/PersonServiceImpl.java

@@ -0,0 +1,149 @@
+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);
+	}
+}