UserAction.java
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:12k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. //Created by MyEclipse Struts
  2. // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
  3. //czp
  4. package com.oa.module.office.user;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.lang.reflect.InvocationTargetException;
  8. import java.util.List;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.servlet.http.HttpSession;
  12. import org.apache.commons.beanutils.BeanUtils;
  13. import org.apache.struts.action.ActionForm;
  14. import org.apache.struts.action.ActionForward;
  15. import org.apache.struts.action.ActionMapping;
  16. import org.apache.struts.actions.DispatchAction;
  17. import com.oa.module.folder.Forder;
  18. import com.oa.module.hints.Thints;
  19. import com.oa.util.PubUtil;
  20. import com.oa.util.XPage;
  21. /** 
  22.  * MyEclipse Struts
  23.  * Creation date: 01-17-2008
  24.  * 
  25.  * XDoclet definition:
  26.  * @struts.action path="/user" name="userForm" input="/Jsp_file/user/user.jsp" parameter="method" scope="request" validate="true"
  27.  */
  28. public class UserAction extends DispatchAction {
  29. private InUserDAO userdao;
  30. private Forder forderdao;
  31. public Forder getForderdao() {
  32. return forderdao;
  33. }
  34. public void setForderdao(Forder forderdao) {
  35. this.forderdao = forderdao;
  36. }
  37. public ActionForward query(ActionMapping mapping, ActionForm form,
  38. HttpServletRequest request, HttpServletResponse response) {
  39. UserForm userForm = (UserForm) form;
  40. int currentPage = 1;
  41. try {
  42. currentPage = Integer.parseInt(request.getParameter("currentPage"));
  43. } catch (Exception e) {
  44. currentPage = 1;
  45. }
  46. int count = 10;
  47. Tuser info = new Tuser();
  48. // 拷贝查询参数(后面拷到前面){前面是目的地,后面是源}
  49. try {
  50. BeanUtils.copyProperties(info, userForm);
  51. } catch (IllegalAccessException e) {
  52. // TODO Auto-generated catch block
  53. e.printStackTrace();
  54. } catch (InvocationTargetException e) {
  55. // TODO Auto-generated catch block
  56. e.printStackTrace();
  57. }
  58. XPage userpage = userdao.getUserlist(currentPage, count, info);
  59. List deptlist = null;
  60. deptlist = userdao.getDept();
  61. request.setAttribute("deptlist", deptlist);
  62. request.setAttribute("userpage", userpage);
  63. return mapping.findForward("userlist");
  64. }
  65. public ActionForward add(ActionMapping mapping, ActionForm form,
  66. HttpServletRequest request, HttpServletResponse response) {
  67. UserForm userForm = (UserForm) form;
  68. userForm.setMethod("addlist");
  69. List deptlist = null;
  70. List worklist = null;
  71. List rolelist = null;
  72. deptlist = userdao.getDept();
  73. worklist = userdao.getWork();
  74. rolelist = userdao.getRole();
  75. request.setAttribute("deptlist",deptlist);
  76. request.setAttribute("worklist",worklist);
  77. request.setAttribute("rolelist", rolelist);
  78. return mapping.getInputForward();
  79. }
  80. public ActionForward addlist(ActionMapping mapping, ActionForm form,
  81. HttpServletRequest request, HttpServletResponse response) {
  82. String[] role1 = request.getParameterValues("role1");
  83. UserForm userForm = (UserForm) form;
  84. userForm.setUislocked("0");
  85. userForm.setUisonline("0");
  86. userForm.setUpwd("888888");
  87. userForm.setUaddtime(PubUtil.getNowDate());
  88. Tuser info = new Tuser();
  89. int num = role1.length;
  90. Tuserrole[] urole = new Tuserrole[num];
  91. Thints hint = new Thints();
  92. hint.setHshowtype("1");
  93. hint.setHshowtime("10");
  94. hint.setHaffair("1");
  95. hint.setHmeeting("1");
  96. hint.setHemail("1");
  97. hint.setHmemo("贴士备注");
  98. hint.setUser(info);
  99. info.setHint(hint);
  100. for(int i=0;i<num;i++){
  101. urole[i] = new  Tuserrole();
  102. urole[i].setRid(Integer.parseInt(role1[i]));
  103. urole[i].setUser(info);
  104. info.getUserrole().add(urole[i]);
  105. }
  106. try {
  107. //info目的地  userForm 源
  108. BeanUtils.copyProperties(info,userForm);
  109. } catch (IllegalAccessException e) {
  110. e.printStackTrace();
  111. } catch (InvocationTargetException e) {
  112. e.printStackTrace();
  113. }
  114. boolean flag = userdao.addList(info);
  115. if (flag) {
  116. // 去列表页面,并显示成功信息
  117. Tuser user = userdao.getUserForName(info.getUname());
  118. String path = this.getServlet().getServletContext().getRealPath("/");
  119. path = path.replace('\', '/');
  120. path += "forder";
  121. System.out.println(forderdao);
  122. forderdao.buildSystemForder(user.getUno(),user.getUname(),path);
  123. request.setAttribute("msg", "添加用户成功");
  124. return mapping.findForward("query");
  125. } else {
  126. // 去添加页面,并显示失败信息
  127. request.setAttribute("msg", "添加用户失败");
  128. return mapping.getInputForward();
  129. }
  130. }
  131. public ActionForward update(ActionMapping mapping, ActionForm form,
  132. HttpServletRequest request, HttpServletResponse response) {
  133. UserForm userForm = (UserForm) form;
  134. if(!(userForm.getUno().toString()==null)&&userForm.getUno().toString()=="1"){
  135. request.setAttribute("msg", "超级管理员不能修改");
  136. return mapping.getInputForward();
  137. }else{
  138. Tuser info = userdao.getUserById(userForm.getUno());
  139. try {
  140. BeanUtils.copyProperties(userForm,info);
  141. } catch (IllegalAccessException e) {
  142. // TODO Auto-generated catch block
  143. e.printStackTrace();
  144. } catch (InvocationTargetException e) {
  145. // TODO Auto-generated catch block
  146. e.printStackTrace();
  147. }
  148. List deptlist = null;
  149. List worklist = null;
  150. List rolelist = null;
  151. List rlist = null;
  152. deptlist = userdao.getDept();
  153. worklist = userdao.getWork();
  154. rolelist = userdao.getRole();
  155. rlist = userdao.getRList(userForm.getUno());
  156. request.setAttribute("deptlist",deptlist);
  157. request.setAttribute("worklist",worklist);
  158. request.setAttribute("rolelist", rolelist);
  159. request.setAttribute("rlist",rlist);
  160. userForm.setMethod("edit");
  161. return mapping.getInputForward();
  162. }
  163. }
  164. public ActionForward edit(ActionMapping mapping, ActionForm form,
  165. HttpServletRequest request, HttpServletResponse response) {
  166. String[] role1 = request.getParameterValues("role1");
  167. UserForm userForm = (UserForm) form;
  168. Tuser info = new Tuser();
  169. try {
  170. BeanUtils.copyProperties(info,userForm);
  171. } catch (IllegalAccessException e) {
  172. e.printStackTrace();
  173. } catch (InvocationTargetException e) {
  174. e.printStackTrace();
  175. }
  176. int num = role1.length;
  177. Tuserrole[] urole = new Tuserrole[num];
  178. for(int i=0;i<num;i++){
  179. urole[i] = new  Tuserrole();
  180. urole[i].setRid(Integer.parseInt(role1[i]));
  181. urole[i].setUser(info);
  182. info.getUserrole().add(urole[i]);
  183. }
  184. boolean flag = userdao.editList(info);
  185. if (flag) {
  186. // 去列表页面,并显示成功信息
  187. request.setAttribute("msg", "修改用户成功");
  188. return mapping.findForward("query");
  189. } else {
  190. // 去添加页面,并显示失败信息
  191. request.setAttribute("msg", "修改用户失败");
  192. return mapping.getInputForward();
  193. }
  194. }
  195. public ActionForward open(ActionMapping mapping, ActionForm form,
  196. HttpServletRequest request, HttpServletResponse response) {
  197. UserForm userForm = (UserForm) form;
  198. Tuser info = userdao.getUserById(userForm.getUno());
  199. info.setUislocked("0");
  200. boolean flag = userdao.openUser(info);
  201. if (flag) {
  202. // 去列表页面,并显示成功信息
  203. request.setAttribute("msg", "恢复用户成功");
  204. return mapping.findForward("query");
  205. } else {
  206. // 去添加页面,并显示失败信息
  207. request.setAttribute("msg", "恢复用户失败");
  208. return mapping.findForward("query");
  209. }
  210. }
  211. public ActionForward close(ActionMapping mapping, ActionForm form,
  212. HttpServletRequest request, HttpServletResponse response) {
  213. UserForm userForm = (UserForm) form;
  214. if(!(userForm.getUno()==null)&&!userForm.getUno().equals("1")){
  215. Tuser info = userdao.getUserById(userForm.getUno());
  216. info.setUislocked("1");
  217. System.out.println(userForm.getUno()+"aaaaaaa");
  218. System.out.println(userForm);
  219. System.out.println("aaaaa");
  220. boolean flag = userdao.closeUser(info);
  221. if (flag) {
  222. // 去列表页面,并显示成功信息
  223. request.setAttribute("msg", "冻结用户成功");
  224. return mapping.findForward("query");
  225. } else {
  226. // 去添加页面,并显示失败信息
  227. request.setAttribute("msg", "冻结用户失败");
  228. return mapping.findForward("query");
  229. }
  230. }else{
  231. request.setAttribute("msg", "超级管理员不能冻结");
  232. return mapping.findForward("query");
  233. }
  234. }
  235. public ActionForward updatepwd(ActionMapping mapping, ActionForm form,
  236. HttpServletRequest request, HttpServletResponse response) {
  237. UserForm userForm = (UserForm) form;
  238. userForm.setMethod("editPwd");
  239. HttpSession session = request.getSession();
  240. Tuser info = (Tuser)session.getAttribute("user");
  241. System.out.println(info.getUno());
  242. try {
  243. BeanUtils.copyProperties(userForm,info);
  244. } catch (IllegalAccessException e) {
  245. // TODO Auto-generated catch block
  246. e.printStackTrace();
  247. } catch (InvocationTargetException e) {
  248. // TODO Auto-generated catch block
  249. e.printStackTrace();
  250. }
  251. return mapping.findForward("updatepwd");
  252. }
  253. public ActionForward editPwd(ActionMapping mapping, ActionForm form,
  254. HttpServletRequest request, HttpServletResponse response) {
  255. String pwd = request.getParameter("newpwd");
  256. UserForm userForm = (UserForm) form;
  257. boolean flag = userdao.updatePwd(userForm.getUno(),pwd);
  258. if (flag) {
  259. // 去列表页面,并显示成功信息
  260. request.setAttribute("msg", "修改密码成功");
  261. return mapping.findForward("updatepwd");
  262. } else {
  263. // 去添加页面,并显示失败信息
  264. request.setAttribute("msg", "修改密码失败");
  265. return mapping.findForward("updatepwd");
  266. }
  267. }
  268. public ActionForward updateuser(ActionMapping mapping, ActionForm form,
  269. HttpServletRequest request, HttpServletResponse response) {
  270. UserForm userForm = (UserForm) form;
  271. userForm.setMethod("edituser");
  272. // Tuser info = userdao.getUserById(userForm.getUno());
  273. HttpSession session = request.getSession();
  274. Tuser info = (Tuser)session.getAttribute("user");
  275. try {
  276. BeanUtils.copyProperties(userForm,info);
  277. } catch (IllegalAccessException e) {
  278. // TODO Auto-generated catch block
  279. e.printStackTrace();
  280. } catch (InvocationTargetException e) {
  281. // TODO Auto-generated catch block
  282. e.printStackTrace();
  283. }
  284. List deptlist = null;
  285. List worklist = null;
  286. deptlist = userdao.getDept();
  287. worklist = userdao.getWork();
  288. request.setAttribute("deptlist",deptlist);
  289. request.setAttribute("worklist",worklist);
  290. return mapping.findForward("updateuser");
  291. }
  292. public ActionForward edituser(ActionMapping mapping, ActionForm form,
  293. HttpServletRequest request, HttpServletResponse response) {
  294. UserForm userForm = (UserForm) form;
  295. Tuser info = new Tuser();
  296. try {
  297. BeanUtils.copyProperties(info,userForm);
  298. } catch (IllegalAccessException e) {
  299. e.printStackTrace();
  300. } catch (InvocationTargetException e) {
  301. e.printStackTrace();
  302. }
  303. boolean flag = userdao.editList(info);
  304. if (flag) {
  305. // 去列表页面,并显示成功信息
  306. request.setAttribute("msg", "修改用户资料成功");
  307. return mapping.findForward("updateuser");
  308. } else {
  309. // 去添加页面,并显示失败信息
  310. request.setAttribute("msg", "修改用户资料失败");
  311. return mapping.getInputForward();
  312. }
  313. }
  314. public ActionForward checkName(ActionMapping mapping, ActionForm form,
  315. HttpServletRequest request, HttpServletResponse response) throws IOException {
  316. PrintWriter out = response.getWriter();
  317. UserForm userForm = (UserForm) form;
  318. if(!(userForm.getUname()==null)&&!userForm.getUname().equals("")){
  319. boolean flag = userdao.getUserByName(userForm.getUname());
  320. if (flag) {
  321. // 去列表页面,并显示成功信息
  322. out.print("此用户已存在,请更换!");
  323. } else {
  324. out.print("可以使用!");
  325. }
  326. } else {
  327. out.print("用户名不能为空!");
  328. }
  329. return null;
  330. }
  331. public InUserDAO getUserdao() {
  332. return userdao;
  333. }
  334. public void setUserdao(InUserDAO userdao) {
  335. this.userdao = userdao;
  336. }
  337. }