yujian
2019-05-20 179b39401c406579a0d10c442a665aeb2802e931
Merge remote-tracking branch 'origin/master'

Conflicts:
fanli/src/main/java/com/yeshi/fanli/controller/client/RecommendController.java
fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
26 文件已重命名
16个文件已修改
3个文件已添加
3745 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsSubClassAdminController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ActivityController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ApiController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/BrandController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ConfigController.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/CustomerServiceController.java 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicRecommendController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsClassController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HelpController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HomeNavbarController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HotSellController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/InviteGetMoneyController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/LostOrderController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java 2344 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/S11Controller.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SMSController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SearchController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java 838 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SystemClientController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserAccountController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserAuthController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserCouponController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserGoodsStorageController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserInfoController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMoneyController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMsgController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserOrderController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/xcx/XcxGoodsClassController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/bus/clazz/GoodsClass.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/bus/clazz/GoodsSubClass.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsClassMapper.xml 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsSubClassMapper.xml 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/LostOrderMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoClassRelationServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserNotificationServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/TaoBaoClassRelationService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java
@@ -33,7 +33,7 @@
@Aspect
@Order(2)
public class SignValidateAspect {
    public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*(..))";
    public static final String EDP = "execution(* com.yeshi.fanli.controller.client.v1.*.*(..))";
    public static String KEY = "";
fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
@@ -225,9 +226,11 @@
            if (errCode == 0)// 成功
            {
                if ("share".equalsIgnoreCase(source)) {
                    response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=0");
                    // response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=0");
                    closeWebPage(response.getWriter());
                } else if ("zigou".equalsIgnoreCase(source)) {
                    response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=0");
                    // response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=0");
                    closeWebPage(response.getWriter());
                } else if ("bind".equalsIgnoreCase(source)) {
                    String script = String.format(
                            "<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"恭喜你,淘宝绑定成功\");yestv.finishPage();}</script>",
@@ -236,9 +239,11 @@
                }
            } else {// 失败
                if ("share".equalsIgnoreCase(source)) {
                    response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=1");
                    // response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=1");
                    closeWebPage(response.getWriter());
                } else if ("zigou".equalsIgnoreCase(source)) {
                    response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=1");
                    // response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=1");
                    closeWebPage(response.getWriter());
                } else if ("bind".equalsIgnoreCase(source)) {
                    String script = String.format(
                            "<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"抱歉,淘宝绑定失败\");yestv.finishPage();}</script>",
@@ -252,6 +257,11 @@
    }
    private void closeWebPage(PrintWriter out) {
        String script = "<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.finishPage();}</script>";
        out.print(script);
    }
    @RequestMapping(value = "pinduoduo")
    public void pinDuoDuo(HttpServletResponse response) {
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsSubClassAdminController.java
@@ -18,8 +18,10 @@
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabelMap;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
import com.yeshi.fanli.exception.FloatADException;
import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService;
import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
import com.yeshi.fanli.service.inter.lable.LabelClassService;
@@ -38,6 +40,9 @@
    @Resource
    private TaoBaoClassService taoBaoClassService;
    @Resource
    private GoodsSubClassLabelService goodsSubClassLabelService;
    /**
     * 保存信息
@@ -212,6 +217,12 @@
                    }
                    goodsSubClass.setTaobaoCids(taobaoCids);
                }
                // 查询标签
                GoodsSubClassLabelMap map = goodsSubClassLabelService.selectBySubClassId(goodsSubClass.getId());
                if (map != null)
                    goodsSubClass.setClassLabel(map.getLabel());
            }
            GsonBuilder gsonBuilder = new GsonBuilder();
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ActivityController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/ActivityController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.IOException;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ApiController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/ApiController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/BrandController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/BrandController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ConfigController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/ConfigController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
@@ -48,7 +48,6 @@
    @Resource
    private FloatADService floatADService;
    
    /**
     * 首页配置信息
@@ -193,19 +192,19 @@
    
    /**
     * 订单解析配置
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getOrderParseConfig", method = RequestMethod.POST)
    public void getOrderParseConfig(AcceptData acceptData, PrintWriter out) {
        String orderJS = "var orderId= document.getElementById('tp-bought-root').getElementsByClassName('js-order-container')[0].getElementsByTagName('div')[0].getAttribute('data-id');";
        orderJS += "if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href='yestv://taobaoorder#'+orderId;} else {window.handle.showOrder(orderId)}";
        String orderJS = configService.get("taobao_order_parse_js");
        JSONObject data = new JSONObject();
        try {
            data.put("orderJS", DESUtil.encode(orderJS, StringUtil.getBase64String("YeShiFANLI889*+"),
                    StringUtil.getBase64String("*M#34f?,")));
            data.put("orderUrl", DESUtil.encode( "https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm",StringUtil.getBase64String("YeShiFANLI889*+"),
                    StringUtil.getBase64String("*M#34f?,")));
            data.put("orderUrl", DESUtil.encode("https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm",
                    StringUtil.getBase64String("YeShiFANLI889*+"), StringUtil.getBase64String("*M#34f?,")));
        } catch (Exception e) {
            e.printStackTrace();
        }
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/CustomerServiceController.java
New file
@@ -0,0 +1,159 @@
package com.yeshi.fanli.controller.client.v1;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.entity.AppInfo;
import com.yeshi.fanli.entity.DeviceInfo;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion;
import com.yeshi.fanli.entity.customerservice.CustomerServiceHistory;
import com.yeshi.fanli.exception.user.UserComplaintException;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceHistoryService;
import com.yeshi.fanli.service.inter.user.UserComplaintService;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
/**
 * 客服api接口
 *
 * @author Administrator
 *
 */
@Controller
@RequestMapping("api/v1/customerservice")
public class CustomerServiceController {
    @Resource
    private CustomerServiceCommonQuestionService customerServiceCommonQuestionService;
    @Resource
    private CustomerServiceHistoryService customerServiceHistoryService;
    @Resource
    private UserComplaintService userComplaintService;
    /**
     * 预设标题的关键字列表
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getkeys", method = RequestMethod.POST)
    public void getKeys(AcceptData acceptData, PrintWriter out) {
        List<String> keys = customerServiceCommonQuestionService.listKeysCache();
        JSONObject data = new JSONObject();
        data.put("keys", keys);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 根据关键字获取答案
     *
     * @param acceptData
     * @param key
     *            -关键字
     * @param out
     */
    @RequestMapping(value = "getanswer", method = RequestMethod.POST)
    public void getGoodsInfo(AcceptData acceptData, String key, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(key)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传问题"));
            return;
        }
        if (key.length() > 512) {
            out.print(JsonUtil.loadFalseResult(2, "问题过长,请精简问题"));
            return;
        }
        Gson gson = new Gson();
        CustomerServiceHistory history = new CustomerServiceHistory();
        AppInfo appInfo = new AppInfo();
        appInfo.setChannel(acceptData.getChannel());
        appInfo.setPackages(acceptData.getPackages());
        appInfo.setVersion(acceptData.getVersion());
        history.setAppInfo(appInfo);
        history.setAppInfoStr(gson.toJson(appInfo));
        history.setContent(key);
        history.setCreateTime(new Date());
        history.setDevice(acceptData.getDevice());
        DeviceInfo deviceInfo = new DeviceInfo();
        deviceInfo.setDevice(acceptData.getDevice());
        deviceInfo.setDeviceType(acceptData.getDeviceType());
        deviceInfo.setNetwork(acceptData.getNetwork());
        deviceInfo.setOsVersion(acceptData.getOsVersion());
        deviceInfo.setPlatform(acceptData.getPlatform());
        history.setDeviceInfo(deviceInfo);
        history.setDeviceInfoStr(gson.toJson(deviceInfo));
        history.setPlatform(acceptData.getPlatform());
        history.setUpdateTime(new Date());
        // 保存问题历史记录
        customerServiceHistoryService.addHistory(history);
        // 搜索问题答案
        CustomerServiceCommonQuestion answer = customerServiceCommonQuestionService.searchByKeyCache(key);
        if (answer == null) {
            answer = new CustomerServiceCommonQuestion();
            answer.setKey("");
            answer.setContentType(CustomerServiceCommonQuestion.TYPE_TEXT);
            answer.setContent("客服机器人不明白您的问题,请输入你问题的准确关键词或转人工客服解决,谢谢!#^.^#");
            // out.print(JsonUtil.loadFalseResult(-1, "无答案"));
            // return;
        }
        out.print(JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(answer)));
    }
    /**
     * 用户吐槽记录添加
     *
     * @param fileList
     * @param uid
     * @param content
     * @param out
     */
    @RequestMapping(value = "complaint")
    public void complaint(AcceptData acceptData, MultipartFile[] fileList, String content, Long uid,
            HttpServletRequest request, PrintWriter out) {
        try {
            List<MultipartFile> files = new ArrayList<>();
            if (fileList != null)
                for (MultipartFile mf : fileList) {
                    files.add(mf);
                }
            userComplaintService.addUserComplaint(files, uid, content);
            out.print(JsonUtil.loadTrueResult("保存成功"));
        } catch (UserComplaintException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (IOException e) {
            out.print(JsonUtil.loadFalseResult("图片上传失败失败"));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("保存失败"));
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/DynamicController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.lang.reflect.Type;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicRecommendController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/DynamicRecommendController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsClassController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsClassController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
@@ -155,8 +155,10 @@
                        else
                            taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId,
                                    tbPidService.getIOSDefault().getPid());
                    } else
                        taoBaoLink = shareGoodsService.getTaoBaoLinkForBuy(uid, auctionId, pidType);
                    LogHelper.test("购买转链:默认PID转链-"+uid+":"+auctionId);
                }
            } else {// 不是返利库的商品,用特殊PID替代
                try {
@@ -175,6 +177,8 @@
                    else
                        taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId,
                                tbPidService.getIOSDefault().getPid());
                    LogHelper.test("购买转链:默认PID转链-非返利库商品-"+uid+":"+auctionId);
                }
            }
            JSONObject link = new JSONObject();
