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

📄 companynewaction.java

📁 本代码是一个权限管理系统源代码
💻 JAVA
字号:
package com.seavision.PermissionManage.action;

import java.util.List;

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.common.BaseAction;
import com.seavision.PermissionManage.components.CompanyManage;
import com.seavision.PermissionManage.components.LogManage;
import com.seavision.PermissionManage.help.DaoFectory;
import com.seavision.PermissionManage.vo.CompanyVO;
import com.seavision.PermissionManage.vo.UserLoginVO;

/**
 * @author 尚渊杰
 * @param String
 *            companyName String company_p String companyAddress String
 *            companyPhone String companyAuthority String companyNet String
 *            companyState String companyType
 * @功能 编辑公司信息action
 * @功能描述: 根据页面传来的公司的参数添加公司记录,进行页面跳转, 成功返回SUCCESS 失败返回FALSE
 */

public class CompanyNewAction extends BaseAction {

	public ActionForward execute(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			// 初始化Action
			String companyName = "";
			String company_p = "";
			String companyAddress = "";
			String companyPhone = "";
			String companyAuthority = "";
			String companyNet = "";
			String companyState = "1";
			String companyType = "";
			String url = "";
			String ipAddress = ""; // ip地址
			String operator = ""; // 操作人
			// boolean b = false; // 用于判断用户权限
			String b1 = ""; // 用于跳转页面
			String message = "";
			this.initializeAction(request, "CompanyNewAction");

			// 从session获取参数
			UserLoginVO userLoginVO = new UserLoginVO();
			userLoginVO = (UserLoginVO)this.getAttribute("userLoginVO");
			operator = userLoginVO.getUserName();

			// 从request中获取参数
			companyName = request.getParameter("companyName");
			company_p = request.getParameter("company_pId");
			companyAddress = request.getParameter("companyAddress");
			companyPhone = request.getParameter("companyPhone");
			companyAuthority = request.getParameter("companyAuthorityId");
			companyNet = request.getParameter("companyNet");
			companyState = request.getParameter("companyState");
			companyType = request.getParameter("companyType");
			// url = request.getParameter("url");
			ipAddress = request.getRemoteAddr();
			url = request.getRequestURI();

			// session参数校验
			if (this.check(userLoginVO)) {
				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(companyName)) {
				message += "公司名称不能为空!";
				return this.moveToFailure(message, "FALSE", actionMapping);
			}
			
			// 判断上级公司编号是否为null
			if (company_p == null || company_p.trim().length() == 0||company_p.equals("请选择")) {
				company_p = "0";
			}
			// 判断公司地址是否为null
			if (check(companyAddress)) {
				companyAddress = "";
			}
			// 判断公司电话是否为null
			if (check(companyPhone)) {
				companyPhone = "";
			}
			// 判断公司负责人是否为null
			if (check(companyAuthority)) {
				companyAuthority = "";
			}else if(companyAuthority.equals("请选择")){
				companyAuthority = "0";
			}
			// 判断公司网址是否为null
			if (check(companyNet)) {
				companyNet = "";
			}
			// 判断公司状态标记是否为null
			if (check(companyState)) {
				companyState = "0";
			}
			// 判断公司类型是否为null
			if (check(companyType)) {
				companyType = "";
			}
			// 判断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);
			}

			// 封装成vo
			CompanyVO company = new CompanyVO();
			company.setCompanyName(companyName);
			company.setCompany_p(Integer.parseInt(company_p));
			company.setCompanyAddress(companyAddress);
			company.setCompanyPhone(companyPhone);
			company.setCompanyAuthority(companyAuthority);
			company.setCompanyNet(companyNet);
			company.setCompanyState(Integer.parseInt(companyState));
			company.setCompanyType(companyType);

			// 调用组件方法,进行业务逻辑处理
			CompanyManage cm = DaoFectory.getCompanyManage();
			List list1 = cm.getCompanyList();
			CompanyVO company1 = new CompanyVO();
			for(int i=0;i<list1.size();i++){
				company1 = (CompanyVO)list1.get(i);
				String companyName1 = company1.getCompanyName();
				if(companyName1.trim().equals(companyName)){
					message = "公司名不能重名!";
					return this.moveToFailure(message, "FALSE", actionMapping);
				}
			}
			if(!company_p.equals("0")){
				b1 = cm.saveDepartmentRelation(company);
			}else{
				b1 = cm.saveCompany(company);			
			}

			// 写入日志
			LogManage lm = DaoFectory.getLogManage();
			lm.addLog(operator, url, ipAddress, "newCompany");

			// 通过返回值进行判断页面跳转
			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 + -