| | |
| | | package com.yeshi.fanli.controller.client.v2; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.lijin.manager.GoodsLijinMnager; |
| | | import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil; |
| | | import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.JsonElement; |
| | | import com.google.gson.JsonPrimitive; |
| | | import com.google.gson.JsonSerializationContext; |
| | | import com.google.gson.JsonSerializer; |
| | | import com.yeshi.fanli.dto.GoodsMoneyConfigParamsDTO; |
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; |
| | | import com.yeshi.fanli.dto.suning.SuningGoodsInfo; |
| | | import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.goods.CollectionGoodsV2; |
| | | import com.yeshi.fanli.entity.goods.CommonGoods; |
| | | import com.yeshi.fanli.entity.goods.ScanHistoryV2; |
| | | import com.yeshi.fanli.entity.jd.JDGoods; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.fanli.exception.goods.CollectionGoodsException; |
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException; |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService; |
| | | import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service; |
| | | import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service; |
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.VersionUtil; |
| | | import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; |
| | | import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil; |
| | | import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; |
| | | import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; |
| | | import com.yeshi.fanli.util.jd.JDApiUtil; |
| | | import com.yeshi.fanli.util.suning.SuningApiUtil; |
| | | import com.yeshi.fanli.util.suning.SuningUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | import com.yeshi.fanli.util.vipshop.VipShopApiUtil; |
| | | import com.yeshi.fanli.vo.goods.GoodsDetailVO; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | /** |
| | | * 用户相关商品 |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | @Controller |
| | | @RequestMapping("api/v2/consumer") |
| | | public class ConsumerControllerV2 { |
| | | |
| | | @Resource |
| | | private BusinessSystemService businessSystemService; |
| | | |
| | | @Resource |
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; |
| | | |
| | | @Resource |
| | | private CollectionGoodsV2Service collectionGoodsV2Service; |
| | | |
| | | @Resource |
| | | private ScanHistoryV2Service scanHistoryV2Service; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; |
| | | |
| | | @Resource |
| | | private JDGoodsCacheUtil jdGoodsCacheUtil; |
| | | |
| | | @Resource |
| | | private PinDuoDuoCacheUtil pinDuoDuoCacheUtil; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private GoodsLijinMnager goodsLijinMnager; |
| | | |
| | | /** |
| | | * 收藏商品 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param id |
| | | * @param type |
| | | * @param goodsType |
| | | * @param out |
| | | */ |
| | | @RequestMapping("collectionGoods") |
| | | public void collectionGoods(AcceptData acceptData, long uid, String id, int type, Integer goodsType, |
| | | PrintWriter out) { |
| | | try { |
| | | if (goodsType == null) { |
| | | goodsType = Constant.SOURCE_TYPE_TAOBAO; |
| | | } |
| | | |
| | | if (type != 1) { |
| | | if (goodsType == Constant.SOURCE_TYPE_SUNING) { |
| | | String[] sts = SuningUtil.getGoodsIdDetail(id); |
| | | collectionGoodsV2Service.cancelCollectionByAuctionId(uid, sts[1], goodsType); |
| | | } else |
| | | collectionGoodsV2Service.cancelCollectionByAuctionId(uid, id, goodsType); |
| | | out.print(JsonUtil.loadTrueResult("取消收藏成功")); |
| | | return; |
| | | } |
| | | String goodsId = null; |
| | | if (goodsType == Constant.SOURCE_TYPE_SUNING) { |
| | | String[] sts = SuningUtil.getGoodsIdDetail(id); |
| | | goodsId =sts[1]; |
| | | } else |
| | | goodsId = id; |
| | | CollectionGoodsV2 find = collectionGoodsV2Service.findByUidAndAuctionId(uid, goodsId, goodsType); |
| | | if (find != null) { |
| | | out.print(JsonUtil.loadFalseResult("")); |
| | | return; |
| | | } |
| | | |
| | | if (goodsType == Constant.SOURCE_TYPE_JD) { |
| | | JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId); |
| | | if (jdGoods == null) { |
| | | jdGoods = JDApiUtil.getGoodsDetail(goodsId); |
| | | } |
| | | if (jdGoods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | collectionGoodsV2Service.addJDCollection(uid, jdGoods); |
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) { |
| | | PDDGoodsDetail pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); |
| | | if (pddGoods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | collectionGoodsV2Service.addPDDCollection(uid, pddGoods); |
| | | } else if (goodsType == Constant.SOURCE_TYPE_VIP) { |
| | | VIPGoodsInfo vipGoods = VipShopApiUtil.getGoodsDetail(id); |
| | | if (vipGoods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | collectionGoodsV2Service.addVIPCollection(uid, vipGoods); |
| | | } else if (goodsType == Constant.SOURCE_TYPE_SUNING) { |
| | | String[] sts = SuningUtil.getGoodsIdDetail(id); |
| | | SuningGoodsInfo suningGoods = SuningApiUtil.getGoodsDetail(sts[1], sts[0]); |
| | | if (suningGoods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | collectionGoodsV2Service.addSuningCollection(uid, suningGoods); |
| | | }else if (goodsType == Constant.SOURCE_TYPE_DY) { |
| | | DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(id)); |
| | | if (goods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | collectionGoodsV2Service.addDYCollection(uid, goods); |
| | | } else { |
| | | try { |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId); |
| | | collectionGoodsV2Service.addCollection(uid, taoBaoGoodsBrief); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品已下架")); |
| | | return; |
| | | } |
| | | } |
| | | out.print(JsonUtil.loadTrueResult("收藏成功")); |
| | | } catch (CollectionGoodsException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除收藏 |
| | | * |
| | | * @param acceptData |
| | | * @param ids |
| | | * @param type |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping("deleteCollectionGoods") |
| | | public void deleteCollectionGoods(AcceptData acceptData, Long uid, String ids, Integer type, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (type != null && type == 1) { // 删除全部 |
| | | try { |
| | | collectionGoodsV2Service.cancelCollectionByUid(uid); |
| | | } catch (CollectionGoodsException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); |
| | | return; |
| | | } |
| | | } else { // 删除部分 |
| | | if (!StringUtil.isNullOrEmpty(ids)) { |
| | | Arrays.asList(ids.split(",")).parallelStream().forEach(idStr -> { |
| | | try { |
| | | collectionGoodsV2Service.deteleBYByUidAndCommonId(uid, Long.parseLong(idStr)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | out.print(JsonUtil.loadTrueResult("删除成功")); |
| | | } |
| | | |
| | | /** |
| | | * 收藏列表 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param page |
| | | * @param goodsType |
| | | * @param out |
| | | */ |
| | | @RequestMapping("collectionGoodsList") |
| | | public void collectionGoodsList(AcceptData acceptData, Long uid, Integer page, Integer goodsType, PrintWriter out) { |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (page < 1) { |
| | | out.print(JsonUtil.loadFalseResult(1, "page不小于1")); |
| | | return; |
| | | } |
| | | |
| | | boolean notBackSuVip = false; |
| | | if (!VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion())) |
| | | notBackSuVip = true; |
| | | |
| | | List<CollectionGoodsV2> collectionGoodsList = collectionGoodsV2Service.getCollectionGoodsList(uid, page, |
| | | Constant.PAGE_SIZE, goodsType, notBackSuVip); |
| | | |
| | | long count = collectionGoodsV2Service.getCollectionGoodsCount(uid, goodsType, notBackSuVip); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | List<GoodsDetailVO> list = new ArrayList<>(); |
| | | |
| | | if (collectionGoodsList != null && collectionGoodsList.size() > 0) { |
| | | List<String> listGid = new ArrayList<>(); |
| | | for (CollectionGoodsV2 collectionGoodsV2 : collectionGoodsList) { |
| | | CommonGoods commonGoods = collectionGoodsV2.getCommonGoods(); |
| | | if (commonGoods == null || commonGoods.getGoodsType() != Constant.SOURCE_TYPE_TAOBAO) { |
| | | continue; |
| | | } |
| | | listGid.add(commonGoods.getGoodsId()); |
| | | } |
| | | |
| | | // API网络接口验证是否在售 |
| | | List<TaoBaoGoodsBrief> listTaoKeGoods = null; |
| | | if (listGid.size() > 0) { |
| | | try { |
| | | listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), |
| | | acceptData.getVersion(), acceptData.getSystem()); |
| | | |
| | | |
| | | List<CommonGoods> commonGoodsList=new ArrayList<>(); |
| | | |
| | | for (CollectionGoodsV2 collectionGoodsV2 : collectionGoodsList) { |
| | | CommonGoods commonGoods = collectionGoodsV2.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 |
| | | && commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { |
| | | int state = 1; // 默认停售 |
| | | String goodsId = commonGoods.getGoodsId(); |
| | | for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { |
| | | String auctionId = taoKeGoods.getAuctionId(); |
| | | if (goodsId == auctionId || goodsId.equals(auctionId)) { |
| | | state = 0; // 在售 |
| | | break; |
| | | } |
| | | } |
| | | commonGoods.setState(state); |
| | | } |
| | | |
| | | commonGoods.setCreateTime(collectionGoodsV2.getCreateTime()); |
| | | commonGoodsList.add(commonGoods); |
| | | } |
| | | |
| | | list=goodsLijinMnager.loadCommonGoodsMoneyInfo(acceptData.getSystem(),uid,commonGoodsList,paramsDTO); |
| | | } |
| | | |
| | | GsonBuilder builder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime() + ""); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(builder).excludeFieldsWithoutExposeAnnotation() |
| | | .create(); |
| | | data.put("list", gson.toJson(list)); |
| | | data.put("count", count); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | /** |
| | | * 删除足迹 |
| | | * |
| | | * @param acceptData |
| | | * @param type |
| | | * @param uid |
| | | * @param ids |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "deleteScanhistory", method = RequestMethod.POST) |
| | | public void deleteScanHistory(AcceptData acceptData, String type, Long uid, String ids, PrintWriter out) { |
| | | if ("1".equals(type)) { |
| | | // 全部删除 |
| | | scanHistoryV2Service.deleteByDeviceOrUid(uid, acceptData.getDevice()); |
| | | } else { |
| | | // 删除部分 |
| | | if (StringUtil.isNullOrEmpty(ids)) { |
| | | out.print(JsonUtil.loadFalseResult("ids不能为空")); |
| | | return; |
| | | } |
| | | |
| | | String[] idStr = ids.split(","); |
| | | for (String id : idStr) { |
| | | scanHistoryV2Service.deleteByCommonIdAndDeviceOrUid(uid, acceptData.getDevice(), Long.parseLong(id)); |
| | | } |
| | | } |
| | | out.print(JsonUtil.loadTrueResult("")); |
| | | } |
| | | |
| | | /** |
| | | * 获取浏览记录 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param page |
| | | * @param goodsType |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getScanHistory", method = RequestMethod.POST) |
| | | public void getScanHistory(AcceptData acceptData, Long uid, int page, Integer goodsType, PrintWriter out) { |
| | | if (page < 1) { |
| | | out.print(JsonUtil.loadFalseResult(1, "page不小于1")); |
| | | return; |
| | | } |
| | | |
| | | boolean notBackSuVip = false; |
| | | if (!VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion())) |
| | | notBackSuVip = true; |
| | | |
| | | List<ScanHistoryV2> list = scanHistoryV2Service.getScanHistoryByDeviceOrUid(uid, acceptData.getDevice(), page, |
| | | 20, goodsType, notBackSuVip); |
| | | |
| | | GsonBuilder gsonBuilder = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()); |
| | | gsonBuilder.excludeFieldsWithoutExposeAnnotation(); |
| | | gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime() + ""); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | long count = scanHistoryV2Service.getCountByDeviceOrUid(uid, acceptData.getDevice(), goodsType, notBackSuVip); |
| | | |
| | | JSONArray array = new JSONArray(); |
| | | List<CommonGoods> commonGoodsList = new ArrayList<>(); |
| | | if (list != null && list.size() > 0) { |
| | | Gson gson = gsonBuilder.create(); |
| | | GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), |
| | | acceptData.getVersion(), acceptData.getSystem()); |
| | | for (ScanHistoryV2 sh : list) { |
| | | CommonGoods commonGoods = sh.getCommonGoods(); |
| | | if (commonGoods == null) { |
| | | continue; |
| | | } |
| | | commonGoods.setCreateTime(sh.getCreateTime()); |
| | | commonGoodsList.add(commonGoods); |
| | | } |
| | | List<GoodsDetailVO> goodsDetailVOS = goodsLijinMnager.loadCommonGoodsMoneyInfo(acceptData.getSystem(), uid, commonGoodsList, paramsDTO); |
| | | for (GoodsDetailVO vo : goodsDetailVOS) { |
| | | array.add(gson.toJson(vo)); |
| | | } |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | | data.put("data", array); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | return; |
| | | } |
| | | |
| | | } |