说明:1、天行数据文案接口降级处理

2、天行数据文案接口调用异常处理
     3、添加jrebel热部署插件
     4、新增文案两个mapper sql
pull/254/head
xjs 4 years ago
parent f8e7e57f3c
commit c76fd56aad

@ -12,7 +12,10 @@ import org.springframework.web.bind.annotation.GetMapping;
* @desc RPC
* @create 2021-12-27
*/
@FeignClient(contextId = "remoteCopyWritingFeign", value = ServiceNameConstants.BUSINESS_ENGLISH_SERVICE, fallbackFactory = RemoteCopyWritingFactory.class)
@FeignClient(contextId = "remoteCopyWritingFeign",
value = ServiceNameConstants.BUSINESS_ENGLISH_SERVICE,
fallbackFactory = RemoteCopyWritingFactory.class)
@FunctionalInterface
public interface RemoteCopyWritingFeign {
/**
*

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-api-system</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-api/ruoyi-api-system/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-auth</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-auth/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-core</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-core/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-datascope</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-datascope/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-datasource</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-datasource/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-log</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-log/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-redis</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-redis/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-security</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-security/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-common-swagger</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-common/ruoyi-common-swagger/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-gateway</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-gateway/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-modules-file</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-modules/ruoyi-file/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-modules-gen</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-modules/ruoyi-gen/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-modules-job</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-modules/ruoyi-job/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-modules-system</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-modules/ruoyi-system/target/classes">
</dir>
</classpath>
</application>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>ruoyi-visual-monitor</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/ruoyi-visual/ruoyi-monitor/target/classes">
</dir>
</classpath>
</application>

@ -13,6 +13,7 @@
<artifactId>xjs-business</artifactId>
<packaging>pom</packaging>
<description>业务模块</description>
<name>业务模块</name>
<modules>
<module>xjs-business-english</module>
</modules>

@ -8,6 +8,7 @@
<version>3.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>业务模块-英语模块</name>
<artifactId>xjs-business-english</artifactId>

@ -16,7 +16,7 @@ import java.util.Optional;
/**
* @author xiejs
* @desc
* @desc api
* @create 2021-12-26
*/
@Component

@ -2,6 +2,7 @@ package com.xjs.common.client;
import com.alibaba.fastjson.JSONObject;
import com.xjs.common.aop.ApiLog;
import com.xjs.common.client.factory.TianXingFeignFactory;
import com.xjs.copywriting.domain.RequestBody;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
@ -12,7 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping;
* @desc api
* @create 2021-12-27
*/
@FeignClient(name = "tianXing",url = "http://api.tianapi.com/pyqwenan/index")
@FeignClient(name = "tianXing",url = "http://api.tianapi.com/pyqwenan/index",fallbackFactory = TianXingFeignFactory.class)
public interface TianXingFeignClient {
@GetMapping

@ -0,0 +1,48 @@
package com.xjs.common.client.factory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xjs.common.client.TianXingFeignClient;
import com.xjs.copywriting.domain.CopyWriting;
import com.xjs.copywriting.domain.RequestBody;
import com.xjs.copywriting.service.CopyWritingService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author xiejs
* @desc
* @create 2021-12-28
*/
@Log4j2
@Component
public class TianXingFeignFactory implements FallbackFactory<TianXingFeignClient> {
@Autowired
private CopyWritingService copyWritingService;
@Override
public TianXingFeignClient create(Throwable cause) {
log.error("英语模块文案服务调用失败:{},执行降级处理", cause.getMessage());
//没用拉姆达考虑后面该feign接口还会调用其他api接口
return new TianXingFeignClient() {
@Override
public JSONObject copyWritingApi(RequestBody requestBody) {
CopyWriting copyWriting = copyWritingService.getOneToRandom();
String jsonString = JSON.toJSONString(copyWriting);
return JSONObject.parseObject(jsonString);
}
};
}
}

@ -9,6 +9,7 @@ import com.ruoyi.common.security.annotation.RequiresPermissions;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +33,15 @@ public class CopyWritingController {
@Autowired
private CopyWritingFactory tianXingcopyWritingFactory;
@Autowired
private CopyWritingService copyWritingService;
//todo 文案管理前端页面,
// 第三方api服务降级
// 分析错误状态码(天行数据),
// 天行数据整合一个菜单,
// 实现其他天行数据接口,
// 实现其他朋友圈文案api
@GetMapping
@ApiOperation("文案接口")
@ -41,7 +51,7 @@ public class CopyWritingController {
public AjaxResult copyWriting(@Validated RequestBody requestBody) {
requestBody = Optional.ofNullable(requestBody).orElseGet(RequestBody::new);
CopyWritingFactory copyWritingFactory = this.randomApi();
CopyWriting copyWriting = copyWritingFactory.productCopyWriting(requestBody);
CopyWriting copyWriting = this.handlerException(copyWritingFactory, requestBody);
return AjaxResult.success(copyWriting);
}
@ -50,7 +60,8 @@ public class CopyWritingController {
@ApiOperation("供定时任务服务RPC远程调用")
public R<CopyWriting> copyWriting() {
CopyWritingFactory copyWritingFactory = this.randomApi();
return R.ok(copyWritingFactory.productCopyWriting(new RequestBody()));
CopyWriting copyWriting = this.handlerException(copyWritingFactory, new RequestBody());
return R.ok(copyWriting);
}
@ -68,6 +79,26 @@ public class CopyWritingController {
}
/**
* apiException
* @param copyWritingFactory
* @param requestBody
* @return
*/
private CopyWriting handlerException(CopyWritingFactory copyWritingFactory, RequestBody requestBody) {
CopyWriting copyWriting = null;
try {
copyWriting = copyWritingFactory.productCopyWriting(requestBody);
return copyWriting;
} catch (Exception e) {
e.printStackTrace();
copyWriting = copyWritingService.getOneToRandom();
return copyWriting;
}
}

@ -9,4 +9,16 @@ import com.xjs.copywriting.domain.CopyWriting;
* @create 2021-12-27
*/
public interface CopyWritingMapper extends BaseMapper<CopyWriting> {
/**
*
* @return CopyWriting
*/
CopyWriting getOneToNew();
/**
*
* @return CopyWriting
*/
CopyWriting getOneToRandom();
}

@ -0,0 +1,24 @@
package com.xjs.copywriting.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.copywriting.domain.CopyWriting;
/**
* @author xiejs
* @desc
* @create 2021-12-28
*/
public interface CopyWritingService extends IService<CopyWriting> {
/**
*
* @return CopyWriting
*/
CopyWriting getOneToNew();
/**
*
* @return CopyWriting
*/
CopyWriting getOneToRandom();
}

@ -0,0 +1,30 @@
package com.xjs.copywriting.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.copywriting.domain.CopyWriting;
import com.xjs.copywriting.mapper.CopyWritingMapper;
import com.xjs.copywriting.service.CopyWritingService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author xiejs
* @desc
* @create 2021-12-28
*/
@Service
public class CopyWritingServiceImpl extends ServiceImpl<CopyWritingMapper, CopyWriting> implements CopyWritingService{
@Resource
private CopyWritingMapper copyWritingMapper;
@Override
public CopyWriting getOneToNew() {
return copyWritingMapper.getOneToNew();
}
@Override
public CopyWriting getOneToRandom() {
return copyWritingMapper.getOneToRandom();
}
}

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xjs.copywriting.mapper.CopyWritingMapper">
<select id="getOneToNew" resultType="com.xjs.copywriting.domain.CopyWriting">
SELECT
id,
content,
source,
mt create_time
FROM
( SELECT max( create_time ) mt FROM api_copywriting ) time,
api_copywriting al
WHERE
time.mt = al.create_time
</select>
<select id="getOneToRandom" resultType="com.xjs.copywriting.domain.CopyWriting">
SELECT * FROM api_copywriting ORDER BY RAND() LIMIT 1
</select>
</mapper>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
<id>xjs-business-english</id>
<classpath>
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/xjs-business/xjs-business-english/target/classes">
</dir>
</classpath>
</application>
Loading…
Cancel
Save