|
@@ -2,8 +2,10 @@ package com.idiot.operationbackend.controller.articles;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.idiot.operationbackend.entity.Articles;
|
|
|
+import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
import com.idiot.operationbackend.service.facade.ArticlesService;
|
|
|
import com.idiot.operationbackend.service.facade.WeChatService;
|
|
|
+import com.idiot.operationbackend.support.CustomException;
|
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -24,7 +26,7 @@ import javax.validation.Valid;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/articles")
|
|
|
-@Api(value = "ArticlesController", tags ="图文")
|
|
|
+@Api(value = "ArticlesController", tags ="图文文章")
|
|
|
public class ArticlesController {
|
|
|
|
|
|
|
|
@@ -36,11 +38,13 @@ public class ArticlesController {
|
|
|
@Autowired
|
|
|
private WeChatService weChatService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AccountService accountService;
|
|
|
|
|
|
- @GetMapping("/{accountId}")
|
|
|
+ @GetMapping
|
|
|
@ApiOperation(value = "查询公众号图文")
|
|
|
public ResponseEntity<JsonResult<Page<Articles>>> ArticlesPage (@RequestHeader String token,
|
|
|
- @PathVariable String accountId,
|
|
|
+ @RequestParam String accountId,
|
|
|
@RequestParam int page){
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
logger.info("用户:{}查询微信公众号{}图文-------------start",userId,accountId);
|
|
@@ -49,18 +53,73 @@ public class ArticlesController {
|
|
|
return ResponseEntity.ok(JsonResult.success(materialPage));
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/{accountId}")
|
|
|
- @ApiOperation(value = "新增公众号图文")
|
|
|
- public ResponseEntity<JsonResult<Boolean>> addArticles (@RequestHeader String token,
|
|
|
- @PathVariable String accountId,
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "新增并发布公众号图文")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> addAndEditArticles (@RequestHeader String token,
|
|
|
+ @RequestParam String accountId,
|
|
|
@RequestBody @Valid Articles articles){
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
- logger.info("用户:{}新增微信公众号{}图文-------------start",userId,accountId);
|
|
|
+ logger.info("用户:{}新增并发布微信公众号{}图文-------------start",userId,accountId);
|
|
|
+ boolean enable = accountService.queryAccountByUserId(userId).stream()
|
|
|
+ .anyMatch(e->accountId.equals(e.getId()));
|
|
|
+ if (!enable) {
|
|
|
+ throw new CustomException(500,"你没有权限操作该公众号");
|
|
|
+ }
|
|
|
String wxJson = weChatService.addNews(articles,accountId);
|
|
|
Boolean addResult = articlesService.addArticles(wxJson,articles);
|
|
|
+ logger.info("用户:{}新增并发布微信公众号{}图文-------------end,结果:{}",userId,accountId,addResult);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(addResult));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/edition")
|
|
|
+ @ApiOperation(value = "发布公众号图文")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> editingArticles (@RequestHeader String token,
|
|
|
+ @RequestParam String accountId,
|
|
|
+ @RequestParam String id){
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}发布微信公众号{}图文-------------start",userId,accountId);
|
|
|
+ boolean enable = accountService.queryAccountByUserId(userId).stream()
|
|
|
+ .anyMatch(e->accountId.equals(e.getId()));
|
|
|
+ if (!enable) {
|
|
|
+ throw new CustomException(500,"你没有权限操作该公众号");
|
|
|
+ }
|
|
|
+ Articles articles = articlesService.getById(id);
|
|
|
+ String wxJson = weChatService.addNews(articles,accountId);
|
|
|
+ Boolean addResult = articlesService.upArticles(wxJson,articles);
|
|
|
+ logger.info("用户:{}发布微信公众号{}图文-------------end,结果:{}",userId,accountId,addResult);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(addResult));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/new")
|
|
|
+ @ApiOperation(value = "新增公众号图文")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> saveArticles (@RequestHeader String token,
|
|
|
+ @RequestParam String accountId,
|
|
|
+ @RequestBody @Valid Articles articles){
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}新增微信公众号{}图文-------------start",userId,accountId);
|
|
|
+ boolean enable = accountService.queryAccountByUserId(userId).stream()
|
|
|
+ .anyMatch(e->accountId.equals(e.getId()));
|
|
|
+ if (!enable) {
|
|
|
+ throw new CustomException(500,"你没有权限操作该公众号");
|
|
|
+ }
|
|
|
+ Boolean addResult = articlesService.save(articles);
|
|
|
logger.info("用户:{}新增微信公众号{}图文-------------end,结果:{}",userId,accountId,addResult);
|
|
|
return ResponseEntity.ok(JsonResult.success(addResult));
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @GetMapping("/rank")
|
|
|
+ @ApiOperation(value = "图文排行榜 2小时更新一次")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> rankArticles (@RequestHeader String token){
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}查询图文排行榜-------------start",userId);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(false));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|