xinyb
2024-09-20 562e208f397b70d27c519f225d821298ab04c5cf
提交 | 用户 | 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) " +
385e2d 67                     " where userCode=" + GridUtils.prossSqlParm(account.getUserCode()) + " and accountId=" + account.getAccountId();
7cf738 68             sql += "select @@ROWCOUNT";
X 69             return jdbcTemplate.queryForObject(sql, Integer.class);
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) " +
81                     " where accountId=" + accountId;
877259 82             sql += "select @@ROWCOUNT";
X 83             return jdbcTemplate.queryForObject(sql, Integer.class);
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) " +
877259 95                     " where accountId=" + accountId;
X 96             sql += "select @@ROWCOUNT";
97             return jdbcTemplate.queryForObject(sql, Integer.class);
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) " +
877259 109                     " where accountId=" + accountId;
385e2d 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
877259 131     public List<T482102Entity> getAccount(String userCode) {
385e2d 132         String sql = "set nocount on\n";
X 133         try {
134             sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
877259 135                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
6a63e2 136                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
X 137                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
385e2d 138                     "from t482102 " +
X 139                     "where userCode=" + GridUtils.prossSqlParm(userCode);
877259 140             sql += " order by accountId";
385e2d 141             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
X 142         } catch (Exception e) {
143             throw e;
144         }
145     }
146
147     @Override
877259 148     public T482102Entity getAccountInfo(String userCode, Integer accountId) throws Exception {
X 149         String sql = "set nocount on\n";
150         try {
151             sql += "select companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
152                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
153                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
154                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
155                     "from t482102 " +
156                     "where userCode=" + GridUtils.prossSqlParm(userCode) + " and accountId=" + accountId;
157             sql += " order by accountId";
158             List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
159             if (t482101HEntity.size() > 0) {
160                 return t482101HEntity.get(0);
161             }
385e2d 162             return null;
877259 163         } catch (Exception e) {
X 164             throw e;
165         }
166     }
167
168     @Override
169     public T482102Entity getAccountInfo(String userCode, String eMail) throws Exception {
170         String sql = "set nocount on\n";
171         try {
7caeae 172             sql += "select top 1 companyId,companyName,email,password,alias_email as aliasEmail,userCode,userName,accountId,receive_server_user_name as receiveServerUserName," +
877259 173                     "isnull(bisync_flag,0) as biSyncFlag,isnull(proxyFlag,0) as proxyFlag,mailDomain,isnull(mailType,0) as mailType,mailStatus,keywordList,siteUrl,receiveProtocol," +
X 174                     "receiveEmail,receivePassword,receiveSSL,receivePort,receiveHost,smtpEmail,smtpPassword,smtpSSL,smtpPort,smtpHost," +
175                     "isnull(invalid,0) as invalid,create_time as createTime,update_time as updateTime,DocVersion " +
176                     "from t482102 " +
177                     "where userCode=" + GridUtils.prossSqlParm(userCode) + " and email=" + GridUtils.prossSqlParm(eMail);
178             sql += " order by accountId";
179             List<T482102Entity> t482101HEntity = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T482102Entity.class));
180             if (t482101HEntity.size() > 0) {
181                 return t482101HEntity.get(0);
182             }
183             return null;
184         } catch (Exception e) {
185             throw e;
385e2d 186         }
X 187     }
188 }