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