UsergroupModAction.java~55~
上传用户: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 + "' group by ug.usergroup,ug.depid,u.id";
  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.                     String temp = "a";
  62.                     for (int j = l; j < same.length; j++) {
  63.                         h = l;
  64.                         if (same[j] != null && ug[i] != null) {
  65.                             if (same[j].equals(ug[i])) {
  66.                                 l++;
  67.                                 break;
  68.                             } else {
  69.                                 tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
  70.                                          yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
  71.                               temp = "b";
  72.                               //System.out.println(tempsql1);
  73.                               dbc.executeUpdate(tempsql1);
  74.                                 break;
  75.                             }
  76.                         }
  77.                     }
  78.                     if (l <= i && l == h) {
  79.                         if (ug[i] != null) {
  80.                             if(temp.equals("a")){
  81.                                 tempsql1 =
  82.                                         "insert into usergroup (usergroup,userid,depid,ugmd5) values('" +
  83.                                         yug[0][0] + "'," + ug[i] + ",'" + dep +
  84.                                         "','" + ugmd5 + "')";
  85.                                 //System.out.println(tempsql1);
  86.                                 dbc.executeUpdate(tempsql1);
  87.                                 //System.out.println("dd" + ids[i]);
  88.                             }
  89.                         }
  90.                     }
  91.                 }
  92.                 l = 0;
  93.                 h = 0;
  94.                 for (int i = 0; i < yug.length; i++) {
  95.                     //得出应该删除的
  96.                     String temp = "a";
  97.                     String tempsql2 = "";
  98.                     for (int j = l; j < same.length; j++) {
  99.                         h = l;
  100.                         if (same[j] != null && yug[i][2] != null) {
  101.                             if (same[j].equals(yug[i][2])) {
  102.                                 l++;
  103.                                 break;
  104.                             } else {
  105.                                 temp = "b";
  106.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  107.                                 //System.out.println(tempsql2);
  108.                                 dbc.executeUpdate(tempsql2);
  109.                                 //System.out.println("ttt" + checkInfo[i][0]);
  110.                                 break;
  111.                             }
  112.                         }
  113.                     }
  114.                     if (l <= i && l == h) {
  115.                         if (yug[i][2] != null)
  116.                             if (!temp.equals("b")) {
  117.                                 tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
  118.                                 //System.out.println(tempsql2);
  119.                                 dbc.executeUpdate(tempsql2);
  120.                                 //System.out.println("ttt" + checkInfo[i][0]);
  121.                             }
  122.                     }
  123.                 }
  124.                 request.setAttribute("msg", "success");
  125.                 return mapping.findForward("succ");
  126.             } else {
  127.                 request.setAttribute("msg", "用户名不能为空!");
  128.                 return mapping.findForward("err");
  129.             }
  130.         } catch (Exception ex) {
  131.             ex.printStackTrace();
  132.             request.setAttribute("msg", "用户组修改出现异常!");
  133.         }
  134.         return mapping.findForward("err");
  135.     }
  136. }