提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.service.mail; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
|
4 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
5 |
import com.iailab.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; |
|
6 |
import com.iailab.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; |
|
7 |
import com.iailab.module.system.dal.dataobject.mail.MailAccountDO; |
|
8 |
import com.iailab.module.system.dal.mysql.mail.MailAccountMapper; |
|
9 |
import com.iailab.module.system.dal.redis.RedisKeyConstants; |
|
10 |
import lombok.extern.slf4j.Slf4j; |
|
11 |
import org.springframework.cache.annotation.CacheEvict; |
|
12 |
import org.springframework.cache.annotation.Cacheable; |
|
13 |
import org.springframework.stereotype.Service; |
|
14 |
import org.springframework.validation.annotation.Validated; |
|
15 |
|
|
16 |
import javax.annotation.Resource; |
|
17 |
import java.util.List; |
|
18 |
|
|
19 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
20 |
import static com.iailab.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; |
|
21 |
import static com.iailab.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS; |
|
22 |
|
|
23 |
/** |
|
24 |
* 邮箱账号 Service 实现类 |
|
25 |
* |
|
26 |
* @author wangjingyi |
|
27 |
* @since 2022-03-21 |
|
28 |
*/ |
|
29 |
@Service |
|
30 |
@Validated |
|
31 |
@Slf4j |
|
32 |
public class MailAccountServiceImpl implements MailAccountService { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private MailAccountMapper mailAccountMapper; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private MailTemplateService mailTemplateService; |
|
39 |
|
|
40 |
@Override |
|
41 |
public Long createMailAccount(MailAccountSaveReqVO createReqVO) { |
|
42 |
MailAccountDO account = BeanUtils.toBean(createReqVO, MailAccountDO.class); |
|
43 |
mailAccountMapper.insert(account); |
|
44 |
return account.getId(); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
@CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#updateReqVO.id") |
|
49 |
public void updateMailAccount(MailAccountSaveReqVO updateReqVO) { |
|
50 |
// 校验是否存在 |
|
51 |
validateMailAccountExists(updateReqVO.getId()); |
|
52 |
|
|
53 |
// 更新 |
|
54 |
MailAccountDO updateObj = BeanUtils.toBean(updateReqVO, MailAccountDO.class); |
|
55 |
mailAccountMapper.updateById(updateObj); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
@CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#id") |
|
60 |
public void deleteMailAccount(Long id) { |
|
61 |
// 校验是否存在账号 |
|
62 |
validateMailAccountExists(id); |
|
63 |
// 校验是否存在关联模版 |
|
64 |
if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) { |
|
65 |
throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); |
|
66 |
} |
|
67 |
|
|
68 |
// 删除 |
|
69 |
mailAccountMapper.deleteById(id); |
|
70 |
} |
|
71 |
|
|
72 |
private void validateMailAccountExists(Long id) { |
|
73 |
if (mailAccountMapper.selectById(id) == null) { |
|
74 |
throw exception(MAIL_ACCOUNT_NOT_EXISTS); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public MailAccountDO getMailAccount(Long id) { |
|
80 |
return mailAccountMapper.selectById(id); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
@Cacheable(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#id", unless = "#result == null") |
|
85 |
public MailAccountDO getMailAccountFromCache(Long id) { |
|
86 |
return getMailAccount(id); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public PageResult<MailAccountDO> getMailAccountPage(MailAccountPageReqVO pageReqVO) { |
|
91 |
return mailAccountMapper.selectPage(pageReqVO); |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public List<MailAccountDO> getMailAccountList() { |
|
96 |
return mailAccountMapper.selectList(); |
|
97 |
} |
|
98 |
|
|
99 |
} |