CRM项目08

复习

  • mybatis里
    排序用${},是把 ${ } 替换成变量的值,完成的是简单的字符串拼接。
    参数用#{},预编译防sql注入,# 加了 ' '

  • input禁止显示历史输入记录autocomplete="off"

  • map 是键值对的集合和类的多个属性名对应多个属性值是一样的

异常

input使用class名input-daterange后,bootstrap会作用于它,使bootstrap-datepicker日期插件无法作用到改input

to

一、报表功能

报表结果封装.png

分组统计sql

  • mapper
    根据员工姓名进行分组 , 统计潜在客户数,根据时间进行分组 , 统计潜在客户数
    返回值为hashMap时SQL语句的别名为key名

  • 查询条件
 
@Getter
@Setter
public class CustomerReportQueryObeject extends QueryObject {
    private String groupType = "e.name"; // 默认按员工姓名查询

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate; // 结束时间

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startDate; // 开始时间

    // 解决结束时间默认天后面的时间为00:00:00 导致查询不到结束时间这一天数据的问题 
    public Date getEndDate() { // 获取结束时间当天最晚的时候
        return DateUtil.getEndDate(endDate);
    }
}

  • 前端按时间分组查询条件预设

二、 图形报表

ECharts可视化图表插件

ECharts是一款由百度前端技术部开发的 , 开源免费的 , 基于Javascript, 可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器,提供直观,生动,可交互,可高度个性化定制的数据可视化图表。
官网:https://echarts.apache.org/zh/index.html

控制器

     /**
     * 访问柱状图页面
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/listByBar")
    public String listByBar (Model model, @ModelAttribute("qo") CustomerReportQueryObeject qo){
        // 查询统计的数据
        List data = customerReportService.selectAll(qo);
        // 准备两个集合
        ArrayList xList = new ArrayList<>();
        ArrayList yList = new ArrayList<>();
        // 遍历获取每个map
        for (HashMap map : data) {
            xList.add(map.get("groupType"));
            yList.add(map.get("number"));
        }
        // freemarker不能直接用${}获取集合
        model.addAttribute("xList", JSON.toJSONString(xList)); // 先转为字符串的形式,再共享到页面
        model.addAttribute("yList", JSON.toJSONString(yList));
        //分组类型转为文字显示
        model.addAttribute("groupTypeName", MessageUtil.changMsg(qo));
        return "customerReport/bar";
    }

    /**
     * 访问饼状图页面
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/listByPie")
    public String listByPie (Model model, @ModelAttribute("qo") CustomerReportQueryObeject qo){
        // 查询统计的数据
        List data = customerReportService.selectAll(qo);
        // 准备两个集合
        ArrayList legendList = new ArrayList<>();
        ArrayList seriesList = new ArrayList<>();
        // 遍历获取每个map
        for (HashMap map : data) {
            legendList.add(map.get("groupType"));
            HashMap obj = new HashMap<>();
            obj.put("name", map.get("groupType"));
            obj.put("value", map.get("number"));
            seriesList.add(obj);
        }
        // freemarker不能直接用${}获取集合
        model.addAttribute("legendList", JSON.toJSONString(legendList)); // 先转为字符串的形式,再共享到页面
        model.addAttribute("seriesList", JSON.toJSONString(seriesList));
        //分组类型转为文字显示
        model.addAttribute("groupTypeName", MessageUtil.changMsg(qo));
        return "customerReport/pie";
    }
 
 

前端远程加载到模态框

         $(".btn-chart").click(function () {
                // 因为load方法只会加载一次,需要清空模态框的缓存
                $('#chartModal').removeData('bs.modal');
                // 获取url地址
                var url = $(this).data('url');
                // 告诉模态框图形报表url是哪个,加载内容并且放到模态框
                $('#chartModal').modal({
                    remote : url + "?" + $("#searchForm").serialize() //加上高级查询的条件
                })
                $("#chartModal").modal('show');
            })

柱状图




    
    柱状图




饼状图

    // 指定图表的配置项和数据
    option = {
        title: {
            text: '潜在客户报表饼状图',
            subtext: "分组类型: ${groupTypeName}",
            left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} 
{b} : {c} ({d}%)' }, legend: { orient: 'vertical', left: 'left', data: ${legendList} }, series: [ { name: '访问来源', type: 'pie', radius: '55%', center: ['50%', '60%'], data: ${seriesList}, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] };

你可能感兴趣的:(CRM项目08)