|
@@ -3,8 +3,12 @@ package com.idiot.operationbackend.controller.interactive;
|
|
import com.idiot.operationbackend.controller.AuthController;
|
|
import com.idiot.operationbackend.controller.AuthController;
|
|
import com.idiot.operationbackend.entity.Account;
|
|
import com.idiot.operationbackend.entity.Account;
|
|
import com.idiot.operationbackend.entity.AccountPush;
|
|
import com.idiot.operationbackend.entity.AccountPush;
|
|
|
|
+import com.idiot.operationbackend.entity.Articles;
|
|
|
|
+import com.idiot.operationbackend.entity.Material;
|
|
import com.idiot.operationbackend.service.facade.AccountPushService;
|
|
import com.idiot.operationbackend.service.facade.AccountPushService;
|
|
import com.idiot.operationbackend.service.facade.AccountService;
|
|
import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
|
+import com.idiot.operationbackend.service.facade.ArticlesService;
|
|
|
|
+import com.idiot.operationbackend.service.facade.MaterialService;
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -40,6 +45,13 @@ public class PushMsgController {
|
|
@Autowired
|
|
@Autowired
|
|
private AccountPushService pushService;
|
|
private AccountPushService pushService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MaterialService materialService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ArticlesService articlesService;
|
|
|
|
+
|
|
|
|
+
|
|
@GetMapping
|
|
@GetMapping
|
|
@ApiOperation(value = "查询推送列表")
|
|
@ApiOperation(value = "查询推送列表")
|
|
public ResponseEntity<JsonResult<List<AccountPush>>> getAccountPushList(@RequestHeader String token) {
|
|
public ResponseEntity<JsonResult<List<AccountPush>>> getAccountPushList(@RequestHeader String token) {
|
|
@@ -59,35 +71,58 @@ public class PushMsgController {
|
|
return ResponseEntity.ok(JsonResult.success(result));
|
|
return ResponseEntity.ok(JsonResult.success(result));
|
|
}
|
|
}
|
|
|
|
|
|
- @PostMapping
|
|
|
|
- @ApiOperation(value = "新增智能推送")
|
|
|
|
- public ResponseEntity<JsonResult<List<AccountPush>>> addAccountPush(@RequestHeader String token,
|
|
|
|
- @RequestBody AccountPush push) {
|
|
|
|
|
|
+ @PutMapping
|
|
|
|
+ @ApiOperation(value = "修改智能推送")
|
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> upAccountPush(@RequestHeader String token,
|
|
|
|
+ @RequestBody AccountPush push) {
|
|
String userId = JwtTokenUtil.getUserId(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<AccountPush> pushList = pushService.queryAccountPush(accIds);
|
|
|
|
- List<AccountPush> result = new ArrayList<>(accIds.size());
|
|
|
|
- for (Account account : accounts) {
|
|
|
|
- AccountPush var = pushList.stream()
|
|
|
|
- .filter(e->account.getId().equals(e.getAccountId()))
|
|
|
|
- .findAny()
|
|
|
|
- .orElseGet(()->nonPush(account));
|
|
|
|
- result.add(var);
|
|
|
|
- }
|
|
|
|
- return ResponseEntity.ok(JsonResult.success(result));
|
|
|
|
|
|
+ logger.info("用户:{}修改推送消息列表",userId);
|
|
|
|
+ boolean addResult = pushService.saveOrUpdate(push);
|
|
|
|
+ return ResponseEntity.ok(JsonResult.success(addResult));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @GetMapping("/{id}")
|
|
|
|
+ @ApiOperation(value = "查看推送详情")
|
|
|
|
+ public ResponseEntity<JsonResult<AccountPush>> getAccountPush(@RequestHeader String token,
|
|
|
|
+ @PathVariable String id,
|
|
|
|
+ @RequestParam String accountId) {
|
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
|
+ logger.info("用户:{}查看推送消息详情",userId);
|
|
|
|
|
|
|
|
+ AccountPush accountPush = pushService.getById(id);
|
|
|
|
+ if (Objects.isNull(accountPush)){
|
|
|
|
+ Account account = accountService.getById(accountId);
|
|
|
|
+ accountPush = nonPush(account);
|
|
|
|
+ }
|
|
|
|
+ queryContents(accountPush);
|
|
|
|
+ return ResponseEntity.ok(JsonResult.success(accountPush));
|
|
|
|
+ }
|
|
|
|
|
|
private AccountPush nonPush (Account account){
|
|
private AccountPush nonPush (Account account){
|
|
AccountPush push = new AccountPush();
|
|
AccountPush push = new AccountPush();
|
|
push.setNikeName(account.getNickName());
|
|
push.setNikeName(account.getNickName());
|
|
push.setHeadImage(account.getHeadImg());
|
|
push.setHeadImage(account.getHeadImg());
|
|
|
|
+ push.setEnable(false);
|
|
return push;
|
|
return push;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void queryContents(AccountPush accountPush) {
|
|
|
|
+ String artIds = accountPush.getArticlesIds();
|
|
|
|
+ String matIds = accountPush.getMaterialIds();
|
|
|
|
+ List<Object> content = new ArrayList<>();
|
|
|
|
+ List<Articles> articles = articlesService.queryArticlesByIds(artIds);
|
|
|
|
+ List<Material> materials = materialService.queryByIds(matIds);
|
|
|
|
+ if (Objects.nonNull(articles)) {
|
|
|
|
+ content.addAll(articles);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(materials)) {
|
|
|
|
+ content.addAll(materials);
|
|
|
|
+ }
|
|
|
|
+ accountPush.setContents(content);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|