UsergroupModAction.java~46~
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:6k
源码类别:

OA系统

开发平台:

Java

  1. package officeol.mc.actions;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.Action;
  8. import officeol.mc.tools.*;
  9. public class UsergroupModAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.         try {
  14.             request.setCharacterEncoding("GBK");
  15.             String ugmd5 = request.getParameter("ugmd5");
  16.             String dep = request.getParameter("dep");
  17.             int len = Integer.parseInt(request.getParameter("ulen"));
  18.             String ug[] = new String[len];
  19.             for (int i = 0; i < len; i++) {
  20.                 ug[i] = request.getParameter("user" + i);
  21.             }
  22.             if (ugmd5 != null && !ugmd5.equals("")) {
  23.                 String ysql = "select ug.usergroup,ug.depid,u.id from usergroup as ug inner join [user] as u on ug.userid = u.id inner join deparment as d on ug.depid = d.id where ugmd5 = '" +
  24.                               ugmd5 + "' ";
  25.                 DBConn dbc = new DBConn();
  26.                 String[][] yug = dbc.getArray(ysql);
  27.                 if (!yug[0][1].equals(dep)) {
  28.                     String depusql =
  29.                             "update usergroup set depid = "+dep+" where ugmd5 = '" +
  30.                             ugmd5 + "' ";
  31.                     dbc.executeUpdate(depusql);
  32.                     //更新用户组所属部门
  33.                 }
  34.                 int length = 0;
  35.                 if (len <= yug.length) {
  36.                     length = yug.length;
  37.                 } else {
  38.                     length = len;
  39.                 }
  40.                 //比较获取相同的UserID
  41.                 String[] same = new String[length];
  42.                 int k = 0;
  43.                 for (int i = 0; i < ug.length; i++) {
  44.                     for (int j = 0; j < yug.length; j++) {
  45.                         if (ug[i] != null && !ug[i].equals("")) {
  46.                             if (ug[i].equals(yug[j][2])) {
  47.                                 same[k] = ug[i];
  48.                                 //System.out.println("same: "+same[k]);
  49.                                 k++;
  50.                                 continue;
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.                 int l = 0;
  56.                 int h = 0;
  57.                 for (int i = 0; i < ug.length; i++) {
  58.                     //得出应该向数据库添加的
  59.                     String tempsql1 = "";
  60.                     for (int j = l; j < same.length; j++) {
  61.                         h = l;
  62.                         if (same[j] != null && ug[i] != null) {
  63.                             if (same[j].equals(ug[i])) {
  64.                                 l++;
  65.                                 break;
  66.                             } else {
  67.                                 tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
  68.                                          yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
  69.                                 //System.out.println(tempsql1);
  70.                                 dbc.executeUpdate(tempsql1);
  71.                                 break;
  72.                             }
  73.                         }
  74.                     }
  75.                     if (l <= i && l == h) {
  76.                         if (ug[i] != null) {
  77.                             tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
  78.                                          yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
  79.                             //System.out.println(tempsql1);
  80.                             dbc.executeUpdate(tempsql1);
  81.                             //System.out.println("dd" + ids[i]);
  82.                         }
  83.                     }
  84.                 }
  85.                 l = 0;
  86.                 h = 0;
  87.                 for (int i = 0; i < yug.length; i++) {
  88.                     //得出应该删除的
  89.                     String temp = "a";
  90.                     String tempsql2 = "";
  91.                     for (int j = l; j < same.length; j++) {
  92.                         h = l;
  93.                         if (same[j] != null && yug[i][2] != null) {
  94.                             if (same[j].equals(yug[i][2])) {
  95.                                 l++;
  96.                                 break;
  97.                             } else {
  98.                                 temp = "b";
  99.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  100.                                 //System.out.println(tempsql2);
  101.                                 dbc.executeUpdate(tempsql2);
  102.                                 //System.out.println("ttt" + checkInfo[i][0]);
  103.                                 break;
  104.                             }
  105.                         }
  106.                     }
  107.                     if (l <= i && l == h) {
  108.                         if (yug[i][2] != null)
  109.                             if (!temp.equals("b")) {
  110.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  111.                                 //System.out.println(tempsql2);
  112.                                 dbc.executeUpdate(tempsql2);
  113.                                 //System.out.println("ttt" + checkInfo[i][0]);
  114.                             }
  115.                     }
  116.                 }
  117.                 request.setAttribute("msg", "success");
  118.                 return mapping.findForward("succ");
  119.             } else {
  120.                 request.setAttribute("msg", "用户名不能为空!");
  121.                 return mapping.findForward("err");
  122.             }
  123.         } catch (Exception ex) {
  124.             ex.printStackTrace();
  125.             request.setAttribute("msg", "用户组修改出现异常!");
  126.         }
  127.         return mapping.findForward("err");
  128.     }
  129. }