From 18738585b455edb5c576ea1b327441122e455055 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 13 十二月 2018 18:09:35 +0800
Subject: [PATCH] 增加首页邀请入口的banner图片
---
fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java | 253 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 225 insertions(+), 28 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java
index 29101da..dda8ea9 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/PushController.java
@@ -1,22 +1,43 @@
package com.yeshi.fanli.controller.client;
import java.io.PrintWriter;
+import java.util.Date;
+import java.util.List;
import javax.annotation.Resource;
+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 com.yeshi.fanli.entity.accept.AcceptData;
-import com.yeshi.fanli.entity.push.DeviceTokenIOS;
+import com.yeshi.fanli.entity.common.JumpDetailV2;
+import com.yeshi.fanli.entity.goods.CommonGoods;
+import com.yeshi.fanli.entity.push.DeviceActive;
+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.System;
+import com.yeshi.fanli.exception.push.PushGoodsGroupException;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemService;
+import com.yeshi.fanli.service.inter.push.DeviceActiveService;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
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.JsonUtil;
+import com.yeshi.fanli.util.factory.JumpDetailParamsFactory;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
@Controller
@RequestMapping(value = "api/v1/push")
@@ -33,6 +54,30 @@
@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;
@RequestMapping(value = "callback", method = RequestMethod.POST)
public void callback(AcceptData acceptData, String pushId, PrintWriter out) {
@@ -60,14 +105,15 @@
@RequestMapping(value = "/insertDeviceToken", method = RequestMethod.POST)
public void insertIOSDeviceToken(AcceptData acceptData, String deviceToken, PrintWriter out) {
if (!StringUtil.isNullOrEmpty(acceptData.getDevice()) && !StringUtil.isNullOrEmpty(deviceToken)) {
- DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
- if (deviceTokenIOS == null)
- iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), deviceToken,
- acceptData.getDevice());
- else {
- deviceTokenIOS.setDeviceToken(deviceToken);
- iosPushService.updateDeviceToken(deviceTokenIOS);
- }
+ // 娣诲姞璁惧娲昏穬璁板綍
+ DeviceActive da = new DeviceActive();
+ da.setDeviceToken(deviceToken);
+ da.setPlatform(DeviceActive.PLATFORM_IOS);
+ da.setVersionCode(Integer.parseInt(acceptData.getVersion()));
+ da.setDevice(acceptData.getDevice());
+ deviceActiveService.addDeviceActive(da);
+ iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), deviceToken,
+ acceptData.getDevice());
out.print(JsonUtil.loadTrue(0, null, "鎴愬姛"));
}
}
@@ -80,21 +126,19 @@
* @param deviceToken
*/
- // 浼犱竴涓猟evice 濡傛灉瀛樺湪device 鏍规嵁device鎵цupdate鎿嶄綔 锛� 濡傛灉涓嶅瓨鍦� 閮芥墽琛宨nsert鎿嶄綔涓変釜鍙傛暟
@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)) {
- DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
- if (deviceTokenIOS != null) {
- if (!StringUtil.isNullOrEmpty(deviceToken))
- deviceTokenIOS.setDeviceToken(deviceToken);
- deviceTokenIOS.setUid(uid);
- deviceTokenIOS.setVersion(Integer.parseInt(acceptData.getVersion()));
- iosPushService.updateDeviceToken(deviceTokenIOS);
- } else {
- iosPushService.addDeviceToken(uid, Integer.parseInt(acceptData.getVersion()), deviceToken,
- acceptData.getDevice());
- }
+ // 娣诲姞璁惧娲昏穬璁板綍
+ DeviceActive da = new DeviceActive();
+ da.setDeviceToken(deviceToken);
+ da.setPlatform(DeviceActive.PLATFORM_IOS);
+ da.setVersionCode(Integer.parseInt(acceptData.getVersion()));
+ da.setDevice(acceptData.getDevice());
+ deviceActiveService.addDeviceActive(da);
+ // 娣诲姞token
+ iosPushService.addDeviceToken(uid, Integer.parseInt(acceptData.getVersion()), deviceToken,
+ acceptData.getDevice());
}
}
@@ -106,12 +150,8 @@
*/
@RequestMapping(value = "/unBind", method = RequestMethod.POST)
public void unBind(AcceptData acceptData, String deviceToken, PrintWriter out) {
- if (deviceToken != null && !"".equals(deviceToken)) {
- DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
- if (deviceTokenIOS != null) {
- deviceTokenIOS.setUid(null);
- iosPushService.updateDeviceToken(deviceTokenIOS);
- }
+ if (!StringUtil.isNullOrEmpty(acceptData.getDevice())) {
+ iosPushService.unBindUidAndDevice(acceptData.getDevice());
out.print(JsonUtil.loadTrue(0, null, "瑙g粦鎴愬姛"));
}
}
@@ -144,4 +184,161 @@
out.print(JsonUtil.loadTrueResult("鎴愬姛"));
}
+ /**
+ * 瑙g粦鎺ㄩ��
+ *
+ * @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;
+ List<PushGoods> list = null;
+ JSONArray resultList = new JSONArray();
+
+ DeviceActive deviceActive = deviceActiveService.getDeviceByDeviceAndPlatform(acceptData.getDevice(),
+ deviceToken, acceptData.getPlatform());
+
+ if (deviceActive != null) {
+
+ // 璁惧娉ㄥ唽鏃堕棿
+ Date createTime = deviceActive.getCreateTime();
+ count = PushGoodsService.countHistoryByPushTime(uid, createTime);
+
+ int pageSize = Constant.PAGE_SIZE;
+
+ list = PushGoodsService.listHistoryByPushTime((page - 1) * pageSize, pageSize, uid, createTime);
+ if (list != null && list.size() > 0) {
+ for (PushGoods pushGoods : list) {
+ JSONObject result = new JSONObject();
+
+ Long pushId = pushGoods.getId();
+ String picture = pushGoods.getPicture();
+ String alertContent = pushGoods.getAlertContent();
+ Date pushTime = pushGoods.getPushTime();
+
+ result.put("content", alertContent);
+ result.put("pushtime", pushTime.getTime());
+
+ // 缁熻鍟嗗搧鏁伴噺
+ long totalgoods = 0;
+ // 鍟嗗搧id
+ Long auctionId = null;
+ if (StringUtil.isNullOrEmpty(picture)) {
+ try {
+ List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(pushId);
+
+ if (listGroup != null && listGroup.size() > 0) {
+
+ totalgoods = listGroup.size();
+
+ PushGoodsGroup pushGoodsGroup = listGroup.get(0);
+ if (pushGoodsGroup != null) {
+ CommonGoods commonGoods = pushGoodsGroup.getCommonGoods();
+ if (commonGoods != null) {
+ picture = commonGoods.getPicture();
+ auctionId = commonGoods.getGoodsId();
+ }
+ }
+ }
+ } catch (PushGoodsGroupException e) {
+ e.printStackTrace();
+ }
+ }
+
+ result.put("picture", picture);
+
+ String fontColor1 = "#666666";
+ String fontColor2 = "#E5005C";
+ JSONArray array = new JSONArray();
+
+ JSONObject contentJson1 = new JSONObject();
+ contentJson1.put("color", fontColor1);
+ contentJson1.put("content", "鏈鎺ㄨ崘鍏�");
+
+ JSONObject contentJson2 = new JSONObject();
+ contentJson2.put("color", fontColor2);
+ contentJson2.put("content", totalgoods);
+
+ JSONObject contentJson3 = new JSONObject();
+ contentJson3.put("color", fontColor1);
+ contentJson3.put("content", "涓晢鍝�");
+
+ array.add(contentJson1);
+ array.add(contentJson2);
+ array.add(contentJson3);
+
+ result.put("totalwords", array);
+
+ String params = "";
+
+ JumpDetailV2 jumpDetail = null;
+ if (totalgoods == 1) {
+
+ params = JumpDetailParamsFactory.createGoodsParams(auctionId);
+ // 鍗曚釜鍟嗗搧璺宠浆鍟嗗搧璇︽儏
+ jumpDetail = jumpDetailV2Service.getByTypeCache("goodsdetail");
+
+ } else {
+ String url = configService.get("push_goods_details");
+ if (url == null) {
+ url = "";
+ }
+ url = url + "?id=" + pushId;
+
+ params = JumpDetailParamsFactory.createWEBParams(url);
+
+ // 璺宠浆鎺ㄨ崘璇︽儏
+ jumpDetail = jumpDetailV2Service.getByTypeCache("web");
+ }
+ result.put("params", params);
+ result.put("jumpDetail", jumpDetail);
+
+ resultList.add(result);
+ }
+ }
+ }
+
+ 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();
+ }
+
+ }
+ });
+ }
+ }
+
}
--
Gitblit v1.8.0