xinyb
2024-09-18 57c8bf0a91f08d6fbd31d2b5c4e66f0945607bb0
提交 | 用户 | age
385e2d 1 package com.yc.crm.mail.service;
X 2
3 import com.yc.action.grid.GridUtils;
7caeae 4 import com.yc.crm.mail.entity.*;
385e2d 5 import com.yc.entity.AttachmentConfig;
X 6 import com.yc.entity.attachment.AttachmentEntity;
7 import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
7caeae 8 import com.yc.sdk.weixincp.util.UploadFiles;
385e2d 9 import com.yc.service.BaseService;
X 10 import org.apache.commons.lang3.StringUtils;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.jdbc.core.BeanPropertyRowMapper;
13 import org.springframework.stereotype.Service;
048b74 14 import org.springframework.transaction.annotation.Transactional;
385e2d 15
7caeae 16 import java.util.ArrayList;
X 17 import java.util.Arrays;
18 import java.util.List;
19 import java.util.Map;
ad7c8d 20 import java.util.regex.Matcher;
X 21 import java.util.regex.Pattern;
f5cc47 22 import java.util.stream.Collectors;
385e2d 23
X 24 /**
25  * @BelongsProject: eCoWorksV3
26  * @BelongsPackage: com.yc.crm.mail.service
27  * @author: xinyb
28  * @CreateTime: 2024-08-06  09:57
29  * @Description:
30  */
31 @Service
32 public class MailImpl extends BaseService implements MailIfc {
33     @Autowired
34     MailAccountIfc emailAccountIfc;
35     @Autowired
36     ShoppingImageDataIfc imgData;
37
38     final static String shoppingImageServer = AttachmentConfig.get("attachment.server");
ad7c8d 39
048b74 40     @Transactional(rollbackFor = Exception.class)
385e2d 41     @Override
X 42     public t482101HEntity saveReceivingMail(t482101HEntity m) {
43         String sql = "set nocount on\n";
44         try {
3c2c1b 45             if (StringUtils.isBlank(m.getDocCode())) {
7cf738 46                 sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
X 47                         "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
385e2d 48                 sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
ad7c8d 49                 sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," +
57c8bf 50                         "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," +//receive_time
d8f4b9 51                         "attach_flag,attachment_list) values ";
385e2d 52                 sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
X 53                         "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
54                         + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
ad7c8d 55                         +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
f4c162 56                         GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
X 57                         GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
385e2d 58                         GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
7caeae 59                         GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
57c8bf 60                         m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" +
7caeae 61                         mailFileSql(m.getMailFile());
385e2d 62                 sql += "select @docCode as docCode";
X 63                 String docCode = jdbcTemplate.queryForObject(sql, String.class);
64                 if (StringUtils.isNotBlank(docCode)) {
65                     m.setDocCode(docCode);
66                 }
3c2c1b 67             } else {
385e2d 68                 updateReceivingMail(m);//修改
X 69             }
70             return m;
71         } catch (Exception e) {
72             throw e;
73         }
74     }
ad7c8d 75
048b74 76     @Transactional(rollbackFor = Exception.class)
385e2d 77     @Override
X 78     public void saveReceivingMailList(List<t482101HEntity> mail) {
79         String sql = "set nocount on\n";
80         try {
7caeae 81             sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
7cf738 82                     "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
385e2d 83             for (t482101HEntity m : mail) {//遍历内容
X 84                 sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
ad7c8d 85                 sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," +
57c8bf 86                         "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," +
d8f4b9 87                         "attach_flag,attachment_list) values ";
385e2d 88                 sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
X 89                         "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
90                         + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
ad7c8d 91                         +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
f4c162 92                         GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
X 93                         GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
385e2d 94                         GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
7caeae 95                         GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
57c8bf 96                         m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" +
7caeae 97                         mailFileSql(m.getMailFile());
385e2d 98             }
X 99             jdbcTemplate.update(sql);
100         } catch (Exception e) {
101             throw e;
7caeae 102         }
X 103     }
104
105     /**
106      * 邮件附件的处理
107      *
108      * @param mailFile
109      * @return
110      */
111     private String mailFileSql(MailFileEntity mailFile) {
112         if (mailFile == null) {//附件保存
113             return "";
114         }
115         String sql = "";
116         String originalFileName = "";
117         String fileType = "";
118         try {
119             for (MailFileEntity.MailBodyPart file : mailFile.getPart()) {
120                 originalFileName = file.getFileName();
121                 fileType = file.getFileType();
122                 sql += "select @unid=" + GridUtils.prossSqlParm(mailFile.getUnId()) + "\n" +
7cf738 123                         ",@fieldId=" + GridUtils.prossSqlParm(file.getFieldId()) + "\n" +
7caeae 124                         ",@originalFileName=" + GridUtils.prossSqlParm(originalFileName) + "\n" +
7cf738 125                         ",@physicalFile=" + GridUtils.prossSqlParm(file.getPhysicalFile()) + "\n" +
7caeae 126                         ",@OriginalPicture=" + UploadFiles.byteToHexString(file.getByteFile()) + "\n";
X 127                 sql += "insert into _sys_Attachment(unId,formId,docCode,fieldId,physicalFile,originalFileName,FileSize,fileType,UploadTime,LastUpdateTime,OriginalPicture) values ";
7cf738 128                 sql += " (@unid,482101,@docCode,@fieldId,@physicalFile,@originalFileName," + file.getFileSize() + "," + GridUtils.prossSqlParm(fileType) + ",getdate(),getdate(),@OriginalPicture) \n";
7caeae 129             }
X 130             return sql;
131         } catch (Exception e) {
132             return "";
385e2d 133         }
X 134     }
ad7c8d 135
048b74 136     @Transactional(rollbackFor = Exception.class)
385e2d 137     @Override
X 138     public Integer updateReceivingMail(t482101HEntity mail) {
139         String sql = "set nocount on\n";
140         try {
f4c162 141             sql += "update t482101H set sender=" + GridUtils.prossSqlParm(mail.getSender()) + ",receiver=" + GridUtils.prossSqlParm(StringUtils.join(mail.getReceiver(), ",")) + "," +
X 142                     "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + ",subject=" + GridUtils.prossSqlParm(mail.getSubject()) + "," +
7caeae 143                     "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",mailType=" + mail.getMailType() + "," +
f4c162 144                     "update_time=getdate() \n";
5b1a4a 145             sql += " where docCode=" + GridUtils.prossSqlParm(mail.getDocCode()) + "\n";
428443 146             sql += "select @@ROWCOUNT";
X 147             return jdbcTemplate.queryForObject(sql, Integer.class);
f4c162 148         } catch (Exception e) {
X 149             throw e;
150         }
151     }
ad7c8d 152
048b74 153     @Transactional(rollbackFor = Exception.class)
f4c162 154     @Override
X 155     public Integer updateDeleteFlag(String userCode, String docCode) {
156         String sql = "set nocount on\n";
157         try {
158             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
159             sql += "update t482101H deleteFlag=1 where userCode =" + GridUtils.prossSqlParm(userCode) +
160                     " and docCode in (select list from GetInStr(@docCode))\n";//标记删除
5b1a4a 161             sql += " select @@ROWCOUNT";
428443 162             return jdbcTemplate.queryForObject(sql, Integer.class);
385e2d 163         } catch (Exception e) {
X 164             throw e;
165         }
166     }
ad7c8d 167
048b74 168     @Transactional(rollbackFor = Exception.class)
385e2d 169     @Override
5b1a4a 170     public Integer deleteEmail(String userCode, String docCode) {
385e2d 171         String sql = "set nocount on\n";
X 172         try {
f4c162 173             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
X 174             sql += "delete t482101H where userCode =" + GridUtils.prossSqlParm(userCode) +
175                     " and docCode in (select list from GetInStr(@docCode))\n";//标记删除
5b1a4a 176             sql += " select @@ROWCOUNT";
428443 177             return jdbcTemplate.queryForObject(sql, Integer.class);
f5cc47 178         } catch (Exception e) {
X 179             throw e;
180         }
181     }
182
183     @Override
5b1a4a 184     public Integer deleteEmail(String messageId) {
f5cc47 185         String sql = "set nocount on\n";
X 186         try {
f4c162 187             sql += "declare @messageId varchar(200) ='" + messageId + "' \n";
X 188             sql += "delete t482101H where messageId in (select list from GetInStr(@messageId))\n";//删除
5b1a4a 189             sql += " select @@ROWCOUNT";
428443 190             return jdbcTemplate.queryForObject(sql, Integer.class);
385e2d 191         } catch (Exception e) {
X 192             throw e;
193         }
194     }
195
196     @Override
f4c162 197     public t482101HEntity getReceivingMailInfo(String docCode) {
385e2d 198         String sql = "set nocount on\n";
X 199         try {
ad7c8d 200             sql += "select top 1 DocCode,companyId,companyName,senderName,senderName,sender,receiver,mailType,subject,content,plain_text,file_unid as fileUNID,messageId," +
5b1a4a 201                     "read_flag,delete_flag,attach_flag,urgent_flag,receipt_flag,track_flag,userCode,userName,create_time,update_time," +
ad7c8d 202                     "send_status,receive_time,sign_id,attachment_list,remark,remark," +
X 203                     "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle,handle_time," +
204                     "DocVersion from t482101H " +
f4c162 205                     "where docCode=" + GridUtils.prossSqlParm(docCode);
385e2d 206             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HEntity.class)).get(0);
X 207         } catch (Exception e) {
208             throw e;
209         }
210     }
211
212     @Override
5b1a4a 213     public List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode) {
385e2d 214         String sql = "set nocount on\n";
X 215         try {
ad7c8d 216             sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
X 217                     "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " +
7cf738 218                     "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
X 219                     "handle_time from t482101H ";
5b1a4a 220             sql += " where userCode=" + GridUtils.prossSqlParm(userCode);
X 221             sql += " and mailType=" + mailType;//0:草稿箱 1:收件箱 2:发件箱
222             if (StringUtils.isNotBlank(email)) {
223                 if (mailType == 1) {
224                     sql += " and receiver like '%" + email + "%'";
225                 } else if (mailType == 2) {
226                     sql += " and sender =" + GridUtils.prossSqlParm(email);
227                 }
7cf738 228             }
X 229             if (isNoRead) {//0表示未读,1表示已读
230                 sql += " and isnull(read_flag,0) = 0";
385e2d 231             }
d8f4b9 232             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
X 233         } catch (Exception e) {
234             throw e;
235         }
236     }
237
238     @Override
57c8bf 239     public List<t482101HList> getHandleMailList(String email, String userCode) {
X 240         String sql = "set nocount on\n";
241         try {
242             sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
243                     "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " +
244                     "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
245                     "handle_time from t482101H ";
246             sql += " where isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()";
247             sql += " and userCode=" + GridUtils.prossSqlParm(userCode) + " and receiver like '%" + email + "%'";
248             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
249         } catch (Exception e) {
250             throw e;
251         }
252     }
253
254     @Override
d8f4b9 255     public List<t482101HList> getUserMailList(String userCode) {
X 256         String sql = " set nocount on \n";
257         try {
7cf738 258             sql = "select a.DocCode,isnull(a.mailType,0) as mailType,isnull(a.read_flag,0) as read_flag,a.sender,a.receiver, " +
X 259                     "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle " +
260                     " from t482101H a where  a.userCode=" + GridUtils.prossSqlParm(userCode) + " order by a.mailType";
428443 261             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
385e2d 262         } catch (Exception e) {
X 263             throw e;
264         }
265     }
266
048b74 267     @Transactional(rollbackFor = Exception.class)
385e2d 268     @Override
X 269     public Integer updateMailDrafts(t482101HEntity mail) {
270         String sql = "set nocount on\n";
271         try {
f4c162 272             sql += "update t482101H set sender=" + GridUtils.prossSqlParm(mail.getSender()) + ",receiver=" + GridUtils.prossSqlParm(StringUtils.join(mail.getReceiver(), ",")) + "," +
f6ae0b 273                     "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + "," +
X 274                     "subject=" + GridUtils.prossSqlParm(mail.getSubject()) + ",messageId=" + GridUtils.prossSqlParm(mail.getMessageId()) + "," +
7caeae 275                     "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",mailType=" + mail.getMailType() + "," +
6a63e2 276                     "update_time=getdate() \n";
385e2d 277             sql += " where docCode=" + GridUtils.prossSqlParm(mail.getDocCode());
5b1a4a 278             sql += " select @@ROWCOUNT";
428443 279             return jdbcTemplate.queryForObject(sql, Integer.class);
385e2d 280         } catch (Exception e) {
X 281             throw e;
282         }
283     }
284
7caeae 285     @Override
X 286     public void saveAttachment(List<MailFileEntity> mailFile) {
385e2d 287         try {
f5cc47 288
385e2d 289         } catch (Exception e) {
X 290             throw e;
291         }
292     }
293
3c2c1b 294
X 295     @Override
296     public List<AttachmentEntity> getAttachmentEntityList(String unIdSeq) {
297         String unId = null;
298         if (StringUtils.isBlank(unIdSeq)) {
299             return null;
300         }
301         String[] array = unIdSeq.split(";");
302         unId = array[0];//在有值时候第一个必定是unId
f6ae0b 303         ArrayList<String> fieldId = new ArrayList<>(Arrays.asList(array));
X 304         fieldId.remove(0);//去掉第一个元素(UNID)
3c2c1b 305         String sql = " set nocount on \n"
f6ae0b 306                 + " declare @unid varchar(50) = " + GridUtils.prossSqlParm(unId) +
X 307                 ",@fieldid varchar(1000) = " + GridUtils.prossSqlParm(StringUtils.join(fieldId, ",")) + " \n";
308
3c2c1b 309         sql += " select UNID,seq,DocCode,RowId,FieldId,FormId, \n"
X 310                 + " PhysicalPath,PhysicalFile,OriginalFileName,FileSize,FileType, \n"
311                 + " AuthorCode,AuthorName,SmallPicPath,UploadTime,OriginalPicture \n"
312                 + " from _sys_Attachment \n"
f5cc47 313                 + " where unid = @unid ";
f6ae0b 314         if (fieldId.size() > 0) {
ad7c8d 315             if (isNumeric(fieldId.get(0))) {
X 316                 sql += " and seq in(select list from GetInStr(@fieldid)) \n";
317             } else {
318                 sql += " and fieldid in(select list from GetInStr(@fieldid)) \n";
319             }
3c2c1b 320         }
X 321         List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql);
322         List<AttachmentEntity> attachmentList = new ArrayList<AttachmentEntity>();
323         for (int i = 0; list != null && i < list.size(); i++) {
324             AttachmentEntity attachment = new AttachmentEntity();
ad7c8d 325             attachment.setUnid(unId);
X 326             attachment.setPhysicalFile(list.get(i).get("PhysicalFile") == null ? null : (String) list.get(i).get("PhysicalFile"));
3c2c1b 327             attachment.setOriginalFileName(list.get(i).get("OriginalFileName") == null ? null : (String) list.get(i).get("OriginalFileName"));
ad7c8d 328             attachment.setOriginalPicture(list.get(i).get("OriginalPicture") == null ? null : (byte[]) list.get(i).get("OriginalPicture"));  //附件处理
3c2c1b 329             attachmentList.add(attachment);
X 330         }
331         return attachmentList;
7caeae 332     }
ad7c8d 333
X 334     /**
335      * 判断是否为数字
336      *
337      * @param str
338      * @return
339      */
340     private static boolean isNumeric(String str) {
341         Pattern pattern = Pattern.compile("\\d+");
342         Matcher matcher = pattern.matcher(str);
343         return matcher.matches();
344     }
345
048b74 346     @Transactional(rollbackFor = Exception.class)
7caeae 347     @Override
X 348     public Integer deleteAttachment(List<String> unId) {
349         try {
350             if (unId == null || unId.size() == 0) {
351                 return 0;
352             }
353             String sql = " set nocount on \n"
354                     + " declare @unid varchar(4000) = '" + StringUtils.join(unId, ",") + "'  \n";
355             sql += "delete _sys_Attachment where unid in (select list from GetInStr(@unid)) \n";
356             sql += "select @@ROWCOUNT";
357             return jdbcTemplate.queryForObject(sql, Integer.class);
358         } catch (Exception e) {
359             throw e;
360         }
3c2c1b 361     }
f5cc47 362
X 363     @Override
364     public List<String> getMessageIdList(String receiver) {
365         List<String> messageId = null;
366         String sql = " set nocount on \n";
367         try {
368             sql += "select messageId from t482101H where receiver='" + receiver + "'";
369             List<t482101HEntity> message = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HEntity.class));
370             if (message != null && message.size() > 0) {
371                 messageId = new ArrayList<>();
372                 messageId = message.stream().map(t482101HEntity::getMessageId).distinct().collect(Collectors.toList());//去重
373             }
374             return messageId;
375         } catch (Exception e) {
376             throw e;
377         }
378     }
57c8bf 379
048b74 380     @Transactional(rollbackFor = Exception.class)
f4c162 381     @Override
7cf738 382     public void updateRead(String docCode, boolean status) {
f4c162 383         String sql = " set nocount on \n";
X 384         try {
5b1a4a 385             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
7cf738 386             sql += "update t482101H set read_flag=" + (status ? 1 : 0) + " where docCode in (select list from GetInStr(@docCode))\n";
f4c162 387             sql += "select @@ROWCOUNT";
X 388             jdbcTemplate.queryForObject(sql, Integer.class);
389         } catch (Exception e) {
390             throw e;
391         }
392     }
d8f4b9 393
X 394     @Override
395     public List<MailModuleEntity> getMailModuleList(String userCode) {
396         List<MailModuleEntity> module = MailModuleEntity.setMailInitial();
397         try {
877259 398             List<T482102Entity> account = emailAccountIfc.getAccount(userCode);//获取这个账号绑定的邮箱
d8f4b9 399             List<t482101HList> userMail = getUserMailList(userCode);
X 400             for (MailModuleEntity m : module) {
401                 List<t482101HList> mailTypeList = null;
402                 int mailType = m.getMailType();//类型
403                 switch (mailType) {
404                     case 0://草稿箱
405                     case 1://收件箱
406                     case 2://发件箱
407                         if (mailType == 0) {
877259 408                             m.setChildren(new ArrayList<>());
d8f4b9 409                             if (userMail.size() > 0) {
X 410                                 m.setTotal((int) userMail.stream().filter(s -> s.getMailType().equals(mailType)).count());
411                             }
412                         } else {
413                             List<MailModuleEntity.MailCode> codeList = new ArrayList<>();
414                             MailModuleEntity.MailCode code = new MailModuleEntity.MailCode();
877259 415                             code.setKey(mailType == 1 ? "InboxPage1" : "IndexPage1");
d8f4b9 416                             code.setMailType(mailType);
X 417                             code.setMailName(mailType == 1 ? "全部收件" : "全部发件");
418                             codeList.add(code);
419                             if (account.size() == 0) {//没有直接跳过
877259 420                                 m.setChildren(codeList);
d8f4b9 421                                 continue;
X 422                             }
423                             int allCount = 0;
424                             int count = 0;
7caeae 425                             for (T482102Entity a : account) {
d8f4b9 426                                 MailModuleEntity.MailCode nextCode = new MailModuleEntity.MailCode();
6a63e2 427                                 String eMail = (mailType == 1 ? a.getReceiveEmail() : a.getSmtpEmail());//获取邮箱账号
7caeae 428                                 nextCode.setKey(mailType == 1 ? "receiver" : "sender");
6a63e2 429                                 nextCode.setMailName(eMail);
d8f4b9 430                                 nextCode.setMailType(m.getMailType());
7cf738 431 //                                if (userMail.size() > 0) {
X 432 //                                    count = (mailType == 1 ? (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail)).count() :
433 //                                            (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getSender().contains(eMail)).count());
434 //                                    nextCode.setTotal(count);
435 //                                }
436                                 if (mailType == 1) {//是收件箱,统计未读数量
437                                     count = (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail) && s.getReadFlag().equals(0)).count();
d8f4b9 438                                     nextCode.setTotal(count);
X 439                                 }
440                                 codeList.add(nextCode);
441                                 allCount = (allCount + count);
442                             }
443                             codeList.get(0).setTotal(allCount);
444                             m.setTotal(allCount);
877259 445                             m.setChildren(codeList);
d8f4b9 446                         }
X 447                         break;
448                     case 3://待处理邮件
877259 449                         m.setChildren(new ArrayList<>());
d8f4b9 450                         if (userMail.size() > 0) {
7cf738 451                             m.setTotal((int) userMail.stream().filter(s -> s.getHandle().equals(1)).count());
d8f4b9 452                         }
X 453                         break;
454                     case 4://未读邮件
877259 455                         m.setChildren(new ArrayList<>());
d8f4b9 456                         if (userMail.size() > 0) {
7cf738 457                             m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals(0)).count());
d8f4b9 458                         }
X 459                         break;
460                     case 5://群邮箱
877259 461                         m.setChildren(new ArrayList<>());
d8f4b9 462                         break;
X 463                     default:
464                         break;
465                 }
466             }
467             return module;
468         } catch (Exception e) {
469             throw e;
470         }
471     }
57c8bf 472
048b74 473     @Transactional(rollbackFor = Exception.class)
7cf738 474     @Override
X 475     public void updateMailHandle(String handleTime, String docCode) {
476         String sql = " set nocount on \n";
477         try {
478             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
479             sql += "update t482101H set handle_time=" + (StringUtils.isBlank(handleTime) ? "null" : GridUtils.prossSqlParm(handleTime)) +
480                     " where docCode = @docCode\n";
481             sql += "select @@ROWCOUNT";
482             jdbcTemplate.queryForObject(sql, Integer.class);
483         } catch (Exception e) {
484             throw e;
485         }
486     }
385e2d 487 }