@@ -199,6 +203,8 @@
                tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_FANLI_IOS);
            }
            LogHelper.test("购买转链:默认PID转链-异常商品-"+uid+":"+auctionId);
            data.put("native", isNative);
            if (tbPid != null) {
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HelpController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/HelpController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HomeNavbarController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/HomeNavbarController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/HotSellController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/HotSellController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/InviteGetMoneyController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/InviteGetMoneyController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.IOException;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/LostOrderController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/LostOrderController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.List;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.Date;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java
New file
@@ -0,0 +1,2344 @@
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.IPUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.NumberUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.homemodule.Special;
import com.yeshi.fanli.entity.bus.homemodule.SuperSpecial;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.bus.recommend.Honest;
import com.yeshi.fanli.entity.bus.recommend.RecommendBanner;
import com.yeshi.fanli.entity.bus.recommend.RecommendBannerV2;
import com.yeshi.fanli.entity.bus.recommend.RecommendSpecial;
import com.yeshi.fanli.entity.bus.su.recommend.SuperRecommendBanner;
import com.yeshi.fanli.entity.bus.su.recommend.SuperRecommendSpecial;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.ShamUser;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.common.ImageInfo;
import com.yeshi.fanli.entity.common.JumpDetail;
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.goods.ScanHistoryV2;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.SearchFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.exception.goods.ScanHistoryException;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
import com.yeshi.fanli.exception.user.UserCustomSettingsException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.JumpDetailService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.config.SystemConfigService;
import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
import com.yeshi.fanli.service.inter.goods.SuperRecommendBannerService;
import com.yeshi.fanli.service.inter.goods.SuperRecommendBannerV2Service;
import com.yeshi.fanli.service.inter.goods.SuperRecommendSpecialService;
import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.homemodule.SpecialService;
import com.yeshi.fanli.service.inter.homemodule.SuperSpecialService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.lable.QualityFlashSaleService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.monitor.MonitorService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.ShamUserService;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.MonitorFactory;
import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import com.yeshi.fanli.vo.user.UserSettingsVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v1/user")
public class RecommendController {
    @Resource
    private BusinessSystemService businessSystemService;
    @Resource
    private SuperRecommendBannerService superRecommendBannerService;
    @Resource
    private SuperRecommendSpecialService superRecommendSpecialService;
    @Resource
    private OrderService orderService;
    @Resource
    private ScanHistoryV2Service scanHistoryV2Service;
    @Resource
    private ConfigService configService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private TaoBaoCouponService taoBaoCouponService;
    @Resource
    private JumpDetailService jumpDetailService;
    @Resource
    private SystemConfigService systemConfigService;
    @Resource
    private CollectionGoodsV2Service collectionGoodsV2Service;
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
    @Resource
    private RedisManager redisManager;
    @Resource
    private TBPidService tbPidService;
    @Resource
    private SystemClientParamsService systemClientParamsService;
    @Resource
    private HongBaoManageService manageService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
    @Resource
    private QualityGoodsService qualityGoodsService;
    @Resource
    private SuperSpecialService superSpecialService;
    @Resource
    private SuperRecommendBannerV2Service superRecommendBannerV2Service;
    @Resource
    private ShamUserService shamUserService;
    @Resource
    private SpecialService specialService;
    @Resource
    private SwiperPictureService swiperPictureService;
    @Resource
    private MonitorService monitorService;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Resource
    private UserGoodsStorageService userGoodsStorageService;
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    @Resource
    private UserCustomSettingsService userCustomSettingsService;
    @Resource
    private ShareGoodsActivityOrderService shareGoodsActivityOrderService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private QualityFlashSaleService qualityFlashSaleService;
    @Resource
    private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
    @Resource
    private TaoBaoShopService taoBaoShopService;
    @RequestMapping(value = "getHonestList")
    public void getHonestList(AcceptData acceptData, PrintWriter out) {
        List<Honest> honestList = null;
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
        if ((Integer.parseInt(acceptData.getVersion()) >= 20 && "android".equalsIgnoreCase(acceptData.getPlatform()))
                || ("ios".equalsIgnoreCase(acceptData.getPlatform())
                        && Integer.parseInt(acceptData.getVersion()) >= 32))// Android
                                                                            // 大于20的版本和ios大于31的版本返回新的内容
        {
            honestList = new ArrayList<>();
            JumpDetail detail = new JumpDetail();
            detail.setActivity(String.format("%s.ui.invite.ShareBrowserActivity",
                    Constant.systemCommonConfig.getAndroidBaseactivityName()));
            detail.setName("网页");
            detail.setController("ShonpingShareViewController");
            Honest honest = new Honest();
            honest.setName("9.9包邮");
            honest.setJumpDetail(detail);
            JSONObject params = new JSONObject();
            params.put("url", "http://cdn.apph5.yeshitv.com/special/jingXuanN_9.html?type=9_9");
            honest.setParams(params.toString());
            honest.setPicture("http://ec-1255749512.file.myqcloud.com/resource/special/9k9.jpg");
            honest.setType(1); /* 1:9块9 2:19块9 3:特价好货 4:分享有礼 */
            honestList.add(honest);
            honest = new Honest();
            honest.setName("今日新品");
            honest.setJumpDetail(detail);
            params = new JSONObject();
            params.put("url", "http://cdn.apph5.yeshitv.com/special/todayNew.html");
            honest.setParams(params.toString());
            honest.setPicture(
                    "http://ec-1255749512.file.myqcloud.com/resource/special/%E4%BB%8A%E6%97%A5%E6%96%B0%E5%93%81.jpg");
            honest.setType(1);
            honestList.add(honest);
            honest = new Honest();
            honest.setName("大额券");
            honest.setJumpDetail(detail);
            params = new JSONObject();
            params.put("url", "http://cdn.apph5.yeshitv.com/special/daEQuan.html");
            honest.setParams(params.toString());
            honest.setPicture(
                    "http://ec-1255749512.file.myqcloud.com/resource/special/%E5%A4%A7%E9%A2%9D%E5%88%B8.jpg");
            honest.setType(1);
            honestList.add(honest);
            honest = new Honest();
            honest.setName("超高返");
            honest.setJumpDetail(detail);
            params = new JSONObject();
            params.put("url", "http://cdn.apph5.yeshitv.com/special/chaoGaoJiangJin.html");
            honest.setParams(params.toString());
            honest.setPicture(
                    "http://ec-1255749512.file.myqcloud.com/resource/special/%E8%B6%85%E9%AB%98%E8%BF%94.jpg");
            honest.setType(1);
            honestList.add(honest);
            if (Constant.IS_TEST) {
                honest = new Honest();
                honest.setName("超高返");
                honest.setJumpDetail(detail);
                params = new JSONObject();
                params.put("url", "http://cdn.apph5.yeshitv.com/special/chaoGaoJiangJin.html");
                honest.setParams(params.toString());
                honest.setPicture(
                        "http://ec-1255749512.file.myqcloud.com/resource/special/%E8%B6%85%E9%AB%98%E8%BF%94.jpg");
                honest.setType(1);
                honestList.add(honest);
            }
            // if (acceptData.getPlatform().equalsIgnoreCase("ios")
            // &&
            // configService.iosOnLining(Integer.parseInt(acceptData.getVersion())))
            // {
            // honest = new Honest();
            // honest.setName("今日必抢");
            // honest.setJumpDetail(detail);
            // params = new JSONObject();
            // params.put("url",
            // "https://pages.tmall.com/wow/a/act/20051/upr?spm=a219t.7664554.1998457203.704.2ae335d9FKajS5&wh_pid=industry-151736&wh_weex=true&wh_biz=tm");
            // honest.setParams(params.toString());
            // honest.setPicture("http://ec-1255749512.file.myqcloud.com/resource/jrbq.png");
            // honest.setType(1);
            // honestList.add(honest);
            // } else {
            // honest = new Honest();
            // honest.setType(4);
            // honest.setName("邀请有奖");
            // honest.setJumpDetail(null);
            // honest.setPicture(
            // "http://ec-1255749512.file.myqcloud.com/resource/%E9%82%80%E8%AF%B7%E6%9C%89%E5%A5%96.png");
            // honestList.add(honest);
            // }
        } else {
            honestList = new ArrayList<>();
            JumpDetail detail = new JumpDetail();
            detail.setActivity(
                    String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
            detail.setName("网页");
            // GoodsDetailController
            detail.setController("BrowserController");
            Honest honest = new Honest();
            honest.setName("9块9");
            honest.setJumpDetail(detail);
            JSONObject params = new JSONObject();
            params.put("url", "https://temai.m.taobao.com/9k9?pid=" + configList.get(0).getDefaultPid());
            honest.setParams(params.toString());
            honest.setPicture("http://ec-1255749512.file.myqcloud.com/resource/9.9.png");
            honest.setType(1); /* 1:9块9 2:19块9 3:特价好货 4:分享有礼 */
            honestList.add(honest);
            honest = new Honest();
            honest.setName("淘宝特卖");
            honest.setJumpDetail(detail);
            params = new JSONObject();
            params.put("url", "https://temai.m.taobao.com/index.htm?pid=" + configList.get(0).getDefaultPid());
            honest.setParams(params.toString());
            honest.setPicture(
                    "http://ec-1255749512.file.myqcloud.com/resource/%E7%89%B9%E4%BB%B7%E5%A5%BD%E8%B4%A7.png");
            honest.setType(1);
            honestList.add(honest);
            honest = new Honest();
            honest.setName("旅游出行");
            honest.setJumpDetail(detail);
            params = new JSONObject();
            params.put("url",
                    "https://s.click.taobao.com/t?e=m%3D2%26s%3DBYnJkWG4TG0cQipKwQzePCperVdZeJviEViQ0P1Vf2kguMN8XjClAu02u1KR7qygWNI3LssOJ1ZWrun95JZUdbCdKVyILC1Y4MhN4biK4jW7lfuQJIvfPIK88P%2FKzi0kxxWvg6Zgs%2BufKdnhu%2B44hB9qAVPM25K0cj5d26O5JTnBV7GfGbfBR06AKI8EMgZwgGJ6r9DajuEo%2Bq0qHgj4%2Fr%2BOY9SrDkfyH5S%2BAXadU8u31WUvb1IPCiGFCzYOOqAQ");
            honest.setParams(params.toString());
            honest.setPicture(
                    "http://ec-1255749512.file.myqcloud.com/resource/%E6%97%85%E6%B8%B8%E5%87%BA%E8%A1%8C.png");
            honest.setType(1);
            honestList.add(honest);
            if (acceptData.getPlatform().equalsIgnoreCase("ios")
                    && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
                honest = new Honest();
                honest.setName("今日必抢");
                honest.setJumpDetail(detail);
                params = new JSONObject();
                params.put("url",
                        "https://pages.tmall.com/wow/a/act/20051/upr?spm=a219t.7664554.1998457203.704.2ae335d9FKajS5&wh_pid=industry-151736&wh_weex=true&wh_biz=tm");
                honest.setParams(params.toString());
                honest.setPicture("http://ec-1255749512.file.myqcloud.com/resource/jrbq.png");
                honest.setType(1);
                honestList.add(honest);
            } else {
                honest = new Honest();
                honest.setType(4);
                honest.setName("邀请有奖");
                honest.setJumpDetail(null);
                honest.setPicture(
                        "http://ec-1255749512.file.myqcloud.com/resource/%E9%82%80%E8%AF%B7%E6%9C%89%E5%A5%96.png");
                honestList.add(honest);
            }
        }
        String result = JsonUtil.loadTrueResult(honestList);
        out.print(result);
        return;
    }
    @RequestMapping(value = "getrecommendspecial")
    public void getRecommendSpecial(AcceptData acceptData, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        String version = acceptData.getVersion();
        JumpDetail jumpDetail = null;
        if (!"1".equals(version) && "android".equalsIgnoreCase(acceptData.getPlatform())) {
            jumpDetail = jumpDetailService.getlastJumpDetailCache();
        }
        List<RecommendSpecial> recommendSpecialList = null;
        List<SuperRecommendSpecial> superRecommendSpecialList = superRecommendSpecialService
                .getSuperRecommendSpecialBySystemId(system.getId());
        if (superRecommendSpecialList != null && superRecommendSpecialList.size() > 0) {
            recommendSpecialList = new ArrayList<RecommendSpecial>();
            for (SuperRecommendSpecial superRecommendSpecial : superRecommendSpecialList) {
                RecommendSpecial recommendSpecial = superRecommendSpecial.getRecommendSpecial();
                if (jumpDetail != null) {
                    recommendSpecial.setJumpDetail(jumpDetail);
                }
                recommendSpecialList.add(recommendSpecial);
            }
        }
        if (recommendSpecialList == null || recommendSpecialList.size() == 0) {
            out.print(JsonUtil.loadFalseResult(1, "暂无数据"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("count", recommendSpecialList.size());
        Gson gson = new Gson();
        data.put("data", gson.toJson(recommendSpecialList));
        String json = JsonUtil.loadTrueResult(data);
        out.print(json);
    }
    // 猜你喜欢
    @RequestMapping(value = "guessLike", method = RequestMethod.POST)
    public void guessLike(AcceptData acceptData, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        List<TaoBaoGoodsBrief> taoBaoGoodsBriefs1 = taoBaoCouponService.getTaoBaoCouponList(2);
        List<TaoBaoGoodsBrief> taoBaoGoodsBriefs2 = new ArrayList<>();
        taoBaoGoodsBriefs2.addAll(taoBaoGoodsBriefs1);
        List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = new ArrayList<>();
        for (int i = 0; i < taoBaoGoodsBriefs2.size(); i++) {
            if (taoBaoGoodsBriefs2.size() > 0 && taoBaoGoodsBriefs.size() < 6) {
                int pos = (int) (Math.random() * taoBaoGoodsBriefs2.size());
                taoBaoGoodsBriefs.add(taoBaoGoodsBriefs2.get(pos));
                taoBaoGoodsBriefs2.remove(pos);
                i--;
            }
        }
        BigDecimal proportion = manageService.getFanLiRate();
        JSONArray array = new JSONArray();
        TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra;
        Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
        for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) {
            taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), "");
            array.add(gson.toJson(taoBaoGoodsBriefExtra));
        }
        JSONObject data = new JSONObject();
        data.put("goods", array);
        data.put("count", array.size());
        out.print(JsonUtil.loadTrueResult(data));
    }
    @RequestMapping(value = "getrecommendbanner")
    public void getRecommendBanner(AcceptData acceptData, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        JSONObject json = new JSONObject();
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        List<SuperRecommendBanner> superRecommendBanners = superRecommendBannerService
                .getSuperRecommendBannersBySystem(system);
        List<RecommendBanner> list = null;
        for (SuperRecommendBanner superRecommendBanner : superRecommendBanners) {
            if (list == null) {
                list = new ArrayList<RecommendBanner>();
            }
            RecommendBanner recommendBanner = superRecommendBanner.getRecommendBanner();
            // 淘特价暂时修改
            if (system.getId() == 7) {
                recommendBanner.getJumpDetail().setActivity(recommendBanner.getJumpDetail().getActivity()
                        .replace("com.yeshi.ec.rebate.myapplication", "com.yeshi.ec.taospecial"));
            }
            list.add(recommendBanner);
        }
        // 测试
        // 添加跳转商品详情
        // RecommendBanner banner = new RecommendBanner();
        // banner.setId(1);
        // JumpDetail jumpDetail = new JumpDetail();
        // jumpDetail.setActivity("com.yeshi.ec.rebate.myapplication.ui.recommend.GoodsBrowserActivity");
        // jumpDetail.setController("GoodsDetailController");
        // jumpDetail.setName("商品详情");
        //
        // banner.setJumpDetail(jumpDetail);
        // banner.setName("详情");
        // banner.setOrderby(1);
        // JSONObject param = new JSONObject();
        // param.put("id", "568650986077");
        // banner.setParams(param.toString());
        // banner.setPicture(
        // "https://gd3.alicdn.com/imgextra/i2/266969832/TB2iiKjoAyWBuNjy0FpXXassXXa_!!266969832.jpg_400x400.jpg_.webp");
        // list.add(banner);
        if (list == null) {
            json.put("code", "1");
            json.put("msg", "暂无数据");
            out.print(json);
            java.lang.System.out.println("json-" + json);
            return;
        }
        json.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("count", list.size());
        Gson gson = new Gson();
        data.put("data", gson.toJson(list));
        json.put("data", data);
        out.print(json);
        return;
    }
    // 获取商品详情
    @RequestMapping(value = "getgoodsdetail", method = RequestMethod.POST)
    public void getGoodsDetail(final AcceptData acceptData, final String id, final String uid, PrintWriter out) {
        long begin = java.lang.System.currentTimeMillis();
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        // 获取会员推广位或者默认推广位
        TaoBaoGoodsBrief simpleGoods = null;
        try {
            simpleGoods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(id));
        } catch (NumberFormatException e2) {
            e2.printStackTrace();
        } catch (TaobaoGoodsDownException e2) {
            e2.printStackTrace();
        }
        if (simpleGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        // 获取淘客参数
        ClientTBPid clientTBPid = null;
        if (simpleGoods.getMaterialLibType() != null && simpleGoods.getMaterialLibType() == 1) {
            String pid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT;
            clientTBPid = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                    pid.split("_")[2], pid.split("_")[3]);
        } else {
            if (acceptData.getPlatform().equalsIgnoreCase("android")) {
                clientTBPid = tbPidService.getAndroidDefault();
            } else {
                clientTBPid = tbPidService.getIOSDefault();
            }
        }
        TaoBaoGoodsBrief tb = null;
        try {
            TaoKeAppInfo app = new TaoKeAppInfo();
            TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(clientTBPid.getSiteId());
            app.setAdzoneId(clientTBPid.getAdZoneId());
            app.setAppKey(clientTBPid.getAppKey());
            app.setAppSecret(config.getAppSecret());
            app.setPid(clientTBPid.getPid());
            tb = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
        } catch (NumberFormatException e1) {
            e1.printStackTrace();
        } catch (TaobaoGoodsDownException e1) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        if (tb != null) {
            // tb.setAuctionUrl(null);
            tb.setId(null);
            int type = 0;
            if ("android".equalsIgnoreCase(acceptData.getPlatform()))
                type = PidUser.TYPE_FANLI_ANDROID;
            else
                type = PidUser.TYPE_FANLI_IOS;
            List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(type);
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            JSONObject data = new JSONObject();
            TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(tb, configList.get(0));
            if (!StringUtil.isNullOrEmpty(tb.getCouponLink()) && taoBaoGoodsBriefExtra.getTaoBaoQuanInfo() != null)
                taoBaoGoodsBriefExtra.getTaoBaoQuanInfo().setCouponLink(tb.getCouponLink());
            taoBaoGoodsBriefExtra.setAuctionUrl(tb.getAuctionUrl());
            if (uid != null && !"".equals(uid.trim())) {
                CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(Long.parseLong(uid),
                        Long.parseLong(id));
                data.put("collection", collectionGoods != null ? true : false);
            }
            data.put("tbPidInfo", clientTBPid);
            JSONObject taobaoJson = JSONObject.fromObject(gson.toJson(taoBaoGoodsBriefExtra));
            if (taoBaoGoodsBriefExtra.getImgList() != null)
                taoBaoGoodsBriefExtra.getImgList().add(0, taoBaoGoodsBriefExtra.getPictUrl());
            taobaoJson.put("imgList", taoBaoGoodsBriefExtra.getImgList());
            taobaoJson.put("saleCount", taoBaoGoodsBriefExtra.getSalesCount());// 销量(和salesCount一致,此处处理兼容)
            if (taoBaoGoodsBriefExtra.getTaoBaoQuanInfo() != null)
                taobaoJson.put("coupon", true);
            else
                taobaoJson.put("coupon", false);
            // taoBaoGoodsBriefExtra.setAuctionUrl(null);
            data.put("taobao", taobaoJson);
            String info = configService.get("detail_prompt");
            data.put("info", info);
            String onlyInfo = configService.get("only_info");
            data.put("only", onlyInfo);
            data.put("helpUrl", configService.get("old_goods_detail_help_url"));
            int showType = taoBaoGoodsBriefExtra.getShowType();
            String price = "";
            if (showType == 1 || showType == 3) {
                price = taoBaoGoodsBriefExtra.getQuanPrice() + "";
            } else {
                price = taoBaoGoodsBriefExtra.getZkPrice() + "";
            }
            String appName = systemConfigService.get("appName", system);
            data.put("sharePrice", "¥" + price + "元      送" + appName + "红包¥"
                    + taoBaoGoodsBriefExtra.getTaoBaoHongBaoInfo().getHongbao() + "元 ");
            data.put("shareTitle", taoBaoGoodsBriefExtra.getTitle());
            data.put("shareContent", "¥" + price + "元");
            data.put("shareImg", taoBaoGoodsBriefExtra.getPictUrl());
            String html = configService.get("downAPP");
            data.put("downAPP", html);
            String shareSinaContent = configService.get("shareSinaContent");
            data.put("shareSina",
                    "¥" + price + "元      送" + appName + "红包¥"
                            + taoBaoGoodsBriefExtra.getTaoBaoHongBaoInfo().getHongbao() + "元    "
                            + taoBaoGoodsBriefExtra.getTitle() + shareSinaContent);
            data.put("sharemoney", "分享奖金 ¥" + taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb) + "元");
            data.put("shareHongBao", "¥" + taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb));
            out.print(JsonUtil.loadTrueResult(data));
            final TaoBaoGoodsBrief tbb = tb;
            ThreadUtil.run(new Runnable() {
                public void run() {
                    // 添加浏览记录
                    try {
                        scanHistoryV2Service.addScanHistory(StringUtil.isNullOrEmpty(uid) ? null : Long.parseLong(uid),
                                acceptData.getDevice(), tbb);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        } else {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
        }
        long end = java.lang.System.currentTimeMillis();
        java.lang.System.out.println("耗时:" + (end - begin));
        return;
    }
    // 新版商品图文详情
    @RequestMapping(value = "getnewgoodsdetail", method = RequestMethod.POST)
    public void getNewGoodsDetail(AcceptData acceptData, String id, String uid, HttpServletRequest request,
            PrintWriter out) {
        if ("0".equalsIgnoreCase(uid))
            uid = "";
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("invalid", false);
        // IOS是否正在上线
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            data.put("iosOnling", configService.iosOnLining(Integer.parseInt(acceptData.getVersion())));
        }
        long startTime = java.lang.System.currentTimeMillis();
        // 获取淘客参数
        ClientTBPid clientTBPid = null;
        // 用户已经登录
        if (acceptData.getPlatform().equalsIgnoreCase("android"))
            clientTBPid = tbPidService.getAndroidDefault();
        else
            clientTBPid = tbPidService.getIOSDefault();
        LogHelper.test("获取PID耗时:" + (java.lang.System.currentTimeMillis() - startTime));
        // 是否在服务端进行转链
        boolean convertInServer = configService.isConvertTaoBaoLinkInServer();
        final String clientPid = clientTBPid.getPid();
        List<String> taskList = new ArrayList<>();
        taskList.add("goods");
        taskList.add("imgs");
        List<String> detailImgs = new ArrayList<>();
        JSONArray detailImgsSize = new JSONArray();
        final List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        taskList.stream().parallel().forEach(task -> {
            if (task.equalsIgnoreCase("goods")) {// 获取商品详情
                // TaoBaoGoodsBrief tb = null;
                JSONObject ticket = new JSONObject();
                TaoBaoGoodsBrief goods = null;
                if (convertInServer) {
                    String appId = clientPid.split("_")[2];
                    TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
                    TaoKeAppInfo app = new TaoKeAppInfo();
                    app.setAdzoneId(clientPid.split("_")[3]);
                    app.setAppKey(config.getAppKey());
                    app.setAppSecret(config.getAppSecret());
                    app.setPid(clientPid);
                    try {
                        goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
                        if (goods != null) {
                            ticket.put("clickUrl", goods.getAuctionUrl());
                            // 测试使用
                            ticket.put("couponUrl", goods.getCouponLink());
                            data.put("ticket", ticket);
                        }
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    } catch (TaobaoGoodsDownException e) {
                        try {
                            monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0, 0, "商品下架"));
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                } else {
                    try {
                        goods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(id));
                    } catch (TaobaoGoodsDownException e) {
                        try {
                            monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0, 0, "商品下架"));
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                        // 商品下架
                        ThreadUtil.run(new Runnable() {
                            public void run() {
                                taoBaoGoodsUpdateService.deleteTaoBaoGoods(Long.parseLong(id));
                            }
                        });
                    }
                }
                if (goods != null) {
                    goodsList.add(goods);
                    final TaoBaoGoodsBrief newGoods = goods;
                    ThreadUtil.run(new Runnable() {
                        public void run() {
                            try {
                                // 更新商品
                                LogHelper.test("更新商品详情:" + newGoods.getAuctionId());
                                taoBaoGoodsUpdateService.updateTaoBaoGoods(newGoods);
                            } catch (TaobaoGoodsUpdateException e) {
                            }
                        }
                    });
                }
            } else if (task.equalsIgnoreCase("imgs")) {// 获取图文详情
                List<ImageInfo> imgs = redisManager.getTaoBaoGoodsDetailImgs(Long.parseLong(id));
                if (imgs != null && imgs.size() > 0) {
                    detailImgs.clear();
                    detailImgsSize.clear();
                    for (ImageInfo imgInfo : imgs) {
                        detailImgs.add(imgInfo.getPicture());
                    }
                    for (ImageInfo imgInfo : imgs) {
                        if (imgInfo.getWidth() <= 0) {
                            detailImgsSize.clear();
                            break;
                        } else {
                            JSONObject size = new JSONObject();
                            size.put("w", imgInfo.getWidth());
                            size.put("h", imgInfo.getHeight());
                            detailImgsSize.add(size);
                        }
                    }
                }
            }
        });
        TaoBaoGoodsBrief tb = null;
        if (goodsList.size() > 0)
            tb = goodsList.get(0);
        if (tb == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        // 获取PID
        String pid = "";
        JSONObject goods = new JSONObject();
        //
        if (tb.getImgList() == null)
            tb.setImgList(new ArrayList<>());
        tb.getImgList().add(0, tb.getPictUrl());
        List<String> finalImgList = new ArrayList<>();
        for (String img : tb.getImgList()) {
            // img=TbImgUtil.getTBSizeImgWebp(img, 600);
            finalImgList.add(img);
        }
        goods.put("auctionId", tb.getAuctionId());
        goods.put("imgList", finalImgList);
        goods.put("title", tb.getTitle());
        goods.put("userType", tb.getUserType() == 1 ? 2 : 1);
        goods.put("price", tb.getReservePrice().toString());
        goods.put("zkPrice", tb.getZkPrice().toString());
        BigDecimal proportion = manageService.getFanLiRate();
        String hongBao = TaoBaoUtil.getGoodsHongBaoInfo(tb, proportion);
        goods.put("hongBao", hongBao);
        // 30天销量
        goods.put("saleCount", TaoBaoUtil.getSaleCount(tb.getBiz30day()));
        // 获取详细的图文信息
        goods.put("detailImgs", detailImgs);
        goods.put("detailImgsSize", detailImgsSize);
        String jumpUrl = "https://item.taobao.com/item.htm?id=" + tb.getAuctionId();
        // 分享赚
        data.put("shareMoney", "¥" + taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb));
        // 判断收藏
        if (!StringUtil.isNullOrEmpty(uid)) {
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(Long.parseLong(uid),
                    Long.parseLong(id));
            data.put("collected", collectionGoods != null ? true : false);
        } else
            data.put("collected", false);
        pid = clientTBPid.getPid();
        LogHelper.test(String.format("PID: uid-%s  pid-%s", uid + "", pid));
        SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
                "goods_detail_jump_taobao");
        // 测试
        if ("1".equalsIgnoreCase((params.getValue() + "").trim()))
            data.put("native", true);
        else
            data.put("native", false);
        goods.put("coupon", StringUtil.isNullOrEmpty(tb.getCouponInfo()) ? false : true);
        // 获取券信息
        if (!StringUtil.isNullOrEmpty(tb.getCouponInfo())) {
            BigDecimal quanPrice = TaoBaoUtil.getAfterUseCouplePrice(tb);
            JSONObject couponInfo = new JSONObject();
            couponInfo.put("couponPrice", quanPrice.toString());
            // 服务端转链
            if (convertInServer && !StringUtil.isNullOrEmpty(tb.getCouponLink()))
                couponInfo.put("couponUrl", tb.getCouponLink());
            else
                couponInfo.put("couponUrl",
                        TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId() + "", pid, tb.getAuctionId() + ""));
            couponInfo.put("couponAmount", NumberUtil.subZeroAndDot(tb.getCouponAmount().toString()));
            couponInfo.put("couponTime", "使用期限:" + tb.getCouponEffectiveStartTime().replace("-", ".") + "-"
                    + tb.getCouponEffectiveEndTime().replace("-", "."));
            goods.put("couponInfo", couponInfo);
        }
        // 測試
        // clientTBPid.setAdZoneId("12");
        // clientTBPid.setPid("mm_123123_123123_123213");
        data.put("tbPidInfo", clientTBPid);
        if (!StringUtil.isNullOrEmpty(tb.getCouponActivityId())) {// 有券,跳转券链接
            jumpUrl = TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), clientTBPid.getPid(),
                    "" + tb.getAuctionId());
        }
        // 设置跳转链接
        if (convertInServer) {
            if (!StringUtil.isNullOrEmpty(tb.getCouponLink()))
                jumpUrl = tb.getCouponLink();
            else
                jumpUrl = tb.getAuctionUrl();
        }
        goods.put("jumpUrl", jumpUrl);
        goods.put("shopInfo", redisManager.getTBShopInfo(tb.getShopTitle(), tb.getSellerId(), tb.getAuctionId()));
        data.put("goods", goods);
        String shareUrl = String.format("%s?id=" + tb.getAuctionId(), Constant.systemCommonConfig.getAppShareInfoUrl());
        data.put("shareUrl", shareUrl);
        out.print(JsonUtil.loadTrueResult(data));
        final String tempUid = uid;
        final TaoBaoGoodsBrief goodsInfo = tb;
        ThreadUtil.run(new Runnable() {
            public void run() {
                // 添加浏览记录
                try {
                    scanHistoryV2Service.addScanHistory(
                            StringUtil.isNullOrEmpty(tempUid) ? null : Long.parseLong(tempUid), acceptData.getDevice(),
                            goodsInfo);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (CommonGoodsException e) {
                    e.printStackTrace();
                } catch (ScanHistoryException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * 淘宝转链
     *
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "gettaobaolink")
    public void getTaobaoLink(AcceptData acceptData, String uid, Long id, PrintWriter out) {
        ClientTBPid clientTBPid = null;
        // 用户已经登录
        if (!StringUtil.isNullOrEmpty(uid)) {
            if (acceptData.getPlatform().equalsIgnoreCase("android")) {
                clientTBPid = tbPidService.getAndroidDefault();
            } else {
                clientTBPid = tbPidService.getIOSDefault();
            }
        } else {
            if (acceptData.getPlatform().equalsIgnoreCase("android"))
                clientTBPid = tbPidService.getAndroidDefault();
            else
                clientTBPid = tbPidService.getIOSDefault();
        }
        JSONObject data = new JSONObject();
        // 是否在服务端进行转链
        boolean convertInServer = configService.isConvertTaoBaoLinkInServer();
        TaoBaoGoodsBrief tb = null;
        JSONObject ticket = new JSONObject();
        if (convertInServer) {
            String appId = clientTBPid.getPid().split("_")[2];
            TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(clientTBPid.getPid().split("_")[3]);
            app.setAppKey(config.getAppKey());
            app.setAppSecret(config.getAppSecret());
            app.setPid(clientTBPid.getPid());
            try {
                tb = TaoKeApiUtil.searchGoodsDetail(id, app);
                if (tb != null) {
                    ticket.put("clickUrl", tb.getAuctionUrl());
                    ticket.put("couponUrl", tb.getCouponLink());
                    data.put("ticket", ticket);
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
        }
        data.put("pidInfo", clientTBPid);
        out.print(JsonUtil.loadTrueResult(data));
    }
    // 根据商品获取推荐
    @RequestMapping(value = "getgoodsrecommend", method = RequestMethod.POST)
    public void getGoodsRecommend(final AcceptData acceptData, long id, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        List<TaoBaoGoodsBrief> goodsList = TaoKeApiUtil.getRelationGoodsRecommend(id, 6);
        if (goodsList == null)
            goodsList = new ArrayList<>();
        if (goodsList == null || goodsList.size() == 0)// 重新做推荐
        {
            TaoBaoGoodsBrief goods = null;
            try {
                goods = redisManager.getTaoBaoGoodsBrief(id);
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
            if (goods == null)// 商品下线
            {
                // 从我们的商品库搜索
                CommonGoods cgoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType(id,
                        CommonGoods.GOODS_TYPE_TB);
                if (cgoods != null) {// 商品有本地缓存
                    // 按名字搜索商品
                    SearchFilter sf = new SearchFilter();
                    sf.setKey(cgoods.getTitle().substring(0, cgoods.getTitle().length() / 2));
                    TaoBaoSearchResult result = TaoBaoUtil.search(sf);
                    if (result != null && result.getTaoBaoGoodsBriefs() != null
                            && result.getTaoBaoGoodsBriefs().size() > 0)
                        for (TaoBaoGoodsBrief gds : result.getTaoBaoGoodsBriefs()) {
                            if (goodsList.size() < 6)
                                goodsList.add(gds);
                        }
                }
            }
        }
        final List<TaoBaoGoodsBrief> recommendGoodsList = new ArrayList<>();
        goodsList.parallelStream().forEach(goods -> {
            // 获取详情
            TaoBaoGoodsBrief taoBaoGoodsBrief = null;
            try {
                taoBaoGoodsBrief = redisManager.getTaoBaoGoodsBrief(goods.getAuctionId());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (taoBaoGoodsBrief != null)
                recommendGoodsList.add(taoBaoGoodsBrief);
        });
        // 取偶数个数据
        if (recommendGoodsList.size() % 2 != 0) {
            recommendGoodsList.remove(recommendGoodsList.size() - 1);
        }
        List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
        BigDecimal proportion = manageService.getFanLiRate();
        if (recommendGoodsList != null)
            for (TaoBaoGoodsBrief taoBaoGoodsBrief : recommendGoodsList) {
                if (taoBaoGoodsBrief == null)
                    continue;
                re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), ""));
            }
        out.print(JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(re)));
    }
    // 上传订单
    @RequestMapping(value = "reportorder", method = RequestMethod.POST)
    public void reportOrder(AcceptData acceptData, String order, String auctionUrl, String money, long uid,
            PrintWriter out, HttpServletRequest request) {
        LogHelper.userOrder("[ip:" + IPUtil.getRemotIP(request) + "],上传的淘宝订单ID:" + order + ",用户ID:" + uid + ",订单金额:"
                + money + ",商品链接:" + auctionUrl);
        if (StringUtil.isNullOrEmpty(order)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传order"));
            LogHelper.userOrder("[ip:" + IPUtil.getRemotIP(request) + "] 上传的订单为空!上传订单失败!");
            return;
        }
        UserInfo user = userInfoService.getUserById(uid);
        if (user == null) {
            out.print(JsonUtil.loadFalseResult(1, "请上传uid"));
            LogHelper.userOrder("[ip:" + IPUtil.getRemotIP(request) + "] 用户不存在!上传订单失败!");
            return;
        }
        order = order.replace("[", "").replace("]", "");
        String[] orderArr = order.split(",");
        for (String tbOrder : orderArr) {
            Order or = new Order();
            or.setBeizhu("接口添加");
            or.setCreatetime(java.lang.System.currentTimeMillis());
            or.setDrawbackTime(0L);
            or.setOrderId(tbOrder.trim());
            or.setOrderType(1);
            or.setState(1);
            or.setUserInfo(new UserInfo(uid));
            or.setVersion(2);
            boolean b;
            try {
                b = orderService.addOrder(or);
            } catch (Exception e) {
                e.printStackTrace();
                b = false;
            }
            if (b) {
                LogHelper.userOrder("用户ID" + uid + "下单成功!订单ID[" + or.getOrderId() + "]");
            } else {
                LogHelper.userOrder("用户ID" + uid + "下单失败!订单ID[" + or.getOrderId() + "]");
            }
        }
        out.print(JsonUtil.loadTrueResult("上报成功"));
        return;
    }
    // 获取浏览记录
    @RequestMapping(value = "getscanhistory", method = RequestMethod.POST)
    public void getScanHistory(AcceptData acceptData, String uid, int page, PrintWriter out) {
        if (page < 0) {
            out.print(JsonUtil.loadFalseResult(1, "page不小于0"));
            return;
        }
        page = page + 1;
        BusinessSystem sys = businessSystemService.getBusinessSystem(acceptData.getPlatform(),
                acceptData.getPackages());
        if (sys == null) {
            out.print(JsonUtil.loadFalseResult(1, "不存在该系统"));
            return;
        }
        List<ScanHistoryV2> list = scanHistoryV2Service.getScanHistoryByDeviceOrUid(
                StringUtil.isNullOrEmpty(uid) ? null : Long.parseLong(uid), acceptData.getDevice(), page, 20);
        long count = scanHistoryV2Service.getCountByDeviceOrUid(
                StringUtil.isNullOrEmpty(uid) ? null : Long.parseLong(uid), acceptData.getDevice());
        JSONObject data = new JSONObject();
        data.put("count", count);
        JSONArray array = new JSONArray();
        GsonBuilder gsonBuilder = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder());
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                if (value == null) {
                    return new JsonPrimitive("");
                } else {
                    return new JsonPrimitive(value.getTime() + "");
                }
            }
        });
        Gson gson = gsonBuilder.create();
        if (list != null) {
            BigDecimal proportion = manageService.getFanLiRate();
            for (ScanHistoryV2 sh : list) {
                TaoBaoGoodsBrief goods = TaoBaoUtil.convert(sh.getCommonGoods());
                goods.setId(sh.getId());
                TaoBaoGoodsBriefExtra extra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goods, proportion.toString(), "");
                extra.setCreatetime(sh.getCreateTime());
                array.add(gson.toJson(extra));
            }
        }
        data.put("data", array);
        out.print(JsonUtil.loadTrueResult(data));
        return;
    }
    @RequestMapping(value = "deletescanhistory", method = RequestMethod.POST)
    public void deleteScanHistory(AcceptData acceptData, String type, String uid, String ids, PrintWriter out) {
        BusinessSystem sys = businessSystemService.getBusinessSystem(acceptData.getPlatform(),
                acceptData.getPackages());
        if (sys == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        if ("0".equals(type)) {
            String[] idStr = ids.split(",");
            for (String auctionIdStr : idStr) {
                scanHistoryV2Service.deleteByAuctionIdAndDeviceOrUid(
                        StringUtil.isNullOrEmpty(uid) ? null : Long.parseLong(uid), acceptData.getDevice(),
                        Long.parseLong(auctionIdStr));
            }
        } else {
            scanHistoryV2Service.deleteByDeviceOrUid(StringUtil.isNullOrEmpty(uid) ? null : Long.parseLong(uid),
                    acceptData.getDevice());
        }
        out.print(JsonUtil.loadTrueResult(""));
        return;
    }
    // 根据原链接获取推广链接
    @RequestMapping(value = "getTaoBaoLink", method = RequestMethod.POST)
    public void getTaoBaoLink(AcceptData acceptData, String url, PrintWriter out) {
        if (!url.contains("//detail.m.tmall.com/item.htm") && !url.contains("h5.m.taobao.com/awp/core/detail.htm")
                && !url.contains("item.taobao.com/item.htm")) {
            out.print(JsonUtil.loadFalseResult(1, "链接错误"));
            return;
        }
        String params = url.split("\\?")[1];
        String[] ps = params.split("&");
        String id = "";
        for (String st : ps) {
            if (st.contains("id=")) {
                id = st.replace("id=", "");
                break;
            }
        }
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "商品ID错误"));
            return;
        }
        /**
         * 防止请求频率过高
         *
         */
        if (Constant.IS_OUTNET) {
            String key = "linkParse-" + acceptData.getDevice() + "-" + id;
            String value = redisManager.getCommonString(key);
            if (!StringUtil.isNullOrEmpty(value)) {
                out.print(JsonUtil.loadFalseResult(11, "请求频率限制"));
                return;
            }
            redisManager.cacheCommonString(key, "1", 5);// 5s间隔
        }
        TaoBaoGoodsBrief goods = null;
        try {
            goods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(id));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (TaobaoGoodsDownException e) {
            e.printStackTrace();
        }
        if (goods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("id", id);
        out.print(JsonUtil.loadTrueResult(data));
        return;
    }
    /**
     * 根据设备信息获取猜你喜欢的内容
     *
     * @param acceptData
     * @param imei
     *            -Android的IMEI信息
     * @param idfa
     *            -IOS的idfa广告标识信息
     */
    @RequestMapping(value = "guessLikeByDevice")
    public void guessUserLikeByDevice(AcceptData acceptData, String imei, String idfa, int page,
            HttpServletRequest request, PrintWriter out) {
        int pageSize = Constant.PAGE_SIZE;
        JSONArray array = new JSONArray();
        Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
        // 从推荐来
        if (page <= 1) {
            array.clear();
            BigDecimal proportion = manageService.getFanLiRate();
            if (!StringUtil.isNullOrEmpty(imei) || !StringUtil.isNullOrEmpty(idfa)) {
                long startTime = java.lang.System.currentTimeMillis();
                TaoBaoSearchResult result = TaoKeApiUtil.guessDeviceLike(page, 50, imei, idfa);
                if (result != null && result.getTaoBaoGoodsBriefs() != null) {
                    // 筛选
                    List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
                    for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) {
                        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && goods.getCouponAmount() != null
                                && goods.getCouponAmount().compareTo(new BigDecimal("5")) >= 0
                                && goods.getBiz30day() > 1000 && !StringUtil.isNullOrEmpty(goods.getPictUrlWhite()))
                            goodsList.add(goods);
                    }
                    try {
                        monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0,
                                (int) (java.lang.System.currentTimeMillis() - startTime), "推荐数量:" + goodsList.size()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Collections.shuffle(goodsList);
                    goodsList = goodsList.size() > 20 ? goodsList.subList(0, 20) : goodsList;
                    for (TaoBaoGoodsBrief goods : goodsList) {
                        array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goods, proportion.toString(), "")));
                    }
                } else {
                    try {
                        monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0,
                                (int) (java.lang.System.currentTimeMillis() - startTime), "无推荐"));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            JSONArray localArray = qualityGoodsService.getRecommendToIndex((page - 1) * pageSize, pageSize,
                    proportion.toString());
            array.addAll(localArray);
        } else {// 从精选库来
            BigDecimal proportion = manageService.getFanLiRate();
            array = qualityGoodsService.getRecommendToIndex((page - 1) * pageSize, pageSize, proportion.toString());
            if (array == null) {
                out.print(JsonUtil.loadFalseResult("没有更多了"));
                return;
            }
        }
        JSONObject data = new JSONObject();
        data.put("data", array);
        data.put("count", 1000);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 获取首页推荐信息
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getRecommendInfo")
    public void getRecommendHomeInfo(AcceptData acceptData, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        // 首页Banner
        List<RecommendBannerV2> listBanner = superRecommendBannerV2Service
                .getSuperRecommendBannerV2sBySystem(system.getId());
        JSONObject root = new JSONObject();
        root.put("banner", listBanner);
        List<Special> honestList = null;
        List<Special> specialList = null;
        Special miaoShaSpecial = new Special();
        // 首页推荐专题
        List<SuperSpecial> listSuper = superSpecialService.listBySystemAndCardCache(system.getId(), "index");
        if (listSuper != null && listSuper.size() > 0) {
            honestList = new ArrayList<Special>();
            specialList = new ArrayList<Special>();
            for (int i = 0; i < listSuper.size(); i++) {
                Special special = listSuper.get(i).getSpecial();
                special.setCreatetime(null);
                special.setUpdatetime(null);
                if ("限时秒杀".equals(special.getName())) {
                    miaoShaSpecial = special;
                    continue;
                }
                if (i < 5) {
                    // 5大专题
                    honestList.add(special);
                } else {
                    // 其他专题
                    specialList.add(special);
                }
            }
        }
        root.put("honest", honestList);
        root.put("special", specialList);
        /* 限时秒杀 - 时间处理 */
        JSONObject msJSON = JSONObject.fromObject(new Gson().toJson(miaoShaSpecial));
        // 获取秒杀
        int[] hours = new int[] { 0, 9, 12, 14, 16, 20, 22 };
        int hour = -1;
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(Long.parseLong(acceptData.getTime()));
        int nowHour = calendar.get(Calendar.HOUR_OF_DAY);
        for (int i = 0; i < hours.length - 1; i++) {
            if (nowHour >= hours[i] && nowHour < hours[i + 1]) {
                hour = hours[i + 1];
                break;
            }
        }
        if (hour < 0)
            hour = 24;
        long time = TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(calendar.getTimeInMillis(), "yyyy-MM-dd"),
                "yyyy-MM-dd") + 1000 * 60 * 60 * hour;
        msJSON.put("time", time);
        root.put("miaoSha", msJSON);
        out.print(JsonUtil.loadTrueResult(root));
    }
    /**
     * 新版推荐专题管理(1.4.0)
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getNewRecommendInfo")
    public void getNewRecommendInfo(AcceptData acceptData, Long uid, String specialCard, String swiperCard,
            PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        List<SwiperPicture> listswiper = null;
        if (!StringUtil.isNullOrEmpty(specialCard)) {
            try {
                listswiper = swiperPictureService.getByBannerCard(swiperCard);
                if (listswiper == null) {
                    listswiper = new ArrayList<SwiperPicture>();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Special miaoShaSpecial = null;
        List<Special> honestList = new ArrayList<Special>();
        List<Special> specialList = new ArrayList<Special>();
        if (!StringUtil.isNullOrEmpty(specialCard)) {
            try {
                List<Special> listSpecial = specialService.listBySystemAndCard(specialCard, system.getId());
                if (listSpecial != null && listSpecial.size() > 0) {
                    for (Special special : listSpecial) {
                        if ("限时秒杀".equals(special.getName())) {
                            miaoShaSpecial = special;
                            continue;
                        }
                        if ("arc".equals(special.getShowType())) {
                            // 同一行专题
                            honestList.add(special);
                        } else {
                            // 其他专题
                            specialList.add(special);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        /* 限时秒杀 - 时间处理 */
        JSONObject msJSON = JSONObject.fromObject(new Gson().toJson(miaoShaSpecial));
        if (miaoShaSpecial != null) {
            // 获取秒杀
            int[] hours = new int[] { 0, 9, 12, 14, 16, 20, 22 };
            int hour = -1;
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(Long.parseLong(acceptData.getTime()));
            int nowHour = calendar.get(Calendar.HOUR_OF_DAY);
            for (int i = 0; i < hours.length - 1; i++) {
                if (nowHour >= hours[i] && nowHour < hours[i + 1]) {
                    hour = hours[i + 1];
                    break;
                }
            }
            if (hour < 0)
                hour = 24;
            long time = TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(calendar.getTimeInMillis(), "yyyy-MM-dd"),
                    "yyyy-MM-dd") + 1000 * 60 * 60 * hour;
            msJSON.put("time", time);
        }
        JSONObject root = new JSONObject();
        root.put("banner", JsonUtil.getApiCommonGson().toJson(listswiper));
        root.put("honest", JsonUtil.getApiCommonGson().toJson(honestList));
        root.put("special", JsonUtil.getApiCommonGson().toJson(specialList));
        root.put("miaoSha", msJSON);
        // 增加邀请有奖
        JSONObject invite = new JSONObject();
        JumpDetailV2 jumpDetail = jumpDetailV2Service.getByTypeCache("invite");
        invite.put("jumpDetail", jumpDetail);
        invite.put("picture", configService.get("home_invite_banner"));
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())
                && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
            // 如果IOS当前版本处于审核状态就不返回
        } else {
            // 按照版本返回,版本覆盖足够后可删除
            if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 30)
                    || ("ios".equalsIgnoreCase(acceptData.getPlatform())
                            && Integer.parseInt(acceptData.getVersion()) > 37)) {
                if (uid != null) {
                    try {
                        UserSettingsVO vo = userCustomSettingsService.getMySettings(uid);
                        if (vo == null || vo.getNoInvitationBonus() == null || vo.getNoInvitationBonus() == 0)// 没有关闭邀请
                            root.put("invite", invite);
                    } catch (UserCustomSettingsException e) {
                        e.printStackTrace();
                    }
                } else
                    root.put("invite", invite);
            }
        }
        out.print(JsonUtil.loadTrueResult(root));
    }
    /**
     * 新版推荐专题管理(1.5.3)
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getRecommendIndex")
    public void getRecommendIndex(AcceptData acceptData, Long uid, PrintWriter out) {
        try {
            // 1、专题模块
            JSONObject root = specialService.listCacheSpecialToIndex(acceptData);
            // 2、顶部轮播图
            List<SwiperPicture> topPicList = getSwiperByCard("index_top");
            if (topPicList == null) {
                topPicList = new ArrayList<SwiperPicture>();
            }
            root.put("topPicList", JsonUtil.getApiCommonGson().toJson(topPicList));
            // 3、邀请有奖
            List<SwiperPicture> invitePicList = null;
            if ("ios".equalsIgnoreCase(acceptData.getPlatform())
                    && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
                // 如果IOS当前版本处于审核状态就不返回
            } else {
                invitePicList = getSwiperByCard("index_invite");
            }
            if (invitePicList == null) {
                invitePicList = new ArrayList<SwiperPicture>();
            }
            root.put("invitePicList", JsonUtil.getApiCommonGson().toJson(invitePicList));
            // 4、IOS的底部网页链接
            String platform = acceptData.getPlatform();
            if ("ios".equalsIgnoreCase(platform)) {
                root.put("htmlLink", configService.get("index_html_link_ios"));
            }
            root.put("spikeGoods",  getSpikeGoodsContent(acceptData));
            out.print(JsonUtil.loadTrueResult(root));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "获取数据失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
    /**
     * 邀请有奖是否需要返回
     *
     * @param uid
     * @param acceptData
     * @return
     */
    public List<SwiperPicture> getInvitePicList(Long uid, AcceptData acceptData) {
        // 如果IOS当前版本处于审核状态就不返回
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())
                && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
            return null;
        }
        List<SwiperPicture> invitePicList = getSwiperByCard("index_invite");
        return invitePicList;
    }
    public List<SwiperPicture> getSwiperByCard(String card) {
        List<SwiperPicture> swiperList = null;
        try {
            swiperList = swiperPictureService.getByBannerCard(card);
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        return swiperList;
    }
    private JSONObject getSpikeGoodsContent(AcceptData acceptData) {
        // 下一次倒计时的时间
        int type = qualityFlashSaleService.getNowType() + 1;
        int hour = 0;
        switch (type) {
        case 1:
            hour = 0;
            break;
        case 2:
            hour = 9;
            break;
        case 3:
            hour = 12;
            break;
        case 4:
            hour = 14;
            break;
        case 5:
            hour = 16;
            break;
        case 6:
            hour = 20;
            break;
        case 7:
            hour = 22;
            break;
        default:
            break;
        }
        Calendar nextTime = Calendar.getInstance();
        nextTime.set(Calendar.HOUR_OF_DAY, hour);
        nextTime.set(Calendar.MINUTE, 0);
        nextTime.set(Calendar.SECOND, 0);
        nextTime.set(Calendar.MILLISECOND, 0);
        JSONArray array = null;
        String timekey = "spikeGoods_hour";
        String cachekey = "spikeGoodsList";
        String timeValue = redisManager.getCommonString(timekey);
        if (timeValue == null || !timeValue.equals(hour + "")) {
            redisManager.cacheCommonString(timekey, hour + "", 60 * 30);
        } else {
            String cacheValue = redisManager.getCommonString(cachekey);
            if (!StringUtil.isNullOrEmpty(cacheValue)) {
                array = JSONArray.fromObject(cacheValue);
            }
        }
        if (array == null) {
            array = new JSONArray();
            BigDecimal proportion = manageService.getFanLiRate();
            Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                    .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
            // 缓存中不存在
            List<QualityFactory> listGoods = qualityGoodsService.listFlashSaleRandGoods();
            if (listGoods == null) {
                listGoods = new ArrayList<QualityFactory>();
            }
            /* 遍历列表数据 */
            for (QualityFactory qualityFactory : listGoods) {
                TaoBaoGoodsBrief taoBaoGoodsBrief = qualityFactory.getTaoBaoGoodsBrief();
                if (taoBaoGoodsBrief == null) {
                    continue;
                }
                array.add(gson
                        .toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
            }
            // 缓存半个小时
            redisManager.cacheCommonString(cachekey, array.toString(), 60 * 30);
        }
        Long endTime = nextTime.getTimeInMillis() - java.lang.System.currentTimeMillis();
        JSONObject root = new JSONObject();
        root.put("time", nextTime.getTimeInMillis());
        root.put("endTime", endTime > 0? endTime : 0);
        root.put("listgoods", array);
        return root;
    }
    /**
     * 限时秒杀 1.5.3
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getSpikeGoods")
    public void getSpikeGoods(AcceptData acceptData, PrintWriter out) {
        JSONObject params = new JSONObject();
        params.put("url", configService.get("spike_goods_link"));
        JumpDetailV2 jumpDetail = jumpDetailV2Service.getByTypeCache("web");
        JSONObject root = getSpikeGoodsContent(acceptData);
        root.put("params", params);
        root.put("jumpDetail", jumpDetail);
        out.print(JsonUtil.loadTrueResult(root));
    }
    /**
     * 商品基本详情 (1.4.0)
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param pageSource
     *            页面来源
     * @param out
     */
    @RequestMapping(value = "getgoodsinfo", method = RequestMethod.POST)
    public void getGoodsInfo(AcceptData acceptData, String id, String uid, String from, PrintWriter out) {
        if ("0".equalsIgnoreCase(uid)) {
            uid = "";
        }
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("invalid", false);
        // IOS是否正在上线
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            String version = acceptData.getVersion();
            data.put("iosOnling", configService.iosOnLining(Integer.parseInt(version)));
        }
        long startTime = java.lang.System.currentTimeMillis();
        // 获取淘客参数
        ClientTBPid clientTBPid = null;
        // 用户未登录
        if (acceptData.getPlatform().equalsIgnoreCase("android")) {
            clientTBPid = tbPidService.getAndroidDefault();
        } else {
            clientTBPid = tbPidService.getIOSDefault();
        }
        LogHelper.test("获取PID耗时:" + (java.lang.System.currentTimeMillis() - startTime));
        final List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        // 是否在服务端进行转链
        boolean convertInServer = configService.isConvertTaoBaoLinkInServer();
        JSONObject ticket = new JSONObject();
        TaoBaoGoodsBrief goods = null;
        if (!convertInServer) {
            try {
                goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(Long.parseLong(id));
                if (goods == null) {
                    TaoKeAppInfo app = new TaoKeAppInfo();
                    app.setAppKey(TaoBaoConstant.TAOBAO_COMMON_APPKEY);
                    app.setAppSecret(TaoBaoConstant.TAOBAO_COMMON_APPSECRET);
                    app.setPid(TaoBaoConstant.TAOBAO_COMMON_PID);
                    app.setAdzoneId(TaoBaoConstant.TAOBAO_COMMON_PID.split("_")[3]);
                    goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
                    final TaoBaoGoodsBrief finalGoods = goods;
                    if (goods != null) {
                        ThreadUtil.run(new Runnable() {
                            @Override
                            public void run() {
                                taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(finalGoods);
                            }
                        });
                    }
                }
            } catch (TaobaoGoodsDownException e) {
                // 商品下架
                ThreadUtil.run(new Runnable() {
                    public void run() {
                        taoBaoGoodsUpdateService.offlineTaoBaoGoods(Long.parseLong(id));
                    }
                });
            }
        } else {
            final String clientPid = clientTBPid.getPid();
            String appId = clientPid.split("_")[2];
            TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(clientPid.split("_")[3]);
            app.setAppKey(config.getAppKey());
            app.setAppSecret(config.getAppSecret());
            app.setPid(clientPid);
            try {
                goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
                if (goods != null) {
                    ticket.put("clickUrl", goods.getAuctionUrl());
                    // 测试使用
                    ticket.put("couponUrl", goods.getCouponLink());
                    data.put("ticket", ticket);
                }
                if (goods.getTkRate() == null || new BigDecimal(0).compareTo(goods.getTkRate()) == 0) {
                    TaoBaoGoodsBrief linkInfo = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app);
                    if (linkInfo != null) {
                        goods.setAuctionUrl(linkInfo.getAuctionUrl());
                        goods.setCouponLink(linkInfo.getCouponLink());
                        goods.setTkRate(linkInfo.getTkRate());
                    }
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
                ThreadUtil.run(new Runnable() {
                    public void run() {
                        taoBaoGoodsUpdateService.offlineTaoBaoGoods(Long.parseLong(id));
                    }
                });
            }
        }
        if (goods != null) {
            goodsList.add(goods);
            final TaoBaoGoodsBrief newGoods = goods;
            ThreadUtil.run(new Runnable() {
                public void run() {
                    try {
                        // 更新商品
                        LogHelper.test("更新商品详情:" + newGoods.getAuctionId());
                        taoBaoGoodsUpdateService.updateTaoBaoGoods(newGoods);
                    } catch (TaobaoGoodsUpdateException e) {
                    }
                }
            });
        }
        TaoBaoGoodsBrief tb = null;
        if (goodsList.size() > 0) {
            tb = goodsList.get(0);
        }
        if (tb == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        if (tb.getImgList() == null) {
            tb.setImgList(new ArrayList<>());
        }
        tb.getImgList().add(0, tb.getPictUrl());
        List<String> finalImgList = new ArrayList<>();
        for (String img : tb.getImgList()) {
            finalImgList.add(TbImgUtil.getTBSizeImg(img, 600));
        }
        if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite()))
            finalImgList.add(0, tb.getPictUrlWhite());
        JSONObject goodsJson = new JSONObject();
        goodsJson.put("auctionId", tb.getAuctionId());
        goodsJson.put("imgList", finalImgList);
        goodsJson.put("title", tb.getTitle());
        goodsJson.put("userType", tb.getUserType() == 1 ? 2 : 1);
        goodsJson.put("price", tb.getReservePrice().toString());
        goodsJson.put("zkPrice", tb.getZkPrice().toString());
        // 30天销量
        goodsJson.put("saleCount", TaoBaoUtil.getSaleCount(tb.getBiz30day()));
        goodsJson.put("salesCount", TaoBaoUtil.getSaleCount(tb.getBiz30day()));
        // 分享赚
        BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb);
        data.put("shareMoney", "¥" + shareMoney);
        // 分享赚人提示
        List<ShamUser> listShareUser = new ArrayList<ShamUser>();
        if (tb.getBiz30day() >= 1000) {
            listShareUser = shamUserService.listRandShareUser(10, shareMoney, 1, 5);
        }
        // 判断收藏
        if (StringUtil.isNullOrEmpty(uid)) {
            data.put("collected", false);
        } else {
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(Long.parseLong(uid),
                    Long.parseLong(id));
            data.put("collected", collectionGoods != null ? true : false);
        }
        // 测试
        SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
                "goods_detail_jump_taobao");
        if ("1".equalsIgnoreCase((params.getValue() + "").trim())) {
            data.put("native", true);
        } else {
            data.put("native", false);
        }
        // 获取PID
        String pid = clientTBPid.getPid();
        LogHelper.test(String.format("PID: uid-%s  pid-%s", uid + "", pid));
        // 是否有券
        goodsJson.put("coupon", StringUtil.isNullOrEmpty(tb.getCouponInfo()) ? false : true);
        // 领券人列表
        List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
        String hongBao = null;
        // 获取券信息
        if (!StringUtil.isNullOrEmpty(tb.getCouponInfo())) {
            BigDecimal quanPrice = TaoBaoUtil.getAfterUseCouplePrice(tb);
            JSONObject couponInfo = new JSONObject();
            couponInfo.put("couponPrice", quanPrice.toString());
            if (from != null && from.equals("miandan")) {
                // 免单商品
                hongBao = "¥" + quanPrice.toString();
            }
            String token = "";
            if (!StringUtil.isNullOrEmpty(tb.getCouponLink())) {
                token = redisManager.getCommonTaoToken(tb.getAuctionId());
                if (StringUtil.isNullOrEmpty(token)) {
                    token = TaoKeApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), tb.getCouponLink());
                    redisManager.saveCommonTaoToken(tb.getAuctionId(), token);
                }
            }
            tb.setCouponLinkTaoToken(token);
            // 服务端转链
            // if (convertInServer &&
            // !StringUtil.isNullOrEmpty(tb.getCouponLink())) {
            couponInfo.put("couponUrl", tb.getCouponLink());
            // } else {
            // couponInfo.put("couponUrl",
            // TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId() + "", pid,
            // tb.getAuctionId() + ""));
            // }
            couponInfo.put("couponAmount", NumberUtil.subZeroAndDot(tb.getCouponAmount().toString()));
            couponInfo.put("couponTime", "使用期限:" + tb.getCouponEffectiveStartTime().replace("-", ".") + "-"
                    + tb.getCouponEffectiveEndTime().replace("-", "."));
            // 券的口令
            couponInfo.put("couponToken", token);
            goodsJson.put("couponInfo", couponInfo);
            if (tb.getBiz30day() >= 1000) {
                // 领券人列表
                listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
            }
        }
        // 红包
        if (hongBao == null) {
            BigDecimal proportion = manageService.getFanLiRate();
            hongBao = TaoBaoUtil.getGoodsHongBaoInfo(tb, proportion);
        }
        goodsJson.put("hongBao", hongBao);
        List<ClientTextStyleVO> labels = new ArrayList<>();
        goodsJson.put("labels", labels);
        data.put("tbPidInfo", clientTBPid);
        String jumpUrl = "https://item.taobao.com/item.htm?id=" + tb.getAuctionId();
        if (!StringUtil.isNullOrEmpty(tb.getCouponActivityId())) {// 有券,跳转券链接
            jumpUrl = TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), clientTBPid.getPid(),
                    "" + tb.getAuctionId());
        }
        // 设置跳转链接
        if (convertInServer) {
            if (!StringUtil.isNullOrEmpty(tb.getCouponLink()))
                jumpUrl = tb.getCouponLink();
            else
                jumpUrl = tb.getAuctionUrl();
        }
        goodsJson.put("jumpUrl", jumpUrl);
        TaoBaoShopInfo tbShopInfo = redisManager.getTBShopInfo(tb.getShopTitle(), tb.getSellerId(), tb.getAuctionId());
        if (tbShopInfo != null) {
            String shopType = tbShopInfo.getShopType();
            if (!StringUtil.isNullOrEmpty(shopType) && shopType.contains("tm.png")) {
                tbShopInfo.setUserType("1");
            } else {
                tbShopInfo.setUserType("0");
            }
        }
        // 店铺
        if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) >= 40)
                || ("ios".equalsIgnoreCase(acceptData.getPlatform())
                        && Integer.parseInt(acceptData.getVersion()) >= 49)) {
            TaoBaoShop shop = taoBaoShopService.getTaoBaoShop(goods.getAuctionId(), goods.getSellerId());
            if (shop != null)
                goodsJson.put("shopInfo", shop);
        } else {
            goodsJson.put("shopInfo", tbShopInfo);
        }
        goodsJson.put("fanliValid",true);// 是否有返利
        // 分享路径
        String shareUrl = String.format("%s?id=" + tb.getAuctionId(), Constant.systemCommonConfig.getAppShareInfoUrl());
        // 是否加入选品库: 0未加入 1 已加入
        boolean storageState = false;
        if (uid != null && uid.trim().length() > 0) {
            storageState = userGoodsStorageService.isExistStorage(Long.parseLong(uid), Long.parseLong(id));
        }
        data.put("storageState", storageState);
        data.put("shareUrl", shareUrl);
        data.put("goods", goodsJson);
        data.put("shareUsers", listShareUser);
        data.put("couponUsers", listCouponUser);
        data.put("detailWebUrl", "http://apph5.yeshitv.com/apppage/goods_img.html?id=" + id);
        data.put("noRebateHelpLink", configService.get("no_rebate_help_link"));
        // 商品链接
        String h5Url = String.format("http://%s%s?id=%s&appType=flq", configService.getH5Host(),
                Constant.systemCommonConfig.getShareGoodsPagePath(), tb.getAuctionId() + "");
        try {
            data.put("h5Url", HttpUtil.getShortLink(h5Url));
        } catch (Exception e) {
            data.put("h5Url", h5Url);
        }
        // 取消分享活动
        // if (!StringUtil.isNullOrEmpty(uid)
        // &&
        // shareGoodsActivityOrderService.countShareGoodsActivityOrder(Long.parseLong(uid))
        // > 0) {
        // } else if(!"miandan".equals(from)) {
        // // 非免单商品
        // JSONObject shareActivity = new JSONObject();
        // shareActivity.put("moneyDesc", "春节狂欢奖金:¥" +
        // TaoBaoUtil.getGoodsHongBaoMoney(tb,
        // new
        // BigDecimal(hongBaoManageService.get("share_activity_proportion"))));
        // shareActivity.put("ruleDescPicture",
        // "http://img.flqapp.com/resource/share_activity_img.png");
        //
        // data.put("shareActivity", shareActivity);
        // }
        out.print(JsonUtil.loadTrueResult(data));
        final String tempUid = uid;
        final TaoBaoGoodsBrief goodsInfo = tb;
        ThreadUtil.run(new Runnable() {
            public void run() {
                // 添加浏览记录
                try {
                    scanHistoryV2Service.addScanHistory(
                            StringUtil.isNullOrEmpty(tempUid) ? null : Long.parseLong(tempUid), acceptData.getDevice(),
                            goodsInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * 获取图文详情(1.4.0)
     *
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "getgoodsdetailimgs", method = RequestMethod.POST)
    public void getgoodsdetailimgs(AcceptData acceptData, String id, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        List<String> detailImgs = new ArrayList<>();
        JSONArray detailImgsSize = new JSONArray();
        List<ImageInfo> imgs = redisManager.getTaoBaoGoodsDetailImgs(Long.parseLong(id));
        if (imgs != null && imgs.size() > 0) {
            for (ImageInfo imgInfo : imgs) {
                detailImgs.add(imgInfo.getPicture());
            }
            for (ImageInfo imgInfo : imgs) {
                if (imgInfo.getWidth() <= 0) {
                    detailImgsSize.clear();
                    break;
                }
                JSONObject size = new JSONObject();
                size.put("w", imgInfo.getWidth());
                size.put("h", imgInfo.getHeight());
                detailImgsSize.add(size);
            }
        }
        JSONObject data = new JSONObject();
        data.put("detailImgs", detailImgs);
        data.put("detailImgsSize", detailImgsSize);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 商品详情推荐1.4.0
     *
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "getgoodsderivation", method = RequestMethod.POST)
    public void getRecommendGoods(AcceptData acceptData, long id, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        List<TaoBaoGoodsBrief> goodsList = TaoKeApiUtil.getRelationGoodsRecommend(id, 10);
        // 初始化
        if (goodsList == null) {
            goodsList = new ArrayList<TaoBaoGoodsBrief>();
        }
        BigDecimal proportion = manageService.getFanLiRate();
        List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        app.setAdzoneId(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
        app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
        List<Long> ids = new ArrayList<>();
        for (TaoBaoGoodsBrief goods : goodsList)
            ids.add(goods.getAuctionId());
        try {
            goodsList = TaoKeApiUtil.getBatchGoodsInfo(ids);
        } catch (TaoKeApiException e1) {
            e1.printStackTrace();
        } catch (TaobaoGoodsDownException e1) {
            e1.printStackTrace();
        }
        if (goodsList != null)
            goodsList.parallelStream().forEach(goods -> {
                // 获取详情
                TaoBaoGoodsBrief taoBaoGoodsBrief = null;
                try {
                    taoBaoGoodsBrief = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goods.getAuctionId());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (taoBaoGoodsBrief == null) {
                    TaoBaoGoodsBrief newGoods = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app);
                    goods.setCouponInfo(newGoods.getCouponInfo());
                    goods.setCouponLink(newGoods.getCouponLink());
                    goods.setTkRate(newGoods.getTkRate());
                    taoBaoGoodsBrief = goods;
                }
                if (taoBaoGoodsBrief != null) {
                    listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), ""));
                }
            });
        List<TaoBaoGoodsBrief> listQuality = new ArrayList<TaoBaoGoodsBrief>();
        // 删除推荐
        //
        // try {
        // List<QualityFactory> listRecommend =
        // qualityGoodsService.recommendByAuctionId(id);
        //
        // if (listRecommend != null && listRecommend.size() > 1) {
        // for (QualityFactory quality : listRecommend) {
        //
        // TaoBaoGoodsBrief taoBaoGoodsBrief = quality.getTaoBaoGoodsBrief();
        // if (taoBaoGoodsBrief == null) {
        // continue;
        // }
        //
        // int biz30day = taoBaoGoodsBrief.getBiz30day();
        // if (biz30day >= 10000) {
        // double sales = biz30day;
        // String salesCountMidea = String.format("%.1f", sales / 10000);
        // taoBaoGoodsBrief.setSalesCount(salesCountMidea + "万");
        // } else {
        // taoBaoGoodsBrief.setSalesCount(biz30day + "");
        // }
        //
        // // 改变图片尺寸
        // String pictUrl = taoBaoGoodsBrief.getPictUrl();
        // if (!StringUtil.isNullOrEmpty(pictUrl) &&
        // !pictUrl.contains("320x320")) {
        // taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
        // }
        //
        // listQuality.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
        // proportion.toString(), null));
        // }
        // }
        // } catch (Exception e2) {
        // e2.printStackTrace();
        // }
        // 取偶数个数据
        if (listExtra.size() % 2 != 0) {
            listExtra.remove(listExtra.size() - 1);
        }
        if (listQuality.size() % 2 != 0) {
            listQuality.remove(listQuality.size() - 1);
        }
        JSONObject data = new JSONObject();
        data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listExtra));
        data.put("listGuess", JsonUtil.getApiCommonGson().toJson(listQuality));
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 活动列表
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getSpecialActivities")
    public void getSpecialActivities(AcceptData acceptData, Long uid, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
            return;
        }
        try {
            // 专题活动
            String specialCard = "special_activities";
            List<Special> listSpecial = specialService.listPageBySystemAndCard(0, Integer.MAX_VALUE, specialCard,
                    system.getId());
            if (listSpecial == null) {
                listSpecial = new ArrayList<Special>();
            }
            JSONObject root = new JSONObject();
            root.put("special", JsonUtil.getApiCommonGson().toJson(listSpecial));
            out.print(JsonUtil.loadTrueResult(root));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/S11Controller.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/S11Controller.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SMSController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/SMSController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SearchController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java
New file
@@ -0,0 +1,838 @@
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.yeshi.fanli.dto.share.ShareInfoDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.dynamic.DynamicInfo;
import com.yeshi.fanli.entity.dynamic.GoodsPicture;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoLink;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.ShareGoodsException;
import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.monitor.MonitorService;
import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.MonitorFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller(value = "ShareController1")
@RequestMapping("api/v1/share")
public class ShareController {
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private ConfigService configService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private MonitorService monitorService;
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
    @Resource
    private RedisManager redisManager;
    @Resource
    private ShareGoodsTextTemplateService shareGoodsTextTemplateService;
    @Resource
    private SystemClientParamsService systemClientParamsService;
    @Resource
    private DynamicInfoService dynamicInfoService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private SpreadUserImgService spreadUserImgService;
    // 获取商品分享链接
    @RequestMapping(value = "getGoodsShareUrl")
    public void getGoodsShareUrl(AcceptData acceptData, long id, PrintWriter out) {
        out.print(JsonUtil
                .loadTrueResult(String.format("%s?id=" + id, Constant.systemCommonConfig.getAppShareInfoUrl())));
    }
    /**
     * 获取淘宝的分享链接
     *
     * @param acceptData
     * @param uid
     *            -用户ID
     * @param auctionId-商品ID
     * @param out
     */
    @RequestMapping(value = "gettaobaosharelink")
    public void getTaobaoShareLink(AcceptData acceptData, Long uid, Long auctionId, HttpServletRequest request,
            PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
            return;
        }
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            return;
        }
        if (auctionId == null || auctionId <= 0) {
            out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
            return;
        }
        UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
        try {
            String relationId = null;
            if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                    && extraInfo.getRelationValid() == true)
                relationId = extraInfo.getRelationId();
            TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId);
            JSONObject data = new JSONObject();
            String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    auctionId + "");
            String shortLink = HttpUtil.getShortLink(url);
            if (!StringUtil.isNullOrEmpty(shortLink)) {
                url = shortLink;
            }
            data.put("clickUrl", url);
            data.put("token", taoBaoLink.getTaoToken());
            data.put("rule",
                    "http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
            data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
            String shareText = "";
            // 无券
            String shopType = taoBaoLink.getGoods().getUserType() == 0 ? "淘宝价" : "天猫价";
            if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
                String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.get("goods_share_text_nocoupon");
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            } else// 有券
            {
                String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.get("goods_share_text_coupon");
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                        .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                        .replace("{优惠券面额}",
                                MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                        .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + "");
            }
            shareText = shareText.replace("{店铺类型}", shopType)
                    .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
                    .replace("{领券短链}", shortLink).replace("{淘口令}", taoBaoLink.getTaoToken());
            data.put("shareText", shareText);
            String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
            if (descText.startsWith("\\r\\n"))
                descText = descText.substring(0);
            data.put("descText", descText);
            //
            String imgs = configService.get("goods_share_notify_imgs");
            JSONArray array = JSONArray.fromObject(imgs);
            int p = (int) (array.size() * Math.random());
            if (p < array.size())
                data.put("notifyPicture", array.optString(p));
            data.put("notifyDesc", configService.get("goods_share_notify"));
            // 添加分享记录
            BigDecimal rate = hongBaoManageService.getShareRate();
            BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
            data.put("shareMoney", "¥" + shareMoney.toString());
            data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
            out.print(JsonUtil.loadTrueResult(data));
            // 异步操作
            com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
                @Override
                public void run() {
                    //异步操作 添加分享记录
                    UserShareGoodsHistory history = new UserShareGoodsHistory();
                    history.setUser(new UserInfo(uid));
                    history.setHongbao(shareMoney);
                    history.setCreateTime(new Date());
                    history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
                    history.setTkCode(taoBaoLink.getTaoToken());
                    history.setLink(taoBaoLink.getClickUrl());
                    history.setQuanLink(taoBaoLink.getCouponLink());
                    history.setGoodsId(taoBaoLink.getGoods().getAuctionId());
                    history.setPostPicture(taoBaoLink.getGoods().getPictUrl());
                    List<String> imgList = taoBaoLink.getGoods().getImgList();
                    if (imgList == null) {
                        imgList = new ArrayList<>();
                    }
                    history.setPictures(JsonUtil.getGson().toJson(imgList));
                    shareGoodsService.addShareGoodsHistory(history);
                }
            });
            return;
        } catch (UserShareGoodsRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (ShareGoodsException e) {
            try {
                monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
            } catch (Exception e1) {
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
        }
    }
    /**
     * 分享记录统计列表
     *
     * @param acceptData
     * @param page
     *            初始1
     * @param uid
     * @param source
     * @param out
     */
    @RequestMapping(value = "getlistrecord", method = RequestMethod.POST)
    public void getListRecord(AcceptData acceptData, Integer page, Long uid, String source, PrintWriter out) {
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult("页码不正确"));
        }
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult("用户未登录"));
        }
        if ("all".equals(source)) {
            source = null;// 查询全部
        }
        try {
            int pageSize = Constant.PAGE_SIZE;
            JSONObject data = new JSONObject();
            List<UserShareGoodsRecord> list = new ArrayList<UserShareGoodsRecord>();
            long count = userShareGoodsRecordService.countQueryByUid(uid, source);
            if (count > 0) {
                list = userShareGoodsRecordService.getMyShareGoodsRecords((page - 1) * pageSize, pageSize, uid, source);
            }
            data.put("count", count);
            data.put("result_list", list);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 获取分享商品
     *
     * @param acceptData
     * @param recordId
     * @param out
     */
    @RequestMapping(value = "getrecordgoods", method = RequestMethod.POST)
    public void getRecordGoods(AcceptData acceptData, Long recordId, PrintWriter out) {
        if (recordId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
        try {
            JSONObject data = userShareGoodsRecordService.getGoodsGroup(recordId);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 获取分享商品单个统计信息
     *
     * @param acceptData
     * @param groupId
     * @param out
     */
    @RequestMapping(value = "getgoodsdata", method = RequestMethod.POST)
    public void getGoodsData(AcceptData acceptData, Long groupId, PrintWriter out) {
        if (groupId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
        try {
            UserShareGoodsGroup userShareGoodsGroup = userShareGoodsGroupService.selectByPrimaryKey(groupId);
            if (userShareGoodsGroup != null) {
                userShareGoodsGroup.setBrowseTime(null);
                userShareGoodsGroup.setCreateTime(null);
                userShareGoodsGroup.setUpdateTime(null);
                userShareGoodsGroup.setRecordId(null);
            }
            JSONObject data = new JSONObject();
            data.put("goodsData", userShareGoodsGroup);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 商品详情分享
     *
     * @param acceptData
     * @param uid
     *            用户id
     * @param auctionId
     *            商品id
     * @param type
     *            图片分享类型 单图single 多图many
     * @param out
     */
    @RequestMapping(value = "sharedetail", method = RequestMethod.POST)
    public void shareDetail(AcceptData acceptData, Long uid, Long auctionId, String type, PrintWriter out) {
        try {
            userShareGoodsRecordService.saveDetail(uid, auctionId, type);
            out.print(JsonUtil.loadTrueResult("分享成功"));
        } catch (UserShareGoodsRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 更新分享记录
     *
     * @param acceptData
     * @param shareId
     * @param out
     */
    @RequestMapping(value = "updaterecord", method = RequestMethod.POST)
    public void updateRecord(AcceptData acceptData, Long shareId, PrintWriter out) {
        if (shareId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
        try {
            userShareGoodsRecordService.updateShareRecord(shareId);
            out.print(JsonUtil.loadTrueResult(""));
        } catch (UserShareGoodsRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 预览分享模板
     *
     * @param acceptData
     * @param uid
     * @param template
     * @param goodsId
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "viewShareTextTemplate", method = RequestMethod.POST)
    public void preViewShareTextTemplate(AcceptData acceptData, Long uid, String template, Long goodsId,
            Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (goodsId == null) {
            out.print(JsonUtil.loadFalseResult(3, "商品ID不能为空"));
            return;
        }
        TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId);
        if (goods == null)
            try {
                goods = redisManager.getTaoBaoGoodsBrief(goodsId);
            } catch (TaobaoGoodsDownException e) {
                goods = null;
            }
        if (goods == null) {
            out.print(JsonUtil.loadFalseResult(4, "商品已下架"));
            return;
        }
        if (StringUtil.isNullOrEmpty(template))
            template = getShareTemplate(uid, hasCoupon);
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            try {
                shareGoodsTextTemplateService.isCouponTemplateRight(template);
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
        // 查询是否有分享
        UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId());
        String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
                Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                goods.getAuctionId() + "");
        String shortLink = HttpUtil.getShortLink(url);
        String token = "";
        if (userShareHistory != null) {
            token = userShareHistory.getTkCode();
        }
        if (StringUtil.isNullOrEmpty(token)) {
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
            app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
            app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
            app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT);
            TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app);
            if (goodsLink != null)
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                        StringUtil.isNullOrEmpty(goodsLink.getCouponLink()) ? goodsLink.getAuctionUrl()
                                : goodsLink.getCouponLink());
        }
        String content = shareGoodsTextTemplateService.createContentByTemplate(template, uid, goods, token, shortLink,
                hasCoupon);
        JSONObject data = new JSONObject();
        data.put("content", content);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 保存模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param template
     * @param out
     */
    @RequestMapping(value = "saveShareTextTemplate", method = RequestMethod.POST)
    public void saveShareTextTemplate(AcceptData acceptData, Long uid, Boolean hasCoupon, String template,
            PrintWriter out) {
        if (StringUtil.isNullOrEmpty(template)) {
            out.print(JsonUtil.loadFalseResult(1, "分享模板为空"));
            return;
        }
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            try {
                shareGoodsTextTemplateService.isCouponTemplateRight(template);
                shareGoodsTextTemplateService.saveCouponTemplate(uid, template);
                out.print(JsonUtil.loadTrueResult(""));
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
                shareGoodsTextTemplateService.saveCommonTemplate(uid, template);
                out.print(JsonUtil.loadTrueResult(""));
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
    }
    /**
     * 还原模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     *            -是否有券
     * @param out
     */
    @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST)
    public void resetShareTextTemplate(AcceptData acceptData, Long uid, Long goodsId, Boolean hasCoupon,
            PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (hasCoupon) {
            shareGoodsTextTemplateService.resetCouponTemplate(uid);
        } else {
            shareGoodsTextTemplateService.resetCommonTemplate(uid);
        }
        if (goodsId != null) {
            preViewShareTextTemplate(acceptData, uid, null, goodsId, hasCoupon, out);
            return;
        }
        out.print(JsonUtil.loadTrueResult(""));
    }
    private String getShareTemplate(Long uid, boolean hasCoupon) {
        if (hasCoupon) {
            String template = shareGoodsTextTemplateService.geteCouponTemplate(uid);
            if (StringUtil.isNullOrEmpty(template))
                template = configService.get("goods_share_text_coupon");
            return template;
        } else {
            String template = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(template))
                template = configService.get("goods_share_text_nocoupon");
            return template;
        }
    }
    /**
     * 获取分享模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplate", method = RequestMethod.POST)
    public void getShareTextTemplate(AcceptData acceptData, Long uid, Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("template", getShareTemplate(uid, hasCoupon));
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 获取分享模板编辑规则
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplateRules", method = RequestMethod.POST)
    public void getShareTextTemplateRules(AcceptData acceptData, PrintWriter out) {
        out.print(JsonUtil.loadTrueResult(configService.get("share_goods_template_rules")));
    }
    /**
     * 查询顶部分类
     * @param acceptData
     * @param page
     * @param cid
     * @param out
     */
    @RequestMapping(value = "shareDynamic", method = RequestMethod.POST)
    public void shareDynamic(AcceptData acceptData, String id, Long uid, PrintWriter out) {
        try {
            if (uid == null || uid <= 0) {
                out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
                return;
            }
            if (StringUtil.isNullOrEmpty(id)) {
                out.print(JsonUtil.loadFalseResult("参数不能为空"));
                return;
            }
            DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
            if (dynamicInfo == null) {
                out.print(JsonUtil.loadFalseResult("该动态信息已不存在"));
                return;
            }
            JSONObject data = new JSONObject();
            // 分类id
            long cid = dynamicInfo.getClassId();
            if (cid == 1) {     // 热销单品
                // 文字内容
                String title ="";
                List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                if (listTitle != null && listTitle.size() > 0) {
                    for (ClientTextStyleVO textStyleVO : listTitle) {
                        title += textStyleVO.getContent();
                    }
                }
                data.put("title", title);
                data.put("content", "我在返利券发现了一个很好的商品,快来看看~");
                // 分享奖金
                ClientTextStyleVO desc = dynamicInfo.getDesc();
                String content = desc.getContent();
                int index = content.indexOf("¥");
                data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())));
                // 商品分享链接
                List<GoodsPicture> imgs2 = dynamicInfo.getImgs();
                GoodsPicture goodsPicture = imgs2.get(0);
                Long auctionId = goodsPicture.getGoods().getAuctionId();
                String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
                        Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                        auctionId + "");
                String shortLink = HttpUtil.getShortLink(url);
                if (!StringUtil.isNullOrEmpty(shortLink)) {
                    url = shortLink;
                }
                data.put("clickUrl", url);
                // 分享提示图片
                String imgs = configService.get("goods_share_notify_imgs");
                JSONArray array = JSONArray.fromObject(imgs);
                int p = (int) (array.size() * Math.random());
                if (p < array.size()) {
                    data.put("notifyPicture", array.optString(p));
                }
                UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
                String relationId = null;
                if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                        && extraInfo.getRelationValid() == true) {
                    relationId = extraInfo.getRelationId();
                }
                TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId);
                data.put("pictUrl", TbImgUtil.getTBSizeImg(goodsPicture.getUrl(), 500));
                // 淘宝口令
                data.put("token", taoBaoLink.getTaoToken());
                // 帮助链接
                data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
                // 分享提醒
                data.put("notifyDesc", configService.get("goods_share_notify"));
                // 分享记录id
                data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
            } else if (cid == 2) {     // 推荐好货
                String picUrl = null;
                List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
                List<GoodsPicture> listImgs = dynamicInfo.getImgs();
                for (GoodsPicture goodsPicture: listImgs) {
                    TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                    listGoods.add(goods);
                    if (picUrl == null) {
                        picUrl = goodsPicture.getUrl();
                    }
                }
                // 文字内容
                String title ="";
                List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                if (listTitle != null && listTitle.size() > 0) {
                    for (ClientTextStyleVO textStyleVO : listTitle) {
                        title += textStyleVO.getContent();
                    }
                }
                data.put("title", title);
                data.put("content", "我在返利券发现了一个很好的商品,快来看看~");
                // 分享奖金
                ClientTextStyleVO desc = dynamicInfo.getDesc();
                String content = desc.getContent();
                int index = content.indexOf("¥");
                data.put("shareMoney", new BigDecimal(content.substring(index + 1 , content.length())));
                // 分享链接
                ShareInfoDTO shareInfo = userShareGoodsRecordService.saveShareRecord(uid,
                        ShareSourceTypeEnum.activity, title, listGoods);
                data.put("shareId", shareInfo.getShareId());
                data.put("clickUrl", shareInfo.getShareUrl());
                data.put("pictUrl", TbImgUtil.getTBSizeImg(picUrl, 500));
                // 帮助链接
                data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
                // 分享提醒
                data.put("notifyDesc", configService.get("goods_share_notify"));
                // 分享提醒语
                String notifyImgs = configService.get("goods_share_notify_imgs");
                JSONArray array = JSONArray.fromObject(notifyImgs);
                int p = (int) (array.size() * Math.random());
                if (p < array.size()) {
                    data.put("notifyPicture", array.optString(p));
                }
            } else if (cid == 4) { // 邀请分享
                String inviteCode = null;
                UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
                if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
                    inviteCode = userInfoExtra.getInviteCode();
                } else {
                    out.print(JsonUtil.loadFalseResult(9001, "邀请码未激活"));
                    return;
                }
                Integer showType = dynamicInfo.getShowType();
                if (showType == 0) {  // 无图分享
                    String title ="";
                    List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                    if (listTitle != null && listTitle.size() > 0) {
                        for (ClientTextStyleVO textStyleVO : listTitle) {
                            title += textStyleVO.getContent();
                        }
                    }
                    title = title.replace("【邀请码】", inviteCode);
                    title = title.replace("【邀请链接】", UserUtil.getInviteShortLink(uid));
                    data.put("title", title);
                } else { // 有图分享
                    // 邀请链接
                    String shortLink = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
                            + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
                    data.put("inviteLink", shortLink);
                    data.put("inviteCode", inviteCode);
                    data.put("helpLink", configService.get("invite_help_link"));
                    // 邀请图片
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    String imgLink = spreadUserImgService.getInviteImg(uid, imgs.get(0).getUrl(), inviteCode);
                    data.put("imgLink", imgLink);
                    //  邀请规则
                    BusinessSystem system = new BusinessSystem();
                    system.setCreatetime(java.lang.System.currentTimeMillis());
                    system.setPlatform(1);
                    system.setId(4L);
                    String key = "inviteRules"; // key值
                    SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key);
                    String valueN = values.getValue();
                    String valueBr = valueN.replace("\n", "<br><br>");
                    data.put("inviteRules", valueBr);
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
            // 更新分享次数
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    Integer shareCount = dynamicInfo.getShareCount();
                    dynamicInfo.setShareCount(shareCount + 1);
                    dynamicInfoService.updateShareCount(dynamicInfo);
                }
            });
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("分享记录失败"));
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SystemClientController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/SystemClientController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserAccountController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserAccountController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserAuthController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserAuthController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserCouponController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserCouponController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserGoodsStorageController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserGoodsStorageController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserInfoController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserInfoController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.IOException;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMoneyController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserMoneyController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.IOException;
import java.io.PrintWriter;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMsgController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserMsgController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.lang.reflect.Type;
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserOrderController.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/controller/client/UserOrderController.java
@@ -1,4 +1,4 @@
package com.yeshi.fanli.controller.client;
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.math.BigDecimal;
fanli/src/main/java/com/yeshi/fanli/controller/xcx/XcxGoodsClassController.java
@@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.controller.client.SearchController;
import com.yeshi.fanli.controller.client.v1.SearchController;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSecondClass;
fanli/src/main/java/com/yeshi/fanli/entity/bus/clazz/GoodsClass.java
@@ -59,6 +59,17 @@
    @Column(name = "cs_state")
    private Integer state;
    
    @Column(name = "sex")
    private Integer sex;//男女  0-部分男女  1-男 2-女
    public Integer getSex() {
        return sex;
    }
    public void setSex(Integer sex) {
        this.sex = sex;
    }
    
    // 点击次数
    private Long countClick = 0l; 
