1、roll平台简繁转换api实现
This commit is contained in:
parent
90d7eb47d8
commit
adbd6075af
|
|
@ -62,6 +62,8 @@ public class ApiConst {
|
||||||
|
|
||||||
public static final String ROLL_HISTORY_TODAY = "ROLL-历史今天";
|
public static final String ROLL_HISTORY_TODAY = "ROLL-历史今天";
|
||||||
|
|
||||||
|
public static final String ROLL_SIMPLE_COMPLEX = "ROLL-简繁转换";
|
||||||
|
|
||||||
|
|
||||||
//-------------------url------------------------------
|
//-------------------url------------------------------
|
||||||
|
|
||||||
|
|
@ -136,6 +138,13 @@ public class ApiConst {
|
||||||
*/
|
*/
|
||||||
public static final String ROLL_HISTORY_TODAY_URL = "https://www.mxnzp.com/api/history/today";
|
public static final String ROLL_HISTORY_TODAY_URL = "https://www.mxnzp.com/api/history/today";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口文档:https://www.mxnzp.com/doc/detail?id=20
|
||||||
|
*/
|
||||||
|
public static final String ROLL_SIMPLE_COMPLEX_URL = "https://www.mxnzp.com/api/convert/zh";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* openApi启动器
|
||||||
* @author xiejs
|
* @author xiejs
|
||||||
* @desc
|
* @since 2021-12-25
|
||||||
* @create 2021-12-25
|
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.ruoyi.common.log.annotation.Log;
|
||||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
import com.xjs.apitools.domain.*;
|
import com.xjs.apitools.domain.*;
|
||||||
import com.xjs.apitools.service.ApiToolsService;
|
import com.xjs.apitools.service.ApiToolsService;
|
||||||
|
import com.xjs.utils.ChineseUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
@ -85,14 +86,23 @@ public class ApiToolsController {
|
||||||
|
|
||||||
@GetMapping("historytoday")
|
@GetMapping("historytoday")
|
||||||
@ApiOperation("获取历史今天信息")
|
@ApiOperation("获取历史今天信息")
|
||||||
@Log(title = "获取历史今天分类")
|
@Log(title = "获取历史今天")
|
||||||
public R<List<ApiHistoryToday>> getHistoryTodayApiData() {
|
public R<List<ApiHistoryToday>> getHistoryTodayApiData() {
|
||||||
return R.ok(apiToolsService.getHistoryTodayList());
|
return R.ok(apiToolsService.getHistoryTodayList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("simplecomplex/{content}")
|
||||||
|
@ApiOperation("获取简繁转换信息")
|
||||||
|
@Log(title = "获取简繁转换")
|
||||||
|
public R<ApiSimpleComplex> getSimpleComplexApiData(@PathVariable("content") String content) {
|
||||||
|
boolean b = ChineseUtils.checkNameChese(content);
|
||||||
|
if (b) {
|
||||||
|
return R.ok(apiToolsService.getSimpleComplex(content));
|
||||||
|
|
||||||
|
}else {
|
||||||
|
return R.fail("请输入中文!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.xjs.apitools.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api简繁转换实体
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ApiSimpleComplex implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原内容
|
||||||
|
*/
|
||||||
|
private String originContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转化后的内容
|
||||||
|
*/
|
||||||
|
private String convertContent;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,16 @@ public class RequestBody {
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否需要详情,0:不需要详情 1:需要详情 默认值 0 可不传
|
* 是否需要详情,0:不需要详情 1:需要详情 默认值 0 可不传 <br>
|
||||||
|
* 1 简体转繁体 2 繁体转简体
|
||||||
*/
|
*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待转换的内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.xjs.apitools.factory.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.apitools.domain.ApiSimpleComplex;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||||
|
import com.xjs.common.client.api.roll.RollSimpleComplexFeignClient;
|
||||||
|
import com.xjs.config.RollProperties;
|
||||||
|
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;
|
||||||
|
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollSimpleComplexFactory implements ApiToolsFactory<ApiSimpleComplex, RequestBody> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RollProperties rollProperties;
|
||||||
|
@Autowired
|
||||||
|
private RollSimpleComplexFeignClient rollSimpleComplexFeignClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiSimpleComplex apiData(RequestBody req) {
|
||||||
|
req.setApp_secret(rollProperties.getApp_secret());
|
||||||
|
req.setApp_id(rollProperties.getApp_id());
|
||||||
|
//type 1 简体转繁体 2 繁体转简体
|
||||||
|
req.setType(1);
|
||||||
|
JSONObject jsonObject = rollSimpleComplexFeignClient.simpleComplexApi(req);
|
||||||
|
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||||
|
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||||
|
return jsonData.toJavaObject(ApiSimpleComplex.class);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -63,5 +63,13 @@ public interface ApiToolsService {
|
||||||
List<ApiHistoryToday> getHistoryTodayList();
|
List<ApiHistoryToday> getHistoryTodayList();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取简繁转换数据
|
||||||
|
* @param content 传入的简体
|
||||||
|
* @return ApiSimpleComplex
|
||||||
|
*/
|
||||||
|
ApiSimpleComplex getSimpleComplex(String content);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.xjs.apitools.factory.impl.*;
|
||||||
import com.xjs.apitools.service.ApiToolsService;
|
import com.xjs.apitools.service.ApiToolsService;
|
||||||
import com.xjs.exception.ApiException;
|
import com.xjs.exception.ApiException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -39,6 +40,10 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
||||||
private ApiToolsFactory<ApiBeautyPicture, Object> beautyPictureFactory;
|
private ApiToolsFactory<ApiBeautyPicture, Object> beautyPictureFactory;
|
||||||
private ApiToolsFactory<ApiHistoryToday,Object> historyTodayFactory;
|
private ApiToolsFactory<ApiHistoryToday,Object> historyTodayFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("rollSimpleComplexFactory")
|
||||||
|
private ApiToolsFactory<ApiSimpleComplex,RequestBody> simpleComplexFactory;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setHolidayFactory(RollHolidayFactory rollHolidayFactory) {
|
public void setHolidayFactory(RollHolidayFactory rollHolidayFactory) {
|
||||||
this.holidayFactory = rollHolidayFactory;
|
this.holidayFactory = rollHolidayFactory;
|
||||||
|
|
@ -146,4 +151,11 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
||||||
throw new ApiException("获取历史上的今天api调用异常!!!");
|
throw new ApiException("获取历史上的今天api调用异常!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiSimpleComplex getSimpleComplex(String content) {
|
||||||
|
RequestBody requestBody = new RequestBody();
|
||||||
|
requestBody.setContent(content);
|
||||||
|
return simpleComplexFactory.apiData(requestBody);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.xjs.common.client.api.roll;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.annotation.ApiLog;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.common.client.factory.RollMobileBelongFeignFactory;
|
||||||
|
import com.xjs.common.client.factory.RollSimpleComplexFeignFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll简繁转换接口api调用
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "rollSimpleComplex", url = ROLL_SIMPLE_COMPLEX_URL, fallbackFactory = RollSimpleComplexFeignFactory.class)
|
||||||
|
public interface RollSimpleComplexFeignClient {
|
||||||
|
|
||||||
|
@GetMapping()
|
||||||
|
@ApiLog(name = ROLL_SIMPLE_COMPLEX,
|
||||||
|
url = ROLL_SIMPLE_COMPLEX_URL,
|
||||||
|
method = "Get")
|
||||||
|
JSONObject simpleComplexApi(@SpringQueryMap RequestBody requestBody);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.common.client.api.roll.RollSimpleComplexFeignClient;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollSimpleComplexFeignFactory implements FallbackFactory<RollSimpleComplexFeignClient> {
|
||||||
|
@Override
|
||||||
|
public RollSimpleComplexFeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块roll 简繁转换服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return requestBody -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue