12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.fdkankan.manage.controller;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.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(ResultCode.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(ResultCode.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(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- mailTemplateService.updateById(mailTemplate);
- return ResultData.ok();
- }
- @PostMapping("/delete")
- public ResultData delete(@RequestBody MailTemplate mailTemplate){
- if(mailTemplate.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- mailTemplateService.removeById(mailTemplate.getId());
- return ResultData.ok();
- }
- }
|