Dashboard

木子李·De 3 years ago
parent 34f73211a3
commit 0dffccd895

@ -0,0 +1,64 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.controller;
import com.anji.plus.gaea.annotation.Permission;
import com.anji.plus.gaea.annotation.log.GaeaAuditLog;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ReportDashboardObjectDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ReportDashboardService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @desc controller
* @website https://gitee.com/anji-plus/gaea
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@RestController
@Api(tags = "大屏设计管理")
@RequestMapping("/reportDashboard")
public class ReportDashboardController {
@Autowired
private ReportDashboardService reportDashboardService;
/**
*
* @param reportCode
* @return
*/
@GetMapping({"/{reportCode}"})
@Permission(code = "DETAIL", name = "明细")
public ResponseBean detail(@PathVariable("reportCode") String reportCode) {
return ResponseBean.builder().data(reportDashboardService.getDetail(reportCode)).build();
}
/**
*
* @param dto
* @return
*/
@PostMapping
@Permission(code = "INSERT", name = "新增")
@GaeaAuditLog(pageTitle = "新增")
public ResponseBean insert(@RequestBody ReportDashboardObjectDto dto) {
reportDashboardService.insertDashboard(dto);
return ResponseBean.builder().build();
}
/**
*
* @param dto
* @return
*/
@PostMapping("/getData")
@Permission(code = "DETAIL", name = "明细图表数据")
public ResponseBean getData(@RequestBody ChartDto dto) {
return ResponseBean.builder().data(reportDashboardService.getChartData(dto)).build();
}
}

@ -0,0 +1,51 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
/**
*
* @description dto
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@Data
public class ChartDto implements Serializable {
private String chartType;
/**数据集编码*/
private String setCode;
/** 传入的自定义参数*/
private Map<String, Object> contextData;
/**图表属性*/
private Map<String, String> chartProperties;
/**时间字段*/
private String timeLineFiled;
/**时间颗粒度*/
private String particles;
/**时间格式化*/
private String dataTimeFormat;
/**时间展示层*/
private String timeLineFormat;
private int timeUnit;
/**时间区间*/
private String startTime;
/**时间区间*/
private String endTime;
}

@ -0,0 +1,55 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto.ReportDashboardWidgetDto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
*
* @description dto
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@Data
public class ReportDashboardDto extends GaeaBaseDTO implements Serializable {
/** 报表编码 */
private String reportCode;
/** 看板标题 */
private String title;
/** 宽度px */
private Long width;
/** 高度px */
private Long height;
/** 背景色 */
private String backgroundColor;
/** 背景图片 */
private String backgroundImage;
/** 工作台中的辅助线 */
private String presetLine;
/** 自动刷新间隔秒数据字典REFRESH_TYPE */
private Integer refreshSeconds;
/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
private Integer enableFlag;
/** 0--未删除 1--已删除 DIC_NAME=DEL_FLAG */
private Integer deleteFlag;
/** 排序,降序 */
private Integer sort;
private List<ReportDashboardWidgetDto> widgets;
}

@ -0,0 +1,32 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto.ReportDashboardWidgetDto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
*
* @description dto
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@Data
public class ReportDashboardObjectDto implements Serializable {
/** 报表编码 */
private String reportCode;
/**
*
*/
private ReportDashboardDto dashboard;
/**
*
*/
private List<ReportDashboardWidgetDto> widgets;
}

