fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
@@ -8,19 +8,14 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.JsonUtil; import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum; import com.yeshi.fanli.exception.PushException; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; import com.yeshi.fanli.service.inter.push.PushRecordService; import com.yeshi.fanli.service.inter.push.PushService; import com.yeshi.fanli.service.inter.user.AccountMessageService; import com.yeshi.fanli.service.inter.user.SystemZnxService; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.IOSPushFactory; @@ -38,144 +33,13 @@ public final static int BAICHUAN = 6; // 站内推送 public final static int WELFARE_CENTER = 7; // 福利中心 @Resource private PushRecordService pushRecordService; @Resource private ConfigService configService; @Resource private SystemZnxService systemZnxService; @Resource private AccountMessageService accountMessageService; @Resource private PushService pushService; @Resource private UserSystemMsgService userSystemMsgService; /** * 商品推送 * * @param uId * -用户ID 可为空 * @param url * -商品链接 * @param title * -推送标题 * @param content * -推送内容 * @param out * @throws Exception */ @RequestMapping(value = "pushGoodsAll_f", method = RequestMethod.POST) public void pushGoods(Long uId, String url, String title, String content, String versions, PrintWriter out) throws Exception { try { String auctionId = null; if (!StringUtil.isNullOrEmpty(url) && url.contains("id=")) { String[] sts = url.split("\\?")[1].split("&"); for (String st : sts) if (st.contains("id=")) { auctionId = st.replace("id=", ""); } } if (StringUtil.isNullOrEmpty(auctionId)) { out.print(JsonUtil.loadFalseResult("提取商品ID失败")); return; } JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content); if (json.toString().getBytes().length > 256) { out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试")); return; } List<String> listVersion = null; if (versions != null && versions.trim().length() > 0) { listVersion = Arrays.asList(versions.split(",")); } pushService.pushGoods(uId, url, title, content, listVersion); out.print(JsonUtil.loadTrueResult("推送成功")); } catch (PushException e) { out.print(JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { out.print(JsonUtil.loadFalseResult("推送失败")); e.printStackTrace(); } } /** * 网页推送 * * @param url * @param title * @param content * @param out * @throws Exception */ @RequestMapping(value = "pushUrlAll_f", method = RequestMethod.POST) public void pushUrl(String url, String title, String content, String versions, PrintWriter out) throws Exception { if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { out.print(JsonUtil.loadFalseResult("请填写链接,标题与内容")); return; } JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content); if (json.toString().getBytes().length > 256) { out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试")); return; } try { List<String> listVersion = null; if (versions != null && versions.trim().length() > 0) { listVersion = Arrays.asList(versions.split(",")); } pushService.pushUrl(null, url, title, content, listVersion); out.print(JsonUtil.loadTrueResult("推送成功")); } catch (PushException e) { out.print(JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { out.print(JsonUtil.loadFalseResult("推送失败")); e.printStackTrace(); } } /** * * 方法说明: 站内信推送 * * @author mawurui createTime 2018年3月12日 下午5:45:00 * @param uId * @param title * @param content * @throws Exception */ @RequestMapping(value = "pushFanZNX_f", method = RequestMethod.POST) public void pushSystemZnx(Long uId, String title, String content, String versions, PrintWriter out) throws Exception { try { List<String> listVersion = null; if (versions != null && versions.trim().length() > 0) { listVersion = Arrays.asList(versions.split(",")); } pushService.pushZNX(uId, title, content, listVersion); out.print(JsonUtil.loadTrueResult("推送成功")); } catch (PushException e) { out.print(JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { out.print(JsonUtil.loadFalseResult("推送失败")); e.printStackTrace(); } } /** * 短链接转换 @@ -221,7 +85,7 @@ * @throws Exception */ @RequestMapping(value = "newPushGoodsAll") public void newPushGoodsAll(String callback, Long uid, String url, String title, String content, String versions, PrintWriter out) public void newPushGoodsAll(String callback, String url, String title, String content, String uids, String versions, PrintWriter out) throws Exception { String auctionId = null; @@ -245,12 +109,31 @@ } try { String[] uidArray = null; if (uids != null) { uidArray = uids.split(","); } List<String> listVersion = null; if (versions != null && versions.trim().length() > 0) { listVersion = Arrays.asList(versions.split(",")); } pushService.pushGoods(uid, url, title, content, listVersion); if (uidArray == null) { // 全推 pushService.pushGoods(null, title, content, url, listVersion); } else { // 部分用户推送 for (int i = 0; i < uidArray.length; i++) { String str_uid = uidArray[i]; if (str_uid != null && str_uid.trim().length() > 0) { pushService.pushGoods(Long.parseLong(str_uid), url, title, content, listVersion); } } } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功")); } catch (PushException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); @@ -270,7 +153,8 @@ * @throws Exception */ @RequestMapping(value = "newPushUrlAll") public void newPushUrlAll(String callback, String url, String title, String content, String versions, PrintWriter out) { public void newPushUrlAll(String callback, String url, String title, String content, String uids, String versions, PrintWriter out) { if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写链接,标题与内容")); @@ -284,12 +168,31 @@ } try { String[] uidArray = null; if (uids != null) { uidArray = uids.split(","); } List<String> listVersion = null; if (versions != null && versions.trim().length() > 0) { listVersion = Arrays.asList(versions.split(",")); } pushService.pushUrl(null, url, title, content, listVersion); if (uidArray == null) { // 全推 pushService.pushUrl(null, title, content, url, listVersion); } else { // 部分推送 for (int i = 0; i < uidArray.length; i++) { String str_uid = uidArray[i]; if (str_uid != null && str_uid.trim().length() > 0) { pushService.pushUrl(Long.parseLong(str_uid), url, title, content, listVersion); } } } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功")); } catch (PushException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); @@ -329,8 +232,10 @@ } if (uidArray == null) { // 全推 pushService.pushZNX(null, title, content, listVersion); } else { // 部分推送 for (int i = 0; i < uidArray.length; i++) { String str_uid = uidArray[i]; if (str_uid != null && str_uid.trim().length() > 0) { @@ -380,8 +285,10 @@ } if (uidArray == null) { // 全推 pushService.pushBaiChuanUrl(null, title, content, url, listVersion); } else { // 部分推送 for (int i = 0; i < uidArray.length; i++) { String str_uid = uidArray[i]; if (str_uid != null && str_uid.trim().length() > 0) { fanli/src/main/java/com/yeshi/fanli/controller/client/CustomerServiceController.java
@@ -9,6 +9,8 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.yeshi.utils.JsonUtil; import com.google.gson.Gson; import com.yeshi.fanli.entity.AppInfo; @@ -19,7 +21,6 @@ import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService; import com.yeshi.fanli.service.inter.customerservice.CustomerServiceHistoryService; import com.yeshi.fanli.util.StringUtil; import org.yeshi.utils.JsonUtil; import net.sf.json.JSONObject; @@ -115,4 +116,35 @@ out.print(JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(answer))); } /** * 用户吐槽 * @param fileList * @param uid * @param content * @param out */ @RequestMapping(value = "complaint") public void complaint(List<CommonsMultipartFile> fileList, Long uid, String content, PrintWriter out) { // 图片最多五张、可以为空 if (fileList != null && fileList.size() > 5 ) { out.print(JsonUtil.loadFalseResult("图片最多可上传五张")); return; } if (content == null || content.trim().length() == 0) { out.print(JsonUtil.loadFalseResult("吐槽内容为空")); return; } try { out.print(JsonUtil.loadTrueResult("吐槽")); } catch (Exception e) { out.print(JsonUtil.loadFalseResult("操作失败")); e.printStackTrace(); } } } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/push/DeviceTokenIOSMapper.java
@@ -22,7 +22,7 @@ List<DeviceTokenIOS> selectByUid( @Param("uid")Long uid, @Param("list")List<Integer> list); List<DeviceTokenIOS> selectList(@Param("start")Long start,@Param("count")int count, @Param("array")String[] arrayVersion); List<DeviceTokenIOS> selectList(@Param("start")Long start,@Param("count")int count, @Param("list")List<Integer> list); long selectCount(); fanli/src/main/java/com/yeshi/fanli/mapping/push/DeviceTokenIOSMapper.xml
@@ -52,9 +52,9 @@ select <include refid="Base_Column_List" /> from yeshi_ec_uid_devicetoken_ios <if test="array != null"> <if test="list != null and list.size() > 0"> WHERE version in <foreach collection="array" item="item" open="(" separator="," close=")"> <foreach collection="list" item="item" open="(" separator="," close=")"> #{item} </foreach> </if> fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java
@@ -1,6 +1,7 @@ package com.yeshi.fanli.service.impl.push; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -288,10 +289,16 @@ } @Override public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) { // 版本号 List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) throws PushException { List<Integer> listCode = null; if (listVersion != null && listVersion.size() > 0) { // 版本号推送限制 listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); if (listCode == null || listCode.size() == 0) { throw new PushException(1, "IOS推送失败,推送版本不存在!"); } } return deviceTokenIOSMapper.selectByUid(uid, listCode); } @@ -329,7 +336,7 @@ * @param json */ @Transactional public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) { public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) throws PushException { try { @@ -345,18 +352,28 @@ int pushNum = 50; String versionCodes = ""; List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); if (listCode != null && listCode.size() > 0) { for (Integer code: listCode) { versionCodes = versionCodes + code + ","; if (listVersion != null && listVersion.size() > 0) { // 加入版本推送限制 List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); if (listCode != null && listCode.size() > 0) { for (Integer code: listCode) { versionCodes = versionCodes + code + ","; } // 去除末尾逗号 if (versionCodes.endsWith(",")) { versionCodes = versionCodes.substring(0, versionCodes.length() - 1); } } // 去除末尾逗号 if (versionCodes.endsWith(",")) { versionCodes = versionCodes.substring(0, versionCodes.length() - 1); if (versionCodes == null || versionCodes.trim().length() == 0) { throw new PushException(1, "IOS推送失败,推送版本不存在!"); } } for (long i = 0; i < tokenCount + totalCount;) { @@ -424,17 +441,33 @@ Long startCursor = pushQueueRecord.getStartCursor(); // 结束位置 Long endCursor = pushQueueRecord.getEndCursor(); // 版本号 String[] versionArray = null; String versions = pushQueueRecord.getVersions(); if (versions != null && versions.trim().length() == 0) { versionArray = versions.split(","); } if (startCursor == null && endCursor == null) { return; } // 推送的版本号 String versions = pushQueueRecord.getVersions(); List<Integer> listVersionCode = null; if (versions != null && versions.trim().length() > 0) { List<String> listVersion = Arrays.asList(versions.split(",")); if (listVersion != null && listVersion.size() > 0) { listVersionCode = new ArrayList<Integer>(); for (String version: listVersion) { if (version != null && version.trim().length() > 0) { listVersionCode.add(Integer.parseInt(version)); } } } if (listVersionCode == null || listVersionCode.size() == 0) { return; //版本号存在异常 } } int total = (int) (endCursor - startCursor); // 每次推送总条数 @@ -454,7 +487,7 @@ // 不足50个数据 if (moveNum > total) { moveNum = (int) (endCursor - startCursor); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, versionArray); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listVersionCode); recordCursor = endCursor; if (list != null) { @@ -468,7 +501,7 @@ // System.out.println("recordCursorend:" +recordCursor); moveNum = (int) (endCursor - recordCursor); // System.out.println(moveNum); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode); if (list != null) { executePushIOS(list, pushQueueRecord, endCursor); PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum); @@ -476,7 +509,7 @@ recordCursor = endCursor; } else { List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray); List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode); recordCursor = recordCursor + 50; if (list != null) { @@ -484,11 +517,8 @@ PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum); } } // System.out.println("recordCursor:" +recordCursor); } } } public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) { fanli/src/main/java/com/yeshi/fanli/service/impl/push/XMPushServiceImpl.java
@@ -38,6 +38,9 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() ==0) { throw new PushException(1, "小米推送失败,推送的版本过低!"); } } else if (minVersionCode > 0) { appVersion = getVersionByMinVersionCode(minVersionCode); } @@ -84,6 +87,9 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() ==0) { throw new PushException(1, "小米推送失败,推送的版本过低!"); } } else if (minVersionCode > 0) { appVersion = getVersionByMinVersionCode(minVersionCode); } @@ -133,6 +139,9 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() == 0) { throw new PushException(1, "小米推送失败,推送的版本过低!"); } } else if (minVersionCode > 0) { appVersion = getVersionByMinVersionCode(minVersionCode); } @@ -216,6 +225,9 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() == 0) { throw new PushException(1, "小米推送失败,推送的版本不能低于1.4.8"); } } else if (minVersionCode > 0) { appVersion = getVersionByMinVersionCode(minVersionCode); } @@ -273,7 +285,7 @@ * @param listVersion * @return */ private String getCanPushVersions(int versionCode, List<String> listVersion) { private String getCanPushVersions(int versionCode, List<String> listVersion) throws PushException{ List<AppVersionInfo> list = appVersionService.listByVersions(AppVersionInfo.PLATFORM_ANDROID, listVersion); String versions = ""; @@ -284,6 +296,8 @@ versions += appVersion.getVersion() + ","; } } } else { throw new PushException(1, "推送的版本不存在,请核实版本信息"); } if (versions.endsWith(",")) { @@ -301,6 +315,10 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() ==0) { throw new PushException(1, "小米推送失败,推送的版本不能低于1.4.8"); } } else if (minVersionCode > 0){ appVersion = getVersionByMinVersionCode(minVersionCode); } @@ -344,6 +362,9 @@ String appVersion = null; if (listVersion != null && listVersion.size() > 0) { appVersion = getCanPushVersions(minVersionCode, listVersion); if (appVersion == null || appVersion.trim().length() ==0) { throw new PushException(1, "小米推送失败,推送的版本不能低于1.5.1"); } } else if (minVersionCode > 0){ appVersion = getVersionByMinVersionCode(minVersionCode); } fanli/src/main/java/com/yeshi/fanli/service/inter/push/IOSPushService.java
@@ -4,6 +4,7 @@ import com.yeshi.fanli.entity.push.DeviceTokenIOS; import com.yeshi.fanli.entity.push.PushQueueRecord; import com.yeshi.fanli.exception.PushException; /** * IOS推送服务 @@ -43,7 +44,7 @@ * @param uid * @return */ public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion); public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) throws PushException; /** * 获取DeviceToken不为空的列表