From 4cb15e222cd7d099d533ccbeb7f9a8cd99bf180c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 十二月 2018 16:35:18 +0800 Subject: [PATCH] 替换原来老的资金详情 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java | 266 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 160 insertions(+), 106 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java index afdfd44..855192c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java @@ -6,8 +6,6 @@ import javax.annotation.Resource; -import net.sf.json.JSONObject; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,18 +24,18 @@ import com.yeshi.fanli.util.CMQManager; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.ThreadUtil; import com.yeshi.fanli.util.push.IOSPushUtil; + +import net.sf.json.JSONObject; @Service public class IOSPushServiceImpl implements IOSPushService { @Resource private DeviceTokenIOSMapper deviceTokenIOSMapper; - + @Resource private PushQueueRecordMapper pushQueueRecordMapper; - @Override public void pushGoods(Long uid, Long auctionId, String title, String content) throws PushException { @@ -65,26 +63,21 @@ pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); if (uid == null || uid == 0) { - - addPushIOSQueue(info, url, PushController.GOODS); - - - /* // 鏌ヨIOS鎵�鏈夎澶囧彿 - // TODO 闇�瑕佸叏鎺� - List<String> deviceTokenList = getDeviceTokenList(1, 20000); - // IOS 鍏ㄦ帹 - ThreadUtil.run(new Runnable() { - @Override - public void run() { - try { - IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS); - } catch (Exception e) { - PushLogHelper.iosError(e); - - } - } - });*/ + addPushIOSQueue(info, url, PushController.GOODS); + + /* + * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList = + * getDeviceTokenList(1, 20000); // IOS 鍏ㄦ帹 ThreadUtil.run(new + * Runnable() { + * + * @Override public void run() { try { + * IOSPushUtil.allPushIOS(deviceTokenList, info, url, + * PushController.GOODS); } catch (Exception e) { + * PushLogHelper.iosError(e); + * + * } } }); + */ } else { // IOS 鍗曟帹 List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); @@ -125,23 +118,20 @@ // IOS 鍏ㄦ帹 if (uid == null || uid == 0) { // TODO 闇�瑕佸叏鎺� - + addPushIOSQueue(info, url, PushController.URL); - - /*List<String> deviceTokenList = getDeviceTokenList(1, 1000); - ThreadUtil.run(new Runnable() { - @Override - public void run() { - try { - - IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.URL); - - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - });*/ + /* + * List<String> deviceTokenList = getDeviceTokenList(1, 1000); + * ThreadUtil.run(new Runnable() { + * + * @Override public void run() { try { + * + * IOSPushUtil.allPushIOS(deviceTokenList, info, url, + * PushController.URL); + * + * } catch (Exception e) { PushLogHelper.iosError(e); } } }); + */ } else { List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); List<String> deviceTokenList = new ArrayList<>(); @@ -155,11 +145,6 @@ PushLogHelper.iosError(e); } } - } - - @Override - public void pushWEEXUrl(Long uid, String weexUrl, String title, String content) throws PushException { - } @Override @@ -192,22 +177,21 @@ PushRecord pushRecord = new PushRecord(); // TODO 闇�瑕佸叏鎺� - + addPushIOSQueue(info, id + "", PushController.ZNX); - - /*List<String> deviceTokenList = getDeviceTokenList(1, 1000); - ThreadUtil.run(new Runnable() { - @Override - public void run() { - try { - IOSPushUtil.allPushIOS(deviceTokenList, info, id + "", PushController.ZNX); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - - } - });*/ + /* + * List<String> deviceTokenList = getDeviceTokenList(1, 1000); + * + * ThreadUtil.run(new Runnable() { + * + * @Override public void run() { try { + * IOSPushUtil.allPushIOS(deviceTokenList, info, id + "", + * PushController.ZNX); } catch (Exception e) { + * PushLogHelper.iosError(e); } + * + * } }); + */ } else if (msg != null) { // 鎻掑叆鎺ㄩ�佽褰� PushRecord pushRecord = new PushRecord(); @@ -248,9 +232,9 @@ @Transactional @Override - public void addDeviceToken(Long uid, String deviceToken, String device) { + public void addDeviceToken(Long uid, int version, String deviceToken, String device) { // 濡傛灉device涓虹┖灏辫繑鍥� - if (StringUtil.isNullOrEmpty(device)) + if (StringUtil.isNullOrEmpty(device) || StringUtil.isNullOrEmpty(deviceToken)) return; // 鍒ゆ柇device鏄惁瀛樺湪 @@ -261,8 +245,18 @@ deviceTokenIos.setUpdateTime(new Date()); deviceTokenIos.setDevice(device); deviceTokenIos.setDeviceToken(deviceToken); + deviceTokenIos.setDeviceTokenMd5(StringUtil.Md5(deviceToken)); deviceTokenIos.setUid(uid); + deviceTokenIos.setVersion(version); deviceTokenIOSMapper.insertSelective(deviceTokenIos); + } else {// 鏇存柊devicetoken + DeviceTokenIOS updateDeviceTokenIOS = new DeviceTokenIOS(); + updateDeviceTokenIOS.setId(deviceTokenIos.getId()); + updateDeviceTokenIOS.setDeviceToken(deviceToken); + updateDeviceTokenIOS.setDeviceTokenMd5(StringUtil.Md5(deviceToken)); + updateDeviceTokenIOS.setUid(uid); + updateDeviceTokenIOS.setUpdateTime(new Date()); + deviceTokenIOSMapper.updateByPrimaryKeySelective(updateDeviceTokenIOS); } } @@ -296,20 +290,20 @@ } @Override - public DeviceTokenIOS getDeviceTokenByDevice(String device) { - return deviceTokenIOSMapper.selectByDevice(device); + public DeviceTokenIOS getDeviceTokenByDeviceToken(String deviceToken) { + return deviceTokenIOSMapper.selectByDeviceToken(deviceToken); } - /** * 淇濆瓨鎺ㄩ�佸唴瀹瑰彧闃熷垪涓� + * * @param json */ @Transactional public void addPushIOSQueue(MessageInfo info, String url, int type) { - + try { - + JSONObject json = IOSPushUtil.getJSONObject(info, url, type); // 鎬绘潯鐩� @@ -332,7 +326,7 @@ pushQueueRecord.setCreatetime(new Date()); // 姣忔鎺ㄩ�佹暟閲� pushQueueRecord.setPushNum(pushNum); - // 鎺ㄩ�佺 IOS + // 鎺ㄩ�佺 IOS pushQueueRecord.setType(1); if (tokenCount - i < totalCount) { @@ -374,94 +368,95 @@ } } - - + /** * 闃熷垪鎵ц鎺ㄩ�佹搷浣� */ @Override public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception { - + // 璧峰浣嶇疆 Long startCursor = pushQueueRecord.getStartCursor(); // 缁撴潫浣嶇疆 Long endCursor = pushQueueRecord.getEndCursor(); - + if (startCursor == null && endCursor == null) { return; } - + int total = (int) (endCursor - startCursor); - + // 姣忔鎺ㄩ�佹�绘潯鏁� int moveNum = pushQueueRecord.getPushNum(); - - int count = total/ moveNum; - + + int count = total / moveNum; + if (total % moveNum > 0) { - count +=1; + count += 1; } - + long recordCursor = startCursor; - + for (int i = 0; i < count; i++) { - + // 涓嶈冻50涓暟鎹� if (moveNum > total) { - moveNum = (int) (endCursor- startCursor); + moveNum = (int) (endCursor - startCursor); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum); recordCursor = endCursor; - + if (list != null) { executePushIOS(list, pushQueueRecord, recordCursor); + PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + startCursor + "锛�" + moveNum); } - + } else { - + if (recordCursor + moveNum > endCursor) { - //System.out.println("recordCursorend:" +recordCursor); - moveNum = (int) (endCursor- recordCursor); - //System.out.println(moveNum); + // System.out.println("recordCursorend:" +recordCursor); + moveNum = (int) (endCursor - recordCursor); + // System.out.println(moveNum); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum); if (list != null) { executePushIOS(list, pushQueueRecord, endCursor); + PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); } recordCursor = endCursor; - + } else { List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum); recordCursor = recordCursor + 50; - + if (list != null) { - executePushIOS(list, pushQueueRecord, recordCursor-1); + executePushIOS(list, pushQueueRecord, recordCursor - 1); + PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); } } - - //System.out.println("recordCursor:" +recordCursor); + + // System.out.println("recordCursor:" +recordCursor); } } - + } - - - public void executePushIOS(List<DeviceTokenIOS> list ,PushQueueRecord pushQueueRecord, long recordCursor) { - + + public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) { + String jsonContent = pushQueueRecord.getJsonContent(); JSONObject json = JSONObject.fromObject(jsonContent); - + List<String> tokenList = new ArrayList<>(); - for (DeviceTokenIOS ios : list){ - if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())){ + for (DeviceTokenIOS ios : list) { + if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())) { tokenList.add(ios.getDeviceToken()); - //System.out.println(ios.getDeviceToken()); + // System.out.println(ios.getDeviceToken()); } } - + if (tokenList.size() > 0) { - //System.out.println(tokenList.size()); + // System.out.println(tokenList.size()); // 鎵ц鎺ㄩ�� try { - IOSPushUtil.executePushIOS(tokenList,json); + IOSPushUtil.executePushIOS(tokenList, json); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -470,10 +465,69 @@ pushQueueRecord.setState(1); pushQueueRecord.setEndtime(new Date()); pushQueueRecord.setRecordCursor(recordCursor); - - //TODO 鏇存柊鏁版嵁搴� + + // TODO 鏇存柊鏁版嵁搴� pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord); } - + @Override + public void unBindUidAndDevice(String device) { + if (StringUtil.isNullOrEmpty(device)) + return; + DeviceTokenIOS deviceTokenIOS = deviceTokenIOSMapper.selectByDevice(device); + if (device != null) { + deviceTokenIOS.setUpdateTime(new Date()); + deviceTokenIOS.setUid(null); + deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIOS); + } + } + + @Override + public void pushWEEX(Long uid, String title, String content, String weexUrl) throws PushException { + MessageInfo info = new MessageInfo(); + info.setTitle(title); + info.setContent(content); + info.setDescription(content); + // IOS 鍏ㄦ帹 + if (uid == null || uid == 0) { + addPushIOSQueue(info, weexUrl, PushController.WEEX); + } else { + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); + List<String> deviceTokenList = new ArrayList<>(); + if (deviceTokenIosList != null) + for (DeviceTokenIOS ios : deviceTokenIosList) { + deviceTokenList.add(ios.getDeviceToken()); + } + try { + IOSPushUtil.allPushIOS(deviceTokenList, info, weexUrl, PushController.WEEX); + } catch (Exception e) { + PushLogHelper.iosError(e); + } + } + } + + @Override + public void pushBaiChuanUrl(Long uid, String title, String content, String url) throws PushException { + MessageInfo info = new MessageInfo(); + info.setTitle(title); + info.setContent(content); + info.setDescription(content); + // IOS 鍏ㄦ帹 + if (uid == null || uid == 0) { + addPushIOSQueue(info, url, PushController.BAICHUAN); + } else { + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); + List<String> deviceTokenList = new ArrayList<>(); + if (deviceTokenIosList != null) + for (DeviceTokenIOS ios : deviceTokenIosList) { + deviceTokenList.add(ios.getDeviceToken()); + } + try { + IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.BAICHUAN); + } catch (Exception e) { + PushLogHelper.iosError(e); + } + } + } + } -- Gitblit v1.8.0