From aad276da26b3b44b7622343fa0bf15583e803585 Mon Sep 17 00:00:00 2001
From: xinyb <574600396@qq.com>
Date: 星期五, 27 九月 2024 11:29:01 +0800
Subject: [PATCH] CRM邮件文件夹和标签

---
 src/com/yc/crm/mail/entity/MailModuleBelowEntity.java |    5 +
 src/com/yc/crm/mail/action/MailController.java        |  123 ++++++++++++++++++++++--
 src/com/yc/crm/mail/action/MailTag.java               |    4 
 src/com/yc/crm/mail/action/MailFolder.java            |    2 
 src/com/yc/crm/mail/service/MailImpl.java             |   66 ++++++++++++
 src/com/yc/crm/mail/service/MailIfc.java              |   41 +++++++-
 6 files changed, 220 insertions(+), 21 deletions(-)

diff --git a/src/com/yc/crm/mail/action/MailController.java b/src/com/yc/crm/mail/action/MailController.java
index 5649883..fcfabb9 100644
--- a/src/com/yc/crm/mail/action/MailController.java
+++ b/src/com/yc/crm/mail/action/MailController.java
@@ -82,6 +82,7 @@
         }
         return msg;
     }
+
     /**
      * 宸﹁竟缁撴瀯涓嬪眰
      *
@@ -99,7 +100,7 @@
             }
             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭�
             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧�
-            List<MailModuleBelowEntity> list =emailIfc.getMailModuleBelowList(userCode);
+            List<MailModuleBelowEntity> list = emailIfc.getMailModuleBelowList(userCode);
             msg.setSuccess("鎵ц鎴愬姛", list);
         } catch (Exception e) {
             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
@@ -134,14 +135,16 @@
             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭�
             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧�
             List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode, page, limit);
+            Map<String, Object> map = new HashMap<>();
+            map.put("page", page);
+            map.put("limit", limit);
             if (t482101HEntityList.size() > 0) {
-                Map<String,Object> map=new HashMap<>();
-                map.put("page",page);
-                map.put("limit",limit);
-                map.put("total",emailIfc.getMailTotal(mail,mailType,isNoRead,userCode));
-                map.put("list",t482101HEntityList);
-                msg.setSuccess("鎵ц瀹屾垚", map);
+                map.put("total", emailIfc.getMailTotal(mail, mailType, isNoRead, null, userCode));
+                map.put("list", t482101HEntityList);
+            } else {
+                map.put("list", new ArrayList<>());
             }
+            msg.setSuccess("鎵ц瀹屾垚", map);
         } catch (Exception e) {
             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
         } finally {
@@ -175,14 +178,16 @@
             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭�
             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧�
             List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode, page, limit);
+            Map<String, Object> map = new HashMap<>();
+            map.put("page", page);
+            map.put("limit", limit);
             if (t482101HEntityList.size() > 0) {
-                Map<String,Object> map=new HashMap<>();
-                map.put("page",page);
-                map.put("limit",limit);
-                map.put("total",emailIfc.getMailTotal(mail,3,false,userCode));
-                map.put("list",t482101HEntityList);
-                msg.setSuccess("鎵ц瀹屾垚", map);
+                map.put("total", emailIfc.getMailTotal(mail, 3, false, null, userCode));
+                map.put("list", t482101HEntityList);
+            } else {
+                map.put("list", new ArrayList<>());
             }
+            msg.setSuccess("鎵ц瀹屾垚", map);
         } catch (Exception e) {
             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
         } finally {
@@ -530,6 +535,98 @@
     }
 
     /**
+     * 绉诲姩閭欢鍒嗙被
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @PostMapping("/updateMailType.do")
+    public AllBackMsg updateMailType(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        AllBackMsg msg = new AllBackMsg();
+        try {
+            HttpSession session = request.getSession();
+            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛
+            if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫
+                msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅");
+                return msg;
+            }
+            if (map.get("docCode") == null) {
+                msg.setFail("鑾峰彇涓嶅埌绉诲姩閭欢缂栧彿docCode");
+                return msg;
+            }
+            String docCode = (String) map.get("docCode");
+            Integer folderId = map.get("folderId") == null ? 0 : (Integer) map.get("folderId");
+            List<String> tagArray = (List<String>) map.get("tagId");
+            if (folderId.equals(0) && (tagArray == null || tagArray.size() == 0)) {
+                msg.setFail("绉诲姩閭欢鍒嗙被涓嶈兘涓虹┖");
+                return msg;
+            }
+            String tagId = "";
+            if (tagArray != null && tagArray.size() > 0) {
+                tagId = StringUtils.join(tagArray, ",");
+            }
+            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭�
+            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧�
+            emailIfc.updateMailType(docCode, folderId, tagId);
+            msg.setOk("绉诲姩鎴愬姛");
+        } catch (Exception e) {
+            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
+        } finally {
+            SpObserver.setDBtoInstance();
+        }
+        return msg;
+    }
+
+    /**
+     * 鍔犺浇涓嶅悓鐩綍閲岀殑閭欢
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @GetMapping("/classificationMail.do")
+    public AllBackMsg classificationMail(@RequestParam(defaultValue = "-1") Integer id, String type, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,
+                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
+        AllBackMsg msg = new AllBackMsg();
+        try {
+            HttpSession session = request.getSession();
+            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//褰撳墠鐧诲綍鐢ㄦ埛
+            if (StringUtils.isBlank(userCode)) {//鑾峰彇涓嶅埌褰撳墠鐢ㄦ埛鐩存帴缁撴潫
+                msg.setFail("鑾峰彇涓嶅埌鐢ㄦ埛淇℃伅");
+                return msg;
+            }
+            if (id == null || id.equals(-1)) {
+                msg.setFail("鑾峰彇涓嶅埌鏂囦欢Id");
+                return msg;
+            }
+            if (StringUtils.isBlank(type)) {
+                msg.setFail("鑾峰彇涓嶅埌鏂囦欢绫诲瀷");
+                return msg;
+            }
+            type = type + "_" + id;//缁勮涓�
+            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧愪俊鎭�
+            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//鍒囨崲鏁版嵁婧�
+            List<t482101HList> t482101 = emailIfc.getFolderMailList(type, userCode, page, limit);
+            Map<String, Object> map = new HashMap<>();
+            map.put("page", page);
+            map.put("limit", limit);
+            if (t482101.size() > 0) {
+                map.put("total", emailIfc.getMailTotal(null, 6, false, type, userCode));
+                map.put("list", t482101);
+            } else {
+                map.put("list", new ArrayList<>());
+            }
+            msg.setSuccess("鎵ц瀹屾垚", map);
+        } catch (Exception e) {
+            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
+        } finally {
+            SpObserver.setDBtoInstance();
+        }
+        return msg;
+    }
+
+    /**
      * 寰呭鐞嗛偖浠�
      *
      * @param request
diff --git a/src/com/yc/crm/mail/action/MailFolder.java b/src/com/yc/crm/mail/action/MailFolder.java
index 1753624..a7e5b4d 100644
--- a/src/com/yc/crm/mail/action/MailFolder.java
+++ b/src/com/yc/crm/mail/action/MailFolder.java
@@ -237,6 +237,8 @@
                     if (fo.size() > 0) {
                         for (T482107Entity y : fo) {
                             MailModuleBelowEntity folder1 = new MailModuleBelowEntity();
+                            folder1.setId(y.getFolderId());
+                            folder1.setType("folder");
                             folder1.setKey(y.getRowId());
                             folder1.setParentKey(y.getParentRowId());
                             folder1.setName(y.getFolderName());
diff --git a/src/com/yc/crm/mail/action/MailTag.java b/src/com/yc/crm/mail/action/MailTag.java
index f9a664d..11ef9c6 100644
--- a/src/com/yc/crm/mail/action/MailTag.java
+++ b/src/com/yc/crm/mail/action/MailTag.java
@@ -181,15 +181,19 @@
         List<MailModuleBelowEntity> tagList = new ArrayList<>();
         MailModuleBelowEntity tag1 = new MailModuleBelowEntity();
         tag1.setKey("systemTag");
+        tag1.setType("tag");
         tag1.setName("绯荤粺鏍囩");
         MailModuleBelowEntity tag2 = new MailModuleBelowEntity();
         tag2.setKey("customTag");
+        tag2.setType("tag");
         tag2.setName("鑷畾涔夋爣绛�");
         try {
             List<MailModuleBelowEntity> system = new ArrayList<>();
             List<MailModuleBelowEntity> custom = new ArrayList<>();
             for (T482115Entity t : T482115) {
                 MailModuleBelowEntity tag = new MailModuleBelowEntity();
+                tag.setId(t.getTagId());
+                tag.setType("tag");
                 tag.setName(t.getTagName());
                 if (t.isSystemFlag()) {
                     tag.setKey("systemTag" + t.getTagId());
diff --git a/src/com/yc/crm/mail/entity/MailModuleBelowEntity.java b/src/com/yc/crm/mail/entity/MailModuleBelowEntity.java
index 7f0247e..fb04520 100644
--- a/src/com/yc/crm/mail/entity/MailModuleBelowEntity.java
+++ b/src/com/yc/crm/mail/entity/MailModuleBelowEntity.java
@@ -14,9 +14,11 @@
  */
 @Data
 public class MailModuleBelowEntity {
+    private Integer id = 0;//鍞竴鍊�
     private String key;//key
     private String parentKey;//鐖秌ey
     private String name;//鍚嶇О
+    private String type;//绫诲瀷
     private Integer number = 0;//鏁伴噺
     private Object list;//涓嬭妭鐐�
 
@@ -25,13 +27,16 @@
         MailModuleBelowEntity a = new MailModuleBelowEntity();
         a.setKey("moduleBelowA");
         a.setName("鏂囦欢澶�");
+        a.setType("folder");
         list1.add(a);
         MailModuleBelowEntity b = new MailModuleBelowEntity();
         b.setKey("moduleBelowB");
         b.setName("鏍囩閭欢");
+        b.setType("tag");
         list1.add(b);
         MailModuleBelowEntity c = new MailModuleBelowEntity();
         c.setKey("moduleBelowC");
+        c.setType("other");
         c.setName("鏄剧ず鏇村");
         list1.add(c);
         return list1;
diff --git a/src/com/yc/crm/mail/service/MailIfc.java b/src/com/yc/crm/mail/service/MailIfc.java
index 2a33c37..43b66b3 100644
--- a/src/com/yc/crm/mail/service/MailIfc.java
+++ b/src/com/yc/crm/mail/service/MailIfc.java
@@ -80,14 +80,23 @@
      * @param isRead   鏄惁宸茶
      * @return
      */
-    List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode,Integer page,Integer limit);
+    List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode, Integer page, Integer limit);
 
     /**
      * 鑾峰彇寰呭鐞嗛偖浠跺垪琛�
+     *
      * @param email
      * @return
      */
