1、实现alapi平台笑话大全api
This commit is contained in:
parent
8f08381625
commit
73391b8b84
|
|
@ -29,13 +29,15 @@ public class CopyWritingTask {
|
|||
* 任务执行
|
||||
*/
|
||||
public void execute() {
|
||||
LocalDateTime localDateTime1 = DateUtil.date().toLocalDateTime();
|
||||
log.info("---------------文案定时任务Start-------------------");
|
||||
R<CopyWriting> r = remoteCopyWritingFeign.copyWriting();
|
||||
log.info("文案定时任务结果:code={},msg={},data={}",r.getCode(),r.getMsg(),r.getData());
|
||||
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||
log.info("文案定时任务Job耗费时间:{}ms", between);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
LocalDateTime localDateTime1 = DateUtil.date().toLocalDateTime();
|
||||
R<CopyWriting> r = remoteCopyWritingFeign.copyWriting();
|
||||
log.info("文案定时任务[{}]结果:code={},msg={},data={}",i,r.getCode(),r.getMsg(),r.getData());
|
||||
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||
log.info("文案[{}]定时任务Job耗费时间:{}ms", i,between);
|
||||
}
|
||||
log.info("---------------文案定时任务end---------------------");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -290,6 +290,11 @@ export default {
|
|||
float: left;
|
||||
width: 75%;
|
||||
text-shadow: 2px 2px 2px grey;
|
||||
/*显示6行*/
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 6;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.source_div {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ public class ApiConst {
|
|||
|
||||
public static final String UOMG_EARTH_LOVE = "Uomg-土味情话";
|
||||
|
||||
public static final String ALAPI_JOKE_ALL = "ALAPI-笑话大全";
|
||||
|
||||
|
||||
//-------------------url------------------------------
|
||||
|
||||
|
|
@ -185,6 +187,11 @@ public class ApiConst {
|
|||
*/
|
||||
public static final String UOMG_EARTH_LOVE_URL = "https://api.uomg.com/api/rand.qinghua";
|
||||
|
||||
/**
|
||||
* 接口文档:https://www.alapi.cn/api/view/11
|
||||
*/
|
||||
public static final String ALAPI_JOKE_ALL_URL = "http://v2.alapi.cn/api/joke/random";
|
||||
|
||||
|
||||
//-----------------------api请求参数常量-----------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,9 @@ public class CopyWritingConst {
|
|||
|
||||
//土味情话
|
||||
public static final Integer TWQH= 9;
|
||||
|
||||
//------------------alapi平台参数--------------------------
|
||||
|
||||
//笑话大去哪
|
||||
public static final Integer XHDQ= 10;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.xjs.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* ALAPI平台token参数
|
||||
* @author xiejs
|
||||
* @since 2022-02-15
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "alapi.open")
|
||||
@Component
|
||||
public class AlApiProperties {
|
||||
|
||||
private String token;
|
||||
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 百度平台密钥
|
||||
* @author xiejs
|
||||
* @desc
|
||||
* @create 2021-12-25
|
||||
* @since 2021-12-25
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "baidu.open")
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 天行数据配置
|
||||
* @author xiejs
|
||||
* @desc 天行数据配置
|
||||
* @create 2021-12-27
|
||||
* @since 2021-12-27
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "tianxing.open")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.xjs.common.client.api.alapi;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.annotation.ApiLog;
|
||||
import com.xjs.common.client.factory.AlapiJokeAllFeignFactory;
|
||||
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.ALAPI_JOKE_ALL;
|
||||
import static com.xjs.consts.ApiConst.ALAPI_JOKE_ALL_URL;
|
||||
|
||||
/**
|
||||
* alapi平台笑话大全feign
|
||||
* @author xiejs
|
||||
* @since 2022-02-15
|
||||
*/
|
||||
@FeignClient(name = "alapiJokeAll", url = ALAPI_JOKE_ALL_URL, fallbackFactory = AlapiJokeAllFeignFactory.class)
|
||||
public interface AlapiJokeAllFeignClient {
|
||||
@GetMapping( headers ={ "Accept-Encoding=''"})//解决响应乱码
|
||||
@ApiLog(name = ALAPI_JOKE_ALL,
|
||||
url = ALAPI_JOKE_ALL_URL,
|
||||
method = "Get")
|
||||
JSONObject alapiJokeAllApi(@RequestParam("token") String token);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.xjs.common.client.factory;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.common.client.api.alapi.AlapiJokeAllFeignClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* alapi平台笑话大全降级处理
|
||||
* @author xiejs
|
||||
* @since 2022-02-15
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class AlapiJokeAllFeignFactory implements FallbackFactory<AlapiJokeAllFeignClient> {
|
||||
@Override
|
||||
public AlapiJokeAllFeignClient create(Throwable cause) {
|
||||
log.error("api模块alapi平台笑话大全服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return (token -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -57,6 +57,8 @@ public class CopyWritingController extends BaseController {
|
|||
private CopyWritingFactory lqAWordCopyWritingFactory;
|
||||
@Autowired
|
||||
private CopyWritingFactory uomgEarthLoveCopyWritingFactory;
|
||||
@Autowired
|
||||
private CopyWritingFactory alapiJokeAllCopyWritingFactory;
|
||||
|
||||
|
||||
@GetMapping
|
||||
|
|
@ -110,6 +112,7 @@ public class CopyWritingController extends BaseController {
|
|||
factories.add(lqDogDiaryCopyWritingFactory);
|
||||
factories.add(lqPoisonChickenWritingFactory);
|
||||
factories.add(lqAWordCopyWritingFactory);
|
||||
factories.add(alapiJokeAllCopyWritingFactory);
|
||||
//factories.add(uomgEarthLoveCopyWritingFactory);
|
||||
//--------add----------------------------;-
|
||||
//随机调用集合中的接口
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package com.xjs.copywriting.factory.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.xjs.common.client.api.alapi.AlapiJokeAllFeignClient;
|
||||
import com.xjs.consts.CopyWritingConst;
|
||||
import com.xjs.copywriting.domain.CopyWriting;
|
||||
import com.xjs.copywriting.domain.RequestBody;
|
||||
import com.xjs.copywriting.factory.CopyWritingFactory;
|
||||
import com.xjs.copywriting.service.CopyWritingService;
|
||||
import com.xjs.exception.ApiException;
|
||||
import com.xjs.properties.AlApiProperties;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* alapi平台笑话大全 工厂实现
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-02-15
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class AlapiJokeAllCopyWritingFactory implements CopyWritingFactory {
|
||||
|
||||
@Autowired
|
||||
private CopyWritingService copyWritingService;
|
||||
@Autowired
|
||||
private AlapiJokeAllFeignClient alapiJokeAllFeignClient;
|
||||
@Autowired
|
||||
private AlApiProperties alApiProperties;
|
||||
|
||||
@Override
|
||||
public CopyWriting productCopyWriting(RequestBody requestBody) {
|
||||
JSONObject jsonObject = alapiJokeAllFeignClient.alapiJokeAllApi(alApiProperties.getToken());
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
throw new ApiException("alapi平台笑话大全接口调用异常");
|
||||
}
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONObject dataJson = jsonObject.getJSONObject("data");
|
||||
String content = dataJson.getString("content");
|
||||
CopyWriting copyWriting = new CopyWriting();
|
||||
copyWriting.setContent(content);
|
||||
copyWriting.setSource("笑话大全");
|
||||
copyWriting.setType(CopyWritingConst.XHDQ);
|
||||
copyWritingService.save(copyWriting);
|
||||
return copyWriting;
|
||||
} else {
|
||||
throw new ApiException("alapi平台笑话大全接口调用异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue