| | |
| | | package com.yeshi.fanli.service.impl.push;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.push.PushGoodsMapper;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.push.PushGoods;
|
| | | import com.yeshi.fanli.entity.push.PushGoodsGroup;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.exception.PushException;
|
| | | import com.yeshi.fanli.exception.push.PushGoodsException;
|
| | | import com.yeshi.fanli.goods.CommonGoods;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.push.PushGoodsGroupService;
|
| | |
| | | import com.yeshi.fanli.service.inter.push.PushService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.factory.IOSPushFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class PushGoodsServiceImpl implements PushGoodsService {
|
| | |
| | | } else {
|
| | | // 修改
|
| | | record.setUpdateTime(new Date());
|
| | | pushGoodsMapper.insertSelective(record);
|
| | | pushGoodsMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | // 处理商品信息
|
| | |
| | | if (goodsList == null || goodsList.size() == 0) {
|
| | | throw new PushException(1, "推送无商品,请完善数据");
|
| | | }
|
| | |
|
| | | |
| | | String versions = pushGoods.getVersions();
|
| | | if (versions == null || versions.trim().length() == 0) {
|
| | | throw new PushException(1, "推送版本不能为空");
|
| | | }
|
| | | |
| | | List<String> listIOS = new ArrayList<String>();
|
| | | JSONObject json = JSONObject.fromObject(versions);
|
| | | String versionsIOS = json.getString("IOS");
|
| | | if (versionsIOS != null && versionsIOS.trim().length() > 0) {
|
| | | if (versionsIOS.contains("全推")) {
|
| | | listIOS = null;
|
| | | } else {
|
| | | listIOS = Arrays.asList(versionsIOS.split(","));
|
| | | }
|
| | | }
|
| | | |
| | | List<String> listAndroid = new ArrayList<String>();
|
| | | String versionsAndroid = json.getString("Android");
|
| | | if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
|
| | | if (versionsAndroid.contains("全推")) {
|
| | | listAndroid = null;
|
| | | } else {
|
| | | listAndroid = Arrays.asList(versionsAndroid.split(","));
|
| | | }
|
| | | }
|
| | | |
| | | if (goodsList.size() == 1) {
|
| | | /* 单个商品推送: 直接处理为商品信息 */
|
| | | PushGoodsGroup pushGoodsGroup = goodsList.get(0);
|
| | |
| | |
|
| | | Long goodsId = commonGoods.getGoodsId();
|
| | | String url = "https://item.taobao.com/item.htm?id=" + goodsId;
|
| | | |
| | | pushService.pushGoods(pushGoods.getUid(), alertTitle, alertContent, url,listIOS, listAndroid);
|
| | |
|
| | | pushService.pushGoods(pushGoods.getUid(), url, alertTitle, alertContent);
|
| | |
|
| | | } else {
|
| | | /* 多个商品推送 */
|
| | | String url = configService.get("push_goods_details");
|
| | |
| | | // 生成链接
|
| | | url = url + "?id=" + id;
|
| | |
|
| | | pushService.pushUrl(pushGoods.getUid(), url, alertTitle, alertContent);
|
| | | pushService.pushUrl(pushGoods.getUid(), alertTitle, alertContent, url, listIOS, listAndroid);
|
| | | }
|
| | |
|
| | | // 已推送
|
| | |
| | | pushGoods.setUpdateTime(new Date());
|
| | |
|
| | | updateByPrimaryKeySelective(pushGoods);
|
| | |
|
| | | }
|
| | |
|
| | | }
|