admin
2019-02-18 69ca458784b49c11b33dbee404ee242b4fb0b9c2
框架修改
33个文件已添加
3956 ■■■■■ 已修改文件
fanli-common-config/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-common-config/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-common/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-common/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-goods/src/main/java/org/fanli/facade/goods/utils/RedisGoodsManager.java 293 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-goods/src/main/java/org/fanli/facade/goods/utils/taobao/TaoKeGoodsApiUtil.java 1585 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-order/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-order/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/dto/taobao/TaoKeAppInfo.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/hongbao/HongBaoManage.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/exception/TaoKeApiException.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/service/hongbao/HongBaoManageService.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/util/taobao/TaoBaoHttpUtil.java 493 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/util/taobao/TaoKeBaseUtil.java 292 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/.project 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-order/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-order/.project 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/.project 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/hongbao/HongBaoManageMapper.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/common/SystemClientParamsMapper.xml 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/common/SystemManageMapper.xml 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/hongbao/HongBaoManageMapper.xml 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/hongbao/HongBaoManageServiceImpl.java 138 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/.project 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-utils/.classpath 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-utils/.project 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-common-config/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-common-config/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-common-config</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
fanli-common/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-common/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-common</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
fanli-facade-goods/src/main/java/org/fanli/facade/goods/utils/RedisGoodsManager.java
New file
@@ -0,0 +1,293 @@
package org.fanli.facade.goods.utils;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.goods.entity.taobao.TaoBaoShopInfo;
import org.fanli.facade.goods.entity.taobao.TaoBaoUnionConfig;
import org.fanli.facade.goods.exception.taobao.TaobaoGoodsDownException;
import org.fanli.facade.goods.service.taobao.TaoBaoShopService;
import org.fanli.facade.goods.service.taobao.TaoBaoUnionConfigService;
import org.fanli.facade.goods.utils.taobao.TaoBaoCouponUtil;
import org.fanli.facade.goods.utils.taobao.TaoBaoUtil;
import org.fanli.facade.goods.utils.taobao.TaoKeGoodsApiUtil;
import org.springframework.stereotype.Component;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.base.Constant;
import com.yeshi.fanli.base.dto.ImageInfo;
import com.yeshi.fanli.base.entity.goods.TaoBaoGoodsBrief;
import com.yeshi.fanli.base.entity.user.PidUser;
import com.yeshi.fanli.base.log.LogHelper;
import net.sf.json.JSONArray;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
 * 商品的Redis缓存
 *
 * @author Administrator
 *
 */
