com.yougou.merchant.api.common.MerchantLogTools.java Source code

Java tutorial

Introduction

Here is the source code for com.yougou.merchant.api.common.MerchantLogTools.java

Source

/**
 * 
 */
package com.yougou.merchant.api.common;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import com.yougou.merchant.api.supplier.vo.ContactsVo;
import com.yougou.merchant.api.supplier.vo.ContractVo;
import com.yougou.merchant.api.supplier.vo.MerchantUser;
import com.yougou.merchant.api.supplier.vo.RejectedAddressVo;
import com.yougou.merchant.api.supplier.vo.SupplierVo;

/**
 * ??
 * 
 * @author huang.tao
 *
 */
public class MerchantLogTools {

    private static final Map<String, String> BASIC_DATA_TRANSLATABLE_FIELDS = new HashMap<String, String>();

    private static final Map<String, String> ACCOUNT_TRANSLATABLE_FIELDS = new HashMap<String, String>();

    private static final Map<String, String> CONTACT_TRANSLATABLE_FIELDS = new HashMap<String, String>();

    private static final Map<String, String> CONTRACT_TRANSLATABLE_FIELDS = new HashMap<String, String>();

    private static final Map<String, String> AFTER_SERVICE_TRANSLATABLE_FIELDS = new HashMap<String, String>();

    private static final String LINE_SEPARATOR = System.getProperty("line.separator");

