package com.server; import com.dao.ChartsConfigMapper; import com.dao.ShowChartsMapper; import com.model.bo.ChartsColumnConfig; import com.model.bo.Screen; import com.model.bo.ScreenStr; import com.model.pojo.RepCode; import com.model.pojo.RepEntity; import com.model.vo.configVo.IndividualConfigInfo; import com.model.vo.dataVo.PopAndIndDataInfo; import com.util.BasesSource.DynamicDataSourceContextHolder; import com.util.ScreenUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; /* 个人统计表 */ @Service public class ShowIndividualService { @Autowired ChartsConfigMapper chartsConfigMapper; @Autowired GetChartsDataUtilService getChartsDataUtilService; @Autowired ShowChartsMapper showChartsMapper; @Autowired ScreenUtil screenUtil; @Autowired ChartsUtilService chartsUtilService; public RepEntity showIndividual(IndividualConfigInfo individualConfigInfo, String token){ if (individualConfigInfo == null || "".equals(individualConfigInfo)){ return new RepEntity(RepCode.Null); } PopAndIndDataInfo popAndIndDataInfo = new PopAndIndDataInfo(); List> targetValue = new ArrayList<>(); //取表名 int id = individualConfigInfo.getId(); //获取列配置 ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id); if (chartsColumn == null || "".equals(chartsColumn)){ return new RepEntity(RepCode.Null); } String style = chartsColumn.getChartStyle(); String config = chartsColumn.getChartConfig(); popAndIndDataInfo.setChartsConfig(config); popAndIndDataInfo.setChartsStyle(style); String tableName = chartsUtilService.getSqlStr(token, id); if ("".equals(tableName)){ return new RepEntity(RepCode.NoAuthority); } int baseId = getChartsDataUtilService.getBaseId(id); System.out.println("切换数据库"+String.valueOf(baseId)); try{ if (!DynamicDataSourceContextHolder.isContainsDataSource(String.valueOf(baseId))) { //joinPoint.getSignature() :获取连接点的方法签名对象 System.out.println("数据源 " + String.valueOf(baseId) + " 不存在使用默认的数据源 -> "); } else { System.out.println("使用数据源:" + String.valueOf(baseId)); DynamicDataSourceContextHolder.setDataSourceType(String.valueOf(baseId)); } //取主建名 // String tableKey = tableName + "_PK"; // String keyName = showChartsMapper.getTableKey(tableName, tableKey); // // //取筛选列表 List screens = individualConfigInfo.getFilters(); ScreenStr scr = new ScreenStr(); String screen = ""; String screenStr = ""; if ("".equals(screens) || screens == null || screens.size() == 0){ screen = ""; screenStr = ""; }else { scr = screenUtil.screensUtil(screens, "", ""); screen = scr.getRet(); StringBuilder sb = new StringBuilder(screen); screenStr = String.valueOf(sb .replace(1, 5, "where ")); } String columnName = individualConfigInfo.getSortColumn(); System.out.println("columnName:"+columnName); //查询其他列 String columnListName = individualConfigInfo.getColumnListName().toString(); String line = String.valueOf(individualConfigInfo.getShowLine() + 1); String sort = individualConfigInfo.getSort(); String tableListName = this.getString(columnListName); targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, line, screenStr); popAndIndDataInfo.setValueList(targetValue); }catch (Exception e){ e.printStackTrace(); System.out.println("异常"); return new RepEntity(RepCode.erro); }finally { DynamicDataSourceContextHolder.clearDataSourceType(); } return new RepEntity(RepCode.success, popAndIndDataInfo); } private String getString(String str){ String st1 = "["; String st2 = "]"; String strA = str.replace(st1, ""); String strB = strA.replace(st2, ""); System.out.println("str:"+ strB); return strB; } }