fs-danaus
2024-09-13 d4a21ed564d51bbcf00543b8d7c3eedb77ff28f4
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.yc.crm.mail.service;
 
import com.yc.action.grid.GridUtils;
import com.yc.crm.mail.entity.T482102Entity;
import com.yc.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.service
 * @author: xinyb
 * @CreateTime: 2024-07-26  09:06
 * @Description:
 */
@Service
public class MailAccountImpl extends BaseService implements MailAccountIfc {
    @Override
    public void addEmailAccount(T482102Entity account) {
        String sql = "set nocount on\n";
        try {
            sql += "insert into t482102(companyId,companyName,email,password,alias_email,userCode,userName,receiveProtocol," +
                    "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost," +
                    "smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost,invalid,bisync_flag,proxyFlag,mailType,mailStatus,create_time,update_time)\n" +
                    "values(" + GridUtils.prossSqlParm(account.getCompanyId()) + "," + GridUtils.prossSqlParm(account.getCompanyName()) + "," + GridUtils.prossSqlParm(account.getEmail()) + "," +
                    GridUtils.prossSqlParm(account.getPassword()) + "," +
                    GridUtils.prossSqlParm(account.getAliasEmail()) + "," + GridUtils.prossSqlParm(account.getUserCode()) + "," + GridUtils.prossSqlParm(account.getUserName()) + "," +
                    GridUtils.prossSqlParm(account.getReceiveProtocol()) + "," + GridUtils.prossSqlParm(account.getReceiveEmail()) + "," + GridUtils.prossSqlParm(account.getReceivePassword()) + "," +
                    "'" + account.isReceiveSSL() + "'," + account.getReceivePort() + "," + GridUtils.prossSqlParm(account.getReceiveHost()) + "," +
                    GridUtils.prossSqlParm(account.getSmtpEmail()) + "," + GridUtils.prossSqlParm(account.getSmtpPassword()) + ",'" + account.isSmtpSSL() + "'," +
                    account.getSmtpPort() + "," + GridUtils.prossSqlParm(account.getSmtpHost()) + ",'" + account.isInvalid() + "','" + account.isBiSyncFlag() + "','" + account.isProxyFlag() + "'," +
                    account.getMailType() + "," + GridUtils.prossSqlParm(account.getMailStatus()) + ",convert(varchar(19),getdate(),120),convert(varchar(19),getdate(),120))";
            jdbcTemplate.update(sql);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Integer updateEmailAccount(T482102Entity account) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(account.getAliasEmail()) + ",";
            if (StringUtils.isNotBlank(account.getPassword())) {
                sql += "password=" + GridUtils.prossSqlParm(account.getPassword()) + ",";
            }
            sql += " receiveEmail=" + GridUtils.prossSqlParm(account.getReceiveEmail()) + ",";
            if (StringUtils.isNotBlank(account.getReceivePassword())) {
                sql += "receivePassword=" + GridUtils.prossSqlParm(account.getReceivePassword()) + ",";
            }
            sql += " receiveSSL='" + account.isReceiveSSL() + "',receivePort=" + account.getReceivePort() + ", " +
                    " receiveHost=" + GridUtils.prossSqlParm(account.getReceiveHost()) + "," +
                    " smtpEmail=" + GridUtils.prossSqlParm(account.getSmtpEmail()) + ",";
            if (StringUtils.isNotBlank(account.getSmtpPassword())) {
                sql += "smtpPassword=" + GridUtils.prossSqlParm(account.getSmtpPassword()) + ",";
            }
            sql += " smtpSSL='" + account.isSmtpSSL() + "'," + " smtpPort=" + account.getSmtpPort() + ",smtpHost=" + GridUtils.prossSqlParm(account.getSmtpHost()) + "," +
                    " invalid='" + account.isInvalid() + "',bisync_flag='" + account.isBiSyncFlag() + "',proxyFlag='" + account.isProxyFlag() + "'," +
                    " mailType=" + account.getMailType() + ",mailStatus=" + GridUtils.prossSqlParm(account.getMailStatus()) +
//                    " ,update_time=convert(varchar(19),getdate(),120) " +
                    " where userCode=" + GridUtils.prossSqlParm(account.getUserCode()) + " and accountId=" + account.getAccountId();
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Integer updateEmailTime(Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Integer updateMailStatus(String status, Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set mailStatus=" + GridUtils.prossSqlParm(status) + //",update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Integer updateAliasEmail(String aliasEmail, Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(aliasEmail) + //",update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Integer deleteEmailAccount(String userCode, Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "delete t482102 where userCode='" + userCode + "' and accountId=" + accountId + "\n";
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public List<T482102Entity> getAccount(String userCode) {
        String sql = "set nocount on\n";
        try {
            sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
                    "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
                    "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
                    "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
                    "from t482102 " +
                    "where userCode=" + GridUtils.prossSqlParm(userCode);
            sql += " order by accountId";
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public T482102Entity getAccountInfo(String userCode, Integer accountId) throws Exception {
        String sql = "set nocount on\n";
        try {
            sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
                    "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
                    "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
                    "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
                    "from t482102 " +
                    "where userCode=" + GridUtils.prossSqlParm(userCode) + " and accountId=" + accountId;
            sql += " order by accountId";
            List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
            if (t482101HEntity.size() > 0) {
                return t482101HEntity.get(0);
            }
            return null;
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public T482102Entity getAccountInfo(String userCode, String eMail) throws Exception {
        String sql = "set nocount on\n";
        try {
            sql += "select top 1 companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
                    "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
                    "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
                    "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
                    "from t482102 " +
                    "where userCode=" + GridUtils.prossSqlParm(userCode) + " and email=" + GridUtils.prossSqlParm(eMail);
            sql += " order by accountId";
            List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
            if (t482101HEntity.size() > 0) {
                return t482101HEntity.get(0);
            }
            return null;
        } catch (Exception e) {
            throw e;
        }
    }
}