parent
08db46f3ca
commit
8f71b8ad49
|
|
@ -24,3 +24,10 @@ export function delOneenglish(id) {
|
||||||
method: 'delete'
|
method: 'delete'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取英语一言api接口
|
||||||
|
export function getOneEnglishApi() {
|
||||||
|
return request({
|
||||||
|
url: '/openapi/oneenglish/getOneEnglish'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 ref="formEdit" :model="form" :rules="rulesEdit" label-width="80px" v-loading="loadingEdit">
|
||||||
<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="请输入英语单词"/>
|
||||||
|
|
@ -189,7 +189,7 @@
|
||||||
</el-select>
|
</el-select>
|
||||||
</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="submitFormEdit">确 定</el-button>
|
<el-button type="primary" @click="submitFormEdit">确 定</el-button>
|
||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -250,6 +250,11 @@
|
||||||
<div class="div2">
|
<div class="div2">
|
||||||
{{ form.content }}
|
{{ form.content }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="div2" style="height:320px ">
|
||||||
|
{{ oneEnglishData.en }}
|
||||||
|
<el-divider><i class="el-icon-mobile-phone"></i></el-divider>
|
||||||
|
{{ oneEnglishData.zh }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -258,7 +263,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 {
|
export default {
|
||||||
name: "Word",
|
name: "Word",
|
||||||
|
|
@ -303,6 +309,8 @@ export default {
|
||||||
form: {
|
form: {
|
||||||
sort: 0
|
sort: 0
|
||||||
},
|
},
|
||||||
|
//英语一言数据
|
||||||
|
oneEnglishData: {},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rulesEdit: {
|
rulesEdit: {
|
||||||
englishWord: [
|
englishWord: [
|
||||||
|
|
@ -341,6 +349,13 @@ export default {
|
||||||
this.getList();
|
this.getList();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
//获取英语一言api数据
|
||||||
|
getOneEnglishApi() {
|
||||||
|
getOneEnglishApi().then(res => {
|
||||||
|
this.oneEnglishData = res.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
//根据id查询放入抽屉
|
//根据id查询放入抽屉
|
||||||
findById(id) {
|
findById(id) {
|
||||||
this.loadingC = true;
|
this.loadingC = true;
|
||||||
|
|
@ -362,6 +377,7 @@ export default {
|
||||||
this.drawer = true
|
this.drawer = true
|
||||||
this.form = row;
|
this.form = row;
|
||||||
this.findById(row.id)
|
this.findById(row.id)
|
||||||
|
this.getOneEnglishApi()
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 查询英语单词列表 */
|
/** 查询英语单词列表 */
|
||||||
|
|
@ -436,14 +452,14 @@ export default {
|
||||||
this.$refs["formEdit"].validate(valid => {
|
this.$refs["formEdit"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
this.loadingEdit= true
|
this.loadingEdit = true
|
||||||
updateWord(this.form).then(response => {
|
updateWord(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.loadingEdit= false
|
this.loadingEdit = false
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
}).catch(err =>{
|
}).catch(err => {
|
||||||
this.loadingEdit= false
|
this.loadingEdit = false
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -456,14 +472,14 @@ export default {
|
||||||
this.$refs["formAdd"].validate(valid => {
|
this.$refs["formAdd"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id == null) {
|
if (this.form.id == null) {
|
||||||
this.loadingEdit= true
|
this.loadingEdit = true
|
||||||
addWord(this.form).then(response => {
|
addWord(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("新增成功");
|
this.$modal.msgSuccess("新增成功");
|
||||||
this.openAdd = false;
|
this.openAdd = false;
|
||||||
this.loadingEdit= false
|
this.loadingEdit = false
|
||||||
this.getList();
|
this.getList();
|
||||||
}).catch(err =>{
|
}).catch(err => {
|
||||||
this.loadingEdit= false
|
this.loadingEdit = false
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,19 @@ public class RedisConst {
|
||||||
//----------------------key------------------------
|
//----------------------key------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻译字典常量
|
* 翻译字典常量key
|
||||||
*/
|
*/
|
||||||
public static final String TRAN_DICT= "tranDict";
|
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 cn.hutool.http.HttpStatus;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
import com.xjs.common.client.TianXingOneEnglishFeignClient;
|
import com.xjs.common.client.TianXingOneEnglishFeignClient;
|
||||||
import com.xjs.config.TianXingProperties;
|
import com.xjs.config.TianXingProperties;
|
||||||
import com.xjs.exception.ApiException;
|
import com.xjs.exception.ApiException;
|
||||||
|
|
@ -13,6 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
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
|
* @author xiejs
|
||||||
|
|
@ -28,12 +35,21 @@ public class TianXingOneEnglishFactory implements OneEnglishFactory {
|
||||||
private TianXingProperties tianXingProperties;
|
private TianXingProperties tianXingProperties;
|
||||||
@Autowired
|
@Autowired
|
||||||
private TianXingOneEnglishFeignClient tianXingOneEnglishFeignClient;
|
private TianXingOneEnglishFeignClient tianXingOneEnglishFeignClient;
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiEnglish getOneEnglish(RequestBody requestBody) {
|
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());
|
requestBody.setKey(tianXingProperties.getKey());
|
||||||
JSONObject jsonObject = tianXingOneEnglishFeignClient.oneEnglishApi(requestBody);
|
JSONObject jsonObject = tianXingOneEnglishFeignClient.oneEnglishApi(requestBody);
|
||||||
ApiEnglish apiEnglish = new ApiEnglish();
|
|
||||||
if (!jsonObject.containsKey("error")) {
|
if (!jsonObject.containsKey("error")) {
|
||||||
if (jsonObject.getInteger("code") == HttpStatus.HTTP_OK) {
|
if (jsonObject.getInteger("code") == HttpStatus.HTTP_OK) {
|
||||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||||
|
|
@ -41,6 +57,13 @@ public class TianXingOneEnglishFactory implements OneEnglishFactory {
|
||||||
apiEnglish.setEn(content.getString("en"));
|
apiEnglish.setEn(content.getString("en"));
|
||||||
apiEnglish.setZh(content.getString("zh"));
|
apiEnglish.setZh(content.getString("zh"));
|
||||||
apiEnglishMapper.insert(apiEnglish);
|
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 {
|
}else {
|
||||||
throw new ApiException("英语一言接口调用成功,但内部错误");
|
throw new ApiException("英语一言接口调用成功,但内部错误");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue