From ee2316e2cb7afde1c54f5e4216a1b0d1e055749e Mon Sep 17 00:00:00 2001
From: xinyb <574600396@qq.com>
Date: 星期五, 27 九月 2024 17:33:14 +0800
Subject: [PATCH] CRM邮箱配置调整

---
 src/com/yc/crm/mail/service/MailImpl.java |  741 ++++++++++++++++++++------------------------------------
 1 files changed, 262 insertions(+), 479 deletions(-)

diff --git a/src/com/yc/crm/mail/service/MailImpl.java b/src/com/yc/crm/mail/service/MailImpl.java
index 8285a9a..48a224d 100644
--- a/src/com/yc/crm/mail/service/MailImpl.java
+++ b/src/com/yc/crm/mail/service/MailImpl.java
@@ -1,39 +1,22 @@
 package com.yc.crm.mail.service;
 
-import com.sun.mail.imap.IMAPBodyPart;
-import com.sun.mail.imap.IMAPStore;
 import com.yc.action.grid.GridUtils;
-import com.yc.crm.mail.entity.MailModuleEntity;
-import com.yc.crm.mail.entity.T482102Entity;
-import com.yc.crm.mail.entity.t482101HEntity;
-import com.yc.crm.mail.entity.t482101HList;
+import com.yc.crm.base.entity.T482115Entity;
+import com.yc.crm.mail.action.MailFolder;
+import com.yc.crm.mail.action.MailTag;
+import com.yc.crm.mail.entity.*;
 import com.yc.entity.AttachmentConfig;
-import com.yc.entity.DataSourceEntity;
-import com.yc.entity.attachment.AttachmentEntity;
-import com.yc.entity.attachment.AttachmentWhereEntity;
-import com.yc.factory.FactoryBean;
-import com.yc.multiData.MultiDataSource;
 import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
+import com.yc.sdk.weixincp.util.UploadFiles;
 import com.yc.service.BaseService;
