Commit 115d13d4 by 邓实川

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

parent 2679930c
...@@ -49,6 +49,7 @@ import cn.timer.api.config.annotation.UserBean; ...@@ -49,6 +49,7 @@ import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enums.SysRoleType; import cn.timer.api.config.enums.SysRoleType;
import cn.timer.api.dao.crm.CrmClientContactsMapper; import cn.timer.api.dao.crm.CrmClientContactsMapper;
import cn.timer.api.dao.crm.CrmClientDataMapper; 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.dto.crm.CrmClientDataImportVo;
import cn.timer.api.utils.CheckUtil; import cn.timer.api.utils.CheckUtil;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
...@@ -969,23 +970,25 @@ public class CrmController { ...@@ -969,23 +970,25 @@ public class CrmController {
} }
listAll.add(cartogram5); listAll.add(cartogram5);
List<Map<String, Object>> cartogram6 = new ArrayList<Map<String, Object>>(); // 图6 // List<Map<String, Object>> cartogram6 = new ArrayList<Map<String, Object>>(); // 图6
for (Integer keyId : getKeyIdList()) { // for (Integer keyId : getKeyIdList()) {
Map<String, Object> map = cartogram3(orgCode, groupId, keyId, belonger, startCreateTime, endCreateTime); // Map<String, Object> map = cartogram3(orgCode, groupId, keyId, belonger, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0) { // if ((Integer) map.get("num") > 0) {
cartogram6.add(map); // cartogram6.add(map);
} // }
} // }
List<CrmCartogramDto> cartogram6 = getCartogram6(orgCode, belonger, groupId, startCreateTime, endCreateTime);
listAll.add(cartogram6); listAll.add(cartogram6);
return ResultUtil.data(listAll, "获取成功"); return ResultUtil.data(listAll, "获取成功");
} }
// 获取省份id // 获取省份id
private List<Integer> getKeyIdList() { // private List<Integer> getKeyIdList() {
List<SysRegion> list = SysRegion.builder().build() // List<SysRegion> list = SysRegion.builder().build()
.selectList(new LambdaQueryWrapper<SysRegion>().eq(SysRegion::getLevel, 1).select(SysRegion::getKeyId)); // .selectList(new LambdaQueryWrapper<SysRegion>().eq(SysRegion::getLevel, 1).select(SysRegion::getKeyId));
return list.stream().map(SysRegion::getKeyId).collect(Collectors.toList()); // return list.stream().map(SysRegion::getKeyId).collect(Collectors.toList());
} // }
@GetMapping("getAllBusinessMan") @GetMapping("getAllBusinessMan")
@ApiOperation(value = "获取全部业务员", httpMethod = "GET", notes = "接口发布说明") @ApiOperation(value = "获取全部业务员", httpMethod = "GET", notes = "接口发布说明")
...@@ -1022,7 +1025,12 @@ public class CrmController { ...@@ -1022,7 +1025,12 @@ public class CrmController {
.eq(belonger != null, CrmClientData::getBelongUser, belonger) .eq(belonger != null, CrmClientData::getBelongUser, belonger)
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime) .ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime)
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, endCreateTime)); .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("name", name);
map.put("num", num); map.put("num", num);
return map; return map;
...@@ -1048,6 +1056,10 @@ public class CrmController { ...@@ -1048,6 +1056,10 @@ public class CrmController {
list.add(map); list.add(map);
} }
} }
Map<String, Object> map = selectMap(orgCode, 0, status, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0)
list.add(map);
} else { } else {
Map<String, Object> map = selectMap(orgCode, belonger, status, startCreateTime, endCreateTime); Map<String, Object> map = selectMap(orgCode, belonger, status, startCreateTime, endCreateTime);
if ((Integer) map.get("num") > 0) { if ((Integer) map.get("num") > 0) {
...@@ -1109,42 +1121,56 @@ public class CrmController { ...@@ -1109,42 +1121,56 @@ public class CrmController {
* @param belonger 业务员id (可不填) * @param belonger 业务员id (可不填)
* @return * @return
*/ */
private Map<String, Object> cartogram3(Integer orgCode, Integer groupId, Integer provinceId, Integer belonger, // private Map<String, Object> cartogram3(Integer orgCode, Integer groupId, Integer provinceId, Integer belonger,
String startCreateTime, String endCreateTime) { // String startCreateTime, String endCreateTime) {
Map<String, Object> map = new HashMap<String, Object>(); // Map<String, Object> map = new HashMap<String, Object>();
Integer num = 0; // Integer num = 0;
if (belonger == null) { // if (belonger == null) {
List<Integer> members = getAllBusinessGroupMember(orgCode, groupId); //
for (Integer memberId : members) { // List<Integer> members = getAllBusinessGroupMember(orgCode, groupId);
num += CrmClientData.builder().build() // for (Integer memberId : members) {
.selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode) // num += CrmClientData.builder().build()
.eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, memberId) // .selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode)
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, // .eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, memberId)
startCreateTime) // .ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime,
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, // startCreateTime)
endCreateTime)); // .le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime,
} // endCreateTime));
map.put("provinceId", provinceId); // }
String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda() // map.put("provinceId", provinceId);
.eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName)) // String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda()
.getRegionName(); // .eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName))
map.put("provinceName", name); // .getRegionName();
map.put("num", num); // 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() * 统计图6-籍贯
.selectCount(new QueryWrapper<CrmClientData>().lambda().eq(CrmClientData::getOrgCode, orgCode) *
.eq(CrmClientData::getProvinceId, provinceId).eq(CrmClientData::getBelongUser, belonger) * @param orgCode
.ge(StringUtils.isNotBlank(startCreateTime), CrmClientData::getCreateTime, startCreateTime) * @param belongGroup
.le(StringUtils.isNotBlank(endCreateTime), CrmClientData::getCreateTime, endCreateTime)); * @param createTime
map.put("provinceId", provinceId); * @return
String name = SysRegion.builder().build().selectOne(new QueryWrapper<SysRegion>().lambda() */
.eq(SysRegion::getLevel, 1).eq(SysRegion::getKeyId, provinceId).select(SysRegion::getRegionName)) private List<CrmCartogramDto> getCartogram6(Integer orgCode, Integer belongUser, Integer belongGroup,
.getRegionName(); String startCreateTime, String endCreateTime) {
map.put("provinceName", name); return crmClientDataMapper.crmCartogram(orgCode, belongUser, belongGroup, startCreateTime, endCreateTime);
map.put("num", num);
}
return map;
} }
/** /**
......
...@@ -7,13 +7,17 @@ ...@@ -7,13 +7,17 @@
*/ */
package cn.timer.api.dao.crm; 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 com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.timer.api.bean.crm.CrmClientData; import cn.timer.api.bean.crm.CrmClientData;
import cn.timer.api.dto.crm.CrmCartogramDto;
/** /**
* Title: CrmClientDataMapper.java * Title: CrmClientDataMapper.java Description:
* Description:
* *
* @author dsc * @author dsc
* @date 2020年6月5日 * @date 2020年6月5日
...@@ -21,4 +25,9 @@ import cn.timer.api.bean.crm.CrmClientData; ...@@ -21,4 +25,9 @@ import cn.timer.api.bean.crm.CrmClientData;
*/ */
public interface CrmClientDataMapper extends BaseMapper<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; ...@@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
/** /**
* Title: CrmClientDataImportVo.java * Title: CrmClientDataImportVo.java
* *
* @Description: * @Description: 客户导入
* @author dsc * @author dsc
* @date 2020年6月12日 * @date 2020年6月12日
* @version 1.0 * @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