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

📄 shiptoaction.java

📁 一个关于tlms的一个小程序 看看能否帮助到别人
💻 JAVA
字号:
/**
 * =============================================
 * Copyright 2006 szmx
 *
 * Change Revision
 * --------------------------------
 *   Date                Author         Remarks
 *   2006-4-18        Alex.Ji     Create com.szmx.SalesOrgService
 * =============================================
 */

package com.szmx.tlms.supplychain.web;

import com.szmx.framework.base.web.BaseAction;
import com.szmx.framework.base.model.Pagination;
import com.szmx.tlms.supplychain.service.ShipToService;
import com.szmx.tlms.supplychain.model.ShipTo;
import com.szmx.tlms.GlobalConstants;
import com.szmx.tlms.TlmsServiceException;
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 org.hibernate.StaleObjectStateException;

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

/**
 * <desc>
 *
 * @author Alex.Ji
 * @since 2006-4-18
 */

public class ShipToAction extends BaseAction {
    public static final String SEARCH_BEAN="searchBean";
    public static final String SHIP_TO_BEAN="shipToBean";

    public static final String SHIP_TO_SERVICE="shipToService";
    public static final String PAGINATION="pagination";
    public static final String IDARR="idArr";
    public static final String ROW="row";
    public static final String UPDATE_IND="updateInd";

    public static final String SUCCESS="success";
    public static final String FAILURE="failure";
    public static final String MESSAGE_ADD="message.add";
    public static final String MESSAGE_DELETE="message.delete";
    public static final String MESSAGE_UPDATE="message.update";

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward searchShipToInfo(ActionMapping mapping, ActionForm form,
                                            HttpServletRequest request,
                                            HttpServletResponse response)
            throws Exception {

        if (log.isDebugEnabled()) {
            log.debug("Entering 'searchShipToInfo' method");
        }
        
        ShipToService shipToService = (ShipToService) getBean(SHIP_TO_SERVICE);
        DynaActionForm dynaForm = (DynaActionForm) form;
        Pagination pageObj = new Pagination(request, ROW);
        ShipTo shipTo= (ShipTo)dynaForm.get(SEARCH_BEAN);
        shipTo.check();//to check the shipTo's englishnaem1 and chineseName wheather are empty or null
        Pagination pagination = shipToService.getShipTos(pageObj,shipTo);
        request.setAttribute(PAGINATION, pagination);

        return mapping.findForward(SUCCESS);
    }

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward initUpdateShipTo(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'initUpdateShipTo' method");
        }
        String id = null;
        ShipToService shipToService = (ShipToService) getBean(SHIP_TO_SERVICE);
        DynaActionForm dynaForm = (DynaActionForm) form;
        ShipTo shioTo=(ShipTo)dynaForm.get(SHIP_TO_BEAN);

        id= String.valueOf(shioTo.getId());
        dynaForm.set(SHIP_TO_BEAN, shipToService.getShipTo(id));
        request.setAttribute(SHIP_TO_BEAN, shipToService.getShipTo(id));
        request.setAttribute(UPDATE_IND, Boolean.TRUE);
        return mapping.findForward(SUCCESS);
    }

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

        DynaActionForm dynaForm = (DynaActionForm) form;
        ShipTo shipTo = (ShipTo) dynaForm.get(SHIP_TO_BEAN);
        ShipToService shipToService = (ShipToService) getBean(SHIP_TO_SERVICE);

        shipTo.populateUpdateBean(new Long(1111));//todo
        try {
            shipToService.saveShipTo(shipTo);
            dynaForm.set(SHIP_TO_BEAN, shipTo);
            request.setAttribute(SHIP_TO_BEAN, shipTo);
        } catch (TlmsServiceException e) {
            request.setAttribute(SHIP_TO_BEAN, shipTo);
            saveActionErrorMessage(request, GlobalConstants.COMMON_MESSAGE_UPDATE_FAIL, null);
            throw e;
        }

        saveActionTripMessage(request, MESSAGE_UPDATE, null);
        return mapping.findForward(SUCCESS);
    }

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward initAddShipTo(ActionMapping mapping, ActionForm form,
                                         HttpServletRequest request,
                                         HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {

            log.debug("Entering 'initAddShipTo' method");
        }

        ShipTo shipTo = new ShipTo();
        request.setAttribute(SHIP_TO_BEAN, shipTo);
        return mapping.findForward(SUCCESS);
    }

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward addShipTo(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {

            log.debug("Entering 'addShipTo' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        ShipTo shipTo = (ShipTo) dynaForm.get(SHIP_TO_BEAN);
        shipTo.populateCreateBean(new Long(1010));//todo


        ShipToService shipToService = (ShipToService) getBean(SHIP_TO_SERVICE);

        try {
            shipToService.saveShipTo(shipTo);
            dynaForm.set(SHIP_TO_BEAN, shipTo);
            request.setAttribute(SHIP_TO_BEAN, shipTo);
        } catch (TlmsServiceException e) {
            saveActionErrorMessage(request, GlobalConstants.COMMON_MESSAGE_ADD_FAIL, null);
            throw e;
        }
        saveActionTripMessage(request, MESSAGE_ADD, null);

        return mapping.findForward(SUCCESS);
    }

    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward removeShipTo(ActionMapping mapping, ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {

            log.debug("Entering 'removeShipTo' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;

        String[] splitString = (String[]) dynaForm.get(IDARR);
        ShipToService service = (ShipToService) getBean(SHIP_TO_SERVICE);
        try {
            service.removeAllShipTo(splitString);
            saveActionTripMessage(request, MESSAGE_DELETE, null);
        } catch (TlmsServiceException e) {
            saveActionErrorMessage(request,GlobalConstants.COMMON_MESSAGE_DELETE_FAIL, null);
            throw e;
        }
        return mapping.findForward(SUCCESS);
    }

}

⌨️ 快捷键说明

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