Commit 1e858569 by 邓实川 Committed by chenzg

提交客户管理接口

parent 44a7d176
......@@ -7,6 +7,7 @@
*/
package cn.timer.api.controller.crm;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -17,6 +18,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -25,7 +27,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......@@ -33,7 +34,10 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.timer.api.bean.clazz.ClientSourceClass;
import cn.timer.api.bean.clazz.ClientTypeClass;
import cn.timer.api.bean.clazz.IndustryClass;
......@@ -48,8 +52,10 @@ import cn.timer.api.bean.crm.CrmSeaRule;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.controller.dzht.cn.tign.hz.comm.FileHelper;
import cn.timer.api.dao.crm.CrmClientContactsMapper;
import cn.timer.api.dao.crm.CrmClientDataMapper;
import cn.timer.api.dto.crm.CrmClientDataImportVo;
import cn.timer.api.utils.CheckUtil;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
......@@ -71,6 +77,9 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping(value = "/crm", produces = { "application/json" })
public class CrmController {
@Value(value = "${config-8timer.crm-excel.realPath}")
private String realPath;
@Autowired
private CrmClientDataMapper crmClientDataMapper;
......@@ -862,6 +871,20 @@ public class CrmController {
return list.stream().map(SysRegion::getKeyId).collect(Collectors.toList());
}
@GetMapping("getAllBusinessMan")
@ApiOperation(value = "获取全部业务员", httpMethod = "GET", notes = "接口发布说明")
public Result<Object> getAllBusinessMan(@CurrentUser UserBean userBean) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<Integer> empNums = getAllBusinessGroupMember(getOrgCode(userBean), null);
for (Integer integer : empNums) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("empNum", integer);
map.put("name", getEmpName(getOrgCode(userBean), integer));
list.add(map);
}
return ResultUtil.data(list, "获取成功");
}
// 获取公司全部业务员
private List<Integer> getAllBusinessGroupMember(Integer orgCode, Integer groupId) {
List<CrmBusinessGroupMember> list = CrmBusinessGroupMember.builder().build()
......@@ -904,6 +927,7 @@ public class CrmController {
List<Integer> members = getAllBusinessGroupMember(orgCode, groupId);
for (Integer memberId : members) {
Map<String, Object> map = selectMap(orgCode, memberId, status, startCreateTime, endCreateTime);
System.err.println(map);
if ((Integer) map.get("num") > 0) {
list.add(map);
}
......@@ -914,6 +938,7 @@ public class CrmController {
list.add(map);
}
}
System.err.println("list:" + list);
return list;
}
......@@ -1007,10 +1032,141 @@ public class CrmController {
return map;
}
// TODO 导入客户
@PostMapping("importexcel")
public Object importWatchExcel(@RequestParam("excelFile") MultipartFile xlsFile) {
return xlsFile;
/**
* 导入
*
* @param url 上传路径
* @return
*/
@PostMapping("importClient")
@Transactional
@ApiOperation(value = "导入客户", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> importClient(@CurrentUser UserBean userBean, @RequestParam String url) {
Integer empNum = getEmpNum(userBean);
Integer orgCode = getOrgCode(userBean);
String filePath = null;
try {
String time = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
filePath = FileHelper.downLoadFromUrl(url, time + ".xls", realPath);
} catch (IOException e) {
e.printStackTrace();
}
// 从文件中读取Excel为ExcelReader
ExcelReader reader;
// 从流中读取Excel为ExcelReader(比如从ClassPath中读取Excel文件)
reader = ExcelUtil.getReader(ResourceUtil.getStream(filePath));
reader.addHeaderAlias("*客户名称(必填)", "clientName");
reader.addHeaderAlias("*所属分组(必填)", "belongGroupName");
reader.addHeaderAlias("行业", "industryName");
reader.addHeaderAlias("客户类型", "clientTypeName");
reader.addHeaderAlias("手机号码(客户)", "clientCellphone");
reader.addHeaderAlias("座机号码", "clientTelephone");
reader.addHeaderAlias("官网", "clientUrl");
reader.addHeaderAlias("邮箱", "clientEmail");
reader.addHeaderAlias("地址", "address");
reader.addHeaderAlias("联系人姓名", "linkName");
reader.addHeaderAlias("手机号码(联系人)", "cellphone");
reader.addHeaderAlias("所属公司", "company");
reader.addHeaderAlias("性别", "gender");
reader.addHeaderAlias("职位", "position");
reader.addHeaderAlias("办公电话", "telephone");
reader.addHeaderAlias("个人邮箱", "email");
reader.addHeaderAlias("个人地址", "linkAddress");
List<CrmClientDataImportVo> list = reader.read(0, 1, CrmClientDataImportVo.class);
for (CrmClientDataImportVo crmClientDataImportVo : list) {
System.err.println(crmClientDataImportVo);
String clientName = crmClientDataImportVo.getClientName(); // 客户名称(必填)
String belongGroupName = crmClientDataImportVo.getBelongGroupName(); // 分组名(必填)
String industryName = crmClientDataImportVo.getIndustryName(); // 行业名
String clientTypeName = crmClientDataImportVo.getClientTypeName(); // 客户类型名
String clientCellphone = crmClientDataImportVo.getClientCellphone(); // 客户手机号
String clientTelephone = crmClientDataImportVo.getClientTelephone(); // 客户座机号
String clientUrl = crmClientDataImportVo.getClientUrl(); // 官网
String clientEmail = crmClientDataImportVo.getClientEmail(); // 邮箱
String clientAddress = crmClientDataImportVo.getAddress(); // 地址
String linkname = crmClientDataImportVo.getLinkName(); // 联系人姓名
String linkcellphone = crmClientDataImportVo.getCellphone(); // 手机号码
String linkcompany = crmClientDataImportVo.getCompany(); // 所属公司
String linkgender = crmClientDataImportVo.getGender(); // 性别
String linkposition = crmClientDataImportVo.getPosition(); // 职位
String linktelephone = crmClientDataImportVo.getTelephone(); // 办公电话
String linkemail = crmClientDataImportVo.getEmail(); // 个人邮箱
String linkaddress = crmClientDataImportVo.getLinkAddress(); // 个人地址
CrmClientData crmClientData = new CrmClientData();
// 业务组
CrmBusinessGroup crmBusinessGroup = CrmBusinessGroup.builder().build()
.selectOne(new LambdaQueryWrapper<CrmBusinessGroup>()
.eq(CrmBusinessGroup::getOrgCode, userBean.getOrgCode())
.eq(CrmBusinessGroup::getName, belongGroupName).select(CrmBusinessGroup::getId));
if (crmBusinessGroup == null)
return ResultUtil.error("没有匹配的业务组名称");
if (StrUtil.isNotBlank(industryName)) {
// 行业字典
IndustryClass industryClass = IndustryClass.builder().build()
.selectOne(new LambdaQueryWrapper<IndustryClass>().eq(IndustryClass::getName, industryName)
.select(IndustryClass::getId));
if (industryClass == null)
return ResultUtil.error("没有匹配的行业名称");
crmClientData.setIndustry(industryClass.getId());
}
if (StrUtil.isNotBlank(clientTypeName)) {
// 客户类型
ClientTypeClass clientTypeClass = ClientTypeClass.builder().build()
.selectOne(new LambdaQueryWrapper<ClientTypeClass>()
.eq(ClientTypeClass::getName, clientTypeName).select(ClientTypeClass::getId));
if (clientTypeClass == null)
return ResultUtil.error("没有匹配的客户类型名称");
crmClientData.setClientType(clientTypeClass.getId());
}
crmClientData.setClientStatus(0);
crmClientData.setContactsNum(1);
crmClientData.setBelongUser(empNum);
crmClientData.setBelongUserName(getEmpName(orgCode, empNum));
crmClientData.setClientName(clientName);
crmClientData.setBelongGroupName(belongGroupName);
crmClientData.setBelongGroup(crmBusinessGroup.getId());
crmClientData.setIndustryName(industryName);
crmClientData.setClientTypeName(clientTypeName);
crmClientData.setClientCellphone(clientCellphone);
crmClientData.setClientTelephone(clientTelephone);
crmClientData.setClientUrl(clientUrl);
crmClientData.setClientEmail(clientEmail);
crmClientData.setAddress(clientAddress);
crmClientData.insert();
Integer cid = crmClientData.getId();
CrmClientContacts contacts = new CrmClientContacts();
contacts.setName(linkname);
contacts.setCellphone(linkcellphone);
contacts.setCompany(linkcompany);
if (linkgender == "女")
contacts.setGender(0);
else if (linkgender == "男")
contacts.setGender(1);
else
contacts.setGender(null);
contacts.setPosition(linkposition);
contacts.setTelephone(linktelephone);
contacts.setEmail(linkemail);
contacts.setAddress(linkaddress);
if (!(linkname == null && linkcellphone == null && linkcompany == null && linkgender == null
&& linkposition == null && linktelephone == null && linkemail == null && linkaddress == null)) {
contacts.setCid(cid);
contacts.insert();
}
}
return ResultUtil.success("导入成功");
}
}
......@@ -62,21 +62,25 @@ public class CrmRuleController {
Integer status = crmClientData.getClientStatus();
String belongUserName = crmClientData.getBelongUserName();
String clientName = crmClientData.getClientName();
Date now = new Date();
// 客户创建时间+ x天 = 过期释放时间
DateTime overDate1 = DateUtil.offsetDay(createTime, one);
Long compare2 = null;
if (lastFollowTime != null) {
DateTime overDate2 = DateUtil.offsetDay(lastFollowTime, two);
compare2 = DateUtil.between(overDate2, now, DateUnit.DAY, false);
}
DateTime overDate3 = DateUtil.offsetDay(createTime, three);
// 时间比较
Date now = new Date();
long compare1 = DateUtil.between(overDate1, now, DateUnit.DAY, false);
long compare2 = DateUtil.between(overDate2, now, DateUnit.DAY, false);
long compare3 = DateUtil.between(overDate3, now, DateUnit.DAY, false);
// 判断1和2和3
if ((lastFollowTime == null && compare1 >= 0) || (lastFollowTime != null && compare2 >= 0)
|| (compare3 >= 0 && status != 3 && status != 4))
release(crmClientData);
// 判断4
if (compare1 == -four || compare2 == -four || compare3 == -four)
if (compare1 == -four || compare2 == -four || compare3 == -four) // TODO
remind(belongUserName, clientName, four);
}
}
......
/**
* Title: CrmClientDataImportVo.java
* Description:
* @author dsc
* @date 2020年6月12日
* @version 1.0
*/
package cn.timer.api.dto.crm;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Title: CrmClientDataImportVo.java
*
* @Description:
* @author dsc
* @date 2020年6月12日
* @version 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CrmClientDataImportVo implements Serializable {
private static final long serialVersionUID = 3241644321635711815L;
// 客户名
private String clientName;
// 组
private String belongGroupName;
// 行业
private String industryName;
// 客户类型
private String clientTypeName;
// 手机号
private String clientCellphone;
// 客户座机
private String clientTelephone;
// 客户官网
private String clientUrl;
// 邮箱
private String clientEmail;
// 详细地址
private String address;
// 联系人信息
private String linkName;
private String cellphone;
private String company;
private String gender;
private String position;
private String telephone;
private String email;
private String linkAddress;
}
......@@ -202,6 +202,9 @@ config-8timer:
three: 30
init-password: 123456
# 客户管理导入服务器保存路径
crm-excel:
realPath: 'D:/excel/'
\ No newline at end of file
......@@ -172,3 +172,7 @@ config-8timer:
two: 7
three: 30
init-password: 123456
# 客户管理导入服务器保存路径
crm-excel:
realPath: 'crm-excel/'
\ No newline at end of file
......@@ -171,3 +171,7 @@ config-8timer:
two: 7
three: 30
init-password: 123456
# 客户管理导入服务器保存路径
crm-excel:
realPath: 'crm-excel/'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment