parent
ea6149e91c
commit
47b3f68b9d
@ -0,0 +1,28 @@
|
|||||||
|
package com.xjs.common.client.api.tianxing;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.common.aop.ApiLog;
|
||||||
|
import com.xjs.common.client.factory.TianXingQWRSFeignFactory;
|
||||||
|
import com.xjs.common.client.factory.TianXingWXRSFeignFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天行微信热搜feign
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
@FeignClient(name = "tianXingWXRS",url = TIANXING_TOPSEARCHALLWECHAT_URL,fallbackFactory = TianXingWXRSFeignFactory.class)
|
||||||
|
public interface TianXingWXRSFeignClient {
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiLog(name = TIANXING_TOPSEARCHWECHAT,
|
||||||
|
url = TIANXING_TOPSEARCHALLWECHAT_URL,
|
||||||
|
method = "Get")
|
||||||
|
JSONObject topSearchApi(@RequestParam("key") String key);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.common.client.api.tianxing.TianXingWXRSFeignClient;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class TianXingWXRSFeignFactory implements FallbackFactory<TianXingWXRSFeignClient> {
|
||||||
|
@Override
|
||||||
|
public TianXingWXRSFeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块天行微信热搜榜服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return key -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
//构建一个异常json给下层接口处理
|
||||||
|
jsonObject.put("error", R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.xjs.topsearch.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信热搜榜实体
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("api_topsearch_wechat")
|
||||||
|
public class ApiTopsearchWechat implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键 */
|
||||||
|
@TableId("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 话题 */
|
||||||
|
@Excel(name = "话题")
|
||||||
|
private String word;
|
||||||
|
|
||||||
|
|
||||||
|
@Excel(name = "创建时间",dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.xjs.topsearch.factory.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.constant.HttpStatus;
|
||||||
|
import com.xjs.common.client.api.tianxing.TianXingWXRSFeignClient;
|
||||||
|
import com.xjs.config.TianXingProperties;
|
||||||
|
import com.xjs.topsearch.domain.ApiTopsearchAllnetwork;
|
||||||
|
import com.xjs.topsearch.domain.ApiTopsearchWechat;
|
||||||
|
import com.xjs.topsearch.factory.TopserachFactory;
|
||||||
|
import com.xjs.topsearch.service.ApiTopsearchWechatService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信热搜api工厂实现
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class TianXingTopsearchWechatFactory implements TopserachFactory<ApiTopsearchWechat> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TianXingProperties tianXingProperties;
|
||||||
|
@Autowired
|
||||||
|
private TianXingWXRSFeignClient tianXingWXRSFeignClient;
|
||||||
|
@Autowired
|
||||||
|
private ApiTopsearchWechatService apiTopsearchWechatService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public List<ApiTopsearchWechat> topSearchApi() {
|
||||||
|
JSONObject jsonObject = tianXingWXRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||||
|
if (!jsonObject.containsKey("error")) {
|
||||||
|
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||||
|
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||||
|
List<ApiTopsearchWechat> collect = newslist.stream().map(arrayJson -> {
|
||||||
|
ApiTopsearchWechat apiTopsearchWechat = new ApiTopsearchWechat();
|
||||||
|
JSONObject json = (JSONObject) arrayJson;
|
||||||
|
apiTopsearchWechat.setWord(json.getString("word"));
|
||||||
|
return apiTopsearchWechat;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
log.info("微信热搜批量插入成功了嘛---" + apiTopsearchWechatService.saveBatch(collect));
|
||||||
|
return collect;
|
||||||
|
} else {
|
||||||
|
log.error("天行微信热搜服务调用成功,但返回异常");
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("天行微信热搜服务调用失败,被降级!!");
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.xjs.topsearch.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xjs.topsearch.domain.ApiTopsearchWechat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
public interface ApiTopsearchWechatMapper extends BaseMapper<ApiTopsearchWechat> {
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.xjs.topsearch.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.xjs.topsearch.domain.ApiTopsearchWechat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
public interface ApiTopsearchWechatService extends IService<ApiTopsearchWechat> {
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.xjs.topsearch.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.xjs.topsearch.domain.ApiTopsearchWechat;
|
||||||
|
import com.xjs.topsearch.mapper.ApiTopsearchWechatMapper;
|
||||||
|
import com.xjs.topsearch.service.ApiTopsearchWechatService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-11
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ApiTopsearchWechatServiceImpl extends ServiceImpl<ApiTopsearchWechatMapper, ApiTopsearchWechat> implements ApiTopsearchWechatService {
|
||||||
|
}
|
Loading…
Reference in new issue