-    List<t482101HList> getHandleMailList(String email,String userCode,Integer page,Integer limit);
+    List<t482101HList> getHandleMailList(String email, String userCode, Integer page, Integer limit);
+
+    /**
+     * 鑾峰彇鏂囦欢澶归偖浠跺垪琛�
+     *
+     * @param email
+     * @return
+     */
+    List<t482101HList> getFolderMailList(String type, String userCode, Integer page, Integer limit) throws Exception;
 
     /**
      * 鑾峰彇鐢ㄦ埛鐨勫叏閮ㄩ偖浠�
@@ -125,7 +134,18 @@
      *
      * @param docCode
      */
-    abstract void updateRead(String docCode,boolean status);
+    abstract void updateRead(String docCode, boolean status);
+
+    /**
+     * 鏇存柊绉诲姩閭欢浣嶇疆
+     *
+     * @param userCode
+     * @param docCode
+     * @param folderId
+     * @param tagId
+     * @return
+     */
+    abstract void updateMailType(String docCode, Integer folderId, String tagId);
 
     /**
      * 缁戝畾璐﹀彿鐨勯偖绠辨ā鍧�
@@ -136,12 +156,23 @@
     abstract List<MailModuleEntity> getMailModuleList(String userCode);
 
     abstract List<MailModuleBelowEntity> getMailModuleBelowList(String userCode);
+
     /**
      * 寰呭鐞嗛偖浠�
+     *
      * @param handleTime
      * @param docCode
      */