-import com.yc.service.upload.AttachmentIfc;
-import com.yc.utils.SessionKey;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import javax.mail.*;
-import javax.mail.internet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.regex.Pattern;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.stream.Collectors;
 
 /**
@@ -45,34 +28,39 @@
  */
 @Service
 public class MailImpl extends BaseService implements MailIfc {
-
     @Autowired
     MailAccountIfc emailAccountIfc;
     @Autowired
     ShoppingImageDataIfc imgData;
+    @Autowired
+    MailTagIfc mailTagIfc;
+    @Autowired
+    MailFolderIfc mailFolderIfc;
 
     final static String shoppingImageServer = AttachmentConfig.get("attachment.server");
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public t482101HEntity saveReceivingMail(t482101HEntity m) {
         String sql = "set nocount on\n";
         try {
             if (StringUtils.isBlank(m.getDocCode())) {
-                sql += "declare @docCode varchar(50) \n";
+                sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
+                        "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
                 sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
-                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
-                        "cc,bcc,subject,userCode,userName,content,plain_text,file_unid,messageId,read_flag,delete_flag,create_time,update_time,receive_time," +
+                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,sender_time,receiver,receiving_time," +
+                        "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," +//receive_time
                         "attach_flag,attachment_list) values ";
                 sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
                         "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
                         + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
-                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
-                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
+                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," + GridUtils.prossSqlParm(m.getSenderTime()) + "," +
+                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(m.getReceivingTime()) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
                         GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
                         GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
-                        GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getFileUNID()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
-                        m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + GridUtils.prossSqlParm(m.getReceiveTime()) + "," + m.getAttachFlag() + "," +
-                        GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n";
+                        GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
+                        m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" +
+                        mailFileSql(m.getMailFile());
                 sql += "select @docCode as docCode";
                 String docCode = jdbcTemplate.queryForObject(sql, String.class);
                 if (StringUtils.isNotBlank(docCode)) {
@@ -87,41 +75,75 @@
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
-    public void saveReceivingMailList(List<t482101HEntity> mail) {
+    public String saveReceivingMailList(List<t482101HEntity> mail) {
         String sql = "set nocount on\n";
         try {
-            sql += "declare @docCode varchar(50) \n";
+            sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100),@docCodeList varchar(3000)=''," +
+                    "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
             for (t482101HEntity m : mail) {//閬嶅巻鍐呭
                 sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
-                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
-                        "cc,bcc,subject,userCode,userName,content,plain_text,file_unid,messageId,read_flag,delete_flag,create_time,update_time,receive_time," +
+                sql += " select @docCodeList=@docCodeList+@docCode+';'\n" +//杩斿洖鍗曞彿
+                        "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,sender_time,receiver,receiving_time," +
+                        "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," +
                         "attach_flag,attachment_list) values ";
                 sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," +
                         "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),"
                         + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
-                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSender()) + "," +
-                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
+                        +m.getMailType() + "," + GridUtils.prossSqlParm(m.getSenderName()) + "," + GridUtils.prossSqlParm(m.getSender()) + "," + GridUtils.prossSqlParm(m.getSenderTime()) + "," +
+                        GridUtils.prossSqlParm(StringUtils.join(m.getReceiver(), ",")) + "," + GridUtils.prossSqlParm(m.getReceivingTime()) + "," + GridUtils.prossSqlParm(StringUtils.join(m.getCc(), ",")) + "," +
                         GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," +
                         GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," +
-                        GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getFileUNID()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
-                        m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + GridUtils.prossSqlParm(m.getReceiveTime()) + "," +
-                        m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n";
-//                sql +="exec postt482101V3 '' ,'',''";
+                        GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," +
+                        m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" +
+                        mailFileSql(m.getMailFile());
             }
-            jdbcTemplate.update(sql);
+            return jdbcTemplate.queryForObject(sql + "\n select @docCodeList", String.class);
         } catch (Exception e) {
             throw e;
         }
     }
 
+    /**
+     * 閭欢闄勪欢鐨勫鐞�
+     *
+     * @param mailFile
+     * @return
+     */
+    private String mailFileSql(MailFileEntity mailFile) {
+        if (mailFile == null) {//闄勪欢淇濆瓨
+            return "";
+        }
+        String sql = "";
+        String originalFileName = "";
+        String fileType = "";
+        try {
+            for (MailFileEntity.MailBodyPart file : mailFile.getPart()) {
+                originalFileName = file.getFileName();
+                fileType = file.getFileType();
+                sql += "select @unid=" + GridUtils.prossSqlParm(mailFile.getUnId()) + "\n" +
+                        ",@fieldId=" + GridUtils.prossSqlParm(file.getFieldId()) + "\n" +
+                        ",@originalFileName=" + GridUtils.prossSqlParm(originalFileName) + "\n" +
+                        ",@physicalFile=" + GridUtils.prossSqlParm(file.getPhysicalFile()) + "\n" +
+                        ",@OriginalPicture=" + UploadFiles.byteToHexString(file.getByteFile()) + "\n";
+                sql += "insert into _sys_Attachment(unId,formId,docCode,fieldId,physicalFile,originalFileName,FileSize,fileType,UploadTime,LastUpdateTime,OriginalPicture) values ";
+                sql += " (@unid,482101,@docCode,@fieldId,@physicalFile,@originalFileName," + file.getFileSize() + "," + GridUtils.prossSqlParm(fileType) + ",getdate(),getdate(),@OriginalPicture) \n";
+            }
+            return sql;
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Integer updateReceivingMail(t482101HEntity mail) {
         String sql = "set nocount on\n";
         try {
             sql += "update t482101H set sender=" + GridUtils.prossSqlParm(mail.getSender()) + ",receiver=" + GridUtils.prossSqlParm(StringUtils.join(mail.getReceiver(), ",")) + "," +
                     "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + ",subject=" + GridUtils.prossSqlParm(mail.getSubject()) + "," +
-                    "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",file_unid=" + GridUtils.prossSqlParm(mail.getFileUNID()) + ",mailType=" + mail.getMailType() + "," +
+                    "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",mailType=" + mail.getMailType() + "," +
                     "update_time=getdate() \n";
             sql += " where docCode=" + GridUtils.prossSqlParm(mail.getDocCode()) + "\n";
             sql += "select @@ROWCOUNT";
@@ -131,6 +153,7 @@
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Integer updateDeleteFlag(String userCode, String docCode) {
         String sql = "set nocount on\n";
@@ -145,12 +168,13 @@
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Integer deleteEmail(String userCode, String docCode) {
         String sql = "set nocount on\n";
         try {
             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
-            sql += "delete t482101H where userCode =" + GridUtils.prossSqlParm(userCode) +
+            sql += "update t482101H deleteFlag=1 where userCode =" + GridUtils.prossSqlParm(userCode) +
                     " and docCode in (select list from GetInStr(@docCode))\n";//鏍囪鍒犻櫎
             sql += " select @@ROWCOUNT";
             return jdbcTemplate.queryForObject(sql, Integer.class);
@@ -164,7 +188,7 @@
         String sql = "set nocount on\n";
         try {
             sql += "declare @messageId varchar(200) ='" + messageId + "' \n";
-            sql += "delete t482101H where messageId in (select list from GetInStr(@messageId))\n";//鍒犻櫎
+            sql += " delete t482101H where messageId in (select list from GetInStr(@messageId))\n";//鍒犻櫎
             sql += " select @@ROWCOUNT";
             return jdbcTemplate.queryForObject(sql, Integer.class);
         } catch (Exception e) {
@@ -176,9 +200,11 @@
     public t482101HEntity getReceivingMailInfo(String docCode) {
         String sql = "set nocount on\n";
         try {
-            sql += "select top 1 DocCode,companyId,companyName,sender,receiver,mailType,subject,content,plain_text,file_unid as fileUNID,messageId," +
+            sql += "select top 1 DocCode,companyId,companyName,senderName,senderName,sender,receiver,mailType,subject,content,plain_text,file_unid as fileUNID,messageId," +
                     "read_flag,delete_flag,attach_flag,urgent_flag,receipt_flag,track_flag,userCode,userName,create_time,update_time," +
-                    "send_status,receive_time,sign_id,attachment_list,remark,remark,DocVersion from t482101H " +
+                    "send_status,receive_time,sign_id,attachment_list,remark,remark,sender_time,receiving_time," +
+                    "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle,handle_time," +
+                    "DocVersion from t482101H " +
                     "where docCode=" + GridUtils.prossSqlParm(docCode);
             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HEntity.class)).get(0);
         } catch (Exception e) {
@@ -187,14 +213,14 @@
     }
 
     @Override
-    public List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode) {
+    public List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode, Integer page, Integer limit) {
         String sql = "set nocount on\n";
         try {
-            sql += "select companyId,companyName,mailType,DocCode,sender,receiver,subject,plain_text," +
-                    "receive_time,update_time,create_time,sender,userCode,userName,folder_id,delete_Flag, " +
-                    "read_Flag from t482101H ";
+            sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
+                    "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag,attachment_list," +
+                    "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
+                    "handle_time,sender_time,receiving_time from t482101H ";
             sql += " where userCode=" + GridUtils.prossSqlParm(userCode);
-            sql += " and isnull(read_flag,0) = " + (isNoRead ? 0 : 1);//0琛ㄧず鏈锛�1琛ㄧず宸茶
             sql += " and mailType=" + mailType;//0锛氳崏绋跨 1锛氭敹浠剁 2锛氬彂浠剁
             if (StringUtils.isNotBlank(email)) {
                 if (mailType == 1) {
@@ -203,6 +229,55 @@
                     sql += " and sender =" + GridUtils.prossSqlParm(email);
                 }
             }
+            if (isNoRead) {//0琛ㄧず鏈锛�1琛ㄧず宸茶
+                sql += " and isnull(read_flag,0) = 0";
+            }
+            sql += " order by docCode asc \n";
+            sql += " OFFSET (" + page + " - 1) * " + limit + " ROWS FETCH NEXT " + limit + " ROWS ONLY";
+            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @Override
+    public List<t482101HList> getHandleMailList(String email, String userCode, Integer page, Integer limit) {
+        String sql = "set nocount on\n";
+        try {
+            sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
+                    "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " +
+                    "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
+                    "handle_time,sender_time,receiving_time from t482101H ";
+            sql += " where isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()";
+            sql += " and userCode=" + GridUtils.prossSqlParm(userCode) + " and receiver like '%" + email + "%'";
+            sql += " order by docCode asc \n";
+            sql += " OFFSET (" + page + " - 1) * " + limit + " ROWS FETCH NEXT " + limit + " ROWS ONLY";
+            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @Override
+    public List<t482101HList> getFolderMailList(String type, String userCode, Integer page, Integer limit) throws Exception {
+        String sql = "set nocount on\n";
+        try {
+            String[] id = type.split("_");
+            if (id.length != 2) {
+                throw new Exception("閭欢绫诲瀷Id鏍煎紡涓嶆纭�");
+            }
+            sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," +
+                    "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " +
+                    "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
+                    "handle_time,sender_time,receiving_time from t482101H ";
+            sql += " where userCode=" + GridUtils.prossSqlParm(userCode) + " \n";
+            if (id[0].equals("folder")) {//鏄枃浠跺す
+                sql += " and folder_id=" + id[1] + " \n";
+            } else if (id[0].equals("tag")) {//鏄爣绛�
+                sql += " and tag_list like '%," + id[1] + ",%'";
+            }
+            sql += " order by docCode asc \n";
+            sql += " OFFSET (" + page + " - 1) * " + limit + " ROWS FETCH NEXT " + limit + " ROWS ONLY";
             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
         } catch (Exception e) {
             throw e;
@@ -213,179 +288,24 @@
     public List<t482101HList> getUserMailList(String userCode) {
         String sql = " set nocount on \n";
         try {
-            sql = "select a.DocCode,isnull(a.mailType,0) as mailType,isnull(a.read_flag,0) as read_flag,a.sender,a.receiver " +
-                    "from t482101H a where  a.userCode=" + GridUtils.prossSqlParm(userCode) + " order by a.mailType";
+            sql = "select a.DocCode,isnull(a.mailType,0) as mailType,isnull(a.read_flag,0) as read_flag,a.sender,a.receiver, " +
+                    "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle " +
+                    " from t482101H a where  a.userCode=" + GridUtils.prossSqlParm(userCode) + " order by a.mailType";
             return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
         } catch (Exception e) {
             throw e;
         }
     }
 
-
-    @Override
-    public List<t482101HEntity> getMailReceiving(T482102Entity emailEntity, HttpServletRequest request) throws MessagingException {
-        String imapServer = emailEntity.getReceiveHost();//"imap.qq.com";
-        String user = emailEntity.getReceiveEmail();//"xxx@qq.com";
-        String pwd = emailEntity.getReceivePassword();//"xxxx";
-
-        Properties properties = new Properties();
-        properties.put("mail.store.protocol", "imaps");//emailEntity.getReceiveProtocol()); // IMAP over SSL
-        properties.put("mail.imaps.host", emailEntity.getReceiveHost());
-        properties.put("mail.imaps.port", emailEntity.getReceivePort());
-        properties.put("mail.imaps.starttls.enable", "true");//// IMAP 鍗忚璁剧疆 STARTTLS
-
-        HashMap IAM = new HashMap();
-        //甯︿笂IMAP ID淇℃伅锛岀敱key鍜寁alue缁勬垚锛屼緥濡俷ame锛寁ersion锛寁endor锛宻upport-email绛夈��
-        IAM.put("name", emailEntity.getReceiveEmail());
-        IAM.put("version", emailEntity.getDocVersion() + "");
-        IAM.put("vendor", emailEntity.getCompanyName());
-        IAM.put("support-email", emailEntity.getEmail());
-        //鍒涘缓浼氳瘽
-        Session session = Session.getInstance(properties, new Authenticator() {
-            @Override
-            protected PasswordAuthentication getPasswordAuthentication() {
-                return new PasswordAuthentication(user, pwd);
-            }
-        });
-        //瀛樺偍瀵硅薄
-        IMAPStore store = (IMAPStore) session.getStore(emailEntity.getReceiveProtocol());//imap鍗忚鎴杙op3鍗忚绫诲瀷锛堟帹鑽愪綘浣跨敤IMAP鍗忚鏉ュ瓨鍙栨湇鍔″櫒涓婄殑閭欢銆傦級
-        //杩炴帴
-        store.connect(imapServer, user, pwd);
-        store.id(IAM);//163閭闇�瑕侊紝涓嶇劧浼氭姤锛欰3 NO SELECT Unsafe Login. Please contact kefu@188.com for help
-        Folder folder = null;
-        try {
-            // 鑾峰緱鏀朵欢绠�
-            folder = store.getFolder("INBOX");
-            // 浠ヨ鍐欐ā寮忔墦寮�鏀朵欢绠�
-            folder.open(Folder.READ_WRITE);
-            //false 琛ㄧず鏈
-//            FlagTerm flagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN), true);
-            //鑾峰緱鏀朵欢绠辩殑閭欢鍒楄〃(宸茶鐨勶紝鏍规嵁涓婇潰鐨刦lagTerm鑾峰彇宸茶鎴栨湭璇�)
-//            Message[] messages = folder.search(flagTerm);
-            //鑾峰彇鏀朵欢绠遍偖浠讹紙鍏ㄩ儴锛�
-            Message[] messages = folder.getMessages();
-            //杩斿洖閭灏佽鍐呭
-            return setMailContent(messages, user, request);
-        } catch (NoSuchProviderException e) {
-            throw e;
-        } catch (MessagingException e) {
-            throw e;
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            try {
-                if (folder != null) {
-                    folder.close(false);
-                }
-                if (store != null) {
-                    store.close();
-                }
-            } catch (MessagingException e) {
-                throw e;
-            }
-        }
-    }
-
-
-    @Override
-    public void sendingMail(t482101HEntity t482101H, HttpServletRequest request) throws Exception {
-        try {
-            //鏍规嵁褰撳墠鐢ㄦ埛鏌ヨ缁戝畾鐨勯偖绠变俊鎭�
-            T482102Entity emailEntity = emailAccountIfc.getAccountInfo(t482101H.getUserCode(), t482101H.getSender());//杩斿洖閭鐨勮处鍙蜂俊鎭�
-            if (emailEntity == null || StringUtils.isBlank(emailEntity.getSmtpEmail())) {
-                if (StringUtils.isBlank(t482101H.getDocCode())) {
-                    t482101H.setMailType(0);//鑽夌绠辩姸鎬�
-                    t482101H = saveReceivingMail(t482101H);//淇濆瓨鍒拌崏绋跨鍐�
-                }
-                throw new Exception("鎵句笉鍒伴偖绠憋細" + t482101H.getSender() + "閰嶇疆淇℃伅璇峰畬鍠勩�傞偖浠跺凡淇濆瓨鍒拌崏绋跨#" + t482101H.getDocCode());
-            }
-            //鏈夊彂閫佺殑閭欢淇濆瓨鍒板悗鍙版暟鎹簱
-            //閭鏈嶅姟鍣ㄩ厤缃�
-            Properties properties = new Properties();
-            properties.setProperty("mail.smtp.host", emailEntity.getSmtpHost());
-            properties.setProperty("mail.smtp.port", emailEntity.getSmtpPort() + "");
-            properties.setProperty("mail.smtp.auth", "true");// // 璁剧疆SMTP鏄惁闇�瑕佽璇�
-            properties.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");// // 璁剧疆鍚敤SSL鍔犲瘑
-            properties.setProperty("mail.smtp.starttls.enable", "true");//// SMTP 鍗忚璁剧疆 STARTTLS  寮�鍚痶ls
-
-            //
-            String sendEmail = emailEntity.getSmtpEmail();//鍙戜欢浜�
-            String sendPassword = emailEntity.getSmtpPassword();//瀵嗙爜
-            String recipientEmail = StringUtils.join(t482101H.getReceiver(), ",");//鏀朵欢浜�
-            Session session = Session.getInstance(properties, new Authenticator() {
-                @Override
-                protected PasswordAuthentication getPasswordAuthentication() {
-                    return new PasswordAuthentication(sendEmail, sendPassword);
-                }
-            });
-
-            MimeMessage message = new MimeMessage(session);
-            message.setFrom(new InternetAddress(sendEmail));
-            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
-            message.setSubject(t482101H.getSubject());
-
-            String Unique_ID = "<onBus_" + UUID.randomUUID().toString().toUpperCase() + "@mail.com>";//绯荤粺鍗曞彿鍞竴鐮�
-            message.setHeader("Message-ID", Unique_ID);//绯荤粺鍐呴儴鍞竴鐮�
-            t482101H.setMessageId(Unique_ID);//messageId璧嬪��
-
-            if (t482101H.getCc() != null && t482101H.getCc().size() > 0) {//鎶勯��
-                message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(StringUtils.join(t482101H.getCc(), ",")));
-            }
-            if (t482101H.getBcc() != null && t482101H.getBcc().size() > 0) {//瀵嗛��
-                message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(StringUtils.join(t482101H.getBcc(), ",")));
-            }
-
-            //鍒涘缓澶氶儴鍒嗘秷鎭�
-            Multipart multipart = new MimeMultipart();
-
-            MimeBodyPart textPart = new MimeBodyPart();
-            textPart.setText(t482101H.getContent());//鍐呭
-            multipart.addBodyPart(textPart);
-
-            //涓嬮潰闄勪欢鍐呭
-            if (StringUtils.isNotBlank(t482101H.getFileUNID())) {//鏈夐檮浠跺唴瀹�
-                //鑾峰彇鍒伴檮浠跺唴瀹�
-                List<AttachmentEntity> attachmentEntities = getAttachmentEntityList(t482101H.getFileUNID());
-                if (attachmentEntities != null && attachmentEntities.size() > 0) {
-                    for (AttachmentEntity a : attachmentEntities) {
-                        InputStream inputStream = new ByteArrayInputStream(a.getOriginalPicture());
-                        File file = new File(a.getOriginalFileName());
-                        FileUtils.copyInputStreamToFile(inputStream, file);
-                        MimeBodyPart bodyPart = new MimeBodyPart();
-                        bodyPart.attachFile(file);
-                        bodyPart.setFileName(a.getOriginalFileName());
-                        multipart.addBodyPart(bodyPart);
-                    }
-                }
-            }
-            message.setContent(multipart);
-            try {
-                if (StringUtils.isBlank(t482101H.getDocCode())) {//涓嶅湪鑽夌绠辨湁鍗曞彿
-                    saveReceivingMail(t482101H);//淇濆瓨鍚庡彂閫�
-                } else {
-                    t482101H.setMailType(2);//鍙戜欢绠辩姸鎬�
-                    updateMailDrafts(t482101H);//鏇存柊鎴愬彂浠剁
-                }
-                Transport.send(message);//鍙戦��
-            } catch (MessagingException m) {//鍙戦�佸紓甯稿鐞�
-                t482101H.setMailType(0);//鑽夌绠辩姸鎬�
-                updateMailDrafts(t482101H);//鏇存柊鎴愯崏绋跨
-                throw new Exception("鍙戦�侀偖浠跺紓甯�,閭欢宸蹭繚瀛樺湪鑽夌绠便�傚紓甯稿師鍥狅細" + m.getCause() != null ? m.getCause().getMessage() : m.getMessage());
-            }
-        } catch (Exception e) {
-            throw e;
-        }
-    }
-
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public Integer updateMailDrafts(t482101HEntity mail) {
         String sql = "set nocount on\n";
         try {
             sql += "update t482101H set sender=" + GridUtils.prossSqlParm(mail.getSender()) + ",receiver=" + GridUtils.prossSqlParm(StringUtils.join(mail.getReceiver(), ",")) + "," +
-                    "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + ",subject=" + GridUtils.prossSqlParm(mail.getSubject()) + "," +
-                    "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",file_unid=" + GridUtils.prossSqlParm(mail.getFileUNID()) + ",mailType=" + mail.getMailType() + "," +
+                    "cc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getCc(), ",")) + ",bcc=" + GridUtils.prossSqlParm(StringUtils.join(mail.getBcc(), ",")) + "," +
+                    "subject=" + GridUtils.prossSqlParm(mail.getSubject()) + ",messageId=" + GridUtils.prossSqlParm(mail.getMessageId()) + "," +
+                    "content=" + GridUtils.prossSqlParm(mail.getContent()) + ",attachment_list=" + GridUtils.prossSqlParm(mail.getAttachmentList()) + ",mailType=" + mail.getMailType() + "," +
                     "update_time=getdate() \n";
             sql += " where docCode=" + GridUtils.prossSqlParm(mail.getDocCode());
             sql += " select @@ROWCOUNT";
@@ -393,259 +313,6 @@
         } catch (Exception e) {
             throw e;
         }
-    }
-
-//    @Override
-//    public Integer deleteMailDrafts(String userCode, String docCode) {
-//        String sql = "set nocount on\n";
-//        try {
-//            sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
-//            sql += "delete t482101H where userCode =" + GridUtils.prossSqlParm(userCode) +
-//                    " and docCode in (select list from GetInStr(@docCode)) \n";
-//            sql += " select @@ROWCOUNT";
-//            return jdbcTemplate.queryForObject(sql, Integer.class);
-//        } catch (Exception e) {
-//            throw e;
-//        }
-//    }
-
-    /**
-     * 鏀朵欢绠辫繑鍥炵殑淇℃伅杩涜灏佽澶勭悊
-     *
-     * @param messages
-     * @return
-     * @throws MessagingException
-     * @throws IOException
-     */
-    public List<t482101HEntity> setMailContent(Message[] messages, String receiver, HttpServletRequest request) throws Exception {
-        try {
-            List<t482101HEntity> t482101HEntityList = new ArrayList<>();
-            HttpSession session = request.getSession();
-            List<String> messageIdList = getMessageIdList(receiver);
-            Message m = null;
-            List<String> deleteMsgId = new ArrayList<>();
-            for (int i = 0; i < messages.length; i++) {
-                m = messages[i];
-                String messageId = m.getHeader("Message-ID")[0];
-                if (messageIdList != null && messageIdList.contains(messageId)) {
-                    if (m.isSet(Flags.Flag.DELETED)) {//閭欢鏄惁闇�瑕佸垹闄�
-                        deleteMsgId.add(messageId);//鍒犻櫎鐨�
-                    }
-                    //宸茬粡瀛樺湪灏变笉闇�瑕佸啀娆″皝瑁呭鐞�
-                    continue;
-                }
-
-                t482101HEntity mail = new t482101HEntity();
-                mail.setMessageId(messageId);//鑾峰彇閭欢鍞竴ID
-                mail.setMailType(1);//鏀朵欢
-                if (m.isSet(Flags.Flag.SEEN)) {//閭欢宸叉爣璁颁负宸茶
-                    mail.setReadFlag(1);//宸茶
-                }
-                if (m.isExpunged()) {//妫�鏌ヤ竴涓秷鎭槸鍚﹀凡琚垹闄ゃ�傗��
-                    mail.setDeleteFlag(1);//宸插垹闄�
-                }
-                if (m.isSet(Flags.Flag.ANSWERED)) {//閭欢鏄惁宸插洖澶�
-
-                }
-                if (m.isSet(Flags.Flag.DRAFT)) {//鏄惁鏄崏绋跨
-                    mail.setMailType(0);//鏄崏绋跨
-                }
-
-                mail.setClassType(1);
-                mail.setUserCode((String) session.getAttribute(SessionKey.USERCODE));
-                mail.setUserName((String) session.getAttribute(SessionKey.USERNAME));
-                mail.setCompanyId((String) session.getAttribute(SessionKey.COMPANY_ID));
-                mail.setCompanyName((String) session.getAttribute(SessionKey.COMPANY_NAME));
-                mail.setSubject(m.getSubject());//鏍囬
-                Date date = m.getReceivedDate();//鏃堕棿
-                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                mail.setReceiveTime(formatter.format(date));
-                String result = "";
-                StringBuilder plainText = new StringBuilder();
-                if (m.isMimeType("text/plain")) {
-                    plainText.append(m.getContent());
-                } else if (m.isMimeType("text/html")) {//html鏍煎紡
-                    result = m.getContent().toString();
-                } else if (m.isMimeType("multipart/*")) {
-                    List<String> fileSeq = new ArrayList<>();
-                    MimeMultipart mimeMultipart = (MimeMultipart) m.getContent();
-                    String uuId = UUID.randomUUID().toString().toUpperCase();//鐢熸垚uuid
-                    result = getTextFromMimeMultipart(mimeMultipart, uuId, fileSeq, plainText, request);
-                    if (fileSeq.size() > 0) {//鏈夐檮浠跺唴瀹逛繚瀛�
-                        mail.setFileUNID(uuId + ";" + StringUtils.join(fileSeq, ";"));
-                        mail.setAttachmentList(uuId + ";" + StringUtils.join(fileSeq, ";"));
-                        mail.setAttachFlag(1);//鏈夐檮浠�
-                    }
-                } else {
-                    result = m.getContent().toString();
-                }
-                mail.setContent(result);//淇濆瓨鍐呭
-                mail.setPlainText(plainText.toString().trim());//鏄庢枃
-                String from = MimeUtility.decodeText(m.getFrom()[0].toString());
-                InternetAddress internetAddress = new InternetAddress(from);
-                mail.setSender(internetAddress.getAddress());//鍙戜欢浜�
-                from = MimeUtility.decodeText(m.getRecipients(Message.RecipientType.TO)[0].toString());
-                internetAddress = new InternetAddress(from);
-//                mail.setReceiver(internetAddress.getAddress());//鏀朵欢浜�
-                List<String> receivers = new ArrayList<>();//鎶勯�佷汉
-                receivers.add(receiver);
-                mail.setReceiver(receivers);//缁熶竴鎴愪竴涓敹浠朵汉
-
-                Address[] ccAddress = m.getRecipients(Message.RecipientType.CC);
-                if (ccAddress != null && ccAddress.length > 0) {
-                    List<String> cc = new ArrayList<>();//鎶勯�佷汉
-                    for (Address c : ccAddress) {
-                        from = MimeUtility.decodeText(c.toString());
-                        internetAddress = new InternetAddress(from);
-                        cc.add(internetAddress.getAddress());
-                    }
-                    mail.setCc(cc);
-                }
-                Address[] bccAddress = m.getRecipients(Message.RecipientType.BCC);
-                if (bccAddress != null && bccAddress.length > 0) {
-                    List<String> bcc = new ArrayList<>();//瀵嗛��
-                    for (Address c : bccAddress) {
-                        from = MimeUtility.decodeText(c.toString());
-                        internetAddress = new InternetAddress(from);
-                        bcc.add(internetAddress.getAddress());
-                    }
-                    mail.setBcc(bcc);//瀵嗛�佷汉
-                }
-                t482101HEntityList.add(mail);
-            }
-            if (deleteMsgId.size() > 0) {
-                //鍒犻櫎
-                deleteEmail(StringUtils.join(deleteMsgId, ","));
-            }
-            return t482101HEntityList;
-        } catch (Exception e) {
-            throw e;
-        }
-    }
-
-    // 杈呭姪鏂规硶锛岀敤浜庨�掑綊鑾峰彇绾枃鏈偖浠跺唴瀹�
-    private String getTextFromMimeMultipart(MimeMultipart mimeMultipart, String uuId, List<String> fileSeq, StringBuilder plainText, HttpServletRequest request) throws Exception {
-        int count = mimeMultipart.getCount();
-        if (count == 0) {
-            throw new MessagingException("Multipart with no body parts");
-        }
-        boolean multipartAlternative = isMultipartAlternative(mimeMultipart);
-        StringBuilder result = new StringBuilder();
-        if (multipartAlternative) {
-            for (int i = 0; i < count; i++) {
-                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
-                if (bodyPart.isMimeType("text/plain")) {//杩欎釜鏄幏鍙栫函鏂囨湰
-                    plainText.append(bodyPart.getContent());
-                }
-                if (bodyPart.isMimeType("text/html")) {//杩欎釜鏄幏鍙杊tml鏍煎紡
-                    result.append(bodyPart.getContent());
-                }
-            }
-        } else {
-            for (int i = 0; i < count; i++) {
-                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
-                if (bodyPart.isMimeType("image/*")) {//鍥剧墖
-                    String nextResult = result.toString();
-                    String unIdPath = saveFileAndImage(bodyPart, "image", uuId, request);
-                    String cId = ((IMAPBodyPart) bodyPart).getContentID();//鑾峰彇cId
-                    if (nextResult.contains(cId) && StringUtils.isNotBlank(unIdPath)) {//鏈夊祵濂楀唴瀹�
-                        nextResult = nextResult.replace("cid:" + cId + "", unIdPath);//鏇挎崲
-                        result.setLength(0);//娓呯┖鍏�
-                        result.append(nextResult);
-                    }
-                } else if (Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())) {//闄勪欢
-                    fileSeq.add(saveFileAndImage(bodyPart, Part.ATTACHMENT, uuId, request));
-                } else if (bodyPart.isMimeType("multipart/*")) {
-                    result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent(), uuId, fileSeq, plainText, request));
-                }
-            }
-        }
-        return result.toString();
-    }
-
-    // 杈呭姪鏂规硶锛屽垽鏂槸鍚︿负multipart/alternative绫诲瀷鐨勯偖浠�
-    private boolean isMultipartAlternative(MimeMultipart mimeMultipart) throws Exception {
-        boolean textPlainFound = false;
-        boolean textHtmlFound = false;
-        int count = mimeMultipart.getCount();
-        for (int i = 0; i < count; i++) {
-            BodyPart bodyPart = mimeMultipart.getBodyPart(i);
-            if (bodyPart.isMimeType("text/plain")) {
-                textPlainFound = true;
-            } else if (bodyPart.isMimeType("text/html")) {
-                textHtmlFound = true;
-            }
-        }
-        return textPlainFound && textHtmlFound;
-    }
-
-    private String saveFileAndImage(BodyPart bodyPart, String type, String unId, HttpServletRequest request) throws Exception {
-        try {
-            String fileName = MimeUtility.decodeText(bodyPart.getFileName());
-            if (type.equals("image")) {
-                String pattern = ".*\\.(jpg|jpeg|png|gif)$";
-                fileName = Pattern.matches(pattern, fileName) ? fileName : fileName + ".jpg";
-            }
-            File file = new File(fileName);
-            FileUtils.copyInputStreamToFile(bodyPart.getInputStream(), file);
-            AttachmentEntity attachmentEntity = new AttachmentEntity();
-            attachmentEntity.setDoccode("");
-            attachmentEntity.setRowId("");
-            attachmentEntity.setFormId(482101);
-            attachmentEntity.setUnid(unId);
-            attachmentEntity.setSeq(null);
-            attachmentEntity.setFieldId("file");
-            attachmentEntity.setPhysicalFile(file.getName());
-            attachmentEntity.setOriginalFileName(file.getName());
-            AttachmentIfc attachmentIfc = (AttachmentIfc) FactoryBean.getBean("AttachmentImpl");
-            //淇濆瓨闄勪欢
-            AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(attachmentEntity, file, "2");
-            if (type.equals("image")) {
-                //杈撳嚭 url
-//                return imgData.getImageUrl(attachmentWhereEntity.getUnid() + ";" + attachmentWhereEntity.getSeq(), null,
-//                        null, true, true, null);
-                DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
-                return shoppingImageServer + "/uploads/attachment/" + dataSourceEntity.getDbId() + "/482101/" + attachmentWhereEntity.getUnid() + "@p@" + attachmentWhereEntity.getSeq() + ".jpg";
-            } else if (type.equals(Part.ATTACHMENT)) {
-                return attachmentWhereEntity.getSeq() + "";
-            } else {
-                return null;
-            }
-        } catch (Exception e) {
-            throw e;
-        }
-    }
-
-    @Override
-    public List<AttachmentEntity> getAttachmentEntityList(String unIdSeq) {
-        String unId = null;
-        if (StringUtils.isBlank(unIdSeq)) {
-            return null;
-        }
-        String[] array = unIdSeq.split(";");
-        unId = array[0];//鍦ㄦ湁鍊兼椂鍊欑涓�涓繀瀹氭槸unId
-        ArrayList<String> seqs = new ArrayList<>(Arrays.asList(array));
-        seqs.remove(0);//鍘绘帀绗竴涓厓绱狅紙UNID锛�
-        String sql = " set nocount on \n"
-                + " declare @unid varchar(50) = " + GridUtils.prossSqlParm(unId) + "  \n";
-        sql += " select UNID,seq,DocCode,RowId,FieldId,FormId, \n"
-                + " PhysicalPath,PhysicalFile,OriginalFileName,FileSize,FileType, \n"
-                + " AuthorCode,AuthorName,SmallPicPath,UploadTime,OriginalPicture \n"
-                + " from _sys_Attachment \n"
-                + " where unid = @unid ";
-        if (seqs.size() > 0) {
-            sql += " and seq in(" + StringUtils.join(seqs, ",") + ")\n";
-        }
-        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql);
-        List<AttachmentEntity> attachmentList = new ArrayList<AttachmentEntity>();
-        for (int i = 0; list != null && i < list.size(); i++) {
-            AttachmentEntity attachment = new AttachmentEntity();
-            attachment.setOriginalFileName(list.get(i).get("OriginalFileName") == null ? null : (String) list.get(i).get("OriginalFileName"));
-            //闄勪欢澶勭悊
-            attachment.setOriginalPicture(list.get(i).get("OriginalPicture") == null ? null : (byte[]) list.get(i).get("OriginalPicture"));
-            attachmentList.add(attachment);
-        }
-        return attachmentList;
     }
 
     @Override
@@ -665,12 +332,35 @@
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
-    public void updateRead(String docCode) {
+    public void updateRead(String docCode, boolean status) {
         String sql = " set nocount on \n";
         try {
             sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
-            sql += "update t482101H set read_flag=1 where docCode in (select list from GetInStr(@docCode))\n";
+            sql += "update t482101H set read_flag=" + (status ? 1 : 0) + " where docCode in (select list from GetInStr(@docCode))\n";
+            sql += "select @@ROWCOUNT";
+            jdbcTemplate.queryForObject(sql, Integer.class);
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @Override
+    public void updateMailType(String docCode, Integer folderId, String tagId) {
+        String sql = " set nocount on \n";
+        try {
+            boolean bol = false;
+            sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
+            sql += "update t482101H set \n";
+            if (!folderId.equals(0)) {
+                sql += " folder_id=" + folderId + "\n";
+                bol = true;
+            }
+            if (StringUtils.isNotBlank(tagId)) {
+                sql += (bol ? "," : "") + " tag_list='," + tagId + ",' \n";
+            }
+            sql += " where docCode in (select list from GetInStr(@docCode))\n";
             sql += "select @@ROWCOUNT";
             jdbcTemplate.queryForObject(sql, Integer.class);
         } catch (Exception e) {
@@ -709,15 +399,19 @@
                             }
                             int allCount = 0;
                             int count = 0;
-                            for (T482102Entity a:account) {
+                            for (T482102Entity a : account) {
                                 MailModuleEntity.MailCode nextCode = new MailModuleEntity.MailCode();
                                 String eMail = (mailType == 1 ? a.getReceiveEmail() : a.getSmtpEmail());//鑾峰彇閭璐﹀彿
-                                nextCode.setKey(mailType == 1 ? "page" : "page");
+                                nextCode.setKey(mailType == 1 ? "receiver" : "sender");
                                 nextCode.setMailName(eMail);
                                 nextCode.setMailType(m.getMailType());
-                                if (userMail.size() > 0) {
-                                    count = (mailType == 1 ? (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail)).count() :
-                                            (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getSender().contains(eMail)).count());
+//                                if (userMail.size() > 0) {
+//                                    count = (mailType == 1 ? (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail)).count() :
+//                                            (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getSender().contains(eMail)).count());
+//                                    nextCode.setTotal(count);
+//                                }
+                                if (mailType == 1) {//鏄敹浠剁锛岀粺璁℃湭璇绘暟閲�
+                                    count = (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail) && s.getReadFlag().equals(0)).count();
                                     nextCode.setTotal(count);
                                 }
                                 codeList.add(nextCode);
@@ -731,13 +425,13 @@
                     case 3://寰呭鐞嗛偖浠�
                         m.setChildren(new ArrayList<>());
                         if (userMail.size() > 0) {
-                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals("1")).count());
+                            m.setTotal((int) userMail.stream().filter(s -> s.getHandle().equals(1)).count());
                         }
                         break;
                     case 4://鏈閭欢
                         m.setChildren(new ArrayList<>());
                         if (userMail.size() > 0) {
-                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals("0")).count());
+                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals(0)).count());
                         }
                         break;
                     case 5://缇ら偖绠�
@@ -752,4 +446,93 @@
             throw e;
         }
     }
+
+    @Override
+    public List<MailModuleBelowEntity> getMailModuleBelowList(String userCode) {
+        List<MailModuleBelowEntity> below = MailModuleBelowEntity.setMailInitial();
+        try {
+            for (MailModuleBelowEntity b : below) {
+                String key = b.getKey();
+                if (key.equals("moduleBelowA")) {//鏂囦欢澶�
+                    List<T482107Entity> t482107 = mailFolderIfc.getMailFolder(userCode);
+                    b.setList(MailFolder.getFolderModule(t482107, ""));
+                }
+                if (key.equals("moduleBelowB")) {//鏍囩閭欢
+                    List<T482115Entity> tag = mailTagIfc.getTagList(userCode, "", -1);
+                    b.setList(MailTag.getTagModule(tag));
+                }
+                if (key.equals("moduleBelowC")) {//鏄剧ず鏇村
+                    List<MailModuleBelowEntity> CList = new ArrayList<>();
+                    MailModuleBelowEntity delete = new MailModuleBelowEntity();
+                    delete.setKey("deleteMail");
+                    delete.setName("宸插垹闄ら偖浠�");
+                    CList.add(delete);
+                    MailModuleBelowEntity waste = new MailModuleBelowEntity();
+                    waste.setKey("wasteMail");
+                    waste.setName("鍨冨溇閭欢");
+                    CList.add(waste);
+                    MailModuleBelowEntity track = new MailModuleBelowEntity();
+                    track.setKey("trackMail");
+                    track.setName("杩借釜淇℃伅");
+                    CList.add(track);
+                    b.setList(CList);
+                }
+            }
+            return below;
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void updateMailHandle(String handleTime, String docCode) {
+        String sql = " set nocount on \n";
+        try {
+            sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
+            sql += "update t482101H set handle_time=" + (StringUtils.isBlank(handleTime) ? "null" : GridUtils.prossSqlParm(handleTime)) +
+                    " where docCode in (select list from GetInStr(@docCode))\n";
+            sql += "select @@ROWCOUNT";
+            jdbcTemplate.queryForObject(sql, Integer.class);
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @Override
+    public Integer getMailTotal(String email, Integer mailType, boolean isNoRead, String id, String userCode) {
+        String sql = "set nocount on\n";
+        try {
+            sql += "select count(*) from t482101H ";
+            sql += " where userCode=" + GridUtils.prossSqlParm(userCode);
+            if (mailType < 3) {
+                sql += " and mailType=" + mailType;//0锛氳崏绋跨 1锛氭敹浠剁 2锛氬彂浠剁
+            }
+            if (StringUtils.isNotBlank(email)) {
+                if (mailType == 1) {
+                    sql += " and receiver like '%" + email + "%'";
+                } else if (mailType == 2) {
+                    sql += " and sender =" + GridUtils.prossSqlParm(email);
+                } else if (mailType == 3) {
+                    sql += " and isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate() ";
+                }
+            }
+            if (isNoRead) {//0琛ㄧず鏈锛�1琛ㄧず宸茶
+                sql += " and isnull(read_flag,0) = 0";
+            }
+            if (StringUtils.isNotBlank(id)) {//鏂囦欢澶�
+                String[] type = id.split("_");
+                if (type.length == 2) {
+                    if (type[0].equals("folder")) {
+                        sql += " and folder_id=" + type[1];
+                    } else if (type[0].equals("tag")) {
+                        sql += " and tag_list like '%," + type[1] + ",%'";
+                    }
+                }
+            }
+            return jdbcTemplate.queryForObject(sql, Integer.class);
+        } catch (Exception e) {
+            return 0;
+        }
+    }
 }

--
Gitblit v1.8.0