| | |
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsRecordMapper;
|
| | | import com.yeshi.fanli.dto.share.ShareInfoDTO;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
|
| | |
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class UserShareGoodsRecordServiceImpl implements UserShareGoodsRecordService {
|
| | |
| | | singleGoodsShare(userShareGoodsRecord, goodsBrief);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public Long saveSingleShareRecord(Long uid, Long auctionId) throws UserShareGoodsRecordException {
|
| | |
|
| | | if (auctionId == null) {
|
| | | throw new UserShareGoodsRecordException(1, "分享商品不能为空");
|
| | | }
|
| | |
|
| | | if (uid == null) {
|
| | | throw new UserShareGoodsRecordException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goodsBrief = null;
|
| | | try {
|
| | | goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new UserShareGoodsRecordException(1, "商品已下架");
|
| | | }
|
| | |
|
| | | UserShareGoodsRecord userShareGoodsRecord = new UserShareGoodsRecord();
|
| | | userShareGoodsRecord.setUid(uid);
|
| | | userShareGoodsRecord.setSource(ShareSourceTypeEnum.goodsDetail);
|
| | | userShareGoodsRecord.setShareState(0);
|
| | | // 单个商品分享
|
| | | singleGoodsShare(userShareGoodsRecord, goodsBrief);
|
| | | |
| | | return userShareGoodsRecord.getId();
|
| | | }
|
| | | |
| | | @Override
|
| | | public void save(Long uid, ShareSourceTypeEnum source, String title, TaoBaoGoodsBrief taoBaoGoodsBrief)
|
| | | throws UserShareGoodsRecordException {
|
| | |
| | |
|
| | | return map;
|
| | | }
|
| | | |
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 保存分享记录
|
| | | * |
| | | * @param userShareGoodsRecord
|
| | | * 分享记录: uid、picture、source 为必输入
|
| | | * @throws UserShareGoodsRecordException
|
| | | */
|
| | | @Override
|
| | | public ShareInfoDTO saveShareRecord(Long uid, ShareSourceTypeEnum source, String title,
|
| | | List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
|
| | |
|
| | | if (listGoods == null || listGoods.size() == 0) {
|
| | | throw new UserShareGoodsRecordException(1, "分享商品数量不足");
|
| | | }
|
| | |
|
| | | if (uid == null) {
|
| | | throw new UserShareGoodsRecordException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (source == null) {
|
| | | throw new UserShareGoodsRecordException(1, "分享来源不能为空");
|
| | | }
|
| | |
|
| | | UserShareGoodsRecord userShareGoodsRecord = new UserShareGoodsRecord();
|
| | | userShareGoodsRecord.setUid(uid);
|
| | | userShareGoodsRecord.setSource(source);
|
| | | userShareGoodsRecord.setTitle(title);
|
| | | // 取一个商品图片作为主图
|
| | | userShareGoodsRecord.setPicture(listGoods.get(0).getPictUrl());
|
| | |
|
| | | Date date = new Date();
|
| | | userShareGoodsRecord.setShareState(0); // 初始未分享
|
| | | userShareGoodsRecord.setCreateTime(date);
|
| | | userShareGoodsRecord.setUpdateTime(date);
|
| | | userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord);
|
| | |
|
| | | // 多个商品分享
|
| | | multipleGoodsShareRecord(userShareGoodsRecord, listGoods);
|
| | | |
| | | ShareInfoDTO shareInfo = new ShareInfoDTO();
|
| | | shareInfo.setShareId(userShareGoodsRecord.getId());
|
| | | shareInfo.setShareUrl(getShareUrl(userShareGoodsRecord));
|
| | | |
| | | return shareInfo;
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 单个商品分享生成记录
|
| | |
| | |
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 多个商品分享生成记录
|
| | | * |
| | | * @param userShareGoodsRecord
|
| | | * @param listGoods
|
| | | */
|
| | | @Transactional
|
| | | public void multipleGoodsShareRecord(UserShareGoodsRecord userShareGoodsRecord,
|
| | | List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
|
| | |
|
| | | // 分享记录
|
| | | Date date = new Date();
|
| | |
|
| | | List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>();
|
| | | List<UserShareGoodsGroup> listGroup = new ArrayList<UserShareGoodsGroup>();
|
| | |
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) {
|
| | | CommonGoods commonGoods = CommonGoodsFactory.create(taoBaoGoodsBrief);
|
| | | commonGoods.setState(taoBaoGoodsBrief.getState());
|
| | | try {
|
| | | CommonGoods resultCommonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
|
| | |
|
| | | if (resultCommonGoods != null) {
|
| | | TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(resultCommonGoods);
|
| | | listGoodsBrief.add(goodsBrief);
|
| | | }
|
| | |
|
| | | UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup();
|
| | | shareGoodsGroup.setTotalOrder(0);
|
| | | shareGoodsGroup.setTotalBrowse(0);
|
| | | shareGoodsGroup.setTodayBrowse(0);
|
| | | shareGoodsGroup.setTotalMoney(new BigDecimal(0));
|
| | | shareGoodsGroup.setCreateTime(date);
|
| | | shareGoodsGroup.setUpdateTime(date);
|
| | | shareGoodsGroup.setCommonGoods(resultCommonGoods);
|
| | | shareGoodsGroup.setRecordId(userShareGoodsRecord.getId());
|
| | |
|
| | | listGroup.add(shareGoodsGroup);
|
| | |
|
| | | } catch (CommonGoodsException e) {
|
| | | e.printStackTrace();
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | if (listGroup.size() > 0) {
|
| | | userShareGoodsGroupService.insertBatch(listGroup);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 多个商品分享生成记录
|
| | | *
|
| | |
| | | return shareImg;
|
| | | }
|
| | |
|
| | | public String getShareUrl (UserShareGoodsRecord shareRecord) {
|
| | | Long uid = shareRecord.getUid();
|
| | | Long shareId = shareRecord.getId();
|
| | | String source = shareRecord.getSource().name();
|
| | |
|
| | | String url = String.format("http://%s/share_mushGoods.html?uid=%s&shareId=%s&source=%s",
|
| | | configService.getH5Host(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), shareId + "",
|
| | | source + "");
|
| | |
|
| | | String shortLink = HttpUtil.getShortLink(url);
|
| | | if (!StringUtil.isNullOrEmpty(shortLink)) {
|
| | | url = shortLink;
|
| | | }
|
| | | return url;
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成分享图
|
| | | *
|
| | |
| | | }
|
| | |
|
| | | shareRecord.setShareState(1);// 分享生效
|
| | | updateByPrimaryKeySelective(shareRecord);
|
| | | // 更新商品为已分享
|
| | | userGoodsStorageService.updateShareState(shareId);
|
| | | updateByPrimaryKeySelective(shareRecord);// 更新商品为已分享
|
| | | |
| | | // 更新选品库商品为已分享
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | userGoodsStorageService.updateShareState(shareId);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countShareRecordByUid(Long uid) {
|
| | |
|
| | | return userShareGoodsRecordMapper.countQueryByUid(uid, null);
|
| | |
|
| | | }
|
| | | }
|