소스 검색

邮件模板管理

lyhzzz 2 년 전
부모
커밋
0561c99f2a

+ 64 - 0
src/main/java/com/fdkankan/manage/controller/EmailTemplateController.java

@@ -0,0 +1,64 @@
+package com.fdkankan.manage.controller;
+
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.manage.entity.MailTemplate;
+import com.fdkankan.manage.service.IMailTemplateService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("/service/manage")
+public class EmailTemplateController {
+
+    @Autowired
+    IMailTemplateService mailTemplateService;
+
+    @PostMapping("/list")
+    public ResultData list(){
+        return ResultData.ok(mailTemplateService.list());
+    }
+    @GetMapping("/getInfo")
+    public ResultData getInfo(@RequestParam(required = false) Integer mailTemplateId){
+        if(mailTemplateId == null){
+            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        return ResultData.ok(mailTemplateService.getById(mailTemplateId));
+    }
+
+    /**
+     * sendMail         4Dkankan@4dage.com
+     * sendPassword     6996790AAaa
+     * sendHost         smtp.exmail.qq.com
+     */
+    @PostMapping("/save")
+    public ResultData save(@RequestBody MailTemplate mailTemplate){
+        if(StringUtils.isBlank(mailTemplate.getSendMail()) || StringUtils.isBlank(mailTemplate.getSendPassword())
+            || StringUtils.isBlank(mailTemplate.getSubject()) || StringUtils.isBlank(mailTemplate.getMsg())){
+            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        mailTemplate.setSendHost("smtp.exmail.qq.com");
+        mailTemplateService.save(mailTemplate);
+        return ResultData.ok();
+    }
+
+    @PostMapping("/update")
+    public ResultData update(@RequestBody MailTemplate mailTemplate){
+        if(mailTemplate.getId() == null ){
+            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        mailTemplateService.updateById(mailTemplate);
+        return ResultData.ok();
+    }
+
+    @PostMapping("/delete")
+    public ResultData delete(@RequestBody MailTemplate mailTemplate){
+        if(mailTemplate.getId() == null){
+            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        mailTemplateService.removeById(mailTemplate.getId());
+        return ResultData.ok();
+    }
+}

+ 1 - 1
src/main/java/com/fdkankan/manage/entity/MailTemplate.java

@@ -35,7 +35,7 @@ public class MailTemplate implements Serializable {
     private String sendMail;
 
     /**
-     * 发件人邮箱
+     * 发件人邮箱授权
      */
     @TableField("send_password")
     private String sendPassword;

+ 9 - 0
src/main/java/com/fdkankan/manage/exception/GlobalExceptionHandler.java

@@ -32,4 +32,13 @@ public class GlobalExceptionHandler {
         log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
         return ResultData.error(e.getCode(), e.getMessage());
     }
+    /**
+     * 处理业务异常
+     */
+    @ResponseBody
+    @ExceptionHandler(value = com.fdkankan.common.exception.BusinessException.class)
+    public ResultData businessExceptionHandler2(com.fdkankan.common.exception.BusinessException e) {
+        log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
+        return ResultData.error(e.getCode(), e.getMessage());
+    }
 }