package com.yc.crm.mail.action;
|
|
import com.yc.crm.mail.entity.FolderEntity;
|
import com.yc.crm.mail.entity.MailModuleBelowEntity;
|
import com.yc.crm.mail.entity.T482107Entity;
|
import com.yc.crm.mail.service.MailFolderIfc;
|
import com.yc.crm.mail.util.AllBackMsg;
|
import com.yc.entity.DataSourceEntity;
|
import com.yc.multiData.MultiDataSource;
|
import com.yc.multiData.SpObserver;
|
import com.yc.utils.SessionKey;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* @BelongsProject: eCoWorksV3
|
* @BelongsPackage: com.yc.crm.mail.action
|
* @author: xinyb
|
* @CreateTime: 2024-08-23 09:23
|
* @Description:邮件文件夹
|
*/
|
@CrossOrigin
|
@RestController
|
@RequestMapping("/crm/mail/folder")
|
public class MailFolder {
|
|
/**
|
* 要获取rowId直接调用接口 http://yingchen.onbus.cn:9010/getRowid.do
|
*/
|
@Autowired
|
MailFolderIfc mailFolderIfc;
|
|
/**
|
* 添加邮件文件夹
|
*
|
* @param folder
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/addFolder.do")
|
public AllBackMsg addFolder(@RequestBody T482107Entity folder, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
|
HttpSession session = request.getSession();
|
String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
|
String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
String userName = (String) session.getAttribute(SessionKey.USER_NAME);
|
folder.setCompanyId(companyId);
|
folder.setCompanyName(companyName);
|
folder.setUserCode(userCode);
|
folder.setUserName(userName);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
String rowId = mailFolderIfc.saveFolder(folder);
|
Map<String, Object> map = new HashMap<>();
|
if (StringUtils.isNotBlank(rowId)) {
|
map.put("cod", 0);
|
map.put("rowId", rowId);
|
msg.setSuccess("已保存", map);
|
} else {
|
map.put("cod", -1);
|
map.put("msg", "保存后返回rowId出错");
|
msg.setSuccess("已保存", map);
|
}
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
|
/**
|
* 修改邮件文件夹
|
*
|
* @param folder
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/updateFolder.do")
|
public AllBackMsg updateFolder(@RequestBody T482107Entity folder, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if (folder.getFolderId() == null || folder.getFolderId().equals(0)) {
|
msg.setFail("缺少文本夹ID值,请检查");
|
return msg;
|
}
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
if (StringUtils.isBlank(userCode)) {
|
msg.setFail("登录用户已过期,请检查");
|
return msg;
|
}
|
folder.setUserCode(userCode);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
mailFolderIfc.updateFolder(folder);
|
msg.setOk("已更新");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 删除邮件文件夹
|
*
|
* @param account
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/deleteFolder.do")
|
public AllBackMsg deleteFolder(@RequestParam(defaultValue = "0") Integer folderId, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if (folderId.equals(0)) {
|
msg.setFail("邮件文件夹编号ID获取不到");
|
return msg;
|
}
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
if (StringUtils.isBlank(userCode)) {
|
msg.setFail("登录用户已过期,请检查");
|
return msg;
|
}
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
Integer cont = mailFolderIfc.deleteFolder(userCode, folderId);
|
if (cont > 0) {
|
msg.setOk("已删除");
|
}
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* @param search 搜索
|
* @param request
|
* @param response
|
* @return
|
*/
|
@GetMapping("/getFolder.do")
|
public AllBackMsg getFolder(HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
if (StringUtils.isBlank(userCode)) {
|
msg.setFail("登录用户已过期,请检查");
|
return msg;
|
}
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
List<T482107Entity> t482107Entities = mailFolderIfc.getMailFolder(userCode);
|
if (t482107Entities.size() > 0) {
|
//返回树结构
|
msg.setSuccess("执行成功", getFolderList(t482107Entities, ""));
|
}
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 文件夹树结构
|
*
|
* @param t482107
|
* @param rowId
|
* @return
|
*/
|
public static List<FolderEntity> getFolderList(List<T482107Entity> t482107, String rowId) {
|
List<FolderEntity> folder = new ArrayList<>();
|
try {
|
for (T482107Entity t : t482107) {
|
if (folder.stream().filter(f -> f.getParentRowId().equals(rowId)).count() == 0) {
|
List<T482107Entity> fo = t482107.stream().filter(o -> o.getParentRowId().equals(rowId)).collect(Collectors.toList());
|
if (fo.size() > 0) {
|
for (T482107Entity y : fo) {
|
FolderEntity folderEntity = new FolderEntity();
|
folderEntity.setFolderId(y.getFolderId());
|
folderEntity.setFolderName(y.getFolderName());
|
folderEntity.setRowId(y.getRowId());
|
folderEntity.setParentRowId(y.getParentRowId());
|
folderEntity.setTreeControl(y.getTreeControl());
|
if (!y.getRowId().equals(y.getParentRowId())) {
|
folderEntity.setList(getFolderList(t482107, y.getRowId()));
|
}
|
folder.add(folderEntity);
|
}
|
}
|
}
|
}
|
return folder;
|
} catch (Exception e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 文件夹树结构
|
*
|
* @param t482107
|
* @param rowId
|
* @return
|
*/
|
public static List<MailModuleBelowEntity> getFolderModule(List<T482107Entity> t482107, String rowId) {
|
List<MailModuleBelowEntity> folder = new ArrayList<>();
|
try {
|
for (T482107Entity t : t482107) {
|
if (folder.stream().filter(f -> f.getParentKey().equals(rowId)).count() == 0) {
|
List<T482107Entity> fo = t482107.stream().filter(o -> o.getParentRowId().equals(rowId)).collect(Collectors.toList());
|
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());
|
if (!y.getRowId().equals(y.getParentRowId())) {
|
folder1.setList(getFolderModule(t482107, y.getRowId()));
|
}
|
folder.add(folder1);
|
}
|
} else {
|
break;
|
}
|
}
|
}
|
return folder;
|
} catch (Exception e) {
|
throw e;
|
}
|
}
|
}
|