功能介绍
系统管理员:系统管理,用户信息管理,区域信息管理,水表结算类型维护(月、季度、年),水费单价信息维护,水表信息管理,水费信息管理。
用户:水费超表,退出系统。
部分功能模块代码
package com.action;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.util.Pagination;
import com.entity.Admin;
import com.entity.User;
import com.dao.AdminDAO;
public class AdminAction extends BaseAction implements ModelDriven<Admin> {
@Autowired
private AdminDAO adminDAO;
// 模型驱动使用的对象,通过登录执行的方法将用户名和密码封装在Admin对象里.
private Admin admin = new Admin();
public Admin getModel() {
return admin;
}
public String toadd() {
return "toadd";
}
public String userlogin() {
if(admin != null){
String userNm = ServletActionContext.getRequest().getParameter("userName");
String userPwd = ServletActionContext.getRequest().getParameter("userPw");
Admin userTemp = new Admin();
userTemp.setUsername(userNm);
userTemp.setUserpwd(userPwd);
userTemp.setIdentity("抄表员");
List userList = adminDAO.findByExample(admin);
if(null != userList && userList.size() > 0){
Admin user = (Admin) userList.get(0);
ServletActionContext.getRequest().getSession().setAttribute("userType", 1);
ServletActionContext.getRequest().getSession().setAttribute("user", user);
return "userloginsucc";
}
}
return "userloginfail";
}
public String add() {
adminDAO.save(admin);
this.setMessage("添加成功");
this.setPath("admin!listpage.action");
return "succeed";
}
//
public String toedit() {
admin = adminDAO.findById(admin.getId());
getRequestMap().put("Admin", admin);
return "toedit";
}
// 修改的执行方法
public String edit() {
adminDAO.merge(admin);
this.setMessage("修改成功");
this.setPath("admin!listpage.action");
return "succeed";
}
public String listall() {
List adminList = adminDAO.findByExample(admin);
Map request = getRequestMap();
request.put("adminList", adminList);
return "list";
}
public String listpage() {
List adminList = adminDAO.findByExample(admin);
Map request = getRequestMap();
request.put("adminList", adminList);
return "list";
}
/**
* 删除
*/
public String del() {
if("admin".endsWith(admin.getUsername())){
this.setMessage("超级管理员不能删除");
this.setPath("admin!listpage.action");
return "succeed";
}
adminDAO.delete(admin);
this.setMessage("添加成功");
this.setPath("admin!listpage.action");
return "succeed";
}
public AdminDAO getAdminDAO() {
return adminDAO;
}
public void setAdminDAO(AdminDAO adminDAO) {
this.adminDAO = adminDAO;
}
public Admin getAdmin() {
return this.admin;
}
public void setAdmin(Admin admin) {
this.admin = admin;
}
}
package com.service;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import com.dao.AdminDAO;
import com.dao.UserDAO;
import com.entity.Admin;
import com.entity.User;
public class loginService {
private AdminDAO adminDAO;
private UserDAO userDAO;
public String login(String userName, String userPw, int userType) {
System.out.println("userType" + userType);
try {
Thread.sleep(700);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = "no";
if (userType == 0)//
{
String sql = "from Admin where identity = '管理员' and username=? and userpwd=?";
Object[] con = { userName, userPw };
List adminList = adminDAO.getHibernateTemplate().find(sql, con);
if (adminList.size() == 0) {
result = "no";
} else {
WebContext ctx = WebContextFactory.get();
HttpSession session = ctx.getSession();
Admin admin = (Admin) adminList.get(0);
session.setAttribute("userType", 0);
session.setAttribute("admin", admin);
result = "yes";
}
}
if (userType == 1) {
String sql = "from User where loginname=? and pwd=?";
Object[] con = { userName, userPw };
List userList = userDAO.getHibernateTemplate().find(sql, con);
if (userList.size() == 0) {
result = "no";
} else {
WebContext ctx = WebContextFactory.get();
HttpSession session = ctx.getSession();
User user = (User) userList.get(0);
session.setAttribute("userType", 1);
session.setAttribute("user", user);
result = "yes";
}
}
return result;
}
public String adminPwEdit(String userPwNew) {
System.out.println("DDDD");
try {
Thread.sleep(700);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebContext ctx = WebContextFactory.get();
HttpSession session = ctx.getSession();
Admin admin = (Admin) session.getAttribute("admin");
admin.setUserpwd(userPwNew);
adminDAO.getHibernateTemplate().update(admin);
session.setAttribute("admin", admin);
return "yes";
}
public AdminDAO getAdminDAO() {
return adminDAO;
}
public void setAdminDAO(AdminDAO adminDAO) {
this.adminDAO = adminDAO;
}
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
}
package com.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.entity.Admin;
public class AdminDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(AdminDAO.class);
public int findCount() {
String hql = "select count(*)from Admin";
List<Long> list = this.getHibernateTemplate().find(hql);
if (list.size() > 0) {
return list.get(0).intValue();
}
return 0;
}
/**
* 分页查找
*/
public List<Admin> findByPage(int begin, int pageSize) {
DetachedCriteria critertia = DetachedCriteria.forClass(Admin.class);
List<Admin> list = this.getHibernateTemplate().findByCriteria(
critertia, begin, pageSize);
return list;
}
public void save(Admin instance) {
this.getHibernateTemplate().save(instance);
}
public void delete(Admin instance) {
this.getHibernateTemplate().delete(instance);
}
public Admin findById(Integer id) {
return (Admin) getHibernateTemplate().get("com.entity.Admin", id);
}
public List findByExample(Admin instance) {
return getHibernateTemplate().findByExample(instance);
}
public List findByProperty(String propertyName, Object value) {
String queryString = "from Admin as model where model." + propertyName
+ "= ?";
return getHibernateTemplate().find(queryString, value);
}
public List findAll() {
return getHibernateTemplate().find("from Admin");
}
public Admin merge(Admin instance) {
return (Admin) getHibernateTemplate().merge(instance);
}
public void saveOrUpdate(Admin instance) {
this.getHibernateTemplate().saveOrUpdate(instance);
}
}
论文目录