| | |
| | | import com.yeshi.fanli.service.inter.user.HistorySearchService;
|
| | | import com.yeshi.fanli.service.inter.user.TokenRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
|
| | | import com.yeshi.fanli.service.manger.goods.jd.JDGoodsLinkParseManager;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.DouYinUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private BrandInfoService brandInfoService;
|
| | |
|
| | | @Resource
|
| | | private JDGoodsLinkParseManager jdGoodsLinkParseManager;
|
| | |
|
| | | /**
|
| | | * 粘贴板信息推荐
|
| | |
| | |
|
| | | // 领券短连接
|
| | | if (StringUtil.isNullOrEmpty(jdId) && text.contains("u.jd.com")) {
|
| | | jdId = JDUtil.getJDGoodsIdByUJD(text);
|
| | | jdId = jdGoodsLinkParseManager.parseGoodsIdByJDShortUrl(text);
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(jdId)) {
|
| | |
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | | data.put("type", type);
|
| | | data.put("goods",
|
| | | gson.toJson(GoodsDetailVOFactory.convertCommonGoods(commonGoods,hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion()))));
|
| | | data.put("goods", gson.toJson(GoodsDetailVOFactory.convertCommonGoods(commonGoods,
|
| | | hongBaoManageService.getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion()))));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | return;
|
| | | }
|
| | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("type", 3);
|
| | | data.put("goods",
|
| | | gson.toJson(GoodsDetailVOFactory.convertTaoBao(goodsBrief,
|
| | | hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion()))));
|
| | | gson.toJson(GoodsDetailVOFactory.convertTaoBao(goodsBrief, hongBaoManageService
|
| | | .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion()))));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | List<GoodsDetailVO> list = new ArrayList<GoodsDetailVO>();
|
| | | ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | |
|
| | | for (TaoBaoGoodsBrief goods : taoBaoGoodsBriefs) {
|
| | |
| | | || ("android".equalsIgnoreCase(platform) && VersionUtil.greaterThan_2_0_2(platform, version))) {
|
| | | BrandInfoVO brandInfoVO = null;
|
| | | try {
|
| | | brandInfoVO = brandInfoService.listByAlikeName(key,acceptData.getPlatform(),acceptData.getVersion());
|
| | | brandInfoVO = brandInfoService.listByAlikeName(key, acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | | } catch (Exception e) {
|
| | | }
|
| | | if (brandInfoVO != null)
|
| | | data.put("shop", JsonUtil.getApiCommonGson().toJson(brandInfoVO));
|
| | | } else {
|
| | | List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKeyV2(key,acceptData.getPlatform(),acceptData.getVersion());
|
| | | List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKeyV2(key, acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | | if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoodsVO() != null
|
| | | && listShop.get(0).getListGoodsVO().size() > 2) {
|
| | | TaoBaoShopVO taoBaoShop = listShop.get(0);
|
| | |
| | | Gson gson = JsonUtil.getApiCommonGson();
|
| | | List<PDDGoodsDetail> goodsList = result.getGoodsList();
|
| | | if (goodsList != null && goodsList.size() > 0) {
|
| | | ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | |
|
| | | for (PDDGoodsDetail goods : goodsList) {
|
| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.xxl.job.core.biz.model.ReturnT;
|
| | | import com.xxl.job.core.handler.annotation.XxlJob;
|
| | | import com.yeshi.fanli.entity.brand.BrandInfo;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.brand.BrandInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
| | | /**
|
| | | * 每两个小时进行更新品牌商品信息
|
| | | */
|
| | | // @Scheduled(cron = "0 0 1/2 * * ? ")
|
| | | @XxlJob("brandGoodsUpdateHandler")
|
| | | public ReturnT<String> demoJobHandler(String param) throws Exception {
|
| | | updateGoods();
|
| | |
| | | if (count == 0)
|
| | | return;
|
| | |
|
| | | List<BrandInfo> list = new ArrayList<>();
|
| | |
|
| | | long totalPage = (count / 100) + 1;
|
| | | for (long page = 0; page < totalPage; page++) {
|
| | | List<BrandInfo> tempList = brandInfoService.listValidOrderByUpdateTime((int) (page + 1), 100);
|
| | | if (tempList != null && tempList.size() > 0) {
|
| | | list.addAll(tempList);
|
| | | }
|
| | | }
|
| | |
|
| | | for (int page = 0; page < totalPage; page++) {
|
| | | try {
|
| | | brandInfoService.addShopAndGoods(page * 100, 100);
|
| | | brandInfoService.addShopAndGoods(
|
| | | list.subList(page * 100, page * 100 + 100 > count ? (int) count : (page * 100 + 100)));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | long endTime = java.lang.System.currentTimeMillis();
|
| | | LogHelper.test("结束执行品牌更新---updateGoods" + endTime + ",总耗时:" + (endTime - startTime) / 1000);
|
| | | }
|
| | |
| | | @Override
|
| | | public void addShopAndGoods(long start, int count) {
|
| | | List<BrandInfo> list = brandInfoMapper.listValidAll(start, count);
|
| | | addShopAndGoods(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void addShopAndGoods(List<BrandInfo> list) {
|
| | | if (list == null || list.size() == 0)
|
| | | return;
|
| | |
|
| | | long startTime = java.lang.System.currentTimeMillis();
|
| | | LogHelper.test(start + "品牌更新service---addShopAndGoods" + startTime);
|
| | |
|
| | | // long startTime = java.lang.System.currentTimeMillis();
|
| | | for (BrandInfo brandInfo : list) {
|
| | | try {
|
| | | String name = brandInfo.getName();
|
| | |
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | long endTime = java.lang.System.currentTimeMillis();
|
| | | LogHelper.test(start + "品牌更新service---addShopAndGoods" + endTime + ",本次总耗时:" + (endTime - startTime) / 1000);
|
| | | // long endTime = java.lang.System.currentTimeMillis();
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | @Override
|
| | | @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key+'-'+#platform+'-'+#version")
|
| | | public BrandInfoVO listByAlikeName(String key,String platform,String version) {
|
| | | public BrandInfoVO listByAlikeName(String key, String platform, String version) {
|
| | | if (StringUtil.isNullOrEmpty(key))
|
| | | return null;
|
| | |
|
| | |
| | | if (list == null || list.size() == 0)
|
| | | return null;
|
| | |
|
| | |
|
| | | ConfigParamsDTO configParamsDTO = hongBaoManageService.getShowComputeRate(platform, version);
|
| | | ConfigParamsDTO configParamsDTO = hongBaoManageService.getShowComputeRate(platform, version);
|
| | |
|
| | | BrandInfoVO brand = list.get(0);
|
| | | List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId());
|
| | |
| | | brand.setListGoods(listGoodsVO);
|
| | | return brand;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<BrandInfo> listValidOrderByUpdateTime(int page, int pageSize) {
|
| | | return brandInfoMapper.listValidAll((page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | updateExtract.setId(id);
|
| | | updateExtract.setState(Extract.STATE_PROCESSING);
|
| | | extractMapper.updateByPrimaryKeySelective(updateExtract);
|
| | | //TODO 新版部署后删除
|
| | | // TODO 新版部署后删除
|
| | | // 改变资金记录状态
|
| | | UserMoneyDetail detail = userMoneyDetailService
|
| | | .selectByTypeAndUidAndIdentifyCode(UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId());
|
| | | UserMoneyDetail detail = userMoneyDetailService.selectByTypeAndUidAndIdentifyCode(
|
| | | UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId());
|
| | | if (detail != null) {
|
| | | UserMoneyDetail update = new UserMoneyDetail(detail.getId());
|
| | | update.setShow(true);
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public synchronized void rejectExtract(long id, String reason, AdminUser admin)
|
| | | throws ObjectStateException, NotExistObjectException {
|
| | | Extract find = extractMapper.selectByPrimaryKey(id);
|
| | |
| | | response = alipayClient.execute(request);
|
| | | LogHelper.userErrorInfo("提现:支付宝通过提现成功-" + extract.getId());
|
| | | } catch (AlipayApiException e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, "支付宝转账异常:" + extract.getId(), "");
|
| | | LogHelper.userErrorInfo("提现:支付宝提现异常:" + response + ",提现信息" + GsonUtil.toJson(extract));
|
| | | }
|
| | |
|
| | |
| | | return extractMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void checkExtract(Long uid) throws ExtractException {
|
| | | BigDecimal compensateMoney = extractMapper.computeCompensateByUid(uid);
|
| | |
| | | }
|
| | | return listOpendIDs;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public List<UserInfo> preAutoUserTo1212() throws Exception {
|
| | | int page = 0;
|
| | |
| | | }
|
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<String> getAutoExtractOpenIdsTo1212() throws Exception {
|
| | | int page = 0;
|
| | |
| | | userMoneyService.subUserMoney(uid, drawBackMoney, userMoneyDetail);
|
| | | userMoneyMsgNotificationService.shareOrderWeiQuan(uid, orderId, Constant.SOURCE_TYPE_TAOBAO, drawBackMoney,
|
| | |
|
| | | userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
|
| | | userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.log.OrderLogHelper;
|
| | | import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService;
|
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderProcessService;
|
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderService;
|
| | |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.manger.HongBaoV2AddManager;
|
| | | import com.yeshi.fanli.service.manger.order.HongBaoV2AddManager;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | |
| | | }
|
| | | }
|
| | | }, null);
|
| | | else{
|
| | | else {
|
| | | try {
|
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), key);
|
| | |
| | | if (orderList != null && orderList.size() > 0 & !StringUtil.isNullOrEmpty(orderList.get(0).getSettlementTime()))
|
| | | order.setJieSuanTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getSettlementTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | | // if (order.getJieSuanTime().getTime() >=
|
| | | // TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | // return;
|
| | | // }
|
| | |
|
| | | // TODO 处理维权成功但是已到账的订单
|
| | |
|
| | | // 处理维权成功但是已到账的订单
|
| | | if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 结算时间在2月1号的开始处理已到账但是维权的
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | order.getOrderItemId());
|
| | |
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService
|
| | | .selectByOrderItemId(order.getOrderItemId());
|
| | | if (drawBack == null) {// 还未扣款
|
| | | OrderLogHelper.taoBaoWeiQuan("已到账未扣款处理:子订单号:" + order.getOrderItemId());
|
| | | try {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId());
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId());
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, null, "订单号:" + order.getOrderId());
|
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // 查询子红包是否已到账
|
| | | List<HongBaoV2> children = hongBaoV2Service
|
| | | .listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | for (HongBaoV2 hongBaoV2 : children) {
|
| | | if (hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | try {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail;
|
| | |
| | | @Resource
|
| | | private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService;
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void addWeiQuanOrder(TaoBaoWeiQuanOrder order) {
|
| | | if (order == null)
|
| | |
| | | userOrderWeiQuanRecordService.addTaoBaoWeiQuan(taoBaoWeiQuanOrder);
|
| | | }
|
| | |
|
| | | List<MsgOrderDetail> msgList = msgOrderDetailService.listMsgOrderByOrderId(order.getOrderId());
|
| | | for (MsgOrderDetail msg : msgList) {
|
| | | if (msg.getType() == MsgTypeOrderTypeEnum.fanli) {
|
| | | userOrderMsgNotificationService.orderFanLiStateChanged(msg.getUser().getId(),
|
| | | order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null, null, CommonOrder.STATE_WQ);
|
| | | } else if (msg.getType() == MsgTypeOrderTypeEnum.invite) {
|
| | | userOrderMsgNotificationService.orderInviteStateChanged(msg.getUser().getId(),
|
| | | order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null, null, CommonOrder.STATE_WQ);
|
| | | } else if (msg.getType() == MsgTypeOrderTypeEnum.share) {
|
| | | userOrderMsgNotificationService.orderShareStateChanged(msg.getUser().getId(),
|
| | | order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null, null, CommonOrder.STATE_WQ);
|
| | | }
|
| | | }
|
| | | // 维权状态不需要消息
|
| | | // List<MsgOrderDetail> msgList =
|
| | | // msgOrderDetailService.listMsgOrderByOrderId(order.getOrderId());
|
| | | // for (MsgOrderDetail msg : msgList) {
|
| | | // if (msg.getType() == MsgTypeOrderTypeEnum.fanli) {
|
| | | // userOrderMsgNotificationService.orderFanLiStateChanged(msg.getUser().getId(),
|
| | | // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
|
| | | // null, CommonOrder.STATE_WQ);
|
| | | // } else if (msg.getType() == MsgTypeOrderTypeEnum.invite)
|
| | | // {
|
| | | // userOrderMsgNotificationService.orderInviteStateChanged(msg.getUser().getId(),
|
| | | // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
|
| | | // null, CommonOrder.STATE_WQ);
|
| | | // } else if (msg.getType() == MsgTypeOrderTypeEnum.share) {
|
| | | // userOrderMsgNotificationService.orderShareStateChanged(msg.getUser().getId(),
|
| | | // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
|
| | | // null, CommonOrder.STATE_WQ);
|
| | | // }
|
| | | // }
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | |
| | | order.setCreateTime(new Date());
|
| | | order.setUpdateTime(new Date());
|
| | | taoBaoWeiQuanOrderMapper.insertSelective(order);
|
| | | if (order.getState().contains("维权成功")) {
|
| | | // 更改CommonOrder的状态
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | order.getOrderItemId());
|
| | | if (commonOrder != null) {
|
| | | CommonOrder updateCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | updateCommonOrder.setState(CommonOrder.STATE_WQ);
|
| | | updateCommonOrder.setUpdateTime(new Date());
|
| | | commonOrderService.updateByPrimaryKeySelective(updateCommonOrder);
|
| | | userOrderWeiQuanRecordService.addTaoBaoWeiQuan(taoBaoWeiQuanOrder);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | * @param count
|
| | | */
|
| | | public void addShopAndGoods(long start, int count);
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 检索有效的品牌信息,按更新时间排序
|
| | | * @param page
|
| | | * @param pageSize
|
| | | * @return
|
| | | */
|
| | | public List<BrandInfo> listValidOrderByUpdateTime(int page,int pageSize);
|
| | | |
| | | |
| | | /**
|
| | | * 添加品牌商品
|
| | | * @param brandList
|
| | | */
|
| | | public void addShopAndGoods(List<BrandInfo> brandList);
|
| | |
|
| | |
|
| | | public long countValidByCidToApp(Long cid);
|
File was renamed from fanli/src/main/java/com/yeshi/fanli/service/manger/HongBaoV2AddManager.java |
| | |
| | | package com.yeshi.fanli.service.manger;
|
| | | package com.yeshi.fanli.service.manger.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Calendar;
|
| | |
| | | package com.yeshi.fanli.util.goods.jd;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | | import org.jsoup.nodes.Element;
|
| | | import org.jsoup.select.Elements;
|
| | |
|
| | | import com.yeshi.fanli.dao.goods.jd.NYouHuiGoods;
|
| | |
|
| | | /**
|
| | | * 京东内优惠商品爬取 https://www.n-youhui.com
|
| | |
| | | *
|
| | | */
|
| | | public class NYouHuiUtil {
|
| | | public static List<String> getClasses() {
|
| | | List<String> classList = new ArrayList<>();
|
| | |
|
| | | private static Document getDocument(String url) {
|
| | | Document doc = null;
|
| | | try {
|
| | | Document doc = Jsoup.connect("https://www.n-youhui.com").timeout(20000)
|
| | | doc = Jsoup.connect(url).timeout(20000)
|
| | | .userAgent(
|
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36")
|
| | | .get();
|
| | | Element classesRoot = doc.getElementsByClass("widget_categories").get(0);
|
| | | Elements level0 = classesRoot.getElementsByClass("level-0");
|
| | | for (int i = 0; i < level0.size(); i++) {
|
| | | String name = level0.get(i).html().replace(" ", "").replaceAll("\\(([0-9]|,)*\\)", "").trim();
|
| | | classList.add(name);
|
| | | }
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return doc;
|
| | | }
|
| | |
|
| | | public static List<String> getClasses() {
|
| | | List<String> classList = new ArrayList<>();
|
| | | Document doc = getDocument("https://www.n-youhui.com");
|
| | | Element classesRoot = doc.getElementsByClass("widget_categories").get(0);
|
| | | Elements level0 = classesRoot.getElementsByClass("level-0");
|
| | | for (int i = 0; i < level0.size(); i++) {
|
| | | String name = level0.get(i).html().replace(" ", "").replaceAll("\\(([0-9]|,)*\\)", "").trim();
|
| | | classList.add(name);
|
| | | }
|
| | |
|
| | | return classList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @param className
|
| | | * @return
|
| | | */
|
| | | public static List<NYouHuiGoods> listByClassName(String className, int page) {
|
| | | List<NYouHuiGoods> goodsList = new ArrayList<>();
|
| | | String url = null;
|
| | | try {
|
| | | url = "https://www.n-youhui.com/" + URLEncoder.encode(className, "UTF-8").toLowerCase() + "/page/" + page;
|
| | | } catch (UnsupportedEncodingException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | Document doc = getDocument(url);
|
| | | Element content = doc.getElementsByClass("content").get(0);
|
| | | if (content != null) {
|
| | | Elements articles = content.getElementsByTag("article");
|
| | | if (articles != null)
|
| | | for (int i = 0; i < articles.size(); i++) {
|
| | | String link = articles.get(i).getElementsByTag("a").get(0).attr("href");
|
| | | String name = articles.get(i).getElementsByTag("a").get(0).ownText();
|
| | | String time = articles.get(i).getElementsByClass("time").get(0).ownText();
|
| | | time = time.split(" ")[time.split(" ").length - 1];
|
| | | NYouHuiGoods goods = new NYouHuiGoods();
|
| | | goods.setName(name);
|
| | | goods.setSourceUrl(link);
|
| | | goods.setPublishTime(time);
|
| | | goodsList.add(goods);
|
| | | }
|
| | | }
|
| | | return goodsList;
|
| | | }
|
| | |
|
| | | public static NYouHuiGoods getGoodsDetail(String url) {
|
| | | NYouHuiGoods goods = new NYouHuiGoods();
|
| | | Document doc = getDocument(url);
|
| | | Element article = doc.getElementsByClass("article-content").get(0);
|
| | | Elements ps = article.getElementsByTag("p");
|
| | | String text = "";
|
| | | for (int i = 0; i < ps.size(); i++) {
|
| | | // 移除图片
|
| | | Elements imgList = ps.get(i).getElementsByTag("img");
|
| | | for (int j = 0; j < imgList.size(); j++)
|
| | | imgList.get(j).remove();
|
| | | text += ps.get(i).html().replace("<br>", "\n") + "\n";
|
| | | }
|
| | | |
| | | text=text.trim();
|
| | |
|
| | | String regex = "(https://u\\.jd\\.com/)[0-9A-Za-z]{1,20}";
|
| | | Pattern pattern = Pattern.compile(regex);
|
| | | Matcher m = pattern.matcher(text);
|
| | | List<String> urlList = new ArrayList<>();
|
| | | while (m.find()) {
|
| | | urlList.add(m.group());
|
| | | }
|
| | | goods.setLinkList(urlList);
|
| | | goods.setDesc(text.replaceAll(regex, "[链接]"));
|
| | | goods.setName(doc.getElementsByClass("article-title").get(0).getElementsByTag("a").get(0).ownText());
|
| | | String time = doc.getElementsByClass("article-meta").get(0).getElementsByTag("li").get(0).ownText().trim();
|
| | | goods.setPublishTime(time.split(" ")[time.split(" ").length - 1]);
|
| | | goods.setSourceUrl(url);
|
| | | return goods;
|
| | | }
|
| | |
|
| | | }
|