| | |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.es.service.ElasticsearchDocumentService; |
| | | import org.springblade.es.vo.EsParam; |
| | | import org.springblade.modules.article.entity.Article; |
| | | import org.springblade.modules.article.service.ArticleService; |
| | | import org.springblade.modules.article.vo.ArticleVO; |
| | |
| | | public class ArticleController { |
| | | |
| | | private final ArticleService articleService; |
| | | private final ElasticsearchDocumentService elasticsearchDocumentService; |
| | | |
| | | /** |
| | | * 查询资讯分页信息 |
| | |
| | | @PostMapping("/submit") |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改资讯信息", notes = "传入article") |
| | | public R submit(@RequestBody ArticleVO article) { |
| | | public R submit(@RequestBody Article article) { |
| | | boolean flag = false; |
| | | if (null == article.getId()) { |
| | | flag = true; |
| | | if (null == article.getCreateTime()) { |
| | | article.setCreateTime(new Date()); |
| | | } |
| | | } |
| | | article.setUpdateTime(new Date()); |
| | | return R.status(articleService.saveOrUpdate(article)); |
| | | boolean saveOrUpdate = articleService.saveOrUpdate(article); |
| | | if (saveOrUpdate){ |
| | | EsParam esParam = new EsParam(); |
| | | esParam.setIndexName("test"); |
| | | esParam.setTableName("jczz_article"); |
| | | if (flag) { |
| | | // 更新到es库 |
| | | elasticsearchDocumentService.addArticle(esParam, article); |
| | | }else { |
| | | esParam.setTableId(article.getId().toString()); |
| | | // 更新 |
| | | elasticsearchDocumentService.update(esParam,article); |
| | | } |
| | | } |
| | | return R.status(saveOrUpdate); |
| | | } |
| | | |
| | | |