package com.yc.crm.custom.action;
|
|
import com.yc.crm.custom.entity.T480601Entity;
|
import com.yc.crm.custom.service.CustomIfc;
|
import com.yc.crm.mail.entity.MailModuleEntity;
|
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.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @BelongsProject: eCoWorksV3
|
* @BelongsPackage: com.yc.crm.custom.action
|
* @author: xinyb
|
* @CreateTime: 2024-08-24 14:15
|
* @Description:
|
*/
|
@CrossOrigin
|
@RestController
|
@RequestMapping("/crm/custom/")
|
public class CustomController {
|
@Autowired
|
CustomIfc customIfc;
|
|
/**
|
* 获取客户左边模块
|
*
|
* @return
|
*/
|
@GetMapping("/getCustomModule.do")
|
public AllBackMsg getCustomModule(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
|
if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
|
msg.setFail("获取不到用户信息");
|
return msg;
|
}
|
String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
|
String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
|
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
|
List<MailModuleEntity> list = null;
|
msg.setSuccess("执行成功", list);
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 保存客户
|
*
|
* @return
|
*/
|
@PostMapping("/saveCustom.do")
|
public AllBackMsg saveCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
|
if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
|
msg.setFail("获取不到用户信息");
|
return msg;
|
}
|
String userName = (String) session.getAttribute(SessionKey.USERNAME);
|
String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
|
String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
|
custom.setCompanyid(companyId);
|
custom.setCompanyname(companyName);
|
custom.setEnterCode(userCode);
|
custom.setEnterName(userName);
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
|
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
|
String docCode = customIfc.saveCustom(custom);
|
Map<String, Object> map = new HashMap<>();
|
if (StringUtils.isNotBlank(docCode)) {
|
map.put("docCode", docCode);
|
}
|
msg.setSuccess("执行成功", map);
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 修改客户
|
*
|
* @return
|
*/
|
@PostMapping("/updateCustom.do")
|
public AllBackMsg updateCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
AllBackMsg msg = new AllBackMsg();
|
try {
|
HttpSession session = request.getSession();
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
|
if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
|
msg.setFail("获取不到用户信息");
|
return msg;
|
}
|
if (StringUtils.isBlank(custom.getDocCode())) {
|
msg.setFail("请输入修改的客户编号");
|
return msg;
|
}
|
String userName = (String) session.getAttribute(SessionKey.USERNAME);
|
String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
|
String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
|
custom.setCompanyid(companyId);
|
custom.setCompanyname(companyName);
|
custom.setEnterCode(userCode);
|
custom.setEnterName(userName);
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
|
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
|
customIfc.updateCustom(custom);
|
msg.setSuccess("执行成功", "已保存");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 删除客户
|
*
|
* @return
|
*/
|
@PostMapping("/deleteCustom.do")
|
public AllBackMsg deleteCustom(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
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 dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
|
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
|
customIfc.deleteCustom(docCode, userCode);
|
msg.setSuccess("执行成功", "已保存");
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
}
|