fanli/src/main/java/com/yeshi/fanli/entity/bus/clazz/GoodsSubClass.java
@@ -73,6 +73,39 @@
    @Column(name = "sub_updatetime")
    private Date updatetime; // 创建时间
    @Column(name = "sub_sex")
    private Integer sex;//性别
    @Column(name = "sub_month")
    private String month;//月份
    private GoodsSubClassLabel classLabel;//标签
    public GoodsSubClassLabel getClassLabel() {
        return classLabel;
    }
    public void setClassLabel(GoodsSubClassLabel classLabel) {
        this.classLabel = classLabel;
    }
    public Integer getSex() {
        return sex;
    }
    public void setSex(Integer sex) {
        this.sex = sex;
    }
    public String getMonth() {
        return month;
    }
    public void setMonth(String month) {
        this.month = month;
    }
    private Long countClick = 0l;
    // 关联标签数量
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsClassMapper.xml
@@ -12,18 +12,29 @@
    <result column="orderby" property="orderby" jdbcType="INTEGER"/>
    <result column="createtime" property="createtime" jdbcType="BIGINT"/>
    <result column="ios_click" property="iosClick" jdbcType="BIGINT"/>
    <result column="android_click" property="androidClick" jdbcType="BIGINT"/>
        <result column="android_click" property="androidClick"
            jdbcType="BIGINT" />
    <result column="cs_state" property="state" jdbcType="INTEGER"/>
        <result column="sex" property="sex" jdbcType="INTEGER" />
  </resultMap>
   <sql id="Base_Column_List">id,`name`,picture,`key`,search_param,orderby,createtime,ios_click,android_click,cs_state</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
          select * from yeshi_ec_class where id = #{id,jdbcType=BIGINT}
    <sql id="Base_Column_List">id,`name`,picture,`key`,search_param,orderby,createtime,ios_click,android_click,cs_state,sex
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">select * from yeshi_ec_class where id =
        #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_class where id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_class (id,`name`,picture,url,`key`,search_param,orderby,createtime,ios_click,android_click,cs_state) values (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{url,jdbcType=VARCHAR},#{key,jdbcType=VARCHAR},#{searchParam,jdbcType=VARCHAR},#{orderby,jdbcType=INTEGER},#{createtime,jdbcType=BIGINT},#{iosClick,jdbcType=BIGINT},#{androidClick,jdbcType=BIGINT},#{state,jdbcType=INTEGER})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_class
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_class where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_class
        (id,`name`,picture,url,`key`,search_param,orderby,createtime,ios_click,android_click,cs_state,sex)
        values
        (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{url,jdbcType=VARCHAR},#{key,jdbcType=VARCHAR},#{searchParam,jdbcType=VARCHAR},#{orderby,jdbcType=INTEGER},#{createtime,jdbcType=BIGINT},#{iosClick,jdbcType=BIGINT},#{androidClick,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{sex,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_class
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">id,</if>
      <if test="name != null">`name`,</if>
@@ -36,7 +47,10 @@
      <if test="iosClick != null">ios_click,</if>
      <if test="androidClick != null">android_click,</if>
      <if test="state != null">cs_state,</if>
    </trim>values
            <if test="sex != null">sex,</if>
        </trim>
        values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="name != null">#{name,jdbcType=VARCHAR},</if>
@@ -49,10 +63,23 @@
      <if test="iosClick != null">#{iosClick,jdbcType=BIGINT},</if>
      <if test="androidClick != null">#{androidClick,jdbcType=BIGINT},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="sex != null">#{sex,jdbcType=INTEGER}</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">update yeshi_ec_class set `name` = #{name,jdbcType=VARCHAR},picture = #{picture,jdbcType=VARCHAR},url = #{url,jdbcType=VARCHAR},`key` = #{key,jdbcType=VARCHAR},search_param = #{searchParam,jdbcType=VARCHAR},orderby = #{orderby,jdbcType=INTEGER},createtime = #{createtime,jdbcType=BIGINT},ios_click = #{iosClick,jdbcType=BIGINT},android_click = #{androidClick,jdbcType=BIGINT},cs_state = #{state,jdbcType=INTEGER} where id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">update yeshi_ec_class
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">update
        yeshi_ec_class set `name` = #{name,jdbcType=VARCHAR},picture =
        #{picture,jdbcType=VARCHAR},url = #{url,jdbcType=VARCHAR},`key` =
        #{key,jdbcType=VARCHAR},search_param =
        #{searchParam,jdbcType=VARCHAR},orderby =
        #{orderby,jdbcType=INTEGER},createtime =
        #{createtime,jdbcType=BIGINT},ios_click =
        #{iosClick,jdbcType=BIGINT},android_click =
        #{androidClick,jdbcType=BIGINT},cs_state = #{state,jdbcType=INTEGER}
        ,sex =#{sex,jdbcType=INTEGER} where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">
        update yeshi_ec_class
    <set>
      <if test="name != null">`name`=#{name,jdbcType=VARCHAR},</if>
      <if test="picture != null">picture=#{picture,jdbcType=VARCHAR},</if>
@@ -64,66 +91,49 @@
      <if test="iosClick != null">ios_click=#{iosClick,jdbcType=BIGINT},</if>
      <if test="androidClick != null">android_click=#{androidClick,jdbcType=BIGINT},</if>
      <if test="state != null">cs_state=#{state,jdbcType=INTEGER},</if>
    </set> where id = #{id,jdbcType=BIGINT}
            <if test="sex !=null">sex =#{sex,jdbcType=INTEGER},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
  </update>
    <select id="getKeysById" resultType="java.lang.String">
        SELECT ec.`key` FROM `yeshi_ec_class` ec WHERE ec.`id` = #{id};
    <select id="getKeysById" resultType="java.lang.String">SELECT ec.`key` FROM
        `yeshi_ec_class` ec WHERE ec.`id` = #{id};
    </select>
     <select id="listGoodsClassBySystemId" resultMap="BaseResultMap">
         SELECT c.id,c.name,c.picture,c.url FROM `yeshi_ec_class` c
        RIGHT JOIN `yeshi_ec_super_goodsclass` sp ON sp.`goodsclass_id` = c.`id`
        WHERE sp.`system_id` = #{systemId}
        ORDER BY c.`orderby`
    <select id="listGoodsClassBySystemId" resultMap="BaseResultMap">SELECT
        c.id,c.name,c.picture,c.url FROM `yeshi_ec_class` c RIGHT JOIN
        `yeshi_ec_super_goodsclass` sp ON sp.`goodsclass_id` = c.`id` WHERE
        sp.`system_id` = #{systemId} ORDER BY c.`orderby`
     </select>
     <select id="getByAdjoinOrder" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_class fd
        WHERE  1=1
        <if test="type == -1">
            AND fd.`orderby` <![CDATA[<]]> #{order}
            ORDER BY fd.`orderby` desc
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_class fd WHERE 1=1
        <if test="type == -1">AND
            fd.`orderby` <![CDATA[<]]>
            #{order} ORDER BY fd.`orderby` desc
        </if>
        <if test="type == 1">
            AND fd.`orderby` <![CDATA[>]]> #{order}
            ORDER BY fd.`orderby`
        <if test="type == 1">AND
            fd.`orderby` <![CDATA[>]]>
            #{order} ORDER BY fd.`orderby`
        </if>
        LIMIT 1
   </select>
     <select id="getGoodsClassAll" resultMap="BaseResultMap">
         SELECT *  FROM yeshi_ec_class rs ORDER BY rs.`orderby`
    <select id="getGoodsClassAll" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_class rs ORDER BY rs.`orderby`
     </select>
     <select id="listByName" resultMap="BaseResultMap">
         SELECT *  from yeshi_ec_class rs
         WHERE rs.name like '%#{name}%'
         LIMIT ${start},${count}
     </select>
    <select id="listByName" resultMap="BaseResultMap">SELECT * from yeshi_ec_class
        rs WHERE rs.name like '%#{name}%' LIMIT ${start},${count}</select>
     <select id="countByName" resultType="java.lang.Integer">
         SELECT  IFNULL(COUNT(rs.id),0) FROM yeshi_ec_class rs 
         <if test="systemId != null">
            RIGHT JOIN yeshi_ec_super_goodsclass sp ON sp.`goodsclass_id` = rs.`id`
        <if test="systemId != null">RIGHT JOIN yeshi_ec_super_goodsclass sp ON
            sp.`goodsclass_id` = rs.`id`
        </if>
        WHERE rs.name LIKE '%#{name}%' 
            <if test="systemId != null">
                AND sp.`system_id` = #{systemId}
            </if>
        <if test="systemId != null">AND sp.`system_id` = #{systemId}</if>
     </select>
     <select id="getMaxOrder" resultType="java.lang.Integer">
         SELECT IFNULL(MAX(orderby),0) FROM `yeshi_ec_class`
    <select id="getMaxOrder" resultType="java.lang.Integer">SELECT
        IFNULL(MAX(orderby),0) FROM `yeshi_ec_class`
     </select>
     <select id="getEffectiveClass" resultMap="BaseResultMap">
         SELECT *  FROM yeshi_ec_class rs
         WHERE rs.cs_state = 1
         ORDER BY rs.`orderby`
    <select id="getEffectiveClass" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_class rs WHERE rs.cs_state = 1 ORDER BY rs.`orderby`
     </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsSubClassMapper.xml
@@ -20,10 +20,13 @@
            jdbcType="BIGINT" />
        <result column="sub_createtime" property="createtime" jdbcType="TIMESTAMP" />
        <result column="sub_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
        <result column="sub_sex" property="sex" jdbcType="INTEGER" />
        <result column="sub_month" property="month" jdbcType="VARCHAR" />
        <association property="rootClass" column="sub_root_id"
            select="com.yeshi.fanli.dao.mybatis.GoodsClassMapper.selectByPrimaryKey" />
        <association property="parent" column="sub_pid"
            select="com.yeshi.fanli.dao.mybatis.GoodsSubClassMapper.selectByPrimaryKey" />
    </resultMap>
    <resultMap id="SimpleResultMap"
        type="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass">
@@ -43,6 +46,8 @@
            jdbcType="BIGINT" />
        <result column="sub_createtime" property="createtime" jdbcType="TIMESTAMP" />
        <result column="sub_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
        <result column="sub_sex" property="sex" jdbcType="INTEGER" />
        <result column="sub_month" property="month" jdbcType="VARCHAR" />
        <association property="rootClass" column="sub_root_id"
            javaType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">
            <id column="sub_root_id" property="id" jdbcType="BIGINT" />
@@ -52,7 +57,7 @@
            <id column="sub_pid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">sub_id,sub_name,sub_picture,sub_picture_second,sub_weight,sub_root_id,sub_pid,sub_level,sub_state,sub_key,sub_search_json,sub_ios_click,sub_android_click,sub_createtime,sub_updatetime
    <sql id="Base_Column_List">sub_id,sub_name,sub_picture,sub_picture_second,sub_weight,sub_root_id,sub_pid,sub_level,sub_state,sub_key,sub_search_json,sub_ios_click,sub_android_click,sub_createtime,sub_updatetime,sub_sex,sub_month
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
@@ -61,12 +66,13 @@
        from yeshi_ec_sub_class where sub_id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_sub_class where sub_id = #{id,jdbcType=BIGINT}</delete>
        yeshi_ec_sub_class where sub_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_sub_class
        (sub_id,sub_name,sub_picture,sub_picture_second,sub_weight,sub_root_id,sub_pid,sub_level,sub_state,sub_key,sub_search_json,sub_ios_click,sub_android_click,sub_createtime,sub_updatetime)
        (sub_id,sub_name,sub_picture,sub_picture_second,sub_weight,sub_root_id,sub_pid,sub_level,sub_state,sub_key,sub_search_json,sub_ios_click,sub_android_click,sub_createtime,sub_updatetime,sub_sex,sub_month)
        values
        (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{pictureSecond,jdbcType=VARCHAR},#{weight,jdbcType=INTEGER},#{rootClass.id,jdbcType=BIGINT},#{parent.id,jdbcType=BIGINT},#{level,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{key,jdbcType=VARCHAR},#{searchJson,jdbcType=VARCHAR},#{iosClick,jdbcType=BIGINT},#{androidClick,jdbcType=BIGINT},#{createtime,jdbcType=TIMESTAMP},#{updatetime,jdbcType=TIMESTAMP})
        (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{pictureSecond,jdbcType=VARCHAR},#{weight,jdbcType=INTEGER},#{rootClass.id,jdbcType=BIGINT},#{parent.id,jdbcType=BIGINT},#{level,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{key,jdbcType=VARCHAR},#{searchJson,jdbcType=VARCHAR},#{iosClick,jdbcType=BIGINT},#{androidClick,jdbcType=BIGINT},#{createtime,jdbcType=TIMESTAMP},#{updatetime,jdbcType=TIMESTAMP},#{sex,jdbcType=INTEGER},#{month,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass"
        useGeneratedKeys="true" keyProperty="id">
@@ -87,6 +93,8 @@
            <if test="androidClick != null">sub_android_click,</if>
            <if test="createtime != null">sub_createtime,</if>
            <if test="updatetime != null">sub_updatetime,</if>
            <if test="sex != null">sub_sex,</if>
            <if test="month != null">sub_month,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -105,6 +113,8 @@
            <if test="androidClick != null">#{androidClick,jdbcType=BIGINT},</if>
            <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
            <if test="updatetime != null">#{updatetime,jdbcType=TIMESTAMP},</if>
            <if test="sex != null">#{sex,jdbcType=INTEGER},</if>
            <if test="month != null">#{month,jdbcType=VARCHAR}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass">update
@@ -120,7 +130,9 @@
        #{iosClick,jdbcType=BIGINT},sub_android_click =
        #{androidClick,jdbcType=BIGINT},sub_createtime =
        #{createtime,jdbcType=TIMESTAMP},sub_updatetime =
        #{updatetime,jdbcType=TIMESTAMP}  where sub_id = #{id,jdbcType=BIGINT}
        #{updatetime,jdbcType=TIMESTAMP} ,sub_sex =#{sex,jdbcType=INTEGER}
        ,sub_month =#{month,jdbcType=VARCHAR} where sub_id =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass">
        update yeshi_ec_sub_class
@@ -140,6 +152,8 @@
            <if test="androidClick != null">sub_android_click=#{androidClick,jdbcType=BIGINT},</if>
            <if test="createtime != null">sub_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
            <if test="updatetime != null">sub_updatetime=#{updatetime,jdbcType=TIMESTAMP},</if>
            <if test="sex !=null">sub_sex =#{sex,jdbcType=INTEGER},</if>
            <if test="month !=null">sub_month =#{month,jdbcType=VARCHAR},</if>
        </set>
        where sub_id = #{id,jdbcType=BIGINT}
    </update>
fanli/src/main/java/com/yeshi/fanli/mapping/order/LostOrderMapper.xml
@@ -40,9 +40,11 @@
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_lost_order where id = #{id,jdbcType=BIGINT}
    </delete>
    <select id="selectByOrderId" resultMap="BaseResultMap"
        parameterType="java.lang.String">select * from yeshi_ec_lost_order where orderId=#{orderId} and `type`=#{type}
    <select id="selectByOrderIdAndType" resultMap="BaseResultMap">select * from
        yeshi_ec_lost_order where orderId=#{orderId} and `type`=#{type}
    </select>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">select * from yeshi_ec_lost_order where id=#{0}</select>
    <select id="listByStateAndResultCode" resultMap="BaseResultMap">select * from
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoClassRelationServiceImpl.java
@@ -7,12 +7,14 @@
import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClassRelation;
import com.yeshi.fanli.service.inter.goods.TaoBaoClassRelationService;
import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
@Service
public class TaoBaoClassRelationServiceImpl implements TaoBaoClassRelationService {
    @Resource
    private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
@@ -43,6 +45,5 @@
    public int updateByPrimaryKey(TaoBaoClassRelation record) {
        return taoBaoClassRelationMapper.updateByPrimaryKey(record);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
@@ -28,7 +28,7 @@
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
import sun.security.krb5.internal.ccache.CCacheInputStream;
@Service
public class SpecialServiceImpl implements SpecialService {
@@ -48,16 +48,14 @@
    @Resource
    private ConfigService configService;
    @Override
    public Special selectByPrimaryKey(Long id) {
        return specialMapper.selectByPrimaryKey(id);
    }
    @Override
    public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record, String jumpType)
            throws SpecialException, Exception{
    public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record,
            String jumpType) throws SpecialException, Exception {
        
        Long cardId = record.getCardId();
        if (cardId == null) {
@@ -142,8 +140,6 @@
                resultObj.setSubPicture(null);
            }
            
            if (picture != null && picture.trim().length() > 0) {
                // 删除老图
                removePicture(resultObj.getPicture());
@@ -162,7 +158,6 @@
                record.setSubPicture(resultObj.getSubPicture());
            }
            
            if (icon != null && icon.trim().length() > 0) {
                // 删除老图
                removePicture(resultObj.getIcon());
@@ -179,9 +174,9 @@
        }
    }
    
    /**
     * 上传图片
     *
     * @param file
     * @return
     * @throws Exception
@@ -203,6 +198,7 @@
    /**
     * 删除图片-不更新数据库
     *
     * @param record
     * @throws Exception
     */
@@ -211,7 +207,6 @@
            COSManager.getInstance().deleteFile(picture);
        }
    }
    
    @Override
    @Transactional
@@ -245,7 +240,6 @@
        specialMapper.updateByPrimaryKey(resultObj);
        specialMapper.updateByPrimaryKey(exchangeObject);
    }
    
    @Override
    @Transactional
@@ -283,7 +277,6 @@
        return specialMapper.deleteBatchByCardID(list);
    }
    
    @Override
    public List<Special> listQueryByCard(long start, int count, Long card, String key){
        
@@ -316,12 +309,10 @@
        return list;
    }
    
    @Override
    public long countlistQueryByCard(Long card, String key) {
        return specialMapper.countlistQueryByCard(card, key);
    }
    
    @Override
    @Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
@@ -329,16 +320,14 @@
        return specialMapper.listBySystemAndCard(card, systemId);
    }
    @Override
    @Cacheable(value = "configCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId")
    public List<Special> listPageBySystemAndCard(long start, int count, String card, Long systemId) {
        return specialMapper.listPageBySystemAndCard(start, count, card, systemId);
    }
    @Override
    @Cacheable(value = "configCache", key = "'listCacheSpecialToIndex'")
    @Cacheable(value = "configCache", key = "'listCacheSpecialToIndex'+#acceptData.platform+'-'+#acceptData.version")
    public JSONObject listCacheSpecialToIndex(AcceptData acceptData) throws Exception{
        
        // 首页-5圆形2排区域
@@ -356,7 +345,6 @@
        // 数据处理
        handlelist(listArc);
        arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
        
        // 首页-活动区域(女王节)
        JSONObject activityMap = new JSONObject();
@@ -377,11 +365,10 @@
                activityMap.put("bottomPicture", special.getBottomPicture());
            }
        }
        // 数据处理
        handlelist(listActivity);
        activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity));
        
        // 首页-方形专题(品牌券、母婴...)
        JSONObject blockJsonMap = new JSONObject();
