package cn.itcast.oa.view.action;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.itcast.oa.base.BaseAction;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.domain.Role;
import cn.itcast.oa.domain.User;
import cn.itcast.oa.util.DepartmentUtils;
import cn.itcast.oa.util.QueryHelper;
import com.opensymphony.xwork2.ActionContext;
@Controller
@Scope("prototype")
public class UserAction extends BaseAction<User> {
private Long departmentId;
private Long[] roleIds;
/** 列表 */
public String list() throws Exception {
// List<User> userList = userService.findAll();
// ActionContext.getContext().put("userList", userList);
// 准备分页信息
new QueryHelper(User.class, "u").preparePageBean(userService, pageNum, pageSize);
return "list";
}
/** 删除 */
public String delete() throws Exception {
userService.delete(model.getId());
return "toList";
}
/** 添加页面 */
public String addUI() throws Exception {
// 准备数据, departmentList
List<Department> topList = departmentService.findTopList();
List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
ActionContext.getContext().put("departmentList", departmentList);
// 准备数据, roleList
List<Role> roleList = roleService.findAll();
ActionContext.getContext().put("roleList", roleList);
return "saveUI";
}
/** 添加 */
public String add() throws Exception {
// 封装到对象中(当model是实体类型时,也可以使用model,但要设置未封装的属性)
// >> 设置所属部门
model.setDepartment(departmentService.getById(departmentId));
// >> 设置关联的岗位
List<Role> roleList = roleService.getByIds(roleIds);
model.setRoles(new HashSet<Role>(roleList));
// >> 设置默认密码为1234(要使用MD5摘要)
String md5Digest = DigestUtils.md5Hex("1234");
model.setPassword(md5Digest);
// 保存到数据库
userService.save(model);
return "toList";
}
/** 修改页面 */
public String editUI() throws Exception {
// 准备数据, departmentList
List<Department> topList = departmentService.findTopList();
List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
ActionContext.getContext().put("departmentList", departmentList);
// 准备数据, roleList
List<Role> roleList = roleService.findAll();
ActionContext.getContext().put("roleList", roleList);
// 准备回显的数据
User user = userService.getById(model.getId());
ActionContext.getContext().getValueStack().push(user);
if (user.getDepartment() != null) {
departmentId = user.getDepartment().getId();
}
if (user.getRoles() != null) {
roleIds = new Long[user.getRoles().size()];
int index = 0;
for (Role role : user.getRoles()) {
roleIds[index++] = role.getId();
}
}
return "saveUI";
}
/** 修改 */
public String edit() throws Exception {
// 1,从数据库中取出原对象
User user = userService.getById(model.getId());
// 2,设置要修改的属性
user.setLoginName(model.getLoginName());
user.setName(model.getName());
user.setGender(model.getGender());
user.setPhoneNumber(model.getPhoneNumber());
user.setEmail(model.getEmail());
user.setDescription(model.getDescription());
// >> 设置所属部门
user.setDepartment(departmentService.getById(departmentId));
// >> 设置关联的岗位
List<Role> roleList = roleService.getByIds(roleIds);
user.setRoles(new HashSet<Role>(roleList));
// 3,更新到数据库
userService.update(user);
return "toList";
}
/** 初始化密码为1234 */
public String initPassword() throws Exception {
// 1,从数据库中取出原对象
User user = userService.getById(model.getId());
// 2,设置要修改的属性(要使用MD5摘要)
String md5Digest = DigestUtils.md5Hex("1234");
user.setPassword(md5Digest);
// 3,更新到数据库
userService.update(user);
return "toList";
}
/** 登录页面 */
public String loginUI() throws Exception {
return "loginUI";
}
/** 登录 */
public String login() throws Exception {
User user = userService.findByLoginNameAndPassword(model.getLoginName(), model.getPassword());
if (user == null) {
addFieldError("login", "用户名或密码不正确!");
return "loginUI";
} else {
// 登录用户
ActionContext.getContext().getSession().put("user", user);
return "toIndex";
}
}
/** 注销 */
public String logout() throws Exception {
ActionContext.getContext().getSession().remove("user");
return "logout";
}
// ---
public Long getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}
public Long[] getRoleIds() {
return roleIds;
}
public void setRoleIds(Long[] roleIds) {
this.roleIds = roleIds;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA-人事管理系统项目.zip

共1320个文件
gif:739个
js:193个
png:53个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
29 浏览量
2023-03-29
18:23:39
上传
评论
收藏 48.76MB ZIP 举报
温馨提示
JAVA_人事管理系统项目.zip
资源推荐
资源详情
资源评论















收起资源包目录





































































































共 1320 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论



程序员一灯
- 粉丝: 781
- 资源: 1724
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


会员权益专享
最新资源
- neteasestudy15.jpg
- Microsoft.CodeAnalysis.dll.netdisk.p.downloading
- Monitor Control.dmg
- Hankerila速卖通运费模板表V3.22.1.xlsx
- cudnn-linux-x86-64-8.8.1.3-cuda11-archive.tar.xz
- SecureCRT.dmg
- Mac ftp传输的工具
- ice-cream-sales.csv causal21
- 全国普通高等学校名单(截至2021年9月30日)
- SQLyog社区版 SQLyog Community Edition - 13.2.0 (64-Bit)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
