| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package com.database2.server;
- import com.database2.dao.ShowChartsMapper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- /*
- 处理时间分段
- */
- @Service
- public class TimeConverterUtil {
- @Autowired
- ShowChartsMapper showChartsMapper;
- //x轴时间类型
- public List<String> timeConverter(String xColumnName, String tableName, String timeType){
- String timeGroup = "'YYYY-MM-DD'";
- List<String> value = new ArrayList<String>();
- if ("year".equals(timeType)){
- timeGroup = "'YYYY'";
- value = showChartsMapper.getTimeDate(xColumnName, tableName, timeGroup);
- }else if ("month".equals(timeType)){
- timeGroup = "'YYYY-MM'";
- value = showChartsMapper.getTimeDate(xColumnName, tableName, timeGroup);
- }else if ("day".equals(timeType) || "".equals(timeType)){
- value = showChartsMapper.getTimeDate(xColumnName, tableName, timeGroup);
- }else if ("quarter".equals(timeType)){
- timeGroup = "'YYYY-Q'";
- value = showChartsMapper.getTimeDate(xColumnName, tableName, timeGroup);
- }else if ("week".equals(timeType)){
- timeGroup = "'YYYY-WW'";
- value = showChartsMapper.getTimeDate(xColumnName, tableName, timeGroup);
- }else if ("halfYear".equals(timeType)){
- value = showChartsMapper.getTimeYear(xColumnName, tableName);
- }else {
- return null;
- }
- return value;
- }
- //x轴时间类型包装
- public List<String> toRespons(List<String> dataList, String timeType){
- List<String> value = new ArrayList<String>();
- String dataLast = null;
- Iterator isDataList = dataList.iterator();
- while (isDataList.hasNext()){
- String data = (String) isDataList.next();
- if ("quarter".equals(timeType)){
- String[] str = data.split("-");
- dataLast = str[0] + "-Q" + str[1];
- }else if ("month".equals(timeType)){
- String[] str = data.split("-");
- dataLast = str[0] + "-M" + str[1];
- }else if ("week".equals(timeType)){
- String[] str = data.split("-");
- dataLast = str[0] + "-W" + str[1];
- }
- value.add(dataLast);
- }
- return value;
- }
- //无分组时间值
- public String getTimeValueConverter(String yColumn, String xColumn, String tableName, String dataType, String timeType, String xdata){
- String timeGroup = "'YYYY-MM-DD'";
- String value = null;
- //判断时间类型
- if ("halfYear".equals(timeType)){
- String[] str = xdata.split("-");
- if ("上半年".equals(str[1])){
- String firstIndex = str[0] + "-01";
- String afterIndex = str[0] + "-06";
- value = showChartsMapper.getTimeValueYear(dataType, yColumn, tableName, xColumn, firstIndex, afterIndex);
- }else {
- String firstIndex = str[0] + "-07";
- String afterIndex = str[0] + "-12";
- value = showChartsMapper.getTimeValueYear(dataType, yColumn, tableName, xColumn, firstIndex, afterIndex);
- }
- }else if ("year".equals(timeType)){
- timeGroup = "'YYYY'";
- value = showChartsMapper.getTimeValue(dataType, yColumn, tableName, xColumn, timeGroup,xdata);
- }else if ("month".equals(timeType)){
- timeGroup = "'YYYY-MM'";
- value = showChartsMapper.getTimeValue(dataType, yColumn, tableName, xColumn, timeGroup,xdata);
- }else if ("day".equals(timeType) || "".equals(timeType)){
- value = showChartsMapper.getTimeValue(dataType, yColumn, tableName, xColumn, timeGroup,xdata);
- }else if ("quarter".equals(timeType)){
- timeGroup = "'YYYY-Q'";
- value = showChartsMapper.getTimeValue(dataType, yColumn, tableName, xColumn, timeGroup,xdata);
- }else if ("week".equals(timeType)){
- timeGroup = "'YYYY-WW'";
- value = showChartsMapper.getTimeValue(dataType, yColumn, tableName, xColumn, timeGroup,xdata);
- }
- return value;
- }
- //有分组时间类型值处理
- public String getGroupTimeConverter(String dataType, String yColumn, String tableName, String groupByName, String timeType,
- String groupsName, String xColumn, String xAxisDataOne){
- String timeGroup = "'YYYY-MMDD'";
- String value = null;
- if ("year".equals(timeType)){
- timeGroup = "'YYYY'";
- value = showChartsMapper.getGroupsValueTime(dataType, yColumn, tableName, groupByName, groupsName, xColumn,
- timeGroup, xAxisDataOne);
- }else if ("month".equals(timeType)){
- timeGroup = "'YYYY-MM'";
- value = showChartsMapper.getGroupsValueTime(dataType, yColumn, tableName, groupByName, groupsName, xColumn,
- timeGroup, xAxisDataOne);
- }else if ("quarter".equals(timeType)){
- timeGroup = "'YYYY-Q'";
- value = showChartsMapper.getGroupsValueTime(dataType, yColumn, tableName, groupByName, groupsName, xColumn,
- timeGroup, xAxisDataOne);
- }else if ("week".equals(timeType)){
- timeGroup = "'YYYY-WW'";
- value = showChartsMapper.getGroupsValueTime(dataType, yColumn, tableName, groupByName, groupsName, xColumn,
- timeGroup, xAxisDataOne);
- }else if ("day".equals(timeType) || "".equals(timeType)){
- value = showChartsMapper.getGroupsValueTime(dataType, yColumn, tableName, groupByName, groupsName, xColumn,
- timeGroup, xAxisDataOne);
- }else if ("halfYear".equals(timeType)){
- String[] str = xAxisDataOne.split("-");
- if ("上半年".equals(str[1])){
- String firstIndex = str[0] + "-01";
- String afterIndex = str[0] + "-06";
- value = showChartsMapper.getTimeValueHalfYear(dataType, yColumn, tableName, xColumn, firstIndex, afterIndex, groupByName, groupsName);
- }else {
- String firstIndex = str[0] + "-07";
- String afterIndex = str[0] + "-12";
- value = showChartsMapper.getTimeValueHalfYear(dataType, yColumn, tableName, xColumn, firstIndex, afterIndex, groupByName, groupsName);
- }
- }
- return value;
- }
- }
|