package com.yc.crm.mail.action;
|
|
import com.yc.crm.mail.entity.T482106Entity;
|
import com.yc.crm.mail.service.MailBlackListIfc;
|
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.List;
|
|
/**
|
* @BelongsProject: eCoWorksV3
|
* @BelongsPackage: com.yc.crm.mail.action
|
* @author: xinyb
|
* @CreateTime: 2024-08-19 15:33
|
* @Description: 邮件黑名单
|
*/
|
@CrossOrigin
|
@RestController
|
@RequestMapping("/crm/mail/blacklist")
|
public class MailBlacklist {
|
|
@Autowired
|
MailBlackListIfc mailBlackListIfc;
|
|
/**
|
* 添加黑名单
|
*
|
* @param BlackList
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/addBlackList.do")
|
public AllBackMsg addBlackList(@RequestBody T482106Entity BlackList, 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);
|
BlackList.setCompanyId(companyId);
|
BlackList.setCompanyName(companyName);
|
BlackList.setUserCode(userCode);
|
BlackList.setUserName(userName);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
mailBlackListIfc.saveBlackList(BlackList);
|
msg.setSuccess("执行成功", "已保存");
|
} catch (Exception e) {
|
msg.setError("执行出错", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 修改黑名单
|
*
|
* @param BlackList
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/updateBlackList.do")
|
public AllBackMsg updateBlackList(@RequestBody T482106Entity BlackList, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if(BlackList.getBlackId()==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;
|
}
|
BlackList.setUserCode(userCode);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
mailBlackListIfc.updateBlackList(BlackList);
|
msg.setOk("已更新");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 删除黑名单
|
*
|
* @param blackId
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/deleteBlackList.do")
|
public AllBackMsg deleteBlackList(@RequestParam(defaultValue = "0") Integer blackId, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if (blackId == 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 = mailBlackListIfc.deleteBlackList(userCode,blackId);
|
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("/getBlackList.do")
|
public AllBackMsg getSignature(String search, 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<T482106Entity> list = mailBlackListIfc.getBlackList(userCode,search);
|
msg.setSuccess("执行成功", list);
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
}
|