可通过复选框不同条件实现不同列数据加载
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('数据报告')" />
<th:block th:include="include :: ztree-css" />
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: bootstrap-select-css"/>
<style>
.center{text-align: center;}
</style>
</head>
<body class="gray-bg">
<div class="wrapper animated fadeInRight">
<!-- 搜索条件-->
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
部门:<input type="text" name="createUserName" id="createUserName" readonly="readonly" onclick="ztreeShow();"/>
<input type="text" name="createByIds" id="createByIds" style="display: none" onclick="ztreeShow();"/>
</li>
<li style="height: 30px;">
<div style="float: left; padding-top: 8px;">
线索类型:
</div>
<div style="float: left;">
<select name="actionClueType" id="actionClueType" class="form-control">
<option value="">请选择</option>
<option th:each="regular:${regulars}"
th:value="${regular.id}" th:text="${regular.clueTypeName}"></option>
</select>
</div>
</li>
<li>
<label>查询时间:</label>
<input type="text" readonly="readonly" placeholder="时间范围" name="recordDate" id="recordDate"/>
<input type="hidden" name="startTime" id="startTime"/>
<input type="hidden" name="endTime" id="endTime"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="resetSearch();"><i class="fa fa-refresh"></i> 重置</a>
</li>
</ul>
</div>
<div id="treeDiv" class="box1" style="display: none;width: 200px;box-sizing: border-box;box-shadow: 0 2px 4px rgba(0, 0, 0, .12); position: absolute;z-index: 999;background-color: #fff;border: 1px solid #d2d2d2;">
<ul class="tree_ul ztree" id="tree" ></ul>
</div>
</form>
</div>
</div>
<!-- title-->
<div class="row">
<div class="ibox-content" style="padding: 15px 0px;">
<div class="alert alert-info" style="margin-bottom: 0px;">
综合指标
</div>
</div>
</div>
<!-- 8个div-->
<div class="row ibox-content">
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">跟进线索数量</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="followClueNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">有效线索数量</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="validClueNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">商机数</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="intendNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">更新商机数</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="updateIntentNum">0</h2>
</div>
</div>
</div>
</div>
<div class="row ibox-content">
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">已报价线索数量</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="quotationNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">有疑义线索数量</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="doubtNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">成单数量</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="orderPayNum">0</h2>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="ibox">
<div class="ibox-title">
<h4 class="center">成单金额</h4>
</div>
<div class="ibox-content">
<p class="center beginToEnd">2021/07/01-2021/07/07</p>
<h2 class="center" id="orderPayAmount">0</h2>
</div>
</div>
</div>
</div>
<!-- 曲线+漏斗-->
<div class="row ibox-content">
<div class="col-sm-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>线索变化趋势</h5>
<p style="float: right;" class="beginToEnd">2020/07/01-2020/07/07</p>
</div>
<div class="ibox-content">
<div class="echarts" id="changeOne"></div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>线索转化漏斗</h5>
<p style="float: right;" class="beginToEnd">2020/07/01-2020/07/07</p>
</div>
<div class="ibox-content">
<div class="echarts" id="changeTwo"></div>
</div>
</div>
</div>
</div>
<!-- 列表-->
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="form2">
<div class="select-list">
<ul>
<li>
维度:
<input type="checkbox" name="selectParam" value="1" style="width: 50px;height: 20px;"/>团队
<input type="checkbox" name="selectParam" value="2" style="width: 50px;height: 20px;"/>电销
<input type="checkbox" name="selectParam" value="3" style="width: 50px;height: 20px;"/>线索类型
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="query();"><i class="fa fa-search"></i> 加载</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="reset();"><i class="fa fa-refresh"></i> 重置</a>
</li>
</ul>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js" />
<th:block th:include="include :: echarts-js" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: bootstrap-select-js"/>
<script th:inline="javascript">
var prefix = ctx + "project/telemarketingData";
var columus = [
{
field : 'followClueNum',
title : '跟进线索数量'
},
{
field : 'validClueNum',
title : '有效线索数量'
},
{
field : 'intendNum',
title : '商机数量'
},
{
field : 'updateIntentNum',
title : '更新商机数量'
},
{
field : 'quotationNum',
title : '已报价数量'
},
{
field : 'doubtNum',
title : '有疑义线索数量'
},
{
field : 'orderPayNum',
title : '成单量'
},
{
field : 'orderPayAmount',
title : '成单金额'
},
{
field : 'addWechatNum',
title : '已加微信数量'
}];
function query() {
$("#bootstrap-table").bootstrapTable('destroy');
//增加展示列
var columns2 = [];
var selectParam = "";
$("input[name='selectParam']:checked").each(function () {
selectParam = selectParam + $(this).val() + ",";
});
if (selectParam != "") {
var one = selectParam.indexOf("1");
var two = selectParam.indexOf("2");
var three = selectParam.indexOf("3");
if (one >= 0 && two < 0 && three < 0) {
// 1
columns2.push({
field : 'deptName',
title : '部门'
});
columns2 = columns2.concat(columus);
}else if (one >= 0 && two >= 0 && three < 0) {
// 1,2
columns2.push({
field : 'deptName',
title : '部门'
},
{
field : 'userName',
title : '电销'
});
columns2 = columns2.concat(columus);
}else if (one >= 0 && two < 0 && three >= 0) {
//1,3
columns2.push({
field : 'deptName',
title : '部门'
},
{
field : 'clueTypeName',
title : '线索类型'
});
columns2 = columns2.concat(columus);
}else if (one >= 0 && two >= 0 && three >= 0) {
//1,2,3
columns2.push({
field : 'deptName',
title : '部门'
},
{
field : 'userName',
title : '电销'
},
{
field : 'clueTypeName',
title : '线索类型'
});
columns2 = columns2.concat(columus);
}else if (one < 0 && two >= 0 && three < 0) {
//2
columns2.push(
{
field : 'userName',
title : '电销'
});
columns2 = columns2.concat(columus);
}else if (one < 0 && two >= 0 && three >= 0) {
//2,3
columns2.push(
{
field : 'userName',
title : '电销'
},
{
field : 'clueTypeName',
title : '线索类型'
});
columns2 = columns2.concat(columus);
}else {
//3
columns2.push(
{
field : 'clueTypeName',
title : '线索类型'
});
columns2 = columns2.concat(columus);
}
}else {
columns2 = columus;
}
var options = {
url: prefix + "/getTelemarketingDataGroup",
modalName: "统计报表",
showExport: false,
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
pagination:false,
queryParams: queryParams,
columns: columns2
};
$.table.init(options);
}
function queryParams(params) {
//获取复选框选中的值
var selectParam = "";
$("input[name='selectParam']:checked").each(function () {
selectParam = selectParam + $(this).val() + ",";
});
var search = $.table.queryParams(params);
search.selectParam = selectParam.toString();
return search;
}
function reset() {
$("[name='selectParam']").removeAttrs("checked");
}
$(function() {
// 初始化时间范围插件,传入三个id的名称
initDaterangepickerWithoutInitTime("recordDate","startTime","endTime");
getZtree();
var options = {
url: prefix + "/list",
modalName: "统计报表",
showExport: false,
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
pagination:false,
onLoadSuccess:onLoadSuccess,
columns: columus
};
$.table.init(options);
});
function onLoadSuccess(data) {
var rows = data.rows;
var beginToEnd = "";
var followClueNum = 0;
var validClueNum = 0;
var intendNum = 0;
var updateIntentNum = 0;
var quotationNum = 0;
var doubtNum = 0;
var orderPayNum = 0;
var orderPayAmount = 0;
var addWechatNum = 0;
var arrx = new Array();
var followClueNumArr = new Array();
var validClueNumArr = new Array();
var intendNumArr = new Array();
var updateIntentNumArr = new Array();
var quotationNumArr = new Array();
var doubtNumArr = new Array();
var orderPayNumArr = new Array();
var orderPayAmountArr = new Array();
rows.forEach(function (e,index) {
arrx[index] = e.recordDate;
//获取时间组合串
if (index == 0) {
beginToEnd += e.recordDate +"-";
}
if (index == rows.length-1) {
beginToEnd += e.recordDate;
}
followClueNumArr[index] = e.followClueNum;
followClueNum = parseInt(followClueNum) + parseInt(e.followClueNum);
validClueNumArr[index] = e.validClueNum;
validClueNum = parseInt(validClueNum) + parseInt(e.validClueNum);
intendNumArr[index] = e.intendNum;
intendNum = parseInt(intendNum) + parseInt(e.intendNum);
updateIntentNumArr[index] = e.updateIntentNum;
updateIntentNum = parseInt(updateIntentNum) + parseInt(e.updateIntentNum);
quotationNumArr[index] = e.quotationNum;
quotationNum = parseInt(quotationNum) + parseInt(e.quotationNum);
doubtNumArr[index] = e.doubtNum;
doubtNum = parseInt(doubtNum) + parseInt(e.doubtNum);
orderPayNumArr[index] = e.orderPayNum;
orderPayNum = parseInt(orderPayNum) + parseInt(e.orderPayNum);
orderPayAmountArr[index] = e.orderPayAmount;
orderPayAmount = parseInt(orderPayAmount) + parseInt(e.orderPayAmount);
addWechatNum = parseInt(addWechatNum) + parseInt(e.addWechatNum);
});
$(".beginToEnd").html(beginToEnd);
$("#followClueNum").html(followClueNum);
$("#validClueNum").html(validClueNum);
$("#intendNum").html(intendNum);
$("#updateIntentNum").html(updateIntentNum);
$("#quotationNum").html(quotationNum);
$("#doubtNum").html(doubtNum);
$("#orderPayNum").html(orderPayNum);
$("#orderPayAmount").html(orderPayAmount);
loadLine(arrx,followClueNumArr,validClueNumArr,intendNumArr,updateIntentNumArr,quotationNumArr,doubtNumArr,orderPayNumArr,orderPayAmountArr);
loadFunnel(validClueNum,intendNum,orderPayNum);
//重新加载合计后的数据 组合数据data
var newdata = [];
newdata.push({followClueNum:followClueNum,validClueNum:validClueNum,intendNum:intendNum,
updateIntentNum:updateIntentNum,quotationNum:quotationNum,doubtNum:doubtNum,
orderPayNum:orderPayNum,orderPayAmount:orderPayAmount,addWechatNum:addWechatNum});
//获取原始 columns
var params = $("#bootstrap-table").bootstrapTable('getOptions');
//销毁初始加载表格
$("#bootstrap-table").bootstrapTable('destroy');
//重新加载
$("#bootstrap-table").bootstrapTable({
modalName: "统计报表",
data:newdata,
showExport: false,
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
pagination:false,
columns: params.columns
});
}
//加载折线
function loadLine(arrx,followClueNumArr,validClueNumArr,intendNumArr,updateIntentNumArr,quotationNumArr,doubtNumArr,orderPayNumArr,orderPayAmountArr) {
//加载曲线
var chartDom = document.getElementById('changeOne');
var myChart = echarts.init(chartDom);
var option;
option = {
title: {
text: ''
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['跟进线索数量','有效线索数量', '商机数','更新商机数', '已报价线索数量', '有疑义线索数量', '成单数量','成单金额']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: arrx
},
yAxis: {
type: 'value'
},
series: [
{
name: '跟进线索数量',
type: 'line',
stack: '总量',
data: followClueNumArr
},
{
name: '有效线索数量',
type: 'line',
stack: '总量',
data: validClueNumArr
},
{
name: '商机数',
type: 'line',
stack: '总量',
data: intendNumArr
},
{
name: '更新商机数',
type: 'line',
stack: '总量',
data: updateIntentNumArr
},
{
name: '已报价线索数量',
type: 'line',
stack: '总量',
data: quotationNumArr
},
{
name: '有疑义线索数量',
type: 'line',
stack: '总量',
data: doubtNumArr
},
{
name: '成单数量',
type: 'line',
stack: '总量',
data: orderPayNumArr
},
{
name: '成单金额',
type: 'line',
stack: '总量',
data: orderPayAmountArr
}
]
};
option && myChart.setOption(option);
}
//加载漏斗图
function loadFunnel(validClueNum,intendNum,orderPayNum) {
//新建数组存放数量
var dataNum = new Array();
var json0 = {name:"有效用户"};
var json1 = {name:"商机"};
var json2 = {name:"成单"};
json0["value"]=validClueNum;
json1["value"]=intendNum;
json2["value"]=orderPayNum;
dataNum[0] = json0;
dataNum[1] = json1;
dataNum[2] = json2;
//新建数组存放转化率
var dataPercent = new Array();
var json00 = {name:"有效用户"};
var json11 = {name:"商机"};
var json22 = {name:"成单"};
if (validClueNum != 0) {
//商机转化率
var validPercent = parseFloat(validClueNum*100/validClueNum).toFixed(2);
var intendPercent = parseFloat(intendNum*100/validClueNum).toFixed(2);
json00["value"]=validPercent;
json11["value"]=intendPercent;
}else {
json00["value"]=0;
json11["value"]=0;
}
if (intendNum != 0) {
var orderPercent = parseFloat(orderPayNum*100/intendNum).toFixed(2);
json22["value"]=orderPercent;
}else {
json22["value"]=0;
}
dataPercent[0] = json00;
dataPercent[1] = json11;
dataPercent[2] = json22;
var chartDom = document.getElementById('changeTwo');
var myChart = echarts.init(chartDom);
var option;
option = {
tooltip: {
trigger: 'item',
formatter: "{b} : {c}"
},
legend: {
data: ['有效用户','商机','成单']
},
series: [
{
name: '数量',
type: 'funnel',
left: '10%',
width: '80%',
label: {
formatter: '{b}数'
},
labelLine: {
show: false
},
itemStyle: {
opacity: 0.7
},
emphasis: {
label: {
position: 'inside',
formatter: '{b}数: {c}'
}
},
data: dataNum
},
{
name: '转化率',
type: 'funnel',
left: '10%',
width: '80%',
label: {
position: 'inside',
formatter: '{c}%',
color: '#fff'
},
itemStyle: {
opacity: 0.5,
borderColor: '#fff',
borderWidth: 2
},
emphasis: {
label: {
position: 'inside',
formatter: '{b}转化率: {c}%'
}
},
data: dataPercent,
z: 100
}
]
};
option && myChart.setOption(option);
}
// 重置
function resetSearch(){
$("#actionClueType option:first").prop("selected",'selected');
$('#actionClueType').trigger('change.select2');
$.form.reset();
$("#recordDate").val('');
$("#startTime").val('');
$("#endTime").val('');
}
function getZtree() {
var url = ctx + "sys/userTreeData?status=0";
var options = {
url: url,
expandLevel: 2,
onCheck: callback,//点击事件
check: {
enable: true//是否开启复选框
}
};
$.tree.init(options);
//树节点点击事件
function callback() {
var treeObj = $.fn.zTree.getZTreeObj("tree"),
nodes = treeObj.getCheckedNodes(true),
v = "";
var userNames="";
var userIds="";
for (var i = 0; i < nodes.length; i++) {
//获取以u结尾的用户信息
if (nodes[i].id.toString().indexOf("u")!=-1) {
userNames+=nodes[i].name+";";
userIds+=nodes[i].id.toString().split("u")[0]+",";
}
}
$("#createUserName").val(userNames);
$("#createByIds").val(userIds);
}
}
//部门
function ztreeShow() {
var nameObj = $("#createUserName");
var nameOffset = nameObj.offset();
$("#treeDiv").css({left:nameOffset.left-20 + "px", top:nameOffset.top-21 + nameObj.outerHeight() + "px"}).slideDown("fast");
$("body").bind("mousedown", onBodyDown);
}
//树折叠
function onBodyDown(event) {
if (!(event.target.id == "treeDiv" || $(event.target).parents("#treeDiv").length > 0)) {
hideMenu();
}
}
function hideMenu() {
$("#treeDiv").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);
}
</script>
</body>
</html>
package com.dongao.project.telemarketingdata.controller;
import com.dongao.project.clueregular.domain.ClueRegular;
import com.dongao.project.clueregular.service.IClueRegularService;
import com.dongao.project.common.constants.Constants;
import com.dongao.project.sys.domain.MaxDataScope;
import com.dongao.project.sys.service.SysService;
import com.dongao.project.telemarketingdata.domain.TelemarketingData;
import com.dongao.project.telemarketingdata.service.ITelemarketingDataService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.DataScopeAspect;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.role.domain.Role;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 电销数据信息操作处理
*
* @author dongao
* @date 2021-08-16
*/
@Controller
@RequestMapping("/project/telemarketingData")
public class TelemarketingDataController extends BaseController
{
private String prefix = "project/telemarketingdata";
@Autowired
private ITelemarketingDataService telemarketingDataService;
@Autowired
private IClueRegularService clueRegularService;
@Autowired
private SysService sysService;
@RequiresPermissions("project:telemarketingData:view")
@GetMapping()
public String telemarketingData(ModelMap mmap)
{
//获取有效线索类型
ClueRegular cr = new ClueRegular();
cr.setDelFlag(Constants.DEL_FLAG.YES.getValue());
List<ClueRegular> clueRegulars = clueRegularService.selectClueRegularList(cr);
mmap.put("regulars",clueRegulars);
return prefix + "/telemarketingdata";
}
/**
* 查询电销数据列表
*/
@RequiresPermissions("project:telemarketingData:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(@RequestParam Map<String,Object> paramMap)
{
//电销数据列表 所属部门
String createByIds = (String) paramMap.get("createByIds");
if (StringUtils.isNotEmpty(createByIds)) {
paramMap.put("userList", Arrays.asList(Convert.toLongArray(createByIds)));
}else {
//部門數據權限
User currentUser = ShiroUtils.getSysUser();
List<Role> roles = currentUser.getRoles();
MaxDataScope maxDataScope = sysService.getMaxDataScope(roles, currentUser);
if (DataScopeAspect.DATA_SCOPE_ALL.equals(maxDataScope.getDataScope())) {
//当前用户角色是全数据权限
}else {
List<Long> userList = maxDataScope.getUserList();
paramMap.put("userList",userList);
}
}
List<Map> list = telemarketingDataService.getTelemarketingDataGroup(paramMap);
return getDataTable(list);
}
/**
* 获取有分组维度的统计数据
*/
@RequestMapping("/getTelemarketingDataGroup")
@ResponseBody
public TableDataInfo getTelemarketingDataGroup(@RequestParam Map<String,Object> paramMap)
{
String createByIds = (String) paramMap.get("createByIds");
//电销数据列表 所属部门
if (StringUtils.isNotEmpty(createByIds)) {
paramMap.put("userList", Arrays.asList(Convert.toLongArray(createByIds)));
}else {
//部門數據權限
User currentUser = ShiroUtils.getSysUser();
List<Role> roles = currentUser.getRoles();
MaxDataScope maxDataScope = sysService.getMaxDataScope(roles, currentUser);
if (DataScopeAspect.DATA_SCOPE_ALL.equals(maxDataScope.getDataScope())) {
//当前用户角色是全数据权限
}else {
List<Long> userList = maxDataScope.getUserList();
paramMap.put("userList",userList);
}
}
List<Map> list = telemarketingDataService.getTelemarketingDataGroup(paramMap);
return getDataTable(list);
}
}
package com.dongao.project.telemarketingdata.service;
import com.dongao.project.clueregular.domain.ClueRegular;
import com.dongao.project.clueregular.mapper.ClueRegularMapper;
import com.dongao.project.telemarketingdata.domain.TelemarketingData;
import com.dongao.project.telemarketingdata.mapper.TelemarketingDataMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.mapper.DeptMapper;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.mapper.UserMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* 电销数据 服务层实现
*
* @author dongao
* @date 2021-08-16
*/
@Service
public class TelemarketingDataServiceImpl implements ITelemarketingDataService
{
@Autowired
private TelemarketingDataMapper telemarketingDataMapper;
@Autowired
private DeptMapper deptMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private ClueRegularMapper clueRegularMapper;
/**
* 查询电销数据列表
* @param paramMap
* @return
*/
@Override
public List<Map> selectTelemarketingDataListOther(Map<String, Object> paramMap) {
List<TelemarketingData> dataList = telemarketingDataMapper.selectTelemarketingDataListOther(paramMap);
List<Map> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(dataList)) {
//获取返回参数值
TreeMap<Date, List<TelemarketingData>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getRecordDate, TreeMap::new, Collectors.toList()));
for (Date date : collect.keySet()) {
Map map = new HashMap(16);
//key 为分组日期参数
map.put("recordDate",DateUtils.parseDateToStr("yyyy/MM/dd",date));
List<TelemarketingData> teleData = collect.get(date);
getResultList(list, map, teleData);
}
}
return list;
}
/**
* 获取有分组维度的统计数据
* @param paramMap
* @return
*/
@Override
public List<Map> getTelemarketingDataGroup(Map paramMap) {
List<TelemarketingData> dataList = telemarketingDataMapper.selectTelemarketingDataListOther(paramMap);
List<Map> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(dataList)) {
//判断按那种维度分组
String selectParam = (String) paramMap.get("selectParam");
if (StringUtils.isNotEmpty(selectParam)) {
//1 团队 2 电销 3 线索类型
boolean one = selectParam.contains("1");
boolean two = selectParam.contains("2");
boolean three = selectParam.contains("3");
if (one && !two && !three) {
//1 团队分组
TreeMap<Long, List<TelemarketingData>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getDeptId, TreeMap::new, Collectors.toList()));
for (Long deptId : collect.keySet()) {
Map map = new HashMap(16);
// key is deptId
Dept dept = deptMapper.selectDeptById(deptId);
if (dept != null) {
map.put("deptName",dept.getDeptName());
}
List<TelemarketingData> teleData = collect.get(deptId);
getResultList(list, map, teleData);
}
}else if (one && two && !three) {
//1,2 团队+电销分组
TreeMap<Long, TreeMap<Long, List<TelemarketingData>>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getDeptId, TreeMap::new, Collectors.groupingBy(TelemarketingData::getRecordBy, TreeMap::new, Collectors.toList())));
for (Long deptId : collect.keySet()) {
// key is deptId
Dept dept = deptMapper.selectDeptById(deptId);
TreeMap<Long, List<TelemarketingData>> collect2 = collect.get(deptId);
for (Long recordBy : collect2.keySet()) {
Map map = new HashMap(16);
if (dept != null) {
map.put("deptName",dept.getDeptName());
}
//key is recordBy
User user = userMapper.selectUserById(recordBy);
if (user != null) {
map.put("userName",user.getUserName());
}
List<TelemarketingData> teleData = collect2.get(recordBy);
getResultList(list, map, teleData);
}
}
}else if (one && !two && three) {
//1,3 团队+线索类型分组
TreeMap<Long, TreeMap<Long, List<TelemarketingData>>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getDeptId, TreeMap::new, Collectors.groupingBy(TelemarketingData::getActionClueType, TreeMap::new, Collectors.toList())));
for (Long deptId : collect.keySet()) {
// key is deptId
Dept dept = deptMapper.selectDeptById(deptId);
TreeMap<Long, List<TelemarketingData>> collect2 = collect.get(deptId);
for (Long actionClueType : collect2.keySet()) {
Map map = new HashMap(16);
if (dept != null) {
map.put("deptName",dept.getDeptName());
}
//key is actionClueType
ClueRegular clueRegular = clueRegularMapper.selectClueRegularById(actionClueType);
if (clueRegular != null) {
map.put("clueTypeName",clueRegular.getClueTypeName());
}
List<TelemarketingData> teleData = collect2.get(actionClueType);
getResultList(list, map, teleData);
}
}
}else if (one && two && three) {
//1,2,3 团队+电销+线索类型 分组
TreeMap<Long, TreeMap<Long, TreeMap<Long, List<TelemarketingData>>>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getDeptId, TreeMap::new, Collectors.groupingBy(TelemarketingData::getRecordBy, TreeMap::new, Collectors.groupingBy(TelemarketingData::getActionClueType, TreeMap::new, Collectors.toList()))));
for (Long deptId : collect.keySet()) {
// key is deptId
Dept dept = deptMapper.selectDeptById(deptId);
TreeMap<Long, TreeMap<Long, List<TelemarketingData>>> collect2 = collect.get(deptId);
for (Long recordBy : collect2.keySet()) {
// key is recordBy
User user = userMapper.selectUserById(recordBy);
TreeMap<Long, List<TelemarketingData>> collect3 = collect2.get(recordBy);
for (Long actionClueType : collect3.keySet()) {
Map map = new HashMap(16);
if (dept != null) {
map.put("deptName",dept.getDeptName());
}
if (user != null) {
map.put("userName",user.getUserName());
}
//key is actionClueType
ClueRegular clueRegular = clueRegularMapper.selectClueRegularById(actionClueType);
if (clueRegular != null) {
map.put("clueTypeName",clueRegular.getClueTypeName());
}
List<TelemarketingData> teleData = collect3.get(actionClueType);
getResultList(list, map, teleData);
}
}
}
}else if (!one && two && !three) {
//2 电销分组
TreeMap<Long, List<TelemarketingData>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getRecordBy, TreeMap::new, Collectors.toList()));
for (Long recordBy : collect.keySet()) {
Map map = new HashMap(16);
// key is recordBy
User user = userMapper.selectUserById(recordBy);
if (user != null) {
map.put("userName",user.getUserName());
}
List<TelemarketingData> teleData = collect.get(recordBy);
getResultList(list, map, teleData);
}
}else if (!one && two && three) {
//2,3 电销+线索类型 分组
TreeMap<Long, TreeMap<Long, List<TelemarketingData>>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getRecordBy, TreeMap::new, Collectors.groupingBy(TelemarketingData::getActionClueType, TreeMap::new, Collectors.toList())));
for (Long recordBy : collect.keySet()) {
// key is recordBy
User user = userMapper.selectUserById(recordBy);
TreeMap<Long, List<TelemarketingData>> collect2 = collect.get(recordBy);
for (Long actionClueType : collect2.keySet()) {
Map map = new HashMap(16);
if (user != null) {
map.put("userName",user.getUserName());
}
//key is actionClueType
ClueRegular clueRegular = clueRegularMapper.selectClueRegularById(actionClueType);
if (clueRegular != null) {
map.put("clueTypeName",clueRegular.getClueTypeName());
}
List<TelemarketingData> teleData = collect2.get(actionClueType);
getResultList(list, map, teleData);
}
}
}else {
// 最后一种分组方式 3 线索类型分组
TreeMap<Long, List<TelemarketingData>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getActionClueType, TreeMap::new, Collectors.toList()));
for (Long actionClueType : collect.keySet()) {
Map map = new HashMap(16);
// key is actionClueType
ClueRegular clueRegular = clueRegularMapper.selectClueRegularById(actionClueType);
if (clueRegular != null) {
map.put("clueTypeName",clueRegular.getClueTypeName());
}
List<TelemarketingData> teleData = collect.get(actionClueType);
getResultList(list, map, teleData);
}
}
}else {
//无维度参数 则默认 统计日期分组
TreeMap<Date, List<TelemarketingData>> collect = dataList.stream().collect(Collectors.groupingBy(TelemarketingData::getRecordDate, TreeMap::new, Collectors.toList()));
for (Date date : collect.keySet()) {
Map map = new HashMap(16);
map.put("recordDate",DateUtils.parseDateToStr("yyyy/MM/dd",date));
List<TelemarketingData> teleData = collect.get(date);
getResultList(list, map, teleData);
}
}
}
return list;
}
/**
* 组装返回参数值
* @param list
* @param map
* @param teleData
*/
private void getResultList(List<Map> list, Map map, List<TelemarketingData> teleData) {
/** 跟进线索数量 */
long followClueNum = 0;
/** 有效线索数量 */
long validClueNum = 0;
/** 商机数量 */
long intendNum = 0;
/** 更新商机数量 */
long updateIntentNum = 0;
/** 已报价数量 */
long quotationNum = 0;
/** 有疑义线索数量 */
long doubtNum = 0;
/** 成单量 */
long orderPayNum = 0;
/** 成单金额 */
BigDecimal orderPayAmount = new BigDecimal(0);
/** 已加微信数量 */
long addWechatNum = 0;
for (TelemarketingData td : teleData) {
followClueNum += td.getFollowClueNum();
validClueNum += td.getValidClueNum();
intendNum += td.getIntendNum();
updateIntentNum += td.getUpdateIntentNum();
quotationNum += td.getQuotationNum();
doubtNum += td.getDoubtNum();
orderPayNum += td.getOrderPayNum();
orderPayAmount = orderPayAmount.add(td.getOrderPayAmount());
addWechatNum += td.getAddWechatNum();
}
map.put("followClueNum",followClueNum);
map.put("validClueNum",validClueNum);
map.put("intendNum",intendNum);
map.put("updateIntentNum",updateIntentNum);
map.put("quotationNum",quotationNum);
map.put("doubtNum",doubtNum);
map.put("orderPayNum",orderPayNum);
map.put("orderPayAmount",orderPayAmount);
map.put("addWechatNum",addWechatNum);
list.add(map);
}
}
<?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="com.dongao.project.telemarketingdata.mapper.TelemarketingDataMapper">
<resultMap type="TelemarketingData" id="TelemarketingDataResult">
<result property="id" column="id" />
<result property="recordDate" column="record_date" />
<result property="recordBy" column="record_by" />
<result property="actionClueType" column="action_clue_type" />
<result property="followClueNum" column="follow_clue_num" />
<result property="validClueNum" column="valid_clue_num" />
<result property="intendNum" column="intend_num" />
<result property="updateIntentNum" column="update_intent_num" />
<result property="quotationNum" column="quotation_num" />
<result property="doubtNum" column="doubt_num" />
<result property="orderPayNum" column="order_pay_num" />
<result property="orderPayAmount" column="order_pay_amount" />
<result property="addWechatNum" column="add_wechat_num" />
<result property="delFlag" column="del_flag" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectTelemarketingDataVo">
select id, record_date, record_by, action_clue_type, follow_clue_num, valid_clue_num, intend_num,update_intent_num, quotation_num, doubt_num, order_pay_num, order_pay_amount, add_wechat_num, del_flag, create_time, create_by, update_time, update_by, remark from crm_account_telemarketing_data
</sql>
<select id="selectTelemarketingDataList" parameterType="TelemarketingData" resultMap="TelemarketingDataResult">
<include refid="selectTelemarketingDataVo"/>
<where>
and del_flag = 0
<if test="id != null "> and id = #{id}</if>
<if test="recordDate != null "> and record_date = #{recordDate}</if>
<if test="recordBy != null "> and record_by = #{recordBy}</if>
<if test="actionClueType != null "> and action_clue_type = #{actionClueType}</if>
<if test="followClueNum != null "> and follow_clue_num = #{followClueNum}</if>
<if test="validClueNum != null "> and valid_clue_num = #{validClueNum}</if>
<if test="intendNum != null "> and intend_num = #{intendNum}</if>
<if test="updateIntentNum != null "> and update_intent_num = #{updateIntentNum}</if>
<if test="quotationNum != null "> and quotation_num = #{quotationNum}</if>
<if test="doubtNum != null "> and doubt_num = #{doubtNum}</if>
<if test="orderPayNum != null "> and order_pay_num = #{orderPayNum}</if>
<if test="orderPayAmount != null "> and order_pay_amount = #{orderPayAmount}</if>
<if test="addWechatNum != null "> and add_wechat_num = #{addWechatNum}</if>
<if test="delFlag != null "> and del_flag = #{delFlag}</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="createBy != null and createBy != '' "> and create_by = #{createBy}</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="updateBy != null and updateBy != '' "> and update_by = #{updateBy}</if>
<if test="remark != null and remark != '' "> and remark = #{remark}</if>
</where>
</select>
<select id="selectTelemarketingData" parameterType="TelemarketingData" resultMap="TelemarketingDataResult">
<include refid="selectTelemarketingDataVo"/>
<where>
and del_flag = 0
<if test="id != null "> and id = #{id}</if>
<if test="recordDate != null "> and record_date = #{recordDate}</if>
<if test="recordBy != null "> and record_by = #{recordBy}</if>
<if test="actionClueType != null "> and action_clue_type = #{actionClueType}</if>
<if test="followClueNum != null "> and follow_clue_num = #{followClueNum}</if>
<if test="validClueNum != null "> and valid_clue_num = #{validClueNum}</if>
<if test="intendNum != null "> and intend_num = #{intendNum}</if>
<if test="updateIntentNum != null "> and update_intent_num = #{updateIntentNum}</if>
<if test="quotationNum != null "> and quotation_num = #{quotationNum}</if>
<if test="doubtNum != null "> and doubt_num = #{doubtNum}</if>
<if test="orderPayNum != null "> and order_pay_num = #{orderPayNum}</if>
<if test="orderPayAmount != null "> and order_pay_amount = #{orderPayAmount}</if>
<if test="addWechatNum != null "> and add_wechat_num = #{addWechatNum}</if>
<if test="delFlag != null "> and del_flag = #{delFlag}</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="createBy != null and createBy != '' "> and create_by = #{createBy}</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="updateBy != null and updateBy != '' "> and update_by = #{updateBy}</if>
<if test="remark != null and remark != '' "> and remark = #{remark}</if>
</where>
</select>
<select id="selectTelemarketingDataListOther" parameterType="Map" resultMap="TelemarketingDataResult">
SELECT t1.record_date, t1.record_by, t1.action_clue_type, t1.follow_clue_num, t1.valid_clue_num, t1.intend_num,t1.update_intent_num,
t1.quotation_num, t1.doubt_num, t1.order_pay_num, t1.order_pay_amount, t1.add_wechat_num,t2.dept_id deptId
FROM crm_account_telemarketing_data t1
LEFT JOIN sys_user t2 ON t1.record_by=t2.user_id
WHERE t1.del_flag=0 AND t2.del_flag=0
<if test="paramMap != null">
<if test="paramMap.userList != null">
AND record_by IN
<foreach collection="paramMap.userList" item="recordBy" open="(" close=")" separator=",">
#{recordBy}
</foreach>
</if>
<if test="paramMap.actionClueType != null and paramMap.actionClueType != ''">
AND action_clue_type = #{paramMap.actionClueType}
</if>
<choose>
<when test="paramMap.startTime != null or paramMap.startTime != ''">
<if test="paramMap.startTime != null and paramMap.startTime != ''" >
AND record_date >= #{paramMap.startTime}
</if>
<if test="paramMap.endTime != null and paramMap.endTime != '' " >
AND record_date <= #{paramMap.endTime}
</if>
</when>
<otherwise>
AND record_date <= now()
</otherwise>
</choose>
</if>
ORDER BY record_date
</select>
</mapper>
【注】本文仅用于工作中日常记录,方便后续查阅,仅可用于学习用途,不可用于商业用途。