UsergroupModAction.java~54~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:6k
源码类别:
OA系统
开发平台:
Java
- package officeol.mc.actions;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.Action;
- import officeol.mc.tools.*;
- public class UsergroupModAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- try {
- request.setCharacterEncoding("GBK");
- String ugmd5 = request.getParameter("ugmd5");
- String dep = request.getParameter("dep");
- int len = Integer.parseInt(request.getParameter("ulen"));
- String ug[] = new String[len];
- for (int i = 0; i < len; i++) {
- ug[i] = request.getParameter("user" + i);
- }
- if (ugmd5 != null && !ugmd5.equals("")) {
- 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 = '" +
- ugmd5 + "' group by ug.usergroup,ug.depid,u.id";
- DBConn dbc = new DBConn();
- String[][] yug = dbc.getArray(ysql);
- if (!yug[0][1].equals(dep)) {
- String depusql =
- "update usergroup set depid = "+dep+" where ugmd5 = '" +
- ugmd5 + "' ";
- //System.out.println(depusql);
- dbc.executeUpdate(depusql);
- //更新用户组所属部门
- }
- int length = 0;
- if (len <= yug.length) {
- length = yug.length;
- } else {
- length = len;
- }
- //比较获取相同的UserID
- String[] same = new String[length];
- int k = 0;
- for (int i = 0; i < ug.length; i++) {
- for (int j = 0; j < yug.length; j++) {
- if (ug[i] != null && !ug[i].equals("")) {
- if (ug[i].equals(yug[j][2])) {
- same[k] = ug[i];
- //System.out.println("same: "+same[k]);
- k++;
- continue;
- }
- }
- }
- }
- int l = 0;
- int h = 0;
- for (int i = 0; i < ug.length; i++) {
- //得出应该向数据库添加的
- String tempsql1 = "";
- String temp = "a";
- for (int j = l; j < same.length; j++) {
- h = l;
- if (same[j] != null && ug[i] != null) {
- if (same[j].equals(ug[i])) {
- l++;
- break;
- } else {
- tempsql1 = "insert into usergroup (usergroup,userid,depid,ugmd5) values('"+
- yug[0][0]+"',"+ug[i]+",'"+dep+"','"+ugmd5+"')";
- temp = "b";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- break;
- }
- }
- }
- if (l <= i && l == h) {
- if (ug[i] != null) {
- if(temp.equals("a")){
- tempsql1 =
- "insert into usergroup (usergroup,userid,depid,ugmd5) values('" +
- yug[0][0] + "'," + ug[i] + ",'" + dep +
- "','" + ugmd5 + "')";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- //System.out.println("dd" + ids[i]);
- }
- }
- }
- }
- l = 0;
- h = 0;
- for (int i = 0; i < yug.length; i++) {
- //得出应该删除的
- String temp = "a";
- String tempsql2 = "";
- for (int j = l; j < same.length; j++) {
- h = l;
- if (same[j] != null && yug[i][2] != null) {
- if (same[j].equals(yug[i][2])) {
- l++;
- break;
- } else {
- temp = "b";
- tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
- //System.out.println(tempsql2);
- dbc.executeUpdate(tempsql2);
- //System.out.println("ttt" + checkInfo[i][0]);
- break;
- }
- }
- }
- if (l <= i && l == h) {
- if (yug[i][2] != null)
- if (!temp.equals("b")) {
- tempsql2 ="delete from usergroup where userid = "+yug[i][2]+" and ugmd5 = '"+ugmd5+"'";
- //System.out.println(tempsql2);
- dbc.executeUpdate(tempsql2);
- //System.out.println("ttt" + checkInfo[i][0]);
- }
- }
- }
- request.setAttribute("msg", "success");
- return mapping.findForward("succ");
- } else {
- request.setAttribute("msg", "用户名不能为空!");
- return mapping.findForward("err");
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- request.setAttribute("msg", "用户组修改出现异常!");
- }
- return mapping.findForward("err");
- }
- }