com.neusoft.mid.clwapi.service.advise.AdviseServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.neusoft.mid.clwapi.service.advise.AdviseServiceImpl.java

Source

/**
 * @(#)AdviseServiceImpl.java 2013-3-25
 *
 * Copyright 2013 Neusoft Group Ltd. All rights reserved.
 * Neusoft PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.neusoft.mid.clwapi.service.advise;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.neusoft.mid.clwapi.common.ErrorConstant;
import com.neusoft.mid.clwapi.common.ModCommonConstant;
import com.neusoft.mid.clwapi.common.UserInfoKey;
import com.neusoft.mid.clwapi.entity.advise.UserAdviseReq;
import com.neusoft.mid.clwapi.exception.common.ApplicationException;
import com.neusoft.mid.clwapi.mapper.AdviseMapper;
import com.neusoft.mid.clwapi.tools.JacksonUtils;

/**
 * @author <a href="mailto:majch@neusoft.com">majch </a>
 * @version $Revision 1.0 $ 2013-3-25 ?10:01:08
 */
public class AdviseServiceImpl implements AdviseService {

    /**
     * .
     */
    private static Logger logger = LoggerFactory.getLogger(ModCommonConstant.LOGGER_NAME);

    @Autowired
    private AdviseMapper adviseMapper;
    @Context
    private MessageContext context;

    /**
     * ??.
     * 
     * @param token
     *            ?.
     * @param adviseCont
     *            ??.
     * @return ??.
     */
    @Override
    public Response sendTtMsg(String token, String adviseCont) {

        UserAdviseReq reqInfo = JacksonUtils.fromJsonRuntimeException(adviseCont, UserAdviseReq.class);

        if (StringUtils.isEmpty(StringUtils.strip(reqInfo.getAdviseCont()))) {
            logger.info("??");
            // ???
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        } else {
            String userId = context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID);
            String enterpriseId = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
            if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(enterpriseId)) {
                logger.info("??USER_IDENTERPRISE_ID?");
                // ???
                throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
            } else {
                // ????.
                adviseMapper.insertUserAdviseInfo(userId, enterpriseId, reqInfo.getAdviseCont());
                return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache")
                        .build();
            }
        }
    }

}