📄 departmentnewaction.java
字号:
package com.seavision.PermissionManage.action.unitManage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.seavision.PermissionManage.components.DepartmentManage;
import com.seavision.PermissionManage.components.LogManage;
import com.seavision.PermissionManage.components.UrlBalanceManage;
import com.seavision.PermissionManage.help.DaoFectory;
import com.seavision.PermissionManage.common.BaseAction;
import com.seavision.PermissionManage.vo.DepartmentVO;
import com.seavision.PermissionManage.vo.UserVO;
public class DepartmentNewAction extends BaseAction {
/**
* @author 尚渊杰
* @param String departmentName String department_p
* String departmentPhone String departmentAuthority
* String departmentState String departmentType
* @功能 新增部门action
* @功能描述: 根据页面传来的参数新增部门信息,进行页面跳转,
* 成功返回SUCCESS 失败返回FALSE
*/
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
try {
// 初始化Action
String departmentName = "";
String department_p = "";
String departmentPhone = "";
String departmentAuthority = "";
String departmentState = "";
String departmentType = "";
String url = "";
String ipAddress = ""; // ip地址
String operator = ""; // 操作人
boolean b = false; // 用于判断用户权限
String b1 = ""; // 用于跳转页面
String message = "";
this.initializeAction(request, "DepartmentNewAction");
// 获取参数
UserVO userVO = (UserVO) this.getAttribute("loginUserBean");
operator = userVO.getUserName();
// request获取参数
departmentName = request.getParameter("departmentName");
department_p = request.getParameter("department_p");
departmentPhone = request.getParameter("departmentPhone");
departmentAuthority = request.getParameter("departmentAuthority");
departmentState = request.getParameter("departmentState");
departmentType = request.getParameter("departmentType");
url = request.getParameter("url");
ipAddress = request.getRemoteAddr();
// session校验参数校验
if (this.check(userVO)) {
message += "用户名密码不配,请重新登录!";
// 返回到登录页面
return this.moveToFailure(message, "logon", actionMapping);
}
// 判断用户权限
UrlBalanceManage ubm = new UrlBalanceManage();
b = ubm.urlBalance(url);
if (!b) {
message += "您没有此权限";
return this.moveToFailure(message, "FALSE", actionMapping);
}
// 判断部门名是否为null
if (check(departmentName)) {
message += "部门名称不能为空!";
return this.moveToFailure(message, "FALSE", actionMapping);
}
// 判断上级部门编号是否为null
if (check(String.valueOf(department_p))) {
department_p = "";
}
// 判断部门电话是否为null
if (check(departmentPhone)) {
departmentPhone = "";
}
// 判断部门负责人是否为null
if (check(departmentAuthority)) {
departmentAuthority = "";
}
// 判断部门状态标记是否为null
if (check(departmentState)) {
departmentState = "";
}
// 判断部门类型是否为null
if (check(departmentType)) {
departmentType = "";
}
// 判断url是否为null
if (check(url)) {
message = "url不能为空!";
return this.moveToFailure(message, "FALSE", actionMapping);
}
// 判断ip地址不能为空
if (check(ipAddress)) {
message = "ip地址不能为空!";
return this.moveToFailure(message, "FALSE", actionMapping);
}
// 判断操作人不能为空
if (check(operator)) {
message = "操作人不能为空!";
return this.moveToFailure(message, "FALSE", actionMapping);
}
DepartmentVO department = new DepartmentVO();
department.setDepartmentName(departmentName);
department.setDepartment_p(Integer.parseInt(department_p));
department.setDepartmentPhone(departmentPhone);
department.setDepartmentAuthority(Integer.parseInt(departmentAuthority));
department.setDepartmentState(Integer.parseInt(departmentState));
department.setDepartmentType(departmentType);
// 调用组件方法,进行业务逻辑处理
DepartmentManage dm = DaoFectory.getDepantManage();
b1 = dm.saveDepartment(department);
// 写入日志
LogManage lm = DaoFectory.getLogManage();
lm.addLog(operator, url, ipAddress, "新增部门");
// 通过返回值进行判断页面跳转
if (b1.equals("SUCCESS")) {
return this.moveToSuccess("SUCCESS", actionMapping);
} else {
return this.moveToFailure("新增失败", "FALSE", actionMapping);
}
} catch (Exception e) {
return this.moveToError(e.getMessage(), "error", actionMapping);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -