邮箱账号管理 TODO意见修改
parent
50f7af00e9
commit
54ad304514
@ -0,0 +1,85 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.mail;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||
import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
|
||||
@Api(tags = "管理后台 - 邮件模板")
|
||||
@RestController
|
||||
@RequestMapping("/system/mail-account")
|
||||
public class MailAccountController {
|
||||
@Resource
|
||||
private MailAccountService mailAccountService;
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建邮箱账号")
|
||||
@PreAuthorize("@ss.hasPermission('system:mail-account:create')")
|
||||
public CommonResult<Long> createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) {
|
||||
return success(mailAccountService.create(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改邮箱账号")
|
||||
@PreAuthorize("@ss.hasPermission('system:mail-account:update')")
|
||||
public CommonResult<Boolean> updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) {
|
||||
mailAccountService.update(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除邮箱账号")
|
||||
@PreAuthorize("@ss.hasPermission('system:mail-account:delete')")
|
||||
public CommonResult<Boolean> deleteMailAccount(@Valid @RequestBody Long id) {
|
||||
mailAccountService.delete(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得邮箱账号")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:mail-account:get')")
|
||||
public CommonResult<MailAccountBaseVO> getMailAccount(@RequestParam("id") Long id) {
|
||||
MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id);
|
||||
return success(MailAccountConvert.INSTANCE.convert(mailAccountDO));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得邮箱账号分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:mail-account:query')")
|
||||
public CommonResult<PageResult<MailAccountBaseVO>> getSmsChannelPage(@Valid MailAccountPageReqVO pageReqVO) {
|
||||
PageResult<MailAccountDO> pageResult = mailAccountService.getMailAccountPage(pageReqVO);
|
||||
return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获得邮箱账号精简列表")
|
||||
public CommonResult<List<MailAccountBaseVO>> getSimpleSmsChannels() {
|
||||
List<MailAccountDO> list = mailAccountService.getMailAccountList();
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(MailAccountDO::getId));
|
||||
return success(MailAccountConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
}
|
||||
9
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java → yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java
9
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/SystemMailAccountBaseVO.java → yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java
@ -0,0 +1,8 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MailAccountCreateReqVO extends MailAccountBaseVO{
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MailAccountPageReqVO extends PageParam {
|
||||
@ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com")
|
||||
private String from;
|
||||
|
||||
@ApiModelProperty(value = "用户名" , required = true , example = "yudao")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty(value = "密码" , required = true , example = "123456")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "网站" , required = true , example = "www.iocoder.cn")
|
||||
private String host;
|
||||
|
||||
@ApiModelProperty(value = "端口" , required = true , example = "80")
|
||||
private String port;
|
||||
|
||||
@ApiModelProperty(value = "是否开启ssl" , required = true , example = "2")
|
||||
private Boolean sslEnable;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MailAccountUpdateReqVO extends MailAccountBaseVO{
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.system.convert.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountBaseVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface MailAccountConvert {
|
||||
MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class);
|
||||
|
||||
MailAccountDO convert (MailAccountBaseVO mailAccountBaseVO);
|
||||
|
||||
MailAccountBaseVO convert (MailAccountDO mailAccountDO);
|
||||
|
||||
PageResult<MailAccountBaseVO> convertPage(PageResult<MailAccountDO> pageResult);
|
||||
|
||||
List<MailAccountBaseVO> convertList02(List<MailAccountDO> list);
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.convert.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SystemMailAccountConvert {
|
||||
SystemMailAccountConvert INSTANCE = Mappers.getMapper(SystemMailAccountConvert.class);
|
||||
|
||||
SystemMailAccountDO convert (SystemMailAccountBaseVO systemMailAccountBaseVO);
|
||||
|
||||
SystemMailAccountBaseVO convert (SystemMailAccountDO systemMailAccountDO);
|
||||
|
||||
PageResult<SystemMailAccountBaseVO> convertPage(PageResult<SystemMailAccountDO> pageResult);
|
||||
|
||||
List<SystemMailAccountBaseVO> convertList02(List<SystemMailAccountDO> list);
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MailAccountMapper extends BaseMapperX<MailAccountDO> {
|
||||
|
||||
default PageResult<MailAccountDO> selectPage(MailAccountPageReqVO pageReqVO) {
|
||||
return selectPage(pageReqVO, new QueryWrapperX<MailAccountDO>()
|
||||
.likeIfPresent("form" , pageReqVO.getFrom())
|
||||
.likeIfPresent("host" , pageReqVO.getHost())
|
||||
.likeIfPresent("username" , pageReqVO.getUsername())
|
||||
.eqIfPresent("password" , pageReqVO.getPassword())
|
||||
.eqIfPresent("port" , pageReqVO.getPort())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
// TODO @ジョイイ: Mapper 一般不用注释,因为用途不大
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author wangjingyi
|
||||
* @since 2022-03-21
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemMailAccountMapper extends BaseMapperX<SystemMailAccountDO> {
|
||||
|
||||
default PageResult<SystemMailAccountDO> selectPage(PageParam pageParam) {
|
||||
return selectPage(pageParam, new QueryWrapperX<SystemMailAccountDO>());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.service.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮箱账号 Service 接口
|
||||
* </p>
|
||||
*
|
||||
* @author wangjingyi
|
||||
* @since 2022-03-21
|
||||
*/
|
||||
public interface MailAccountService {
|
||||
|
||||
Long create(MailAccountCreateReqVO createReqVO);
|
||||
|
||||
void update(MailAccountUpdateReqVO updateReqVO);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
MailAccountDO getMailAccount(Long id);
|
||||
|
||||
PageResult<MailAccountDO> getMailAccountPage(MailAccountPageReqVO pageReqVO);
|
||||
|
||||
List<MailAccountDO> getMailAccountList();
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.service.mail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.SystemMailAccountBaseVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.SystemMailAccountDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO @ジョイイ:类注释,应该是 邮箱账号 Service 接口
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wangjingyi
|
||||
* @since 2022-03-21
|
||||
*/
|
||||
public interface SystemMailAccountService {
|
||||
|
||||
Long create(SystemMailAccountBaseVO baseVO);
|
||||
|
||||
String update(SystemMailAccountBaseVO baseVO);
|
||||
|
||||
String delete(SystemMailAccountBaseVO baseVO);
|
||||
|
||||
SystemMailAccountDO getMailAccount(Long id);
|
||||
|
||||
PageResult<SystemMailAccountDO> getMailAccountPage(PageParam pageParam);
|
||||
|
||||
List<SystemMailAccountDO> getMailAccountList();
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package cn.iocoder.yudao.module.system.service.mail.impl;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
|
||||
import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮箱账号 Service 实现类
|
||||
* </p>
|
||||
*
|
||||
* @author wangjingyi
|
||||
* @since 2022-03-21
|
||||
*/
|
||||
@Service
|
||||
public class MailAccountServiceImpl implements MailAccountService {
|
||||
|
||||
@Resource
|
||||
private MailAccountMapper mailAccountMapper;
|
||||
|
||||
@Override
|
||||
public Long create(MailAccountCreateReqVO createReqVO) {
|
||||
// username 要校验唯一
|
||||
Map<String , String> map = new HashMap<>();
|
||||
map.put("username" , createReqVO.getUsername());
|
||||
this.validateMailAccountOnly(map);
|
||||
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO);
|
||||
mailAccountMapper.insert(mailAccountDO);
|
||||
return mailAccountDO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(MailAccountUpdateReqVO updateReqVO) {
|
||||
// username 要校验唯一
|
||||
Map<String , String> map = new HashMap<>();
|
||||
map.put("username" , updateReqVO.getUsername());
|
||||
this.validateMailAccountOnly(map);
|
||||
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
|
||||
// 校验是否存在
|
||||
this.validateMailAccountExists(mailAccountDO.getId());
|
||||
mailAccountMapper.updateById(mailAccountDO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
// 校验是否存在
|
||||
this.validateMailAccountExists(id);
|
||||
mailAccountMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailAccountDO getMailAccount(Long id) {
|
||||
return mailAccountMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MailAccountDO> getMailAccountPage(MailAccountPageReqVO pageReqVO) {
|
||||
return mailAccountMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MailAccountDO> getMailAccountList() {
|
||||
return mailAccountMapper.selectList();
|
||||
}
|
||||
|
||||
private void validateMailAccountExists(Long id) {
|
||||
if (mailAccountMapper.selectById(id) == null) {
|
||||
throw exception(MAIL_ACCOUNT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateMailAccountOnly(Map params){
|
||||
QueryWrapper queryWrapper = new QueryWrapper<MailAccountDO>();
|
||||
params.forEach((k , v)->{
|
||||
queryWrapper.like(k , v);
|
||||
});
|
||||
if (mailAccountMapper.selectOne(queryWrapper) != null) {
|
||||
throw exception(MAIL_ACCOUNT_EXISTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue