| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.scheduling.annotation.Async;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.goods.taobao.dataoke.DaTaoKeGoodsDetailV2Dao;
|
| | | import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
|
| | | import com.yeshi.fanli.dto.dataoke.DingDongQiangDTO;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
|
| | | @Service
|
| | | public class DaTaoKeGoodsDetailV2ServiceImpl implements DaTaoKeGoodsDetailV2Service {
|
| | |
| | |
|
| | | int totalCount = 0;
|
| | | try {
|
| | |
|
| | | DaTaoKeGoodsResult result = DaTaoKeApiUtil.listAll("1");
|
| | | int page = 0;
|
| | |
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e, "大淘客全量数据出错", "");
|
| | | } finally {
|
| | | LogHelper.test("大淘客新版商品同步数量:" + totalCount);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<DaTaoKeDetailV2> listPreShareHotGoods(int page) {
|
| | | public List<DaTaoKeDetailV2> listPreShareHotGoods(int page, BigDecimal minCommission) {
|
| | | Map<Long, DaTaoKeDetailV2> map = new HashMap<>();
|
| | | List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) * 100, 100, "monthSales");
|
| | | List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) * 100, 100, "hotPush",
|
| | | minCommission);
|
| | | System.out.println(list);
|
| | | for (DaTaoKeDetailV2 v2 : list) {
|
| | | map.put(v2.getId(), v2);
|
| | |
| | | return finalList;
|
| | | }
|
| | |
|
| | | private boolean canAddToTLJBuyGoods(DaTaoKeDetailV2 v2) {
|
| | | return TaoBaoUtil.canAddToTLJBuyGoods(TaoBaoUtil.convert(v2));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<DaTaoKeDetailV2> listPreTLJBuyGoods(int page) {
|
| | | if (page == 1) {
|
| | | List<DaTaoKeDetailV2> listPreGoodsList = new ArrayList<>();
|
| | | // 热销榜
|
| | | DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_HOT, null);
|
| | | List<DaTaoKeDetailV2> goodsList = new ArrayList<>();
|
| | | for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
|
| | | BigDecimal commision = MoneyBigDecimalUtil
|
| | | .div(MoneyBigDecimalUtil.mul(v2.getActualPrice(), v2.getCommissionRate()), new BigDecimal(100));
|
| | | if (result != null && result.getGoodsList() != null)
|
| | | listPreGoodsList.addAll(result.getGoodsList());
|
| | | // 复购榜
|
| | | result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_REBUY, null);
|
| | | if (result != null && result.getGoodsList() != null)
|
| | | listPreGoodsList.addAll(result.getGoodsList());
|
| | | // 综合搜索
|
| | | try {
|
| | | result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
|
| | | if (result == null)
|
| | | throw new Exception();
|
| | | } catch (Exception e) {// 异常重复一次
|
| | | result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
|
| | | }
|
| | |
|
| | | if (commision.multiply(new BigDecimal("0.7")).compareTo(new BigDecimal("1.01")) >= 0
|
| | | && v2.getActualPrice().compareTo(new BigDecimal(30)) < 0 && v2.getMonthSales() >= 5000) {
|
| | | if (result != null && result.getGoodsList() != null)
|
| | | listPreGoodsList.addAll(result.getGoodsList());
|
| | |
|
| | | List<DaTaoKeDetailV2> goodsList = new ArrayList<>();
|
| | | for (DaTaoKeDetailV2 v2 : listPreGoodsList) {
|
| | | if (canAddToTLJBuyGoods(v2)) {
|
| | | Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"));
|
| | |
|
| | | Date targetTime = new Date(TimeUtil
|
| | |
| | | goodsList.add(v2);
|
| | | }
|
| | | }
|
| | |
|
| | | // 去重
|
| | | Map<Long, DaTaoKeDetailV2> goodsMap = new HashMap<>();
|
| | | for (DaTaoKeDetailV2 v2 : goodsList) {
|
| | | goodsMap.put(v2.getGoodsId(), v2);
|
| | | }
|
| | | goodsList.clear();
|
| | | for (Iterator<Long> its = goodsMap.keySet().iterator(); its.hasNext();) {
|
| | | goodsList.add(goodsMap.get(its.next()));
|
| | | }
|
| | | Comparator<DaTaoKeDetailV2> cm = new Comparator<DaTaoKeDetailV2>() {
|
| | |
|
| | | @Override
|
| | | public int compare(DaTaoKeDetailV2 o1, DaTaoKeDetailV2 o2) {
|
| | | return o1.getActualPrice().compareTo(o2.getActualPrice());
|
| | | }
|
| | | };
|
| | | Collections.sort(goodsList, cm);
|
| | | return goodsList;
|
| | | } else
|
| | | return new ArrayList<>();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteOutOfDate(Date minTime) {
|
| | | daTaoKeGoodsDetailV2Dao.listAndRemoveByMinUpdateTime(minTime, 0, 3000);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countByMinUpdateTime(Date minTime) {
|
| | | return daTaoKeGoodsDetailV2Dao.countByMinUpdateTime(minTime);
|
| | | }
|
| | |
|
| | | @Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData'")
|
| | | @Override
|
| | | public List<DingDongQiangDTO> getDingDongQiangData() {
|
| | | List<DingDongQiangDTO> list = null;
|
| | | int count = 0;
|
| | | while ((list == null || list.size() == 0) && count < 3) {
|
| | | count++;
|
| | | list = DaTaoKeUtil.getDingDongQiang();
|
| | | }
|
| | | if (list == null)
|
| | | return null;
|
| | | return list;
|
| | | }
|
| | |
|
| | | @Async
|
| | | private void updateGoods(Long id) {
|
| | | DaTaoKeDetailV2 v2 = DaTaoKeApiUtil.getGoodsDetail(id);
|
| | | if (v2 != null)
|
| | | daTaoKeGoodsDetailV2Dao.save(v2);
|
| | | }
|
| | |
|
| | | private List<DaTaoKeDetailV2> getDefaultDingDongQiang() {
|
| | | // 按更新时间加
|
| | | DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_TIME, null);
|
| | | if (result != null && result.getGoodsList().size() > 0) {
|
| | | List<DaTaoKeDetailV2> finalList = new ArrayList<>();
|
| | | Collections.shuffle(result.getGoodsList());
|
| | | finalList.addAll(result.getGoodsList().subList(0,
|
| | | result.getGoodsList().size() > 8 ? 8 : result.getGoodsList().size()));
|
| | | for (DaTaoKeDetailV2 detail : finalList) {
|
| | | detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
|
| | | if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
|
| | | detail.setCouponReceiveNum(detail.getCouponTotalNum());
|
| | | }
|
| | | return finalList;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData-'+#time")
|
| | | @Override
|
| | | public List<DaTaoKeDetailV2> getDingDongQiangData(String time) {
|
| | | List<DingDongQiangDTO> list = getDingDongQiangData();
|
| | | if (list == null || list.size() == 0) {
|
| | | return getDefaultDingDongQiang();
|
| | | }
|
| | |
|
| | | Map<String, DingDongQiangDTO> map = new HashMap<>();
|
| | | for (DingDongQiangDTO dto : list)
|
| | | map.put(dto.getTime(), dto);
|
| | |
|
| | | DingDongQiangDTO dto = map.get(time);
|
| | | if (dto != null) {
|
| | | List<Long> idList = new ArrayList<>();
|
| | | for (DaTaoKeDetailV2 td : dto.getGoodsList())
|
| | | idList.add(td.getId());
|
| | | List<DaTaoKeDetailV2> finalList = listByIds(idList);
|
| | | if (finalList.size() != idList.size()) {
|
| | | for (Long id : idList)
|
| | | updateGoods(id);
|
| | | finalList = listByIds(idList);
|
| | | }
|
| | |
|
| | | // 如果商品数小于4,需要再加商品
|
| | | if (finalList == null || finalList.size() <= 3) {
|
| | | // 按更新时间加
|
| | | List<DaTaoKeDetailV2> latestList = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods(0, 50, "updateTime",
|
| | | new BigDecimal("0.5"));
|
| | | if (latestList != null && latestList.size() > 0) {
|
| | | Collections.shuffle(latestList);
|
| | | finalList.addAll(latestList.subList(0, latestList.size() > 8 ? 8 : latestList.size()));
|
| | | }
|
| | | }
|
| | |
|
| | | for (DaTaoKeDetailV2 detail : finalList) {
|
| | | detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
|
| | | if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
|
| | | detail.setCouponReceiveNum(detail.getCouponTotalNum());
|
| | | }
|
| | | return finalList;
|
| | | } else {
|
| | | return getDefaultDingDongQiang();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<String> getDingDongQiangTime() {
|
| | | List<DingDongQiangDTO> list = getDingDongQiangData();
|
| | | List<String> dateList = new ArrayList<>();
|
| | | for (DingDongQiangDTO dto : list) {
|
| | | dateList.add(dto.getTime());
|
| | | }
|
| | | return dateList;
|
| | | }
|
| | |
|
| | | }
|