| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.InputStream;
|
| | | 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 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.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.QRCodeUtil;
|
| | | import org.yeshi.utils.entity.FileUploadResult;
|
| | | import org.yeshi.utils.exception.HttpException;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsRecordMapper;
|
| | | 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.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
| | | import com.yeshi.fanli.exception.goods.CommonGoodsException;
|
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
|
| | | import com.yeshi.fanli.util.AESUtil;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.ImageUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
|
| | | @Service
|
| | | public class UserShareGoodsRecordServiceImpl implements UserShareGoodsRecordService {
|
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | | |
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | |
| | | @Resource
|
| | | private UserInfoMapper userInfoMapper;
|
| | | |
| | | @Resource
|
| | | private UserAccountService userAccountService;
|
| | | |
| | | @Resource
|
| | | private UserShareGoodsRecordMapper userShareGoodsRecordMapper;
|
| | | |
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | | |
| | | @Resource
|
| | | private UserShareGoodsGroupService userShareGoodsGroupService;
|
| | | |
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | | |
| | | @Resource
|
| | | private UserGoodsStorageService userGoodsStorageService;
|
| | |
|
| | | @Override
|
| | | public int insert(UserShareGoodsRecord record) {
|
| | | return userShareGoodsRecordMapper.insert(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insertSelective(UserShareGoodsRecord record) {
|
| | | return userShareGoodsRecordMapper.insertSelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsRecord selectByPrimaryKey(Long id) {
|
| | | return userShareGoodsRecordMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(UserShareGoodsRecord record) {
|
| | | return userShareGoodsRecordMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public List<UserShareGoodsRecord> listQueryByUid(long start, int count, Long uid, String source) {
|
| | | return userShareGoodsRecordMapper.listQueryByUid(start, count, uid, source);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countQueryByUid(Long uid, String source) {
|
| | | return userShareGoodsRecordMapper.countQueryByUid(uid, source);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<UserShareGoodsRecord> listCountRecord(List<Long> list) {
|
| | | return userShareGoodsRecordMapper.listCountRecord(list);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<UserShareGoodsRecord> getMyShareGoodsRecords(long start, int count, Long uid, String source) {
|
| | | |
| | | List<UserShareGoodsRecord> list = listQueryByUid(start, count, uid, source);
|
| | | if (list == null) {
|
| | | list = new ArrayList<UserShareGoodsRecord>();
|
| | | }
|
| | | |
| | | if (list.size() > 0) {
|
| | | List<Long> listId = new ArrayList<Long>();
|
| | | |
| | | for (UserShareGoodsRecord userShareGoodsRecord: list) {
|
| | | userShareGoodsRecord.setShareTime(userShareGoodsRecord.getUpdateTime().getTime());
|
| | | userShareGoodsRecord.setCreateTime(null);
|
| | | userShareGoodsRecord.setUpdateTime(null);
|
| | | listId.add(userShareGoodsRecord.getId());
|
| | | |
| | | // 改变图片尺寸
|
| | | String pictUrl = userShareGoodsRecord.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
|
| | | userShareGoodsRecord.setPicture(TbImgUtil.getTBSize320Img(pictUrl));
|
| | | }
|
| | | |
| | | |
| | | }
|
| | | |
| | | // 今日浏览统计
|
| | | List<UserShareGoodsRecord> listTodayBrowse= userShareGoodsRecordMapper.listCountTodayBrowse(listId);
|
| | | |
| | | // 订单、浏览数量、金额统计
|
| | | List<UserShareGoodsRecord> listCountRecord = listCountRecord(listId);
|
| | | |
| | | if ((listCountRecord != null && listCountRecord.size() > 0)
|
| | | || (listTodayBrowse != null && listTodayBrowse.size() > 0)) {
|
| | | |
| | | for (UserShareGoodsRecord shareRecord: list) {
|
| | | Long id = shareRecord.getId() ;
|
| | | |
| | | if (listTodayBrowse != null && listTodayBrowse.size() > 0){
|
| | | for (UserShareGoodsRecord goodsRecord: listTodayBrowse) {
|
| | | Long recordId = goodsRecord.getId();
|
| | | if (id == recordId || id.equals(recordId)) {
|
| | | shareRecord.setTodayBrowse(goodsRecord.getTodayBrowse());
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | if (listCountRecord != null && listCountRecord.size() > 0) {
|
| | | for (UserShareGoodsRecord goodsRecord: listCountRecord) {
|
| | | Long recordId = goodsRecord.getId();
|
| | | if (id == recordId || id.equals(recordId)) {
|
| | | shareRecord.setTotalBrowse(goodsRecord.getTotalBrowse());
|
| | | shareRecord.setTotalOrder(goodsRecord.getTotalOrder());
|
| | | |
| | | BigDecimal totalMoney = goodsRecord.getTotalMoney();
|
| | | if (totalMoney != null && totalMoney.compareTo(new BigDecimal(0))>0 ) {
|
| | | shareRecord.setTotalMoney(goodsRecord.getTotalMoney());
|
| | | } else {
|
| | | shareRecord.setTotalMoney(goodsRecord.getRevenueMoney());
|
| | | }
|
| | | shareRecord.setRevenueMoney(null);
|
| | | |
| | | |
| | | Integer totalGoods = goodsRecord.getTotalGoods();
|
| | | shareRecord.setTotalGoods(totalGoods);
|
| | | if (totalGoods > 1) {
|
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_GROUP);
|
| | | } else {
|
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_SINGLE);
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void saveDetail(Long uid, Long auctionId, String type) 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(1);// 已分享成功
|
| | | // 单个商品分享
|
| | | singleGoodsShare(userShareGoodsRecord, goodsBrief);
|
| | | }
|
| | | |
| | | @Override
|
| | | public void save(Long uid, ShareSourceTypeEnum source, String title, TaoBaoGoodsBrief taoBaoGoodsBrief) throws UserShareGoodsRecordException {
|
| | | |
| | | if (taoBaoGoodsBrief == null) {
|
| | | 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);
|
| | | // 单个商品分享
|
| | | singleGoodsShare(userShareGoodsRecord, taoBaoGoodsBrief);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 保存分享记录
|
| | | * @param userShareGoodsRecord 分享记录: uid、picture、source 为必输入
|
| | | * @throws UserShareGoodsRecordException
|
| | | */
|
| | | @Override
|
| | | public JSONObject save(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);
|
| | | |
| | | |
| | | JSONObject data = new JSONObject();
|
| | | // 多个商品分享
|
| | | FileUploadResult loadResult = multipleGoodsShare(userShareGoodsRecord, listGoods);
|
| | | data.put("loadResult", loadResult);
|
| | | data.put("shareId", userShareGoodsRecord.getId());
|
| | | |
| | | return data;
|
| | | }
|
| | | |
| | | /**
|
| | | * 单个商品分享生成记录
|
| | | * @param userShareGoodsRecord
|
| | | * @param taoBaoGoodsBrief
|
| | | */
|
| | | @Transactional
|
| | | public void singleGoodsShare(UserShareGoodsRecord userShareGoodsRecord, TaoBaoGoodsBrief taoBaoGoodsBrief) {
|
| | | |
| | | CommonGoods commonGoods = CommonGoodsFactory.create(taoBaoGoodsBrief);
|
| | | commonGoods.setState(taoBaoGoodsBrief.getState());
|
| | | try {
|
| | | CommonGoods resultCommonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
|
| | | |
| | | if (resultCommonGoods == null) {
|
| | | return;
|
| | | }
|
| | | |
| | | |
| | | UserShareGoodsGroup singleGoods = userShareGoodsGroupService.getSingleGoods(resultCommonGoods.getId(),
|
| | | userShareGoodsRecord.getUid());
|
| | | |
| | | if (singleGoods != null) {
|
| | | // 单个商品多次分享
|
| | | userShareGoodsRecord.setPicture(taoBaoGoodsBrief.getPictUrl());
|
| | | userShareGoodsRecord.setId(singleGoods.getRecordId());
|
| | | userShareGoodsRecord.setUpdateTime(new Date());
|
| | | userShareGoodsRecordMapper.updateByPrimaryKeySelective(userShareGoodsRecord);
|
| | | |
| | | // 最新商品
|
| | | singleGoods.setUpdateTime(new Date());
|
| | | userShareGoodsGroupService.updateByPrimaryKeySelective(singleGoods);
|
| | | |
| | | } else |
| | | {
|
| | | // 单个商品第一次分享
|
| | | Date date = new Date();
|
| | | userShareGoodsRecord.setPicture(taoBaoGoodsBrief.getPictUrl());
|
| | | userShareGoodsRecord.setCreateTime(date);
|
| | | userShareGoodsRecord.setUpdateTime(date);
|
| | | userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord);
|
| | | |
| | | singleGoods = new UserShareGoodsGroup();
|
| | | singleGoods.setTotalOrder(0);
|
| | | singleGoods.setTotalBrowse(0);
|
| | | singleGoods.setTodayBrowse(0);
|
| | | singleGoods.setTotalMoney(new BigDecimal(0));
|
| | | singleGoods.setCreateTime(date);
|
| | | singleGoods.setUpdateTime(date);
|
| | | singleGoods.setCommonGoods(resultCommonGoods);
|
| | | singleGoods.setRecordId(userShareGoodsRecord.getId());
|
| | | |
| | | userShareGoodsGroupService.insertSelective(singleGoods);
|
| | | }
|
| | | |
| | | } catch (CommonGoodsException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 多个商品分享生成记录
|
| | | * @param userShareGoodsRecord
|
| | | * @param listGoods
|
| | | */
|
| | | @Transactional
|
| | | public FileUploadResult multipleGoodsShare(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;
|
| | | }
|
| | | }
|
| | | |
| | | FileUploadResult shareImg = createShareImg(userShareGoodsRecord, listGoodsBrief);
|
| | | |
| | | if (listGroup.size() > 0) {
|
| | | userShareGoodsGroupService.insertBatch(listGroup);
|
| | | }
|
| | | |
| | | return shareImg;
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成分享图
|
| | | * @param uid 用户id
|
| | | * @param shareId 分享记录id
|
| | | * @param source 来源
|
| | | * @param listGoods
|
| | | * @return
|
| | | * @throws UserShareGoodsRecordException
|
| | | */
|
| | | public FileUploadResult createShareImg (UserShareGoodsRecord shareRecord, List<TaoBaoGoodsBrief> listGoods) |
| | | throws UserShareGoodsRecordException{
|
| | | |
| | | 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), shareRecord.getId() + "", source +"");
|
| | | |
| | | String shortLink = HttpUtil.getShortLink(url);
|
| | | if (!StringUtil.isNullOrEmpty(shortLink)) {
|
| | | url = shortLink;
|
| | | }
|
| | | InputStream erCodeInputStream = null;
|
| | |
|
| | | // 生成链接二维码
|
| | | try {
|
| | | erCodeInputStream = QRCodeUtil.getInstance(500).encode(url);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | // 获取到用户的头像
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | if (user == null) {
|
| | | throw new UserShareGoodsRecordException(1, "用户信息不存在");
|
| | | }
|
| | | |
| | | InputStream portrait = null;
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(user.getPortrait())) {
|
| | | try {
|
| | | portrait = HttpUtil.downLoadImg(user.getPortrait());
|
| | | } catch (HttpException e) {
|
| | | String portraitUrl = userAccountService.repairPortrait(uid);
|
| | | if (StringUtil.isNullOrEmpty(portraitUrl))
|
| | | throw new UserShareGoodsRecordException(1, "获取头像出错");
|
| | | else {
|
| | | // 再次获取头像
|
| | | try {
|
| | | portrait = HttpUtil.downLoadImg(portraitUrl);
|
| | | } catch (HttpException e1) {
|
| | | throw new UserShareGoodsRecordException(1, "获取头像出错");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | InputStream inputStream = ImageUtil.drawGoodsShareBigImg(erCodeInputStream, portrait, listGoods);
|
| | | |
| | | FileUploadResult shareImg = COSManager.getInstance().uploadInputStream(inputStream,
|
| | | "sharegoods/share_" + uid + "_" + shareId + "_" + System.currentTimeMillis() + ".png");
|
| | | |
| | | return shareImg;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public JSONObject getGoodsGroup(Long recordId) throws UserShareGoodsRecordException {
|
| | | |
| | | JSONArray array = new JSONArray();
|
| | | List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
|
| | |
|
| | | List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
|
| | | if (list != null && list.size() > 0) {
|
| | |
|
| | | Date nowDate = new Date();
|
| | | long nh = 1000 * 60 * 60;
|
| | | long nd = 1000 * 24 * 60 * 60;
|
| | |
|
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | |
|
| | | Map<String, String> map = hongBaoManageService.convertMap();
|
| | | String proportion = map.get("hongbao_goods_proportion");
|
| | |
|
| | | for (UserShareGoodsGroup userShareGoodsGroup : list) {
|
| | | CommonGoods commonGoods = userShareGoodsGroup.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goodsBrief = null;
|
| | | JSONObject dataObject = new JSONObject();
|
| | |
|
| | | // 更新一个小时之内的商品不再更新
|
| | | Integer goodsState = commonGoods.getState();
|
| | | // 状态未下架时进行更新
|
| | | if (goodsState != null && (goodsState != 1 || !goodsState.equals(1))) {
|
| | | Date updateTime = commonGoods.getUpdateTime();
|
| | | if (updateTime != null) {
|
| | | |
| | | // 计算差多少小时
|
| | | long diff = nowDate.getTime() - updateTime.getTime();
|
| | | long day = diff / nd;
|
| | | long hour = diff % nd / nh;
|
| | | if (hour > 1 || day > 0 ) {
|
| | | try {
|
| | | if (commonGoods.getGoodsType() == CommonGoods.GOODS_TYPE_TB) {
|
| | | goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId());
|
| | | |
| | | goodsState = 0;
|
| | | goodsBrief.setState(goodsState);
|
| | | |
| | | CommonGoods upadeteCommonGoods = CommonGoodsFactory.create(goodsBrief);
|
| | | upadeteCommonGoods.setState(goodsState);
|
| | | upadeteCommonGoods.setId(commonGoods.getId());
|
| | | listUpadteCommonGoods.add(upadeteCommonGoods);
|
| | | }
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | // 已下架
|
| | | goodsState = 1;
|
| | | commonGoods.setState(goodsState);
|
| | | listUpadteCommonGoods.add(commonGoods);
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (goodsBrief == null) {
|
| | | goodsBrief = TaoBaoUtil.convert(commonGoods);
|
| | | } |
| | |
|
| | | // 改变图片尺寸
|
| | | String pictUrl = goodsBrief.getPictUrl();
|
| | | if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
|
| | | goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
|
| | | }
|
| | | |
| | | userShareGoodsGroup.setId(null);
|
| | | userShareGoodsGroup.setBrowseTime(null);
|
| | | userShareGoodsGroup.setCreateTime(null);
|
| | | userShareGoodsGroup.setUpdateTime(null);
|
| | | userShareGoodsGroup.setRecordId(null);
|
| | | |
| | | dataObject.put("todayBrowse",userShareGoodsGroup.getTodayBrowse() );
|
| | | dataObject.put("totalBrowse",userShareGoodsGroup.getTotalBrowse() );
|
| | | dataObject.put("totalOrder", userShareGoodsGroup.getTotalOrder());
|
| | | dataObject.put("totalMoney", "¥"+userShareGoodsGroup.getTotalMoney());
|
| | | dataObject.put("goods", gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null)));
|
| | | array.add(dataObject);
|
| | | }
|
| | | }
|
| | | |
| | | String title = "";
|
| | | UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId);
|
| | | if(userShareGoodsRecord != null) {
|
| | | title = userShareGoodsRecord.getTitle();
|
| | | }
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("title", title);
|
| | | data.put("count", list.size());
|
| | | data.put("result_list", array);
|
| | |
|
| | | if (listUpadteCommonGoods.size() > 0) {
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | // 更新简版信息
|
| | | commonGoodsService.updateBatchCommonGoods(listUpadteCommonGoods);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | |
| | | return data;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public JSONObject getGoodsGroupDetail(Long recordId) throws UserShareGoodsRecordException {
|
| | | |
| | | List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
|
| | |
|
| | | JSONArray array = new JSONArray();
|
| | | |
| | | List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
|
| | | if (list != null && list.size() > 0) {
|
| | |
|
| | | Date nowDate = new Date();
|
| | | long nh = 1000 * 60 * 60;
|
| | | long nd = 1000 * 24 * 60 * 60;
|
| | |
|
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | | |
| | | |
| | | Map<String, String> map = hongBaoManageService.convertMap();
|
| | | String proportion = map.get("hongbao_goods_proportion");
|
| | |
|
| | | for (UserShareGoodsGroup userShareGoodsGroup : list) {
|
| | | CommonGoods commonGoods = userShareGoodsGroup.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goodsBrief = null;
|
| | | // 更新一个小时之内的商品不再更新
|
| | | Integer goodsState = commonGoods.getState();
|
| | | // 状态未下架时进行更新
|
| | | if (goodsState != null && (goodsState != 1 || !goodsState.equals(1))) {
|
| | | Date updateTime = commonGoods.getUpdateTime();
|
| | | if (updateTime != null) {
|
| | | |
| | | // 计算差多少小时
|
| | | long diff = nowDate.getTime() - updateTime.getTime();
|
| | | long day = diff / nd;
|
| | | long hour = diff % nd / nh;
|
| | | if (hour > 1 || day > 0 ) {
|
| | | try {
|
| | | if (commonGoods.getGoodsType() == CommonGoods.GOODS_TYPE_TB) {
|
| | | goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId());
|
| | | |
| | | goodsState = 0;
|
| | | goodsBrief.setState(goodsState); // 在售
|
| | | |
| | | CommonGoods upadeteCommonGoods = CommonGoodsFactory.create(goodsBrief);
|
| | | upadeteCommonGoods.setState(goodsState);
|
| | | upadeteCommonGoods.setId(commonGoods.getId());
|
| | | listUpadteCommonGoods.add(upadeteCommonGoods);
|
| | | }
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | // 已下架
|
| | | goodsState = 1;
|
| | | commonGoods.setState(goodsState);
|
| | | listUpadteCommonGoods.add(commonGoods);
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (goodsBrief == null) {
|
| | | goodsBrief = TaoBaoUtil.convert(commonGoods);
|
| | | } |
| | | |
| | | if (goodsBrief.getCouponLeftCount() < 1 || StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())) {
|
| | | goodsBrief.setState(1); // 已抢光
|
| | | }
|
| | | |
| | | // 改变图片尺寸
|
| | | String pictUrl = goodsBrief.getPictUrl();
|
| | | if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
|
| | | goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
|
| | | }
|
| | | |
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null);
|
| | | array.add(gson.toJson(taoBaoGoodsBriefExtra));
|
| | | }
|
| | | }
|
| | | |
| | | String title = "";
|
| | | UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId);
|
| | | if(userShareGoodsRecord != null) {
|
| | | title = userShareGoodsRecord.getTitle();
|
| | | }
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("title", title);
|
| | | data.put("count", list.size());
|
| | | data.put("result_list", array);
|
| | |
|
| | | if (listUpadteCommonGoods.size() > 0) {
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | // 更新简版信息
|
| | | commonGoodsService.updateBatchCommonGoods(listUpadteCommonGoods);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | |
| | | return data;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateShareRecord (Long shareId) throws UserShareGoodsRecordException {
|
| | | UserShareGoodsRecord shareRecord = userShareGoodsRecordMapper.selectByPrimaryKey(shareId);
|
| | | if (shareRecord == null) {
|
| | | throw new UserShareGoodsRecordException(1, "分享记录不存在");
|
| | | }
|
| | | |
| | | shareRecord.setShareState(1);// 分享生效
|
| | | updateByPrimaryKeySelective(shareRecord);
|
| | | // 更新商品为已分享
|
| | | userGoodsStorageService.updateShareState(shareId);
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.service.inter.user.*; |
| | | 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 org.yeshi.utils.QRCodeUtil; |
| | | import org.yeshi.utils.entity.FileUploadResult; |
| | | import org.yeshi.utils.exception.HttpException; |
| | | import org.yeshi.utils.taobao.TbImgUtil; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsRecordMapper; |
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; |
| | | import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | 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.entity.bus.user.UserGoodsStorage; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; |
| | | import com.yeshi.fanli.entity.goods.CommonGoods; |
| | | import com.yeshi.fanli.entity.jd.JDGoods; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBriefExtra; |
| | | import com.yeshi.fanli.exception.goods.CommonGoodsException; |
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException; |
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException; |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService; |
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService; |
| | | import com.yeshi.fanli.util.AESUtil; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.FilePathEnum; |
| | | import com.yeshi.fanli.util.ImageUtil; |
| | | import com.yeshi.fanli.util.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | 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 { |
| | | |
| | | @Resource(name = "taskExecutor") |
| | | private TaskExecutor executor; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserAccountService userAccountService; |
| | | |
| | | @Resource |
| | | private UserShareGoodsRecordMapper userShareGoodsRecordMapper; |
| | | |
| | | @Resource |
| | | private CommonGoodsService commonGoodsService; |
| | | |
| | | @Resource |
| | | private UserShareGoodsGroupService userShareGoodsGroupService; |
| | | |
| | | @Resource |
| | | private HongBaoManageService hongBaoManageService; |
| | | |
| | | @Resource |
| | | private UserGoodsStorageService userGoodsStorageService; |
| | | |
| | | @Resource |
| | | private IntegralGetService integralGetService; |
| | | |
| | | @Override |
| | | public int insert(UserShareGoodsRecord record) { |
| | | return userShareGoodsRecordMapper.insert(record); |
| | | } |
| | | |
| | | @Override |
| | | public int insertSelective(UserShareGoodsRecord record) { |
| | | return userShareGoodsRecordMapper.insertSelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public UserShareGoodsRecord selectByPrimaryKey(Long id) { |
| | | return userShareGoodsRecordMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public int updateByPrimaryKeySelective(UserShareGoodsRecord record) { |
| | | return userShareGoodsRecordMapper.updateByPrimaryKeySelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserShareGoodsRecord> listQueryByUid(long start, int count, Long uid, String source) { |
| | | return userShareGoodsRecordMapper.listQueryByUid(start, count, uid, source); |
| | | } |
| | | |
| | | @Override |
| | | public long countQueryByUid(Long uid, String source) { |
| | | return userShareGoodsRecordMapper.countQueryByUid(uid, source); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserShareGoodsGroup> listByRecordId(Long shareId) { |
| | | return userShareGoodsGroupService.listByRecordId(shareId, true); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserShareGoodsRecord> listCountRecord(List<Long> list) { |
| | | return userShareGoodsRecordMapper.listCountRecord(list); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserShareGoodsRecord> getMyShareGoodsRecords(long start, int count, Long uid, String source) { |
| | | |
| | | List<UserShareGoodsRecord> list = listQueryByUid(start, count, uid, source); |
| | | if (list == null) { |
| | | list = new ArrayList<UserShareGoodsRecord>(); |
| | | } |
| | | |
| | | if (list.size() > 0) { |
| | | List<Long> listId = new ArrayList<Long>(); |
| | | |
| | | for (UserShareGoodsRecord userShareGoodsRecord : list) { |
| | | userShareGoodsRecord.setShareTime(userShareGoodsRecord.getUpdateTime().getTime()); |
| | | userShareGoodsRecord.setCreateTime(null); |
| | | userShareGoodsRecord.setUpdateTime(null); |
| | | listId.add(userShareGoodsRecord.getId()); |
| | | |
| | | // 改变图片尺寸 |
| | | String pictUrl = userShareGoodsRecord.getPicture(); |
| | | if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) { |
| | | userShareGoodsRecord.setPicture(TbImgUtil.getTBSize320Img(pictUrl)); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 今日浏览统计 |
| | | List<UserShareGoodsRecord> listTodayBrowse = userShareGoodsRecordMapper.listCountTodayBrowse(listId); |
| | | |
| | | // 订单、浏览数量、金额统计 |
| | | List<UserShareGoodsRecord> listCountRecord = listCountRecord(listId); |
| | | |
| | | if ((listCountRecord != null && listCountRecord.size() > 0) |
| | | || (listTodayBrowse != null && listTodayBrowse.size() > 0)) { |
| | | |
| | | for (UserShareGoodsRecord shareRecord : list) { |
| | | Long id = shareRecord.getId(); |
| | | |
| | | if (listTodayBrowse != null && listTodayBrowse.size() > 0) { |
| | | for (UserShareGoodsRecord goodsRecord : listTodayBrowse) { |
| | | Long recordId = goodsRecord.getId(); |
| | | if (id == recordId || id.equals(recordId)) { |
| | | shareRecord.setTodayBrowse(goodsRecord.getTodayBrowse()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (listCountRecord != null && listCountRecord.size() > 0) { |
| | | for (UserShareGoodsRecord goodsRecord : listCountRecord) { |
| | | Long recordId = goodsRecord.getId(); |
| | | if (id == recordId || id.equals(recordId)) { |
| | | shareRecord.setTotalBrowse(goodsRecord.getTotalBrowse()); |
| | | shareRecord.setTotalOrder(goodsRecord.getTotalOrder()); |
| | | |
| | | BigDecimal totalMoney = goodsRecord.getTotalMoney(); |
| | | if (totalMoney != null && totalMoney.compareTo(new BigDecimal(0)) > 0) { |
| | | shareRecord.setTotalMoney(goodsRecord.getTotalMoney()); |
| | | } else { |
| | | shareRecord.setTotalMoney(goodsRecord.getRevenueMoney()); |
| | | } |
| | | shareRecord.setRevenueMoney(null); |
| | | |
| | | Integer totalGoods = goodsRecord.getTotalGoods(); |
| | | shareRecord.setTotalGoods(totalGoods); |
| | | if (totalGoods > 1) { |
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_GROUP); |
| | | } else { |
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_SINGLE); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | String shareType = shareRecord.getShareType(); |
| | | if (StringUtil.isNullOrEmpty(shareType)) { |
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_SINGLE); |
| | | } |
| | | |
| | | BigDecimal totalMoney = shareRecord.getTotalMoney(); |
| | | if (totalMoney == null) { |
| | | shareRecord.setTotalMoney(new BigDecimal(0)); |
| | | } |
| | | } |
| | | } else { |
| | | for (UserShareGoodsRecord shareRecord : list) { |
| | | String shareType = shareRecord.getShareType(); |
| | | if (StringUtil.isNullOrEmpty(shareType)) { |
| | | shareRecord.setShareType(UserShareGoodsRecord.SHARETYPE_SINGLE); |
| | | } |
| | | |
| | | BigDecimal totalMoney = shareRecord.getTotalMoney(); |
| | | if (totalMoney == null) { |
| | | shareRecord.setTotalMoney(new BigDecimal(0)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void saveSingleShareRecord(Long uid, String goodsId, Integer goodsType) throws UserShareGoodsRecordException { |
| | | if (goodsId == null) { |
| | | throw new UserShareGoodsRecordException(1, "分享商品不能为空"); |
| | | } |
| | | |
| | | if (uid == null) { |
| | | throw new UserShareGoodsRecordException(1, "用户ID不能为空"); |
| | | } |
| | | |
| | | if (goodsType == null) { |
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO; |
| | | } |
| | | |
| | | CommonGoods convertGoods = null; |
| | | if (goodsType == Constant.SOURCE_TYPE_JD) { |
| | | JDGoods jdGoods = redisManager.getJDGoods(goodsId); |
| | | if (jdGoods == null) { |
| | | throw new UserShareGoodsRecordException(1, "商品已下架"); |
| | | } |
| | | convertGoods = CommonGoodsFactory.create(jdGoods); |
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) { |
| | | PDDGoodsDetail pddGoods = redisManager.getPDDGoodsDetail(goodsId); |
| | | if (pddGoods == null) { |
| | | throw new UserShareGoodsRecordException(1, "商品已下架"); |
| | | } |
| | | convertGoods = CommonGoodsFactory.create(pddGoods); |
| | | } else { |
| | | TaoBaoGoodsBrief goodsBrief = null; |
| | | try { |
| | | goodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | throw new UserShareGoodsRecordException(1, "商品已下架"); |
| | | } |
| | | convertGoods = CommonGoodsFactory.create(goodsBrief); |
| | | } |
| | | |
| | | UserShareGoodsRecord userShareGoodsRecord = new UserShareGoodsRecord(); |
| | | userShareGoodsRecord.setUid(uid); |
| | | userShareGoodsRecord.setSource(ShareSourceTypeEnum.goodsDetail); |
| | | userShareGoodsRecord.setShareState(1); |
| | | |
| | | convertGoods.setState(0); |
| | | CommonGoods resultCommonGoods = null; |
| | | try { |
| | | resultCommonGoods = commonGoodsService.addOrUpdateCommonGoods(convertGoods); |
| | | } catch (CommonGoodsException e) { |
| | | throw new UserShareGoodsRecordException(1, "商品存入失败"); |
| | | } |
| | | |
| | | UserShareGoodsGroup singleGoods = userShareGoodsGroupService.getSingleGoods(resultCommonGoods.getId(), |
| | | userShareGoodsRecord.getUid()); |
| | | |
| | | if (singleGoods != null) { |
| | | // 单个商品多次分享 |
| | | userShareGoodsRecord.setPicture(resultCommonGoods.getPicture()); |
| | | userShareGoodsRecord.setId(singleGoods.getRecordId()); |
| | | userShareGoodsRecord.setUpdateTime(new Date()); |
| | | userShareGoodsRecordMapper.updateByPrimaryKeySelective(userShareGoodsRecord); |
| | | |
| | | // 最新商品 |
| | | singleGoods.setUpdateTime(new Date()); |
| | | userShareGoodsGroupService.updateByPrimaryKeySelective(singleGoods); |
| | | |
| | | } else { |
| | | // 单个商品第一次分享 |
| | | Date date = new Date(); |
| | | userShareGoodsRecord.setPicture(resultCommonGoods.getPicture()); |
| | | userShareGoodsRecord.setCreateTime(date); |
| | | userShareGoodsRecord.setUpdateTime(date); |
| | | userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord); |
| | | |
| | | singleGoods = new UserShareGoodsGroup(); |
| | | singleGoods.setTotalOrder(0); |
| | | singleGoods.setTotalBrowse(0); |
| | | singleGoods.setTodayBrowse(0); |
| | | singleGoods.setTotalMoney(new BigDecimal(0)); |
| | | singleGoods.setCreateTime(date); |
| | | singleGoods.setUpdateTime(date); |
| | | singleGoods.setCommonGoods(resultCommonGoods); |
| | | singleGoods.setRecordId(userShareGoodsRecord.getId()); |
| | | userShareGoodsGroupService.insertSelective(singleGoods); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 多个商品分享生成记录 |
| | | * |
| | | * @param listGoods |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void multipleGoodsShareRecord(Long shareId, List<CommonGoods> listGoods) |
| | | throws UserShareGoodsRecordException { |
| | | // 分享记录 |
| | | Date date = new Date(); |
| | | List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); |
| | | List<UserShareGoodsGroup> listGroup = new ArrayList<UserShareGoodsGroup>(); |
| | | |
| | | for (CommonGoods commonGoods : listGoods) { |
| | | 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(shareId); |
| | | listGroup.add(shareGoodsGroup); |
| | | } catch (CommonGoodsException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | if (listGroup.size() > 0) { |
| | | userShareGoodsGroupService.insertBatch(listGroup); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 多个商品分享生成记录 |
| | | * |
| | | * @param userShareGoodsRecord |
| | | * @param listGoods |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public FileUploadResult multipleGoodsShare(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; |
| | | } |
| | | } |
| | | |
| | | FileUploadResult shareImg = createShareImg(userShareGoodsRecord, listGoodsBrief); |
| | | |
| | | if (listGroup.size() > 0) { |
| | | userShareGoodsGroupService.insertBatch(listGroup); |
| | | } |
| | | |
| | | return shareImg; |
| | | } |
| | | |
| | | /** |
| | | * 生成分享图 |
| | | * |
| | | * @param listGoods |
| | | * @return |
| | | * @throws UserShareGoodsRecordException |
| | | */ |
| | | public FileUploadResult createShareImg(UserShareGoodsRecord shareRecord, List<TaoBaoGoodsBrief> listGoods) |
| | | throws UserShareGoodsRecordException { |
| | | |
| | | Long uid = shareRecord.getUid(); |
| | | Long shareId = shareRecord.getId(); |
| | | String source = shareRecord.getSource().name(); |
| | | |
| | | SystemEnum system = userInfoService.getUserSystem(uid); |
| | | |
| | | String url = String.format("http://%s/share_mushGoods.html?uid=%s&shareId=%s&source=%s", |
| | | configService.getH5Host(system), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), shareRecord.getId() + "", |
| | | source + ""); |
| | | |
| | | String shortLink = HttpUtil.getShortLink(url); |
| | | if (!StringUtil.isNullOrEmpty(shortLink)) { |
| | | url = shortLink; |
| | | } |
| | | InputStream erCodeInputStream = null; |
| | | |
| | | // 生成链接二维码 |
| | | try { |
| | | erCodeInputStream = QRCodeUtil.getInstance(500).encode(url); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 获取到用户的头像 |
| | | UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid); |
| | | if (user == null) { |
| | | throw new UserShareGoodsRecordException(1, "用户信息不存在"); |
| | | } |
| | | |
| | | InputStream portrait = null; |
| | | |
| | | if (!StringUtil.isNullOrEmpty(user.getPortrait())) { |
| | | try { |
| | | portrait = HttpUtil.downLoadImg(user.getPortrait()); |
| | | } catch (HttpException e) { |
| | | String portraitUrl = userAccountService.repairPortrait(uid); |
| | | if (StringUtil.isNullOrEmpty(portraitUrl)) |
| | | throw new UserShareGoodsRecordException(1, "获取头像出错"); |
| | | else { |
| | | // 再次获取头像 |
| | | try { |
| | | portrait = HttpUtil.downLoadImg(portraitUrl); |
| | | } catch (HttpException e1) { |
| | | throw new UserShareGoodsRecordException(1, "获取头像出错"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | InputStream inputStream = ImageUtil.drawGoodsShareBigImg(erCodeInputStream, portrait, listGoods); |
| | | |
| | | FileUploadResult shareImg = COSManager.getInstance().uploadInputStream(inputStream, |
| | | FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + shareId + "_" + System.currentTimeMillis() |
| | | + ".png"); |
| | | |
| | | return shareImg; |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getGoodsGroup(Long recordId, SystemEnum system) throws UserShareGoodsRecordException { |
| | | |
| | | JSONArray array = new JSONArray(); |
| | | |
| | | List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId, true); |
| | | |
| | | List<String> listGid = new ArrayList<>(); |
| | | for (UserShareGoodsGroup goodsGroup : list) { |
| | | CommonGoods commonGoods = goodsGroup.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | listGid.add(commonGoods.getGoodsId()); |
| | | } |
| | | |
| | | // API网络接口验证是否在售 |
| | | List<TaoBaoGoodsBrief> listTaoKeGoods = null; |
| | | try { |
| | | listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) |
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); |
| | | |
| | | BigDecimal shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen, |
| | | java.lang.System.currentTimeMillis(),system); |
| | | |
| | | for (UserShareGoodsGroup goodsGroup : list) { |
| | | CommonGoods commonGoods = goodsGroup.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) { |
| | | int state = 1; // 默认停售 |
| | | String goodsId = commonGoods.getGoodsId(); |
| | | for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { |
| | | String auctionId = taoKeGoods.getAuctionId(); |
| | | if (TaoBaoUtil.isEqual(goodsId ,auctionId)) { |
| | | state = 0; // 在售 |
| | | break; |
| | | } |
| | | } |
| | | commonGoods.setState(state); |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); |
| | | |
| | | // 今日浏览记录处理 |
| | | Date date = new Date(); |
| | | Date browseTime = goodsGroup.getBrowseTime(); |
| | | if (!DateUtil.isSameDay(browseTime, date)) { |
| | | goodsGroup.setTodayBrowse(0); // 不是同一天浏览记录设置0 |
| | | } |
| | | |
| | | JSONObject dataObject = new JSONObject(); |
| | | dataObject.put("todayBrowse", goodsGroup.getTodayBrowse()); |
| | | dataObject.put("totalBrowse", goodsGroup.getTotalBrowse()); |
| | | dataObject.put("totalOrder", goodsGroup.getTotalOrder()); |
| | | dataObject.put("totalMoney", "¥" + goodsGroup.getTotalMoney()); |
| | | dataObject.put("goods", gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, shareRate + "", null))); |
| | | array.add(dataObject); |
| | | } |
| | | |
| | | String title = ""; |
| | | UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId); |
| | | if (userShareGoodsRecord != null) { |
| | | title = userShareGoodsRecord.getTitle(); |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("title", title); |
| | | data.put("count", list.size()); |
| | | data.put("result_list", array); |
| | | return data; |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getGoodsGroupDetail(Long recordId, SystemEnum system) throws UserShareGoodsRecordException { |
| | | |
| | | JSONArray array = new JSONArray(); |
| | | |
| | | List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId, true); |
| | | |
| | | if (list != null && list.size() > 0) { |
| | | |
| | | List<String> listGid = new ArrayList<>(); |
| | | for (UserShareGoodsGroup goodsGroup : list) { |
| | | CommonGoods commonGoods = goodsGroup.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | listGid.add(commonGoods.getGoodsId()); |
| | | } |
| | | |
| | | // API网络接口验证是否在售 |
| | | List<TaoBaoGoodsBrief> listTaoKeGoods = null; |
| | | try { |
| | | listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) |
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); |
| | | |
| | | BigDecimal shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen, |
| | | java.lang.System.currentTimeMillis(),system); |
| | | |
| | | for (UserShareGoodsGroup goodsGroup : list) { |
| | | CommonGoods commonGoods = goodsGroup.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) { |
| | | int state = 1; // 默认停售 |
| | | String goodsId = commonGoods.getGoodsId(); |
| | | for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { |
| | | String auctionId = taoKeGoods.getAuctionId(); |
| | | if (TaoBaoUtil.isEqual( goodsId , auctionId)) { |
| | | state = 0; // 在售 |
| | | break; |
| | | } |
| | | } |
| | | commonGoods.setState(state); |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); |
| | | |
| | | if (goodsBrief.getCouponLeftCount() < 1 || StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())) { |
| | | goodsBrief.setState(1); // 已抢光 |
| | | } |
| | | |
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, |
| | | shareRate + "", null); |
| | | array.add(gson.toJson(taoBaoGoodsBriefExtra)); |
| | | } |
| | | |
| | | } |
| | | |
| | | String title = ""; |
| | | UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId); |
| | | if (userShareGoodsRecord != null) { |
| | | title = userShareGoodsRecord.getTitle(); |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("title", title); |
| | | data.put("count", list.size()); |
| | | data.put("result_list", array); |
| | | |
| | | return data; |
| | | } |
| | | |
| | | @Override |
| | | public long countShareRecordByUid(Long uid) { |
| | | return userShareGoodsRecordMapper.countQueryByUid(uid, null); |
| | | } |
| | | |
| | | @Override |
| | | public ShareGoodsRecordDTO addRecordGoodsDetail(Long uid, String auctionId, Integer goodsType, boolean isTaolijin) |
| | | throws UserShareGoodsRecordException { |
| | | if (auctionId == null || uid == null || uid <= 0) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | |
| | | ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); |
| | | recordDTO.setUid(uid); |
| | | recordDTO.setAuctionId(auctionId); |
| | | recordDTO.setGoodsType(goodsType); |
| | | recordDTO.setTaolijin(isTaolijin); |
| | | recordDTO.setSource(ShareSourceTypeEnum.goodsDetail); |
| | | |
| | | // 分享id |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, |
| | | StringUtil.Md5(uid + "#GoodsDetail#" + auctionId + "#Type#" + goodsType)); |
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); |
| | | recordDTO.setRedisKey(key); |
| | | |
| | | return recordDTO; |
| | | } |
| | | |
| | | @Override |
| | | public ShareGoodsRecordDTO addRecordGoodsStorage(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief, |
| | | List<Long> listStorageID) throws UserShareGoodsRecordException { |
| | | if (uid == null || uid <= 0 || listGoodsBrief == null || listGoodsBrief.size() == 0) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | // 插入记录 |
| | | UserShareGoodsRecord record = new UserShareGoodsRecord(); |
| | | record.setUid(uid); |
| | | record.setShareState(0); // 初始未分享 |
| | | record.setSource(ShareSourceTypeEnum.storage); |
| | | record.setPicture(listGoodsBrief.get(0).getPictUrl()); // 取一个商品图片作为主图 |
| | | record.setCreateTime(new Date()); |
| | | userShareGoodsRecordMapper.insertSelective(record); |
| | | |
| | | List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); |
| | | for (TaoBaoGoodsBrief goodsBrief : listGoodsBrief) { |
| | | listCommonGoods.add(CommonGoodsFactory.create(goodsBrief)); |
| | | } |
| | | |
| | | Long id = record.getId(); |
| | | // 分享链接 |
| | | String shareUrl = getShareUrl(record); |
| | | // 分享二维码链接 |
| | | FileUploadResult uploadResult = drawingSharePicture(uid, id, shareUrl, listCommonGoods); |
| | | |
| | | ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); |
| | | recordDTO.setUid(uid); |
| | | recordDTO.setShareId(id); |
| | | recordDTO.setShareUrl(shareUrl); |
| | | recordDTO.setListId(listStorageID); |
| | | recordDTO.setListGoods(listCommonGoods); |
| | | recordDTO.setSharePictureUrl(uploadResult.getUrl()); |
| | | recordDTO.setSource(ShareSourceTypeEnum.storage); |
| | | |
| | | // 缓存分享商品信息 |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5(uid + "#GoodsStorage#" + id)); |
| | | recordDTO.setRedisKey(key); |
| | | |
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); |
| | | |
| | | return recordDTO; |
| | | } |
| | | |
| | | @Override |
| | | public ShareGoodsRecordDTO addRecordGoodsStorageV2(Long uid, List<CommonGoods> listGoods, List<Long> listStorageID, |
| | | boolean needDrawPicture) throws UserShareGoodsRecordException { |
| | | if (uid == null || uid <= 0 || listGoods == null || listGoods.size() == 0) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | // 插入记录 |
| | | UserShareGoodsRecord record = new UserShareGoodsRecord(); |
| | | record.setUid(uid); |
| | | record.setShareState(0); // 初始未分享 |
| | | record.setSource(ShareSourceTypeEnum.storage); |
| | | record.setPicture(listGoods.get(0).getPicture()); // 取一个商品图片作为主图 |
| | | record.setCreateTime(new Date()); |
| | | userShareGoodsRecordMapper.insertSelective(record); |
| | | |
| | | Long id = record.getId(); |
| | | // 分享链接 |
| | | String shareUrl = getShareUrlV2(record); |
| | | // 分享二维码链接 |
| | | |
| | | ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); |
| | | recordDTO.setUid(uid); |
| | | recordDTO.setShareId(id); |
| | | recordDTO.setShareUrl(shareUrl); |
| | | recordDTO.setListId(listStorageID); |
| | | recordDTO.setListGoods(listGoods); |
| | | if (needDrawPicture) { |
| | | FileUploadResult uploadResult = drawingSharePicture(uid, id, shareUrl, listGoods); |
| | | recordDTO.setSharePictureUrl(uploadResult.getUrl()); |
| | | } |
| | | recordDTO.setSource(ShareSourceTypeEnum.storage); |
| | | |
| | | // 缓存分享商品信息 |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5(uid + "#GoodsStorage#" + id)); |
| | | recordDTO.setRedisKey(key); |
| | | |
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); |
| | | |
| | | return recordDTO; |
| | | } |
| | | |
| | | @Override |
| | | public ShareGoodsRecordDTO addRecordActivity(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief) |
| | | throws UserShareGoodsRecordException { |
| | | |
| | | if (uid == null || uid <= 0 || listGoodsBrief == null || listGoodsBrief.size() == 0) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | |
| | | // 插入记录 |
| | | UserShareGoodsRecord record = new UserShareGoodsRecord(); |
| | | record.setUid(uid); |
| | | record.setShareState(0); // 初始未分享 |
| | | record.setSource(ShareSourceTypeEnum.activity); |
| | | record.setPicture(listGoodsBrief.get(0).getPictUrl()); // 取一个商品图片作为主图 |
| | | record.setCreateTime(new Date()); |
| | | userShareGoodsRecordMapper.insertSelective(record); |
| | | |
| | | List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); |
| | | for (TaoBaoGoodsBrief goodsBrief : listGoodsBrief) { |
| | | listCommonGoods.add(CommonGoodsFactory.create(goodsBrief)); |
| | | } |
| | | |
| | | Long id = record.getId(); |
| | | // 分享链接 |
| | | String shareUrl = getShareUrl(record); |
| | | // 分享二维码链接 |
| | | FileUploadResult uploadResult = drawingSharePicture(uid, id, shareUrl, listCommonGoods); |
| | | |
| | | ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); |
| | | recordDTO.setUid(uid); |
| | | recordDTO.setShareId(id); |
| | | recordDTO.setListGoods(listCommonGoods); |
| | | recordDTO.setShareUrl(shareUrl); |
| | | recordDTO.setSharePictureUrl(uploadResult.getUrl()); |
| | | recordDTO.setSource(ShareSourceTypeEnum.activity); |
| | | // 缓存分享商品信息 |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5(uid + "#Activity#" + id)); |
| | | recordDTO.setRedisKey(key); |
| | | |
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); |
| | | |
| | | return recordDTO; |
| | | } |
| | | |
| | | @Override |
| | | public ShareGoodsRecordDTO addRecordDynamic(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief) |
| | | throws UserShareGoodsRecordException { |
| | | if (uid == null || uid <= 0 || listGoodsBrief == null || listGoodsBrief.size() == 0) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | |
| | | // 插入记录 |
| | | UserShareGoodsRecord record = new UserShareGoodsRecord(); |
| | | record.setUid(uid); |
| | | record.setShareState(0); // 初始未分享 |
| | | record.setSource(ShareSourceTypeEnum.activity); |
| | | record.setPicture(listGoodsBrief.get(0).getPictUrl()); // 取一个商品图片作为主图 |
| | | record.setCreateTime(new Date()); |
| | | userShareGoodsRecordMapper.insertSelective(record); |
| | | |
| | | List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); |
| | | for (TaoBaoGoodsBrief goodsBrief : listGoodsBrief) { |
| | | listCommonGoods.add(CommonGoodsFactory.create(goodsBrief)); |
| | | } |
| | | |
| | | Long id = record.getId(); |
| | | // 分享链接 |
| | | String shareUrl = getShareUrl(record); |
| | | |
| | | ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); |
| | | recordDTO.setUid(uid); |
| | | recordDTO.setShareId(id); |
| | | recordDTO.setShareUrl(shareUrl); |
| | | recordDTO.setListGoods(listCommonGoods); |
| | | recordDTO.setSource(ShareSourceTypeEnum.activity); |
| | | |
| | | // 缓存分享商品信息 |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5(uid + "#Dynamic#" + id)); |
| | | recordDTO.setRedisKey(key); |
| | | |
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); |
| | | |
| | | return recordDTO; |
| | | } |
| | | |
| | | @Override |
| | | public void takeEffectShareRecord(AcceptData acceptData, String shareKey) throws UserShareGoodsRecordException { |
| | | if (StringUtil.isNullOrEmpty(shareKey)) { |
| | | throw new UserShareGoodsRecordException(1, "传递参数不正确"); |
| | | } |
| | | ShareGoodsRecordDTO recordDTO = null; |
| | | String redisKey = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, shareKey); |
| | | String value = redisManager.getCommonString(redisKey); |
| | | if (!StringUtil.isNullOrEmpty(value)) { |
| | | recordDTO = JsonUtil.getSimpleGson().fromJson(value, ShareGoodsRecordDTO.class); |
| | | } |
| | | |
| | | if (recordDTO == null) { |
| | | throw new UserShareGoodsRecordException(1, "分享信息不存在"); |
| | | } |
| | | |
| | | Long uid = recordDTO.getUid(); |
| | | boolean taolijin = recordDTO.isTaolijin(); |
| | | boolean singleGoods = true; |
| | | Long shareId = recordDTO.getShareId(); |
| | | ShareSourceTypeEnum source = recordDTO.getSource(); |
| | | if (ShareSourceTypeEnum.goodsDetail.equals(source)) { |
| | | // 商品详情分享 |
| | | saveSingleShareRecord(recordDTO.getUid(), recordDTO.getAuctionId(), recordDTO.getGoodsType()); |
| | | } else if (ShareSourceTypeEnum.activity.equals(source)) { |
| | | // 动态分享 |
| | | UserShareGoodsRecord shareRecord = new UserShareGoodsRecord(); |
| | | shareRecord.setId(shareId); |
| | | shareRecord.setShareState(1); |
| | | shareRecord.setUpdateTime(new Date()); |
| | | updateByPrimaryKeySelective(shareRecord); |
| | | |
| | | List<CommonGoods> listGoods = recordDTO.getListGoods(); |
| | | if (listGoods != null && listGoods.size() > 1) |
| | | singleGoods = false; |
| | | |
| | | // 保存商品信息 |
| | | multipleGoodsShareRecord(shareId, recordDTO.getListGoods()); |
| | | |
| | | } else if (ShareSourceTypeEnum.storage.equals(source)) { |
| | | // 分享库分享 |
| | | singleGoods = false; |
| | | |
| | | UserShareGoodsRecord shareRecord = new UserShareGoodsRecord(); |
| | | shareRecord.setId(shareId); |
| | | shareRecord.setShareState(1); |
| | | shareRecord.setUpdateTime(new Date()); |
| | | updateByPrimaryKeySelective(shareRecord); |
| | | |
| | | // 保存商品信息 |
| | | multipleGoodsShareRecord(shareId, recordDTO.getListGoods()); |
| | | |
| | | // 更新选品库商品状态 为已分享 |
| | | List<Long> listId = recordDTO.getListId(); |
| | | if (listId != null && listId.size() > 0) { |
| | | for (Long id : listId) { |
| | | UserGoodsStorage userGoodsStorage = new UserGoodsStorage(); |
| | | userGoodsStorage.setId(id); |
| | | userGoodsStorage.setState(1); |
| | | userGoodsStorageService.updateByPrimaryKeySelective(userGoodsStorage); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 清理缓存 |
| | | redisManager.removeCommonString(redisKey); |
| | | |
| | | if (singleGoods) { |
| | | if (taolijin) { |
| | | integralGetService.addShareTLJGoods(uid); |
| | | } else { |
| | | integralGetService.addShareSingleGoods(uid); |
| | | } |
| | | } else { |
| | | integralGetService.addShareMultipleGoods(uid); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 分享链接 |
| | | * |
| | | * @param shareRecord |
| | | * @return |
| | | */ |
| | | public String getShareUrl(UserShareGoodsRecord shareRecord) { |
| | | Long uid = shareRecord.getUid(); |
| | | Long shareId = shareRecord.getId(); |
| | | String source = shareRecord.getSource().name(); |
| | | |
| | | SystemEnum system = userInfoService.getUserSystem(uid); |
| | | |
| | | String url = String.format("http://%s/share_mushGoods.html?uid=%s&shareId=%s&source=%s", |
| | | configService.getH5Host(system), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), shareId + "", source + ""); |
| | | |
| | | String shortLink = HttpUtil.getShortLink(url); |
| | | if (!StringUtil.isNullOrEmpty(shortLink)) { |
| | | url = shortLink; |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | | * 分享链接 |
| | | * |
| | | * @param shareRecord |
| | | * @return |
| | | */ |
| | | public String getShareUrlV2(UserShareGoodsRecord shareRecord) { |
| | | Long uid = shareRecord.getUid(); |
| | | Long shareId = shareRecord.getId(); |
| | | SystemEnum system = userInfoService.getUserSystem(uid); |
| | | String url = String.format("http://%s/share_mushGoods_1.6.0.html?uid=%s&shareId=%s", configService.getH5Host(system), |
| | | AESUtil.encrypt(uid + "", Constant.UIDAESKEY), shareId + ""); |
| | | |
| | | String shortLink = HttpUtil.getShortLink(url); |
| | | if (!StringUtil.isNullOrEmpty(shortLink)) { |
| | | url = shortLink; |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | | * 生成分享图 |
| | | * |
| | | * @param uid 用户id |
| | | * @param shareId 分享记录id |
| | | * @param listGoods |
| | | * @return |
| | | * @throws UserShareGoodsRecordException |
| | | */ |
| | | public FileUploadResult drawingSharePicture(Long uid, Long shareId, String url, List<CommonGoods> listGoods) |
| | | throws UserShareGoodsRecordException { |
| | | |
| | | InputStream erCodeInputStream = null; |
| | | // 生成链接二维码 |
| | | try { |
| | | erCodeInputStream = QRCodeUtil.getInstance(500).encode(url); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 获取到用户的头像 |
| | | UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid); |
| | | if (user == null) { |
| | | throw new UserShareGoodsRecordException(1, "用户信息不存在"); |
| | | } |
| | | |
| | | InputStream portrait = null; |
| | | if (!StringUtil.isNullOrEmpty(user.getPortrait())) { |
| | | try { |
| | | portrait = HttpUtil.downLoadImg(user.getPortrait()); |
| | | } catch (HttpException e) { |
| | | String portraitUrl = userAccountService.repairPortrait(uid); |
| | | if (StringUtil.isNullOrEmpty(portraitUrl)) |
| | | throw new UserShareGoodsRecordException(1, "获取头像出错"); |
| | | else { |
| | | // 再次获取头像 |
| | | try { |
| | | portrait = HttpUtil.downLoadImg(portraitUrl); |
| | | } catch (HttpException e1) { |
| | | throw new UserShareGoodsRecordException(1, "获取头像出错"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | InputStream inputStream = ImageUtil.drawGoodsSharePicture(erCodeInputStream, portrait, listGoods); |
| | | FileUploadResult shareImg = COSManager.getInstance().uploadInputStream(inputStream, |
| | | FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + shareId + "_" + System.currentTimeMillis() |
| | | + ".png"); |
| | | |
| | | return shareImg; |
| | | } |
| | | |
| | | @Override |
| | | public void saveShareRecord(Long uid, CommonGoods goods) throws UserShareGoodsRecordException { |
| | | if (goods == null || uid == null) { |
| | | throw new UserShareGoodsRecordException(1, "参数缺失"); |
| | | } |
| | | |
| | | UserShareGoodsRecord userShareGoodsRecord = new UserShareGoodsRecord(); |
| | | userShareGoodsRecord.setShareState(1); |
| | | userShareGoodsRecord.setUid(uid); |
| | | userShareGoodsRecord.setSource(ShareSourceTypeEnum.goodsDetail); |
| | | CommonGoods resultCommonGoods = null; |
| | | try { |
| | | resultCommonGoods = commonGoodsService.addOrUpdateCommonGoods(goods); |
| | | } catch (CommonGoodsException e) { |
| | | throw new UserShareGoodsRecordException(1, "商品存入失败"); |
| | | } |
| | | |
| | | UserShareGoodsGroup singleGoods = userShareGoodsGroupService.getSingleGoods(resultCommonGoods.getId(), uid); |
| | | if (singleGoods != null) { |
| | | // 单个商品多次分享 |
| | | userShareGoodsRecord.setPicture(resultCommonGoods.getPicture()); |
| | | userShareGoodsRecord.setId(singleGoods.getRecordId()); |
| | | userShareGoodsRecord.setUpdateTime(new Date()); |
| | | userShareGoodsRecordMapper.updateByPrimaryKeySelective(userShareGoodsRecord); |
| | | |
| | | // 最新商品 |
| | | singleGoods.setUpdateTime(new Date()); |
| | | userShareGoodsGroupService.updateByPrimaryKeySelective(singleGoods); |
| | | } else { |
| | | // 单个商品第一次分享 |
| | | Date date = new Date(); |
| | | userShareGoodsRecord.setPicture(resultCommonGoods.getPicture()); |
| | | userShareGoodsRecord.setCreateTime(date); |
| | | userShareGoodsRecord.setUpdateTime(date); |
| | | userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord); |
| | | |
| | | singleGoods = new UserShareGoodsGroup(); |
| | | singleGoods.setTotalOrder(0); |
| | | singleGoods.setTotalBrowse(0); |
| | | singleGoods.setTodayBrowse(0); |
| | | singleGoods.setTotalMoney(new BigDecimal(0)); |
| | | singleGoods.setCreateTime(date); |
| | | singleGoods.setUpdateTime(date); |
| | | singleGoods.setCommonGoods(resultCommonGoods); |
| | | singleGoods.setRecordId(userShareGoodsRecord.getId()); |
| | | userShareGoodsGroupService.insertSelective(singleGoods); |
| | | } |
| | | } |
| | | |
| | | } |