@ -0,0 +1,20 @@
/**/
package com.anjiplus.template.gaea.business.modules.data.dashboard.controller.param;
import lombok.Data;
import java.io.Serializable;
import com.anji.plus.gaea.annotation.Query;
import com.anji.plus.gaea.constant.QueryEnum;
import com.anji.plus.gaea.curd.params.PageParam;
import java.util.List;
/**
* @desc ReportDashboard
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@Data
public class ReportDashboardParam extends PageParam implements Serializable{
}

@ -0,0 +1,16 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.dao;
import org.apache.ibatis.annotations.Mapper;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.dashboard.dao.entity.ReportDashboard;
/**
* ReportDashboard Mapper
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@Mapper
public interface ReportDashboardMapper extends GaeaBaseMapper<ReportDashboard> {
}

@ -0,0 +1,58 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.dao.entity;
import com.anji.plus.gaea.annotation.Unique;
import com.anjiplus.template.gaea.common.RespCommonCode;
import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import javax.validation.constraints.*;
import java.sql.Timestamp;
/**
* @description entity
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@TableName(value="gaea_report_dashboard")
@Data
public class ReportDashboard extends GaeaBaseEntity {
@ApiModelProperty(value = "报表编码")
@Unique(code = RespCommonCode.REPORT_CODE_ISEXIST)
private String reportCode;
@ApiModelProperty(value = "看板标题")
private String title;
@ApiModelProperty(value = "宽度px")
private Long width;
@ApiModelProperty(value = "高度px")
private Long height;
@ApiModelProperty(value = "背景色")
private String backgroundColor;
@ApiModelProperty(value = "背景图片")
private String backgroundImage;
@ApiModelProperty(value = "工作台中的辅助线")
private String presetLine;
@ApiModelProperty(value = "自动刷新间隔秒数据字典REFRESH_TYPE")
private Integer refreshSeconds;
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
private Integer enableFlag;
@ApiModelProperty(value = " 0--未删除 1--已删除 DIC_NAME=DEL_FLAG")
private Integer deleteFlag;
@ApiModelProperty(value = "排序,降序")
private Integer sort;
}

@ -0,0 +1,26 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import java.util.List;
/**
* Created by raodeming on 2021/4/26.
*/
public interface ChartStrategy {
/**
*
* @return
*/
String type();
/**
*
*
* @param dto
* @return
*/
Object transform(ChartDto dto, List<JSONObject> data);
}

@ -0,0 +1,38 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ReportDashboardObjectDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.param.ReportDashboardParam;
import com.anjiplus.template.gaea.business.modules.data.dashboard.dao.entity.ReportDashboard;
/**
* @desc ReportDashboard
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
public interface ReportDashboardService extends GaeaBaseService<ReportDashboardParam, ReportDashboard> {
/***
*
*
* @param reportCode
*/
ReportDashboardObjectDto getDetail(String reportCode);
/***
*
*
* @param dto
*/
void insertDashboard(ReportDashboardObjectDto dto);
/**
*
* @param dto
* @return
*/
Object getChartData(ChartDto dto);
}

@ -0,0 +1,81 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ChartStrategy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 线
* Created by raodeming on 2021/4/26.
*/
@Component
public class BarChartServiceImpl implements ChartStrategy {
/**
*
*
* @return
*/
@Override
public String type() {
return "widget-barchart|widget-linechart";
}
/**
*
*
* @param dto
* @param data
* @return
*/
@Override
public Object transform(ChartDto dto, List<JSONObject> data) {
// JSONObject json = new JSONObject();
// List<Object> xAxis = new ArrayList<>();
// List<Object> series = new ArrayList<>();
// data.forEach(jsonObject -> {
// jsonObject.forEach((s, o) -> {
// if ("xAxis".equals(s)) {
// xAxis.add(o);
// } else {
// series.add(o);
// }
// });
// });
//
// json.put("xAxis", xAxis);
// JSONArray objects = new JSONArray();
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("data", series);
// objects.add(jsonObject);
// json.put("series", objects);
// return json.toJSONString();
return data;
}
/* {
"xAxis": [
"哈哈",
"洗洗",
"来了",
"问问",
"天天"
],
"series": [
{
"data": [
1,
2,
3,
4,
5
]
}
]
}*/
}

