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

📄 operatoraction.java

📁 一个关于tlms的一个小程序 看看能否帮助到别人
💻 JAVA
字号:
package com.szmx.tlms.admin.web;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.szmx.framework.base.model.Pagination;
import com.szmx.framework.base.web.BaseAction;
import com.szmx.tlms.TlmsServiceErrorCodes;
import com.szmx.tlms.GlobalConstants;
import com.szmx.tlms.admin.model.Operator;
import com.szmx.tlms.admin.model.Employee;
import com.szmx.tlms.admin.service.OperatorService;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: tan
 * Date: 2006-7-31
 * Time: 11:01:18
 * To change this template use File | Settings | File Templates.
 */
public class OperatorAction extends BaseAction {

    //private methods begin:
    private Long getUserId(HttpServletRequest request) throws Exception {
        return ((Employee) getLoginedUser(request)).getId();
    }
    //private methods end:

    // Operator actions begin: ----------------------------------------

    /**
     * Operator search action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward searchOperator(ActionMapping mapping,
                                        ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'searchOperator' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        Operator operator = (Operator) dynaForm.get("searchBean");
        Pagination pagination = new Pagination(request, "pagination");

        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");
        pagination = service.searchOperators(pagination, operator);
        //
        request.setAttribute("pagination", pagination);
        //得到所有的部门列表
        List departmentList = service.getDepartmentList();
        //放入request中
        request.setAttribute("departmentList", departmentList);
        //重定向
        return mapping.findForward("success");
    }

    /**
     * Operator initAdd action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward initAddOperator(ActionMapping mapping,
                                         ActionForm form,
                                         HttpServletRequest request,
                                         HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'initAddOperator' method");
        }

        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");
        //得到所有的部门列表
        List departmentList = service.getDepartmentList();
        //放入request中
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("operatorBean", new Operator());
        //重定向
        return mapping.findForward("success");
    }

    /**
     * Operator initUpdate action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward initUpdateOperator(ActionMapping mapping,
                                            ActionForm form,
                                            HttpServletRequest request,
                                            HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'initUpdateOperator' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        Operator operator = (Operator) dynaForm.get("operatorBean");
        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");
        operator = service.getOperator(operator.getId());
        if (operator == null) {
            saveActionErrorMessage(request, TlmsServiceErrorCodes.SERVICE_ERROR_AD002);
            return mapping.findForward("failure");
        }
        //得到所有的部门列表
        List departmentList = service.getDepartmentList();
        //放入request
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("operatorBean", operator);
        //重定向
        return mapping.findForward("success");
    }

    /**
     * Operator  add     action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward addOperator(ActionMapping mapping,
                                     ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'addOperator' method");
        }

        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");

        DynaActionForm dynaForm = (DynaActionForm) form;
        Operator operator = (Operator) dynaForm.get("operatorBean");
        request.setAttribute("operatorBean", operator);

        //添加保存
        service.saveOperator(operator);
        //
        saveActionTripMessage(request, "message.add");
        //重定向
        return mapping.findForward("success");
    }

    /**
     * Operator update action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward updateOperator(ActionMapping mapping,
                                        ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'updateOperator' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        Operator operator = (Operator) dynaForm.get("operatorBean");
        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");
        //得到所有的部门列表
        List departmentList = service.getDepartmentList();
        //放入request
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("operatorBean", operator);
        //更新保存
        service.updateOperator(operator);
        //
        saveActionTripMessage(request, "message.update");
        //重定向
        return mapping.findForward("success");
    }

    /**
     * Operator remove action
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward removeOperator(ActionMapping mapping,
                                        ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'removeOperator' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        String[] splitString = (String[]) dynaForm.get("idArr");
        //通过搜索Spring配置文件得到Provider业务类
        //spring配置文件为:applicationContext-service-admin.xml
        //对应的BeanID为:operatorService
        OperatorService service = (OperatorService) getBean("operatorService");
        //删除
        service.removeOperators(splitString, getUserId(request));
        //
        saveActionTripMessage(request, "message.delete");
        //重定向
        return mapping.findForward("success");
    }
// Operator actions end: ----------------------------------------


}

⌨️ 快捷键说明

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