南昌市物联网技防平台-公安版
Administrator
2021-06-11 7a91c739851b8141dbbef8529bb14283de601a32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package org.springblade.jfpt.article.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.jfpt.article.entity.Article;
import org.springblade.jfpt.article.service.ArticleService;
import org.springblade.jfpt.article.vo.ArticleVo;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
 
/**
 * @author zhongrj
 * @title 资讯控制层
 */
@RestController
@AllArgsConstructor
@RequestMapping("/article/article")
public class ArticleController {
 
    private final ArticleService articleService;
 
 
    /**
     *
     * 查询资讯分页信息
     * @param response
     * @param article 资讯对象
     * @param query 查询参数
     * @return
     */
    @GetMapping("/page")
    public R<IPage<Article>> page(HttpServletResponse response, ArticleVo article, Query query){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Allow-Credentials","true");
        return R.data(articleService.selectArticlePage(Condition.getPage(query),article));
    }
 
    /**
     * 资讯详情
     * @param article 资讯查询对象
     * @param response
     */
    @GetMapping("/detail")
    public R<Article> detail(Article article, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Allow-Credentials","true");
        Article detail = articleService.getOne(Condition.getQueryWrapper(article));
        return R.data(detail);
    }
 
    /**
     * 新增资讯信息
     * @param article 资讯对象
     */
    @PostMapping("/save")
    public R save(@Valid Article article) {
        return R.status(articleService.save(article));
    }
 
    /**
     * 修改资讯信息
     * @param article 资讯对象
     */
    @PostMapping("/update")
    public R update(@Valid @RequestBody Article article) {
        return R.status(articleService.updateById(article));
    }
 
    /**
     * 新增或修改资讯信息
     * @param article 资讯对象信息
     */
    @PostMapping("/submit")
    public R submit(@Valid @RequestBody Article article) {
        //创建时间
        if (null == article.getId()) {
            article.setCreateTime(new Date());
        }
        article.setUpdateTime(new Date());
        return R.status(articleService.saveOrUpdate(article));
    }
 
 
    /**
     * 删除资讯信息
     * @param ids 资讯主键id,id集合
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(articleService.removeByIds(Func.toLongList(ids)));
    }
}