说明:1、api模块实现调用天性数据翻译字典接口
2、英语模块实现远程rpc调用api模块接口
3、前端校验bug修复
4、根据id查看英语单词接口完成
This commit is contained in:
parent
75c99ea561
commit
1b0ad3fe0e
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.xjs.business.api;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.api.domain.TranslationVo;
|
||||||
|
import com.xjs.business.api.factory.RemoteTranDictFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc rpc调用翻译字典接口
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@FeignClient(contextId = "remoteTranDictFeign",
|
||||||
|
value = ServiceNameConstants.BUSINESS_OPENAPI_SERVICE,
|
||||||
|
fallbackFactory = RemoteTranDictFactory.class)
|
||||||
|
public interface RemoteTranDIctFeign {
|
||||||
|
|
||||||
|
@GetMapping(value = "/tranDict/tranDictForRPC")
|
||||||
|
R<TranslationVo> tranDict(@RequestParam("content") String content);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.xjs.business.english;
|
package com.xjs.business.api;
|
||||||
|
|
||||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.xjs.business.english.domain.TranslationVo;
|
import com.xjs.business.api.domain.TranslationVo;
|
||||||
import com.xjs.business.english.factory.RemoteTranslationFactory;
|
import com.xjs.business.api.factory.RemoteTranslationFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.xjs.business.english.domain;
|
package com.xjs.business.api.domain;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.xjs.business.api.factory;
|
package com.xjs.business.api.factory;
|
||||||
|
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
|
|
||||||
import com.xjs.business.api.RemoteCopyWritingFeign;
|
import com.xjs.business.api.RemoteCopyWritingFeign;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -16,7 +15,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class RemoteCopyWritingFactory implements FallbackFactory<RemoteCopyWritingFeign> {
|
public class RemoteCopyWritingFactory implements FallbackFactory<RemoteCopyWritingFeign> {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
|
private static final Logger log = LoggerFactory.getLogger(RemoteCopyWritingFactory.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteCopyWritingFeign create(Throwable cause) {
|
public RemoteCopyWritingFeign create(Throwable cause) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.xjs.business.api.factory;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.api.RemoteTranDIctFeign;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 翻译字段服务降级处理
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RemoteTranDictFactory implements FallbackFactory<RemoteTranDIctFeign> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteTranDictFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteTranDIctFeign create(Throwable cause) {
|
||||||
|
log.error("api模块文案服务调用失败:{}", cause.getMessage());
|
||||||
|
return content -> R.fail("文案服务调用失败" + cause.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package com.xjs.business.english.factory;
|
package com.xjs.business.api.factory;
|
||||||
|
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
|
import com.xjs.business.api.RemoteTranslationFeign;
|
||||||
import com.xjs.business.english.RemoteTranslationFeign;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
@ -16,7 +15,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class RemoteTranslationFactory implements FallbackFactory<RemoteTranslationFeign> {
|
public class RemoteTranslationFactory implements FallbackFactory<RemoteTranslationFeign> {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
|
private static final Logger log = LoggerFactory.getLogger(RemoteTranslationFactory.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteTranslationFeign create(Throwable cause) {
|
public RemoteTranslationFeign create(Throwable cause) {
|
||||||
|
|
@ -106,6 +106,14 @@
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
|
<el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
|
<el-tooltip class="item" effect="dark" content="点击查看详情" placement="top-start">
|
||||||
|
<el-button circle
|
||||||
|
type=""
|
||||||
|
icon="el-icon-view"
|
||||||
|
@click="handleView(scope.row,scope.index)"
|
||||||
|
v-hasPermi="['openapi:word:query']"
|
||||||
|
></el-button>
|
||||||
|
</el-tooltip>
|
||||||
<el-button circle
|
<el-button circle
|
||||||
type="primary"
|
type="primary"
|
||||||
icon="el-icon-edit"
|
icon="el-icon-edit"
|
||||||
|
|
@ -132,7 +140,7 @@
|
||||||
|
|
||||||
<!-- 修改英语单词对话框 -->
|
<!-- 修改英语单词对话框 -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rulesEdit" label-width="80px">
|
<el-form ref="formEdit" :model="form" :rules="rulesEdit" label-width="80px">
|
||||||
<el-form-item label="英语单词" prop="englishWord">
|
<el-form-item label="英语单词" prop="englishWord">
|
||||||
<el-input v-model="form.englishWord" placeholder="请输入英语单词"/>
|
<el-input v-model="form.englishWord" placeholder="请输入英语单词"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -167,14 +175,14 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button type="primary" @click="submitFormEdit">确 定</el-button>
|
||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<!--添加英语对话框-->
|
<!--添加英语对话框-->
|
||||||
<el-dialog :title="title" :visible.sync="openAdd" width="500px" append-to-body>
|
<el-dialog :title="title" :visible.sync="openAdd" width="500px" append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rulesAdd" label-width="80px">
|
<el-form ref="formAdd" :model="form" :rules="rulesAdd" label-width="80px">
|
||||||
<el-form-item label="中英文" prop="content">
|
<el-form-item label="中英文" prop="content">
|
||||||
<el-input v-model="form.content" placeholder="请输入中文或英文"/>
|
<el-input v-model="form.content" placeholder="请输入中文或英文"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -206,10 +214,24 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button type="primary" @click="submitFormAdd">确 定</el-button>
|
||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 抽屉 查看详情-->
|
||||||
|
<el-drawer
|
||||||
|
title="单词内容"
|
||||||
|
:visible.sync="drawer"
|
||||||
|
direction="rtl"
|
||||||
|
:before-close="handleClose">
|
||||||
|
|
||||||
|
|
||||||
|
<span>我来啦!</span>
|
||||||
|
|
||||||
|
|
||||||
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -221,6 +243,8 @@ export default {
|
||||||
dicts: ['english_collect', 'english_top'],
|
dicts: ['english_collect', 'english_top'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
//抽屉开关
|
||||||
|
drawer: false,
|
||||||
// 遮罩层
|
// 遮罩层
|
||||||
loading: true,
|
loading: true,
|
||||||
// 选中数组
|
// 选中数组
|
||||||
|
|
@ -251,7 +275,9 @@ export default {
|
||||||
createTime: null
|
createTime: null
|
||||||
},
|
},
|
||||||
// 表单参数
|
// 表单参数
|
||||||
form: {},
|
form: {
|
||||||
|
sort: 0
|
||||||
|
},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rulesEdit: {
|
rulesEdit: {
|
||||||
englishWord: [
|
englishWord: [
|
||||||
|
|
@ -261,10 +287,10 @@ export default {
|
||||||
{required: true, message: "中文不能为空", trigger: "blur"}
|
{required: true, message: "中文不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
isCollect: [
|
isCollect: [
|
||||||
{required: true, message: "是否收藏 1收藏 2不收藏不能为空", trigger: "change"}
|
{required: true, message: "是否收藏 1收藏 2不收藏不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
top: [
|
top: [
|
||||||
{required: true, message: "置顶 1置顶 2不置顶不能为空", trigger: "change"}
|
{required: true, message: "置顶 1置顶 2不置顶不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
createTime: [
|
createTime: [
|
||||||
{required: true, message: "创建时间不能为空", trigger: "blur"}
|
{required: true, message: "创建时间不能为空", trigger: "blur"}
|
||||||
|
|
@ -275,10 +301,10 @@ export default {
|
||||||
{required: true, message: "中英文不能为空", trigger: "blur"}
|
{required: true, message: "中英文不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
isCollect: [
|
isCollect: [
|
||||||
{required: true, message: "是否收藏 1收藏 2不收藏不能为空", trigger: "change"}
|
{required: true, message: "是否收藏 1收藏 2不收藏不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
top: [
|
top: [
|
||||||
{required: true, message: "置顶 1置顶 2不置顶不能为空", trigger: "change"}
|
{required: true, message: "置顶 1置顶 2不置顶不能为空", trigger: "blur"}
|
||||||
],
|
],
|
||||||
createTime: [
|
createTime: [
|
||||||
{required: true, message: "创建时间不能为空", trigger: "blur"}
|
{required: true, message: "创建时间不能为空", trigger: "blur"}
|
||||||
|
|
@ -290,6 +316,17 @@ export default {
|
||||||
this.getList();
|
this.getList();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
//关闭抽屉
|
||||||
|
handleClose(done) {
|
||||||
|
done();
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 详细按钮操作 */
|
||||||
|
handleView(row) {
|
||||||
|
this.drawer = true
|
||||||
|
this.form = row;
|
||||||
|
},
|
||||||
|
|
||||||
/** 查询英语单词列表 */
|
/** 查询英语单词列表 */
|
||||||
getList() {
|
getList() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
@ -358,25 +395,37 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm() {
|
submitFormEdit() {
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["formEdit"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
updateWord(this.form).then(response => {
|
updateWord(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
addWord(this.form).then(response => {
|
|
||||||
this.$modal.msgSuccess("新增成功");
|
|
||||||
this.openAdd = false;
|
|
||||||
this.getList();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
submitFormAdd() {
|
||||||
|
this.$refs["formAdd"].validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
if (this.form.id == null) {
|
||||||
|
addWord(this.form).then(response => {
|
||||||
|
this.$modal.msgSuccess("新增成功");
|
||||||
|
this.openAdd = false;
|
||||||
|
this.getList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
const ids = row.id || this.ids;
|
const ids = row.id || this.ids;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,6 +32,7 @@ public class EnglishWord {
|
||||||
*/
|
*/
|
||||||
@Excel(name = "英语单词")
|
@Excel(name = "英语单词")
|
||||||
@NotBlank(message = "英语单词不能为空",groups = {UpdateGroup.class})
|
@NotBlank(message = "英语单词不能为空",groups = {UpdateGroup.class})
|
||||||
|
@Size(max = 15,message = "请控制长度在5字符",groups = {UpdateGroup.class})
|
||||||
private String englishWord;
|
private String englishWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +40,7 @@ public class EnglishWord {
|
||||||
*/
|
*/
|
||||||
@Excel(name = "中文")
|
@Excel(name = "中文")
|
||||||
@NotBlank(message = "中文不能为空",groups = {UpdateGroup.class})
|
@NotBlank(message = "中文不能为空",groups = {UpdateGroup.class})
|
||||||
|
@Size(max = 5,message = "请控制长度在5字符",groups = {UpdateGroup.class})
|
||||||
private String chineseWord;
|
private String chineseWord;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -46,6 +49,7 @@ public class EnglishWord {
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
@NotBlank(message = "内容不能为空",groups = {AddGroup.class})
|
@NotBlank(message = "内容不能为空",groups = {AddGroup.class})
|
||||||
|
@Size(max = 15,message = "请控制长度在5字符",groups = {AddGroup.class})
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ package com.xjs.word.service.impl;
|
||||||
|
|
||||||
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.xjs.business.english.RemoteTranslationFeign;
|
import com.xjs.business.api.RemoteTranDIctFeign;
|
||||||
import com.xjs.business.english.domain.TranslationVo;
|
import com.xjs.business.api.RemoteTranslationFeign;
|
||||||
|
import com.xjs.business.api.domain.TranslationVo;
|
||||||
import com.xjs.exception.BusinessException;
|
import com.xjs.exception.BusinessException;
|
||||||
import com.xjs.utils.ChineseUtil;
|
import com.xjs.utils.ChineseUtil;
|
||||||
import com.xjs.word.domain.EnglishWord;
|
import com.xjs.word.domain.EnglishWord;
|
||||||
|
|
@ -14,6 +15,8 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 英语单词Service业务层处理
|
* 英语单词Service业务层处理
|
||||||
|
|
@ -27,30 +30,31 @@ public class EnglishWordServiceImpl implements IEnglishWordService {
|
||||||
private EnglishWordMapper englishWordMapper;
|
private EnglishWordMapper englishWordMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RemoteTranslationFeign remoteTranslationFeign;
|
private RemoteTranslationFeign remoteTranslationFeign;
|
||||||
|
@Autowired
|
||||||
|
private RemoteTranDIctFeign remoteTranDIctFeign;
|
||||||
|
|
||||||
|
|
||||||
//------------------------代码自动生成-----------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询英语单词
|
* 查询英语单词、远程调用获取翻译字典
|
||||||
*
|
*
|
||||||
* @param id 英语单词主键
|
* @param id 英语单词主键
|
||||||
* @return 英语单词
|
* @return 英语单词
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EnglishWord selectEnglishWordById(Long id) {
|
public EnglishWord selectEnglishWordById(Long id) {
|
||||||
return englishWordMapper.selectEnglishWordById(id);
|
//todo 查看单个单词详细信息
|
||||||
}
|
EnglishWord englishWord = englishWordMapper.selectById(id);
|
||||||
|
R<TranslationVo> r = remoteTranDIctFeign.tranDict(englishWord.getEnglishWord());
|
||||||
/**
|
if (r.getCode() != R.FAIL) {
|
||||||
* 查询英语单词列表
|
if (Objects.isNull(r.getData().getErrorCode())) {
|
||||||
*
|
//指定to为翻译字典转换的内容
|
||||||
* @param englishWord 英语单词
|
englishWord.setContent(r.getData().getTo());
|
||||||
* @return 英语单词
|
}
|
||||||
*/
|
}
|
||||||
@Override
|
//每次调用查看次数+1
|
||||||
public List<EnglishWord> selectEnglishWordList(EnglishWord englishWord) {
|
Long count = englishWord.getLookCount() + 1;
|
||||||
return englishWordMapper.selectEnglishWordList(englishWord);
|
englishWord.setLookCount(count);
|
||||||
|
return englishWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,13 +68,9 @@ public class EnglishWordServiceImpl implements IEnglishWordService {
|
||||||
//校验前端传入的是否英文或中文
|
//校验前端传入的是否英文或中文
|
||||||
boolean alpha = ChineseUtil.isAlpha(englishWord.getContent());
|
boolean alpha = ChineseUtil.isAlpha(englishWord.getContent());
|
||||||
boolean chinese = ChineseUtil.checkNameChese(englishWord.getContent());
|
boolean chinese = ChineseUtil.checkNameChese(englishWord.getContent());
|
||||||
boolean contains = englishWord.getContent().contains(" ");
|
|
||||||
//如果两个都不成立,代表包含字符
|
|
||||||
if (!alpha && !chinese) {
|
if (!alpha && !chinese) {
|
||||||
throw new BusinessException("不能包含其他符号!!!");
|
throw new BusinessException("不能包含其他符号!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//代表用户输入中文
|
//代表用户输入中文
|
||||||
if (chinese) {
|
if (chinese) {
|
||||||
englishWord.setChineseWord(englishWord.getContent());
|
englishWord.setChineseWord(englishWord.getContent());
|
||||||
|
|
@ -89,11 +89,29 @@ public class EnglishWordServiceImpl implements IEnglishWordService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
englishWord.setLookCount(0L);
|
englishWord.setLookCount(0L);
|
||||||
|
//如果排序字段没有值默认=0
|
||||||
|
Integer integer = Optional.ofNullable(englishWord.getSort()).orElseGet(() -> 0);
|
||||||
|
englishWord.setSort(integer);
|
||||||
return englishWordMapper.insert(englishWord);
|
return englishWordMapper.insert(englishWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------代码自动生成-----------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询英语单词列表
|
||||||
|
*
|
||||||
|
* @param englishWord 英语单词
|
||||||
|
* @return 英语单词
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<EnglishWord> selectEnglishWordList(EnglishWord englishWord) {
|
||||||
|
return englishWordMapper.selectEnglishWordList(englishWord);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改英语单词
|
* 修改英语单词
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.xjs.common.client;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.common.aop.ApiLog;
|
||||||
|
import com.xjs.common.client.factory.TianXingTranDictFeignFactory;
|
||||||
|
import com.xjs.copywriting.domain.RequestBody;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import static com.xjs.common.consts.ApiConst.TIANXING_TRAN_DICT;
|
||||||
|
import static com.xjs.common.consts.ApiConst.TIANXING_TRAN_DICT_URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 天行翻译字典接口api调用
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
@FeignClient(name = "tianXingTranDict",url = TIANXING_TRAN_DICT_URL,fallbackFactory = TianXingTranDictFeignFactory.class)
|
||||||
|
public interface TianXingTranDictClient {
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiLog(name = TIANXING_TRAN_DICT,
|
||||||
|
url = TIANXING_TRAN_DICT_URL,
|
||||||
|
method = "Get")
|
||||||
|
JSONObject tranDictApi(@SpringQueryMap RequestBody requestBody);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.TianXingTranDictClient;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 天行api翻译字典降级处理
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class TianXingTranDictFeignFactory implements FallbackFactory<TianXingTranDictClient> {
|
||||||
|
@Override
|
||||||
|
public TianXingTranDictClient create(Throwable cause) {
|
||||||
|
log.error("api模块翻译字典服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return requestBody -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("error", R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.xjs.common.client.factory;
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.xjs.common.client.YouDaoFeignClient;
|
import com.xjs.common.client.YouDaoFeignClient;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
@ -21,7 +22,7 @@ public class YouDaoFeignFactory implements FallbackFactory<YouDaoFeignClient> {
|
||||||
return qo -> {
|
return qo -> {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
//构建一个异常json给下层接口处理
|
//构建一个异常json给下层接口处理
|
||||||
jsonObject.put("error", 500);
|
jsonObject.put("error", R.FAIL);
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ public class ApiConst {
|
||||||
|
|
||||||
public static final String TIANXING_MMMY= "天行-名人名言";
|
public static final String TIANXING_MMMY= "天行-名人名言";
|
||||||
|
|
||||||
|
public static final String TIANXING_TRAN_DICT= "天行-翻译字典";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final String TEN_YY= "Ten-一言";
|
public static final String TEN_YY= "Ten-一言";
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,6 +42,10 @@ public class ApiConst {
|
||||||
|
|
||||||
public static final String TIANXING_MMMY_URL= "http://api.tianapi.com/mingyan/index";
|
public static final String TIANXING_MMMY_URL= "http://api.tianapi.com/mingyan/index";
|
||||||
|
|
||||||
|
public static final String TIANXING_TRAN_DICT_URL= "http://api.tianapi.com/enwords/index";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final String TEN_YY_URL= "https://tenapi.cn/yiyan/";
|
public static final String TEN_YY_URL= "https://tenapi.cn/yiyan/";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,9 @@ public class RequestBody {
|
||||||
* 请求类型 json/js/text
|
* 请求类型 json/js/text
|
||||||
*/
|
*/
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 词
|
||||||
|
*/
|
||||||
|
private String word;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.xjs.translation.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.security.annotation.RequiresLogin;
|
||||||
|
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
||||||
|
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
||||||
|
import com.xjs.translation.factory.TranslationFactory;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 翻译字典控制器
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("tranDict")
|
||||||
|
@Api(tags = "业务模块-翻译字典管理")
|
||||||
|
@Log4j2
|
||||||
|
public class TranDictController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TranslationFactory tianXingTranDictFactory;
|
||||||
|
|
||||||
|
@GetMapping("tranDictForRPC")
|
||||||
|
@RequiresLogin
|
||||||
|
public R<TranslationVo> tranDict(String content) {
|
||||||
|
TranslationQo translationQo = new TranslationQo();
|
||||||
|
translationQo.setQ(content);
|
||||||
|
TranslationVo translationVo;
|
||||||
|
try {
|
||||||
|
translationVo = tianXingTranDictFactory.translationApi(translationQo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
translationVo = new TranslationVo();
|
||||||
|
translationVo.setErrorCode((long) R.FAIL);
|
||||||
|
log.error("翻译字典接口平台异常");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return R.ok(translationVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -65,7 +65,7 @@ public class TranslationController {
|
||||||
translationVo = translationFactory.translationApi(translationQo);
|
translationVo = translationFactory.translationApi(translationQo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
translationVo = new TranslationVo();
|
translationVo = new TranslationVo();
|
||||||
translationVo.setErrorCode(500L);
|
translationVo.setErrorCode((long) R.FAIL);
|
||||||
log.error("翻译接口平台异常");
|
log.error("翻译接口平台异常");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.xjs.translation.factory.impl;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.common.client.TianXingTranDictClient;
|
||||||
|
import com.xjs.config.TianXingProperties;
|
||||||
|
import com.xjs.copywriting.domain.RequestBody;
|
||||||
|
import com.xjs.exception.ApiException;
|
||||||
|
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
||||||
|
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
||||||
|
import com.xjs.translation.factory.TranslationFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 天行数据平台翻译字典实现工厂
|
||||||
|
* @create 2021-12-30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TianXingTranDictFactory implements TranslationFactory {
|
||||||
|
@Autowired
|
||||||
|
private TianXingProperties tianXingProperties;
|
||||||
|
@Autowired
|
||||||
|
private TianXingTranDictClient tianXingTranDictClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslationVo translationApi(TranslationQo translationQo) {
|
||||||
|
RequestBody requestBody = new RequestBody();
|
||||||
|
requestBody.setWord(translationQo.getQ());
|
||||||
|
requestBody.setKey(tianXingProperties.getKey());
|
||||||
|
JSONObject jsonObject = tianXingTranDictClient.tranDictApi(requestBody);
|
||||||
|
TranslationVo translationVo = new TranslationVo();
|
||||||
|
if (!jsonObject.containsKey("error")) {
|
||||||
|
//代表没进入降级类
|
||||||
|
if (jsonObject.getInteger("code") == 250) {
|
||||||
|
throw new ApiException("内容输入错误");
|
||||||
|
}
|
||||||
|
if (jsonObject.getInteger("code") == HttpStatus.HTTP_OK) {
|
||||||
|
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||||
|
JSONObject contentJson = newslist.getJSONObject(0);
|
||||||
|
String content = contentJson.getString("content");
|
||||||
|
translationVo.setTo(content);
|
||||||
|
} else {
|
||||||
|
throw new ApiException("api调用成功,但返回错误信息");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
translationVo.setTo(" - ");
|
||||||
|
}
|
||||||
|
return translationVo;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue