zq-erp/src/main/java/com/matrix/system/hiveErp/action/DataAnalysisCustomer.java
@@ -6,10 +6,9 @@ import com.matrix.system.common.bean.SysUsers; import com.matrix.system.hive.bean.SysShopInfo; import com.matrix.system.hive.dao.SysShopInfoDao; import com.matrix.system.hiveErp.analysUtil.SeriesVo; import com.matrix.system.hiveErp.analysUtil.StatisticsParamVo; import com.matrix.system.hiveErp.analysUtil.*; import com.matrix.system.hiveErp.dao.TjVipSumDao; import com.matrix.system.hiveErp.analysUtil.StatisticsTimeUtil; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -41,9 +40,50 @@ * @param statisticsParam * @return */ @RequestMapping(value = "customerHeadCompare") public @ResponseBody AjaxResult vipVisitCompare(StatisticsParamVo statisticsParam) { @RequestMapping(value = "/customerHeadCompare") public @ResponseBody AjaxResult customerHeadCompare(StatisticsParamVo statisticsParam) { return getAnalysisResult(statisticsParam, new Caculate() { @Override public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId) { //从员工业绩统计表中,按时间段,门店的维度统计人头数 return tjVipSumDao.customerHeadCompare(timeSpaceParam,shopId); } }); } /** * 会员人次统计 * 业务说明: * 一个会员在一天进店一次或者多次即为一个人次 * @param statisticsParam * @return */ @RequestMapping(value = "/customerEnterCountCompare") public @ResponseBody AjaxResult customerEnterCountCompare(StatisticsParamVo statisticsParam) { return getAnalysisResult(statisticsParam, new Caculate() { @Override public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId) { //从员工业绩统计表中,按时间段,门店的维度统计人次 return tjVipSumDao.customerEnterCountCompare(timeSpaceParam,shopId); } }); } /** * 按店铺查询数据通用格式执行方法,支持时、日、月、年维度 * 如: A店铺 B店铺 * 2020-01-01 12 13 * 2020-02-02 10 11 * @param statisticsParam 时间条件 * @param caculate 循环调用caculate计算该店的数据 * 查询的数据需满足 只有一个门店只有一行 列名称为 t0,t1,t2 * @return */ private AjaxResult getAnalysisResult(StatisticsParamVo statisticsParam, Caculate caculate) { AjaxResult result = new AjaxResult(); //根据计算横坐标 @@ -62,16 +102,16 @@ int i=0; //按门店统计数据 List<StatisticsTimeDaoParam> timeSpaceParam = StatisticsTimeUtil.buidParam(xAxis); for(SysShopInfo shop: shops){ legendData[i++]=shop.getShopName(); //数据项内容 SeriesVo storeInfoSeries=new SeriesVo(); storeInfoSeries.setName(shop.getShopName()); //从员工业绩统计表中,按时间段,门店的维度统计人头数 Map<String, Integer> yAxisMap = tjVipSumDao.countVisitByTime(StatisticsTimeUtil.buidParam(xAxis),shop.getId()); //调用计算器获取数据库统计的结果 Map<String, Integer> yAxisMap = caculate.exec(timeSpaceParam,shop.getId()); //把统计结果转成数组格式 storeInfoSeries.setData(StatisticsTimeUtil.getSeries(yAxisMap)); series.add(storeInfoSeries); zq-erp/src/main/java/com/matrix/system/hiveErp/analysUtil/Caculate.java
New file @@ -0,0 +1,10 @@ package com.matrix.system.hiveErp.analysUtil; import java.util.List; import java.util.Map; /** * 明细数值计算器 */ public interface Caculate { public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam , Long shopId); } zq-erp/src/main/java/com/matrix/system/hiveErp/analysUtil/StatisticsTimeUtil.java
@@ -14,6 +14,9 @@ */ public class StatisticsTimeUtil { /** * 获取map中的值为数组 * @param yAxisMap zq-erp/src/main/java/com/matrix/system/hiveErp/dao/TjVipSumDao.java
@@ -11,6 +11,7 @@ public interface TjVipSumDao { Map<String,Integer> countVisitByTime(@Param("list") List<StatisticsTimeDaoParam> daoParams, @Param("shopId") Long shopId); Map<String,Integer> customerHeadCompare(@Param("list") List<StatisticsTimeDaoParam> daoParams, @Param("shopId") Long shopId); Map<String, Integer> customerEnterCountCompare(@Param("list") List<StatisticsTimeDaoParam> timeSpaceParam, @Param("shopId") Long shopId); } zq-erp/src/main/resources/mybatis/mapper/hive/TjVipSumDao.xml
@@ -7,7 +7,7 @@ <!-- 人头数统计 --> <select id="countVisitByTime" resultType="java.util.TreeMap"> <select id="customerHeadCompare" resultType="java.util.TreeMap"> select <foreach collection="list" index="index" item="item" separator="," > ( @@ -16,7 +16,6 @@ <if test="shopId !=null and shopId !=0 " > and SHOP_ID = #{shopId} </if> ) t ) as t${index} @@ -24,5 +23,22 @@ from area where id=1 </select> <!-- 人次统计 --> <select id="customerEnterCountCompare" resultType="java.util.TreeMap"> select <foreach collection="list" index="index" item="item" separator="," > ( SELECT count(*) from ( SELECT DISTINCT vip_id ,date_format(datatime,'%Y-%m-%d') from achieve_new where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime} ]]> <if test="shopId !=null and shopId !=0 " > and SHOP_ID = #{shopId} </if> ) t ) as t${index} </foreach> from area where id=1 </select> </mapper> zq-erp/src/main/resources/static/css/style.min.css
@@ -7128,7 +7128,7 @@ } .echarts { height: 240px height: 400px } .checkbox-inline, .checkbox-inline+.checkbox-inline, .radio-inline, zq-erp/src/main/resources/templates/views/admin/hive-erp/analysis/customerFlow.html
@@ -12,7 +12,12 @@ <script type="text/javascript" th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script> <script type="text/javascript" th:src="@{/js/systools/MBase.js}"></script> <style> .echarts { height: 400px } </style> </head> <body class=" container-fluid"> @@ -55,30 +60,17 @@ <div class="row chartsBox " style="margin-top: 40px"> <div class=" col-md-12"> <div class="echarts" id="echarts-line-chart1"></div> </div> </div> <div class="row chartsBox " style="margin-top: 40px"> <div class=" col-md-12"> <div class="echarts" id="echarts-line-chart2"></div> </div> </div> <!-- <div class="row chartsBox " style="margin-top: 40px"> <div class=" col-md-12" id="table"> <table class="table table-striped" > <thead> <tr> <th>时间</th> <th v-for="name in legend" >{{name}}</th> </tr> </thead> <tbody> <tr v-for="(item,index) in xAxis"> <td>{{item}}</td> <td v-for="data in series[index].data" >{{data}}</td> </tr> </tbody> </table> </div> </div> --> </div> <script type="text/javascript" th:src="@{/js/systools/MJsBase.js}"></script> @@ -88,7 +80,7 @@ <script type="text/javascript" th:src="@{/plugin/StringUtil.js}"></script> <script type="text/javascript" th:src="@{/plugin/moment.min.js}"></script> <script type="text/javascript" th:src="@{/js/systools/ChartsUtils.js}"></script> <script type="text/javascript" th:src="@{/js/plugin/vue.js}"></script> <script> @@ -98,11 +90,14 @@ // 基于准备好的dom,初始化echarts实例 var myChart1 = echarts.init(document.getElementById('echarts-line-chart1'), 'macarons'); var myChart2 = echarts.init(document.getElementById('echarts-line-chart2'), 'macarons'); myChart2.on('click', function (params) { /* 点击事件 myChart1.on('click', function (params) { console.log(params); }); */ // 指定图表的配置项和数据 function getption(title) { return { @@ -138,12 +133,6 @@ yAxis: { type: 'value' }, series: [{ name: '人头数', type: 'line', smooth: true, data: [1,2] }], dataZoom: [ { id: 'dataZoomX', @@ -153,8 +142,8 @@ } ], animation: true, animationDuration: 1000, animationDurationUpdate: 1000, animationDuration: 500, animationDurationUpdate: 500, animationEasing: 'linear', animationEasingUpdate: 'linear', } @@ -166,7 +155,7 @@ //加载数据 function loadData() { //加载门店客流对比 myChart2.showLoading(); myChart1.showLoading(); $.AjaxProxy({ p: MForm.toJson("#serchform"), c: false, @@ -181,28 +170,41 @@ option.xAxis.data = map.xAxis; console.log(option); // 使用刚指定的配置项和数据显示图表。 myChart1.setOption(option); myChart1.hideLoading(); }); } var chartsUtils1 = new ChartsUtils(loadData); chartsUtils1.setDataPackTimeValue(); chartsUtils1.loadChartData(); //加载数据2 function loadData2() { //加载门店客流对比 myChart2.showLoading(); $.AjaxProxy({ p: MForm.toJson("#serchform"), c: false, }).invoke(basePath+"/admin/analysis/customerEnterCountCompare", function (loj) { var map = loj.getValue("mapInfo"); var option = getption("门店人次对比"); option.series = map.series; option.legend.data = map.legendData; option.xAxis.data = map.xAxis; // 使用刚指定的配置项和数据显示图表。 myChart2.setOption(option); myChart2.hideLoading(); }); } var ChartsUtils = new ChartsUtils(loadData); ChartsUtils.setDataPackTimeValue(); ChartsUtils.loadChartData(); var chartsUtils2 = new ChartsUtils(loadData2); chartsUtils2.setDataPackTimeValue(); chartsUtils2.loadChartData(); function buildTable(map){ console.log(buildTable,map); var app = new Vue({ el: '#table', data: { series : map.series, legend : map.legendData, xAxis : map.xAxis } } ); }