@ -0,0 +1,108 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ChartStrategy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* Created by raodeming on 2021/4/26.
*/
@Component
public class BarLineChartServiceImpl implements ChartStrategy {
/**
*
*
* @return
*/
@Override
public String type() {
return "widget-barlinechart";
}
/**
*
*
* @param dto
* @param data
* @return
*/
@Override
public Object transform(ChartDto dto, List<JSONObject> data) {
// JSONObject json = new JSONObject();
// List<Object> xAxis = new ArrayList<>();
// Map<String, List<Object>> series = new HashMap<>();
// data.forEach(jsonObject -> {
// jsonObject.forEach((s, o) -> {
// if ("xAxis".equals(s)) {
// xAxis.add(o);
// } else {
// List<Object> objects;
// if (series.containsKey(s)) {
// objects = series.get(s);
// } else {
// objects = new ArrayList<>();
//
// }
// objects.add(o);
// series.put(s, objects);
//
// }
// });
// });
//
// json.put("xAxis", xAxis);
// List<JSONObject> result = new ArrayList<>();
// series.forEach((s, objects) -> {
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("name", s);
// if (s.endsWith("bar")) {
// jsonObject.put("type", "bar");
// } else {
// jsonObject.put("type", "line");
// }
// jsonObject.put("data", objects);
// result.add(jsonObject);
// });
// json.put("series", result);
// return json.toJSONString();
return data;
}
/*{
"xAxis": [
"1月",
"2月",
"3月"
],
"series": [
{
"name": "指标1", //暂时用不上
"type": "bar", //需要处理
"data": [
2,
49,
2
]
},
{
"name": "指标2",
"type": "line",
"yAxisIndex": 1,
"data": [
2,
32,
4
]
}
]
}*/
}

@ -0,0 +1,43 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ChartStrategy;
import org.springframework.stereotype.Component;
import java.util.List;
/**
*
* Created by raodeming on 2021/4/26.
*/
@Component
public class GaugeChartServiceImpl implements ChartStrategy {
/**
*
*
* @return
*/
@Override
public String type() {
return "widget-gauge";
}
/**
*
*
* @param dto
* @param data
* @return
*/
@Override
public Object transform(ChartDto dto, List<JSONObject> data) {
// return "{\"value\": 50, \"name\": \"名称1\", \"unit\": \"%\"}";
return data;
}
}

@ -0,0 +1,52 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ChartStrategy;
import org.springframework.stereotype.Component;
import java.util.List;
/**
*
* Created by raodeming on 2021/4/26.
*/
@Component
public class PieChartServiceImpl implements ChartStrategy {
/**
*
*
* @return
*/
@Override
public String type() {
return "widget-piechart|widget-hollow-piechart|widget-funnel";
}
/**
*
*
* @param dto
* @param data
* @return
*/
@Override
public Object transform(ChartDto dto, List<JSONObject> data) {
return data;
}
/* [
{
"value": 11,
"name": "指标1"
},
{
"value": 10,
"name": "指标2"
}
]*/
}

