| | |
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.user.cloud.UserCloudGoodsService;
|
| | | import com.yeshi.fanli.service.inter.user.cloud.UserCloudManageService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
|
| | |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | | import com.yeshi.fanli.util.suning.SuningApiUtil;
|
| | | import com.yeshi.fanli.util.suning.SuningUtil;
|
| | | import com.yeshi.fanli.util.vipshop.VipShopApiUtil;
|
| | |
|
| | |
|
| | | @Service
|
| | | public class UserCloudGoodsServiceImpl implements UserCloudGoodsService {
|
| | |
|
| | | @Resource
|
| | | private UserCloudGoodsMapper userCloudGoodsMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | |
| | |
|
| | | @Resource
|
| | | private JDGoodsCacheUtil jdGoodsCacheUtil;
|
| | | |
| | |
|
| | | @Resource
|
| | | private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
|
| | | |
| | |
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserCloudManageService userCloudManageService;
|
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public void deleteByPrimaryKeyAndUid(Long id, Long uid) {
|
| | | userCloudGoodsMapper.deleteByPrimaryKeyAndUid(id, uid);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public UserCloudGoods selectByPrimaryKey(Long id) {
|
| | | return userCloudGoodsMapper.selectByPrimaryKey(id);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void updateByPrimaryKeySelective(UserCloudGoods record) {
|
| | | userCloudGoodsMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public List<UserCloudGoods> query(int page, int pageSize, String key) {
|
| | | return userCloudGoodsMapper.query((page - 1) * pageSize, pageSize, key);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long count(String key) {
|
| | | return userCloudGoodsMapper.count(key);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserCloudGoods> listByUid(long start, int count, Long uid) {
|
| | | return userCloudGoodsMapper.listByUid(start, count, uid);
|
| | |
| | | return userCloudGoodsMapper.listByNotShare(uid);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public long countByUid(Long uid) {
|
| | | return userCloudGoodsMapper.countByUid(uid);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public UserCloudGoods getByUidAndGoods(Long uid, Long goodsId, Integer goodsType) {
|
| | | return userCloudGoodsMapper.getByUidAndGoods(uid, goodsId, goodsType);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void addGoods(Long uid, Set<String> set, Integer goodsType) throws UserCloudGoodsException {
|
| | | if (uid == null) {
|
| | | public UserCloudGoods addGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudGoodsException {
|
| | | if (uid == null)
|
| | | throw new UserCloudGoodsException(1, "用户尚未登录");
|
| | | }
|
| | |
|
| | | if (set == null || set.size() == 0 || goodsType == null) {
|
| | | if (goodsId == null || goodsType == null)
|
| | | throw new UserCloudGoodsException(1, "系统参数不正确");
|
| | | |
| | | CommonGoods commonGoods = null;
|
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { // 淘宝
|
| | | try {
|
| | | TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId);
|
| | | commonGoods = CommonGoodsFactory.create(goodsBrief);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new UserCloudGoodsException(1, goodsId + "商品已下架");
|
| | | }
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_JD) { // 京东
|
| | | JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) { // 拼多多
|
| | | PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_VIP) { // 唯品会
|
| | | VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId +"");
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_SUNING) { // 苏宁
|
| | | SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(goodsId +"", sellerId + "");
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | }
|
| | |
|
| | | for (String goodsId : set) {
|
| | | CommonGoods commonGoods = null;
|
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { // 淘宝
|
| | | try {
|
| | | TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(Long.parseLong(goodsId));
|
| | | commonGoods = CommonGoodsFactory.create(goodsBrief);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new UserCloudGoodsException(1, goodsId + "商品已下架");
|
| | | }
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_JD) { // 京东
|
| | | JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(Long.parseLong(goodsId));
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) { // 拼多多
|
| | | PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(Long.parseLong(goodsId));
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_VIP) { // 唯品会
|
| | | VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId);
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_SUNING) { // 苏宁
|
| | | String[] ids = SuningUtil.getGoodsIdDetail(goodsId);
|
| | | SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(ids[1], ids[0]);
|
| | | if (goods == null)
|
| | | throw new UserCloudGoodsException(1, goodsId + "未找到商品信息");
|
| | | commonGoods = CommonGoodsFactory.create(goods);
|
| | | }
|
| | | if (commonGoods == null) {
|
| | | LogHelper.test("云发单未找到商品详情,id=" + goodsId + "type=" + goodsType);
|
| | | throw new UserCloudGoodsException(1, "商品信息获取失败");
|
| | | }
|
| | |
|
| | | if (commonGoods == null) {
|
| | | LogHelper.test("云发单未找到商品详情,id=" + goodsId + "type=" + goodsType);
|
| | | continue;
|
| | | }
|
| | | |
| | | try {
|
| | | commonGoodsService.addOrUpdateCommonGoods(commonGoods);
|
| | | } catch (CommonGoodsException e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new UserCloudGoodsException(1, "商品信息更新失败");
|
| | | }
|
| | | try {
|
| | | commonGoodsService.addOrUpdateCommonGoods(commonGoods);
|
| | | } catch (CommonGoodsException e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new UserCloudGoodsException(1, "商品信息更新失败");
|
| | | }
|
| | | |
| | | UserCloudGoods result = null;
|
| | | UserCloudGoods cloudGoods = userCloudGoodsMapper.getByUidAndCommonGoodsId(uid, commonGoods.getId());
|
| | | if (cloudGoods != null) {
|
| | | result = cloudGoods;
|
| | | |
| | | UserCloudGoods update = new UserCloudGoods();
|
| | | update.setId(cloudGoods.getId());
|
| | | update.setState(UserCloudGoods.STATE_NORMAL);
|
| | | update.setUpdateTime(new Date());
|
| | | userCloudGoodsMapper.updateByPrimaryKeySelective(update);
|
| | | } else {
|
| | | cloudGoods = new UserCloudGoods();
|
| | | cloudGoods.setUid(uid);
|
| | | cloudGoods.setState(UserCloudGoods.STATE_NORMAL);
|
| | | cloudGoods.setCommonGoods(commonGoods);
|
| | | cloudGoods.setCreateTime(new Date());
|
| | | cloudGoods.setUpdateTime(new Date());
|
| | | userCloudGoodsMapper.insertSelective(cloudGoods);
|
| | | |
| | | result = cloudGoods;
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | UserCloudGoods cloudGoods = userCloudGoodsMapper.getByUidAndCommonGoodsId(uid, commonGoods.getId());
|
| | | if (cloudGoods != null) {
|
| | | UserCloudGoods update = new UserCloudGoods();
|
| | | update.setId(cloudGoods.getId());
|
| | | update.setState(UserCloudGoods.STATE_NORMAL);
|
| | | update.setUpdateTime(new Date());
|
| | | userCloudGoodsMapper.updateByPrimaryKeySelective(update);
|
| | | } else {
|
| | | cloudGoods = new UserCloudGoods();
|
| | | cloudGoods.setUid(uid);
|
| | | cloudGoods.setState(UserCloudGoods.STATE_NORMAL);
|
| | | cloudGoods.setCommonGoods(commonGoods);
|
| | | cloudGoods.setCreateTime(new Date());
|
| | | cloudGoods.setUpdateTime(new Date());
|
| | | userCloudGoodsMapper.insertSelective(cloudGoods);
|
| | | }
|
| | | |
| | | if (cloudGoods.getId() != null) {
|
| | | if (!Constant.IS_TEST) {
|
| | | UserCloudMQMsg msg = new UserCloudMQMsg(uid, cloudGoods.getId() +"", UserCloudMQMsg.TYPE_STORE);
|
| | | Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
|
| | | producer.send(message);
|
| | | }
|
| | | }
|
| | | |
| | | @Override
|
| | | public void sendGoodsMQMsg(Long uid) {
|
| | | if (Constant.IS_TEST) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<UserCloudGoods> list = userCloudGoodsMapper.listByNotShare(uid);
|
| | | if (list == null || list.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | long deliverTime = java.lang.System.currentTimeMillis();
|
| | | for (UserCloudGoods cloudGoods : list) {
|
| | | UserCloudMQMsg msg = new UserCloudMQMsg(uid, cloudGoods.getId() + "", UserCloudMQMsg.TYPE_STORE);
|
| | | Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
|
| | | message.setStartDeliverTime(deliverTime);
|
| | | producer.send(message);
|
| | | // 每5分钟查询一次
|
| | | deliverTime = deliverTime + 1000 * 60 * 5;
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | }
|