package com.yc.crm.mail.action;
|
|
//import com.yc.crm.mail.entity.T482115Entity;
|
|
import com.yc.crm.base.entity.T482115Entity;
|
import com.yc.crm.mail.entity.MailModuleBelowEntity;
|
import com.yc.crm.mail.service.MailTagIfc;
|
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.List;
|
|
/**
|
* @BelongsProject: eCoWorksV3
|
* @BelongsPackage: com.yc.crm.mail.action
|
* @author: xinyb
|
* @CreateTime: 2024-09-04 15:22
|
* @Description:标签
|
*/
|
@CrossOrigin
|
@RestController
|
@RequestMapping("/crm/mail/tag")
|
public class MailTag {
|
@Autowired
|
MailTagIfc mailTagIfc;
|
|
/**
|
* 添加标签
|
*
|
* @param signature
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/addTag.do")
|
public AllBackMsg addTag(@RequestBody T482115Entity tag, 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);
|
tag.setCompanyId(companyId);
|
tag.setCompanyName(companyName);
|
tag.setUserCode(userCode);
|
tag.setUserName(userName);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
//保存
|
mailTagIfc.saveTag(tag);
|
msg.setOk("已保存");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 修改标签
|
*
|
* @param signature
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/updateTag.do")
|
public AllBackMsg updateTag(@RequestBody T482115Entity tag, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if (tag.getTagId() == null || tag.getTagId().equals(0)) {
|
msg.setFail("缺少tagId值,请检查");
|
return msg;
|
}
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
if (StringUtils.isBlank(userCode)) {
|
msg.setFail("登录用户已过期,请检查");
|
return msg;
|
}
|
tag.setUserCode(userCode);
|
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
|
SpObserver.setDBtoInstance("_" + dataSource.getDbId());
|
mailTagIfc.updateTag(tag);
|
msg.setOk("已更新");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 删除标签
|
*
|
* @param signId
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/deleteTag.do")
|
public AllBackMsg deleteTag(@RequestParam(defaultValue = "0") Integer tagId, HttpServletRequest request, HttpServletResponse response) {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
if (tagId.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 = mailTagIfc.deleteTag(userCode, tagId);
|
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("/getTagList.do")
|
public AllBackMsg getTagList(String search, @RequestParam(defaultValue = "-1") Integer type, 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<T482115Entity> list = mailTagIfc.getTagList(userCode, search, type);
|
msg.setSuccess("执行成功", list);
|
} 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<MailModuleBelowEntity> getTagModule(List<T482115Entity> T482115) {
|
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());
|
system.add(tag);
|
} else {
|
tag.setKey("customTag" + t.getTagId());
|
custom.add(tag);
|
}
|
}
|
tag1.setList(system);
|
tag2.setList(custom);
|
tagList.add(tag1);
|
tagList.add(tag2);
|
return tagList;
|
} catch (Exception e) {
|
throw e;
|
}
|
}
|
}
|