@ -0,0 +1,314 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anji.plus.gaea.utils.GaeaAssert;
import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ChartDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ReportDashboardDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.controller.dto.ReportDashboardObjectDto;
import com.anjiplus.template.gaea.business.modules.data.dashboard.dao.ReportDashboardMapper;
import com.anjiplus.template.gaea.business.modules.data.dashboard.dao.entity.ReportDashboard;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ChartStrategy;
import com.anjiplus.template.gaea.business.modules.data.dashboard.service.ReportDashboardService;
import com.anjiplus.template.gaea.business.modules.data.dashboard.util.DateUtil;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto.ReportDashboardWidgetDto;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto.ReportDashboardWidgetValueDto;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.entity.ReportDashboardWidget;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.service.ReportDashboardWidgetService;
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.DataSetDto;
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.OriginalDataDto;
import com.anjiplus.template.gaea.business.modules.data.dataSet.service.DataSetService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author Raod
* @desc ReportDashboard
* @date 2021-04-12 14:52:21.761
**/
@Service
//@RequiredArgsConstructor
public class ReportDashboardServiceImpl implements ReportDashboardService, InitializingBean, ApplicationContextAware {
@Autowired
private ReportDashboardMapper reportDashboardMapper;
@Autowired
private ReportDashboardWidgetService reportDashboardWidgetService;
@Autowired
private DataSetService dataSetService;
private Map<String, ChartStrategy> queryServiceImplMap = new HashMap<>();
private ApplicationContext applicationContext;
@Override
public GaeaBaseMapper<ReportDashboard> getMapper() {
return reportDashboardMapper;
}
@Override
public ReportDashboardObjectDto getDetail(String reportCode) {
ReportDashboardObjectDto result = new ReportDashboardObjectDto();
ReportDashboardDto reportDashboardDto = new ReportDashboardDto();
ReportDashboard reportDashboard = this.selectOne("report_code", reportCode);
GaeaAssert.notNull(reportDashboard, ResponseCode.RULE_CONTENT_NOT_EXIST, "reportDashboard");
GaeaBeanUtils.copyAndFormatter(reportDashboard, reportDashboardDto);
List<ReportDashboardWidget> list = reportDashboardWidgetService.list(
new QueryWrapper<ReportDashboardWidget>().lambda()
.eq(ReportDashboardWidget::getReportCode, reportCode)
.orderByAsc(ReportDashboardWidget::getSort)
);
List<ReportDashboardWidgetDto> reportDashboardWidgetDtoList = new ArrayList<>();
list.forEach(reportDashboardWidget -> {
ReportDashboardWidgetDto reportDashboardWidgetDto = new ReportDashboardWidgetDto();
ReportDashboardWidgetValueDto value = new ReportDashboardWidgetValueDto();
value.setSetup(StringUtils.isNotBlank(reportDashboardWidget.getSetup()) ? JSONObject.parseObject(reportDashboardWidget.getSetup()) : new JSONObject());
value.setData(StringUtils.isNotBlank(reportDashboardWidget.getData()) ? JSONObject.parseObject(reportDashboardWidget.getData()) : new JSONObject());
value.setPosition(StringUtils.isNotBlank(reportDashboardWidget.getPosition()) ? JSONObject.parseObject(reportDashboardWidget.getPosition()) : new JSONObject());
value.setCollapse(StringUtils.isNotBlank(reportDashboardWidget.getCollapse()) ? JSONObject.parseObject(reportDashboardWidget.getCollapse()) : new JSONObject());
//实时数据的替换
analysisData(value);
reportDashboardWidgetDto.setType(reportDashboardWidget.getType());
reportDashboardWidgetDto.setValue(value);
reportDashboardWidgetDtoList.add(reportDashboardWidgetDto);
});
reportDashboardDto.setWidgets(reportDashboardWidgetDtoList);
result.setDashboard(reportDashboardDto);
result.setReportCode(reportCode);
return result;
}
/***
*
*
* @param dto
*/
@Override
@Transactional
public void insertDashboard(ReportDashboardObjectDto dto) {
String reportCode = dto.getReportCode();
GaeaAssert.notEmpty(reportCode, ResponseCode.PARAM_IS_NULL, "reportCode");
//查询ReportDashboard
ReportDashboard reportDashboard = this.selectOne("report_code", reportCode);
ReportDashboard dashboard = new ReportDashboard();
GaeaBeanUtils.copyAndFormatter(dto.getDashboard(), dashboard);
BeanUtils.copyProperties(dto.getDashboard(), dashboard);
dashboard.setReportCode(reportCode);
if (null == reportDashboard) {
//新增
this.insert(dashboard);
} else {
//更新
dashboard.setId(reportDashboard.getId());
this.update(dashboard);
}
//删除reportDashboardWidget
reportDashboardWidgetService.delete(new QueryWrapper<ReportDashboardWidget>()
.lambda().eq(ReportDashboardWidget::getReportCode, reportCode));
List<ReportDashboardWidgetDto> widgets = dto.getWidgets();
List<ReportDashboardWidget> reportDashboardWidgetList = new ArrayList<>();
for (int i = 0; i < widgets.size(); i++) {
ReportDashboardWidget reportDashboardWidget = new ReportDashboardWidget();
ReportDashboardWidgetDto reportDashboardWidgetDto = widgets.get(i);
String type = reportDashboardWidgetDto.getType();
ReportDashboardWidgetValueDto value = reportDashboardWidgetDto.getValue();
reportDashboardWidget.setReportCode(reportCode);
reportDashboardWidget.setType(type);
reportDashboardWidget.setSetup(value.getSetup() != null ? JSONObject.toJSONString(value.getSetup()) : "");
reportDashboardWidget.setData(value.getData() != null ? JSONObject.toJSONString(value.getData()) : "");
reportDashboardWidget.setPosition(value.getPosition() != null ? JSONObject.toJSONString(value.getPosition()) : "");
reportDashboardWidget.setCollapse(value.getCollapse() != null ? JSONObject.toJSONString(value.getCollapse()) : "");
reportDashboardWidget.setEnableFlag(1);
reportDashboardWidget.setDeleteFlag(0);
reportDashboardWidget.setSort((long) (i + 1));
reportDashboardWidgetList.add(reportDashboardWidget);
}
reportDashboardWidgetService.insertBatch(reportDashboardWidgetList);
}
@Override
public Object getChartData(ChartDto dto) {
// String chartType = dto.getChartType();
DataSetDto setDto = new DataSetDto();
setDto.setSetCode(dto.getSetCode());
setDto.setContextData(dto.getContextData());
OriginalDataDto result = dataSetService.getData(setDto);
List<JSONObject> data = result.getData();
//处理时间轴
List<JSONObject> resultData = buildTimeLine(data, dto);
return resultData;
// return getTarget(chartType).transform(dto, result.getData());
}
public ChartStrategy getTarget(String type) {
for (String s : queryServiceImplMap.keySet()) {
if (s.contains(type)) {
return queryServiceImplMap.get(s);
}
}
throw BusinessExceptionBuilder.build(ResponseCode.RULE_CONTENT_NOT_EXIST);
}
@Override
public void afterPropertiesSet() {
Map<String, ChartStrategy> beanMap = applicationContext.getBeansOfType(ChartStrategy.class);
//遍历该接口的所有实现将其放入map中
for (ChartStrategy serviceImpl : beanMap.values()) {
queryServiceImplMap.put(serviceImpl.type(), serviceImpl);
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/**
*
*
* @param dto
*/
public void analysisData(ReportDashboardWidgetValueDto dto) {
// if (StringUtils.isBlank(reportDashboardWidgetDto.getSetCode())) {
// return;
// }
// DataSetDto dto = new DataSetDto();
// dto.setSetCode(reportDashboardWidgetDto.getSetCode());
// if (reportDashboardWidgetDto.getContextData() != null && reportDashboardWidgetDto.getContextData().size() > 0) {
// dto.setContextData(reportDashboardWidgetDto.getContextData());
// }
// OriginalDataDto data = dataSetService.getData(dto);
// reportDashboardWidgetDto.setData(JSONObject.toJSONString(data.getData()));
}
public List<JSONObject> buildTimeLine(List<JSONObject> data, ChartDto dto) {
Map<String, String> chartProperties = dto.getChartProperties();
if (null == chartProperties || chartProperties.size() < 1) {
return data;
}
Map<String, Object> contextData = dto.getContextData();
if (null == contextData || contextData.size() < 1) {
return data;
}
if (contextData.containsKey("startTime") && contextData.containsKey("endTime")) {
dto.setStartTime(contextData.get("startTime").toString());
dto.setEndTime(contextData.get("endTime").toString());
}
if (StringUtils.isBlank(dto.getStartTime()) || StringUtils.isBlank(dto.getEndTime())) {
return data;
}
//获取时间轴字段和解析时间颗粒度
chartProperties.forEach((key, value) -> {
dto.setParticles(value);
setTimeLineFormat(dto);
if (StringUtils.isNotBlank(dto.getDataTimeFormat())) {
dto.setTimeLineFiled(key);
return;
}
});
if (StringUtils.isBlank(dto.getDataTimeFormat())) {
return data;
}
Date beginTime = DateUtil.parseHmsTime(dto.getStartTime());
Date endTime = DateUtil.parseHmsTime(dto.getEndTime());
SimpleDateFormat showFormat = new SimpleDateFormat(dto.getTimeLineFormat());
SimpleDateFormat dataFormat = new SimpleDateFormat(dto.getDataTimeFormat());
Calendar calendar = Calendar.getInstance();
calendar.setTime(beginTime);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTime(endTime);
List<String> timeLine = new ArrayList<>();
List<String> dataTimeline = new ArrayList<>();
timeLine.add(showFormat.format(calendar.getTime()));
dataTimeline.add(dataFormat.format(calendar.getTime()));
//添加时间轴数据
while (true) {
calendar.add(dto.getTimeUnit(), 1);
timeLine.add(showFormat.format(calendar.getTime()));
dataTimeline.add(dataFormat.format(calendar.getTime()));
if (showFormat.format(calendar.getTime()).equals(showFormat.format(calendarEnd.getTime()))) {
break;
}
}
//根据时间轴生成对应的时间线,数据不存在,补数据
List<JSONObject> result = new ArrayList<>();
JSONObject jsonDemo = data.get(0);
String timeLineFiled = dto.getTimeLineFiled();
for (String dateFormat : dataTimeline) {
boolean flag = true;
for (JSONObject datum : data) {
if (datum.containsKey(timeLineFiled) && datum.getString(timeLineFiled).equals(dateFormat)) {
result.add(datum);
flag = false;
}
}
if (flag) {
//补数据
JSONObject json = new JSONObject();
jsonDemo.forEach((s, o) -> {
if (s.equals(timeLineFiled)) {
json.put(timeLineFiled, dateFormat);
} else {
json.put(s, 0);
}
});
result.add(json);
}
}
return result;
}
//设置时间格式
private void setTimeLineFormat(ChartDto dto) {
String particles = dto.getParticles();
if ("xAxis-hour".equals(particles)) {
dto.setDataTimeFormat("yyyy-MM-dd HH");
dto.setTimeLineFormat("MM-dd HH");
dto.setTimeUnit(Calendar.HOUR);
} else if ("xAxis-day".equals(particles)) {
dto.setDataTimeFormat("yyyy-MM-dd");
dto.setTimeLineFormat("yyyy-MM-dd");
dto.setTimeUnit(Calendar.DATE);
} else if ("xAxis-month".equals(particles)) {
dto.setDataTimeFormat("yyyy-MM");
dto.setTimeLineFormat("yyyy-MM");
dto.setTimeUnit(Calendar.MONTH);
} else if ("xAxis-year".equals(particles)) {
dto.setDataTimeFormat("yyyy");
dto.setTimeLineFormat("yyyy");
dto.setTimeUnit(Calendar.YEAR);
}
}
}

@ -0,0 +1,47 @@
package com.anjiplus.template.gaea.business.modules.data.dashboard.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by raodeming on 2021/4/29.
*/
public class DateUtil {
private static String defaultDatePattern = "yyyy-MM-dd";
private static String defaultDateTimePattern = "yyyy-MM-dd HH:mm:ss.SSS";
private static String defaultyyyyMMddPattern = "yyyyMMdd";
private static String defaultYmdHmsPattern = "yyyy-MM-dd HH:mm:ss";
private static String defaultHmsPattern = "HH:mm:ss";
/**yyyy-MM-dd HH:mm:ss
* @param dateStr yyyy-MM-dd HH:mm:ss
* @return
*/
public static Date parseHmsTime(String dateStr) {
return parse(dateStr, defaultYmdHmsPattern);
}
/**
* @param dateStr
* @param pattern
* @return
*/
public static Date parse(String dateStr, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
if (dateStr == null || "".equals(dateStr)) {
return null;
}
try {
Date d = sdf.parse(dateStr);
return d;
} catch (ParseException e) {
System.out.println("日期转换错误: " + e.getMessage());
return null;
}
}
}

@ -0,0 +1,28 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto;
import lombok.Data;
import java.io.Serializable;
/**
*
* @description dto
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@Data
public class ReportDashboardWidgetDto implements Serializable {
/**
* DASHBOARD_PANEL_TYPE
*/
private String type;
/**
* value
*/
private ReportDashboardWidgetValueDto value;
}

@ -0,0 +1,42 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.dto;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import java.io.Serializable;
/**
*
* @description dto
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@Data
public class ReportDashboardWidgetValueDto implements Serializable {
/** 报表编码 */
private String reportCode;
/** 组件的渲染属性json */
private JSONObject setup;
/** 组件的数据属性json */
private JSONObject data;
/** 组件的配置属性json */
private JSONObject collapse;
/** 组件的大小位置属性json */
private JSONObject position;
/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
private Integer enableFlag;
/** 0--未删除 1--已删除 DIC_NAME=DEL_FLAG */
private Integer deleteFlag;
/** 排序,图层的概念 */
private Long sort;
}

