xinyb
6 天以前 ee2316e2cb7afde1c54f5e4216a1b0d1e055749e
提交 | 用户 | age
385e2d 1 package com.yc.crm.mail.action;
X 2
53241c 3 import com.yc.crm.mail.entity.FolderEntity;
b7ef4b 4 import com.yc.crm.mail.entity.MailModuleBelowEntity;
385e2d 5 import com.yc.crm.mail.entity.T482107Entity;
X 6 import com.yc.crm.mail.service.MailFolderIfc;
7 import com.yc.crm.mail.util.AllBackMsg;
8 import com.yc.entity.DataSourceEntity;
9 import com.yc.multiData.MultiDataSource;
10 import com.yc.multiData.SpObserver;
11 import com.yc.utils.SessionKey;
f5cc47 12 import org.apache.commons.lang3.StringUtils;
385e2d 13 import org.springframework.beans.factory.annotation.Autowired;
X 14 import org.springframework.web.bind.annotation.*;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18 import javax.servlet.http.HttpSession;
53241c 19 import java.util.ArrayList;
658898 20 import java.util.HashMap;
385e2d 21 import java.util.List;
658898 22 import java.util.Map;
53241c 23 import java.util.stream.Collectors;
385e2d 24
X 25 /**
26  * @BelongsProject: eCoWorksV3
27  * @BelongsPackage: com.yc.crm.mail.action
28  * @author: xinyb
29  * @CreateTime: 2024-08-23  09:23
30  * @Description:邮件文件夹
31  */
32 @CrossOrigin
33 @RestController
f5cc47 34 @RequestMapping("/crm/mail/folder")
385e2d 35 public class MailFolder {
658898 36
X 37     /**
38      * 要获取rowId直接调用接口 http://yingchen.onbus.cn:9010/getRowid.do
39      */
385e2d 40     @Autowired
X 41     MailFolderIfc mailFolderIfc;
42
43     /**
f5cc47 44      * 添加邮件文件夹
385e2d 45      *
X 46      * @param folder
47      * @param request
48      * @param response
49      * @return
50      */
51     @PostMapping("/addFolder.do")
52     public AllBackMsg addFolder(@RequestBody T482107Entity folder, HttpServletRequest request, HttpServletResponse response) {
53         AllBackMsg msg = new AllBackMsg();
54         try {
55
56             HttpSession session = request.getSession();
57             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
58             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
59             String userCode = (String) session.getAttribute(SessionKey.USERCODE);
60             String userName = (String) session.getAttribute(SessionKey.USER_NAME);
61             folder.setCompanyId(companyId);
62             folder.setCompanyName(companyName);
63             folder.setUserCode(userCode);
64             folder.setUserName(userName);
65             DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
66             SpObserver.setDBtoInstance("_" + dataSource.getDbId());
658898 67             String rowId = mailFolderIfc.saveFolder(folder);
X 68             Map<String, Object> map = new HashMap<>();
69             if (StringUtils.isNotBlank(rowId)) {
70                 map.put("cod", 0);
71                 map.put("rowId", rowId);
72                 msg.setSuccess("已保存", map);
73             } else {
74                 map.put("cod", -1);
75                 map.put("msg", "保存后返回rowId出错");
76                 msg.setSuccess("已保存", map);
77             }
385e2d 78         } catch (Exception e) {
f5cc47 79             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 80         } finally {
X 81             SpObserver.setDBtoInstance();
82         }
83         return msg;
84     }
85
53241c 86
385e2d 87     /**
f5cc47 88      * 修改邮件文件夹
385e2d 89      *
X 90      * @param folder
91      * @param request
92      * @param response
93      * @return
94      */
95     @PostMapping("/updateFolder.do")
3c2c1b 96     public AllBackMsg updateFolder(@RequestBody T482107Entity folder, HttpServletRequest request, HttpServletResponse response) {
385e2d 97         AllBackMsg msg = new AllBackMsg();
X 98         try {
658898 99             if (folder.getFolderId() == null || folder.getFolderId().equals(0)) {
f5cc47 100                 msg.setFail("缺少文本夹ID值,请检查");
X 101                 return msg;
102             }
385e2d 103             HttpSession session = request.getSession();
f5cc47 104             String userCode = (String) session.getAttribute(SessionKey.USERCODE);
X 105             if (StringUtils.isBlank(userCode)) {
106                 msg.setFail("登录用户已过期,请检查");
107                 return msg;
108             }
109             folder.setUserCode(userCode);
385e2d 110             DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
X 111             SpObserver.setDBtoInstance("_" + dataSource.getDbId());
112             mailFolderIfc.updateFolder(folder);
f5cc47 113             msg.setOk("已更新");
385e2d 114         } catch (Exception e) {
f5cc47 115             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 116         } finally {
X 117             SpObserver.setDBtoInstance();
118         }
119         return msg;
120     }
121
122     /**
f5cc47 123      * 删除邮件文件夹
385e2d 124      *
X 125      * @param account
126      * @param request
127      * @param response
128      * @return
129      */
130     @PostMapping("/deleteFolder.do")
131     public AllBackMsg deleteFolder(@RequestParam(defaultValue = "0") Integer folderId, HttpServletRequest request, HttpServletResponse response) {
132         AllBackMsg msg = new AllBackMsg();
133         try {
53241c 134             if (folderId.equals(0)) {
385e2d 135                 msg.setFail("邮件文件夹编号ID获取不到");
X 136                 return msg;
137             }
138             HttpSession session = request.getSession();
139             String userCode = (String) session.getAttribute(SessionKey.USERCODE);
f5cc47 140             if (StringUtils.isBlank(userCode)) {
X 141                 msg.setFail("登录用户已过期,请检查");
142                 return msg;
143             }
385e2d 144             DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
X 145             SpObserver.setDBtoInstance("_" + dataSource.getDbId());
146             Integer cont = mailFolderIfc.deleteFolder(userCode, folderId);
147             if (cont > 0) {
f5cc47 148                 msg.setOk("已删除");
385e2d 149             }
X 150         } catch (Exception e) {
f5cc47 151             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 152         } finally {
X 153             SpObserver.setDBtoInstance();
154         }
155         return msg;
156     }
157
158     /**
159      * @param search   搜索
160      * @param request
161      * @param response
162      * @return
163      */
164     @GetMapping("/getFolder.do")
b7ef4b 165     public AllBackMsg getFolder(HttpServletRequest request, HttpServletResponse response) {
385e2d 166         AllBackMsg msg = new AllBackMsg();
X 167         try {
168             HttpSession session = request.getSession();
169             String userCode = (String) session.getAttribute(SessionKey.USERCODE);
f5cc47 170             if (StringUtils.isBlank(userCode)) {
X 171                 msg.setFail("登录用户已过期,请检查");
172                 return msg;
173             }
385e2d 174             DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
X 175             SpObserver.setDBtoInstance("_" + dataSource.getDbId());
b7ef4b 176             List<T482107Entity> t482107Entities = mailFolderIfc.getMailFolder(userCode);
385e2d 177             if (t482107Entities.size() > 0) {
658898 178                 //返回树结构
53241c 179                 msg.setSuccess("执行成功", getFolderList(t482107Entities, ""));
385e2d 180             }
X 181         } catch (Exception e) {
f5cc47 182             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
385e2d 183         } finally {
X 184             SpObserver.setDBtoInstance();
185         }
186         return msg;
187     }
53241c 188
X 189     /**
190      * 文件夹树结构
191      *
192      * @param t482107
193      * @param rowId
194      * @return
195      */
196     public static List<FolderEntity> getFolderList(List<T482107Entity> t482107, String rowId) {
197         List<FolderEntity> folder = new ArrayList<>();
198         try {
199             for (T482107Entity t : t482107) {
200                 if (folder.stream().filter(f -> f.getParentRowId().equals(rowId)).count() == 0) {
201                     List<T482107Entity> fo = t482107.stream().filter(o -> o.getParentRowId().equals(rowId)).collect(Collectors.toList());
202                     if (fo.size() > 0) {
203                         for (T482107Entity y : fo) {
204                             FolderEntity folderEntity = new FolderEntity();
205                             folderEntity.setFolderId(y.getFolderId());
206                             folderEntity.setFolderName(y.getFolderName());
207                             folderEntity.setRowId(y.getRowId());
208                             folderEntity.setParentRowId(y.getParentRowId());
209                             folderEntity.setTreeControl(y.getTreeControl());
f632e7 210                             if (!y.getRowId().equals(y.getParentRowId())) {
X 211                                 folderEntity.setList(getFolderList(t482107, y.getRowId()));
212                             }
53241c 213                             folder.add(folderEntity);
X 214                         }
215                     }
216                 }
217             }
218             return folder;
219         } catch (Exception e) {
220             throw e;
221         }
222     }
b7ef4b 223
X 224     /**
225      * 文件夹树结构
226      *
227      * @param t482107
228      * @param rowId
229      * @return
230      */
231     public static List<MailModuleBelowEntity> getFolderModule(List<T482107Entity> t482107, String rowId) {
232         List<MailModuleBelowEntity> folder = new ArrayList<>();
233         try {
234             for (T482107Entity t : t482107) {
235                 if (folder.stream().filter(f -> f.getParentKey().equals(rowId)).count() == 0) {
236                     List<T482107Entity> fo = t482107.stream().filter(o -> o.getParentRowId().equals(rowId)).collect(Collectors.toList());
237                     if (fo.size() > 0) {
238                         for (T482107Entity y : fo) {
239                             MailModuleBelowEntity folder1 = new MailModuleBelowEntity();
aad276 240                             folder1.setId(y.getFolderId());
X 241                             folder1.setType("folder");
b7ef4b 242                             folder1.setKey(y.getRowId());
X 243                             folder1.setParentKey(y.getParentRowId());
244                             folder1.setName(y.getFolderName());
f632e7 245                             if (!y.getRowId().equals(y.getParentRowId())) {
X 246                                 folder1.setList(getFolderModule(t482107, y.getRowId()));
247                             }
b7ef4b 248                             folder.add(folder1);
X 249                         }
250                     } else {
251                         break;
252                     }
253                 }
254             }
255             return folder;
256         } catch (Exception e) {
257             throw e;
258         }
259     }
385e2d 260 }