    static {
        // 
        BASIC_DATA_TRANSLATABLE_FIELDS.put("supplier", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("supplierType", "");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("isInputYougouWarehouse", "");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("setOfBooksName", "???");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("taxRate", "");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("shipmentType", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("couponsAllocationProportion", "");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("contact", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("businessLocal", "?");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("account", "???");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("businessValidity", "?");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("subBank", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("tallageNo", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("bankLocal", "");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("institutional", "?");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("businessLicense", "??");
        BASIC_DATA_TRANSLATABLE_FIELDS.put("taxpayer", "?");
        // ?
        ACCOUNT_TRANSLATABLE_FIELDS.put("userName", "???");
        ACCOUNT_TRANSLATABLE_FIELDS.put("loginName", "??");
        ACCOUNT_TRANSLATABLE_FIELDS.put("password", "?");
        ACCOUNT_TRANSLATABLE_FIELDS.put("status", "??");
        ACCOUNT_TRANSLATABLE_FIELDS.put("isAdministrator", "??");
        ACCOUNT_TRANSLATABLE_FIELDS.put("deleteFlag", "?");
        ACCOUNT_TRANSLATABLE_FIELDS.put("isYougouAdmin", "??");
        // ?
        CONTACT_TRANSLATABLE_FIELDS.put("contact", "??");
        CONTACT_TRANSLATABLE_FIELDS.put("type", "");
        CONTACT_TRANSLATABLE_FIELDS.put("telePhone", "???");
        CONTACT_TRANSLATABLE_FIELDS.put("mobilePhone", "??");
        CONTACT_TRANSLATABLE_FIELDS.put("fax", "??");
        CONTACT_TRANSLATABLE_FIELDS.put("email", "?");
        CONTACT_TRANSLATABLE_FIELDS.put("address", "?");
        // ??
        CONTRACT_TRANSLATABLE_FIELDS.put("contractNo", "???");
        CONTRACT_TRANSLATABLE_FIELDS.put("effectiveDate", "()");
        CONTRACT_TRANSLATABLE_FIELDS.put("failureDate", "()");
        CONTRACT_TRANSLATABLE_FIELDS.put("clearingForm", "?");
        // ?
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("supplierName", "??");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("consigneeName", "??");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("consigneePhone", "");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("consigneeTell", "?");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("warehousePostcode", "");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("warehouseArea", "");
        AFTER_SERVICE_TRANSLATABLE_FIELDS.put("warehouseAdress", "?");
    }

    public static String buildMerchantBasicDataOperationNotes(SupplierVo source, SupplierVo target)
            throws Exception {
        if (target == null) {
            throw new NullPointerException("target");
        }
        if (source == null) {
            return "?";
        }

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : BASIC_DATA_TRANSLATABLE_FIELDS.entrySet()) {
            Object o1 = PropertyUtils.getProperty(source, entry.getKey());
            Object o2 = PropertyUtils.getProperty(target, entry.getKey());
            if (!ObjectUtils.equals(o1, o2)) {
                if (StringUtils.equals("isInputYougouWarehouse", entry.getKey())) {
                    CooperationModel[] cooperationModels = CooperationModel.values();
                    o1 = cooperationModels[(Integer) o1].getDescription();
                    o2 = cooperationModels[(Integer) o2].getDescription();
                } else if (StringUtils.equals("shipmentType", entry.getKey())) {
                    o1 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o1) ? "" : "";
                    o2 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o2) ? "" : "";
                }
                sb.append(MessageFormat.format("{0}??{1}?{2}{3}", entry.getValue(),
                        o1, o2, LINE_SEPARATOR));
            }
        }
        return sb.toString();
    }

    public static String buildMerchantAccountOperationNotes(MerchantUser source, MerchantUser target)
            throws Exception {
        if (target == null) {
            throw new NullPointerException("target");
        }
        if (source == null) {
            return "??";
        }

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : ACCOUNT_TRANSLATABLE_FIELDS.entrySet()) {
            Object o1 = PropertyUtils.getProperty(source, entry.getKey());
            Object o2 = PropertyUtils.getProperty(target, entry.getKey());
            if (!ObjectUtils.equals(o1, o2)) {
                if (StringUtils.equals("status", entry.getKey())) {
                    o1 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o1) ? "?" : "?";
                    o2 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o2) ? "?" : "?";
                } else if (StringUtils.equals("isAdministrator", entry.getKey())
                        || StringUtils.equals("deleteFlag", entry.getKey())
                        || StringUtils.equals("isYougouAdmin", entry.getKey())) {
                    o1 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o1) ? "" : "?";
                    o2 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o2) ? "" : "?";
                }
                sb.append(MessageFormat.format("{0}??{1}?{2}{3}", entry.getValue(),
                        o1, o2, LINE_SEPARATOR));
            }
        }
        return sb.toString();
    }

    public static String buildContactOperationNotes(ContactsVo source, ContactsVo target) throws Exception {
        if (target == null) {
            throw new NullPointerException("target");
        }
        if (source == null) {
            return "?";
        }

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : CONTACT_TRANSLATABLE_FIELDS.entrySet()) {
            Object o1 = PropertyUtils.getProperty(source, entry.getKey());
            Object o2 = PropertyUtils.getProperty(target, entry.getKey());
            if (!ObjectUtils.equals(o1, o2)) {
                if (StringUtils.equals("type", entry.getKey())) {
                    o1 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o1) ? ""
                            : ObjectUtils.equals(2, o1) ? "?"
                                    : ObjectUtils.equals(3, o1) ? ""
                                            : ObjectUtils.equals(4, o1) ? ""
                                                    : ObjectUtils.equals(5, o1) ? "" : "";
                    o2 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o2) ? ""
                            : ObjectUtils.equals(2, o2) ? "?"
                                    : ObjectUtils.equals(3, o2) ? ""
                                            : ObjectUtils.equals(4, o2) ? ""
                                                    : ObjectUtils.equals(5, o2) ? "" : "";
                }
                sb.append(MessageFormat.format("{0}??{1}?{2}{3}", entry.getValue(),
                        o1, o2, LINE_SEPARATOR));
            }
        }
        return sb.toString();
    }

    public static String builContractOperationNotes(ContractVo source, ContractVo target) throws Exception {
        if (target == null) {
            throw new NullPointerException("target");
        }
        if (source == null) {
            return "??";
        }

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : CONTRACT_TRANSLATABLE_FIELDS.entrySet()) {
            Object o1 = PropertyUtils.getProperty(source, entry.getKey());
            Object o2 = PropertyUtils.getProperty(target, entry.getKey());
            if (!ObjectUtils.equals(o1, o2)) {
                if (StringUtils.equals("clearingForm", entry.getKey())) {
                    o1 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o1) ? ""
                            : ObjectUtils.equals(2, o1) ? ""
                                    : ObjectUtils.equals(3, o1) ? "?"
                                            : ObjectUtils.equals(4, o1) ? "" : "";
                    o2 = ObjectUtils.equals(NumberUtils.INTEGER_ONE, o2) ? ""
                            : ObjectUtils.equals(2, o2) ? ""
                                    : ObjectUtils.equals(3, o2) ? "?"
                                            : ObjectUtils.equals(4, o2) ? "" : "";
                }
                sb.append(MessageFormat.format("{0}??{1}?{2}{3}", entry.getValue(),
                        o1, o2, LINE_SEPARATOR));
            }
        }
        return sb.toString();
    }

    public static String buildRejectAddressOperationNotes(RejectedAddressVo source, RejectedAddressVo target)
            throws Exception {
        if (target == null) {
            throw new NullPointerException("target");
        }
        if (source == null) {
            return "??";
        }

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : AFTER_SERVICE_TRANSLATABLE_FIELDS.entrySet()) {
            Object o1 = PropertyUtils.getProperty(source, entry.getKey());
            Object o2 = PropertyUtils.getProperty(target, entry.getKey());
            if (!ObjectUtils.equals(o1, o2)) {
                sb.append(MessageFormat.format("{0}??{1}?{2}{3}", entry.getValue(),
                        o1, o2, LINE_SEPARATOR));
            }
        }
        return sb.toString();
    }

    /**
     * ??
     */
    public static enum CooperationModel {
        /*
         * ??????(???)
         */
        NON_ENTER_YOUGOU_WAREHOUSE_MERCHANT_DELIVERY("??",
                true), ENTER_YOUGOU_WAREHOUSE_YOUGOU_DELIVERY(
                        "?"), NON_ENTER_YOUGOU_WAREHOUSE_YOUGOU_DELIVERY(
                                "??");

        private String description;
        private boolean checked;

        private CooperationModel(String description) {
            this(description, false);
        }

        private CooperationModel(String description, boolean checked) {
            this.description = description;
            this.checked = checked;
        }

        public String getDescription() {
            return description;
        }

        public boolean isChecked() {
            return checked;
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {

    }

}