fanli/src/main/java/com/yeshi/fanli/controller/client/RecommendController.java
@@ -62,6 +62,7 @@ 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; @@ -103,6 +104,7 @@ 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.TaoBaoOrderUtil; @@ -221,6 +223,9 @@ @Resource private UserInfoExtraService userInfoExtraService; @Resource private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; @RequestMapping(value = "getHonestList") public void getHonestList(AcceptData acceptData, PrintWriter out) { @@ -1622,105 +1627,98 @@ LogHelper.test("获取PID耗时:" + (java.lang.System.currentTimeMillis() - startTime)); final String clientPid = clientTBPid.getPid(); final List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); // 是否在服务端进行转链 boolean convertInServer = configService.isConvertTaoBaoLinkInServer(); List<String> taskList = new ArrayList<>(); // 获取商品基本信息 taskList.add("goods"); JSONObject ticket = new JSONObject(); TaoBaoGoodsBrief goods = null; taskList.stream().parallel().forEach(task -> { if (task.equalsIgnoreCase("goods")) { JSONObject ticket = new JSONObject(); TaoBaoGoodsBrief goods = null; if (!convertInServer) { try { goods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(id)); if (goods.getTkRate() == null || new BigDecimal(0).compareTo(goods.getTkRate()) == 0) { 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); TaoBaoGoodsBrief linkInfo = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app); if (linkInfo != null) { goods.setAuctionUrl(linkInfo.getAuctionUrl()); goods.setCouponLink(linkInfo.getCouponLink()); goods.setTkRate(linkInfo.getTkRate()); } } } catch (TaobaoGoodsDownException e) { // 商品下架 ThreadUtil.run(new Runnable() { public void run() { taoBaoGoodsUpdateService.offlineTaoBaoGoods(Long.parseLong(id)); } }); } } else { String appId = clientPid.split("_")[2]; TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId); if (!convertInServer) { try { goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(Long.parseLong(id)); if (goods == null) { 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) { 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() { taoBaoGoodsUpdateService.offlineTaoBaoGoods(Long.parseLong(id)); taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(finalGoods); } }); } } } 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) { } } }); } } }); } 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) { @@ -1743,17 +1741,19 @@ for (String img : tb.getImgList()) { finalImgList.add(TbImgUtil.getTBSizeImg(img, 600)); } if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite())) finalImgList.add(0, tb.getPictUrlWhite()); JSONObject goods = new JSONObject(); 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()); 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天销量 goods.put("saleCount", TaoBaoUtil.getSaleCount(tb.getBiz30day())); goodsJson.put("saleCount", TaoBaoUtil.getSaleCount(tb.getBiz30day())); // 分享赚 BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb); @@ -1787,7 +1787,7 @@ LogHelper.test(String.format("PID: uid-%s pid-%s", uid + "", pid)); // 是否有券 goods.put("coupon", StringUtil.isNullOrEmpty(tb.getCouponInfo()) ? false : true); goodsJson.put("coupon", StringUtil.isNullOrEmpty(tb.getCouponInfo()) ? false : true); // 领券人列表 List<ShamUser> listCouponUser = new ArrayList<ShamUser>(); @@ -1816,19 +1816,21 @@ 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() + "")); // } // 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); goods.put("couponInfo", couponInfo); goodsJson.put("couponInfo", couponInfo); if (tb.getBiz30day() >= 1000) { // 领券人列表 @@ -1841,7 +1843,7 @@ BigDecimal proportion = manageService.getFanLiRate(); hongBao = TaoBaoUtil.getGoodsHongBaoInfo(tb, proportion); } goods.put("hongBao", hongBao); goodsJson.put("hongBao", hongBao); data.put("tbPidInfo", clientTBPid); @@ -1859,7 +1861,7 @@ else jumpUrl = tb.getAuctionUrl(); } goods.put("jumpUrl", jumpUrl); goodsJson.put("jumpUrl", jumpUrl); TaoBaoShopInfo tbShopInfo = redisManager.getTBShopInfo(tb.getShopTitle(), tb.getSellerId(), tb.getAuctionId()); if (tbShopInfo != null) { @@ -1871,7 +1873,7 @@ } } // 店铺 goods.put("shopInfo", tbShopInfo); goodsJson.put("shopInfo", tbShopInfo); // 分享路径 String shareUrl = String.format("%s?id=" + tb.getAuctionId(), Constant.systemCommonConfig.getAppShareInfoUrl()); @@ -1885,7 +1887,7 @@ data.put("storageState", storageState); data.put("shareUrl", shareUrl); data.put("goods", goods); 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); @@ -2009,20 +2011,48 @@ List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>(); goodsList.parallelStream().forEach(goods -> { // 获取详情 TaoBaoGoodsBrief taoBaoGoodsBrief = null; try { taoBaoGoodsBrief = redisManager.getTaoBaoGoodsBrief(goods.getAuctionId()); } catch (Exception e) { e.printStackTrace(); } 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); if (taoBaoGoodsBrief != null) { listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), "")); } 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>(); // 删除推荐 fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java
@@ -48,6 +48,8 @@ import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.EhcacheUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.ThreadUtil; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; import com.yeshi.fanli.util.taobao.SearchFilterUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; @@ -84,6 +86,9 @@ @Resource private QualityGoodsService qualityGoodsService; @Resource private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; @RequestMapping(value = "gethotsearch", method = RequestMethod.POST) public void getHotSearch(AcceptData acceptData, PrintWriter out) { BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), @@ -101,7 +106,8 @@ List<HotSearch> hotSearchList = new ArrayList<HotSearch>(); for (SuperHotSearch superHotSearch : superHotSearchList) { HotSearch hotSearch = superHotSearch.getHotSearch(); hotSearchList.add(hotSearch); if (hotSearch != null) hotSearchList.add(hotSearch); } JSONObject data = new JSONObject(); @@ -615,9 +621,19 @@ map.put(g.getAuctionId(), g.getMaterialLibType()); for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) goods.setMaterialLibType(map.get(goods.getAuctionId())); ThreadUtil.run(new Runnable() { @Override public void run() { // 更新到緩存 for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(goods); } }); } catch (TaobaoGoodsDownException e) { e.printStackTrace(); } } List<TaoBaoSearchNav> navList = TaoBaoUtil.getBaseNav(); fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
@@ -23,12 +23,16 @@ import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord; import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoLink; 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.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.UserExtraTaoBaoInfoService; @@ -37,7 +41,9 @@ 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.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; import com.yeshi.fanli.util.factory.MonitorFactory; import com.yeshi.fanli.util.taobao.TaoBaoUtil; @@ -74,6 +80,15 @@ @Resource private UserInfoService userInfoService; @Resource private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; @Resource private RedisManager redisManager; @Resource private ShareGoodsTextTemplateService shareGoodsTextTemplateService; // 获取商品分享链接 @RequestMapping(value = "getGoodsShareUrl") @@ -360,4 +375,179 @@ } } /** * 预览分享模板 * * @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; } } String content = shareGoodsTextTemplateService.createContentByTemplate(template, uid, goods, 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, Boolean hasCoupon, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult(1, "用户未登录")); return; } if (hasCoupon) { shareGoodsTextTemplateService.resetCouponTemplate(uid); } else { shareGoodsTextTemplateService.resetCommonTemplate(uid); } 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"))); } } fanli/src/main/java/com/yeshi/fanli/controller/client/SystemClientController.java
@@ -80,7 +80,7 @@ // 老版本weex(1.5.1之前的) ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js"); } else if ("ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) < 44) && Integer.parseInt(acceptData.getVersion()) < 44&&system.getId().longValue()!=5L) ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js"); } list.add(ssp); fanli/src/main/java/com/yeshi/fanli/dao/mybatis/goods/ShareGoodsTextTemplateMapper.java
New file @@ -0,0 +1,15 @@ package com.yeshi.fanli.dao.mybatis.goods; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate; public interface ShareGoodsTextTemplateMapper extends BaseMapper<ShareGoodsTextTemplate> { /** * 根据用户查询 * @param uid * @return */ ShareGoodsTextTemplate selectByUid(Long uid); } fanli/src/main/java/com/yeshi/fanli/entity/goods/ShareGoodsTextTemplate.java
New file @@ -0,0 +1,76 @@ package com.yeshi.fanli.entity.goods; import java.util.Date; import org.yeshi.utils.mybatis.Column; import org.yeshi.utils.mybatis.Table; /** * 分享商品的话语模板 * * @author Administrator * */ @Table("yeshi_ec_share_template") public class ShareGoodsTextTemplate { @Column(name = "st_id") private Long id; @Column(name = "st_uid") private Long uid; @Column(name = "st_share_text_template") private String shareTextTemplate;// 普通商品分享模板 @Column(name = "st_share_coupon_text_template") private String shareCouponTextTemplate;// 券分享模板 @Column(name = "st_create_time") private Date createTime; @Column(name = "st_update_time") private Date updateTime; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Long getUid() { return uid; } public void setUid(Long uid) { this.uid = uid; } public String getShareTextTemplate() { return shareTextTemplate; } public void setShareTextTemplate(String shareTextTemplate) { this.shareTextTemplate = shareTextTemplate; } public String getShareCouponTextTemplate() { return shareCouponTextTemplate; } public void setShareCouponTextTemplate(String shareCouponTextTemplate) { this.shareCouponTextTemplate = shareCouponTextTemplate; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } } fanli/src/main/java/com/yeshi/fanli/exception/goods/ShareGoodsTextTemplateException.java
New file @@ -0,0 +1,32 @@ package com.yeshi.fanli.exception.goods; public class ShareGoodsTextTemplateException extends Exception { /** * */ private static final long serialVersionUID = 1L; private int code; private String msg; public int getCode() { return code; } public String getMsg() { return msg; } public ShareGoodsTextTemplateException(int code, String msg) { this.code = code; this.msg = msg; } public ShareGoodsTextTemplateException() { } @Override public String getMessage() { return this.msg; } } fanli/src/main/java/com/yeshi/fanli/mapping/goods/ShareGoodsTextTemplateMapper.xml
New file @@ -0,0 +1,84 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.goods.ShareGoodsTextTemplateMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate"> <id column="st_id" property="id" jdbcType="BIGINT" /> <result column="st_uid" property="uid" jdbcType="BIGINT" /> <result column="st_share_text_template" property="shareTextTemplate" jdbcType="VARCHAR" /> <result column="st_share_coupon_text_template" property="shareCouponTextTemplate" jdbcType="VARCHAR" /> <result column="st_create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="st_update_time" property="updateTime" jdbcType="TIMESTAMP" /> </resultMap> <sql id="Base_Column_List">st_id,st_uid,st_share_text_template,st_share_coupon_text_template,st_create_time,st_update_time </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_share_template where st_id = #{id,jdbcType=BIGINT} </select> <select id="selectByUid" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_share_template where st_uid = #{0} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_share_template where st_id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_share_template (st_id,st_uid,st_share_text_template,st_share_coupon_text_template,st_create_time,st_update_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{shareTextTemplate,jdbcType=VARCHAR},#{shareCouponTextTemplate,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}) </insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate" useGeneratedKeys="true" keyProperty="id"> insert into yeshi_ec_share_template <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">st_id,</if> <if test="uid != null">st_uid,</if> <if test="shareTextTemplate != null">st_share_text_template,</if> <if test="shareCouponTextTemplate != null">st_share_coupon_text_template,</if> <if test="createTime != null">st_create_time,</if> <if test="updateTime != null">st_update_time,</if> </trim> values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="uid != null">#{uid,jdbcType=BIGINT},</if> <if test="shareTextTemplate != null">#{shareTextTemplate,jdbcType=VARCHAR},</if> <if test="shareCouponTextTemplate != null">#{shareCouponTextTemplate,jdbcType=VARCHAR},</if> <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate">update yeshi_ec_share_template set st_uid = #{uid,jdbcType=BIGINT},st_share_text_template = #{shareTextTemplate,jdbcType=VARCHAR},st_share_coupon_text_template = #{shareCouponTextTemplate,jdbcType=VARCHAR},st_create_time = #{createTime,jdbcType=TIMESTAMP},st_update_time = #{updateTime,jdbcType=TIMESTAMP} where st_id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate"> update yeshi_ec_share_template <set> <if test="uid != null">st_uid=#{uid,jdbcType=BIGINT},</if> <if test="shareTextTemplate != null">st_share_text_template=#{shareTextTemplate,jdbcType=VARCHAR}, </if> <if test="shareCouponTextTemplate != null">st_share_coupon_text_template=#{shareCouponTextTemplate,jdbcType=VARCHAR}, </if> <if test="createTime != null">st_create_time=#{createTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">st_update_time=#{updateTime,jdbcType=TIMESTAMP},</if> </set> where st_id = #{id,jdbcType=BIGINT} </update> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
New file @@ -0,0 +1,153 @@ package com.yeshi.fanli.service.impl.goods; import java.util.Date; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.yeshi.utils.HttpUtil; import com.yeshi.fanli.dao.mybatis.goods.ShareGoodsTextTemplateMapper; import com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; /** * 分享商品模板 * * @author Administrator * */ @Service public class ShareGoodsTextTemplateServiceImpl implements ShareGoodsTextTemplateService { @Resource private ShareGoodsTextTemplateMapper shareGoodsTextTemplateMapper; @Resource private ConfigService configService; @Override public void saveCommonTemplate(Long uid, String template) throws ShareGoodsTextTemplateException { isCommonTemplateRight(template); ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid); if (old != null) { ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); update.setId(old.getId()); update.setShareTextTemplate(template); update.setUpdateTime(new Date()); shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); } else { ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); textTemplate.setCreateTime(new Date()); textTemplate.setShareTextTemplate(template); textTemplate.setUid(uid); shareGoodsTextTemplateMapper.insertSelective(textTemplate); } } @Override public String getCommonTemplate(Long uid) { ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); if (template != null) return template.getShareTextTemplate(); return null; } @Override public void saveCouponTemplate(Long uid, String template) throws ShareGoodsTextTemplateException { isCouponTemplateRight(template); } @Override public String geteCouponTemplate(Long uid) { ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); if (template != null) return template.getShareCouponTextTemplate(); return null; } @Override public void isCommonTemplateRight(String template) throws ShareGoodsTextTemplateException { String[] keys = new String[] { "{标题}", "{店铺类型}", "{商品原价}", "{月销量}", "{短链}", "{淘口令}" }; int keysCount = 0; for (String key : keys) if (template != null && template.contains(key)) keysCount++; if (keysCount == 0) throw new ShareGoodsTextTemplateException(1, "模板格式有误"); } @Override public void isCouponTemplateRight(String template) throws ShareGoodsTextTemplateException { String[] keys = new String[] { "{标题}", "{店铺类型}", "{商品原价}", "{优惠券面额}", "{优惠券价}", "{月销量}", "{领券短链}", "{淘口令}" }; int keysCount = 0; for (String key : keys) if (template != null && template.contains(key)) keysCount++; if (keysCount == 0) throw new ShareGoodsTextTemplateException(1, "模板格式有误"); } @Override public String createContentByTemplate(String template, Long uid, TaoBaoGoodsBrief goods, boolean hasCoupon) { 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); if (!hasCoupon) { String token = goods.getCouponLinkTaoToken(); if (StringUtil.isNullOrEmpty(token)) token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), goods.getAuctionUrl()); return template.replace("{标题}", goods.getTitle()).replace("{商品原价}", goods.getZkPrice().toString()) .replace("{月销量}", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{短链}", shortLink) .replace("{淘口令}", "").replace("{店铺类型}", goods.getUserType() == 1 ? "天猫价" : "淘宝价"); } else { String token = goods.getCouponLinkTaoToken(); if (StringUtil.isNullOrEmpty(token)) token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), goods.getCouponLink()); return template.replace("{标题}", goods.getTitle()).replace("{商品原价}", goods.getZkPrice().toString()) .replace("{月销量}", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{领券短链}", shortLink) .replace("{淘口令}", token).replace("{优惠券面额}", goods.getCouponAmount().toString()) .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(goods).toString()) .replace("{店铺类型}", goods.getUserType() == 1 ? "天猫价" : "淘宝价"); } } @Override public void resetCommonTemplate(Long uid) { ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); if (template != null) { ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); update.setId(template.getId()); update.setShareTextTemplate(""); update.setUpdateTime(new Date()); shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); } } @Override public void resetCouponTemplate(Long uid) { ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); if (template != null) { ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); update.setId(template.getId()); update.setShareCouponTextTemplate(""); update.setUpdateTime(new Date()); shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); } } } fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoOrderServiceImpl.java
@@ -81,23 +81,22 @@ @Transactional @Override public void addTaoBaoOrder(String orderId, List<TaoBaoOrder> list) { LogHelper.test("订单号与订单数量:" + orderId + "-" + list.size()); // 验证orderby是否正确 if (list != null && list.size() > 0) { int maxOrderBy=list.get(0).getOrderBy(); if(list.size()>1) for(TaoBaoOrder order:list) { if(order.getOrderBy()>maxOrderBy) maxOrderBy=order.getOrderBy(); if (list != null && list.size() > 0) { int maxOrderBy = list.get(0).getOrderBy(); if (list.size() > 1) for (TaoBaoOrder order : list) { if (order.getOrderBy() > maxOrderBy) maxOrderBy = order.getOrderBy(); } if (list.size() != maxOrderBy) { LogHelper.test("捕捉到排序值错误:" + orderId); return; } } List<TaoBaoOrder> oldOrderList = taoBaoOrderMapper.selectTaoBaoOrderByOrderId(orderId); if (oldOrderList == null || oldOrderList.size() == 0) { for (TaoBaoOrder taoBaoOrder : list) { fanli/src/main/java/com/yeshi/fanli/service/inter/goods/ShareGoodsTextTemplateService.java
New file @@ -0,0 +1,81 @@ package com.yeshi.fanli.service.inter.goods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException; public interface ShareGoodsTextTemplateService { /** * 保存普通分享商品模板 * * @param uid * @param template * @throws ShareGoodsTextTemplateException */ public void saveCommonTemplate(Long uid, String template) throws ShareGoodsTextTemplateException; /** * 获取普通分享商品模板 * * @param uid * @return */ public String getCommonTemplate(Long uid); /** * 普通商品分享模板是否正确 * * @param template * @return * @throws ShareGoodsTextTemplateException */ public void isCommonTemplateRight(String template) throws ShareGoodsTextTemplateException; /** * 保存券分享模板 * * @param uid * @param template * @throws ShareGoodsTextTemplateException */ public void saveCouponTemplate(Long uid, String template) throws ShareGoodsTextTemplateException; /** * 获取券分享模板 * * @param uid * @return */ public String geteCouponTemplate(Long uid); /** * 券分享模板是否正确 * * @param template * @return * @throws ShareGoodsTextTemplateException */ public void isCouponTemplateRight(String template) throws ShareGoodsTextTemplateException; /** * 根据模板生成内容 * * @param template * @param goods * @return */ public String createContentByTemplate(String template, Long uid, TaoBaoGoodsBrief goods, boolean hasCoupon); /** * 还原普通模板 * * @param uid */ public void resetCommonTemplate(Long uid); /** * 还原券模板 * * @param uid */ public void resetCouponTemplate(Long uid); } fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java
New file @@ -0,0 +1,45 @@ package com.yeshi.fanli.util.cache; import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.google.gson.Gson; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; @Component public class TaoBaoGoodsCacheUtil { @Resource private RedisManager redisManager; /** * 保存常规的淘宝商品详情(搜索,详情) * * @param goods */ public void saveCommonTaoBaoGoodsInfo(TaoBaoGoodsBrief goods) { if (goods == null || goods.getAuctionId() == null) return; String key = "taobao-goods-common-" + goods.getAuctionId(); // 保存20分钟 redisManager.cacheCommonString(key, new Gson().toJson(goods), 60 * 20); } /** * 获取缓存 * * @param auctionId * @return */ public TaoBaoGoodsBrief getCommonTaoBaoGoodsInfo(long auctionId) { String key = "taobao-goods-common-" + auctionId; String value = redisManager.getCommonString(key); if (!StringUtil.isNullOrEmpty(value)) { return new Gson().fromJson(value, TaoBaoGoodsBrief.class); } else return null; } } fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java
@@ -4,11 +4,19 @@ import java.util.HashMap; import java.util.Map; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.jsoup.Connection; import org.jsoup.Connection.Response; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import org.yeshi.utils.HttpUtil; import com.yeshi.fanli.util.StringUtil; import net.sf.json.JSONObject; public class JDUtil { @@ -79,4 +87,37 @@ System.out.println(result); } @SuppressWarnings("deprecation") public static void searchByKey(String key) { JSONObject params = new JSONObject(); params.put("pageNo", 1); params.put("pageSize", 20); params.put("searchUUID", StringUtil.Md5(System.currentTimeMillis() + "")); JSONObject data = new JSONObject(); data.put("deliveryType", "0"); data.put("hasCoupon", "0"); data.put("isCare", "0"); data.put("isPinGou", "0"); data.put("isZY", "0"); data.put("key", key); data.put("keywordType", "kt1"); data.put("lock", ""); data.put("orientationFlag", ""); data.put("searchType", "st1"); params.put("data", data); HttpClient client = new HttpClient(); PostMethod pm = new PostMethod("https://union.jd.com/api/goods/search"); pm.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"); pm.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); pm.setRequestHeader("Referer", "https://union.jd.com/proManager/index?pageNo=1&keywords=%E9%9E%8B%E5%AD%90"); pm.setRequestBody(params.toString()); try { client.executeMethod(pm); String result = pm.getResponseBodyAsString(); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } } } fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
@@ -1102,6 +1102,8 @@ goods.setZkPrice(new BigDecimal(item.optString("zk_final_price"))); goods.setAuctionUrl(item.optString("item_url")); goods.setPictUrl(item.optString("pict_url")); goods.setSalesCount(item.optString("volume")); goods.setUserType(item.optInt("user_type")); list.add(goods); } } @@ -1662,8 +1664,10 @@ String itemLink = resultJSON.optString("item_url"); TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); goods.setAuctionUrl(itemLink); if (!StringUtil.isNullOrEmpty(resultJSON.optString("coupon_info"))) if (!StringUtil.isNullOrEmpty(resultJSON.optString("coupon_info"))) { goods.setCouponLink(couponLink); goods.setCouponInfo(resultJSON.optString("coupon_info")); } String tkRate = resultJSON.optString("max_commission_rate"); if (!StringUtil.isNullOrEmpty(tkRate)) { goods.setTkRate(new BigDecimal(tkRate));