|
@@ -0,0 +1,122 @@
|
|
|
+package com.idiot.operationbackend.controller.interactive;
|
|
|
+
|
|
|
+import com.idiot.operationbackend.controller.AuthController;
|
|
|
+import com.idiot.operationbackend.entity.*;
|
|
|
+import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
+import com.idiot.operationbackend.service.facade.ArticlesService;
|
|
|
+import com.idiot.operationbackend.service.facade.FollowReplyService;
|
|
|
+import com.idiot.operationbackend.service.facade.MaterialService;
|
|
|
+import com.idiot.operationbackend.support.JsonResult;
|
|
|
+import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wang xiao
|
|
|
+ * @date Created in 17:30 2020/9/21
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/followReply")
|
|
|
+@Api(value = "FollowReplyController", tags ="被关注回复")
|
|
|
+public class FollowReplyController {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(AuthController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountService accountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FollowReplyService followReplyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MaterialService materialService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ArticlesService articlesService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping
|
|
|
+ @ApiOperation(value = "查询智能回复列表")
|
|
|
+ public ResponseEntity<JsonResult<List<FollowReply>>> getAccountPushList(@RequestHeader String token) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}查询推送消息列表",userId);
|
|
|
+ List<Account> accounts = accountService.queryAccountByUserId(userId);
|
|
|
+ List<String> accIds = accounts.stream().map(Account::getId).collect(Collectors.toList());
|
|
|
+ List<FollowReply> pushList = followReplyService.queryFollowReply(accIds);
|
|
|
+ List<FollowReply> result = new ArrayList<>(accIds.size());
|
|
|
+ for (Account account : accounts) {
|
|
|
+ FollowReply var = pushList.stream()
|
|
|
+ .filter(e->account.getId().equals(e.getAccountId()))
|
|
|
+ .findAny()
|
|
|
+ .orElseGet(()->nonReply(account));
|
|
|
+ result.add(var);
|
|
|
+ }
|
|
|
+ return ResponseEntity.ok(JsonResult.success(result));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ @ApiOperation(value = "查看被关注回复详情")
|
|
|
+ public ResponseEntity<JsonResult<FollowReply>> getFollowReply(@RequestHeader String token,
|
|
|
+ @PathVariable String id,
|
|
|
+ @RequestParam String accountId) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}查看被关注回复详情",userId);
|
|
|
+
|
|
|
+ FollowReply followReply = followReplyService.getById(id);
|
|
|
+ if (Objects.isNull(followReply)){
|
|
|
+ Account account = accountService.getById(accountId);
|
|
|
+ followReply = nonReply(account);
|
|
|
+ }
|
|
|
+ queryContents(followReply);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(followReply));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping
|
|
|
+ @ApiOperation(value = "修改被关注回复")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> upFollowReply(@RequestHeader String token,
|
|
|
+ @RequestBody FollowReply reply) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}修改被关注回复",userId);
|
|
|
+ boolean addResult = followReplyService.saveOrUpdate(reply);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(addResult));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private FollowReply nonReply (Account account){
|
|
|
+ FollowReply reply = new FollowReply();
|
|
|
+ reply.setNikeName(account.getNickName());
|
|
|
+ reply.setHeadImage(account.getHeadImg());
|
|
|
+ reply.setEnable(false);
|
|
|
+ reply.setSetUp(false);
|
|
|
+ return reply;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryContents(FollowReply reply) {
|
|
|
+ String artIds = reply.getArticlesIds();
|
|
|
+ List<Object> content = new ArrayList<>();
|
|
|
+ List<Articles> articles = articlesService.queryArticlesByIds(artIds);
|
|
|
+ if (Objects.nonNull(articles)) {
|
|
|
+ content.addAll(articles);
|
|
|
+ }
|
|
|
+ String matIds = reply.getMaterialIds();
|
|
|
+ List<Material> materials = materialService.queryByIds(matIds);
|
|
|
+ if (Objects.nonNull(materials)) {
|
|
|
+ content.addAll(materials);
|
|
|
+ }
|
|
|
+ reply.setContents(content);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|