|
|
@@ -37,13 +37,20 @@ public class ReceiverController {
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
@PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public String saveReceiver(@Validated NotifyReceiver notifyReceiver) {
|
|
|
- String type = notifyReceiver.getType();
|
|
|
- NotifyReceiver notifyReceiver1 = notifyReceiverRepository.findByType(type);
|
|
|
+ String name = notifyReceiver.getName();
|
|
|
+ NotifyReceiver notifyReceiver1 = notifyReceiverRepository.findByName(name);
|
|
|
if (notifyReceiver1 != null) {
|
|
|
- String errMsg = String.format("NotifyType %s already exist", type);
|
|
|
+ String errMsg = String.format("NotifyReceiver %s exist", name);
|
|
|
return WebResult.failWithMsg(errMsg);
|
|
|
}
|
|
|
|
|
|
+ /*String type = notifyReceiver.getType();
|
|
|
+ NotifyReceiver notifyReceiver1 = notifyReceiverRepository.findByType(type);
|
|
|
+ if (notifyReceiver1 != null) {
|
|
|
+ String errMsg = String.format("NotifyType %s already exist", type);
|
|
|
+ return WebResult.failWithMsg(errMsg);
|
|
|
+ }*/
|
|
|
+ String type = notifyReceiver.getType();
|
|
|
if (type.equals(NotifyType.email.name())) {
|
|
|
List<EmailAccount> list = emailAccountRepository.findAll();
|
|
|
if (list.isEmpty()) {
|
|
|
@@ -77,6 +84,23 @@ public class ReceiverController {
|
|
|
return WebResult.success();
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "更新通知接收")
|
|
|
+ @PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
+ @PostMapping(value = "/default/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String updateDefaultReceiver(@PathVariable("name") String name) {
|
|
|
+ NotifyReceiver notifyReceiver1 = notifyReceiverRepository.findByName(name);
|
|
|
+ if (notifyReceiver1 == null || notifyReceiver1.getSetdefault()) {
|
|
|
+ String errMsg = String.format("NotifyReceiver %s not exist or it is default receiver", name);
|
|
|
+ return WebResult.failWithMsg(errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ NotifyReceiver notifyReceiver2 = notifyReceiverRepository.findByTypeAndSetdefaultIsTrue(notifyReceiver1.getType());
|
|
|
+ notifyReceiver1.setSetdefault(true);
|
|
|
+ notifyReceiver2.setSetdefault(false);
|
|
|
+ notifyReceiverRepository.saveAll(List.of(notifyReceiver1, notifyReceiver2));
|
|
|
+ return WebResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "删除通知接收")
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
@DeleteMapping(value = "/delete/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
|