package com.yeshi.fanli.service.impl.activity;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
import org.yeshi.utils.entity.FileUploadResult;
|
import org.yeshi.utils.taobao.TbImgUtil;
|
|
import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
import com.yeshi.fanli.dao.mybatis.activity.ActivityUserMapper;
|
import com.yeshi.fanli.dao.mybatis.activity.RecommendActivityImgMapper;
|
import com.yeshi.fanli.dao.mybatis.activity.RecommendActivityInviteInfoMapper;
|
import com.yeshi.fanli.dao.mybatis.activity.RecommendActivityMapper;
|
import com.yeshi.fanli.dao.mybatis.activity.RecommendActivityTaoBaoGoodsMapper;
|
import com.yeshi.fanli.entity.bus.activity.ActivityShareResult;
|
import com.yeshi.fanli.entity.bus.activity.ActivityUser;
|
import com.yeshi.fanli.entity.bus.activity.RecommendActivity;
|
import com.yeshi.fanli.entity.bus.activity.RecommendActivityImg;
|
import com.yeshi.fanli.entity.bus.activity.RecommendActivityInviteInfo;
|
import com.yeshi.fanli.entity.bus.activity.RecommendActivityTaoBaoGoods;
|
import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
|
import com.yeshi.fanli.entity.goods.CommonGoods;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
import com.yeshi.fanli.exception.ActivityException;
|
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
|
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.activity.ActivityService;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
|
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
|
import com.yeshi.fanli.service.inter.user.TBPidService;
|
import com.yeshi.fanli.service.inter.user.UserAccountService;
|
import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
|
import com.yeshi.fanli.util.ImageUtil;
|
import com.yeshi.fanli.util.RedisManager;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.activity.ActivityUtil;
|
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
|
@Service
|
public class ActivityServiceImpl implements ActivityService {
|
|
@Resource
|
private RecommendActivityMapper recommendActivityMapper;
|
|
@Resource
|
private ShareGoodsService shareGoodsService;
|
|
@Resource
|
private SpreadUserImgService spreadUserImgService;
|
|
@Resource
|
private ActivityUserMapper activityUserMapper;
|
|
@Resource
|
private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
|
@Resource
|
private RecommendActivityTaoBaoGoodsMapper recommendActivityTaoBaoGoodsMapper;
|
|
@Resource
|
private RecommendActivityImgMapper recommendActivityImgMapper;
|
|
@Resource
|
private RecommendActivityInviteInfoMapper recommendActivityInviteInfoMapper;
|
|
@Resource
|
private RedisManager redisManager;
|
|
@Resource
|
private TBPidService tbPidService;
|
|
@Resource
|
private ConfigService configService;
|
|
@Resource
|
private UserInfoMapper userInfoMapper;
|
|
@Resource
|
private UserAccountService userAccountService;
|
|
@Resource
|
private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
|
@Resource
|
private UserShareGoodsRecordService userShareGoodsRecordService;
|
|
@Resource
|
private CommonGoodsService commonGoodsService;
|
|
@Override
|
public List<RecommendActivity> getRecommendActivityList(int page, int pageSize) {
|
return recommendActivityMapper.getRecommendActivityList((page - 1) * pageSize, pageSize);
|
}
|
|
@Override
|
public List<RecommendActivity> queryRecommendActivityList(String title, int page, int pageSize) {
|
return recommendActivityMapper.queryRecommendActivityList(title, (page - 1) * pageSize, pageSize);
|
}
|
|
@Override
|
public long getRecommendActivityCount() {
|
return recommendActivityMapper.getRecommendActivityCount();
|
}
|
|
@Override
|
public ActivityShareResult shareActivityGoods(Long uid, Long activityId)
|
throws ActivityException, UserShareGoodsRecordException {
|
|
RecommendActivity activity = recommendActivityMapper.selectByPrimaryKey(activityId);
|
|
if (activity == null)
|
throw new ActivityException(2, "动态不存在");
|
|
if (activity.getType() != RecommendActivity.TYPE_SHARE_GOODS)
|
throw new ActivityException(3, "不属于分享商品动态");
|
|
ActivityShareResult result = new ActivityShareResult();
|
|
String title = activity.getTitle().replace("<br>", "/n").replace("<p>", "").replace("</p>", "");
|
if (title != null && title.trim().endsWith("/n"))
|
title = title.trim().substring(0, title.trim().length() - 2);
|
result.setTitle(title);
|
List<FileUploadResult> imgList = new ArrayList<>();
|
|
List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
|
if (activity.getGoodsList() != null) {
|
|
activity.getGoodsList().stream().parallel().forEach(goodsActivity -> {
|
|
try {
|
TaoBaoGoodsBrief goodsBrief = redisManager
|
.getTaoBaoGoodsBrief(Long.parseLong(goodsActivity.getAuctionId()));
|
listGoodsBrief.add(goodsBrief);
|
} catch (TaobaoGoodsDownException e) {
|
|
CommonGoods commonGoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType(
|
Long.parseLong(goodsActivity.getAuctionId()), CommonGoods.GOODS_TYPE_TB);
|
if (commonGoods != null) {
|
TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
|
goodsBrief.setState(1);
|
listGoodsBrief.add(goodsBrief);
|
}
|
|
try {
|
LogHelper.errorDetailInfo(e, "分享商品出错-商品ID:" + goodsActivity.getAuctionId(), "--");
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
});
|
}
|
|
if (listGoodsBrief.size() < 1) {
|
throw new ActivityException(1, "商品下架");
|
}
|
|
Map<String, Object> map = userShareGoodsRecordService.save(uid, ShareSourceTypeEnum.activity, title,
|
listGoodsBrief);
|
imgList.add((FileUploadResult) map.get("loadResult"));
|
result.setImgList(imgList);
|
|
return result;
|
}
|
|
@Override
|
public JSONObject shareGoodsV2(Long uid, Long activityId) throws ActivityException, UserShareGoodsRecordException {
|
|
RecommendActivity activity = recommendActivityMapper.selectByPrimaryKey(activityId);
|
|
if (activity == null)
|
throw new ActivityException(2, "动态不存在");
|
|
if (activity.getType() != RecommendActivity.TYPE_SHARE_GOODS)
|
throw new ActivityException(3, "不属于分享商品动态");
|
|
ActivityShareResult result = new ActivityShareResult();
|
|
String title = activity.getTitle().replace("<br>", "/n").replace("<p>", "").replace("</p>", "");
|
if (title != null && title.trim().endsWith("/n"))
|
title = title.trim().substring(0, title.trim().length() - 2);
|
|
result.setTitle(title);
|
|
List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
|
if (activity.getGoodsList() != null) {
|
activity.getGoodsList().stream().parallel().forEach(goodsActivity -> {
|
try {
|
TaoBaoGoodsBrief goodsBrief = redisManager
|
.getTaoBaoGoodsBrief(Long.parseLong(goodsActivity.getAuctionId()));
|
listGoodsBrief.add(goodsBrief);
|
|
} catch (TaobaoGoodsDownException e) {
|
|
CommonGoods commonGoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType(
|
Long.parseLong(goodsActivity.getAuctionId()), CommonGoods.GOODS_TYPE_TB);
|
if (commonGoods != null) {
|
TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
|
goodsBrief.setState(1);
|
listGoodsBrief.add(goodsBrief);
|
}
|
|
try {
|
LogHelper.errorDetailInfo(e, "分享商品出错-商品ID:" + goodsActivity.getAuctionId(), "--");
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
});
|
}
|
|
if (listGoodsBrief.size() < 1) {
|
throw new ActivityException(1, "商品下架");
|
}
|
|
String fontColor1 = "#000000";
|
String fontColor2 = "#E5005C";
|
JSONArray array = new JSONArray();
|
|
JSONObject contentJson1 = new JSONObject();
|
contentJson1.put("color", fontColor1);
|
contentJson1.put("content", "预估分享奖金:");
|
String shareMoney = "0";
|
String revenue = "¥0";
|
String totalGetMoney = activity.getTotalGetMoney();
|
if (totalGetMoney != null && totalGetMoney.trim().length() > 0) {
|
String[] split = totalGetMoney.split(":");
|
if (split != null) {
|
revenue = split[1];
|
}
|
|
String[] splitMoney = totalGetMoney.split("¥");
|
if (splitMoney != null) {
|
shareMoney = splitMoney[1];
|
}
|
}
|
|
JSONObject contentJson2 = new JSONObject();
|
contentJson2.put("color", fontColor2);
|
contentJson2.put("content", revenue);
|
|
array.add(contentJson1);
|
array.add(contentJson2);
|
|
JSONObject data = new JSONObject();
|
|
Map<String, Object> map = userShareGoodsRecordService.save(uid, ShareSourceTypeEnum.activity, title,
|
listGoodsBrief);
|
|
data.put("title", title);
|
data.put("revenue", array);
|
data.put("fanMoney", shareMoney);
|
data.put("shareId", map.get("shareId"));
|
data.put("shareImg", map.get("loadResult"));
|
data.put("notifyDesc", configService.get("goods_share_multiple_notify"));
|
|
return data;
|
|
}
|
|
@Override
|
public ActivityShareResult shareInviteImg(Long uid, Long activityId) throws ActivityException {
|
RecommendActivity activity = recommendActivityMapper.selectByPrimaryKey(activityId);
|
if (activity == null)
|
throw new ActivityException(2, "动态不存在");
|
if (activity.getType() != RecommendActivity.TYPE_INVITE)
|
throw new ActivityException(3, "不属于邀请动态");
|
if (activity.getImageList() == null || activity.getImageList().size() < 1)
|
throw new ActivityException(4, "无背景图");
|
|
ActivityShareResult result = new ActivityShareResult();
|
result.setTitle(activity.getTitle().replace("<br>", "/n").replace("<p>", "").replace("</p>", ""));
|
List<FileUploadResult> imgList = new ArrayList<>();
|
|
RecommendActivityInviteInfo inviteInfo = recommendActivityInviteInfoMapper.selectByActivityId(activityId);
|
|
String img = spreadUserImgService.getUserSpreadImg(uid, activity.getImageList().get(0), inviteInfo.getPx(),
|
inviteInfo.getPy(), inviteInfo.getSize());
|
if (!StringUtil.isNullOrEmpty(img))
|
imgList.add(new FileUploadResult(img, ""));
|
result.setImgList(imgList);
|
return result;
|
}
|
|
@Override
|
public List<ActivityUser> getActivityUserList() {
|
return activityUserMapper.selectList();
|
}
|
|
@Override
|
public RecommendActivity addShareGoodsRecommendActivity(Long activityUid, String title, List<Long> goodsList,
|
boolean top, int shareCount) throws ActivityException {
|
|
if (goodsList == null || goodsList.size() == 0 || goodsList.size() > 9)
|
throw new ActivityException(1, "商品数量错误:10>商品数量>0");
|
|
RecommendActivity activity = new RecommendActivity();
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setCreateTime(new Date());
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
activity.setType(RecommendActivity.TYPE_SHARE_GOODS);
|
recommendActivityMapper.insertSelective(activity);
|
|
List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>();
|
|
BigDecimal taotaoMoney = new BigDecimal(0);
|
for (long auctionId : goodsList) {
|
TaoBaoGoodsBrief tb = null;
|
try {
|
tb = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
} catch (TaobaoGoodsDownException e) {
|
e.printStackTrace();
|
}
|
if (tb == null)
|
continue;
|
RecommendActivityTaoBaoGoods goods = new RecommendActivityTaoBaoGoods();
|
goods.setAuctionId(tb.getAuctionId() + "");
|
goods.setCreateTime(new Date());
|
goods.setDesc(ActivityUtil.getGoodsShowPrice(tb));
|
goods.setOrderBy(0);
|
goods.setPictUrl(TbImgUtil.getTBSize220ImgWebp(tb.getPictUrl()));
|
goods.setTaoBaoGoodsBrief(tb);
|
goods.setRecommendActivity(activity);
|
goods.setCouponAmount(tb.getCouponAmount());
|
recommendActivityTaoBaoGoodsMapper.insertSelective(goods);
|
BigDecimal money = taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb);
|
taotaoMoney = taotaoMoney.add(money);
|
|
// 转换简版商品信息
|
CommonGoods commonGoods = CommonGoodsFactory.create(tb);
|
listCommonGoods.add(commonGoods);
|
}
|
|
try {
|
// 更新简版信息
|
commonGoodsService.addBatchCommonGoods(listCommonGoods);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
RecommendActivity updateActivity = new RecommendActivity();
|
updateActivity.setId(activity.getId());
|
updateActivity.setTotalGetMoney("预估分享奖金:¥" + taotaoMoney.toString());
|
recommendActivityMapper.updateByPrimaryKeySelective(updateActivity);
|
|
return activity;
|
}
|
|
@Override
|
public RecommendActivity addInviteImgRecommendActivity(Long activityUid, String title, String url, boolean top,
|
int shareCount, int px, int py, int erCodeSize) throws ActivityException {
|
RecommendActivity activity = new RecommendActivity();
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setCreateTime(new Date());
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
activity.setType(RecommendActivity.TYPE_INVITE);
|
recommendActivityMapper.insertSelective(activity);
|
RecommendActivityImg img = new RecommendActivityImg();
|
img.setImg(url);
|
img.setOrderBy(0);
|
img.setRecommendActivity(activity);
|
try {
|
int[] hw = ImageUtil.getImgWidthAndHeight(url);
|
img.setImgHeight(hw[1]);
|
img.setImgWidth(hw[0]);
|
} catch (Exception e) {
|
throw new ActivityException(2, "图片尺寸获取失败");
|
}
|
|
// 插入二维码位置信息
|
RecommendActivityInviteInfo recommendActivityInviteInfo = new RecommendActivityInviteInfo();
|
recommendActivityInviteInfo.setPx(px);
|
recommendActivityInviteInfo.setPy(py);
|
recommendActivityInviteInfo.setRecommendActivity(activity);
|
recommendActivityInviteInfo.setSize(erCodeSize);
|
recommendActivityInviteInfoMapper.insertSelective(recommendActivityInviteInfo);
|
|
recommendActivityImgMapper.insertSelective(img);
|
return activity;
|
}
|
|
@Override
|
public RecommendActivity addTextAndImgRecommendActivity(Long activityUid, String title, List<String> imgList,
|
boolean top, int shareCount) throws ActivityException {
|
RecommendActivity activity = new RecommendActivity();
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setCreateTime(new Date());
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
activity.setType(RecommendActivity.TYPE_TEXTIMG);
|
recommendActivityMapper.insertSelective(activity);
|
for (String imgUrl : imgList) {
|
RecommendActivityImg img = new RecommendActivityImg();
|
img.setImg(imgUrl);
|
img.setOrderBy(0);
|
img.setRecommendActivity(activity);
|
try {
|
int[] hw = ImageUtil.getImgWidthAndHeight(imgUrl);
|
img.setImgHeight(hw[1]);
|
img.setImgWidth(hw[0]);
|
} catch (Exception e) {
|
throw new ActivityException(2, "图片尺寸获取失败");
|
}
|
recommendActivityImgMapper.insertSelective(img);
|
}
|
return activity;
|
}
|
|
@Override
|
public void deleteRecommendActivity(long[] ids) {
|
recommendActivityMapper.batchDeleteByPrimaryKey(ids);
|
recommendActivityImgMapper.batchDeleteByActivityid(ids);
|
recommendActivityTaoBaoGoodsMapper.batchDeleteByActivityid(ids);
|
|
}
|
|
@Override
|
public RecommendActivity getRecommendActivityById(Long id) {
|
return recommendActivityMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public RecommendActivity updateShareGoodsRecommendActivity(Long id, Long activityUid, String title,
|
List<Long> goodsList, boolean top, int shareCount) throws ActivityException {
|
if (goodsList == null || goodsList.size() == 0 || goodsList.size() > 9)
|
throw new ActivityException(1, "商品数量错误:10>商品数量>0");
|
// 删除之前的商品
|
recommendActivityTaoBaoGoodsMapper.batchDeleteByActivityid(new long[] { id });
|
RecommendActivity activity = new RecommendActivity();
|
activity.setId(id);
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
|
activity.setType(RecommendActivity.TYPE_SHARE_GOODS);
|
recommendActivityMapper.updateByPrimaryKeySelective(activity);
|
|
BigDecimal taotaoMoney = new BigDecimal(0);
|
for (long auctionId : goodsList) {
|
TaoBaoGoodsBrief tb = null;
|
|
try {
|
tb = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
} catch (TaobaoGoodsDownException e) {
|
e.printStackTrace();
|
}
|
|
if (tb == null)
|
continue;
|
RecommendActivityTaoBaoGoods goods = new RecommendActivityTaoBaoGoods();
|
goods.setAuctionId(tb.getAuctionId() + "");
|
goods.setCreateTime(new Date());
|
goods.setDesc(ActivityUtil.getGoodsShowPrice(tb));
|
goods.setOrderBy(0);
|
goods.setPictUrl(TbImgUtil.getTBSize220ImgWebp(tb.getPictUrl()));
|
goods.setTaoBaoGoodsBrief(tb);
|
goods.setRecommendActivity(activity);
|
goods.setTitle(tb.getTitle());
|
goods.setCouponAmount(tb.getCouponAmount());
|
recommendActivityTaoBaoGoodsMapper.insertSelective(goods);
|
BigDecimal money = taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb);
|
taotaoMoney = taotaoMoney.add(money);
|
}
|
|
RecommendActivity updateActivity = new RecommendActivity();
|
updateActivity.setId(activity.getId());
|
updateActivity.setTotalGetMoney("预估分享奖金:¥" + taotaoMoney.toString());
|
recommendActivityMapper.updateByPrimaryKeySelective(updateActivity);
|
|
return activity;
|
}
|
|
@Override
|
public RecommendActivity updateInviteImgRecommendActivity(Long id, Long activityUid, String title, String url,
|
boolean top, int shareCount, int px, int py, int erCodeSize) throws ActivityException {
|
recommendActivityImgMapper.batchDeleteByActivityid(new long[] { id });
|
RecommendActivity activity = new RecommendActivity();
|
activity.setId(id);
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
activity.setType(RecommendActivity.TYPE_INVITE);
|
recommendActivityMapper.updateByPrimaryKeySelective(activity);
|
RecommendActivityImg img = new RecommendActivityImg();
|
img.setImg(url);
|
img.setOrderBy(0);
|
img.setRecommendActivity(activity);
|
try {
|
int[] hw = ImageUtil.getImgWidthAndHeight(url);
|
img.setImgHeight(hw[1]);
|
img.setImgWidth(hw[0]);
|
} catch (Exception e) {
|
throw new ActivityException(2, "图片尺寸获取失败");
|
}
|
recommendActivityImgMapper.insertSelective(img);
|
|
RecommendActivityInviteInfo inviteInfo = recommendActivityInviteInfoMapper.selectByActivityId(activity.getId());
|
if (inviteInfo != null)
|
recommendActivityInviteInfoMapper.deleteByPrimaryKey(inviteInfo.getId());
|
|
// 插入二维码位置信息
|
RecommendActivityInviteInfo recommendActivityInviteInfo = new RecommendActivityInviteInfo();
|
recommendActivityInviteInfo.setPx(px);
|
recommendActivityInviteInfo.setPy(py);
|
recommendActivityInviteInfo.setRecommendActivity(activity);
|
recommendActivityInviteInfo.setSize(erCodeSize);
|
recommendActivityInviteInfoMapper.insertSelective(recommendActivityInviteInfo);
|
|
return activity;
|
}
|
|
@Override
|
public RecommendActivity updateTextAndImgRecommendActivity(Long id, Long activityUid, String title,
|
List<String> imgList, boolean top, int shareCount) throws ActivityException {
|
recommendActivityImgMapper.batchDeleteByActivityid(new long[] { id });
|
RecommendActivity activity = new RecommendActivity();
|
activity.setId(id);
|
activity.setActivityUser(new ActivityUser(activityUid));
|
activity.setGoodsList(null);
|
activity.setOrderBy(0);
|
activity.setShareCount(shareCount);
|
activity.setTitle(title);
|
activity.setTop(top);
|
activity.setType(RecommendActivity.TYPE_TEXTIMG);
|
recommendActivityMapper.updateByPrimaryKeySelective(activity);
|
for (String imgUrl : imgList) {
|
RecommendActivityImg img = new RecommendActivityImg();
|
img.setImg(imgUrl);
|
img.setOrderBy(0);
|
img.setRecommendActivity(activity);
|
try {
|
int[] hw = ImageUtil.getImgWidthAndHeight(imgUrl);
|
img.setImgHeight(hw[1]);
|
img.setImgWidth(hw[0]);
|
} catch (Exception e) {
|
throw new ActivityException(2, "图片尺寸获取失败");
|
}
|
recommendActivityImgMapper.insertSelective(img);
|
}
|
return activity;
|
}
|
|
@Override
|
public void addShareCount(Long activityId, int count) {
|
recommendActivityMapper.addShareCount(activityId, count);
|
}
|
|
@Cacheable(value = "activityCache", key = "'getRecommendActivityList-'+#page+'-'+#pageSize")
|
@Override
|
public List<RecommendActivity> getRecommendActivityListCache(int page, int pageSize) {
|
List<RecommendActivity> activityList = getRecommendActivityList(page, pageSize);
|
if (activityList != null)
|
for (RecommendActivity activity : activityList) {
|
if (activity != null && activity.getGoodsList() != null)
|
for (RecommendActivityTaoBaoGoods goods : activity.getGoodsList()) {
|
goods.setQuanPrice(goods.getDesc().replace("券后价:¥", ""));
|
}
|
}
|
return activityList;
|
}
|
|
@Cacheable(value = "activityCache", key = "'getRecommendActivityCount'")
|
@Override
|
public long getRecommendActivityCountCache() {
|
return getRecommendActivityCount();
|
}
|
|
@Override
|
public void upgradeShareGoodsRecommendActivity(Long id) throws ActivityException {
|
// 获取商品
|
List<RecommendActivityTaoBaoGoods> list = recommendActivityTaoBaoGoodsMapper.selectByActivityId(id);
|
if (list != null)
|
for (RecommendActivityTaoBaoGoods goods : list) {
|
// 下架商品不必更新
|
if (goods.getState() == RecommendActivityTaoBaoGoods.STATE_UNSHELVE)
|
continue;
|
try {
|
TaoBaoGoodsBrief tbGoods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(goods.getAuctionId()));
|
if (tbGoods != null) {
|
RecommendActivityTaoBaoGoods update = new RecommendActivityTaoBaoGoods();
|
update.setPictUrl(TbImgUtil.getTBSize220ImgWebp(tbGoods.getPictUrl()));
|
update.setId(goods.getId());
|
update.setDesc(ActivityUtil.getGoodsShowPrice(tbGoods));
|
update.setCouponAmount(tbGoods.getCouponAmount());
|
// 当没有券的时候商品无效
|
if (StringUtil.isNullOrEmpty(tbGoods.getCouponActivityId())
|
|| tbGoods.getCouponLeftCount() == null || tbGoods.getCouponLeftCount() == 0)
|
update.setState(RecommendActivityTaoBaoGoods.STATE_UNSHELVE);
|
else
|
update.setState(RecommendActivityTaoBaoGoods.STATE_NORMAL);
|
recommendActivityTaoBaoGoodsMapper.updateByPrimaryKeySelective(update);
|
try {
|
taoBaoGoodsUpdateService.updateTaoBaoGoods(tbGoods);
|
} catch (TaobaoGoodsUpdateException e) {
|
e.printStackTrace();
|
}
|
}
|
} catch (TaobaoGoodsDownException e) {
|
RecommendActivityTaoBaoGoods update = new RecommendActivityTaoBaoGoods();
|
update.setId(goods.getId());
|
update.setState(RecommendActivityTaoBaoGoods.STATE_UNSHELVE);
|
recommendActivityTaoBaoGoodsMapper.updateByPrimaryKeySelective(update);
|
taoBaoGoodsUpdateService.offlineTaoBaoGoods(Long.parseLong(goods.getAuctionId()));
|
}
|
}
|
}
|
|
@Override
|
public List<RecommendActivity> getRecommendActivityList(int type, int page, int pageSize) {
|
return recommendActivityMapper.getRecommendActivityListByType(type, (page - 1) * pageSize, pageSize);
|
}
|
|
@Override
|
public long getRecommendActivityCount(int type) {
|
return recommendActivityMapper.getRecommendActivityCountByType(type);
|
}
|
|
@Override
|
public RecommendActivityInviteInfo getRecommendActivityInviteInfoByActivityId(Long activityId) {
|
return recommendActivityInviteInfoMapper.selectByActivityId(activityId);
|
}
|
|
@Override
|
public void downTaoBaoGoods(Long auctionId) {
|
recommendActivityTaoBaoGoodsMapper.updateStateByAuctionId(auctionId,
|
RecommendActivityTaoBaoGoods.STATE_UNSHELVE);
|
}
|
|
@Override
|
public RecommendActivity getRecommendActivityDetail(Long activityId) {
|
|
RecommendActivity activity = recommendActivityMapper.selectByPrimaryKey(activityId);
|
if (activity != null && activity.getGoodsList() != null) {
|
for (RecommendActivityTaoBaoGoods goods : activity.getGoodsList()) {
|
goods.setQuanPrice(goods.getDesc().replace("券后价:¥", ""));
|
goods.setPictUrl(goods.getPictUrl().replace("_.webp", ""));
|
}
|
}
|
|
return activity;
|
}
|
|
@Override
|
public int insert(RecommendActivity record) {
|
return recommendActivityMapper.insert(record);
|
}
|
|
@Override
|
public int insertSelective(RecommendActivity record) {
|
return recommendActivityMapper.insertSelective(record);
|
}
|
|
@Override
|
public RecommendActivity selectByPrimaryKey(Long id) {
|
return recommendActivityMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public int updateByPrimaryKeySelective(RecommendActivity record) {
|
return recommendActivityMapper.updateByPrimaryKeySelective(record);
|
}
|
|
@Override
|
public int updateByPrimaryKey(RecommendActivity record) {
|
return recommendActivityMapper.updateByPrimaryKey(record);
|
}
|
|
@Override
|
public ActivityUser selectActivityUserByPrimaryKey(Long id) {
|
return activityUserMapper.selectByPrimaryKey(id);
|
}
|
}
|