@ -0,0 +1,20 @@
/**/
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.param;
import lombok.Data;
import java.io.Serializable;
import com.anji.plus.gaea.annotation.Query;
import com.anji.plus.gaea.constant.QueryEnum;
import com.anji.plus.gaea.curd.params.PageParam;
import java.util.List;
/**
* @desc ReportDashboardWidget
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@Data
public class ReportDashboardWidgetParam extends PageParam implements Serializable{
}

@ -0,0 +1,16 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao;
import org.apache.ibatis.annotations.Mapper;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.entity.ReportDashboardWidget;
/**
* ReportDashboardWidget Mapper
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@Mapper
public interface ReportDashboardWidgetMapper extends GaeaBaseMapper<ReportDashboardWidget> {
}

@ -0,0 +1,45 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.entity;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description entity
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@TableName(value="gaea_report_dashboard_widget")
@Data
public class ReportDashboardWidget extends GaeaBaseEntity {
@ApiModelProperty(value = "报表编码")
private String reportCode;
@ApiModelProperty(value = "组件类型参考字典DASHBOARD_PANEL_TYPE")
private String type;
@ApiModelProperty(value = "组件的渲染属性json")
private String setup;
@ApiModelProperty(value = "组件的数据属性json")
private String data;
@ApiModelProperty(value = "组件的配置属性json")
private String collapse;
@ApiModelProperty(value = "组件的大小位置属性json")
private String position;
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
private Integer enableFlag;
@ApiModelProperty(value = " 0--未删除 1--已删除 DIC_NAME=DEL_FLAG")
private Integer deleteFlag;
@ApiModelProperty(value = "排序,图层的概念")
private Long sort;
}

@ -0,0 +1,21 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.service;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.entity.ReportDashboardWidget;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.controller.param.ReportDashboardWidgetParam;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
/**
* @desc ReportDashboardWidget
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
public interface ReportDashboardWidgetService extends GaeaBaseService<ReportDashboardWidgetParam, ReportDashboardWidget> {
/***
*
*
* @param id
*/
ReportDashboardWidget getDetail(Long id);
}

@ -0,0 +1,34 @@
package com.anjiplus.template.gaea.business.modules.data.dashboardwidget.service.impl;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.entity.ReportDashboardWidget;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.service.ReportDashboardWidgetService;
import com.anjiplus.template.gaea.business.modules.data.dashboardwidget.dao.ReportDashboardWidgetMapper;
/**
* @desc ReportDashboardWidget
* @author Raod
* @date 2021-04-12 15:12:43.724
**/
@Service
//@RequiredArgsConstructor
public class ReportDashboardWidgetServiceImpl implements ReportDashboardWidgetService {
@Autowired
private ReportDashboardWidgetMapper reportDashboardWidgetMapper;
@Override
public GaeaBaseMapper<ReportDashboardWidget> getMapper() {
return reportDashboardWidgetMapper;
}
@Override
public ReportDashboardWidget getDetail(Long id) {
ReportDashboardWidget reportDashboardWidget = this.selectOne(id);
return reportDashboardWidget;
}
}
Loading…
Cancel
Save