@Component
public class RedisGoodsManager {
    @Resource
    private JedisPool jedisPool;
    @Resource
    private TaoBaoShopService taoBaoShopService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     */
    private void setString(String key, String value) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.set(key, value);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    /**
     * 删除某个键值
     *
     * @param key
     * @param value
     */
    private void removeKey(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.del(key);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    /**
     * 缓存字符串
     *
     * @param key
     * @param value
     * @param seconds
     *            -缓存时间(s)
     */
    private void setString(String key, String value, int seconds) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.setex(key, seconds, value);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    private String getString(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            return jedis.get(key);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    public void cacheCommonString(String key, String value, int seconds) {
        setString(key, value, seconds);
    }
    public void cacheCommonString(String key, String value) {
        setString(key, value);
    }
    public String getCommonString(String key) {
        return getString(key);
    }
    public void removeCommonString(String key) {
        removeKey(key);
    }
    /**
     * 将信息永久保存到Redis
     *
     * @param goods
     */
    public void saveTaoBaoGoodsBriefForever(TaoBaoGoodsBrief goods) {
        String key = "taobao-goods-" + goods.getAuctionId();
        if (Constant.IS_OUTNET) {
            cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods));
        }
    }
    /**
     * 删除缓存
     *
     * @param auctionId
     */
    public void deleteTaoBaoGoodsBrief(Long auctionId) {
        String key = "taobao-goods-" + auctionId;
        if (Constant.IS_OUTNET)
            removeKey(key);
    }
    public TaoBaoGoodsBrief getTaoBaoGoodsBrief(long auctionId) throws TaobaoGoodsDownException {
        long startTime = System.currentTimeMillis();
        String key = "taobao-goods-" + auctionId;
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = null;
            goods = TaoKeGoodsApiUtil.searchGoodsDetail(auctionId);
            if (goods != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 20);
            LogHelper.test(auctionId + "-获取商品详情耗时:" + (System.currentTimeMillis() - startTime));
            return goods;
        } else {// 直接取缓存
            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
        }
    }
    public List<ImageInfo> getTaoBaoGoodsDetailImgs(long auctionId) {
        String key = "taobao-goods-detailimgs-size-" + auctionId;
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            List<ImageInfo> list = null;
            try {
                list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (list == null || list.size() == 0) {
                list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
            }
            if (list != null && list.size() > 0)
                // 缓存1天
                if (Constant.IS_OUTNET)
                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(list), 60 * 60 * 24);
            return list;
        } else {// 直接取缓存
            List<ImageInfo> imgList = new Gson().fromJson(value, new TypeToken<List<ImageInfo>>() {
            }.getType());
            return imgList;
        }
    }
    public String getXCXCouponToken(TaoBaoGoodsBrief tb) {
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
        String key = "taobao-couple-xcx-" + tb.getAuctionId();
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            value = TaoKeGoodsApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), TaoBaoCouponUtil
                    .getCoupleUrl(tb.getCouponActivityId(), configList.get(0).getDefaultPid(), tb.getAuctionId() + ""));
            if (value != null)
                // 缓存20分钟
                if (Constant.IS_OUTNET)
                cacheCommonString(key, value, 60 * 20);
            return value;
        } else {// 直接取缓存
            return value;
        }
    }
    /**
     * IP访问频率限制 适用于 小程序,H5,WEB 同一IP,5s内限制请求100次
     *
     * @param ip
     */
    public boolean ipFrequencyLimit(String ip, String apiName) {
        String key = ip + "-" + StringUtil.Md5(apiName);
        Jedis jedis = jedisPool.getResource();
        try {
            long count = jedis.incr(key);
            if (count == 1)
                jedis.expire(key, 5);
            if (count >= 100)
                return true;
            else
                return false;
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    /**
     * 获取淘宝图片
     *
     * @param auctionId
     * @return
     */
    public List<String> getTBImg(Long auctionId) {
        String key = "taobao-img-" + auctionId;
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            List<String> list = TaoBaoUtil.getTbImg(auctionId + "");
            if (Constant.IS_OUTNET && list != null && list.size() > 0) {
                value = new Gson().toJson(list);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            return list;
        } else {
            JSONArray array = JSONArray.fromObject(value);
            List<String> list = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                list.add(array.getString(i));
            }
            return list;
        }
    }
    /**
     * 获取淘宝店铺信息
     *
     * @param shopTitle
     * @param sellerId
     * @return
     */
    public TaoBaoShopInfo getTBShopInfo(String shopTitle, Long sellerId, Long auctionId) {
        String key = "taobao-shop-" + sellerId;
        String value = "";
        if (Constant.IS_OUTNET)
            value = getCommonString(key);
        if (StringUtil.isNullOrEmpty(value)) {
            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
            goods.setShopTitle(shopTitle);
            goods.setSellerId(sellerId);
            goods.setAuctionId(auctionId);
            TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
            if (Constant.IS_OUTNET && info != null) {
                value = new Gson().toJson(info);
                cacheCommonString(key, value, 60 * 60 * 2);
            }
            return info;
        } else {
            return new Gson().fromJson(value, TaoBaoShopInfo.class);
        }
    }
}
fanli-facade-goods/src/main/java/org/fanli/facade/goods/utils/taobao/TaoKeGoodsApiUtil.java
New file
@@ -0,0 +1,1585 @@
package org.fanli.facade.goods.utils.taobao;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.fanli.facade.goods.dto.taobao.TaoBaoHead;
import org.fanli.facade.goods.dto.taobao.TaoBaoProvince;
import org.fanli.facade.goods.dto.taobao.TaoBaoSearchNav;
import org.fanli.facade.goods.dto.taobao.TaoBaoSearchResult;
import org.fanli.facade.goods.dto.taoke.RelateGoods;
import org.fanli.facade.goods.entity.taobao.TaoBaoShopInfo;
import org.fanli.facade.goods.exception.taobao.TaobaoGoodsDownException;
import org.fanli.facade.order.entity.order.TaoBaoOrder;
import org.fanli.facade.system.dto.taobao.TaoKeAppInfo;
import org.fanli.facade.system.exception.TaoKeApiException;
import org.fanli.facade.system.util.taobao.TaoKeBaseUtil;
import org.yeshi.utils.MoneyBigDecimalUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.taobao.api.ApiException;
import com.yeshi.fanli.base.dto.PageEntity;
import com.yeshi.fanli.base.dto.SearchFilter;
import com.yeshi.fanli.base.entity.goods.TaoBaoGoodsBrief;
import com.yeshi.fanli.base.log.LogHelper;
import com.yeshi.fanli.base.log.TaoKeLogHelper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
//淘宝客API接口
public class TaoKeGoodsApiUtil {
    /**
     * 按关键字和分类搜索券
     *
     * @param key
     * @param catList
     * @return
     */
    public static TaoBaoSearchResult searchCouple(String key, List<Long> catList, int page, int pageSize) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.item.coupon.get");
        map.put("page_size", pageSize + "");
        map.put("page_no", page + "");
        String cate = "";
        if (catList != null && catList.size() > 10)
            catList = catList.subList(0, 10);
        if (catList != null && catList.size() > 0) {
            for (Long c : catList)
                cate += c + ",";
            if (cate.endsWith(","))
                cate = cate.substring(0, cate.length() - 1);
            map.put("cat", cate);
        }
        if (!StringUtil.isNullOrEmpty(key)) {
            map.put("q", key);
        }
        String result = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(result);
        TaoBaoSearchResult finalResult = parseCoupleContent(result);
        if (finalResult == null)
            return null;
        PageEntity pageEntity = finalResult.getPageEntity();
        pageEntity.setPageIndex(page);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotalPage(pageEntity.getTotalCount() % pageSize == 0
                ? ((int) (pageEntity.getTotalCount() / pageSize)) : (int) (pageEntity.getTotalCount() / pageSize + 1));
        finalResult.setPageEntity(pageEntity);
        return finalResult;
    }
    // 解析券的内容
    private static TaoBaoSearchResult parseCoupleContent(String content) {
        TaoBaoSearchResult result = new TaoBaoSearchResult();
        JSONObject root = JSONObject.fromObject(content);
        root = root.optJSONObject("tbk_dg_item_coupon_get_response");
        if (root.optJSONObject("results") == null)
            return null;
        JSONArray array = root.optJSONObject("results").optJSONArray("tbk_coupon");
        if (array != null) {
            List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                JSONObject item = array.optJSONObject(i);
                TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
                goods.setPictUrl(item.optString("pict_url"));
                goods.setAuctionId(item.optLong("num_iid"));
                goods.setAuctionUrl(item.optString("item_url"));
                goods.setBiz30day(item.optInt("volume"));
                goods.setCouponInfo(item.optString("coupon_info"));
                List<BigDecimal> quanInfo = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
                goods.setCouponAmount(quanInfo.get(1));
                goods.setCouponEffectiveEndTime(item.optString("coupon_end_time"));
                goods.setCouponEffectiveStartTime(item.optString("coupon_start_time"));
                goods.setCouponStartFee(quanInfo.get(0));
                goods.setCouponLeftCount(item.optInt("coupon_remain_count"));
                goods.setCouponLink(item.optString("coupon_click_url"));
                goods.setCouponTotalCount(item.optInt("coupon_total_count"));
                goods.setDayLeft(-1);
                if (item.optJSONObject("small_images") != null) {
                    JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
                    if (imgArray != null) {
                        List<String> imgList = new ArrayList<>();
                        for (int n = 0; n < imgArray.size(); n++) {
                            imgList.add(imgArray.optString(n));
                        }
                        goods.setImgList(imgList);
                    }
                }
                goods.setSellerId(item.optLong("seller_id"));
                goods.setShopTitle(item.optString("shop_title"));
                goods.setTitle(item.optString("title"));
                goods.setTkRate(new BigDecimal(item.optString("commission_rate")));
                goods.setTotalNum(1000);
                goods.setUserType(item.optInt("user_type"));
                goods.setUserTypeName("");
                goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
                if (goods.getZkPrice().compareTo(goods.getCouponStartFee()) >= 0
                        && goods.getZkPrice().compareTo(goods.getCouponAmount()) > 0) {
                    BigDecimal finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
                    goods.setTkCommFee(finalPrice.multiply(goods.getTkRate()).divide(new BigDecimal(100)));
                } else
                    goods.setTkCommFee(new BigDecimal(0));
                goodsList.add(goods);
            }
            result.setTaoBaoGoodsBriefs(goodsList);
            int totalCount = 1000;// root.optInt("total_results");
            PageEntity pe = new PageEntity(0, 0, totalCount);
            result.setPageEntity(pe);
        }
        result.setNavList(new ArrayList<>());
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount());
        result.setTaoBaoHead(taoBaoHead);
        return result;
    }
    /**
     * 获取商品详情,简版
     *
     * @param id
     *            -商品AuctionId
     * @return
     */
    public static TaoBaoGoodsBrief getSimpleGoodsInfo(Long id) throws TaobaoGoodsDownException {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.info.get");
        map.put("num_iids", id + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        // System.out.println(resultStr);
        JSONObject data = JSONObject.fromObject(resultStr);
        // 商品下架
        if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 15
                && data.optJSONObject("error_response").optInt("sub_code") == 50001) {
            throw new TaobaoGoodsDownException(data.optJSONObject("error_response").optInt("code"), "商品下架");
        }
        if (data.optJSONObject("tbk_item_info_get_response") == null)
            return null;
        JSONArray array = data.optJSONObject("tbk_item_info_get_response").optJSONObject("results")
                .optJSONArray("n_tbk_item");
        if (array != null && array.size() > 0) {
            JSONObject item = array.optJSONObject(0);
            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
            goods.setAuctionId(item.optLong("num_iid"));
            goods.setAuctionUrl(item.optString("item_url"));
            goods.setBiz30day(item.optInt("volume"));
            if (item.optJSONObject("small_images") != null) {
                JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
                if (imgArray != null) {
                    List<String> imgList = new ArrayList<>();
                    for (int n = 0; n < imgArray.size(); n++) {
                        imgList.add(imgArray.optString(n));
                    }
                    goods.setImgList(imgList);
                }
            }
            goods.setTitle(item.optString("title"));
            goods.setUserType(item.optInt("user_type"));
            goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
            goods.setReservePrice(new BigDecimal(item.optString("zk_final_price")));
            goods.setAuctionUrl(item.optString("item_url"));
            goods.setProvcity(item.optString("provcity"));
            goods.setPictUrl(item.optString("pict_url"));
            goods.setShopTitle(item.optString("nick"));
            goods.setSellerId(item.optLong("seller_id"));
            String optString = item.optString("shop_dsr");
            if (!StringUtil.isNullOrEmpty(optString)) {
                goods.setShopDsr(new Integer(optString));
            }
            String ratesum = item.optString("ratesum");
            if (!StringUtil.isNullOrEmpty(ratesum)) {
                goods.setRatesum(new Integer(ratesum));
            }
            if (item.optBoolean("is_prepay"))
                goods.setIsPrepay(1);
            if (item.optBoolean("i_rfd_rate"))
                goods.setRfdRate(1);
            if (item.optBoolean("h_good_rate"))
                goods.setGoodRate(1);
            if (item.optBoolean("h_pay_rate30"))
                goods.setPayRate30(1);
            if (item.optBoolean("free_shipment"))
                goods.setFreeShipment(1);
            if (!StringUtil.isNullOrEmpty(item.optString("material_lib_type")))
                goods.setMaterialLibType(item.optInt("material_lib_type"));
            return goods;
        }
        return null;
    }
    public String convertSpecialGoodsLink(Long auctionId, TaoKeAppInfo app) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.coupon.convert");
        map.put("item_id", auctionId + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, app);
        return resultStr;
    }
    public static List<TaoBaoGoodsBrief> getBatchGoodsInfo(List<Long> listId)
            throws TaoKeApiException, TaobaoGoodsDownException {
        if (listId == null || listId.size() == 0) {
            throw new TaobaoGoodsDownException(1, "淘宝商品ID不能为空");
        }
        if (listId.size() > 40) {
            throw new TaobaoGoodsDownException(1, "淘宝商品ID不能超过40个");
        }
        StringBuffer ids = new StringBuffer();
        for (Long id : listId) {
            ids.append(id + ",");
        }
        return getBatchGoodsInfos(ids.substring(0, ids.length() - 1));
    }
    /**
     * 获取商品详情,简版
     *
     * @param id
     * @return
     */
    public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids) throws TaobaoGoodsDownException {
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.info.get");
        map.put("num_iids", ids + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject data = JSONObject.fromObject(resultStr);
        // 商品下架
        if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 15
                && data.optJSONObject("error_response").optInt("sub_code") == 50001) {
            throw new TaobaoGoodsDownException(data.optJSONObject("error_response").optInt("code"), "商品下架");
        }
        if (data.optJSONObject("tbk_item_info_get_response") == null)
            return null;
        JSONArray array = data.optJSONObject("tbk_item_info_get_response").optJSONObject("results")
                .optJSONArray("n_tbk_item");
        if (array != null && array.size() > 0) {
            for (int i = 0; i < array.size(); i++) {
                TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
                JSONObject item = array.optJSONObject(i);
                goods.setAuctionId(item.optLong("num_iid"));
                goods.setAuctionUrl(item.optString("item_url"));
                goods.setBiz30day(item.optInt("volume"));
                if (item.optJSONObject("small_images") != null) {
                    JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
                    if (imgArray != null) {
                        List<String> imgList = new ArrayList<>();
                        for (int n = 0; n < imgArray.size(); n++) {
                            imgList.add(imgArray.optString(n));
                        }
                        goods.setImgList(imgList);
                    }
                }
                goods.setTitle(item.optString("title"));
                goods.setUserType(item.optInt("user_type"));
                goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
                goods.setReservePrice(new BigDecimal(item.optString("zk_final_price")));
                goods.setAuctionUrl(item.optString("item_url"));
                goods.setProvcity(item.optString("provcity"));
                goods.setPictUrl(item.optString("pict_url"));
                goods.setShopTitle(item.optString("nick"));
                String optString = item.optString("shop_dsr");
                if (!StringUtil.isNullOrEmpty(optString)) {
                    goods.setShopDsr(new Integer(optString));
                }
                String ratesum = item.optString("ratesum");
                if (!StringUtil.isNullOrEmpty(ratesum)) {
                    goods.setRatesum(new Integer(ratesum));
                }
                if (item.optBoolean("is_prepay"))
                    goods.setIsPrepay(1);
                if (item.optBoolean("i_rfd_rate"))
                    goods.setRfdRate(1);
                if (item.optBoolean("h_good_rate"))
                    goods.setGoodRate(1);
                if (item.optBoolean("h_pay_rate30"))
                    goods.setPayRate30(1);
                if (item.optBoolean("free_shipment"))
                    goods.setFreeShipment(1);
                if ("1".equalsIgnoreCase(item.optString("material_lib_type")))
                    ;
                goodsList.add(goods);
            }
        }
        return goodsList;
    }
    /**
     * 搜索商品详情-详细
     *
     * @param id
     * @return
     * @throws TaobaoGoodsDownException
     */
    public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
        TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
        if (goods == null)
            return null;
        SearchFilter filter = new SearchFilter();
        filter.setKey(goods.getTitle());
        filter.setPage(1);
        filter.setPageSize(50);
        TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                goods.getUserType());
        if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                if (goods.getAuctionId().longValue() == g.getAuctionId()) {
                    g.setId(goods.getAuctionId());
                    // 判断是否有优惠券
                    if (!StringUtil.isNullOrEmpty(g.getCouponActivityId())) {
                        // 获取优惠券详情
                        QuanInfo quanInfo = getQuanInfo(g.getAuctionId(), g.getCouponActivityId());
                        if (quanInfo != null) {
                            g.setCouponAmount(quanInfo.coupon_amount);
                            g.setCouponEffectiveEndTime(quanInfo.coupon_end_time);
                            g.setCouponEffectiveStartTime(quanInfo.coupon_start_time);
                            g.setCouponLeftCount(quanInfo.coupon_remain_count);
                            g.setCouponStartFee(quanInfo.coupon_start_fee);
                            g.setCouponTotalCount(quanInfo.coupon_total_count);
                        }
                    } else {
                        g.setCouponAmount(new BigDecimal(0));
                        g.setCouponStartFee(new BigDecimal(0));
                    }
                    g.setCreatetime(new Date());
                    return g;
                }
            }
        // 再从淘宝联盟网页搜索
        filter.setKey(goods.getAuctionUrl());
        TaoBaoSearchResult searchResult = TaoBaoUtil.searchFromAlimamaWeb(filter, null);
        if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null
                && searchResult.getTaoBaoGoodsBriefs().size() > 0) {
            for (TaoBaoGoodsBrief g : searchResult.getTaoBaoGoodsBriefs()) {
                if (g.getAuctionId().longValue() == goods.getAuctionId()) {
                    g.setImgList(goods.getImgList());
                    goods = g;
                    if ("无".equalsIgnoreCase(goods.getCouponInfo()))
                        goods.setCouponInfo(null);
                    return goods;
                }
            }
        }
        TaoKeLogHelper.error(null, "没有搜索到详情:" + id);
        goods.setCouponAmount(new BigDecimal("0"));
        goods.setTkMktStatus("1");
        goods.setTkRate(new BigDecimal("0"));
        goods.setReservePrice(new BigDecimal(0));
        goods.setTkCommFee(new BigDecimal(0));
        return goods;
    }
    /**
     * 搜索商品详情-详细
     *
     * @param id
     * @return
     * @throws TaobaoGoodsDownException
     */
    public static TaoBaoGoodsBrief searchGoodsDetail(Long id, TaoKeAppInfo app) throws TaobaoGoodsDownException {
        TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
        if (goods == null)
            return null;
        SearchFilter filter = new SearchFilter();
        filter.setKey(goods.getTitle());
        filter.setPage(1);
        filter.setPageSize(50);
        TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                goods.getUserType(), app);
        if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                if (goods.getAuctionId().longValue() == g.getAuctionId()) {
                    g.setId(goods.getAuctionId());
                    // 判断是否有优惠券
                    if (!StringUtil.isNullOrEmpty(g.getCouponActivityId())) {
                        // 获取优惠券详情
                        QuanInfo quanInfo = getQuanInfo(g.getAuctionId(), g.getCouponActivityId());
                        if (quanInfo != null) {
                            g.setCouponAmount(quanInfo.coupon_amount);
                            g.setCouponEffectiveEndTime(quanInfo.coupon_end_time);
                            g.setCouponEffectiveStartTime(quanInfo.coupon_start_time);
                            g.setCouponLeftCount(quanInfo.coupon_remain_count);
                            g.setCouponStartFee(quanInfo.coupon_start_fee);
                            g.setCouponTotalCount(quanInfo.coupon_total_count);
                        }
                    } else {
                        g.setCouponAmount(new BigDecimal(0));
                        g.setCouponStartFee(new BigDecimal(0));
                    }
                    g.setCreatetime(new Date());
                    return g;
                }
            }
        // 再从淘宝联盟网页搜索
        filter.setKey(goods.getAuctionUrl());
        TaoBaoSearchResult searchResult = TaoBaoUtil.searchFromAlimamaWeb(filter, null);
        if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null
                && searchResult.getTaoBaoGoodsBriefs().size() > 0) {
            for (TaoBaoGoodsBrief g : searchResult.getTaoBaoGoodsBriefs()) {
                if (g.getAuctionId().longValue() == goods.getAuctionId()) {
                    g.setImgList(goods.getImgList());
                    goods = g;
                    if ("无".equalsIgnoreCase(goods.getCouponInfo()))
                        goods.setCouponInfo(null);
                    return goods;
                }
            }
        }
        TaoKeLogHelper.error(null, "没有搜索到详情:" + id);
        goods.setCouponAmount(new BigDecimal("0"));
        goods.setTkMktStatus("1");
        goods.setTkRate(new BigDecimal("0"));
        goods.setReservePrice(new BigDecimal(0));
        goods.setTkCommFee(new BigDecimal(0));
        return goods;
    }
    /**
     * 物料转链
     *
     * @param id
     * @param app
     * @return
     * @throws TaobaoGoodsDownException
     */
    public static TaoBaoGoodsBrief searchGoodsDetailForConvert(Long id, TaoKeAppInfo app)
            throws TaobaoGoodsDownException {
        TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
        if (goods == null)
            return null;
        SearchFilter filter = new SearchFilter();
        filter.setKey(goods.getTitle());
        filter.setPage(1);
        filter.setPageSize(50);
        TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                goods.getUserType(), app);
        if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                if (goods.getAuctionId().longValue() == g.getAuctionId()) {
                    g.setId(goods.getAuctionId());
                    g.setCreatetime(new Date());
                    return g;
                }
            }
        TaoKeLogHelper.error(null, "没有搜索到详情:" + id);
        goods.setCouponAmount(new BigDecimal("0"));
        goods.setTkMktStatus("1");
        goods.setTkRate(new BigDecimal("0"));
        goods.setReservePrice(new BigDecimal(0));
        goods.setTkCommFee(new BigDecimal(0));
        return goods;
    }
    public static List<TaoBaoGoodsBrief> searchBatchGoodsDetail(String ids) throws TaobaoGoodsDownException {
        List<TaoBaoGoodsBrief> goodsBriefList = getBatchGoodsInfos(ids);
        if (goodsBriefList == null || goodsBriefList.size() == 0) {
            return null;
        }
        // System.out.println("---------goodsBriefList--------------:"+
        // goodsBriefList.size());
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        for (TaoBaoGoodsBrief goods : goodsBriefList) {
            boolean pross = false;
            SearchFilter filter = new SearchFilter();
            filter.setKey(goods.getTitle());
            filter.setPage(1);
            filter.setPageSize(50);
            TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                    goods.getUserType());
            if (result != null && result.getTaoBaoGoodsBriefs() != null)
                for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                    if (goods.getAuctionId().longValue() == g.getAuctionId()) {
                        g.setId(goods.getAuctionId());
                        g.setAuctionUrl(goods.getAuctionUrl());
                        g.setShopTitle(goods.getShopTitle());
                        // 判断是否有优惠券
                        if (!StringUtil.isNullOrEmpty(g.getCouponActivityId())) {
                            // 获取优惠券详情
                            QuanInfo quanInfo = getQuanInfo(g.getAuctionId(), g.getCouponActivityId());
                            if (quanInfo != null) {
                                g.setCouponAmount(quanInfo.coupon_amount);
                                g.setCouponEffectiveEndTime(quanInfo.coupon_end_time);
                                g.setCouponEffectiveStartTime(quanInfo.coupon_start_time);
                                g.setCouponLeftCount(quanInfo.coupon_remain_count);
                                g.setCouponStartFee(quanInfo.coupon_start_fee);
                                g.setCouponTotalCount(quanInfo.coupon_total_count);
                            }
                        } else {
                            g.setCouponAmount(new BigDecimal(0));
                            g.setCouponStartFee(new BigDecimal(0));
                        }
                        g.setCreatetime(new Date());
                        goodsList.add(g);
                        pross = true;
                        break;
                    }
                }
            if (pross)
                continue;
            // 再从淘宝联盟网页搜索
            filter.setKey(goods.getAuctionUrl());
            TaoBaoSearchResult searchResult = TaoBaoUtil.searchFromAlimamaWeb(filter, null);
            if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null
                    && searchResult.getTaoBaoGoodsBriefs().size() > 0) {
                for (TaoBaoGoodsBrief g : searchResult.getTaoBaoGoodsBriefs()) {
                    if (g.getAuctionId().longValue() == goods.getAuctionId()) {
                        g.setImgList(goods.getImgList());
                        g.setId(goods.getAuctionId());
                        g.setAuctionUrl(goods.getAuctionUrl());
                        g.setShopTitle(goods.getShopTitle());
                        goods = g;
                        if ("无".equalsIgnoreCase(goods.getCouponInfo()))
                            goods.setCouponInfo(null);
                        goodsList.add(goods);
                        pross = true;
                        break;
                    }
                }
            }
            if (pross)
                continue;
            goods.setCouponAmount(new BigDecimal("0"));
            goods.setTkMktStatus("1");
            goods.setTkRate(new BigDecimal("0"));
            goods.setReservePrice(new BigDecimal(0));
            goods.setTkCommFee(new BigDecimal(0));
            goodsList.add(goods);
        }
        return goodsList;
    }
    /**
     * 商品物料搜索
     *
     * @param filter
     * @return
     */
    public static TaoBaoSearchResult searchWuLiao(SearchFilter filter) {
        if (filter.getKey() != null && filter.getKey().trim().equalsIgnoreCase(""))
            return null;
        if (filter.getKey() != null && filter.getKey().length() > 100)
            return null;
        PageEntity pageEntity = new PageEntity();
        TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.material.optional");
        map.put("page_size", filter.getPageSize() == 0 ? "20" : filter.getPageSize() + "");
        map.put("page_no", (filter.getPage() <= 0 ? 1 : filter.getPage()) + "");
        // map.put("material_id", "3756");
        pageEntity.setPageIndex(filter.getPage());
        pageEntity.setPageSize(filter.getPageSize() == 0 ? 20 : filter.getPageSize());
        // 包含了地区筛选
        if (filter.getProvinceId() > 0) {
            List<TaoBaoProvince> provinceList = TaoBaoUtil.getTaoBaoProvinceList();
            for (TaoBaoProvince province : provinceList) {
                if (Integer.parseInt(province.getId()) == filter.getProvinceId()) {
                    map.put("itemloc", province.getName());
                    break;
                }
            }
        }
        if (filter.getMaterialId() != null)
            map.put("material_id", filter.getMaterialId());
        if (filter.getStartPrice() != null)
            map.put("start_price", filter.getStartPrice() + "");
        if (filter.getEndPrice() != null)
            map.put("end_price", filter.getEndPrice() + "");
        if (filter.getStartTkRate() > 0)
            map.put("start_tk_rate", filter.getStartTkRate() + "");
        if (filter.getEndTkRate() > 0)
            map.put("end_tk_rate", filter.getEndTkRate() + "");
        if (filter.getStartKaTkRate() > 0)
            map.put("start_ka_tk_rate", filter.getStartKaTkRate() + "");
        if (filter.getEndKaTkRate() > 0)
            map.put("end_ka_tk_rate", filter.getEndKaTkRate() + "");
        if (filter.isTmall())
            map.put("is_tmall", filter.isTmall() + "");
        if (filter.isOverseas())
            map.put("is_overseas", filter.isOverseas() + "");
        if (filter.isBaoYou())
            map.put("need_free_shipment", filter.isBaoYou() + "");
        if (filter.isNeedPrepay())
            map.put("need_prepay", filter.isNeedPrepay() + "");
        if (filter.isIncludePayRate30())
            map.put("include_pay_rate_30", filter.isIncludePayRate30() + "");
        if (filter.isIncludeGoodRate())
            map.put("include_good_rate", filter.isIncludeGoodRate() + "");
        if (filter.isIncludeRfdRate())
            map.put("include_rfd_rate", filter.isIncludeRfdRate() + "");
        if (filter.getStartDsr() > 0)
            map.put("start_dsr", filter.getStartDsr() + "");
        if (filter.getNpxLevel() > 0)
            map.put("npx_level", filter.getNpxLevel() + "");
        if (!StringUtil.isNullOrEmpty(filter.getCateIds()))
            map.put("cat", filter.getCateIds());
        if (!StringUtil.isNullOrEmpty(filter.getKey()))
            map.put("q", filter.getKey());
        if (filter.getQuan() > 0)
            map.put("has_coupon", true + "");
        if (!StringUtil.isNullOrEmpty(filter.getIp()))
            map.put("ip", filter.getIp());
        if (filter.getSort() > 0) {
            if (filter.getSort() == TaoBaoUtil.SORT_SALE_HIGH_TO_LOW) {
                map.put("sort", "total_sales_des"); // 销量从高到低
            } else if (filter.getSort() == TaoBaoUtil.SORT_SALE_LOW_TO_HIGH) {
                map.put("sort", "total_sales_asc"); // 销量从低到高
            } else if (filter.getSort() == TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW) {
                map.put("sort", "price_des"); // 价格从高到低
            } else if (filter.getSort() == TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH) {
                map.put("sort", "price_asc"); // 价格从低到高
            } else if (filter.getSort() == TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW) {
                map.put("sort", "tk_rate_des"); // 淘客佣金比率高到低
            } else if (filter.getSort() == TaoBaoUtil.SORT_TKRATE_LOW_TO_HIGH) {
                map.put("sort", "tk_rate_asc"); // 淘客佣金比率低到高
            } else if (filter.getSort() == TaoBaoUtil.SORT_TOTAL_COMMI_HIGH_TO_LOW) {
                map.put("sort", "tk_total_commi_des"); // 总支出佣金高到低
            } else if (filter.getSort() == TaoBaoUtil.SORT_TOTAL_COMMI_LOW_TO_HIGH) {
                map.put("sort", "tk_total_commi_asc"); // 总支出佣金低到高
            } else if (filter.getSort() == TaoBaoUtil.SORT_TOTAL_SALES_HIGH_TO_LOW) {
                map.put("sort", "tk_total_sales_des"); // 累计推广量高到低
            } else if (filter.getSort() == TaoBaoUtil.SORT_TOTAL_SALES_LOW_TO_HIGH) {
                map.put("sort", "tk_total_sales_asc"); // 累计推广量低到高
            }
        }
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        // System.out.println("resultStr"+ resultStr);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_dg_material_optional_response") != null
                && data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list") != null) {
            JSONArray array = data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list")
                    .optJSONArray("map_data");
            List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    TaoBaoGoodsBrief goods = parseWuLiaoItem(array.optJSONObject(i));
                    if (goods != null)
                        goodsList.add(goods);
                }
            }
            taoBaoSearchResult.setTaoBaoGoodsBriefs(goodsList);
            JSONObject optJSONObject = data.optJSONObject("tbk_dg_material_optional_response");
            int totalResults = optJSONObject.getInt("total_results");
            int totalPage = totalResults % pageEntity.getPageSize() == 0 ? totalResults / pageEntity.getPageSize()
                    : totalResults / pageEntity.getPageSize() + 1;
            pageEntity.setTotalCount(totalResults);
            pageEntity.setTotalPage(totalPage);
        }
        List<TaoBaoSearchNav> navList = new ArrayList<>();
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) pageEntity.getTotalCount());
        taoBaoSearchResult.setTaoBaoHead(taoBaoHead);
        taoBaoSearchResult.setPageEntity(pageEntity);
        // filter.get
        // 设置发货地址
        TaoBaoSearchNav nav = new TaoBaoSearchNav();
        nav.setName("发货地选择");
        nav.setFlag("address");
        nav.setId(11110);
        nav.setType("fahuodi");
        List<TaoBaoSearchNav> childNavList = new ArrayList<>();
        List<TaoBaoProvince> provinceList = TaoBaoUtil.getTaoBaoProvinceList();
        for (TaoBaoProvince province : provinceList) {
            TaoBaoSearchNav childNav = new TaoBaoSearchNav();
            childNav.setName(province.getName());
            childNav.setId(Integer.parseInt(province.getId()));
            childNav.setType("fahuodi-child");
            if (Integer.parseInt(province.getId()) == filter.getProvinceId())
                childNav.setSelector(1);
            childNavList.add(childNav);
        }
        nav.setSubIds(childNavList);
        navList.add(nav);
        // 测试
        taoBaoSearchResult.setNavList(navList);
        return taoBaoSearchResult;
    }
    /**
     * 商品物料搜索
     *
     * @param filter
     * @return
     */
    public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
            int userType) {
        if (provcity.trim().contains(" "))
            provcity = provcity.split(" ")[provcity.split(" ").length - 1];
        TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.material.optional");
        map.put("page_size", 50 + "");
        map.put("page_no", 1 + "");
        map.put("start_price", (int) zkPrice.subtract(new BigDecimal(1)).doubleValue() + "");
        map.put("end_price", (int) zkPrice.add(new BigDecimal(1)).doubleValue() + "");
        map.put("is_tmall", (userType == 1) + "");
        map.put("q", title);
        map.put("itemloc", provcity);
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_dg_material_optional_response") != null
                && data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list") != null) {
            JSONArray array = data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list")
                    .optJSONArray("map_data");
            List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    TaoBaoGoodsBrief goods = parseWuLiaoItem(array.optJSONObject(i));
                    if (goods != null)
                        goodsList.add(goods);
                }
            }
            taoBaoSearchResult.setTaoBaoGoodsBriefs(goodsList);
        }
        List<TaoBaoSearchNav> navList = new ArrayList<>();
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound(1000);
        taoBaoSearchResult.setTaoBaoHead(taoBaoHead);
        taoBaoSearchResult.setPageEntity(new PageEntity());
        taoBaoSearchResult.setNavList(navList);
        return taoBaoSearchResult;
    }
    /**
     * 商品物料搜索
     *
     * @param filter
     * @return
     */
    public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
            int userType, TaoKeAppInfo app) {
        if (provcity.trim().contains(" "))
            provcity = provcity.split(" ")[provcity.split(" ").length - 1];
        TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.material.optional");
        map.put("page_size", 50 + "");
        map.put("page_no", 1 + "");
        map.put("start_price", (int) zkPrice.subtract(new BigDecimal(1)).doubleValue() + "");
        map.put("end_price", (int) zkPrice.add(new BigDecimal(1)).doubleValue() + "");
        map.put("is_tmall", (userType == 1) + "");
        map.put("q", title);
        map.put("itemloc", provcity);
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, app);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_dg_material_optional_response") != null
                && data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list") != null) {
            JSONArray array = data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list")
                    .optJSONArray("map_data");
            List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    TaoBaoGoodsBrief goods = parseWuLiaoItem(array.optJSONObject(i));
                    if (goods != null)
                        goodsList.add(goods);
                }
            }
            taoBaoSearchResult.setTaoBaoGoodsBriefs(goodsList);
        }
        List<TaoBaoSearchNav> navList = new ArrayList<>();
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound(1000);
        taoBaoSearchResult.setTaoBaoHead(taoBaoHead);
        taoBaoSearchResult.setPageEntity(new PageEntity());
        taoBaoSearchResult.setNavList(navList);
        return taoBaoSearchResult;
    }
    // 解析物料
    private static TaoBaoGoodsBrief parseWuLiaoItem(JSONObject item) {
        TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
        goods.setPictUrl(item.optString("pict_url"));
        if (!StringUtil.isNullOrEmpty(item.optString("white_image"))) {
            goods.setPictUrlWhite(item.optString("white_image"));
        }
        goods.setAuctionId(item.optLong("num_iid"));
        goods.setAuctionUrl("https:" + item.optString("url"));
        goods.setBiz30day(item.optInt("volume"));
        goods.setCouponInfo(item.optString("coupon_info"));
        if (goods.getCouponInfo() != null)
            goods.setCouponInfo(goods.getCouponInfo().replace(".00", ""));
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
            List<BigDecimal> quanInfo = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
            goods.setCouponAmount(quanInfo.get(1));
            goods.setCouponEffectiveEndTime(
                    TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24, "yyyy-MM-dd"));
            goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
            goods.setCouponStartFee(quanInfo.get(0));
            goods.setCouponLeftCount(item.optInt("coupon_remain_count"));
            goods.setCouponLink("https:" + item.optString("coupon_share_url"));
            goods.setCouponTotalCount(item.optInt("coupon_total_count"));
            goods.setCouponActivityId(item.optString("coupon_id"));
        } else {
            goods.setCouponAmount(new BigDecimal(0));
        }
        goods.setDayLeft(-1);
        if (item.optJSONObject("small_images") != null) {
            JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
            if (imgArray != null) {
                List<String> imgList = new ArrayList<>();
                for (int n = 0; n < imgArray.size(); n++) {
                    imgList.add(imgArray.optString(n));
                }
                goods.setImgList(imgList);
            }
        }
        if (item.optBoolean("include_mkt"))
            goods.setTkMktStatus("1");
        else
            goods.setTkMktStatus("0");
        if (item.optBoolean("include_dxjh"))
            goods.setIncludeDxjh(1);
        goods.setSellerId(item.optLong("seller_id"));
        goods.setShopTitle(item.optString("shop_title"));
        goods.setTitle(item.optString("title"));
        if (!StringUtil.isNullOrEmpty(item.optString("level_one_category_id"))) {
            goods.setRootCatId(item.optInt("level_one_category_id"));
        }
        goods.setRootCategoryName(item.optString("level_one_category_name"));
        if (!StringUtil.isNullOrEmpty(item.optString("category_id"))) {
            goods.setLeafCatId(item.optInt("category_id"));
        }
        goods.setLeafName(item.optString("category_name"));
        goods.setTkRate(new BigDecimal(item.optString("commission_rate")).divide(new BigDecimal(100)));
        goods.setTotalNum(1000);
        goods.setUserType(item.optInt("user_type"));
        goods.setUserTypeName("");
        goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
        if (item.optBoolean("include_dxjh")) {
            goods.setDxjhInfo(item.optString("info_dxjh"));
        }
        if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) {// 无券
            goods.setTkCommFee(goods.getZkPrice().multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else if (goods.getZkPrice().compareTo(goods.getCouponStartFee()) >= 0// 有券
                && goods.getZkPrice().compareTo(goods.getCouponAmount()) >= 0) {
            BigDecimal finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
            goods.setTkCommFee(finalPrice.multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else {
            goods.setTkCommFee(new BigDecimal(0));
        }
        if (!StringUtil.isNullOrEmpty(item.optString("reserve_price")))
            goods.setReservePrice(new BigDecimal(item.optString("reserve_price")));
        goods.setTotalFee(new BigDecimal("0"));
        return goods;
    }
    /**
     * 获取淘口令
     *
     * @param logo
     *            -图标
     * @param text
     *            -文字
     * @param url
     *            -简介
     * @return
     */
    public static String getTKToken(String logo, String text, String url) {
        if (text == null)
            return null;
        if (text.length() < 5)
            text = "好货:" + text;
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.tpwd.create");
        map.put("url", url);
        map.put("text", text);
        map.put("logo", logo);
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data") != null)
            return data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data").optString("model");
        return null;
    }
    public static List<RelateGoods> getRelateGoodsList(long auctionId) throws ApiException {
        List<RelateGoods> resultList = new ArrayList<>();
        List<TaoBaoGoodsBrief> list = getRelationGoodsRecommend(auctionId, 9);
        for (TaoBaoGoodsBrief goods : list) {
            if (goods != null) {
                RelateGoods rg = new RelateGoods();
                rg.setId(goods.getAuctionId() + "");
                rg.setPicUrl(goods.getPictUrl());
                rg.setTitle(goods.getTitle());
                rg.setZkPrice(goods.getZkPrice().toString());
                rg.setUrl(goods.getAuctionUrl());
                resultList.add(rg);
            }
        }
        return resultList;
    }
    /**
     * 获取券详细信息
     *
     * @param auctionId
     * @param activityId
     * @return
     */
    public static QuanInfo getQuanInfo(Long auctionId, String activityId) {
        QuanInfo info = new QuanInfo();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.coupon.get");
        map.put("item_id", auctionId + "");
        map.put("activity_id", activityId);
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_coupon_get_response") != null) {
            data = data.optJSONObject("tbk_coupon_get_response").optJSONObject("data");
            info.coupon_start_time = data.optString("coupon_start_time");
            info.coupon_end_time = data.optString("coupon_end_time");
            info.coupon_amount = new BigDecimal(data.optString("coupon_amount"));
            info.coupon_total_count = data.optInt("coupon_total_count");
            info.coupon_remain_count = data.optInt("coupon_remain_count");
            info.coupon_start_fee = new BigDecimal(data.optString("coupon_start_fee"));
        } else
            return null;
        return info;
    }
    /**
     * 获取关联商品推荐
     *
     * @param auctionId
     * @return
     */
    public static List<TaoBaoGoodsBrief> getRelationGoodsRecommend(long auctionId, int count) {
        List<TaoBaoGoodsBrief> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.recommend.get");
        map.put("num_iid", auctionId + "");
        map.put("count", count + "");
        map.put("platform", 2 + "");
        map.put("fields",
                "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject data = JSONObject.fromObject(resultStr);
        if (data.optJSONObject("tbk_item_recommend_get_response") != null) {
            if (data.optJSONObject("tbk_item_recommend_get_response").optJSONObject("results") == null)
                return list;
            JSONArray array = data.optJSONObject("tbk_item_recommend_get_response").optJSONObject("results")
                    .optJSONArray("n_tbk_item");
            if (array != null)
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
                    goods.setAuctionId(item.optLong("num_iid"));
                    goods.setTitle(item.optString("title"));
                    goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
                    goods.setAuctionUrl(item.optString("item_url"));
                    goods.setPictUrl(item.optString("pict_url"));
                    list.add(goods);
                }
        }
        return list;
    }
    public static void taoQiangGou() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.ju.tqg.get");
        map.put("fields",
                "click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time");
        map.put("start_time", "2018-06-11 08:00:00");
        map.put("end_time", "2018-06-12 12:00:00");
        map.put("page_no", "1");
        map.put("page_size", "96");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    public static TaoBaoSearchResult taoQiangGou(int page, int pageSize, String startTime, String endTime) {
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.ju.tqg.get");
        map.put("fields",
                "click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time");
        map.put("start_time", startTime);
        map.put("end_time", endTime);
        map.put("page_no", page + "");
        map.put("page_size", pageSize + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject resultJSON = JSONObject.fromObject(resultStr);
        JSONObject response = resultJSON.optJSONObject("tbk_ju_tqg_get_response");
        if (response != null && response.optJSONObject("results") != null) {
            JSONArray array = response.optJSONObject("results").optJSONArray("results");
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    String url = item.optString("click_url");
                    // 排除 非淘客商品
                    if (url.contains("s.click.taobao.com/t?e=m")) {
                        TaoBaoGoodsBrief goods;
                        try {
                            goods = searchGoodsDetail(item.optLong("num_iid"));
                            if (goods != null)
                                goodsList.add(goods);
                        } catch (TaobaoGoodsDownException e) {
                            e.printStackTrace();
                        }
                    }
                }
                pageSize = array.size();
            }
        }
        TaoBaoSearchResult result = new TaoBaoSearchResult();
        result.setTaoBaoGoodsBriefs(goodsList);
        int totalResults = response.getInt("total_results");
        PageEntity pe = new PageEntity(page, pageSize, totalResults);
        result.setPageEntity(pe);
        result.setNavList(new ArrayList<>());
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount());
        result.setTaoBaoHead(taoBaoHead);
        return result;
    }
    /*
     * TODO 获取分类列表
     */
    public static void getTaoBaoCategoryList() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.itemcats.get");
        map.put("parent_cid", "0");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    /**
     * 店铺搜索
     *
     * @param key
     *            -店铺名称
     * @param page
     *            -页码
     * @return
     */
    public static List<TaoBaoShopInfo> searchShop(String key, int page) {
        if (StringUtil.isNullOrEmpty(key))
            return new ArrayList<>();
        List<TaoBaoShopInfo> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.shop.get");
        map.put("fields", "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url");
        map.put("q", key);
        map.put("page_size", "95");
        map.put("page_no", page + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject resultDate = JSONObject.fromObject(resultStr);
        if (resultDate.optJSONObject("tbk_shop_get_response") != null
                && resultDate.optJSONObject("tbk_shop_get_response").optJSONObject("results") != null) {
            JSONArray array = resultDate.optJSONObject("tbk_shop_get_response").optJSONObject("results")
                    .optJSONArray("n_tbk_shop");
            if (array != null)
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    TaoBaoShopInfo info = new TaoBaoShopInfo();
                    info.setPictureUrl(item.optString("pict_url"));
                    info.setSellerNick(item.optString("seller_nick"));
                    info.setShopTitle(item.optString("shop_title"));
                    info.setShopType(item.optString("shop_type"));
                    info.setShopUrl(item.optString("shop_url"));
                    info.setUserId(item.optLong("user_id"));
                    list.add(info);
                }
        }
        return list;
    }
    /**
     * TODO 按设备猜你喜欢
     *
     * @param userNickName
     * @param os
     * @param imei
     * @param idfa
     * @param ip
     * @param ua
     * @param net
     * @param pageNo
     * @param pageSize
     */
    public static void guessLikeByDevice(String userNickName, String os, String imei, String idfa, String ip, String ua,
            String net, int pageNo, int pageSize) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.guess.like");
        if (!StringUtil.isNullOrEmpty(userNickName))
            map.put("user_nick", userNickName);
        map.put("os", os + "");
        if (!StringUtil.isNullOrEmpty(idfa))
            map.put("idfa", idfa);
        if (!StringUtil.isNullOrEmpty(imei)) {
            map.put("imei", imei + "");
            map.put("imei_md5", StringUtil.Md5(imei));
        }
        map.put("ip", ip + "");
        map.put("ua", ua + "");
        map.put("net", net + "");
        map.put("page_no", pageNo + "");
        map.put("page_size", pageSize + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    /**
     * 品牌券获取
     *
     * @param pageNo
     * @param pageSize
     */
    public static void pingPaiCoupon(int pageNo, int pageSize) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.sc.coupon.brand.recommend");
        map.put("page_no", pageNo + "");
        map.put("page_size", pageSize + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    public static void getOrder(String order) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "alibaba.mos.order.get");
        map.put("order_number", order);
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    public static void getTAEGoodsDetail(Long auctionId) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tae.items.list");
        map.put("fields", "title,nick,pic_url,location,cid,price,post_fee,promoted_service,ju,shop_name");
        map.put("num_iids", auctionId + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
    }
    // taobao.ju.items.search
    public static void searchJuHuaSuan() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.ju.items.search");
        map.put("current_page", "1");
        map.put("page_size", 20 + "");
        map.put("pid", "mm_124933865_43788020_381938426");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, false);
        System.out.println(resultStr);
    }
    /**
     * 通过物料ID获取商品信息
     *
     * @param materialId
     *            -物料ID
     * @param page
     *            -页码
     * @param pageSize
     *            -每页数量
     * @return
     */
    public static TaoBaoSearchResult getMaterialByMaterialId(int materialId, int page, int pageSize) {
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("page_no", page + "");
        map.put("page_size", pageSize + "");
        map.put("material_id", materialId + "");
        map.put("content_id", "561388751621");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
        JSONObject resultJSON = JSONObject.fromObject(resultStr);
        JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response");
        if (response != null && response.optJSONObject("result_list") != null) {
            JSONArray array = response.optJSONObject("result_list").optJSONArray("map_data");
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    TaoBaoGoodsBrief goods = parseWuLiaoItemFromMaterialId(item);
                    if (goods != null)
                        goodsList.add(goods);
                }
                pageSize = array.size();
            }
        }
        TaoBaoSearchResult result = new TaoBaoSearchResult();
        result.setTaoBaoGoodsBriefs(goodsList);
        int totalCount = 1000;// root.optInt("total_results");
        PageEntity pe = new PageEntity(page, pageSize, totalCount);
        result.setPageEntity(pe);
        result.setNavList(new ArrayList<>());
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount());
        result.setTaoBaoHead(taoBaoHead);
        return result;
    }
    public static TaoBaoSearchResult getQTZMaterialByMaterialId(int materialId, int page, int pageSize) {
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.sc.optimus.material");
        map.put("page_no", page + "");
        map.put("page_size", pageSize + "");
        map.put("material_id", materialId + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        JSONObject resultJSON = JSONObject.fromObject(resultStr);
        JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response");
        if (response != null && response.optJSONObject("result_list") != null) {
            JSONArray array = response.optJSONObject("result_list").optJSONArray("map_data");
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    TaoBaoGoodsBrief goods = parseWuLiaoItemFromMaterialId(item);
                    if (goods != null)
                        goodsList.add(goods);
                }
                pageSize = array.size();
            }
        }
        TaoBaoSearchResult result = new TaoBaoSearchResult();
        result.setTaoBaoGoodsBriefs(goodsList);
        int totalCount = 1000;// root.optInt("total_results");
        PageEntity pe = new PageEntity(page, pageSize, totalCount);
        result.setPageEntity(pe);
        result.setNavList(new ArrayList<>());
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount());
        result.setTaoBaoHead(taoBaoHead);
        return result;
    }
    /**
     * 根据设备猜你喜欢
     *
     * @param page
     * @param pageSize
     * @param imei
     * @param idfa
     * @return
     */
    public static TaoBaoSearchResult guessDeviceLike(int page, int pageSize, String imei, String idfa) {
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("page_no", page + "");
        map.put("page_size", pageSize + "");
        map.put("material_id", "6708");
        if (StringUtil.isNullOrEmpty(imei) && StringUtil.isNullOrEmpty(idfa))
            return null;
        map.put("device_encrypt", "MD5");
        if (!StringUtil.isNullOrEmpty(imei)) {
            map.put("device_value", StringUtil.Md5(imei));
            map.put("device_type", "IMEI");
        } else {
            map.put("device_value", StringUtil.Md5(idfa));
            map.put("device_type", "IDFA");
        }
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, true);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
        if (resultJSON == null)
            return null;
        // JSONObject resultJSON = JSONObject.fromObject(resultStr);
        JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response");
        if (response != null && response.optJSONObject("result_list") != null) {
            JSONArray array = response.optJSONObject("result_list").optJSONArray("map_data");
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    JSONObject item = array.optJSONObject(i);
                    TaoBaoGoodsBrief goods = parseWuLiaoItemFromMaterialId(item);
                    if (goods != null)
                        goodsList.add(goods);
                }
                pageSize = array.size();
            }
        }
        TaoBaoSearchResult result = new TaoBaoSearchResult();
        result.setTaoBaoGoodsBriefs(goodsList);
        int totalCount = 1000;// root.optInt("total_results");
        PageEntity pe = new PageEntity(page, pageSize, totalCount);
        result.setPageEntity(pe);
        result.setNavList(new ArrayList<>());
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount());
        result.setTaoBaoHead(taoBaoHead);
        return result;
    }
    /**
     * 从淘宝链接中解析商品ID(高级接口)
     *
     * @param link
     * @return
     */
    public static String parseAuctionIdFromLink(String link) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.click.extract");
        map.put("click_url", link + "");
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, true);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
        if (resultJSON == null)
            return null;
        return null;
    }
    private static TaoBaoGoodsBrief parseWuLiaoItemFromMaterialId(JSONObject item) {
        TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
        // 设置成320*320的图片尺寸
        goods.setPictUrl(TbImgUtil.getTBSize320Img("https:" + item.optString("pict_url")));
        goods.setAuctionId(item.optLong("item_id"));
        goods.setAuctionUrl("https://item.taobao.com/item.htm?id=" + goods.getAuctionId());
        goods.setBiz30day(item.optInt("volume"));
        if (!StringUtil.isNullOrEmpty(item.optString("coupon_amount"))) {
            goods.setCouponEffectiveEndTime(TimeUtil.getGernalTime(item.optLong("coupon_end_time"), "yyyy-MM-dd"));
            goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(item.optLong("coupon_start_time"), "yyyy-MM-dd"));
            goods.setCouponStartFee(new BigDecimal(item.optString("coupon_start_fee")));
            goods.setCouponLeftCount(item.optInt("coupon_remain_count"));
            goods.setCouponLink(null);
            goods.setCouponAmount(new BigDecimal(item.optString("coupon_amount")));
            goods.setCouponTotalCount(item.optInt("coupon_total_count"));
            goods.setCouponActivityId(item.optString("coupon_id"));
            if (goods.getCouponStartFee().compareTo(new BigDecimal(0)) > 0)
                goods.setCouponInfo(String.format("满%s元减%s元",
                        MoneyBigDecimalUtil.getWithNoZera(goods.getCouponStartFee()).toString(),
                        MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString()));
            else
                goods.setCouponInfo(String.format("%s元无条件券",
                        MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString()));
            if (goods.getCouponStartFee().compareTo(new BigDecimal(0)) <= 0) {
                goods.setCouponStartFee(goods.getCouponAmount());
            }
        } else {
            goods.setCouponAmount(new BigDecimal(0));
        }
        goods.setDayLeft(-1);
        if (item.optJSONObject("small_images") != null) {
            JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
            if (imgArray != null) {
                List<String> imgList = new ArrayList<>();
                for (int n = 0; n < imgArray.size(); n++) {
                    imgList.add(imgArray.optString(n));
                }
                goods.setImgList(imgList);
            }
        }
        goods.setTkMktStatus("0");
        goods.setIncludeDxjh(0);
        goods.setSellerId(item.optLong("seller_id"));
        goods.setShopTitle(item.optString("shop_title"));
        goods.setTitle(item.optString("title"));
        if (!StringUtil.isNullOrEmpty(item.optString("level_one_category_id"))) {
            goods.setRootCatId(item.optInt("level_one_category_id"));
        }
        goods.setRootCategoryName(item.optString("level_one_category_name"));
        if (!StringUtil.isNullOrEmpty(item.optString("category_id"))) {
            goods.setLeafCatId(item.optInt("category_id"));
        }
        goods.setLeafName(item.optString("category_name"));
        goods.setTotalNum(1000);
        goods.setUserType(item.optInt("user_type"));
        goods.setUserTypeName("");
        if (!StringUtil.isNullOrEmpty(item.optString("commission_rate"))) {
            goods.setTkRate(new BigDecimal(item.optString("commission_rate")));
        } else {
            goods.setTkRate(new BigDecimal(0));
        }
        if (!StringUtil.isNullOrEmpty(item.optString("zk_final_price"))) {
            goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
        } else {
            goods.setZkPrice(new BigDecimal(0));
        }
        if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) {// 无券
            goods.setTkCommFee(goods.getZkPrice().multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else if (goods.getZkPrice().compareTo(goods.getCouponStartFee()) >= 0// 有券
                && goods.getZkPrice().compareTo(goods.getCouponAmount()) >= 0) {
            BigDecimal finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
            goods.setTkCommFee(finalPrice.multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else {
            goods.setTkCommFee(new BigDecimal(0));
        }
        goods.setReservePrice(new BigDecimal(0));
        goods.setTotalFee(new BigDecimal("0"));
        return goods;
    }
}
class QuanInfo {
    public String coupon_start_time;// 开始时间
    public String coupon_end_time; // 券结束时间
    public BigDecimal coupon_amount;// 券金额
    public int coupon_total_count;// 券总数量
    public int coupon_remain_count;// 券剩余数量
    public BigDecimal coupon_start_fee;// 券起始金额
}
fanli-facade-order/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-facade-order/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-facade-order</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
fanli-facade-system/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-facade-system/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-facade-system</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
fanli-facade-system/src/main/java/org/fanli/facade/system/dto/taobao/TaoKeAppInfo.java
New file
@@ -0,0 +1,47 @@
package org.fanli.facade.system.dto.taobao;
/**
 * 淘客的app信息
 *
 * @author Administrator
 *
 */
public class TaoKeAppInfo {
    private String appKey;
    private String appSecret;
    private String pid;
    private String adzoneId;
    public String getAdzoneId() {
        return adzoneId;
    }
    public void setAdzoneId(String adzoneId) {
        this.adzoneId = adzoneId;
    }
    public String getAppKey() {
        return appKey;
    }
    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }
    public String getAppSecret() {
        return appSecret;
    }
    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }
    public String getPid() {
        return pid;
    }
    public void setPid(String pid) {
        this.pid = pid;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/hongbao/HongBaoManage.java
New file
@@ -0,0 +1,72 @@
package org.fanli.facade.system.entity.hongbao;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
 * 红包相关参数设置
 * @author cxx
 *
 * @date 2018年1月29日
 */
@Entity
@Table(name="yeshi_ec_hongbao_manage")
@org.yeshi.utils.mybatis.Table("yeshi_ec_hongbao_manage")
public class HongBaoManage {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    @org.yeshi.utils.mybatis.Column(name="id")
    private Long id;
    @Column(name="`key`")
    @org.yeshi.utils.mybatis.Column(name="key")
    private String key;
    @Column(name="`value`")
    @org.yeshi.utils.mybatis.Column(name="value")
    private String value;
    @Column(name="`remark`")
    @org.yeshi.utils.mybatis.Column(name="remark")
    private String remark;
    public HongBaoManage() {
    }
    public HongBaoManage(String key, String value, String remark) {
        super();
        this.key = key;
        this.value = value;
        this.remark = remark;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getKey() {
        return key;
    }
    public void setKey(String key) {
        this.key = key;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/exception/TaoKeApiException.java
New file
@@ -0,0 +1,70 @@
package org.fanli.facade.system.exception;
import java.util.Map;
/**
 * 淘客API异常
 *
 * @author Administrator
 *
 */
public class TaoKeApiException extends Exception {
    // 淘宝APPkey的请求限制
    public static final int CODE_APPKEY_LIMIT = 1;
    // 无可用app
    public static final int CODE_NO_USE = 2;
    // api请求错误
    public static final int CODE_API_ERROR = 3;
    // 其他错误
    public static final int CODE_OTHER = 4;
    private int code;
    private String msg;
    private Map<String, String> params;
    public Map<String, String> getParams() {
        return params;
    }
    public void setParams(Map<String, String> params) {
        this.params = params;
    }
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public TaoKeApiException() {
    }
    public TaoKeApiException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public TaoKeApiException(int code, String msg, Map<String, String> params) {
        this.code = code;
        this.msg = msg;
        this.params = params;
    }
    @Override
    public String getMessage() {
        return String.format("错误码为:%s  错误信息为:%s", code + "", msg);
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/service/hongbao/HongBaoManageService.java
New file
@@ -0,0 +1,96 @@
package org.fanli.facade.system.service.hongbao;
import java.math.BigDecimal;
public interface HongBaoManageService {
    /**
     * 获取返利订单返利比例
     *
     * @param time
     * @return
     */
    public BigDecimal getFanLiRate(long time);
    /**
     * 获取分享订单返利比例
     *
     * @param time
     * @return
     */
    public BigDecimal getShareRate(long time);
    /**
     * 获取返利订单返利比例
     *
     * @return
     */
    public BigDecimal getFanLiRate();
    /**
     * 获取分享订单返利比例
     *
     * @return
     */
    public BigDecimal getShareRate();
    /**
     * 获取第一级的邀请赚比例
     *
     * @return
     */
    public BigDecimal getFirstInviteRate(int urank);
    /**
     * 获取第一级的邀请赚比例
     *
     * @param time
     * @return
     */
    public BigDecimal getFirstInviteRate(int urank, long time);
    /**
     * 获取第二级的邀请赚比例
     *
     * @return
     */
    public BigDecimal getSecondInviteRate(int urank);
    /**
     * 获取第二级的邀请赚比例
     *
     * @param time
     * @return
     */
    public BigDecimal getSecondInviteRate(int urank, long time);
    /**
     * 获取第一级的分享赚比例
     *
     * @return
     */
    public BigDecimal getFirstShareRate(int urank);
    /**
     * 获取第一级的分享赚比例
     *
     * @param time
     * @return
     */
    public BigDecimal getFirstShareRate(int urank, long time);
    /**
     * 获取第二级的分享赚比例
     *
     * @return
     */
    public BigDecimal getSecondShareRate(int urank);
    /**
     * 获取第二级的分享赚比例
     *
     * @param time
     * @return
     */
    public BigDecimal getSecondShareRate(int urank, long time);
}
fanli-facade-system/src/main/java/org/fanli/facade/system/util/taobao/TaoBaoHttpUtil.java
New file
@@ -0,0 +1,493 @@
package org.fanli.facade.system.util.taobao;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.yeshi.fanli.entity.address.Address;
import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
import net.sf.json.JSONArray;
public class TaoBaoHttpUtil {
    public static String getShortLink(String url) {
        String totalUrl = String.format("http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=%s",
                URLEncoder.encode(url));
        String result = get(totalUrl);
        JSONArray rtesultArray = JSONArray.fromObject(result);
        if (rtesultArray.size() > 0) {
            return rtesultArray.optJSONObject(0).optString("url_short");
        }
        return null;
    }
    public static String proxyGet(String url, String cookie) {
        HttpClient client = new HttpClient();
        // Address address = ProxyUtil.getAddressProxy();
        // if(address != null){
        // client.getHostConfiguration().setProxy(address.getIp(),
        // address.getPort());
        // }
        try {
            GetMethod method = new GetMethod(url);
            if (cookie != null) {
                method.addRequestHeader("cookie", cookie);
            }
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String proxyGet(String url, Map<String, String> headers) {
        HttpClient client = new HttpClient();
        // Address address = ProxyUtil.getAddressProxy();
        // if(address != null){
        // client.getHostConfiguration().setProxy(address.getIp(),
        // address.getPort());
        // }
        try {
            GetMethod method = new GetMethod(url);
            if (headers != null) {
                Iterator<String> keys = headers.keySet().iterator();
                while (keys.hasNext()) {
                    String key = keys.next();
                    method.addRequestHeader(key, headers.get(key));
                }
            }
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String get(String url) {
        return get(url, true);
    }
    public static String get(String url, boolean isProxy) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        if (isProxy) {
            Address address = ProxyUtil.getAddressProxy();
            if (address != null) {
                client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
            }
        }
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String getAsString(String url, boolean isProxy) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        if (isProxy) {
            Address address = ProxyUtil.getAddressProxy();
            if (address != null) {
                client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
            }
        }
        try {
            client.executeMethod(method);
            String response = method.getResponseBodyAsString();
            String s1 = new String(response.getBytes("ISO-8859-1"), "UTF-8");
            return s1;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String tbGet(String url, Map<String, String> params, String tbAccount) {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        // if(address != null){
        // client.getHostConfiguration().setProxy(address.getIp(),
        // address.getPort());
        // }
        Iterator<String> keys = params.keySet().iterator();
        url += "?";
        while (keys.hasNext()) {
            String key = keys.next();
            try {
                url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        GetMethod method = new GetMethod(url);
        try {
            method.setRequestHeader("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
            method.setRequestHeader("Upgrade-Insecure-Requests", "1");
            method.setRequestHeader("Accept",
                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            method.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
            method.setRequestHeader("Cache-Control", "max-age=0");
            String taoBaoCookie = TaoBaoOrderUtil.getTaoBaoCookie(tbAccount);
            method.setRequestHeader("cookie", taoBaoCookie);
            // HttpConnectionManagerParams params2 = new
            // HttpConnectionManagerParams();
            // params2.setConnectionTimeout(3500);
            // client.getHttpConnectionManager().setParams(params2);
            client.executeMethod(method);
            // InputStream inputStream = method.getResponseBodyAsStream();
            // String result = convertInputStreamToString(inputStream);
            return method.getResponseBodyAsString();// convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (Exception e) {
            try {
                address = ProxyUtil.getAddressProxy();
                if (address != null) {
                    client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
                }
                client.executeMethod(method);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        return "";
    }
    public static String get(String url, Map<String, String> params, boolean proxy) {
        HttpClient client = new HttpClient();
        // client.getHostConfiguration().setProxy("192.168.1.122", 8888);
        try {
            Iterator<String> keys = params.keySet().iterator();
            url += "?";
            while (keys.hasNext()) {
                String key = keys.next();
                url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
            }
            // System.out.println("url"+url);
            GetMethod method = new GetMethod(url);
            // 3S的响应超时
            HttpConnectionManagerParams hparams = new HttpConnectionManagerParams();
            hparams.setConnectionTimeout(3000);
            client.getHttpConnectionManager().setParams(hparams);
            /*
             * if(proxy){ Address address = ProxyUtil.getAddressProxy();
             * if(address != null){ HttpConnectionManagerParams hparams = new
             * HttpConnectionManagerParams();
             * hparams.setConnectionTimeout(3500);
             * client.getHttpConnectionManager().setParams(hparams);
             * client.getHostConfiguration().setProxy(address.getIp(),address.
             * getPort()); } }
             */
            // client.getHostConfiguration().setProxy("192.168.1.122",8888);
            client.executeMethod(method);
            String result = method.getResponseBodyAsString();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String get(String url, Map<String, String> params, Map<String, String> headers, boolean proxy) {
        HttpClient client = new HttpClient();
        try {
            Iterator<String> keys = params.keySet().iterator();
            url += "?";
            while (keys.hasNext()) {
                String key = keys.next();
                url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
            }
            System.out.println(url);
            GetMethod method = new GetMethod(url);
            if (headers != null) {
                keys = headers.keySet().iterator();
                while (keys.hasNext()) {
                    String key = keys.next();
                    headers.get(key);
                    method.setRequestHeader(key, headers.get(key));
                }
            }
            /*
             * if(proxy){ Address address = ProxyUtil.getAddressProxy();
             * if(address != null){ HttpConnectionManagerParams hparams = new
             * HttpConnectionManagerParams();
             * hparams.setConnectionTimeout(3500);
             * client.getHttpConnectionManager().setParams(hparams);
             * client.getHostConfiguration().setProxy(address.getIp(),address.
             * getPort()); } }
             */
            // client.getHostConfiguration().setProxy("120.92.118.64", 10000);
            client.executeMethod(method);
            String result = method.getResponseBodyAsString();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String taoKeGet(Map<String, String> params) {
        // 聚石塔服务器环境 118.178.179.189
        // result = get("http://118.178.179.189/taoke/", params, false);
        // if (StringUtil.isNullOrEmpty(result))
        //https://eco.taobao.com/router/rest
        //http://gw.api.taobao.com/router/rest
        String result = get("https://eco.taobao.com/router/rest", params, false);
        return result;
    }
    public static String get(String url, Map<String, String> params) {
        // TODO 淘宝的所有请求需要走聚石塔
        // http://118.178.179.189/taoke/
        return get(url, params, false);
    }
    public static String get(String url, String charset) {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        GetMethod method = new GetMethod(url);
        try {
            client.executeMethod(method);
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(method.getResponseBodyAsStream(), "ISO-8859-1"));
            String tmp = null;
            String htmlRet = "";
            while ((tmp = reader.readLine()) != null) {
                htmlRet += tmp + "\r\n";
            }
            return new String(htmlRet.getBytes(charset), "UTF-8");
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static InputStream getAsInputStream(String url) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static InputStream getImage(String url) {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        GetMethod method = new GetMethod(url);
        try {
            method.setRequestHeader("Content-Type", "image/jpeg");
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String post(String url) {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String post(String url, Map<String, String> map) {
        Iterator<String> its = map.keySet().iterator();
        NameValuePair[] params = new NameValuePair[map.keySet().size()];
        int p = 0;
        while (its.hasNext()) {
            String key = its.next();
            NameValuePair np = new NameValuePair(key, map.get(key));
            params[p] = np;
            p++;
        }
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestBody(params);
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String post(String url, Map<String, String> map, Map<String, String> headers) {
        org.apache.http.client.HttpClient client = new DefaultHttpClient();
        HttpPost httpRequst = new HttpPost(url);// 创建HttpPost对象
        List<org.apache.http.NameValuePair> params = new ArrayList<org.apache.http.NameValuePair>();
        Iterator<String> its = map.keySet().iterator();
        while (its.hasNext()) {
            String key = its.next();
            params.add(new BasicNameValuePair(key, map.get(key)));
        }
        try {
            HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
            httpRequst.setEntity(entity);
            HttpResponse httpResponse = client.execute(httpRequst);
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                HttpEntity httpEntity = httpResponse.getEntity();
                String result = EntityUtils.toString(httpEntity, "UTF-8");// 取出应答字符�?
                return result;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
        // Iterator<String> its = map.keySet().iterator();
    }
    private static String convertInputStreamToString(InputStream inputStream) {
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer stringBuffer = new StringBuffer();
        String str = "";
        try {
            while ((str = br.readLine()) != null) {
                stringBuffer.append(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }
    @SuppressWarnings("deprecation")
    public static String post(String url, String entity) {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestBody(entity);
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String postInputStream(String url, File file) throws FileNotFoundException {
        HttpClient client = new HttpClient();
        Address address = ProxyUtil.getAddressProxy();
        if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
        }
        PostMethod postMethod = new PostMethod(url);
        /*
         * postMethod.addRequestHeader("Content-Type",
         * "text/html;charset=UTF-8");
         * postMethod.setRequestHeader("Content-Type",
         * "text/html;charset=UTF-8");
         */
        Part[] parts = { new StringPart("filename", file.getName()), new StringPart("filelength", file.length() + ""),
                new StringPart("content-type", "image/jpg"), new FilePart("file", file) };
        postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
        try {
            client.executeMethod(postMethod);
            return convertInputStreamToString(postMethod.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/util/taobao/TaoKeBaseUtil.java
New file
@@ -0,0 +1,292 @@
package org.fanli.facade.system.util.taobao;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.fanli.facade.system.dto.taobao.TaoKeAppInfo;
import org.fanli.facade.system.exception.TaoKeApiException;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.base.log.LogHelper;
import com.yeshi.fanli.base.log.TaoKeLogHelper;
import net.sf.json.JSONObject;
public class TaoKeBaseUtil {
    private static TaoKeAppInfo taoKeAppInfo = null;
    private static long lastTime = 0;
    public static JSONObject baseRequest(Map<String, String> param, boolean needAdzoneId) throws TaoKeApiException {
        // 复制params
        Map<String, String> params = new HashMap<>();
        if (param != null) {
            Iterator<String> its = param.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                params.put(key, param.get(key));
            }
        }
        // 获取有效的APPKey
        TaoKeAppInfo app = getAvailableTaoKeAppInfo();
        if (app == null)
            throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
        // 签名
        params.put("app_key", app.getAppKey());
        params.put("sign_method", "md5");
        params.put("v", "2.0");
        params.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        params.put("format", "json");
        if (needAdzoneId)
            params.put("adzone_id", app.getAdzoneId());
        params.put("sign", getSign(params, "md5", app).toUpperCase());
        String result = TaoBaoHttpUtil.taoKeGet(params);
        JSONObject data = JSONObject.fromObject(result);
        if (data != null) {
            if (data.optJSONObject("error_response") != null
                    && data.optJSONObject("error_response").optInt("code") == 7) {
                reportAppInvalid(app.getAppKey());
                TaoKeLogHelper.error(params, result);
                throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "淘宝请求限制:" + result, params);
            } else if (data.optJSONObject("error_response") != null) {
                throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
            }
        } else
            throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
        reValid(app.getAppKey());
        return data;
    }
    public static JSONObject baseRequest(Map<String, String> param, TaoKeAppInfo app) throws TaoKeApiException {
        // 复制params
        Map<String, String> params = new HashMap<>();
        if (param != null) {
            Iterator<String> its = param.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                params.put(key, param.get(key));
            }
        }
        // 获取有效的APPKey
        if (app == null)
            throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
        // 签名
        params.put("app_key", app.getAppKey());
        params.put("sign_method", "md5");
        params.put("v", "2.0");
        params.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        params.put("format", "json");
        if (!StringUtil.isNullOrEmpty(app.getAdzoneId()))
            params.put("adzone_id", app.getAdzoneId());
        params.put("sign", getSign(params, "md5", app).toUpperCase());
        String result = TaoBaoHttpUtil.taoKeGet(params);
        JSONObject data = JSONObject.fromObject(result);
        if (data != null) {
            if (data.optJSONObject("error_response") != null
                    && data.optJSONObject("error_response").optInt("code") == 7) {
                reportAppInvalid(app.getAppKey());
                throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "淘宝请求限制:" + result, params);
            } else if (data.optJSONObject("error_response") != null) {
                throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
            }
        } else
            throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
        reValid(app.getAppKey());
        return data;
    }
    /**
     * 重复3次请求,降低出错概率
     *
     * @param params
     * @return
     */
    public static String baseRequestForThreeTimes(Map<String, String> params, boolean needAdzoneId) {
        JSONObject data = null;
        int count = 0;
        String result = null;
        while (data == null && count < 2) {
            count++;
            try {
                data = baseRequest(params, needAdzoneId);
            } catch (TaoKeApiException e) {
                // 记录现场
                TaoKeLogHelper.error(e.getParams(), e.getMsg());
                if (e.getCode() == TaoKeApiException.CODE_API_ERROR) {
                    result = e.getMsg();
                }
            }
        }
        if (!StringUtil.isNullOrEmpty(result)) {
            try {
                data = JSONObject.fromObject(result);
            } catch (Exception e) {
            }
        }
        if (data != null)
            return data.toString();
        else
            return new JSONObject().toString();
    }
    public static String baseRequestForThreeTimes(Map<String, String> params, TaoKeAppInfo app) {
        JSONObject data = null;
        int count = 0;
        while (data == null && count < 3) {
            count++;
            try {
                data = baseRequest(params, app);
            } catch (TaoKeApiException e) {
                // 记录现场
                TaoKeLogHelper.error(e.getParams(), e.getMsg());
            }
        }
        if (data != null)
            return data.toString();
        else
            return new JSONObject().toString();
    }
    /**
     * 获取签名参数
     *
     * @param params
     * @param signMethod
     * @param app
     * @return
     */
    public static String getSign(Map<String, String> params, String signMethod, TaoKeAppInfo app) {
        // 第一步:检查参数是否已经排序
        String[] keys = params.keySet().toArray(new String[0]);
        Arrays.sort(keys);
        // 第二步:把所有参数名和参数值串在一起
        StringBuilder query = new StringBuilder();
        if ("md5".equals(signMethod)) {
            query.append(app.getAppSecret());
        }
        for (String key : keys) {
            String value = params.get(key);
            if (!StringUtil.isNullOrEmpty(value)) {
                query.append(key).append(value);
            }
        }
        query.append(app.getAppSecret());
        return StringUtil.Md5(query.toString());
    }
    static TaoKeAppInfo getAvailableTaoKeAppInfo() {
        if (System.currentTimeMillis() - lastTime > 1000 * 20L)
            taoKeAppInfo = null;
        if (taoKeAppInfo == null) {
            System.out.println("请求。。。。。");
            String result = null;
            try {
                result = HttpUtil.get("http://193.112.35.168:8091/tb/taoke/getcanuseapp");
            } catch (Exception e) {
            }
            // 接口请求失败,默认设置成影视大全IOS的媒体信息
            if (StringUtil.isNullOrEmpty(result)) {
                taoKeAppInfo = new TaoKeAppInfo();
                taoKeAppInfo.setAdzoneId("381938426");
                taoKeAppInfo.setAppKey("24838852");
                taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
                taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
                lastTime = System.currentTimeMillis();
                return taoKeAppInfo;
            }
            JSONObject data = JSONObject.fromObject(result);
            if (data.optInt("code") == 0) {
                TaoKeAppInfo info = new TaoKeAppInfo();
                info.setAppKey(data.optJSONObject("data").optString("appkey"));
                info.setAppSecret(data.optJSONObject("data").optString("appsecret"));
                info.setPid(data.optJSONObject("data").optString("pid"));
                String[] sts = info.getPid().split("_");
                info.setAdzoneId(sts[sts.length - 1]);
                taoKeAppInfo = info;
                lastTime = System.currentTimeMillis();
            } else {// 防止所有的失效
                taoKeAppInfo = new TaoKeAppInfo();
                taoKeAppInfo.setAdzoneId("381938426");
                taoKeAppInfo.setAppKey("24838852");
                taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
                taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
                return taoKeAppInfo;
            }
        }
        return taoKeAppInfo;
    }
    static void filterTaoKeResponse(String result, TaoKeAppInfo app) {
        if (!StringUtil.isNullOrEmpty(result)) {
            try {
                JSONObject data = JSONObject.fromObject(result);
                if (data != null) {
                    if (data.optJSONObject("error_response") != null
                            && data.optJSONObject("error_response").optInt("code") == 7) {
                        reportAppInvalid(app.getAppKey());
                    }
                } else
                    LogHelper.test(result);
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    static Map<String, Integer> invalidMap = new HashMap<>();
    /**
     * 报告该APPKey不能用
     *
     * @param appkey
     */
    static void reportAppInvalid(String appkey) {
        if (invalidMap == null)
            return;
        // 错误三次后再真正上报
        if (invalidMap.get(appkey) == null)
            invalidMap.put(appkey, 1);
        else
            invalidMap.put(appkey, invalidMap.get(appkey) + 1);
        if (invalidMap.get(appkey) < 4)
            return;
        invalidMap.put(appkey, 0);
        HttpUtil.get("http://193.112.35.168:8091/tb/taoke/reportappcannotuse?appkey=" + appkey);
        lastTime = 0;
    }
    /**
     * APPKey恢复可用
     *
     * @param appKey
     */
    static void reValid(String appKey) {
        if (invalidMap == null)
            return;
        Integer count = invalidMap.get(appKey);
        if (count != null && count > 0)
            invalidMap.put(appKey, count - 1);
    }
    public static void setAppValid() {
        HttpUtil.get("http://193.112.35.168:8091/tb/taoke/setappcanuse");
    }
}
fanli-facade-user/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-facade-user/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-facade-user</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
fanli-service-goods/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-service-goods/.project
New file
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-service-goods</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    </natures>
</projectDescription>
fanli-service-order/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-service-order/.project
New file
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-service-order</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    </natures>
</projectDescription>
fanli-service-system/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-service-system/.project
New file
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-service-system</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    </natures>
</projectDescription>
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/hongbao/HongBaoManageMapper.java
New file
@@ -0,0 +1,30 @@
package com.yeshi.fanli.system.dao.hongbao;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.system.entity.hongbao.HongBaoManage;
public interface HongBaoManageMapper {
    int deleteByPrimaryKey(Long id);
    int insert(HongBaoManage record);
    int insertSelective(HongBaoManage record);
    HongBaoManage selectByPrimaryKey(Long id);
    HongBaoManage selectByKey(String key);
    int updateByPrimaryKeySelective(HongBaoManage record);
    int updateByPrimaryKey(HongBaoManage record);
    /**
     * 按最大有效时间搜索红包对象
     *
     * @param key
     * @param timeStamp
     * @return
     */
    HongBaoManage selectByKeyAndMaxValidTime(@Param("key")String key,@Param("timeStamp") long timeStamp);
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/common/SystemClientParamsMapper.xml
New file
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yeshi.fanli.system.dao.common.SystemClientParamsMapper">
      <!-- 返回实体 -->
      <resultMap id="ParamsResultMap" type="org.fanli.facade.system.entity.common.CustomerName" >
          <id column="id" property="id" jdbcType="BIGINT"/>
          <result column="name" property="name" jdbcType="VARCHAR"/>
          <result column="createtime" property="createtime" jdbcType="DATE"/>
      </resultMap>
    <!-- 根据type查询问题数量  -->
    <select id="getCount" resultType="Integer">
        SELECT COUNT(1) FROM yeshi_ec_customer_name yecn WHERE yecn.`type` = #{type};
    </select>
    <!-- 根据id查询二级问题列表数量 -->
    <select id="getProblemCount" resultType="Integer">
        SELECT COUNT(1) FROM `yeshi_ec_customer_content` yecc WHERE cn_id = #{id};
    </select>
    <!-- 查询联系客服信息 -->
    <select id="contactCustomerService" resultType="String">
        SELECT yecc.`content` FROM `yeshi_ec_customer_content` yecc WHERE yecc.`title` = #{title};
    </select>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/common/SystemManageMapper.xml
New file
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.system.dao.common.SystemManageMapper">
    <resultMap id="BaseResultMap" type="org.fanli.facade.system.entity.common.SystemManage">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="platform" property="platform" jdbcType="INTEGER" />
        <result column="createtime" property="createtime" jdbcType="BIGINT" />
        <result column="beizhu" property="beizhu" jdbcType="VARCHAR" />
        <result column="package_name" property="packageName" jdbcType="VARCHAR" />
        <result column="appid" property="appid" jdbcType="VARCHAR" />
    </resultMap>
    <sql id="Base_Column_List">id,name,platform,createtime,beizhu,package_name,appid</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_system where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_system where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.system.entity.common.SystemManage"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_system
        (id,name,platform,createtime,beizhu,package_name,appid) values
        (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{platform,jdbcType=INTEGER},#{createtime,jdbcType=BIGINT},#{beizhu,jdbcType=VARCHAR},#{packageName,jdbcType=VARCHAR},#{appid,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.system.entity.common.SystemManage"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_system
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="platform != null">platform,</if>
            <if test="createtime != null">createtime,</if>
            <if test="beizhu != null">beizhu,</if>
            <if test="packageName != null">package_name,</if>
            <if test="appid != null">appid,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="name != null">#{name,jdbcType=VARCHAR},</if>
            <if test="platform != null">#{platform,jdbcType=INTEGER},</if>
            <if test="createtime != null">#{createtime,jdbcType=BIGINT},</if>
            <if test="beizhu != null">#{beizhu,jdbcType=VARCHAR},</if>
            <if test="packageName != null">#{packageName,jdbcType=VARCHAR},</if>
            <if test="appid != null">#{appid,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.system.entity.common.SystemManage">update
        yeshi_ec_system set name = #{name,jdbcType=VARCHAR},platform =
        #{platform,jdbcType=INTEGER},createtime =
        #{createtime,jdbcType=BIGINT},beizhu =
        #{beizhu,jdbcType=VARCHAR},package_name =
        #{packageName,jdbcType=VARCHAR},appid = #{appid,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.system.entity.common.SystemManage">
        update yeshi_ec_system
        <set>
            <if test="name != null">name=#{name,jdbcType=VARCHAR},</if>
            <if test="platform != null">platform=#{platform,jdbcType=INTEGER},</if>
            <if test="createtime != null">createtime=#{createtime,jdbcType=BIGINT},</if>
            <if test="beizhu != null">beizhu=#{beizhu,jdbcType=VARCHAR},</if>
            <if test="packageName != null">package_name=#{packageName,jdbcType=VARCHAR},</if>
            <if test="appid != null">appid=#{appid,jdbcType=VARCHAR},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/hongbao/HongBaoManageMapper.xml
New file
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.system.dao.hongbao.HongBaoManageMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.system.entity.hongbao.HongBaoManage">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="`key`" property="key" jdbcType="VARCHAR" />
        <result column="`value`" property="value" jdbcType="VARCHAR" />
        <result column="`remark`" property="remark" jdbcType="VARCHAR" />
    </resultMap>
    <sql id="Base_Column_List">id,`key`,`value`,`remark`</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_manage where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByKey" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_manage where `key` = #{0} order by validtime
        desc limit 1
    </select>
    <select id="selectByKeyAndMaxValidTime" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_manage where `key` = #{key} and
        UNIX_TIMESTAMP(validtime)*1000
        <![CDATA[
        <=
        ]]>
        #{timeStamp} order by validtime desc limit 1
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_hongbao_manage where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.system.entity.hongbao.HongBaoManage"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_hongbao_manage (id,`key`,`value`,`remark`) values
        (#{id,jdbcType=BIGINT},#{key,jdbcType=VARCHAR},#{value,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.system.entity.hongbao.HongBaoManage"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_hongbao_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="key != null">`key`,</if>
            <if test="value != null">`value`,</if>
            <if test="remark != null">`remark`,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="key != null">#{key,jdbcType=VARCHAR},</if>
            <if test="value != null">#{value,jdbcType=VARCHAR},</if>
            <if test="remark != null">#{remark,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.system.entity.hongbao.HongBaoManage">update
        yeshi_ec_hongbao_manage set `key` = #{key,jdbcType=VARCHAR},`value` =
        #{value,jdbcType=VARCHAR},`remark` = #{remark,jdbcType=VARCHAR} where
        id
        = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.system.entity.hongbao.HongBaoManage">
        update yeshi_ec_hongbao_manage
        <set>
            <if test="key != null">key=#{key,jdbcType=VARCHAR},</if>
            <if test="value != null">value=#{value,jdbcType=VARCHAR},</if>
            <if test="remark != null">remark=#{remark,jdbcType=VARCHAR},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/hongbao/HongBaoManageServiceImpl.java
New file
@@ -0,0 +1,138 @@
package com.yeshi.fanli.system.service.impl.hongbao;
import java.math.BigDecimal;
import javax.annotation.Resource;
import org.fanli.facade.system.entity.hongbao.HongBaoManage;
import org.fanli.facade.system.service.hongbao.HongBaoManageService;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.base.log.LogHelper;
import com.yeshi.fanli.system.dao.hongbao.HongBaoManageMapper;
@Service
public class HongBaoManageServiceImpl implements HongBaoManageService {
    @Resource
    private HongBaoManageMapper hongBaoManageMapper;
    @Override
    public BigDecimal getFanLiRate(long time) {
        String key = "hongbao_goods_proportion";
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return null;
    }
    @Override
    public BigDecimal getShareRate(long time) {
        String key = "share_proportion";
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取分享赚分成比例出错");
        return null;
    }
    @Override
    public BigDecimal getFanLiRate() {
        return getFanLiRate(System.currentTimeMillis());
    }
    @Override
    public BigDecimal getShareRate() {
        return getShareRate(System.currentTimeMillis());
    }
    @Override
    public BigDecimal getFirstInviteRate(int urank) {
        return getFirstInviteRate(urank, System.currentTimeMillis());
    }
    @Override
    public BigDecimal getFirstInviteRate(int urank, long time) {
        String key = "sale_6_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getSecondInviteRate(int urank) {
        return getSecondInviteRate(urank, System.currentTimeMillis());
    }
    @Override
    public BigDecimal getSecondInviteRate(int urank, long time) {
        String key = "sale_7_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getFirstShareRate(int urank) {
        String key = "share_21_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, System.currentTimeMillis());
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getFirstShareRate(int urank, long time) {
        String key = "share_21_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getSecondShareRate(int urank) {
        String key = "share_22_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, System.currentTimeMillis());
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getSecondShareRate(int urank, long time) {
        String key = "share_22_" + urank;
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return new BigDecimal(0);
    }
}
fanli-service-user/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-service-user/.project
New file
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-service-user</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    </natures>
</projectDescription>
fanli-utils/.classpath
New file
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
fanli-utils/.project
New file
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>fanli-utils</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>