From 24587fd1b4af52469d1e122d2a495eea79d6865e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 24 七月 2023 14:39:30 +0800
Subject: [PATCH] 淘客返利场景修复
---
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java | 1037 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 541 insertions(+), 496 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java
index e6ef213..2a13229 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/PushController.java
@@ -1,496 +1,541 @@
-package com.yeshi.fanli.controller.client.v1;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.yeshi.utils.JsonUtil;
-import org.yeshi.utils.taobao.TbImgUtil;
-
-import com.google.gson.GsonBuilder;
-import com.yeshi.fanli.entity.accept.AcceptData;
-import com.yeshi.fanli.entity.bus.activity.ActivityUser;
-import com.yeshi.fanli.entity.common.JumpDetailV2;
-import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
-import com.yeshi.fanli.entity.dynamic.ImgInfo;
-import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
-import com.yeshi.fanli.entity.goods.CommonGoods;
-import com.yeshi.fanli.entity.push.DeviceActive;
-import com.yeshi.fanli.entity.push.DeviceTokenOPPO;
-import com.yeshi.fanli.entity.push.DeviceTokenVIVO;
-import com.yeshi.fanli.entity.push.DeviceTokenXM;
-import com.yeshi.fanli.entity.push.PushGoods;
-import com.yeshi.fanli.entity.push.PushGoodsGroup;
-import com.yeshi.fanli.entity.push.PushGoodsRecord;
-import com.yeshi.fanli.entity.system.BusinessSystem;
-import com.yeshi.fanli.entity.system.ConfigKeyEnum;
-import com.yeshi.fanli.exception.push.PushGoodsGroupException;
-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.dynamic.GoodsEvaluateService;
-import com.yeshi.fanli.service.inter.push.DeviceActiveService;
-import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
-import com.yeshi.fanli.service.inter.push.DeviceTokenOPPOService;
-import com.yeshi.fanli.service.inter.push.DeviceTokenVIVOService;
-import com.yeshi.fanli.service.inter.push.DeviceTokenXMService;
-import com.yeshi.fanli.service.inter.push.IOSPushService;
-import com.yeshi.fanli.service.inter.push.PushGoodsGroupService;
-import com.yeshi.fanli.service.inter.push.PushGoodsRecordService;
-import com.yeshi.fanli.service.inter.push.PushGoodsService;
-import com.yeshi.fanli.service.inter.push.PushRecordService;
-import com.yeshi.fanli.service.inter.push.PushService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TimeUtil;
-import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
-import com.yeshi.fanli.util.factory.JumpDetailParamsFactory;
-import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
-import com.yeshi.fanli.vo.push.PushRecommendVO;
-
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
-@Controller
-@RequestMapping(value = "api/v1/push")
-public class PushController {
- @Resource
- private BusinessSystemService businessSystemService;
-
- @Resource
- private PushRecordService pushRecordService;
-
- @Resource
- private IOSPushService iosPushService;
-
- @Resource
- private DeviceTokenHWService deviceTokenHWService;
-
- @Resource
- private DeviceActiveService deviceActiveService;
-
- @Resource
- private PushService pushService;
-
- @Resource
- private PushGoodsService pushGoodsService;
-
- @Resource
- private PushGoodsGroupService pushGoodsGroupService;
-
- @Resource
- private PushGoodsRecordService pushGoodsRecordService;
-
- @Resource
- private JumpDetailV2Service jumpDetailV2Service;
-
- @Resource
- private ConfigService configService;
-
- @Resource(name = "taskExecutor")
- private TaskExecutor executor;
-
- @Resource
- private DeviceTokenOPPOService deviceTokenOPPOService;
-
- @Resource
- private DeviceTokenVIVOService deviceTokenVIVOService;
-
- @Resource
- private DeviceTokenXMService deviceTokenXMService;
-
- @Resource
- private GoodsEvaluateService goodsEvaluateService;
-
-
- @RequestMapping(value = "callback", method = RequestMethod.POST)
- public void callback(AcceptData acceptData, String pushId, PrintWriter out) {
- BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
- acceptData.getPackages());
- if (system == null) {
- out.print(JsonUtil.loadFalseResult("涓嶅瓨鍦ㄨ绯荤粺"));
- return;
- }
- int platform = system.getPlatform();
- if (platform == 1) {
- pushRecordService.increaseByAndroid(pushId);
- } else {
- pushRecordService.increaseByIOS(pushId);
- }
- out.print(JsonUtil.loadTrueResult("鍥炶皟鎴愬姛"));
- }
-
- /**
- *
- * 鎻掑叆鑻规灉鎺ㄩ�佺殑deviceToken
- *
- * @author mawurui createTime 2018骞�5鏈�8鏃� 涓嬪崍4:15:44
- * @param deviceToken
- */
- @RequestMapping(value = "/insertDeviceToken", method = RequestMethod.POST)
- public void insertIOSDeviceToken(AcceptData acceptData, String deviceToken, PrintWriter out) {
- if (!StringUtil.isNullOrEmpty(acceptData.getDevice()) && !StringUtil.isNullOrEmpty(deviceToken)) {
- // 娣诲姞璁惧娲昏穬璁板綍
- iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), deviceToken,
- acceptData.getDevice());
- out.print(JsonUtil.loadTrue(0, null, "鎴愬姛"));
- }
- }
-
- /**
- * IOS鎺ㄩ�� 鏂规硶璇存槑: 灏嗙敤鎴穒d鍜宒eviceToken缁戝畾
- *
- * @author mawurui createTime 2018骞�5鏈�8鏃� 涓嬪崍4:29:45
- * @param uid
- * @param deviceToken
- */
- @RequestSerializableByKey(key = "#acceptData.device")
- @RequestMapping(value = "/uidBindDeviceToken", method = RequestMethod.POST)
- public void uidBindIOSDeviceToken(AcceptData acceptData, Long uid, String deviceToken, PrintWriter out) {
- if (uid != null && uid != 0 && !StringUtil.isNullOrEmpty(deviceToken)) {
- // 娣诲姞token
- iosPushService.addDeviceToken(uid, Integer.parseInt(acceptData.getVersion()), deviceToken,
- acceptData.getDevice());
- }
- }
-
- /**
- * IOS鎺ㄩ�� 鏂规硶璇存槑: 瑙g粦
- *
- * @author mawurui createTime 2018骞�5鏈�9鏃� 涓婂崍9:49:58
- * @param deviceToken
- */
- @RequestMapping(value = "/unBind", method = RequestMethod.POST)
- public void unBind(AcceptData acceptData, String deviceToken, PrintWriter out) {
- if (!StringUtil.isNullOrEmpty(acceptData.getDevice())) {
- iosPushService.unBindUidAndDevice(acceptData.getDevice());
- out.print(JsonUtil.loadTrue(0, null, "瑙g粦鎴愬姛"));
- }
- }
-
- /**
- * 缁戝畾鍗庝负鎺ㄩ��
- *
- * @param acceptData
- * @param token
- * -鍗庝负token
- * @param uid
- * -鐢ㄦ埛ID
- * @param out
- */
- @RequestSerializableByKey(key = "#acceptData.device")
- @RequestMapping(value = "/bindHWPush", method = RequestMethod.POST)
- public void bindHWDeviceToken(AcceptData acceptData, String token, Long uid, PrintWriter out) {
- deviceTokenHWService.addDeviceToken(token, acceptData.getDevice(), uid,
- Integer.parseInt(acceptData.getVersion()));
- out.print(JsonUtil.loadTrueResult("鎴愬姛"));
- }
-
- /**
- * 瑙g粦鎺ㄩ��
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "/unBindHWPush", method = RequestMethod.POST)
- public void unBindHWDeviceToken(AcceptData acceptData, PrintWriter out) {
- deviceTokenHWService.unBindDeviceToken(acceptData.getDevice());
- out.print(JsonUtil.loadTrueResult("鎴愬姛"));
- }
-
- /**
- * 鍟嗗搧鎺ㄩ�佽褰�
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "/gethistory", method = RequestMethod.POST)
- public void getHistory(AcceptData acceptData, Long uid, String deviceToken, int page, PrintWriter out) {
- long count = 0;
- JSONArray resultList = new JSONArray();
- DeviceActive deviceActive = deviceActiveService.getDeviceByDeviceAndPlatform(acceptData.getDevice(),
- deviceToken, acceptData.getPlatform());
-
- if (deviceActive == null) {
- JSONObject resultJson = new JSONObject();
- resultJson.put("count", count);
- resultJson.put("result_list", resultList);
- out.print(JsonUtil.loadTrueResult(resultJson));
- return;
- }
-
- // 璁惧娉ㄥ唽鏃堕棿
- Date createTime = deviceActive.getCreateTime();
- count = pushGoodsService.countHistoryByPushTime(uid, createTime);
-
- int pageSize = Constant.PAGE_SIZE;
- List<PushGoods> list = pushGoodsService.listHistoryByPushTime((page - 1) * pageSize, pageSize, uid, createTime);
- if (list == null)
- list = new ArrayList<>();
-
- for (PushGoods pushGoods : list) {
- Long id = pushGoods.getId();
-
- PushRecommendVO vo = new PushRecommendVO();
- vo.setTitle(pushGoods.getTitle());
- vo.setContent(pushGoods.getContent());
- vo.setPicture(pushGoods.getPicture());
- vo.setPushtime(pushGoods.getPushTime().getTime());
-
- Integer scanNum = pushGoods.getScanNum();
- if (scanNum == null) {
-// vo.setScanNum("0");
- } else if (scanNum >= 10000) {
- double num = scanNum;
- String numMidea = String.format("%.1f", num / 10000);
- vo.setScanNum(numMidea + "涓�");
- } else {
- vo.setScanNum(scanNum +"");
- }
-
-
- String params = "";
- String nickName = "";
- JumpDetailV2 jumpDetail = null;
- List<ClientTextStyleVO> totalwords = new ArrayList<ClientTextStyleVO>();
-
- Integer type = pushGoods.getType();
- if (type == null || type == PushGoods.TYPE_GOODS) {
- long totalgoods = 0;
- CommonGoods goods = null;
- try {
- List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(id);
- if (listGroup != null && listGroup.size() > 0) {
- totalgoods = listGroup.size();
- PushGoodsGroup pushGoodsGroup = listGroup.get(0);
- if (pushGoodsGroup != null) {
- goods = pushGoodsGroup.getCommonGoods();
- }
- }
- } catch (PushGoodsGroupException e) {
- e.printStackTrace();
- }
-
- if (goods != null && StringUtil.isNullOrEmpty(vo.getPicture())) {
- vo.setPicture(TbImgUtil.getTBSize320Img(goods.getPicture()));
- }
-
- if (totalgoods == 1) {
- params = JumpDetailParamsFactory.createGoodsParams(goods.getGoodsId(), goods.getGoodsType());
- jumpDetail = jumpDetailV2Service.getByTypeCache("goodsdetail",Constant.getPlatformCode(acceptData.getPlatform()),
- Integer.parseInt(acceptData.getVersion()));
- } else {
- String url = configService.get(ConfigKeyEnum.pushGoodsDetails.getKey());
- if (url == null) {
- url = "";
- }
- url = url + "?id=" + id;
-
- params = JumpDetailParamsFactory.createWEBParams(url);
- jumpDetail = jumpDetailV2Service.getByTypeCache("web",Constant.getPlatformCode(acceptData.getPlatform()),
- Integer.parseInt(acceptData.getVersion()));
- }
-
- totalwords.add(new ClientTextStyleVO("鏈鎺ㄨ崘鍏�", "#666666"));
- totalwords.add(new ClientTextStyleVO(totalgoods + "", "#E5005C"));
- totalwords.add(new ClientTextStyleVO("涓晢鍝�", "#666666"));
- } else if (type == PushGoods.TYPE_ACTIVITY) {
- GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pushGoods.getOtherId());
- if (goodsEvaluate == null) {
- continue;
- }
- ActivityUser user = goodsEvaluate.getUser();
- if (user != null) {
- nickName = user.getNickName();
- }
-
- if (StringUtil.isNullOrEmpty(vo.getPicture()) && goodsEvaluate.getImgList() != null &&
- goodsEvaluate.getImgList().size() > 0) {
- for (ImgInfo tmgInfo: goodsEvaluate.getImgList()) {
- if (tmgInfo.getType() == ImgEnum.img || tmgInfo.getType() == ImgEnum.activity) {
- vo.setPicture(tmgInfo.getUrl());
- }
- }
- }
-
- String url = configService.get(ConfigKeyEnum.pushActivityLink.getKey());
- if (url == null) {
- url = "";
- }
- url = url + "?id=" + id;
- params = JumpDetailParamsFactory.createWEBParams(url);
- jumpDetail = jumpDetailV2Service.getByTypeCache("web",
- Constant.getPlatformCode(acceptData.getPlatform()), Integer.parseInt(acceptData.getVersion()));
- } else {
- continue;
- }
- vo.setNickName(nickName);
- vo.setParams(params);
- vo.setJumpDetail(jumpDetail);
- vo.setTotalwords(totalwords);
- resultList.add(vo);
- }
-
- JSONObject resultJson = new JSONObject();
- resultJson.put("count", count);
- resultJson.put("result_list", resultList);
- out.print(JsonUtil.loadTrueResult(resultJson));
-
-
- if (list != null && list.size() > 0 && deviceActive != null) {
- final List<PushGoods> listPush = list;
- // 璁板綍璁块棶淇℃伅
- executor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- Long deviceId = deviceActive.getId();
- for (PushGoods pushGoods : listPush) {
- List<PushGoodsRecord> listRecord = pushGoodsRecordService
- .listByPushIdAndDeviceId(pushGoods.getId(), deviceId);
- if (listRecord != null && listRecord.size() > 0) {
- continue; // 宸茶璁板綍
- }
-
- PushGoodsRecord pushGoodsRecord = new PushGoodsRecord();
-
- pushGoodsRecord.setCreateTime(new Date());
- pushGoodsRecord.setPushGoods(pushGoods);
- pushGoodsRecord.setDeviceActive(deviceActive);
- pushGoodsRecordService.insert(pushGoodsRecord);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
-
- @RequestMapping("registerOppo")
- public void registerOppo(AcceptData acceptData, String registerId, Long uid, PrintWriter out) {
- DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
- if (deviceActive != null) {
- DeviceTokenOPPO oppo = new DeviceTokenOPPO();
- oppo.setDeviceActiveId(deviceActive.getId());
- oppo.setRegisterId(registerId);
- oppo.setUid(uid);
- deviceTokenOPPOService.addDeviceTokenOPPO(oppo);
- }
- out.print(JsonUtil.loadTrueResult(""));
- }
-
- @RequestMapping("registerVivo")
- public void registerVivo(AcceptData acceptData, String regId, Long uid, PrintWriter out) {
- DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
- if (deviceActive != null) {
- DeviceTokenVIVO vivo = new DeviceTokenVIVO();
- vivo.setDeviceActiveId(deviceActive.getId());
- vivo.setRegisterId(regId);
- vivo.setUid(uid);
- deviceTokenVIVOService.addDeviceTokenVIVO(vivo);
- }
- out.print(JsonUtil.loadTrueResult(""));
- }
-
- @RequestMapping("registerXM")
- public void registerXM(AcceptData acceptData, String regId, Long uid, PrintWriter out) {
- DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
- if (deviceActive != null) {
- DeviceTokenXM xm = new DeviceTokenXM();
- xm.setDeviceActiveId(deviceActive.getId());
- xm.setRegisterId(regId);
- xm.setUid(uid);
- deviceTokenXMService.addDeviceToken(xm);
- }
- out.print(JsonUtil.loadTrueResult(""));
- }
-
- /**
- * 鑾峰彇鎺ㄩ�佹椿鍔ㄨ鎯�
- * @param callback
- * @param acceptData
- * @param uid
- * @param id
- * @param out
- */
- @RequestMapping("getPushDetail")
- public void getPushDetail(String callback, AcceptData acceptData, Long uid, Long id, PrintWriter out) {
- if (uid == null || id == null) {
- JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("鍙傛暟涓嶅畬鏁�"));
- return;
- }
-
- PushGoods pushGoods = pushGoodsService.selectByPrimaryKey(id);
- if (pushGoods == null || StringUtil.isNullOrEmpty(pushGoods.getOtherId())) {
- JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("璇ユ椿鍔ㄥ凡涓嬫灦"));
- return;
- }
-
- GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pushGoods.getOtherId());
- if (goodsEvaluate == null) {
- JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("璇ユ椿鍔ㄥ凡涓嬫灦"));
- return;
- }
-
- String scanResult = null;
- Integer scanNum = pushGoods.getScanNum();
- if (scanNum == null) {
- } else if (scanNum >= 10000) {
- double num = scanNum;
- String numMidea = String.format("%.1f", num / 10000);
- scanResult = numMidea + "涓�";
- } else {
- scanResult = scanNum +"";
- }
-
- String jumpLink = configService.get(ConfigKeyEnum.activityDetailLink.getKey()) + "?type=%s&id=%s";
- jumpLink = String.format(jumpLink, "circle", goodsEvaluate.getId());
- if (!StringUtil.isNullOrEmpty(goodsEvaluate.getJumpLink())) {
- goodsEvaluate.setJumpLink(jumpLink);
- }
-
- List<ImgInfo> imgListNew = new ArrayList<>();
- List<ImgInfo> imgList = goodsEvaluate.getImgList();
- if (imgList != null && imgList.size() > 0) {
- for (ImgInfo imgInfo: imgList) {
- if (imgInfo.getType() != ImgEnum.img || imgInfo.getType() == ImgEnum.activity) {
- ImgInfo imgInfoNew = new ImgInfo();
- try {
- PropertyUtils.copyProperties(imgInfoNew, imgInfo);
- } catch (Exception e) {
- e.printStackTrace();
- continue;
- }
-
- if (!StringUtil.isNullOrEmpty(imgInfoNew.getActivityUrl())) {
- imgInfoNew.setActivityUrl(jumpLink);
- }
-
- imgListNew.add(imgInfoNew);
- continue;
- }
- imgListNew.add(imgInfo);
- }
- }
- goodsEvaluate.setImgList(imgListNew);
-
- GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
-
- JSONObject json = new JSONObject();
- json.put("title", pushGoods.getTitle());
- json.put("content", pushGoods.getContent());
- json.put("pushTime", TimeUtil.formatDate(pushGoods.getPushTime()));
- json.put("scanNum", scanResult);
- json.put("detailInfo", gsonBuilder.create().toJson(goodsEvaluate));
- JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(json));
- }
-}
+package com.yeshi.fanli.controller.client.v1;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.ks.push.pojo.DO.BPushDeviceToken;
+import com.ks.push.pojo.DO.PushPlatform;
+import com.ks.push.service.BDeviceTokenService;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.dubbo.config.annotation.Reference;
+import org.springframework.core.task.TaskExecutor;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.taobao.TbImgUtil;
+
+import com.google.gson.GsonBuilder;
+import com.yeshi.fanli.entity.accept.AcceptData;
+import com.yeshi.fanli.entity.bus.activity.ActivityUser;
+import com.yeshi.fanli.entity.common.JumpDetailV2;
+import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
+import com.yeshi.fanli.entity.dynamic.ImgInfo;
+import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
+import com.yeshi.fanli.entity.goods.CommonGoods;
+import com.yeshi.fanli.entity.push.DeviceActive;
+import com.yeshi.fanli.entity.push.DeviceTokenOPPO;
+import com.yeshi.fanli.entity.push.DeviceTokenVIVO;
+import com.yeshi.fanli.entity.push.DeviceTokenXM;
+import com.yeshi.fanli.entity.push.PushGoods;
+import com.yeshi.fanli.entity.push.PushGoodsGroup;
+import com.yeshi.fanli.entity.push.PushGoodsRecord;
+import com.yeshi.fanli.entity.system.BusinessSystem;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.exception.push.PushGoodsGroupException;
+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.dynamic.GoodsEvaluateService;
+import com.yeshi.fanli.service.inter.push.DeviceActiveService;
+import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
+import com.yeshi.fanli.service.inter.push.DeviceTokenOPPOService;
+import com.yeshi.fanli.service.inter.push.DeviceTokenVIVOService;
+import com.yeshi.fanli.service.inter.push.DeviceTokenXMService;
+import com.yeshi.fanli.service.inter.push.IOSPushService;
+import com.yeshi.fanli.service.inter.push.PushGoodsGroupService;
+import com.yeshi.fanli.service.inter.push.PushGoodsRecordService;
+import com.yeshi.fanli.service.inter.push.PushGoodsService;
+import com.yeshi.fanli.service.inter.push.PushRecordService;
+import com.yeshi.fanli.service.inter.push.PushService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
+import org.yeshi.utils.TimeUtil;
+import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
+import com.yeshi.fanli.util.factory.JumpDetailParamsFactory;
+import com.yeshi.common.vo.ClientTextStyleVO;
+import com.yeshi.fanli.vo.push.PushRecommendVO;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+@Controller
+@RequestMapping(value = "api/v1/push")
+public class PushController {
+ @Resource
+ private BusinessSystemService businessSystemService;
+
+ @Resource
+ private PushRecordService pushRecordService;
+
+ @Resource
+ private IOSPushService iosPushService;
+
+ @Resource
+ private DeviceTokenHWService deviceTokenHWService;
+
+ @Resource
+ private DeviceActiveService deviceActiveService;
+
+ @Resource
+ private PushService pushService;
+
+ @Resource
+ private PushGoodsService pushGoodsService;
+
+ @Resource
+ private PushGoodsGroupService pushGoodsGroupService;
+
+ @Resource
+ private PushGoodsRecordService pushGoodsRecordService;
+
+ @Resource
+ private JumpDetailV2Service jumpDetailV2Service;
+
+ @Resource
+ private ConfigService configService;
+
+ @Resource(name = "taskExecutor")
+ private TaskExecutor executor;
+
+ @Resource
+ private DeviceTokenOPPOService deviceTokenOPPOService;
+
+ @Resource
+ private DeviceTokenVIVOService deviceTokenVIVOService;
+
+ @Resource
+ private DeviceTokenXMService deviceTokenXMService;
+
+ @Resource
+ private GoodsEvaluateService goodsEvaluateService;
+
+ @Reference(version = "1.0", check = false)
+ private BDeviceTokenService bDeviceTokenService;
+
+ /**
+ * 搴楅摵鍒楄〃
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "bindToken", method = RequestMethod.POST)
+ public void bindToken(AcceptData acceptData, Long uid, String type, String token, PrintWriter out) {
+ BPushDeviceToken deviceToken = new BPushDeviceToken();
+ deviceToken.setAppCode(acceptData.getSystem().name());
+ deviceToken.setDeviceId(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid());
+ deviceToken.setBuildModel(acceptData.getDeviceType());
+ deviceToken.setBuildVersion(acceptData.getOsVersion());
+ deviceToken.setToken(token);
+ switch (type) {
+ case "huawei":
+ type = "hw";
+ break;
+ case "xiaomi":
+ type = "xm";
+ break;
+ case "meizu":
+ type = "mz";
+ break;
+ }
+ deviceToken.setType(PushPlatform.valueOf(type));
+ deviceToken.setUid(uid + "");
+ deviceToken.setVersionCode(Integer.parseInt(acceptData.getVersion()));
+ try {
+ bDeviceTokenService.save(deviceToken);
+ out.print(JsonUtil.loadTrueResult(""));
+ } catch (Exception e) {
+ out.print(JsonUtil.loadFalseResult("缁戝畾鍑洪敊锛�" + e.getMessage()));
+ e.printStackTrace();
+ }
+ }
+
+
+
+ @RequestMapping(value = "callback", method = RequestMethod.POST)
+ public void callback(AcceptData acceptData, String pushId, PrintWriter out) {
+ BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
+ acceptData.getPackages(),acceptData.getSystem());
+ if (system == null) {
+ out.print(JsonUtil.loadFalseResult("涓嶅瓨鍦ㄨ绯荤粺"));
+ return;
+ }
+ int platform = system.getPlatform();
+ if (platform == 1) {
+ pushRecordService.increaseByAndroid(pushId);
+ } else {
+ pushRecordService.increaseByIOS(pushId);
+ }
+ out.print(JsonUtil.loadTrueResult("鍥炶皟鎴愬姛"));
+ }
+
+ /**
+ *
+ * 鎻掑叆鑻规灉鎺ㄩ�佺殑deviceToken
+ *
+ * @author mawurui createTime 2018骞�5鏈�8鏃� 涓嬪崍4:15:44
+ * @param deviceToken
+ */
+ @RequestMapping(value = "/insertDeviceToken", method = RequestMethod.POST)
+ public void insertIOSDeviceToken(AcceptData acceptData, String deviceToken, PrintWriter out) {
+ if (!StringUtil.isNullOrEmpty(acceptData.getDevice()) && !StringUtil.isNullOrEmpty(deviceToken)) {
+ // 娣诲姞璁惧娲昏穬璁板綍
+ iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), deviceToken,
+ acceptData.getDevice());
+ out.print(JsonUtil.loadTrue(0, null, "鎴愬姛"));
+ }
+ }
+
+ /**
+ * IOS鎺ㄩ�� 鏂规硶璇存槑: 灏嗙敤鎴穒d鍜宒eviceToken缁戝畾
+ *
+ * @author mawurui createTime 2018骞�5鏈�8鏃� 涓嬪崍4:29:45
+ * @param uid
+ * @param deviceToken
+ */
+ @RequestSerializableByKey(key = "#acceptData.device")
+ @RequestMapping(value = "/uidBindDeviceToken", method = RequestMethod.POST)
+ public void uidBindIOSDeviceToken(AcceptData acceptData, Long uid, String deviceToken, PrintWriter out) {
+ if (uid != null && uid != 0 && !StringUtil.isNullOrEmpty(deviceToken)) {
+ // 娣诲姞token
+ iosPushService.addDeviceToken(uid, Integer.parseInt(acceptData.getVersion()), deviceToken,
+ acceptData.getDevice());
+ }
+ }
+
+ /**
+ * IOS鎺ㄩ�� 鏂规硶璇存槑: 瑙g粦
+ *
+ * @author mawurui createTime 2018骞�5鏈�9鏃� 涓婂崍9:49:58
+ * @param deviceToken
+ */
+ @RequestMapping(value = "/unBind", method = RequestMethod.POST)
+ public void unBind(AcceptData acceptData, String deviceToken, PrintWriter out) {
+ if (!StringUtil.isNullOrEmpty(acceptData.getDevice())) {
+ iosPushService.unBindUidAndDevice(acceptData.getDevice());
+ out.print(JsonUtil.loadTrue(0, null, "瑙g粦鎴愬姛"));
+ }
+ }
+
+ /**
+ * 缁戝畾鍗庝负鎺ㄩ��
+ *
+ * @param acceptData
+ * @param token
+ * -鍗庝负token
+ * @param uid
+ * -鐢ㄦ埛ID
+ * @param out
+ */
+ @RequestSerializableByKey(key = "#acceptData.device")
+ @RequestMapping(value = "/bindHWPush", method = RequestMethod.POST)
+ public void bindHWDeviceToken(AcceptData acceptData, String token, Long uid, PrintWriter out) {
+ deviceTokenHWService.addDeviceToken(token, acceptData.getDevice(), uid,
+ Integer.parseInt(acceptData.getVersion()));
+ out.print(JsonUtil.loadTrueResult("鎴愬姛"));
+ }
+
+ /**
+ * 瑙g粦鎺ㄩ��
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "/unBindHWPush", method = RequestMethod.POST)
+ public void unBindHWDeviceToken(AcceptData acceptData, PrintWriter out) {
+ deviceTokenHWService.unBindDeviceToken(acceptData.getDevice());
+ out.print(JsonUtil.loadTrueResult("鎴愬姛"));
+ }
+
+ /**
+ * 鍟嗗搧鎺ㄩ�佽褰�
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "/gethistory", method = RequestMethod.POST)
+ public void getHistory(AcceptData acceptData, Long uid, String deviceToken, int page, PrintWriter out) {
+ long count = 0;
+ JSONArray resultList = new JSONArray();
+ DeviceActive deviceActive = deviceActiveService.getDeviceByDeviceAndPlatform(acceptData.getDevice(),
+ deviceToken, acceptData.getPlatform());
+
+ if (deviceActive == null) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("count", count);
+ resultJson.put("result_list", resultList);
+ out.print(JsonUtil.loadTrueResult(resultJson));
+ return;
+ }
+
+ // 璁惧娉ㄥ唽鏃堕棿
+ Date createTime = deviceActive.getCreateTime();
+ count = pushGoodsService.countHistoryByPushTime(uid, createTime,acceptData.getSystem());
+
+ int pageSize = Constant.PAGE_SIZE;
+ List<PushGoods> list = pushGoodsService.listHistoryByPushTime((page - 1) * pageSize, pageSize, uid, createTime,acceptData.getSystem());
+ if (list == null)
+ list = new ArrayList<>();
+
+ for (PushGoods pushGoods : list) {
+ Long id = pushGoods.getId();
+
+ PushRecommendVO vo = new PushRecommendVO();
+ vo.setTitle(pushGoods.getTitle());
+ vo.setContent(pushGoods.getContent());
+ vo.setPicture(pushGoods.getPicture());
+ vo.setPushtime(pushGoods.getPushTime().getTime());
+
+ Integer scanNum = pushGoods.getScanNum();
+ if (scanNum == null) {
+// vo.setScanNum("0");
+ } else if (scanNum >= 10000) {
+ double num = scanNum;
+ String numMidea = String.format("%.1f", num / 10000);
+ vo.setScanNum(numMidea + "涓�");
+ } else {
+ vo.setScanNum(scanNum +"");
+ }
+
+
+ String params = "";
+ String nickName = "";
+ JumpDetailV2 jumpDetail = null;
+ List<ClientTextStyleVO> totalwords = new ArrayList<ClientTextStyleVO>();
+
+ Integer type = pushGoods.getType();
+ if (type == null || type == PushGoods.TYPE_GOODS) {
+ long totalgoods = 0;
+ CommonGoods goods = null;
+ try {
+ List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(id);
+ if (listGroup != null && listGroup.size() > 0) {
+ totalgoods = listGroup.size();
+ PushGoodsGroup pushGoodsGroup = listGroup.get(0);
+ if (pushGoodsGroup != null) {
+ goods = pushGoodsGroup.getCommonGoods();
+ }
+ }
+ } catch (PushGoodsGroupException e) {
+ e.printStackTrace();
+ }
+
+ if (goods != null && StringUtil.isNullOrEmpty(vo.getPicture())) {
+ vo.setPicture(TbImgUtil.getTBSize320Img(goods.getPicture()));
+ }
+
+ if (totalgoods == 1) {
+ params = JumpDetailParamsFactory.createGoodsParams(goods.getGoodsId(), goods.getGoodsType());
+ jumpDetail = jumpDetailV2Service.getByTypeCache("goodsdetail",Constant.getPlatformCode(acceptData.getPlatform()),
+ Integer.parseInt(acceptData.getVersion()),acceptData.getSystem());
+ } else {
+ String url = configService.getValue(ConfigKeyEnum.pushGoodsDetails.getKey(),acceptData.getSystem());
+ if (url == null) {
+ url = "";
+ }
+ url = url + "?id=" + id;
+
+ params = JumpDetailParamsFactory.createWEBParams(url);
+ jumpDetail = jumpDetailV2Service.getByTypeCache("web",Constant.getPlatformCode(acceptData.getPlatform()),
+ Integer.parseInt(acceptData.getVersion()),acceptData.getSystem());
+ }
+
+ totalwords.add(new ClientTextStyleVO("鏈鎺ㄨ崘鍏�", "#666666"));
+ totalwords.add(new ClientTextStyleVO(totalgoods + "", "#E5005C"));
+ totalwords.add(new ClientTextStyleVO("涓晢鍝�", "#666666"));
+ } else if (type == PushGoods.TYPE_ACTIVITY) {
+ GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pushGoods.getOtherId());
+ if (goodsEvaluate == null) {
+ continue;
+ }
+ ActivityUser user = goodsEvaluate.getUser();
+ if (user != null) {
+ nickName = user.getNickName();
+ }
+
+ if (StringUtil.isNullOrEmpty(vo.getPicture()) && goodsEvaluate.getImgList() != null &&
+ goodsEvaluate.getImgList().size() > 0) {
+ for (ImgInfo tmgInfo: goodsEvaluate.getImgList()) {
+ if (tmgInfo.getType() == ImgEnum.img || tmgInfo.getType() == ImgEnum.activity) {
+ vo.setPicture(tmgInfo.getUrl());
+ }
+ }
+ }
+
+ String url = configService.getValue(ConfigKeyEnum.pushActivityLink.getKey(),acceptData.getSystem());
+ if (url == null) {
+ url = "";
+ }
+ url = url + "?id=" + id;
+ params = JumpDetailParamsFactory.createWEBParams(url);
+ jumpDetail = jumpDetailV2Service.getByTypeCache("web",
+ Constant.getPlatformCode(acceptData.getPlatform()), Integer.parseInt(acceptData.getVersion()),acceptData.getSystem());
+ } else {
+ continue;
+ }
+ vo.setNickName(nickName);
+ vo.setParams(params);
+ vo.setJumpDetail(jumpDetail);
+ vo.setTotalwords(totalwords);
+ resultList.add(vo);
+ }
+
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("count", count);
+ resultJson.put("result_list", resultList);
+ out.print(JsonUtil.loadTrueResult(resultJson));
+
+
+ if (list != null && list.size() > 0 && deviceActive != null) {
+ final List<PushGoods> listPush = list;
+ // 璁板綍璁块棶淇℃伅
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Long deviceId = deviceActive.getId();
+ for (PushGoods pushGoods : listPush) {
+ List<PushGoodsRecord> listRecord = pushGoodsRecordService
+ .listByPushIdAndDeviceId(pushGoods.getId(), deviceId);
+ if (listRecord != null && listRecord.size() > 0) {
+ continue; // 宸茶璁板綍
+ }
+
+ PushGoodsRecord pushGoodsRecord = new PushGoodsRecord();
+
+ pushGoodsRecord.setCreateTime(new Date());
+ pushGoodsRecord.setPushGoods(pushGoods);
+ pushGoodsRecord.setDeviceActive(deviceActive);
+ pushGoodsRecordService.insert(pushGoodsRecord);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ }
+
+ @RequestMapping("registerOppo")
+ public void registerOppo(AcceptData acceptData, String registerId, Long uid, PrintWriter out) {
+ DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
+ if (deviceActive != null) {
+ DeviceTokenOPPO oppo = new DeviceTokenOPPO();
+ oppo.setDeviceActiveId(deviceActive.getId());
+ oppo.setRegisterId(registerId);
+ oppo.setUid(uid);
+ deviceTokenOPPOService.addDeviceTokenOPPO(oppo);
+ }
+ out.print(JsonUtil.loadTrueResult(""));
+ }
+
+ @RequestMapping("registerVivo")
+ public void registerVivo(AcceptData acceptData, String regId, Long uid, PrintWriter out) {
+ DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
+ if (deviceActive != null) {
+ DeviceTokenVIVO vivo = new DeviceTokenVIVO();
+ vivo.setDeviceActiveId(deviceActive.getId());
+ vivo.setRegisterId(regId);
+ vivo.setUid(uid);
+ deviceTokenVIVOService.addDeviceTokenVIVO(vivo);
+ }
+ out.print(JsonUtil.loadTrueResult(""));
+ }
+
+ @RequestMapping("registerXM")
+ public void registerXM(AcceptData acceptData, String regId, Long uid, PrintWriter out) {
+ DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
+ if (deviceActive != null) {
+ DeviceTokenXM xm = new DeviceTokenXM();
+ xm.setDeviceActiveId(deviceActive.getId());
+ xm.setRegisterId(regId);
+ xm.setUid(uid);
+ deviceTokenXMService.addDeviceToken(xm);
+ }
+ out.print(JsonUtil.loadTrueResult(""));
+ }
+
+ /**
+ * 鑾峰彇鎺ㄩ�佹椿鍔ㄨ鎯�
+ * @param callback
+ * @param acceptData
+ * @param uid
+ * @param id
+ * @param out
+ */
+ @RequestMapping("getPushDetail")
+ public void getPushDetail(String callback, AcceptData acceptData, Long uid, Long id, PrintWriter out) {
+ if (uid == null || id == null) {
+ JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("鍙傛暟涓嶅畬鏁�"));
+ return;
+ }
+
+ PushGoods pushGoods = pushGoodsService.selectByPrimaryKey(id);
+ if (pushGoods == null || StringUtil.isNullOrEmpty(pushGoods.getOtherId())) {
+ JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("璇ユ椿鍔ㄥ凡涓嬫灦"));
+ return;
+ }
+
+ GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pushGoods.getOtherId());
+ if (goodsEvaluate == null) {
+ JsonUtil.printMode(out, callback,JsonUtil.loadFalseResult("璇ユ椿鍔ㄥ凡涓嬫灦"));
+ return;
+ }
+
+ String scanResult = null;
+ Integer scanNum = pushGoods.getScanNum();
+ if (scanNum == null) {
+ } else if (scanNum >= 10000) {
+ double num = scanNum;
+ String numMidea = String.format("%.1f", num / 10000);
+ scanResult = numMidea + "涓�";
+ } else {
+ scanResult = scanNum +"";
+ }
+
+ String jumpLink = configService.getValue(ConfigKeyEnum.activityDetailLink.getKey(),acceptData.getSystem()) + "?type=%s&id=%s";
+ jumpLink = String.format(jumpLink, "circle", goodsEvaluate.getId());
+ if (!StringUtil.isNullOrEmpty(goodsEvaluate.getJumpLink())) {
+ goodsEvaluate.setJumpLink(jumpLink);
+ }
+
+ List<ImgInfo> imgListNew = new ArrayList<>();
+ List<ImgInfo> imgList = goodsEvaluate.getImgList();
+ if (imgList != null && imgList.size() > 0) {
+ for (ImgInfo imgInfo: imgList) {
+ if (imgInfo.getType() != ImgEnum.img || imgInfo.getType() == ImgEnum.activity) {
+ ImgInfo imgInfoNew = new ImgInfo();
+ try {
+ PropertyUtils.copyProperties(imgInfoNew, imgInfo);
+ } catch (Exception e) {
+ e.printStackTrace();
+ continue;
+ }
+
+ if (!StringUtil.isNullOrEmpty(imgInfoNew.getActivityUrl())) {
+ imgInfoNew.setActivityUrl(jumpLink);
+ }
+
+ imgListNew.add(imgInfoNew);
+ continue;
+ }
+ imgListNew.add(imgInfo);
+ }
+ }
+ goodsEvaluate.setImgList(imgListNew);
+
+ GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
+
+ JSONObject json = new JSONObject();
+ json.put("title", pushGoods.getTitle());
+ json.put("content", pushGoods.getContent());
+ json.put("pushTime", TimeUtil.formatDate(pushGoods.getPushTime()));
+ json.put("scanNum", scanResult);
+ json.put("detailInfo", gsonBuilder.create().toJson(goodsEvaluate));
+ JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(json));
+ }
+}
--
Gitblit v1.8.0