洪城义警-正式版后台
tangzy
2022-01-12 e992ea5f4c3d6f027b1030d1898638dbb8f9954b
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package org.springblade.modules.article.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
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.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.article.entity.Article;
import org.springblade.modules.article.service.ArticleService;
import org.springblade.modules.article.vo.ArticleVo;
import org.springblade.modules.mgcx.entity.Mgcx;
import org.springblade.modules.mgcx.service.IMgcxService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.words.DemoApplication;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author zhongrj
 * @title 资讯控制层
 */
@RestController
@AllArgsConstructor
@RequestMapping("/article/article")
public class ArticleController {
 
    private final ArticleService articleService;
    private final IUserService userService;
    private final IMgcxService mgcxService;
 
    /**
     *
     * 查询资讯分页信息
     * @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 response
     * @param article 资讯对象
     * @param query 查询参数
     * @return
     */
    @GetMapping("/pageWords")
    public R<IPage<Article>> pageWords(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.pageWords(Condition.getPage(query),article));
    }
 
    /**
     *
     * 查询资讯分页信息(角色权限)
     * @param response
     * @param article 资讯对象
     * @param query 查询参数
     * @return
     */
    @GetMapping("/pageDate")
    public R<IPage<Article>> pageDate(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.pageDate(Condition.getPage(query),article));
    }
 
    @GetMapping("/pageCollectList")
    public R<IPage<Article>> pageCollectList(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.pageCollectList(Condition.getPage(query),article));
    }
 
    /**
     *
     * 查询资讯分页信息(角色权限)附带点赞评论数
     * @param response
     * @param article 资讯对象
     * @param query 查询参数
     * @return
     */
    @GetMapping("/pageLikes")
    public R<IPage<Article>> pageLikes(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.pageLikes(Condition.getPage(query),article));
    }
 
    /**
     * 查询已收藏的资讯
     */
    @GetMapping("/pageCollect")
    public R<IPage<Article>> pageCollect(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.pageCollect(Condition.getPage(query),article));
    }
 
 
    /**
     * 资讯详情
     * @param article 资讯查询对象
     * @param response
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入articleoy")
    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")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入article")
    public R save(@Valid Article article) {
        return R.status(articleService.save(article));
    }
 
    /**
     * 修改资讯信息
     * @param article 资讯对象
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入article")
    public R update(@Valid @RequestBody Article article) {
        return R.status(articleService.updateById(article));
    }
 
    /**
     * 新增或修改资讯信息
     * @param article 资讯对象信息
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入article")
    public R submit(@Valid @RequestBody ArticleVo article) {
        if (null==article.getId()){
            if (null==article.getCreateTime()){
                article.setCreateTime(new Date());
            }
        }
        //默认为正常
        article.setIswords("0");
 
        if (article.getContent() != null && article.getContent() != ""){
            Map<String,String> content = new HashMap();
            content = DemoApplication.interceptWords(article.getContent());
            System.out.println(content.get("iswords"));
            if (content.get("iswords") == "true"){
                article.setContent(content.get("content"));
                article.setIswords("1");
                article.setWordsContent(content.get("words"));
                //获取登录信息
                String userid = article.getUserid();
                User user = new User();
                user.setId(Long.parseLong(userid));
                User detail = userService.getOne(Condition.getQueryWrapper(user));
                Mgcx mgcx = new Mgcx();
                mgcx.setUid(userid);
                Mgcx one = mgcxService.getOne(Condition.getQueryWrapper(mgcx));
                if (one==null){
                    mgcx.setUid(userid);
                    mgcx.setPhone(detail.getPhone());
                    mgcx.setCardid(detail.getCardid());
                    mgcx.setCountx(10);
                    mgcx.setCounts(1);
                    mgcxService.save(mgcx);
                }
                else {
                    Integer counts = one.getCounts();
                    int i = counts + 1;
                    one.setCounts(i);
                    mgcxService.updateById(one);
                }
 
            }
 
        }
        article.setUpdateTime(new Date());
        return R.status(articleService.saveOrUpdate(article));
    }
 
 
    /**
     * 删除资讯信息
     * @param ids 资讯主键id,id集合
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(articleService.removeByIds(Func.toLongList(ids)));
    }
 
    /**
     * 批量修改评论区状态
     */
    @PostMapping("/upcomment")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,String type) {
        String[] split = ids.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        return R.status(articleService.upcomment(code,type));
    }
}