@@ -395,6 +382,18 @@
                blockJsonMap.put("bottomPicture", special.getBottomPicture());
            }
        }
        // 品牌券
        // >=1.5.40后的版本可以用
        if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 39)
                || "ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 48)
            if (listBlock != null)
                for (int i = 0; i < listBlock.size(); i++) {
                    if ("品牌券".equalsIgnoreCase(listBlock.get(i).getName())) {
                        listBlock.get(i).setJumpDetail(jumpDetailV2Service.getByTypeCache("hot_cakes"));
                    }
                }
        // 数据处理
        handlelist(listBlock);
        blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(listBlock));
@@ -411,9 +410,9 @@
        return specialMapper.listByPlaceKey(placeKey);
    }
    
    /**
     * 处理 数据
     *
     * @param list
     */
    public void handlelist(List<Special> list) {
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailServiceImpl.java
@@ -33,14 +33,7 @@
    @Override
    public void startSyncGoods() {
        // 判断是否有正在进行的更新
        String key1 = "dataoke-updating";
        // if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key1)))
        // return;
        // 开始更新
        redisManager.cacheCommonString(key1, "1", 60 * 20);
        long firstTime = System.currentTimeMillis() - 1000 * 60 * 5L;
        int totalCount = 0;
        for (int p = 1; p <= 2000; p++) {// 10W数据
@@ -48,7 +41,6 @@
                DaTaoKeApiResult result = DaTaoKeApiUtil.goodsList(p);
                if (result.getDetailList().size() < 50)// 更新完成
                {
                    redisManager.removeCommonString(key1);
                    break;
                }
                addGoodsList(result.getDetailList());
@@ -56,7 +48,6 @@
            } catch (Exception e) {
            }
        }
        LogHelper.test("大淘客总共更新数据数量:" + totalCount);
        // 清除过期数据
        if (totalCount > 50000)// 保证有5w数据再清除过期
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserNotificationServiceImpl.java
@@ -6,7 +6,7 @@
import org.springframework.stereotype.Service;
import com.yeshi.fanli.controller.client.UserInfoController;
import com.yeshi.fanli.controller.client.v1.UserInfoController;
import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
import com.yeshi.fanli.entity.bus.user.AccountMessage;
import com.yeshi.fanli.entity.bus.user.BindingAccount;
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/TaoBaoClassRelationService.java
@@ -1,8 +1,6 @@
package com.yeshi.fanli.service.inter.goods;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClassRelation;
public interface TaoBaoClassRelationService {
    
fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
@@ -99,8 +99,7 @@
            "🌟",// 发光的星星
    };
    static final String[] timeEmojis = new String[] {
            "🕛",// 十二点
    static final String[] timeEmojis = new String[] { "🕛", // 十二点
            "🕧",// 十二点半
            "🕐",// 一点钟
            "🕜",// 一点半
@@ -528,18 +527,34 @@
        return parseCurrent(url);
    }
    private static String getRandomCommonEmoji() {
        return commonEmojis[(int) (Math.random() * commonEmojis.length)];
    }
    public static String getDesc(DaTaoKeDetail detail) {
        // 标题+券后价+包邮+描述
        String desc = "😛" + detail.getdTitle() + "😛";
        String desc = detail.getdTitle();
        desc += "\n";
        desc += "😛" + String.format("券后💰【%s元】包邮秒杀 ", MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
                + "😛";
        desc += String.format("券后价%s【%s元】包邮秒杀 ",Math.random()>0.5?"💰":"", MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
                + (Math.random()>0.5?getRandomCommonEmoji():"");
        desc += "\n";
        desc += detail.getIntroduce();
//        desc += detail.getIntroduce();
        String introduce = detail.getIntroduce().replace(",", ",").replace("。", ",").replace("!", ",")
                .replace(",", ",");
        introduce=introduce.replace(",,,", ",").replace(",,", ",");
        String[] sts = introduce.split(",");
        introduce = "";
        for (int i = 0; i < sts.length; i++) {
            if (i % 2 == 1) {// 需要换行
                introduce += sts[i] + (Math.random()>0.5?getRandomCommonEmoji():i==sts.length-1?"":",") + "\n";
            } else
                introduce += sts[i] + (Math.random()>0.5?getRandomCommonEmoji():i==sts.length-1?"":",");
        }
        desc+=introduce;
        return desc;
    }
    
    public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetail detail) {
        if (detail != null) {
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
@@ -765,10 +765,10 @@
        tg.setSalesType(1);
        // 测试使用
        // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
         List<ClientTextStyleVO> labels = new ArrayList<>();
         labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
         labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
         tg.setLabels(labels);
        // List<ClientTextStyleVO> labels = new ArrayList<>();
        // labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
        // labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
        // tg.setLabels(labels);
        return tg;
    }
@@ -1018,10 +1018,10 @@
        // tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
        // tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
        // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
         List<ClientTextStyleVO> labels = new ArrayList<>();
         labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
         labels.add(new ClientTextStyleVO("标签内容", "#000000"));
         tg.setLabels(labels);
        // List<ClientTextStyleVO> labels = new ArrayList<>();
        // labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
        // labels.add(new ClientTextStyleVO("标签内容", "#000000"));
        // tg.setLabels(labels);
        return tg;
    }