xinyb
9 天以前 b7ef4bb09e69ba27c29ea06a7f348f753c530a44
提交 | 用户 | age
385e2d 1 package com.yc.crm.mail.service;
X 2
3 import com.yc.action.grid.GridUtils;
4 import com.yc.crm.mail.entity.T482102Entity;
5 import com.yc.service.BaseService;
6 import org.apache.commons.lang3.StringUtils;
7 import org.springframework.jdbc.core.BeanPropertyRowMapper;
8 import org.springframework.stereotype.Service;
048b74 9 import org.springframework.transaction.annotation.Transactional;
385e2d 10
X 11 import java.util.List;
12
13 /**
14  * @BelongsProject: eCoWorksV3
15  * @BelongsPackage: com.yc.crm.service
16  * @author: xinyb
17  * @CreateTime: 2024-07-26  09:06
18  * @Description:
19  */
20 @Service
21 public class MailAccountImpl extends BaseService implements MailAccountIfc {
048b74 22     @Transactional(rollbackFor = Exception.class)
385e2d 23     @Override
X 24     public void addEmailAccount(T482102Entity account) {
25         String sql = "set nocount on\n";
26         try {
6a63e2 27             sql += "insert into t482102(companyId,companyName,email,password,alias_email,userCode,userName,receiveProtocol," +
X 28                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost," +
877259 29                     "smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost,invalid,bisync_flag,proxyFlag,mailType,mailStatus,create_time,update_time)\n" +
385e2d 30                     "values(" + GridUtils.prossSqlParm(account.getCompanyId()) + "," + GridUtils.prossSqlParm(account.getCompanyName()) + "," + GridUtils.prossSqlParm(account.getEmail()) + "," +
f5cc47 31                     GridUtils.prossSqlParm(account.getPassword()) + "," +
385e2d 32                     GridUtils.prossSqlParm(account.getAliasEmail()) + "," + GridUtils.prossSqlParm(account.getUserCode()) + "," + GridUtils.prossSqlParm(account.getUserName()) + "," +
6a63e2 33                     GridUtils.prossSqlParm(account.getReceiveProtocol()) + "," + GridUtils.prossSqlParm(account.getReceiveEmail()) + "," + GridUtils.prossSqlParm(account.getReceivePassword()) + "," +
X 34                     "'" + account.isReceiveSSL() + "'," + account.getReceivePort() + "," + GridUtils.prossSqlParm(account.getReceiveHost()) + "," +
35                     GridUtils.prossSqlParm(account.getSmtpEmail()) + "," + GridUtils.prossSqlParm(account.getSmtpPassword()) + ",'" + account.isSmtpSSL() + "'," +
8c1986 36                     account.getSmtpPort() + "," + GridUtils.prossSqlParm(account.getSmtpHost()) + ",'" + account.isInvalid() + "','" + account.isBiSyncFlag() + "','" + account.isProxyFlag() + "'," +
877259 37                     account.getMailType() + "," + GridUtils.prossSqlParm(account.getMailStatus()) + ",convert(varchar(19),getdate(),120),convert(varchar(19),getdate(),120))";
385e2d 38             jdbcTemplate.update(sql);
X 39         } catch (Exception e) {
40             throw e;
41         }
42     }
43
048b74 44     @Transactional(rollbackFor = Exception.class)
385e2d 45     @Override
X 46     public Integer updateEmailAccount(T482102Entity account) {
47         String sql = "set nocount on\n";
48         try {
6a63e2 49             sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(account.getAliasEmail()) + ",";
X 50             if (StringUtils.isNotBlank(account.getPassword())) {
51                 sql += "password=" + GridUtils.prossSqlParm(account.getPassword()) + ",";
52             }
8c1986 53             sql += " receiveEmail=" + GridUtils.prossSqlParm(account.getReceiveEmail()) + ",";
6a63e2 54             if (StringUtils.isNotBlank(account.getReceivePassword())) {
X 55                 sql += "receivePassword=" + GridUtils.prossSqlParm(account.getReceivePassword()) + ",";
56             }
57             sql += " receiveSSL='" + account.isReceiveSSL() + "',receivePort=" + account.getReceivePort() + ", " +
58                     " receiveHost=" + GridUtils.prossSqlParm(account.getReceiveHost()) + "," +
59                     " smtpEmail=" + GridUtils.prossSqlParm(account.getSmtpEmail()) + ",";
60             if (StringUtils.isNotBlank(account.getSmtpPassword())) {
61                 sql += "smtpPassword=" + GridUtils.prossSqlParm(account.getSmtpPassword()) + ",";
62             }
63             sql += " smtpSSL='" + account.isSmtpSSL() + "'," + " smtpPort=" + account.getSmtpPort() + ",smtpHost=" + GridUtils.prossSqlParm(account.getSmtpHost()) + "," +
8c1986 64                     " invalid='" + account.isInvalid() + "',bisync_flag='" + account.isBiSyncFlag() + "',proxyFlag='" + account.isProxyFlag() + "'," +
7cf738 65                     " mailType=" + account.getMailType() + ",mailStatus=" + GridUtils.prossSqlParm(account.getMailStatus()) +
X 66 //                    " ,update_time=convert(varchar(19),getdate(),120) " +
b7ef4b 67                     " where userCode=" + GridUtils.prossSqlParm(account.getUserCode()) + " and accountId=" + account.getAccountId() + "\n";
X 68             sql += " select @@ROWCOUNT";
7cf738 69             return jdbcTemplate.queryForObject(sql, Integer.class);
X 70         } catch (Exception e) {
71             throw e;
72         }
73     }
74
048b74 75     @Transactional(rollbackFor = Exception.class)
7cf738 76     @Override
X 77     public Integer updateEmailTime(Integer accountId) {
78         String sql = "set nocount on\n";
79         try {
80             sql += "update t482102 set update_time=convert(varchar(19),getdate(),120) " +
b7ef4b 81                     " where accountId=" + accountId + "\n";
X 82             sql += " select @@ROWCOUNT";
877259 83             return jdbcTemplate.queryForObject(sql, Integer.class);
X 84         } catch (Exception e) {
85             throw e;
86         }
87     }
88
048b74 89     @Transactional(rollbackFor = Exception.class)
877259 90     @Override
X 91     public Integer updateMailStatus(String status, Integer accountId) {
92         String sql = "set nocount on\n";
93         try {
7cf738 94             sql += "update t482102 set mailStatus=" + GridUtils.prossSqlParm(status) + //",update_time=convert(varchar(19),getdate(),120) " +
b7ef4b 95                     " where accountId=" + accountId + "\n";
X 96             sql += " select @@ROWCOUNT";
877259 97             return jdbcTemplate.queryForObject(sql, Integer.class);
X 98         } catch (Exception e) {
99             throw e;
100         }
101     }
102
048b74 103     @Transactional(rollbackFor = Exception.class)
877259 104     @Override
X 105     public Integer updateAliasEmail(String aliasEmail, Integer accountId) {
106         String sql = "set nocount on\n";
107         try {
7cf738 108             sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(aliasEmail) + //",update_time=convert(varchar(19),getdate(),120) " +
b7ef4b 109                     " where accountId=" + accountId + "\n";
X 110             sql += " select @@ROWCOUNT";
f5cc47 111             return jdbcTemplate.queryForObject(sql, Integer.class);
385e2d 112         } catch (Exception e) {
X 113             throw e;
114         }
115     }
116
048b74 117     @Transactional(rollbackFor = Exception.class)
385e2d 118     @Override
X 119     public Integer deleteEmailAccount(String userCode, Integer accountId) {
120         String sql = "set nocount on\n";
121         try {
122             sql += "delete t482102 where userCode='" + userCode + "' and accountId=" + accountId + "\n";
123             sql += "select @@ROWCOUNT";
f5cc47 124             return jdbcTemplate.queryForObject(sql, Integer.class);
385e2d 125         } catch (Exception e) {
X 126             throw e;
127         }
128     }
129
130     @Override
18553a 131     public List<T482102Entity> getAccountList() {
F 132         String sql = "set nocount on\n";
b7ef4b 133         sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
X 134                 "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
135                 "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
136                 "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
137                 "from t482102 where invalid=1";
138         sql += " order by accountId";
139         return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
18553a 140     }
F 141
142     @Override
877259 143     public List<T482102Entity> getAccount(String userCode) {
385e2d 144         String sql = "set nocount on\n";
X 145         try {
146             sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
877259 147                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
6a63e2 148                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
X 149                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
385e2d 150                     "from t482102 " +
X 151                     "where userCode=" + GridUtils.prossSqlParm(userCode);
877259 152             sql += " order by accountId";
385e2d 153             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
X 154         } catch (Exception e) {
155             throw e;
156         }
157     }
158
159     @Override
877259 160     public T482102Entity getAccountInfo(String userCode, Integer accountId) throws Exception {
X 161         String sql = "set nocount on\n";
162         try {
163             sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
164                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
165                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
166                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
167                     "from t482102 " +
168                     "where userCode=" + GridUtils.prossSqlParm(userCode) + " and accountId=" + accountId;
169             sql += " order by accountId";
170             List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
171             if (t482101HEntity.size() > 0) {
172                 return t482101HEntity.get(0);
173             }
385e2d 174             return null;
877259 175         } catch (Exception e) {
X 176             throw e;
177         }
178     }
179
180     @Override
181     public T482102Entity getAccountInfo(String userCode, String eMail) throws Exception {
182         String sql = "set nocount on\n";
183         try {
7caeae 184             sql += "select top 1 companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
877259 185                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
X 186                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
187                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
188                     "from t482102 " +
189                     "where userCode=" + GridUtils.prossSqlParm(userCode) + " and email=" + GridUtils.prossSqlParm(eMail);
190             sql += " order by accountId";
191             List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
192             if (t482101HEntity.size() > 0) {
193                 return t482101HEntity.get(0);
194             }
195             return null;
196         } catch (Exception e) {
197             throw e;
385e2d 198         }
X 199     }
200 }