com.greenline.guahao.biz.manager.partners.xm.converter.XmConverter.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.biz.manager.partners.xm.converter.XmConverter.java

Source

/*
 * Project: guahao-portal-biz-core
 * 
 * File Created at 2014-4-18
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.guahao.biz.manager.partners.xm.converter;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.greenline.guahao.biz.manager.order.dataobject.OrderDO;
import com.greenline.guahao.biz.manager.partners.xm.config.XmConstants;
import com.greenline.guahao.biz.manager.partners.xm.dataobject.XmOrderDO;

/**
 * @Type XmConverter
 * @Desc ??
 * @author alex
 * @date 2014-4-18
 * @Version V1.0
 */
public class XmConverter {
    private static final Log log = LogFactory.getLog(XmConverter.class);

    public static XmOrderDO convertToXmOrderDO(OrderDO o, String xmUserId, String accessToken) {
        XmOrderDO xo = null;
        if (null != o) {
            xo = new XmOrderDO();
            xo.setAccessToken(accessToken); // ?
            xo.setUserId(xmUserId);// ??
            xo.setOrderDepartment(StringUtils.defaultString(o.getHospDepartmentName())); // ??
            xo.setOrderDoctor(StringUtils.defaultString(o.getExpertName()));// ??
            xo.setOrderHospital(StringUtils.defaultString(o.getHosptialName()));// ??
            xo.setOrderId(StringUtils.defaultString(o.getOrderNo()));// ??
            xo.setOrderName(XmConstants.ORDER_NAME);// ???
            xo.setOrderPlace0(StringUtils.defaultString(o.getFetchAddress())); // ???
            xo.setOrderPlace1(StringUtils.defaultString(o.getClinicAddress())); // ?
            xo.setOrderPrice(null == o.getClinicFee() ? 0
                    : new BigDecimal(o.getClinicFee()).divide(new BigDecimal(100)).setScale(2).doubleValue()); // ????
            xo.setOrderPriceInfo(xo.getOrderPlace0());// ?
            xo.setOrderShipType(StringUtils.defaultString(o.getClinicTypeName())); // 
            xo.setOrderShortInfo(getOrderShortInfo(xo));// ???<=32
            xo.setOrderStartTime(parseTimeToSecondFromYyyyMMdd(o.getClinicDate())); // 
            xo.setOrderStatus(switchOrderStatus(o.getStatus())); // ??
            xo.setOrderTime(parseTimeToSecond(o.getCreatedTime())); // ?
            xo.setOrderUrl(getOrderDetailUrl(xo)); // ??
        }
        return xo;
    }

    /**
     * ??
     * 
     * @param date java.util.Date
     * @return
     */
    private static long parseTimeToSecond(Date date) {
        long time = 0;
        if (null != date) {
            time = date.getTime() / 1000;
        }
        return time;
    }

    /**
     * ??
     * 
     * @param yyyyMMdd yyyyMMdd?
     * @return
     */
    private static long parseTimeToSecondFromYyyyMMdd(String yyyyMMdd) {
        long time = 0;
        if (null != yyyyMMdd) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Date date = null;
            try {
                date = sdf.parse(yyyyMMdd);
            } catch (ParseException e) {
                log.error(String.format("?%s", e.getMessage()), e);
            }
            time = parseTimeToSecond(date);
        }
        return time;
    }

    /**
     * ????
     * 
     * @param xo
     * @return
     */
    private static String getOrderShortInfo(XmOrderDO xo) {
        String info = String.format("%s%s", xo.getOrderHospital(), xo.getOrderDepartment());
        return (info.length() > 28 ? info.substring(0, 28) : info) + "?";
    }

    /**
     * ???
     * 
     * @param status
     * @return
     */
    private static int switchOrderStatus(Integer status) {
        int xmStatus = 0; // ????????????
        return xmStatus;
    }

    /**
     * ???
     * 
     * @param xo
     * @return
     */
    private static String getOrderDetailUrl(XmOrderDO xo) {
        return "http://xm.m.guahao.com/mobile/b/order/info?orderId=" + xo.getOrderId();
    }
}