package cn.itcast.oa.view.action;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.usertype.UserCollectionType;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.itcast.oa.base.ModelDrivenBaseAction;
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.HqlHelper;
import com.opensymphony.xwork2.ActionContext;
@Controller
@Scope("prototype")
public class UserAction extends ModelDrivenBaseAction<User> {
private Long departmentId;
private Long[] roleIds;
/** 列表 */
public String list() throws Exception {
// List<User> userList = userService.findAll();
// ActionContext.getContext().put("userList", userList);
new HqlHelper(User.class)//
.buildPageBeanForStruts2(pageNum, userService);
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 {
// 1,新建对象并设置属性(也可以使用model)
Department department = departmentService.getById(departmentId);
model.setDepartment(department);
List<Role> roleList = roleService.getByIds(roleIds);
model.setRoles(new HashSet<Role>(roleList));
String passwdMD5 = DigestUtils.md5Hex("1234");
model.setPassword(passwdMD5); // 默认密码为1234,应使用MD5摘要
// 2,保存到数据库
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().size() > 0) {
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());
// >> 所属部门
Department department = departmentService.getById(departmentId);
user.setDepartment(department);
// >> 关联的岗位
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 passwdMD5 = DigestUtils.md5Hex("1234");
user.setPassword(passwdMD5);
// 3,更新到数据库
userService.update(user);
return "toList";
}
/** 登录页面 */
public String loginUI() throws Exception {
return "loginUI";
}
/** 登录 */
public String login() throws Exception {
// 查询
User user = userService.getByLoginNameAndPassword(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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
完整的SSHOA办公系统(自带权限管理和论坛) (1351个子文件)
config.ascx 5KB
class_upload.asp 10KB
io.asp 7KB
commands.asp 6KB
config.asp 6KB
connector.asp 2KB
upload.asp 2KB
basexml.asp 2KB
util.asp 1KB
connector.aspx 1KB
upload.aspx 1KB
install.bat 129B
image.cfc 46KB
ImageObject.cfc 12KB
cf5_upload.cfm 11KB
cf5_connector.cfm 10KB
cf_io.cfm 10KB
cf_commands.cfm 8KB
config.cfm 8KB
cf_util.cfm 4KB
cf_connector.cfm 3KB
cf_basexml.cfm 3KB
cf_upload.cfm 2KB
connector.cfm 1005B
upload.cfm 993B
connector.cgi 4KB
upload.cgi 3KB
UserAction.class 6KB
BaseDaoImpl.class 5KB
AnchorTag.class 4KB
User.class 4KB
ApplicationTemplateAction.class 4KB
TreeViewPractice.class 4KB
Installer.class 4KB
RoleAction.class 4KB
HqlHelper.class 4KB
FlowAction.class 4KB
ProcessDefinitionServiceImpl.class 3KB
DepartmentAction.class 3KB
ForumAction.class 3KB
ApplicationServiceImpl.class 3KB
TopicAction.class 3KB
ProcessDefinitionAction.class 3KB
BaseAction.class 3KB
ReplyServiceImpl.class 3KB
Application.class 3KB
TopicServiceImpl.class 3KB
Privilege.class 3KB
ForumManageAction.class 3KB
SpringTest.class 2KB
ForumServiceImpl.class 2KB
Forum.class 2KB
ReplyAction.class 2KB
Department.class 2KB
Topic.class 2KB
DepartmentUtils.class 2KB
InitServletContextListener.class 2KB
PageBean.class 2KB
CheckPrivilegeInterceptor.class 2KB
Role.class 2KB
Article.class 2KB
ApproveInfo.class 2KB
HqlHelperTest.class 2KB
ApplicationTemplate.class 2KB
DepartmentServiceImpl.class 1KB
TestService.class 1KB
ModelDrivenBaseAction.class 1KB
UserServiceImpl.class 1KB
ApplicationTemplateServiceImpl.class 1KB
PrivilegeServiceImpl.class 1KB
TestAction.class 987B
TaskView.class 978B
HomeAction.class 949B
BaseDao.class 818B
ReplyService.class 598B
TopicService.class 598B
RoleServiceImpl.class 574B
Reply.class 571B
DepartmentService.class 516B
ApplicationService.class 492B
Configuration.class 468B
ProcessDefinitionService.class 463B
PrivilegeService.class 452B
BaseDaoTest.class 424B
UserService.class 356B
ForumService.class 314B
ApplicationTemplateService.class 298B
RoleService.class 253B
.classpath 6KB
pageCommon.css 17KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_dialog.css 6KB
fck_dialog.css 6KB
fck_dialog.css 6KB
forum.css 4KB
top.css 4KB
file.css 4KB
jquery.treeview.css 3KB
共 1351 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
- king_whq2018-05-17ting haode
- makaay11242018-02-26试试看,先赞一个
- DDC3265982017-12-22感觉很不错
- yj245112016-12-02我认为挺好啊,功能挺全的,导入数据库就可以用了,点赞。
- quancha2016-12-01感觉没啥用啊,很老的东西了心无距离2016-12-01只是你觉得没用罢了,这个项目其实挺有参考价值的,我也是花了时间的
心无距离
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功