From 179b39401c406579a0d10c442a665aeb2802e931 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 20 五月 2019 09:17:03 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java | 2344 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 2,344 insertions(+), 0 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java new file mode 100644 index 0000000..e159152 --- /dev/null +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java @@ -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, "璇蜂笂浼爄d")); + 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());// 閿�閲忥紙鍜宻alesCount涓�鑷达紝姝ゅ澶勭悊鍏煎锛� + 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, "璇蜂笂浼爄d")); + 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鏄惁姝e湪涓婄嚎 + 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) + "],涓婁紶鐨勬窐瀹濊鍗旾D锛�" + order + ",鐢ㄦ埛ID:" + uid + ",璁㈠崟閲戦:" + + money + ",鍟嗗搧閾炬帴:" + auctionUrl); + if (StringUtil.isNullOrEmpty(order)) { + out.print(JsonUtil.loadFalseResult(1, "璇蜂笂浼爋rder")); + LogHelper.userOrder("[ip:" + IPUtil.getRemotIP(request) + "] 涓婁紶鐨勮鍗曚负绌猴紒涓婁紶璁㈠崟澶辫触锛�"); + return; + } + + UserInfo user = userInfoService.getUserById(uid); + if (user == null) { + out.print(JsonUtil.loadFalseResult(1, "璇蜂笂浼爑id")); + 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 + "涓嬪崟鎴愬姛锛佽鍗旾D[" + or.getOrderId() + "]"); + } else { + LogHelper.userOrder("鐢ㄦ埛ID" + uid + "涓嬪崟澶辫触锛佽鍗旾D[" + 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鐨処MEI淇℃伅 + * @param idfa + * -IOS鐨刬dfa骞垮憡鏍囪瘑淇℃伅 + */ + @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銆両OS鐨勫簳閮ㄧ綉椤甸摼鎺� + 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, "璇蜂笂浼爄d")); + 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鏄惁姝e湪涓婄嚎 + 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("-", ".")); + // 鍒哥殑鍙d护 + 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, "璇蜂笂浼爄d")); + 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(); + } + } +} -- Gitblit v1.8.0