package com.wgc.action;

import java.util.List;
import com.opensymphony.xwork2.ActionContext;
import com.wgc.entity.User;
import com.wgc.util.HrmConstants;

/**
 * 处理User操作的Action
 * */
public class UserAction extends AbstractAction {
	
	private User user;
	private String message;
	private List<User> lists;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	


	public List<User> getLists() {
		return lists;
	}

	public void setLists(List<User> lists) {
		this.lists = lists;
	}

	/**
	 * 登录功能
	 * */
	public String login() throws Exception {
		user = sshService.login(user.getLoginname(), user.getPassword());
		if(user != null){
			// 保存到HttpSession
			ActionContext.getContext().getSession()
				.put(HrmConstants.USER_SESSION,user);
			return SUCCESS;
		}else{
			this.message = "登录名或密码错误!请重新登录!";
			return HrmConstants.LOGIN;
		}
	}
	
	/**
	 * 每一个查询页面都做了分页,分页的功能封装到PageModel当中
	 * 
	 * */
	public String selectUser() throws Exception {
		System.out.println("selectUser() -->");
		// 设置请求页数
		if(this.pageIndex != null){
			this.pageModel.setPageIndex(pageIndex);
		}
		// 查询总数
		Integer recordCount = sshService.getUserCount();
		// 把用户总数设置到pageModel当中
		this.pageModel.setRecordCount(recordCount);
		// 查询数据
		this.lists = sshService.selectPage(this.pageModel);
		return SUCCESS;
	}
	//查询
	public String selectUserByComtition() throws Exception {
		System.out.println("selectUserByComtition() -->");
		// 设置请求页数
		if(this.pageIndex != null){
			this.pageModel.setPageIndex(pageIndex);
		}
		// 查询总数
		Integer recordCount = sshService.getUserCountByComdition(user.getUsername(), user.getStatus());
		// 把用户总数设置到pageModel当中
		this.pageModel.setRecordCount(recordCount);
		// 查询数据
		this.lists = sshService.selectUserByComdition(pageModel, user.getUsername(), user.getStatus());
		return SUCCESS;
	}
	//通过用户名或者用户状态查询
	public String selectUserByNameOrStutas() throws Exception {
		System.out.println("selectUserByNameOrStutas() -->");
		
		return SUCCESS;
	}
	public String removeUser() throws Exception {
		System.out.println("removeUser() -->");
		/**
		 * ids传过来是字符串>>"1,2,3,4"
		 * 通过split分割再存进数组》》》》id[0]=1 id[1]=2 id[2]=3
		 */
		String[] temp = ids.split(",");
		System.out.println("temp>>>>"+temp);
		for(String id:temp) {
			sshService.removeUser(Integer.parseInt(id));
		}
		return SUCCESS;
	}
	/**
	 * 1 跳转带添加页面
	 * 2 提交到数据库
	 */
	public String addUser() throws Exception {
		if(flag.equals("1")) {
			return "showAddUser";
		} else {
			sshService.saveUser(user);
			return SUCCESS;
		}
	}
	
	/**
	 * 1 跳转带修改页面
	 * 2 提交到数据库
	 */
	public String updateUser() throws Exception {
		if(flag.equals("1")) {
			user = sshService.findUserId(id);
			return "showUpdateUser";
		} else {
			sshService.updateUser(user);
			return SUCCESS;
		}
	}
}
最近下载更多
程健飞  LV2 2023年3月30日
Hugo_0901  LV5 2022年4月27日
wanglinddad  LV54 2022年4月19日
wangzile1994  LV12 2022年4月16日
槛外人  LV6 2022年3月29日
afei115  LV4 2021年11月29日
864152530  LV5 2021年6月7日
zuihaofdfdfdfdddd  LV10 2021年5月30日
1207748096  LV6 2021年5月12日
and123456  LV11 2021年4月20日
最近浏览更多
WBelong  LV7 2023年12月15日
zhangyanghao 2023年9月21日
暂无贡献等级
lcqlcl  LV11 2023年8月29日
werh0123  LV1 2023年8月17日
2506793979  LV12 2023年7月2日
新工艺  LV7 2023年6月12日
maritime 2023年6月1日
暂无贡献等级
纯爱战士  LV2 2023年5月28日
zzw123zzw  LV6 2023年5月2日
sweetbox  LV10 2023年4月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友