-    abstract void updateMailHandle(String handleTime,String docCode);
+    abstract void updateMailHandle(String handleTime, String docCode);
 
-    abstract Integer getMailTotal(String email, Integer mailType, boolean isNoRead,String userCode);
+    /**
+     * 鏌ユ�绘暟
+     * @param email
+     * @param mailType
+     * @param isNoRead
+     * @param id
+     * @param userCode
+     * @return
+     */
+    abstract Integer getMailTotal(String email, Integer mailType, boolean isNoRead, String id, String userCode);
 }
diff --git a/src/com/yc/crm/mail/service/MailImpl.java b/src/com/yc/crm/mail/service/MailImpl.java
index d72ccf3..48a224d 100644
--- a/src/com/yc/crm/mail/service/MailImpl.java
+++ b/src/com/yc/crm/mail/service/MailImpl.java
@@ -259,6 +259,32 @@
     }
 
     @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;
+        }
+    }
+
+    @Override
     public List<t482101HList> getUserMailList(String userCode) {
         String sql = " set nocount on \n";
         try {
@@ -313,6 +339,28 @@
         try {
             sql += "declare @docCode varchar(200) ='" + 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) {
@@ -452,7 +500,7 @@
     }
 
     @Override
-    public Integer getMailTotal(String email, Integer mailType, boolean isNoRead, String userCode) {
+    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 ";
@@ -461,15 +509,27 @@
                 sql += " and mailType=" + mailType;//0锛氳崏绋跨 1锛氭敹浠剁 2锛氬彂浠剁
             }
             if (StringUtils.isNotBlank(email)) {
-                if (mailType == 1 || mailType == 3) {
-                    sql += " and receiver like '%" + email + "%' and isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate() ";
+                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