| | |
| | | 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.msg.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<Special> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,
|
| | | listKey, platformCode, Integer.parseInt(acceptData.getVersion()));
|
| | |
|
| | | long time = System.currentTimeMillis();
|
| | |
|
| | | // 删除尚未启用的过期的
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | Special 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)
|
| | | special.setTimeTask(true);
|
| | | else
|
| | | special.setTimeTask(false);
|
| | |
|
| | | if (special.isTimeTask()) {
|
| | | 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()));
|
| | |
|
| | | 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)); |
| | | } |
| | | |
| | | } |