parent
08db46f3ca
commit
8f71b8ad49
|
|
@ -24,3 +24,10 @@ export function delOneenglish(id) {
|
|||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
//获取英语一言api接口
|
||||
export function getOneEnglishApi() {
|
||||
return request({
|
||||
url: '/openapi/oneenglish/getOneEnglish'
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,16 +86,16 @@
|
|||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<router-link :to="'/openapi/english/collect/'" class="link-type">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="el-icon-star-off"
|
||||
size="mini"
|
||||
@click="handleCollect"
|
||||
v-hasPermi="['english:word:collect']"
|
||||
>
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="el-icon-star-off"
|
||||
size="mini"
|
||||
@click="handleCollect"
|
||||
v-hasPermi="['english:word:collect']"
|
||||
>
|
||||
收藏夹
|
||||
</el-button>
|
||||
</el-button>
|
||||
</router-link>
|
||||
|
||||
</el-col>
|
||||
|
|
@ -154,7 +154,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="formEdit" :model="form" :rules="rulesEdit" label-width="80px" v-loading="loadingEdit">
|
||||
<el-form-item label="英语单词" prop="englishWord">
|
||||
<el-input v-model="form.englishWord" placeholder="请输入英语单词"/>
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer" >
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitFormEdit">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
|
|
@ -250,6 +250,11 @@
|
|||
<div class="div2">
|
||||
{{ form.content }}
|
||||
</div>
|
||||
<div class="div2" style="height:320px ">
|
||||
{{ oneEnglishData.en }}
|
||||
<el-divider><i class="el-icon-mobile-phone"></i></el-divider>
|
||||
{{ oneEnglishData.zh }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
@ -258,7 +263,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {listWord, getWord, delWord, addWord, updateWord,getWordRPC} from "@/api/business/english/word";
|
||||
import {listWord, getWord, delWord, addWord, updateWord, getWordRPC} from "@/api/business/english/word";
|
||||
import {getOneEnglishApi} from "@/api/business/openapi/oneenglish";
|
||||
|
||||
export default {
|
||||
name: "Word",
|
||||
|
|
@ -303,6 +309,8 @@ export default {
|
|||
form: {
|
||||
sort: 0
|
||||
},
|
||||
//英语一言数据
|
||||
oneEnglishData: {},
|
||||
// 表单校验
|
||||
rulesEdit: {
|
||||
englishWord: [
|
||||
|
|
@ -341,6 +349,13 @@ export default {
|
|||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
//获取英语一言api数据
|
||||
getOneEnglishApi() {
|
||||
getOneEnglishApi().then(res => {
|
||||
this.oneEnglishData = res.data
|
||||
})
|
||||
},
|
||||
|
||||
//根据id查询放入抽屉
|
||||
findById(id) {
|
||||
this.loadingC = true;
|
||||
|
|
@ -362,6 +377,7 @@ export default {
|
|||
this.drawer = true
|
||||
this.form = row;
|
||||
this.findById(row.id)
|
||||
this.getOneEnglishApi()
|
||||
},
|
||||
|
||||
/** 查询英语单词列表 */
|
||||
|
|
@ -436,14 +452,14 @@ export default {
|
|||
this.$refs["formEdit"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != null) {
|
||||
this.loadingEdit= true
|
||||
this.loadingEdit = true
|
||||
updateWord(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.loadingEdit= false
|
||||
this.loadingEdit = false
|
||||
this.open = false;
|
||||
this.getList();
|
||||
}).catch(err =>{
|
||||
this.loadingEdit= false
|
||||
}).catch(err => {
|
||||
this.loadingEdit = false
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -456,14 +472,14 @@ export default {
|
|||
this.$refs["formAdd"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id == null) {
|
||||
this.loadingEdit= true
|
||||
this.loadingEdit = true
|
||||
addWord(this.form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.openAdd = false;
|
||||
this.loadingEdit= false
|
||||
this.loadingEdit = false
|
||||
this.getList();
|
||||
}).catch(err =>{
|
||||
this.loadingEdit= false
|
||||
}).catch(err => {
|
||||
this.loadingEdit = false
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,19 @@ public class RedisConst {
|
|||
//----------------------key------------------------
|
||||
|
||||
/**
|
||||
* 翻译字典常量
|
||||
* 翻译字典常量key
|
||||
*/
|
||||
public static final String TRAN_DICT= "tranDict";
|
||||
|
||||
/**
|
||||
* 英语一言常量key
|
||||
*/
|
||||
public static final String ONE_ENGLISH= "oneEnglish";
|
||||
|
||||
|
||||
//-------------------有效时间-----------------------
|
||||
public static final Integer TRAN_DICT_EXPIRE = 7;
|
||||
public static final Integer TRAN_DICT_EXPIRE = 7; //天
|
||||
|
||||
public static final Integer ONE_ENGLISH_EXPIRE = 10; //分钟
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.xjs.oneenglish.factory;
|
|||
import cn.hutool.http.HttpStatus;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.xjs.common.client.TianXingOneEnglishFeignClient;
|
||||
import com.xjs.config.TianXingProperties;
|
||||
import com.xjs.exception.ApiException;
|
||||
|
|
@ -13,6 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.xjs.consts.RedisConst.ONE_ENGLISH;
|
||||
import static com.xjs.consts.RedisConst.ONE_ENGLISH_EXPIRE;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
|
|
@ -28,12 +35,21 @@ public class TianXingOneEnglishFactory implements OneEnglishFactory {
|
|||
private TianXingProperties tianXingProperties;
|
||||
@Autowired
|
||||
private TianXingOneEnglishFeignClient tianXingOneEnglishFeignClient;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public ApiEnglish getOneEnglish(RequestBody requestBody) {
|
||||
ApiEnglish apiEnglish = new ApiEnglish();
|
||||
//redis中有值直接返回
|
||||
if (redisService.hasKey(ONE_ENGLISH)) {
|
||||
Map<String, String> apiEnglishMap = redisService.getCacheMap(ONE_ENGLISH);
|
||||
apiEnglish.setEn(apiEnglishMap.get("en"));
|
||||
apiEnglish.setZh(apiEnglishMap.get("zh"));
|
||||
return apiEnglish;
|
||||
}
|
||||
requestBody.setKey(tianXingProperties.getKey());
|
||||
JSONObject jsonObject = tianXingOneEnglishFeignClient.oneEnglishApi(requestBody);
|
||||
ApiEnglish apiEnglish = new ApiEnglish();
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.HTTP_OK) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
|
|
@ -41,6 +57,13 @@ public class TianXingOneEnglishFactory implements OneEnglishFactory {
|
|||
apiEnglish.setEn(content.getString("en"));
|
||||
apiEnglish.setZh(content.getString("zh"));
|
||||
apiEnglishMapper.insert(apiEnglish);
|
||||
//把数据存入redis
|
||||
Map<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("en", apiEnglish.getEn());
|
||||
hashMap.put("zh", apiEnglish.getZh());
|
||||
redisService.setCacheMap(ONE_ENGLISH,hashMap);
|
||||
//设置过期时间
|
||||
redisService.expire(ONE_ENGLISH, ONE_ENGLISH_EXPIRE, TimeUnit.MINUTES);
|
||||
}else {
|
||||
throw new ApiException("英语一言接口调用成功,但内部错误");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue