parent
b6a6a9d922
commit
94f4c23ea0
@ -0,0 +1,96 @@
|
|||||||
|
package com.xjs.article.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.xjs.article.domain.EnglishArticle;
|
||||||
|
import com.xjs.article.service.impl.EnglishArticleServiceImpl;
|
||||||
|
import com.xjs.web.MyBaseController;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英语文章Controller
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-03
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/article")
|
||||||
|
@Api(tags = "业务模块-英语文章管理")
|
||||||
|
public class EnglishArticleController extends MyBaseController<EnglishArticle> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EnglishArticleServiceImpl englishArticleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询英语文章列表
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("english:article:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("查询英语文章列表")
|
||||||
|
public AjaxResult list(EnglishArticle englishArticle) {
|
||||||
|
IPage<EnglishArticle> page = englishArticleService.selectEnglishArticleList(startPageMP(), englishArticle);
|
||||||
|
return AjaxResult.success(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/test")
|
||||||
|
public AjaxResult test(EnglishArticle englishArticle) {
|
||||||
|
|
||||||
|
EnglishArticle translation = englishArticleService.translation(englishArticle);
|
||||||
|
return AjaxResult.success(translation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------代码生成------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取英语文章详细信息
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("english:article:query")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
@ApiOperation("获取英语文章详细信息")
|
||||||
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||||
|
return AjaxResult.success(englishArticleService.selectEnglishArticleById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增英语文章
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("english:article:add")
|
||||||
|
@Log(title = "英语文章", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增英语文章")
|
||||||
|
public AjaxResult add(@RequestBody EnglishArticle englishArticle) {
|
||||||
|
return toAjax(englishArticleService.insertEnglishArticle(englishArticle));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改英语文章
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("english:article:edit")
|
||||||
|
@Log(title = "英语文章", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改英语文章")
|
||||||
|
public AjaxResult edit(@RequestBody EnglishArticle englishArticle) {
|
||||||
|
return toAjax(englishArticleService.updateEnglishArticle(englishArticle));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除英语文章
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("english:article:remove")
|
||||||
|
@Log(title = "英语文章", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
@ApiOperation("删除英语文章")
|
||||||
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||||
|
return toAjax(englishArticleService.deleteEnglishArticleByIds(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.xjs.article.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import com.xjs.entity.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英语文章实体类
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class EnglishArticle extends BaseEntity {
|
||||||
|
|
||||||
|
/** 主键ID */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 文章标题 */
|
||||||
|
@Excel(name = "文章标题-英文")
|
||||||
|
private String titleEnglish;
|
||||||
|
|
||||||
|
/** 文章标题-中文 */
|
||||||
|
@Excel(name = "文章标题-中文")
|
||||||
|
private String titleChinese;
|
||||||
|
|
||||||
|
/** 文章内容 */
|
||||||
|
@Excel(name = "文章内容-英文")
|
||||||
|
private String contentEnglish;
|
||||||
|
|
||||||
|
/** 文章内容-中文 */
|
||||||
|
@Excel(name = "文章内容-中文")
|
||||||
|
private String contentChinese;
|
||||||
|
|
||||||
|
/** 文章图片地址 */
|
||||||
|
@Excel(name = "文章图片地址")
|
||||||
|
private String pictureUrl;
|
||||||
|
|
||||||
|
/** 创建用户 */
|
||||||
|
@Excel(name = "创建用户")
|
||||||
|
private String createUser;
|
||||||
|
|
||||||
|
@Excel(name = "创建时间" ,dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Excel(name = "修改时间" ,dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.xjs.article.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xjs.article.domain.EnglishArticle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英语文章Mapper接口
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-03
|
||||||
|
*/
|
||||||
|
public interface EnglishArticleMapper extends BaseMapper<EnglishArticle> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.xjs.article.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.xjs.article.domain.EnglishArticle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英语文章service接口
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-03
|
||||||
|
*/
|
||||||
|
public interface EnglishArticleService extends IService<EnglishArticle> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询英语文章
|
||||||
|
*
|
||||||
|
* @param id 英语文章主键
|
||||||
|
* @return 英语文章
|
||||||
|
*/
|
||||||
|
EnglishArticle selectEnglishArticleById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询英语文章列表
|
||||||
|
*
|
||||||
|
* @param englishArticle 英语文章
|
||||||
|
* @param page 分页参数
|
||||||
|
* @return 英语文章集合
|
||||||
|
*/
|
||||||
|
IPage<EnglishArticle> selectEnglishArticleList(Page<EnglishArticle> page, EnglishArticle englishArticle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增英语文章
|
||||||
|
*
|
||||||
|
* @param englishArticle 英语文章
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
boolean insertEnglishArticle(EnglishArticle englishArticle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改英语文章
|
||||||
|
*
|
||||||
|
* @param englishArticle 英语文章
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
boolean updateEnglishArticle(EnglishArticle englishArticle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除英语文章
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的英语文章主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
boolean deleteEnglishArticleByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除英语文章信息
|
||||||
|
*
|
||||||
|
* @param id 英语文章主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
boolean deleteEnglishArticleById(Long id);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package com.xjs.article.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.common.core.constant.HttpStatus;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.article.domain.EnglishArticle;
|
||||||
|
import com.xjs.article.mapper.EnglishArticleMapper;
|
||||||
|
import com.xjs.article.service.EnglishArticleService;
|
||||||
|
import com.xjs.business.api.RemoteTranslationFeign;
|
||||||
|
import com.xjs.business.api.domain.TranslationVo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英语文章service接口实现
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-03
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EnglishArticleServiceImpl extends ServiceImpl<EnglishArticleMapper, EnglishArticle> implements EnglishArticleService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteTranslationFeign remoteTranslationFeign;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnglishArticle selectEnglishArticleById(Long id) {
|
||||||
|
return super.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<EnglishArticle> selectEnglishArticleList(Page<EnglishArticle> page, EnglishArticle englishArticle) {
|
||||||
|
//封装查询条件
|
||||||
|
LambdaQueryWrapper<EnglishArticle> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
// todo 封装查询条件
|
||||||
|
|
||||||
|
return super.page(page, wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean insertEnglishArticle(EnglishArticle englishArticle) {
|
||||||
|
//封装添加参数 远程调用翻译
|
||||||
|
englishArticle = this.translation(englishArticle);
|
||||||
|
|
||||||
|
return super.save(englishArticle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateEnglishArticle(EnglishArticle englishArticle) {
|
||||||
|
return super.updateById(englishArticle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteEnglishArticleByIds(Long[] ids) {
|
||||||
|
return super.removeByIds(Arrays.asList(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteEnglishArticleById(Long id) {
|
||||||
|
return super.removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻译中文内容
|
||||||
|
*
|
||||||
|
* @param englishArticle 文章实体类
|
||||||
|
* @return 文章实体类
|
||||||
|
*/
|
||||||
|
public EnglishArticle translation(EnglishArticle englishArticle) {
|
||||||
|
// 使用线程安全的Vector
|
||||||
|
Vector<Thread> threads = new Vector<Thread>();
|
||||||
|
|
||||||
|
Thread thread1 = new Thread(() -> {
|
||||||
|
R<TranslationVo> titleR = remoteTranslationFeign.translation(englishArticle.getTitleChinese());
|
||||||
|
if (titleR.getCode() == HttpStatus.SUCCESS) {
|
||||||
|
List<Map<String, String>> transResult = titleR.getData().getTransResult();
|
||||||
|
StringBuilder sbEnglish = new StringBuilder();
|
||||||
|
for (Map<String, String> map : transResult) {
|
||||||
|
sbEnglish.append(map.get("dst"));
|
||||||
|
}
|
||||||
|
englishArticle.setTitleEnglish(sbEnglish.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
threads.add(thread1);
|
||||||
|
thread1.start();
|
||||||
|
|
||||||
|
Thread thread2 = new Thread(() -> {
|
||||||
|
R<TranslationVo> titleR = remoteTranslationFeign.translation(englishArticle.getContentChinese());
|
||||||
|
if (titleR.getCode() == HttpStatus.SUCCESS) {
|
||||||
|
List<Map<String, String>> transResult = titleR.getData().getTransResult();
|
||||||
|
StringBuilder sbEnglish = new StringBuilder();
|
||||||
|
for (Map<String, String> map : transResult) {
|
||||||
|
sbEnglish.append(map.get("dst"));
|
||||||
|
}
|
||||||
|
englishArticle.setContentEnglish(sbEnglish.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
threads.add(thread2);
|
||||||
|
thread2.start();
|
||||||
|
|
||||||
|
for (Thread thread : threads) {
|
||||||
|
// 等待所有线程执行完毕
|
||||||
|
try {
|
||||||
|
thread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return englishArticle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?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.article.mapper.EnglishArticleMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in new issue