项目中需要一个统计功能,同时可以根据勾选不同维度的统计字段来实现列表动态增减,实现效果如图:https://pan.baidu.com/s/1D9cBOWJ2q6rqL7BpU_wcMQ?pwd=wx6q,由于语雀编辑器暂时不支持视频上传,这里是百度网盘的免提取码链接,可直接观看
首先需要处理的是页面动态增减列
accountFlowInfoRecordData.html
-
维度:
数据类型
数据来源
流转部门
考种
班次
员工
时间粒度
页面代码解析
页面核心函数query(),页面代码就说这么多,具体的可以查看源码,下面来看一下后端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);
}
}
后端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;
}
}
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
xml代码解析,主要关注id为selectAccountFlowInfoRecordDataListOther的sql查询,这里用到了${},那么这里也顺便说一下#{} ${}的区别
#{}将传入的参数当成一个字符串,会给传入的参数加一个双引号
KaTeX parse error: Expected 'EOF', got '#' at position 28: …生成在sql中,不会添加引号 #̲{}能够很大程度上防止sql注…{}无法防止sql注入
通过使用${}接收业务逻辑层处理动态传入的字段名动态生成分组查询sql,同时根据页面动态展示查询数据,到这里整个业务逻辑流程也就算完成了,实现的效果就和开始看到的效果一样了。
参考文章:https://developer.aliyun.com/article/985616