UsergroupModAction.java~47~
上传用户: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.                     System.out.println(depusql);
  32.                     //dbc.executeUpdate(depusql);
  33.                     //更新用户组所属部门
  34.                 }
  35.                 int length = 0;
  36.                 if (len <= yug.length) {
  37.                     length = yug.length;
  38.                 } else {
  39.                     length = len;
  40.                 }
  41.                 //比较获取相同的UserID
  42.                 String[] same = new String[length];
  43.                 int k = 0;
  44.                 for (int i = 0; i < ug.length; i++) {
  45.                     for (int j = 0; j < yug.length; j++) {
  46.                         if (ug[i] != null && !ug[i].equals("")) {
  47.                             if (ug[i].equals(yug[j][2])) {
  48.                                 same[k] = ug[i];
  49.                                 //System.out.println("same: "+same[k]);
  50.                                 k++;
  51.                                 continue;
  52.                             }
  53.                         }
  54.                     }
  55.                 }
  56.                 int l = 0;
  57.                 int h = 0;
  58.                 for (int i = 0; i < ug.length; i++) {
  59.                     //得出应该向数据库添加的
  60.                     String tempsql1 = "";
  61.                     for (int j = l; j < same.length; j++) {
  62.                         h = l;
  63.                         if (same[j] != null && ug[i] != null) {
  64.                             if (same[j].equals(ug[i])) {
  65.                                 l++;
  66.                                 break;
  67.                             } else {
  68.                                 tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
  69.                                          yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
  70.                                 System.out.println(tempsql1);
  71.                                 //dbc.executeUpdate(tempsql1);
  72.                                 break;
  73.                             }
  74.                         }
  75.                     }
  76.                     if (l <= i && l == h) {
  77.                         if (ug[i] != null) {
  78.                             tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
  79.                                          yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
  80.                             System.out.println(tempsql1);
  81.                             //dbc.executeUpdate(tempsql1);
  82.                             //System.out.println("dd" + ids[i]);
  83.                         }
  84.                     }
  85.                 }
  86.                 l = 0;
  87.                 h = 0;
  88.                 for (int i = 0; i < yug.length; i++) {
  89.                     //得出应该删除的
  90.                     String temp = "a";
  91.                     String tempsql2 = "";
  92.                     for (int j = l; j < same.length; j++) {
  93.                         h = l;
  94.                         if (same[j] != null && yug[i][2] != null) {
  95.                             if (same[j].equals(yug[i][2])) {
  96.                                 l++;
  97.                                 break;
  98.                             } else {
  99.                                 temp = "b";
  100.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  101.                                 System.out.println(tempsql2);
  102.                                 //dbc.executeUpdate(tempsql2);
  103.                                 //System.out.println("ttt" + checkInfo[i][0]);
  104.                                 break;
  105.                             }
  106.                         }
  107.                     }
  108.                     if (l <= i && l == h) {
  109.                         if (yug[i][2] != null)
  110.                             if (!temp.equals("b")) {
  111.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  112.                                 System.out.println(tempsql2);
  113.                                 //dbc.executeUpdate(tempsql2);
  114.                                 //System.out.println("ttt" + checkInfo[i][0]);
  115.                             }
  116.                     }
  117.                 }
  118.                 request.setAttribute("msg", "success");
  119.                 return mapping.findForward("succ");
  120.             } else {
  121.                 request.setAttribute("msg", "用户名不能为空!");
  122.                 return mapping.findForward("err");
  123.             }
  124.         } catch (Exception ex) {
  125.             ex.printStackTrace();
  126.             request.setAttribute("msg", "用户组修改出现异常!");
  127.         }
  128.         return mapping.findForward("err");
  129.     }
  130. }