⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sysdeptsave.java.svn-base

📁 用JSP JAVA 做的 系统 只是初来扎到还望西黄!别乱来哦!
💻 SVN-BASE
字号:
package com.chis.model.user;

import java.util.List;

import com.chis.util.GUIDKeyGen;
import com.chis.util.GenCode;
import com.stframe.dao.DaoUtil;
import com.stframe.form.ActionForm;
import com.stframe.form.DataForm;
import com.stframe.servlet.ActionInstance;
/**
 * 保存部门数据
 * @author baobao
 *
 */
public class SysDeptSave extends ActionInstance {

	public int execute(ActionForm af) throws Exception {
		String shbdwbh =af.getHttpSession().getAttribute("HBDWBH").toString();
		DataForm deptdf = new DataForm("DEPT","ID");
		try{	
			deptdf.setValues(af.getHttpRequest());
			deptdf.setCmd(af.getHttpRequest().getParameter("CMD"));
			String deptname = deptdf.get("NAME").toString().trim();
			String deptcode = deptdf.get("CODE").toString().trim();
			//用户列表
			String deptuser = af.getHttpRequest().getParameter("hid_h");
			
			if("A".equalsIgnoreCase(deptdf.getCmd()))
			{
				//部门名是否存在
				//String checksql = "SELECT * FROM DEPT WHERE NAME='"+deptname+"'";
				//if(DaoUtil.select(af.getConnection(),checksql,deptdf).size()>0)
				//{
				//	af.getHttpRequest().setAttribute("result","抱歉,该部门名已经存在!");
				//	return 0;
				//}
				
				String checksql = "SELECT * FROM DEPT WHERE CODE='"+deptcode+"'";
				if(DaoUtil.select(af.getConnection(),checksql,deptdf).size()>0)
				{
					af.getHttpRequest().setAttribute("result","抱歉,该部门编码已经存在!");
					return 0;
				}
				deptdf.set("CORP_ID", shbdwbh);
				deptdf.set("NAME",deptname);
				deptdf.set("STATUS","1");
				deptdf.set("ID",GUIDKeyGen.getGUIDKey(af.getConnection()));
				//deptdf.set("CODE",GenCode.genDeptCode(af.getConnection(),"DEPT","CODE"));
				//System.out.println("CODE:"+GenCode.genDeptCode(af.getConnection(),"DEPT","CODE"));
			}
			if("U".equalsIgnoreCase(deptdf.getCmd()))
			{
				//StringBuffer sbsql = new StringBuffer();
				//sbsql.append("select * from DEPT where");
				//sbsql.append(" name in(select name from DEPT where id not in('"+deptdf.get("ID")+"'))");
				//sbsql.append(" and name='"+deptname+"'");
				//if(DaoUtil.select(af.getConnection(),sbsql.toString(),deptdf).size()>0)
				//{
				//	af.getHttpRequest().setAttribute("result","抱歉,该部门名已经存在!");
				//	return 0;					
				//}
				
				String checksql = "SELECT * FROM DEPT WHERE id not in('"+deptdf.get("ID")+"') " +
						"and CODE='"+deptcode+"' and CORP_ID='"+shbdwbh+"'";
				if(DaoUtil.select(af.getConnection(),checksql,deptdf).size()>0)
				{
					af.getHttpRequest().setAttribute("result","抱歉,该部门编码已经存在!");
					return 0;
				}
				
				deptdf.set("NAME",deptname);
				
				//修改部门所拥有的用户列表
				if(deptuser != null && !"".equals(deptuser))
				{	
					String[] userarray = deptuser.split(",");
					String condition = "";
					for(int i = 0;i<userarray.length;i++)
					{
						if(condition == "")
						{
							condition = "'"+userarray[i]+"',";
						}
						else{
							condition = condition + "'" +userarray[i] + "',";	
						}
					}
					condition = condition.substring(0,condition.length()-1);
//					System.out.println("fdsafdsafds"+condition.substring(0,condition.length()-1));
					DataForm upuserdf = new DataForm("SYS_USER","ID");
					String usql = "select * from sys_user where id not in("+condition+") and DEPARTMENT_ID='"+deptdf.get("ID")+"' AND CROP_ID='"+shbdwbh+"'";
					List upulist = DaoUtil.select(af.getConnection(),usql,upuserdf);
					
					for(int j = 0;j < upulist.size();j++)
					{
						DataForm ndf = (DataForm)upulist.get(j);
						String nsql = "update sys_user set DEPARTMENT_ID='' where ID='"+ndf.get("ID")+"'";
						DaoUtil.execute(af.getConnection(),nsql);
						//nsql = "update EMPLOYEE set DEPT_ID='' where USER_ID='"+ndf.get("ID")+"'";
					}
				}
			}
			/*
			//获取经理
			String deptmgr = af.getHttpRequest().getParameter("hid_j");
			if(deptmgr != null && !"".equals(deptmgr))
			{
				String[] mgrarray  = deptmgr.split(",");
				if(mgrarray.length>1)
				{
					af.getHttpRequest().setAttribute("result","一个部门只能有一个经理");
					return 0;
				}else{
					deptdf.set("DIRECT_USER_ID",mgrarray[0]);
				}
			}else{
				
					deptdf.set("DIRECT_USER_ID","");
			}*/			
			
			//拥有用户
			if(deptuser != null && !"".equals(deptuser))
			{
				String[] userarray = deptuser.split(",");
				for(int i = 0;i < userarray.length;i++)
				{
					//更新用户到该部门下
					String upsql = "update sys_user set deptartment_id='"+deptdf.get("ID")+"' where ID='"+userarray[i]+"'";	
					DaoUtil.execute(af.getConnection(),upsql);
					//upsql = "update EMPLOYEE set DEPT_ID='"+deptdf.get("ID")+"' where USER_ID='"+userarray[i]+"'";	
					//DaoUtil.execute(af.getConnection(),upsql);
				}
			}
			DaoUtil.DFOperate(af.getConnection(),deptdf);
			af.getHttpRequest().setAttribute("result","A".equalsIgnoreCase(deptdf.getCmd())?"添加部门信息":"修改部门信息");
			af.getHttpRequest().setAttribute("goto","Selevet.do?action=BASE_SYSDEPT_LIST");
			af.getHttpRequest().setAttribute("CMD",af.getHttpRequest().getParameter("CMD"));
			return 1;
		}catch(Exception e)
		{
			e.printStackTrace();
			af.getHttpRequest().setAttribute("result","A".equalsIgnoreCase(deptdf.getCmd())?"添加部门信息":"修改部门信息");
			return 0;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -