码迷,mamicode.com
首页 > 其他好文 > 详细

@ResponseBody

时间:2017-11-23 08:15:12      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:command   box   turn   rod   ns-3   comm   eof   tail   object   

package com.yundaex.wms.interfaces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yundaex.common.basic.vo.RequestVO;
import com.yundaex.common.basic.vo.SimpleResponseVO;
import com.yundaex.common.exception.WrappedRuntimeException;
import com.yundaex.common.validation.asserts.YDAssert;
import com.yundaex.wms.basicdata.constant.CommandTypeConstants;
import com.yundaex.wms.inbound.handler.PutawayCompleteHandler;
import com.yundaex.wms.inventory.handler.ConsMoveCompleteHandler;
import com.yundaex.wms.inventory.handler.MoveCompleteHandler;
import com.yundaex.wms.outbound.handler.OnhPackFinishHandler;
import com.yundaex.wms.outbound.handler.WrhMainpickFinishHandler;
import com.yundaex.wms.outbound.handler.WrhPartpickFinishHandler;

/**
 * 
 * <pre>
 *   Title: ServicesForWMSSocket.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2017
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author tonglele
 * @version 1.0
 * @date 2017年10月10日
 */
@Controller
@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, value = "/external", produces = "application/json;charset=UTF-8")
public class ServicesForWMSSocket {

    @Autowired
    private WrhMainpickFinishHandler wrhMainpickFinishHandler;
    
    @Autowired
    private OnhPackFinishHandler onhPackFinishHandler;
    
    @Autowired
    private WrhPartpickFinishHandler wrhPartpickFinishHandler;

    @Autowired
    private PutawayCompleteHandler putawayCompleteHandler;
    
    @Autowired
    private ConsMoveCompleteHandler consMoveCompleteHandler;

    @Autowired
    private MoveCompleteHandler moveCompleteHandler;
    
    @RequestMapping(value = "/serviceForWMSSocket.do")
    @ResponseBody
    public Object totalProcesser(@RequestBody RequestVO vo) throws Exception {
        YDAssert.isNotNull(vo, "请求对象不能为空");
        String method = vo.getMethod();
        Object data = vo.getData();
        YDAssert.isNotNull(method, "method字段不能为空");
        YDAssert.isNotNull(data, "data字段不能为空");
        
        SimpleResponseVO responseVO = new SimpleResponseVO();
        Object responseData = null;
        try {
            switch (method) {
            case CommandTypeConstants.WRH_MAINPICK_FINISH:
                responseData = wrhMainpickFinishHandler.propagation(data);
            //取消分拣完成接口    
            /*case CommandTypeConstants.WRH_PARTPICK_FINISH:
                return wrhPartpickFinishHandler.propagation(data);*/
            case CommandTypeConstants.ONH_PACK_FINISH:
                responseData = onhPackFinishHandler.propagation(data);
            case CommandTypeConstants.PTH_PUTAWAY_COMPLETE:
                responseData = putawayCompleteHandler.propagation(data);
            case CommandTypeConstants.CMVH_CONS_MOVE_COMPLETE:
                responseData =consMoveCompleteHandler.propagation(data);
            case CommandTypeConstants.MVH_MOVE_COMPLETE:
                responseData = moveCompleteHandler.propagation(data);
            default:
                YDAssert.isTrue(false, "没有定义该接口" + method);
            }
            responseVO.setData(responseData);
            responseVO.setResult("TRUE");
        } catch (Exception e) {
            String excMsg = e.getMessage();
            String errorCode = "VLD_ILG_ARG";//"参数校验不合法"
            if (e instanceof WrappedRuntimeException) {
                excMsg = ((WrappedRuntimeException)e).getErrorDetails().getExceptionList().get(0);
                errorCode = ((WrappedRuntimeException)e).getErrorCode();
            }
            responseVO.setData(responseData);
            responseVO.setResult("FALSE");
            responseVO.setErrorCode(errorCode);
            responseVO.setRemark(excMsg);
        }
        return responseVO;
    }
}

wms-springmvc-servlet.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<beans  
    xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:context="http://www.springframework.org/schema/context"    
    xmlns:mvc="http://www.springframework.org/schema/mvc"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd   
    http://www.springframework.org/schema/tx   
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.2.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/aop  
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd ">
    
    <mvc:annotation-driven>
        <mvc:argument-resolvers> 
            <bean class="com.yundaex.common.bidiboxing.convert.support.PayloadToBeanArgumentResolver"/> 
        </mvc:argument-resolvers> 
        <mvc:return-value-handlers>
            <bean class="com.yundaex.common.bidiboxing.convert.support.BeanToPayloadReturnTypeResolver" />
        </mvc:return-value-handlers>
        <mvc:message-converters register-defaults="true">  
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >  
                 <property name="supportedMediaTypes" value="*/*" /> 
            </bean>
        </mvc:message-converters>  
    </mvc:annotation-driven>
    
    
    <aop:aspectj-autoproxy proxy-target-class="true" />
    <context:annotation-config />
    <context:component-scan base-package="com.yundaex.wms">
    </context:component-scan>
    
</beans>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

 引用jar包可能spring提供,就不用加

 

public class SimpleResponseVO {
    
    /***
     * 处理结果,TURE/FALSE
     */
    private String result;
    
    /** 返回代码**/
    private String errorCode;
    
    /** 返回的信息**/
    private String remark;
    
    /** 返回的对象**/
    private Object data;

    public Object getResult() {
        return result;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void setResult(String result) {
        this.result = result;
    }

    

}

 

@ResponseBody

标签:command   box   turn   rod   ns-3   comm   eof   tail   object   

原文地址:http://www.cnblogs.com/tonggc1668/p/7881285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!