Commit 186620ae by lal

Merge branch 'develop' of develop-gitlab.youlingrc.com:8timerv2/8timerapiv200 into lal

parents 245e7780 8f686cc8
......@@ -57,10 +57,10 @@ public class CrmClientFollow extends Model<CrmClientFollow> {
private Integer cid;
@ApiModelProperty(value = "跟进内容")
private Integer content;
private String content;
@ApiModelProperty(value = "客户数据状态 0-无 1-潜在 2-意向 3-签约 4-合作中 5-已封档")
private String clientStatus;
private Integer clientStatus;
@ApiModelProperty(value = "联系人姓名")
private String name;
......
......@@ -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;
......@@ -32,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;
......@@ -47,7 +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;
......@@ -69,9 +77,15 @@ 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;
@Autowired
private CrmClientContactsMapper crmClientContactsMapper;
private Integer getEmpNum(UserBean userBean) {
return userBean.getEmpNum();
}
......@@ -428,8 +442,8 @@ public class CrmController {
.eq(status != null && status >= 0, CrmClientData::getClientStatus, status)
.like(!StrUtil.isBlank(like), CrmClientData::getClientName, like).or()
.like(!StrUtil.isBlank(like), CrmClientData::getClientCellphone, like));
if (crmClientData != null)
myCrmClientAssociates.add(crmClientData);
if (crmClientData != null)
myCrmClientAssociates.add(crmClientData);
}
return myCrmClientAssociates;
}
......@@ -468,7 +482,7 @@ public class CrmController {
if (type == null || type == 0) { // 全部客户(去重)
List<CrmClientData> myClient = getMyCilent(empNum, orgCode, groupId, status, like);
List<CrmClientData> myAsso = getMyAssociateCilent(empNum, orgCode, groupId, status, like);
crmClientDatas = CheckUtil.distinct(myClient, myAsso, true);
crmClientDatas = CheckUtil.distinct(myClient, myAsso, true);
} else if (type == 1) // 我负责的客户
crmClientDatas = getMyCilent(empNum, orgCode, groupId, status, like);
else if (type == 2) // 我协作的客户
......@@ -479,11 +493,10 @@ public class CrmController {
crmClientDatas = getCilentFollowOvertime(empNum, orgCode, groupId, status);
else
return ResultUtil.error("查询失败");
// TODO 排序
Collections.sort(crmClientDatas, Comparator.comparing(CrmClientData::getCreateTime).reversed()); // 按时间降序排序
return ResultUtil.data(crmClientDatas, "查询成功");
}
private List<Integer> MyJoinGroup(Integer empNum, Integer orgCode) {
List<CrmBusinessGroupMember> members = CrmBusinessGroupMember.builder().build()
.selectList(new QueryWrapper<CrmBusinessGroupMember>().lambda()
......@@ -562,26 +575,38 @@ public class CrmController {
@PostMapping("addCilentLinkMan")
@Transactional
@ApiOperation(value = "新增/编辑客户联系人", httpMethod = "POST", notes = "接口发布说明")
public Result<Void> addCilentLinkMan(@CurrentUser UserBean userBean, CrmClientContacts crmClientContacts) {
public Result<Void> addCilentLinkMan(@CurrentUser UserBean userBean,
@RequestBody CrmClientContacts crmClientContacts) {
Integer cid = crmClientContacts.getCid();
if (crmClientContacts.getId() == null) {
Integer num = CrmClientData.builder().build().selectById().getContactsNum();
CrmClientData.builder().id(crmClientContacts.getCid()).contactsNum(++num).build().updateById();
if (cid == null)
return ResultUtil.error("编辑失败,请传入客户id");
Integer num = CrmClientData.builder().id(crmClientContacts.getCid()).build().selectById().getContactsNum();
CrmClientData.builder().id(cid).contactsNum(++num).build().updateById();
}
if (crmClientContacts.insertOrUpdate())
return ResultUtil.success("新增/编辑成功");
return ResultUtil.success("新增/编辑失败");
return ResultUtil.error("新增/编辑失败");
}
@DeleteMapping("delCilentLinkMan")
@Transactional
@ApiOperation(value = "删除客户联系人", httpMethod = "DELETE", notes = "接口发布说明")
public Result<Void> delCilentLinkMan(@CurrentUser UserBean userBean, CrmClientContacts crmClientContacts) {
Integer num = CrmClientData.builder().build().selectById().getContactsNum();
CrmClientData.builder().id(crmClientContacts.getCid()).contactsNum(--num).build().updateById();
if (crmClientContacts.deleteById())
public Result<Void> delCilentLinkMan(@CurrentUser UserBean userBean, @RequestParam Integer id,
@RequestParam Integer cid) {
if (cid == null)
return ResultUtil.error("删除失败,请传入客户id");
Integer num = CrmClientData.builder().id(cid).build().selectById().getContactsNum();
if (--num < 0) {
return ResultUtil.error("删除失败,已经没有可以删的联系人了");
}
CrmClientData.builder().id(cid).contactsNum(num).build().updateById();
if (crmClientContactsMapper.deleteById(id) > 0)
return ResultUtil.success("删除成功");
return ResultUtil.success("删除失败");
return ResultUtil.error("删除失败");
}
......@@ -632,7 +657,8 @@ public class CrmController {
Integer orgCode = getOrgCode(userBean);
Integer empNum = getEmpNum(userBean);
CrmClientData.builder().id(crmClientFollow.getCid()).lastFollowTime(new Date()).build().updateById(); // 更新客户最近跟进时间
CrmClientData.builder().id(crmClientFollow.getCid()).clientStatus(crmClientFollow.getClientStatus())
.lastFollowTime(new Date()).build().updateById(); // 更新客户最近跟进时间
crmClientFollow.setOrgCode(orgCode);
crmClientFollow.setCreateUserName(getEmpName(orgCode, empNum));
......@@ -845,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()
......@@ -887,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);
}
......@@ -897,6 +938,7 @@ public class CrmController {
list.add(map);
}
}
System.err.println("list:" + list);
return list;
}
......@@ -990,6 +1032,141 @@ public class CrmController {
return map;
}
// TODO 导入客户
/**
* 导入
*
* @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);
DateTime overDate2 = DateUtil.offsetDay(lastFollowTime, two);
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;
}
......@@ -201,7 +201,10 @@ config-8timer:
two: 7
three: 30
init-password: 123456
# 客户管理导入服务器保存路径
crm-excel:
realPath: 'D:/excel/'
\ No newline at end of file
......@@ -171,4 +171,8 @@ config-8timer:
one: 3
two: 7
three: 30
init-password: 123456
\ No newline at end of file
init-password: 123456
# 客户管理导入服务器保存路径
crm-excel:
realPath: 'crm-excel/'
\ No newline at end of file
......@@ -170,4 +170,8 @@ config-8timer:
one: 3
two: 7
three: 30
init-password: 123456
\ No newline at end of file
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