From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java | 424 +++++++++++++++++++++++++++------------------------- 1 files changed, 218 insertions(+), 206 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java index 327c8f5..90135d7 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java @@ -1,206 +1,218 @@ -package com.yeshi.fanli.controller.wxmp.v1; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.StringUtil; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.yeshi.fanli.dto.WXMPAcceptData; -import com.yeshi.fanli.entity.bus.homemodule.Special; -import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; -import com.yeshi.fanli.entity.common.JumpDetailV2; -import com.yeshi.fanli.entity.dynamic.GoodsPicture; -import com.yeshi.fanli.entity.dynamic.WXMPDynamicInfo; -import com.yeshi.fanli.exception.dynamic.WXMPDynamicInfoException; -import com.yeshi.fanli.log.LogHelper; -import com.yeshi.fanli.service.inter.dynamic.WXMPDynamicInfoService; -import com.yeshi.fanli.service.inter.homemodule.SpecialService; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.JumpDetailUtil; -import com.yeshi.fanli.util.jd.JDApiUtil; -import com.yeshi.fanli.vo.homemodule.SpecialVO; -import com.yeshi.common.vo.ClientTextStyleVO; - -import net.sf.json.JSONObject; - -@Controller("WXMPDynamicController") -@RequestMapping("/wxmp/api/v1/dynamic") -public class DynamicController { - - @Resource - private WXMPDynamicInfoService wxmpDynamicInfoService; - - @Resource - private SpecialService specialService; - - /** - * 棣栭〉涓撻 - * - * @param acceptData - * @param uid - * @param out - */ - @RequestMapping(value = "getHotList") - public void getHotList(WXMPAcceptData acceptData, int page, PrintWriter out) { - - List<WXMPDynamicInfo> infoList = wxmpDynamicInfoService.listDynamicInfo(page, Constant.PAGE_SIZE); - for (WXMPDynamicInfo info : infoList) { - if (info.getImgs() != null) - for (GoodsPicture goodsPicture : info.getImgs()) { - JSONObject params = new JSONObject(); - if (goodsPicture.getGoodsVO() != null && goodsPicture.getJumpDetail() != null) { - params.put("id", goodsPicture.getGoodsVO().getGoodsId()); - goodsPicture.setJumpDetail(null); - goodsPicture.getGoodsVO().setImgList(null); - goodsPicture.getGoodsVO().setShopInfo(null); - goodsPicture.getGoodsVO().setCouponInfoList(null); - } - } - } - - long count = wxmpDynamicInfoService.countDynamicInfo(); - Gson gson = JsonUtil.getConvertDateToShortNameBuilder(JsonUtil - .getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder().excludeFieldsWithoutExposeAnnotation())) - .create(); - try { - JSONObject data = new JSONObject(); - data.put("list", gson.toJson(infoList)); - data.put("count", count); - data.put("page",page); - out.print(JsonUtil.loadTrueResult(data)); - } catch (Exception e) { - out.print(JsonUtil.loadFalseResult(1, "鑾峰彇鏁版嵁澶辫触")); - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - } - - @RequestMapping(value = "copyText") - public void copyText(WXMPAcceptData acceptData, String id, Long uid, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); - return; - } - - if (StringUtil.isNullOrEmpty(id)) { - out.print(JsonUtil.loadFalseResult("鍟嗗搧ID鏈┖")); - return; - } - - try { - String content = wxmpDynamicInfoService.copyContent(id, uid); - JSONObject data = new JSONObject(); - data.put("content", content); - out.print(JsonUtil.loadTrueResult(data)); - } catch (WXMPDynamicInfoException e) { - out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); - } - } - - @RequestMapping(value = "getActivityList") - public void getActivityList(WXMPAcceptData acceptData, int page, PrintWriter out) { - // 骞冲彴鍖哄垎 - int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); - List<String> listKey = new ArrayList<String>(); - listKey.add("special_channel_jd"); - listKey.add("special_channel_pdd"); - - List<SpecialVO> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, - listKey, platformCode, Integer.parseInt(acceptData.getVersion()),acceptData.getSystem()); - - long time = System.currentTimeMillis(); - - // 鍒犻櫎灏氭湭鍚敤鐨勮繃鏈熺殑 - for (int i = 0; i < list.size(); i++) { - SpecialVO special = list.get(i); - if (special.getJumpDetail() != null) { - special.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(special.getJumpDetail())); - } - - if (special.getState() == 1L) { - list.remove(i--); - } else { - if (special.getStartTime() != null && special.getEndTime() != null) { - if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { - list.remove(i--); - } else// 璁剧疆鍊掕鏃� - { - special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); - } - } - - List<SpecialLabel> listLabels = special.getListLabels(); - if (listLabels != null && !listLabels.isEmpty()) { - List<ClientTextStyleVO> labels = new ArrayList<>(); - for (SpecialLabel specialLabel : listLabels) { - labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); - } - special.setLabels(labels); - } - } - } - - long count = specialService.countByPlaceKeyList(listKey, platformCode, - Integer.parseInt(acceptData.getVersion()),acceptData.getSystem()); - - GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); - Gson gson = gsonBuilder.create(); - JSONObject data = new JSONObject(); - data.put("count", count); - data.put("page", page); - data.put("list", gson.toJson(list)); - out.print(JsonUtil.loadTrueResult(data)); - } - - @RequestMapping(value = "getActivityDetail") - public void getActivityDetail(WXMPAcceptData acceptData, Long uid, Long id, PrintWriter out) { - if (uid == null) - out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); - if (id == null) - out.print(JsonUtil.loadFalseResult("娲诲姩ID涓虹┖")); - - Special special = specialService.selectByPrimaryKey(id); - if (special == null) { - out.print(JsonUtil.loadFalseResult("涓撻涓嶅瓨鍦�")); - return; - } - - JumpDetailV2 jumpDetail = special.getJumpDetail(); - jumpDetail.setActivity(null); - jumpDetail.setController(null); - String params = special.getParams(); - if (jumpDetail.getType().equalsIgnoreCase("jd")) {// 浜笢鐨勪笓棰樻椿鍔� - JSONObject paramsJson = JSONObject.fromObject(params); - // 浜笢杞摼 - String url = paramsJson.optString("url"); - String link = JDApiUtil.convertLinkWithSubUnionId(url, null, JDApiUtil.POSITION_FANLI + "", uid + ""); - - if (StringUtil.isNullOrEmpty(link)) { - out.print(JsonUtil.loadFalseResult("杞摼澶辫触")); - return; - } - paramsJson.put("url", link); - params = paramsJson.toString(); - } - - JSONObject data = new JSONObject(); - - GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); - Gson gson = gsonBuilder.create(); - data.put("jumpDetail", gson.toJson(jumpDetail)); - data.put("params", params); - out.print(JsonUtil.loadTrueResult(data)); - } - -} +package com.yeshi.fanli.controller.wxmp.v1; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemPIDInfo; +import com.yeshi.fanli.service.manger.PIDManager; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.StringUtil; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.yeshi.fanli.dto.WXMPAcceptData; +import com.yeshi.fanli.entity.bus.homemodule.Special; +import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; +import com.yeshi.fanli.entity.common.JumpDetailV2; +import com.yeshi.fanli.entity.dynamic.GoodsPicture; +import com.yeshi.fanli.entity.dynamic.WXMPDynamicInfo; +import com.yeshi.fanli.exception.dynamic.WXMPDynamicInfoException; +import com.yeshi.fanli.log.LogHelper; +import com.yeshi.fanli.service.inter.dynamic.WXMPDynamicInfoService; +import com.yeshi.fanli.service.inter.homemodule.SpecialService; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.JumpDetailUtil; +import com.yeshi.fanli.util.jd.JDApiUtil; +import com.yeshi.fanli.vo.homemodule.SpecialVO; +import com.yeshi.common.vo.ClientTextStyleVO; + +import net.sf.json.JSONObject; + +@Controller("WXMPDynamicController") +@RequestMapping("/wxmp/api/v1/dynamic") +public class DynamicController { + + + + @Resource + private WXMPDynamicInfoService wxmpDynamicInfoService; + + @Resource + private SpecialService specialService; + + @Resource + private PIDManager pidManager; + + /** + * 棣栭〉涓撻 + * + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "getHotList") + public void getHotList(WXMPAcceptData acceptData, int page, PrintWriter out) { + + List<WXMPDynamicInfo> infoList = wxmpDynamicInfoService.listDynamicInfo(page, Constant.PAGE_SIZE); + for (WXMPDynamicInfo info : infoList) { + if (info.getImgs() != null) + for (GoodsPicture goodsPicture : info.getImgs()) { + JSONObject params = new JSONObject(); + if (goodsPicture.getGoodsVO() != null && goodsPicture.getJumpDetail() != null) { + params.put("id", goodsPicture.getGoodsVO().getGoodsId()); + goodsPicture.setJumpDetail(null); + goodsPicture.getGoodsVO().setImgList(null); + goodsPicture.getGoodsVO().setShopInfo(null); + goodsPicture.getGoodsVO().setCouponInfoList(null); + } + } + } + + long count = wxmpDynamicInfoService.countDynamicInfo(); + Gson gson = JsonUtil.getConvertDateToShortNameBuilder(JsonUtil + .getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder().excludeFieldsWithoutExposeAnnotation())) + .create(); + try { + JSONObject data = new JSONObject(); + data.put("list", gson.toJson(infoList)); + data.put("count", count); + data.put("page",page); + out.print(JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + out.print(JsonUtil.loadFalseResult(1, "鑾峰彇鏁版嵁澶辫触")); + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + + @RequestMapping(value = "copyText") + public void copyText(WXMPAcceptData acceptData, String id, Long uid, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); + return; + } + + if (StringUtil.isNullOrEmpty(id)) { + out.print(JsonUtil.loadFalseResult("鍟嗗搧ID鏈┖")); + return; + } + + try { + String content = wxmpDynamicInfoService.copyContent(id, uid); + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } catch (WXMPDynamicInfoException e) { + out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); + } + } + + @RequestMapping(value = "getActivityList") + public void getActivityList(WXMPAcceptData acceptData, int page, PrintWriter out) { + // 骞冲彴鍖哄垎 + int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); + List<String> listKey = new ArrayList<String>(); + listKey.add("special_channel_jd"); + listKey.add("special_channel_pdd"); + + List<SpecialVO> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, + listKey, platformCode, Integer.parseInt(acceptData.getVersion()),acceptData.getSystem()); + + long time = System.currentTimeMillis(); + + // 鍒犻櫎灏氭湭鍚敤鐨勮繃鏈熺殑 + for (int i = 0; i < list.size(); i++) { + SpecialVO special = list.get(i); + if (special.getJumpDetail() != null) { + special.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(special.getJumpDetail())); + } + + if (special.getState() == 1L) { + list.remove(i--); + } else { + if (special.getStartTime() != null && special.getEndTime() != null) { + if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { + list.remove(i--); + } else// 璁剧疆鍊掕鏃� + { + special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); + } + } + + List<SpecialLabel> listLabels = special.getListLabels(); + if (listLabels != null && !listLabels.isEmpty()) { + List<ClientTextStyleVO> labels = new ArrayList<>(); + for (SpecialLabel specialLabel : listLabels) { + labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); + } + special.setLabels(labels); + } + } + } + + long count = specialService.countByPlaceKeyList(listKey, platformCode, + Integer.parseInt(acceptData.getVersion()),acceptData.getSystem()); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + JSONObject data = new JSONObject(); + data.put("count", count); + data.put("page", page); + data.put("list", gson.toJson(list)); + out.print(JsonUtil.loadTrueResult(data)); + } + + @RequestMapping(value = "getActivityDetail") + public void getActivityDetail(WXMPAcceptData acceptData, Long uid, Long id, PrintWriter out) { + if (uid == null) + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); + if (id == null) + out.print(JsonUtil.loadFalseResult("娲诲姩ID涓虹┖")); + + Special special = specialService.selectByPrimaryKey(id); + if (special == null) { + out.print(JsonUtil.loadFalseResult("涓撻涓嶅瓨鍦�")); + return; + } + + JumpDetailV2 jumpDetail = special.getJumpDetail(); + jumpDetail.setActivity(null); + jumpDetail.setController(null); + String params = special.getParams(); + if (jumpDetail.getType().equalsIgnoreCase("jd")) {// 浜笢鐨勪笓棰樻椿鍔� + JSONObject paramsJson = JSONObject.fromObject(params); + // 浜笢杞摼 + String url = paramsJson.optString("url"); + String link = null; + try { + link = JDApiUtil.convertLinkWithSubUnionId(url, null, null, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli), uid + ""); + } catch (Exception e) { + e.printStackTrace(); + } + + if (StringUtil.isNullOrEmpty(link)) { + out.print(JsonUtil.loadFalseResult("杞摼澶辫触")); + return; + } + paramsJson.put("url", link); + params = paramsJson.toString(); + } + + JSONObject data = new JSONObject(); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + data.put("jumpDetail", gson.toJson(jumpDetail)); + data.put("params", params); + out.print(JsonUtil.loadTrueResult(data)); + } + +} -- Gitblit v1.8.0