tj
2025-06-05 2d549a04870d1315868a7cf19952b64e8071e711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.cloudroam.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudroam.bo.EmailSmtpSettingBO;
import com.cloudroam.common.LocalUser;
import com.cloudroam.dto.emailSmtp.CreateOrUpdateEmailSmtpDTO;
import com.cloudroam.dto.emailSmtp.QueryEmailSmtpDTO;
import com.cloudroam.common.enumeration.DeletedEnum;
import com.cloudroam.common.enumeration.EnabledEnum;
import com.cloudroam.mapper.EmailSmtpSettingMapperCustom;
import com.cloudroam.model.EmailSmtpSettingDO;
import com.cloudroam.mapper.EmailSmtpSettingMapper;
import com.cloudroam.model.UserDO;
import com.cloudroam.service.EmailSmtpSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 邮箱配置表 服务实现类
 * </p>
 *
 * @author generator@TaoJie
 * @since 2023-08-15
 */
@Service
public class EmailSmtpSettingServiceImpl extends ServiceImpl<EmailSmtpSettingMapper, EmailSmtpSettingDO> implements EmailSmtpSettingService {
 
    @Autowired
    private EmailSmtpSettingMapperCustom emailSmtpSettingMapperCustom;
 
    @Override
    public List<EmailSmtpSettingDO> getEmailSmtpSettingList() {
 
        QueryWrapper<EmailSmtpSettingDO> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", DeletedEnum.DELETED_NO.getCode());
        wrapper.eq("is_enabled", EnabledEnum.YES.getCode());
 
        return this.baseMapper.selectList(wrapper);
    }
 
    @Override
    @Transactional
    public boolean createEmailSmtp(CreateOrUpdateEmailSmtpDTO validator) {
        
        UserDO user = LocalUser.getLocalUser();
 
        EmailSmtpSettingDO emailSmtpSettingDO=new EmailSmtpSettingDO();
        BeanUtils.copyProperties(validator,emailSmtpSettingDO);
 
        emailSmtpSettingDO.setId(IdUtil.simpleUUID());
 
        emailSmtpSettingDO.setCreateTime(new Date());
        emailSmtpSettingDO.setCreateUserId(String.valueOf(user.getId()));
        emailSmtpSettingDO.setCreateUserName(user.getNickname());
 
        emailSmtpSettingDO.setUpdateTime(new Date());
        emailSmtpSettingDO.setUpdateUserId(String.valueOf(user.getId()));
        emailSmtpSettingDO.setUpdateUserName(user.getNickname());
        emailSmtpSettingDO.setIsDeleted(DeletedEnum.DELETED_NO.getCode());
        return baseMapper.insert(emailSmtpSettingDO)>0;
    }
 
    @Override
    @Transactional
    public boolean updateEmailSmtpSetting(CreateOrUpdateEmailSmtpDTO validator) {
        UserDO user = LocalUser.getLocalUser();
 
        EmailSmtpSettingDO emailSmtpSettingDO=new EmailSmtpSettingDO();
        BeanUtils.copyProperties(validator,emailSmtpSettingDO);
 
        emailSmtpSettingDO.setCreateTime(new Date());
        emailSmtpSettingDO.setCreateUserId(String.valueOf(user.getId()));
        emailSmtpSettingDO.setCreateUserName(user.getNickname());
 
        emailSmtpSettingDO.setUpdateTime(new Date());
        emailSmtpSettingDO.setUpdateUserId(String.valueOf(user.getId()));
        emailSmtpSettingDO.setUpdateUserName(user.getNickname());
        emailSmtpSettingDO.setIsDeleted(DeletedEnum.DELETED_NO.getCode());
        return baseMapper.updateById(emailSmtpSettingDO)>0;
    }
 
    @Override
    @Transactional
    public boolean removeByIdLogic(String id) {
        UserDO user = LocalUser.getLocalUser();
 
        EmailSmtpSettingDO emailSmtpSettingDO=new EmailSmtpSettingDO();
        emailSmtpSettingDO.setId(id);
        emailSmtpSettingDO.setIsDeleted(DeletedEnum.DELETED_YES.getCode());
        emailSmtpSettingDO.setDeleteTime(new Date());
        emailSmtpSettingDO.setDeleteUserId(String.valueOf(user.getId()));
        emailSmtpSettingDO.setDeleteUserName(user.getNickname());
 
 
        return baseMapper.updateById(emailSmtpSettingDO)>0;
    }
 
    @Override
    public IPage<EmailSmtpSettingBO> getEmailSmtpSettingPage(QueryEmailSmtpDTO dto) {
        Page<EmailSmtpSettingBO> page=new Page<EmailSmtpSettingBO>(dto.getPage(),dto.getCount());
        return emailSmtpSettingMapperCustom.getEmailSmtpSettingPage(page,dto.getKeyword(),
                dto.getSmtpFrom(),dto.getSmtpHost(),dto.getSmtpPort(),dto.getSmtpUsername()
                ,dto.getIsEnabled(),dto.getSmtpType());
    }
}