Commit 115d13d4 by 邓实川

客户管理统计图查询效率优化

parent 2679930c
......@@ -49,6 +49,7 @@ import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enums.SysRoleType;
import cn.timer.api.dao.crm.CrmClientContactsMapper;
import cn.timer.api.dao.crm.CrmClientDataMapper;
import cn.timer.api.dto.crm.CrmCartogramDto;
import cn.timer.api.dto.crm.CrmClientDataImportVo;
import cn.timer.api.utils.CheckUtil;
import cn.timer.api.utils.Result;
......@@ -969,23 +970,25 @@ public class CrmController {
}
listAll.add(cartogram5);
List<Map<String, Object>> cartogram6 = new ArrayList<Map<String, Object>>(); // 图6
for (Integer keyId : getKeyIdList()) {
Map<String, Object> map = cartogram3(orgCode, groupId, keyId, belonger, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0) {
cartogram6.add(map);
}
}
// List<Map<String, Object>> cartogram6 = new ArrayList<Map<String, Object>>(); // 图6
// for (Integer keyId : getKeyIdList()) {
// Map<String, Object> map = cartogram3(orgCode, groupId, keyId, belonger, startCreateTime, endCreateTime);
// if ((Integer) map.get("num") > 0) {
// cartogram6.add(map);
// }
// }
List<CrmCartogramDto> cartogram6 = getCartogram6(orgCode, belonger, groupId, startCreateTime, endCreateTime);
listAll.add(cartogram6);
return ResultUtil.data(listAll, "获取成功");
}
// 获取省份id
private List<Integer> getKeyIdList() {
List<SysRegion> list = SysRegion.builder().build()
.selectList(new LambdaQueryWrapper<SysRegion>().eq(SysRegion::getLevel, 1).select(SysRegion::getKeyId));
return list.stream().map(SysRegion::getKeyId).collect(Collectors.toList());
}
// private List<Integer> getKeyIdList() {
// List<SysRegion> list = SysRegion.builder().build()
// .selectList(new LambdaQueryWrapper<SysRegion>().eq(SysRegion::getLevel, 1).select(SysRegion::getKeyId));
// return list.stream().map(SysRegion::getKeyId).collect(Collectors.toList());
// }
@GetMapping("getAllBusinessMan")
@ApiOperation(value = "获取全部业务员", httpMethod = "GET", notes = "接口发布说明")
......@@ -1022,7 +1025,12 @@ public class CrmController {
.eq(belonger != null, CrmClientData::getBelongUser, belonger)
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime)
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, endCreateTime));
String name = getEmpName(orgCode, belonger);
String name = "未知";
if (belonger == 0) {
name = "公海客户";
} else {
name = getEmpName(orgCode, belonger);
}
map.put("name", name);
map.put("num", num);
return map;
......@@ -1048,6 +1056,10 @@ public class CrmController {
list.add(map);
}
}
Map<String, Object> map = selectMap(orgCode, 0, status, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0)
list.add(map);
} else {
Map<String, Object> map = selectMap(orgCode, belonger, status, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0) {
......@@ -1109,42 +1121,56 @@ public class CrmController {
* @param belonger 业务员id (可不填)
* @return
*/
private Map<String, Object> cartogram3(Integer orgCode, Integer groupId, Integer provinceId, Integer belonger,
String startCreateTime, String endCreateTime) {
Map<String, Object> map = new HashMap<String, Object>();
Integer num = 0;
if (belonger == null) {
List<Integer> members = getAllBusinessGroupMember(orgCode, groupId);
for (Integer memberId : members) {
num += CrmClientData.builder().build()
.selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode)
.eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, memberId)
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime,
startCreateTime)
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime,
endCreateTime));
}
map.put("provinceId", provinceId);
String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda()
.eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName))
.getRegionName();
map.put("provinceName", name);
map.put("num", num);
// private Map<String, Object> cartogram3(Integer orgCode, Integer groupId, Integer provinceId, Integer belonger,
// String startCreateTime, String endCreateTime) {
// Map<String, Object> map = new HashMap<String, Object>();
// Integer num = 0;
// if (belonger == null) {
//
// List<Integer> members = getAllBusinessGroupMember(orgCode, groupId);
// for (Integer memberId : members) {
// num += CrmClientData.builder().build()
// .selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode)
// .eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, memberId)
// .ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime,
// startCreateTime)
// .le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime,
// endCreateTime));
// }
// map.put("provinceId", provinceId);
// String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda()
// .eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName))
// .getRegionName();
// map.put("provinceName", name);
// map.put("num", num);
//
// } else {
// num = CrmClientData.builder().build()
// .selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode)
// .eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, belonger)
// .ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime)
// .le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, endCreateTime));
// map.put("provinceId", provinceId);
// String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda()
// .eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName))
// .getRegionName();
// map.put("provinceName", name);
// map.put("num", num);
// }
// return map;
// }
} else {
num = CrmClientData.builder().build()
.selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode)
.eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, belonger)
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime)
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, endCreateTime));
map.put("provinceId", provinceId);
String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda()
.eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName))
.getRegionName();
map.put("provinceName", name);
map.put("num", num);
}
return map;
/**
* 统计图6-籍贯
*
* @param orgCode
* @param belongGroup
* @param createTime
* @return
*/
private List<CrmCartogramDto> getCartogram6(Integer orgCode, Integer belongUser, Integer belongGroup,
String startCreateTime, String endCreateTime) {
return crmClientDataMapper.crmCartogram(orgCode, belongUser, belongGroup, startCreateTime, endCreateTime);
}
/**
......
......@@ -7,13 +7,17 @@
*/
package cn.timer.api.dao.crm;
import java.util.List;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.timer.api.bean.crm.CrmClientData;
import cn.timer.api.dto.crm.CrmCartogramDto;
/**
* Title: CrmClientDataMapper.java
* Description:
* Title: CrmClientDataMapper.java Description:
*
* @author dsc
* @date 2020年6月5日
......@@ -21,4 +25,9 @@ import cn.timer.api.bean.crm.CrmClientData;
*/
public interface CrmClientDataMapper extends BaseMapper<CrmClientData> {
List<CrmCartogramDto> crmCartogram(@RequestParam("orgCode") Integer orgCode,
@RequestParam(name = "belongUser", required = false) Integer belongUser,
@RequestParam(name = "belongGroup", required = false) Integer belongGroup,
@RequestParam(name = "startCreateTime", required = false) String startCreateTime,
@RequestParam(name = "endCreateTime", required = false) String endCreateTime);
}
/**
* Title: CrmCartogramDto.java
* Description:
* @author dsc
* @date 2020年6月22日
* @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: CrmCartogramDto.java
*
* @Description:
* @author dsc
* @date 2020年6月22日
* @version 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CrmCartogramDto implements Serializable {
private static final long serialVersionUID = -4445892627839823485L;
private Integer provinceId;
private String province;
private Integer provinceNum;
}
......@@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
/**
* Title: CrmClientDataImportVo.java
*
* @Description:
* @Description: 客户导入
* @author dsc
* @date 2020年6月12日
* @version 1.0
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.timer.api.dao.crm.CrmClientDataMapper">
<select id="crmCartogram"
resultType="cn.timer.api.dto.crm.CrmCartogramDto">
SELECT
province_id,province,count(province_id) provinceNum
FROM
crm_client_data
WHERE
org_code = #{orgCode}
<if test='null != belongUser and belongUser !=""'>AND
belong_user = #{belongUser}
</if>
<if test='null != belongGroup and belongGroup !=""'>AND
belong_group = #{belongGroup}
</if>
<if test='null != startCreateTime and startCreateTime !=""'>AND
create_time <![CDATA[>=]]> #{startCreateTime}
</if>
<if test='null != endCreateTime and endCreateTime !=""'>AND
create_time <![CDATA[<=]]> #{endCreateTime}
</if>
GROUP BY
province_id
</select>
</mapper>
\ 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