• 基于若依springboot架构实现数据多维统计


    基于若依springboot架构实现数据多维统计

    需求背景

    项目中需要一个统计功能,同时可以根据勾选不同维度的统计字段来实现列表动态增减,实现效果如图:https://pan.baidu.com/s/1D9cBOWJ2q6rqL7BpU_wcMQ?pwd=wx6q,由于语雀编辑器暂时不支持视频上传,这里是百度网盘的免提取码链接,可直接观看

    代码实现

    首先需要处理的是页面动态增减列

    页面代码

    accountFlowInfoRecordData.html

    
    
    
      
    
    
         
    • 流转类型:
    • 数据来源:
    • 流转部门:
    • 考种:
    • 班次:
    • 员工:
    • 登记时间:
    •  搜索  重置
    • 维度: 数据类型 数据来源 流转部门 考种 班次 员工 时间粒度
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339

    页面代码解析




    页面核心函数query(),页面代码就说这么多,具体的可以查看源码,下面来看一下后端java代码

    java代码

    controllerk类AccountFlowInfoRecordDataController.java源码

    package com.dongao.project.accountflowinforecorddata.controller;
    
    import java.util.List;
    import java.util.Map;
    
    import com.dongao.project.examtype.domain.ExamType;
    import com.dongao.project.examtype.service.IExamTypeService;
    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 com.ruoyi.framework.aspectj.lang.annotation.Log;
    import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
    import com.dongao.project.accountflowinforecorddata.domain.AccountFlowInfoRecordData;
    import com.dongao.project.accountflowinforecorddata.service.IAccountFlowInfoRecordDataService;
    import com.ruoyi.framework.web.controller.BaseController;
    import com.ruoyi.framework.web.page.TableDataInfo;
    import com.ruoyi.framework.web.domain.AjaxResult;
    import com.ruoyi.common.utils.poi.ExcelUtil;
    
    /**
     * 流转记录统计信息操作处理
     * 
     * @author dongao
     * @date 2022-07-01
     */
    @Controller
    @RequestMapping("/project/accountFlowInfoRecordData")
    public class AccountFlowInfoRecordDataController extends BaseController
    {
        private String prefix = "project/accountFlowInfoRecordData";
      
      @Autowired
      private IAccountFlowInfoRecordDataService accountFlowInfoRecordDataService;
      @Autowired
      private IExamTypeService examTypeService;
      
      @RequiresPermissions("project:accountFlowInfoRecordData:view")
      @GetMapping()
      public String accountFlowInfoRecordData(ModelMap mmap)
      {
        ExamType examType = new ExamType();
        List examTypes = examTypeService.selectExamTypeList(examType);
        mmap.put("examTypes",examTypes);
          return prefix + "/accountFlowInfoRecordData";
      }
      
      /**
       * 查询流转记录统计列表
       */
      @RequiresPermissions("project:accountFlowInfoRecordData:list")
      @PostMapping("/list")
      @ResponseBody
      public TableDataInfo list(@RequestParam Map params)
      {
        startPage();
            List list =
            accountFlowInfoRecordDataService.selectAccountFlowInfoRecordDataListOther(params);
        return getDataTable(list);
      }
    
      /**
       * 分组查询流转记录统计列表
       */
      @RequiresPermissions("project:accountFlowInfoRecordData:list")
      @PostMapping("/getAccountDataGroup")
      @ResponseBody
      public TableDataInfo getAccountDataGroup(@RequestParam Map params)
      {
        startPage();
            List list =
            accountFlowInfoRecordDataService.getAccountDataGroup(params);
        return getDataTable(list);
      }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77

    后端java代码解析


    业务逻辑实现类AccountFlowInfoRecordDataServiceImpl.java代码

    package com.dongao.project.accountflowinforecorddata.service;
    
    import com.dongao.project.accountflowinforecorddata.domain.AccountFlowInfoRecordData;
    import com.dongao.project.accountflowinforecorddata.mapper.AccountFlowInfoRecordDataMapper;
    import com.dongao.project.examtype.domain.ExamType;
    import com.dongao.project.examtype.mapper.ExamTypeMapper;
    import com.ruoyi.common.utils.StringUtils;
    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.util.List;
    import java.util.Map;
    import java.util.Objects;
    
    /**
     * 流转记录统计 服务层实现
     * 
     * @author dongao
     * @date 2022-07-01
     */
    @Service
    public class AccountFlowInfoRecordDataServiceImpl implements IAccountFlowInfoRecordDataService 
    {
      @Autowired
      private AccountFlowInfoRecordDataMapper accountFlowInfoRecordDataMapper;
      @Autowired
      private DeptMapper deptMapper;
      @Autowired
      private ExamTypeMapper examTypeMapper;
      @Autowired
      private UserMapper userMapper;
      
      /**
         * 查询流转记录统计列表
         * 
         * @param accountFlowInfoRecordData 流转记录统计信息
         * @return 流转记录统计集合
         */
      @Override
      public List selectAccountFlowInfoRecordDataList(AccountFlowInfoRecordData accountFlowInfoRecordData)
      {
          return accountFlowInfoRecordDataMapper.selectAccountFlowInfoRecordDataList(accountFlowInfoRecordData);
      }
      
      /**
       * 查询数据
       * @param params
       * @return
       */
      @Override
      public List selectAccountFlowInfoRecordDataListOther(Map params) {
        List list =
            accountFlowInfoRecordDataMapper.selectAccountFlowInfoRecordDataListOther(params);
        return list;
      }
    
      /**
       * 分组查询流转记录统计列表
       * @param params
       * @return
       */
      @Override
      public List getAccountDataGroup(Map params) {
        //分组参数
        String selectParam = (String) params.get("selectParam");
        if (StringUtils.isNotEmpty(selectParam)) {
          String groupby = "";
          String groupfield = "";
          if (selectParam.contains("1")) {
            groupby = groupby + "channel_type,";
            groupfield = groupfield + "channel_type channel_type,";
          }
          if (selectParam.contains("2")) {
            groupby = groupby + "create_dept_id,";
            groupfield = groupfield + "create_dept_id create_dept_id,";
          }
          if (selectParam.contains("3")) {
            groupby = groupby + "flow_dept_id,";
            groupfield = groupfield + "flow_dept_id flow_dept_id,";
          }
          if (selectParam.contains("4")) {
            groupby = groupby + "exam_type_id,";
            groupfield = groupfield + "exam_type_id exam_type_id,";
          }
          if (selectParam.contains("5")) {
            groupby = groupby + "shift_id,";
            groupfield = groupfield + "shift_id shift_id,";
          }
          if (selectParam.contains("6")) {
            groupby = groupby + "user_id,";
            groupfield = groupfield + "user_id user_id,";
          }
          if (selectParam.contains("7")) {
            groupby = groupby + "account_time";
            groupfield = groupfield + "account_time account_time,";
          }
          if (groupby.endsWith(",")) {
            groupby = groupby.substring(0, groupby.length() - 1);
          }
          params.put("groupby",groupby);
          //字段用
          groupfield = groupfield + "SUM(allot_nums) allot_nums,SUM(daily_order_nums) daily_order_nums,SUM(total_order_nums) total_order_nums ";
          params.put("groupfield",groupfield);
        }
        List list = accountFlowInfoRecordDataMapper.selectAccountFlowInfoRecordDataListOther(params);
        if (CollectionUtils.isNotEmpty(list)) {
          // 1 数据类型-页面处理  3 流转部门 4 考种 5 班次--页面处理 6 员工 7 时间粒度
          for (AccountFlowInfoRecordData account : list) {
            //2 数据来源
            if (Objects.nonNull(account.getCreateDeptId())) {
              Dept dept = deptMapper.selectDeptById(account.getCreateDeptId());
              if (Objects.nonNull(dept)) {
                account.setCreateDeptName(dept.getDeptName());
              }
            }
            //3 流转部门
            if (Objects.nonNull(account.getFlowDeptId())) {
              Dept dept = deptMapper.selectDeptById(account.getFlowDeptId());
              if (Objects.nonNull(dept)) {
                account.setFlowDeptName(dept.getDeptName());
              }
            }
            //4 考种
            if (Objects.nonNull(account.getExamTypeId())) {
              ExamType examType = examTypeMapper.selectExamTypeById(account.getExamTypeId());
              if (Objects.nonNull(examType)) {
                account.setExamTypeName(examType.getExamName());
              }
            }
            //6 员工
            if (Objects.nonNull(account.getUserId())) {
              User user = userMapper.selectUserById(account.getUserId());
              if (Objects.nonNull(user)) {
                account.setUserName(user.getUserName());
              }
            }
          }
        }
        return list;
      }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148

    XML代码AccountFlowInfoRecordDataMapper.xml

    
    
    
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
      
        
            select id, account_time, user_id, dept_id, channel_type, create_dept_id, flow_dept_id, exam_type_id, shift_id, smallest_unit, allot_nums, daily_order_nums, total_order_nums, create_time, update_time from crm_account_flow_info_record_data
        
      
        
        
        
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97

    xml代码解析,主要关注id为selectAccountFlowInfoRecordDataListOther的sql查询,这里用到了${},那么这里也顺便说一下#{} ${}的区别

    #{} ${}的区别

    #{}将传入的参数当成一个字符串,会给传入的参数加一个双引号
    KaTeX parse error: Expected 'EOF', got '#' at position 28: …生成在sql中,不会添加引号 #̲{}能够很大程度上防止sql注…{}无法防止sql注入
    通过使用${}接收业务逻辑层处理动态传入的字段名动态生成分组查询sql,同时根据页面动态展示查询数据,到这里整个业务逻辑流程也就算完成了,实现的效果就和开始看到的效果一样了。

    参考文章:https://developer.aliyun.com/article/985616

  • 相关阅读:
    git使用及常用命令
    解决 Cannot read property ‘key‘ of undefined
    授人以渔 选购篇九:扫地机器人(扫拖机器人)选购要点
    word域代码交叉引用合并
    Vue+Leaflet.PM插件实现创建和编辑几何图形(点、线、面、圆等)
    CodeLite 16.0可以编译通过,但是在编辑器界面会显示找不到标准库头文件
    Day07--生命周期的概念与分类
    Semantic-Guided Zero-Shot Learning for Low-Light ImageVideo Enhancement
    智能指针的理解
    大众集团「官宣」造芯计划,汽车芯片「玩法」大变样
  • 原文地址:https://blog.csdn.net/csdn565973850/article/details/126020702