自定义分析改造
正在显示
6 个修改的文件
包含
150 行增加
和
51 行删除
... | @@ -32,17 +32,18 @@ public class CustomConsumeController { | ... | @@ -32,17 +32,18 @@ public class CustomConsumeController { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * <pre> | 34 | * <pre> |
35 | * 自定义分析获取数据类型 | 35 | * 自定义分析获取数据类型 |
36 | * </pre> | 36 | * </pre> |
37 | * @param granularity 时间粒度 | ||
37 | * @return | 38 | * @return |
38 | * @author Li Yuanyuan, 2021年1月29日 下午3:07:12 | 39 | * @author Li Yuanyuan, 2021年1月29日 下午3:07:12 |
39 | */ | 40 | */ |
40 | @ApiOperation(value="自定义分析获取数据类型", notes="自定义分析获取数据类型") | 41 | @ApiOperation(value="自定义分析获取数据类型", notes="自定义分析获取数据类型") |
41 | @GetMapping(value = "/getDataType") | 42 | @GetMapping(value = "/getDataType") |
42 | public Result<List<TreeData>> getDataType(){ | 43 | public Result<List<TreeData>> getDataType(String granularity){ |
43 | Result<List<TreeData>> result = new Result<List<TreeData>>(); | 44 | Result<List<TreeData>> result = new Result<List<TreeData>>(); |
44 | List<TreeData> dataTypeList = new ArrayList<TreeData>(); | 45 | List<TreeData> dataTypeList = new ArrayList<TreeData>(); |
45 | dataTypeList = customConsumeService.getDataType(); | 46 | dataTypeList = customConsumeService.getDataType(granularity); |
46 | result.setResult(dataTypeList); | 47 | result.setResult(dataTypeList); |
47 | result.setSuccess(true); | 48 | result.setSuccess(true); |
48 | return result; | 49 | return result; |
... | @@ -140,9 +141,9 @@ public class CustomConsumeController { | ... | @@ -140,9 +141,9 @@ public class CustomConsumeController { |
140 | 141 | ||
141 | @ApiOperation(value="填报指标获取", notes="填报指标获取") | 142 | @ApiOperation(value="填报指标获取", notes="填报指标获取") |
142 | @GetMapping(value = "/queryDataFillIndex") | 143 | @GetMapping(value = "/queryDataFillIndex") |
143 | public Result<List<Map<String,Object>>> queryDataFillIndex(String reportId) { | 144 | public Result<List<Map<String,Object>>> queryDataFillIndex(String reportId,String granularity) { |
144 | Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>(); | 145 | Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>(); |
145 | List<Map<String, Object>> list = customConsumeService.queryDataFillIndex(reportId); | 146 | List<Map<String, Object>> list = customConsumeService.queryDataFillIndex(reportId,granularity); |
146 | result.setResult(list); | 147 | result.setResult(list); |
147 | result.setSuccess(true); | 148 | result.setSuccess(true); |
148 | return result; | 149 | return result; | ... | ... |
... | @@ -41,4 +41,9 @@ public class AnalyseCustomConsume { | ... | @@ -41,4 +41,9 @@ public class AnalyseCustomConsume { |
41 | @Excel(name = "历史指标标记名称", width = 15) | 41 | @Excel(name = "历史指标标记名称", width = 15) |
42 | @ApiModelProperty(value = "历史指标标记名称") | 42 | @ApiModelProperty(value = "历史指标标记名称") |
43 | private java.lang.String analyseTitle; | 43 | private java.lang.String analyseTitle; |
44 | |||
45 | @Excel(name = "分析指标时间粒度", width = 15) | ||
46 | @ApiModelProperty(value = "分析指标时间粒度") | ||
47 | private java.lang.String analyseGranularity; | ||
48 | |||
44 | } | 49 | } | ... | ... |
... | @@ -54,7 +54,7 @@ public interface ICustomConsumeService { | ... | @@ -54,7 +54,7 @@ public interface ICustomConsumeService { |
54 | * @return | 54 | * @return |
55 | * @author Li Yuanyuan, 2021年1月29日 下午3:10:42 | 55 | * @author Li Yuanyuan, 2021年1月29日 下午3:10:42 |
56 | */ | 56 | */ |
57 | public List<TreeData> getDataType(); | 57 | public List<TreeData> getDataType(String granularity); |
58 | /** | 58 | /** |
59 | * <pre> | 59 | * <pre> |
60 | * 实时数据/水质水量 | 60 | * 实时数据/水质水量 |
... | @@ -89,10 +89,11 @@ public interface ICustomConsumeService { | ... | @@ -89,10 +89,11 @@ public interface ICustomConsumeService { |
89 | * 报表数据项获取 | 89 | * 报表数据项获取 |
90 | * </pre> | 90 | * </pre> |
91 | * @param reportId | 91 | * @param reportId |
92 | * @param granularity 时间粒度 | ||
92 | * @return | 93 | * @return |
93 | * @author Li Yuanyuan, 2021年2月3日 下午3:39:44 | 94 | * @author Li Yuanyuan, 2021年2月3日 下午3:39:44 |
94 | */ | 95 | */ |
95 | public List<Map<String, Object>> queryDataFillIndex(String reportId); | 96 | public List<Map<String, Object>> queryDataFillIndex(String reportId,String granularity); |
96 | 97 | ||
97 | 98 | ||
98 | } | 99 | } | ... | ... |
sk-module-biz/src/main/java/com/skua/modules/dataAnalysis/service/impl/CustomConsumeServiceImpl.java
... | @@ -274,7 +274,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -274,7 +274,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
274 | pattern = "yyyy-MM"; | 274 | pattern = "yyyy-MM"; |
275 | type = "year"; | 275 | type = "year"; |
276 | } | 276 | } |
277 | List<Map<String, Object>> list = reportItemService.getReportItemData(departId,reportId, startTime, endTime, indexs); | 277 | List<Map<String, Object>> list = reportItemService.getReportItemData(departId,reportId, startTime, endTime, indexs,granularity); |
278 | //获取部门数据 | 278 | //获取部门数据 |
279 | List<Map<String, Object>> handleList = new ArrayList<Map<String,Object>>();//接收处理结果 | 279 | List<Map<String, Object>> handleList = new ArrayList<Map<String,Object>>();//接收处理结果 |
280 | String[] factoryArray = departId.split(","); | 280 | String[] factoryArray = departId.split(","); |
... | @@ -366,7 +366,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -366,7 +366,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
366 | if(!StringUtils.isEmpty(contrastType)&&contrastType.contains("tb")) { | 366 | if(!StringUtils.isEmpty(contrastType)&&contrastType.contains("tb")) { |
367 | String tbStartTime = DateUtils.formatAddTime(startTime,pattern,Calendar.YEAR,-1); | 367 | String tbStartTime = DateUtils.formatAddTime(startTime,pattern,Calendar.YEAR,-1); |
368 | String tbEndTime = DateUtils.formatAddTime(endTime,pattern,Calendar.YEAR,-1); | 368 | String tbEndTime = DateUtils.formatAddTime(endTime,pattern,Calendar.YEAR,-1); |
369 | List<Map<String, Object>> tbList =reportItemService.getReportItemData(departId,reportId, tbStartTime, tbEndTime, indexs); | 369 | List<Map<String, Object>> tbList =reportItemService.getReportItemData(departId,reportId, tbStartTime, tbEndTime, indexs,granularity); |
370 | for(Map<String, Object> map : tbList) { | 370 | for(Map<String, Object> map : tbList) { |
371 | tbMap.put(ConvertUtils.getString(map.get("time")+""+map.get("departId")), map); | 371 | tbMap.put(ConvertUtils.getString(map.get("time")+""+map.get("departId")), map); |
372 | } | 372 | } |
... | @@ -374,7 +374,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -374,7 +374,7 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
374 | if(!StringUtils.isEmpty(contrastType)&&contrastType.contains("hb")) { | 374 | if(!StringUtils.isEmpty(contrastType)&&contrastType.contains("hb")) { |
375 | String hbStartTime = DateUtils.formatAddTime(startTime,pattern,Calendar.MONTH,-1); | 375 | String hbStartTime = DateUtils.formatAddTime(startTime,pattern,Calendar.MONTH,-1); |
376 | String hbEndTime = DateUtils.formatAddTime(endTime,pattern,Calendar.MONTH,-1); | 376 | String hbEndTime = DateUtils.formatAddTime(endTime,pattern,Calendar.MONTH,-1); |
377 | List<Map<String, Object>> hbList =reportItemService.getReportItemData(departId,reportId, hbStartTime, hbEndTime, indexs); | 377 | List<Map<String, Object>> hbList =reportItemService.getReportItemData(departId,reportId, hbStartTime, hbEndTime, indexs,granularity); |
378 | for(Map<String, Object> map : hbList) { | 378 | for(Map<String, Object> map : hbList) { |
379 | hbMap.put(ConvertUtils.getString(map.get("time")+""+map.get("departId")), map); | 379 | hbMap.put(ConvertUtils.getString(map.get("time")+""+map.get("departId")), map); |
380 | } | 380 | } |
... | @@ -402,26 +402,31 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -402,26 +402,31 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
402 | } | 402 | } |
403 | 403 | ||
404 | @Override | 404 | @Override |
405 | public List<TreeData> getDataType() { | 405 | public List<TreeData> getDataType(String granularity) { |
406 | List<Map<String,Object>> dataTypeList = new ArrayList<Map<String,Object>>(); | 406 | List<Map<String,Object>> dataTypeList = new ArrayList<Map<String,Object>>(); |
407 | Map<String,Object> ssmap = new HashMap<String,Object>(); | 407 | Map<String,Object> ssmap = new HashMap<String,Object>(); |
408 | ssmap.put("id", "ss"); | 408 | ssmap.put("id", "ss"); |
409 | ssmap.put("pid", ""); | 409 | ssmap.put("pid", ""); |
410 | ssmap.put("title", "实时"); | 410 | ssmap.put("title", "实时"); |
411 | dataTypeList.add(ssmap); | ||
412 | Map<String,Object> szmap = new HashMap<String,Object>(); | 411 | Map<String,Object> szmap = new HashMap<String,Object>(); |
413 | szmap.put("id", "sz"); | 412 | szmap.put("id", "sz"); |
414 | szmap.put("pid", "ss"); | 413 | szmap.put("pid", "ss"); |
415 | szmap.put("title", "采集数据"); | 414 | szmap.put("title", "采集数据"); |
415 | if("hour".equals(granularity)||"day".equals(granularity)) { | ||
416 | dataTypeList.add(ssmap); | ||
417 | dataTypeList.add(szmap); | ||
418 | } | ||
416 | Map<String,Object> tbmap = new HashMap<String,Object>(); | 419 | Map<String,Object> tbmap = new HashMap<String,Object>(); |
417 | tbmap.put("id", "tb"); | 420 | tbmap.put("id", "tb"); |
418 | tbmap.put("pid", ""); | 421 | tbmap.put("pid", ""); |
419 | tbmap.put("title", "填报"); | 422 | tbmap.put("title", "填报"); |
420 | dataTypeList.add(szmap); | 423 | if("day".equals(granularity)||"month".equals(granularity)) { |
421 | dataTypeList.add(tbmap); | 424 | dataTypeList.add(tbmap); |
425 | } | ||
422 | QueryWrapper<FReportManage> fReportManageQueryWrapper = new QueryWrapper<>(); | 426 | QueryWrapper<FReportManage> fReportManageQueryWrapper = new QueryWrapper<>(); |
423 | fReportManageQueryWrapper.eq("status","1"); | 427 | fReportManageQueryWrapper.eq("status","1"); |
424 | fReportManageQueryWrapper.eq("pro_status","1"); | 428 | fReportManageQueryWrapper.eq("pro_status","1"); |
429 | fReportManageQueryWrapper.eq("time_type", granularity); | ||
425 | fReportManageQueryWrapper.orderByAsc("sort_num"); | 430 | fReportManageQueryWrapper.orderByAsc("sort_num"); |
426 | List<FReportManage> fReportManages = reportManageService.list(fReportManageQueryWrapper); | 431 | List<FReportManage> fReportManages = reportManageService.list(fReportManageQueryWrapper); |
427 | for (FReportManage fReportManage : fReportManages) { | 432 | for (FReportManage fReportManage : fReportManages) { |
... | @@ -431,6 +436,12 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -431,6 +436,12 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
431 | report.put("title", fReportManage.getReportName()); | 436 | report.put("title", fReportManage.getReportName()); |
432 | dataTypeList.add(report); | 437 | dataTypeList.add(report); |
433 | } | 438 | } |
439 | //填报追加公式计算字段 | ||
440 | Map<String, Object> formulaReport = new HashMap<>(); | ||
441 | formulaReport.put("id", "formula"); | ||
442 | formulaReport.put("pid", "tb"); | ||
443 | formulaReport.put("title", "填报计算"); | ||
444 | dataTypeList.add(formulaReport); | ||
434 | //将业务数据转换为构造树所需的数据结构 | 445 | //将业务数据转换为构造树所需的数据结构 |
435 | List<TransTreeModel> transTreeModels = dataTypeList.stream().map(bo -> convertToTreeModel(bo)).collect(Collectors.toList()); | 446 | List<TransTreeModel> transTreeModels = dataTypeList.stream().map(bo -> convertToTreeModel(bo)).collect(Collectors.toList()); |
436 | List<TreeData> treeList=TreeUtils.buildTreeByRootId(transTreeModels, ""); | 447 | List<TreeData> treeList=TreeUtils.buildTreeByRootId(transTreeModels, ""); |
... | @@ -477,9 +488,14 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { | ... | @@ -477,9 +488,14 @@ public class CustomConsumeServiceImpl implements ICustomConsumeService { |
477 | } | 488 | } |
478 | 489 | ||
479 | @Override | 490 | @Override |
480 | public List<Map<String, Object>> queryDataFillIndex(String reportId) { | 491 | public List<Map<String, Object>> queryDataFillIndex(String reportId,String granularity) { |
481 | JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); | 492 | JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); |
482 | List<Map<String, Object>> list = masterDB.queryForList("select item_code as indexCode,item_alias as indexName,unit as indexUnit from f_report_item where report_id='"+reportId+"' and is_use_power_analyse='1' order by sort_num"); | 493 | List<Map<String, Object>> list = null; |
494 | if("formula".equals(reportId)) { | ||
495 | list = masterDB.queryForList("select formula_code as indexCode,formula_name as indexName,formula_unit as indexUnit from f_report_itemv_formula where report_id='"+reportId+"' and formula_granularity='"+granularity+"' order by sort_num"); | ||
496 | }else { | ||
497 | list = masterDB.queryForList("select item_code as indexCode,item_alias as indexName,unit as indexUnit from f_report_item where report_id='"+reportId+"' and is_use_power_analyse='1' order by sort_num"); | ||
498 | } | ||
483 | return list; | 499 | return list; |
484 | } | 500 | } |
485 | } | 501 | } | ... | ... |
... | @@ -39,7 +39,7 @@ public interface IFReportItemService extends IService<FReportItem> { | ... | @@ -39,7 +39,7 @@ public interface IFReportItemService extends IService<FReportItem> { |
39 | * @return | 39 | * @return |
40 | * @author Li Yuanyuan, 2021年2月3日 下午5:03:47 | 40 | * @author Li Yuanyuan, 2021年2月3日 下午5:03:47 |
41 | */ | 41 | */ |
42 | List<Map<String,Object>> getReportItemData(String departIds,String reportId,String startTime,String endTime,String index); | 42 | List<Map<String,Object>> getReportItemData(String departIds,String reportId,String startTime,String endTime,String index,String granularity); |
43 | 43 | ||
44 | Map<String, Object> getReportData(String reportId, String dataId); | 44 | Map<String, Object> getReportData(String reportId, String dataId); |
45 | 45 | ... | ... |
1 | package com.skua.modules.report.service.impl; | 1 | package com.skua.modules.report.service.impl; |
2 | 2 | ||
3 | import com.skua.common.report.ReportViewUtil; | 3 | import java.util.ArrayList; |
4 | import com.skua.modules.report.entity.FReportItem; | 4 | import java.util.Arrays; |
5 | import com.skua.modules.report.mapper.FReportItemMapper; | 5 | import java.util.HashMap; |
6 | import com.skua.modules.report.service.IFReportItemService; | 6 | import java.util.LinkedHashSet; |
7 | import java.util.List; | ||
8 | import java.util.Map; | ||
9 | import java.util.Set; | ||
10 | import java.util.stream.Collectors; | ||
11 | |||
12 | import javax.annotation.Resource; | ||
7 | 13 | ||
8 | import org.apache.commons.lang.StringUtils; | 14 | import org.apache.commons.lang.StringUtils; |
15 | import org.springframework.jdbc.core.JdbcTemplate; | ||
9 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
10 | 17 | ||
11 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 18 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
13 | 19 | import com.skua.common.report.CustomReportUtil; | |
14 | import javax.annotation.Resource; | 20 | import com.skua.common.report.ReportViewUtil; |
15 | 21 | import com.skua.core.context.SpringContextUtils; | |
16 | import java.util.HashMap; | 22 | import com.skua.core.util.ConvertUtils; |
17 | import java.util.List; | 23 | import com.skua.modules.report.entity.FReportItem; |
18 | import java.util.Map; | 24 | import com.skua.modules.report.mapper.FReportItemMapper; |
25 | import com.skua.modules.report.service.IFReportItemService; | ||
19 | 26 | ||
20 | /** | 27 | /** |
21 | * 报表数据项管理 | 28 | * 报表数据项管理 |
... | @@ -96,35 +103,104 @@ public class FReportItemServiceImpl extends ServiceImpl<FReportItemMapper, FRepo | ... | @@ -96,35 +103,104 @@ public class FReportItemServiceImpl extends ServiceImpl<FReportItemMapper, FRepo |
96 | return list; | 103 | return list; |
97 | } | 104 | } |
98 | 105 | ||
106 | //fReportManageQueryWrapper.eq("status","1"); | ||
107 | //fReportManageQueryWrapper.eq("pro_status","1"); | ||
108 | //fReportManageQueryWrapper.eq("time_type", granularity); | ||
99 | @Override | 109 | @Override |
100 | public List<Map<String, Object>> getReportItemData(String departIds,String reportId, String startTime, String endTime,String indexs) { | 110 | public List<Map<String, Object>> getReportItemData(String departIds,String reportId, String startTime, String endTime,String indexs,String granularity) { |
101 | String[] indexArray = indexs.split(","); | 111 | String[] indexArray = indexs.split(","); |
112 | //查询报表计算指标 | ||
113 | JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); | ||
114 | String formulaSql = "select formula_code,formula_info from f_report_itemv_formula where formula_granularity='"+granularity+"'"; | ||
115 | List<Map<String, Object>> formulaList = masterDB.queryForList(formulaSql); | ||
116 | Map<String,String> formulaMap = new HashMap<String,String>(); | ||
117 | for(Map<String,Object> map : formulaList) { | ||
118 | formulaMap.put(ConvertUtils.getString(map.get("formula_code")), ConvertUtils.getString(map.get("formula_info"))); | ||
119 | } | ||
120 | //对计算指标进行解析,追加到基础查询指标 | ||
121 | Set<String> indexSet = new LinkedHashSet<String>();//查询指标 | ||
122 | //存在计算指标,重新构造基础指标集合 | ||
102 | String selectPart = ""; | 123 | String selectPart = ""; |
103 | String headSelectPart = ""; | ||
104 | String formulaIds = ""; | ||
105 | for(String index : indexArray) { | 124 | for(String index : indexArray) { |
106 | selectPart = selectPart+","+index; | 125 | if(index.contains("formula_")) { |
107 | headSelectPart = headSelectPart+", max(case when item_code = '"+index+"' then CONCAT(item_alias,'(',unit,')') else '' end) as '"+index+"'"; | 126 | String formula = formulaMap.get(index); |
108 | formulaIds = formulaIds+","+"'"+index+"'"; | 127 | selectPart = selectPart+",round("+formulaMap.get(index).replace("{", "IFNULL(").replace("}", ",0)")+",2) as "+index; |
128 | //提取计算指标 | ||
129 | List<String> formulaIndexList = CustomReportUtil.getFormulaElement(formula); | ||
130 | for(String formulaIndex : formulaIndexList) { | ||
131 | indexSet.add(formulaIndex); | ||
132 | } | ||
133 | }else { | ||
134 | selectPart = selectPart+","+index; | ||
135 | indexSet.add(index); | ||
136 | } | ||
109 | } | 137 | } |
110 | if(!StringUtils.isEmpty(formulaIds)) { | 138 | indexs = String.join(",", indexSet); |
111 | selectPart = selectPart.substring(1); | 139 | //对基础查询指标按照报表进行分组 |
112 | headSelectPart = headSelectPart.substring(1); | 140 | String queryDataFillFieldSql="select item_code,report_id from f_report_item where report_id in(select id from f_report_manage where status='1' and pro_status='1' and time_type='"+granularity+"')"; |
113 | formulaIds = formulaIds.substring(1); | 141 | List<Map<String, Object>> baseDataFillFieldList = masterDB.queryForList(queryDataFillFieldSql); |
142 | Map<String,String> fieldToReportIdMap = new HashMap<String,String>(); | ||
143 | for(Map<String,Object> map : baseDataFillFieldList) { | ||
144 | fieldToReportIdMap.put(ConvertUtils.getString(map.get("item_code")), ConvertUtils.getString(map.get("report_id"))); | ||
114 | } | 145 | } |
115 | String headWhereInPart = "item_code IN("+formulaIds+")"; | 146 | String[] tempIndexArray = indexs.split(","); |
116 | 147 | Map<String,List<String>> reportIndexGroup = new HashMap<String,List<String>>(); | |
117 | Map<String,String> paramMap = new HashMap<String,String>(); | 148 | for(String key : tempIndexArray) { |
118 | paramMap.put("viewName", ReportViewUtil.buildView(reportId, indexs, departIds, startTime, endTime)); | 149 | String tempReportId = fieldToReportIdMap.get(key); |
119 | //paramMap.put("viewName", "view_"+reportId.substring(0, 4)); | 150 | List<String> reportIndexList = reportIndexGroup.get(tempReportId); |
120 | paramMap.put("startTime", startTime); | 151 | if(reportIndexList!=null) { |
121 | paramMap.put("endTime", endTime); | 152 | reportIndexList.add(key); |
122 | paramMap.put("dataSelectPart", selectPart); | 153 | }else { |
123 | paramMap.put("headSelectPart", headSelectPart); | 154 | reportIndexList = new ArrayList<String>(); |
124 | paramMap.put("headWhereInPart", headWhereInPart); | 155 | reportIndexList.add(key); |
125 | paramMap.put("reportId", reportId); | 156 | reportIndexGroup.put(tempReportId, reportIndexList); |
126 | paramMap.put("departIds", departIds); | 157 | } |
127 | return fReportItemMapper.getReportItemData(paramMap); | 158 | } |
159 | //基于报表做基础指标查询 | ||
160 | Set<String> reportIdSet = reportIndexGroup.keySet(); | ||
161 | //构造日期机构主参照表动态视图 | ||
162 | String baseViewPattern = "%Y-%m-%d"; | ||
163 | String baseViewGranularity = "DAY"; | ||
164 | String[] departIdArray = departIds.split(","); | ||
165 | String temp = ""; | ||
166 | for(String tempDepartId : departIdArray) { | ||
167 | temp = temp+",'"+tempDepartId+"'"; | ||
168 | } | ||
169 | if(StringUtils.isNotEmpty(temp)) { | ||
170 | temp = temp.substring(1); | ||
171 | } | ||
172 | String tempStartTime = startTime; | ||
173 | String tempEndTime = endTime; | ||
174 | if("month".equals(granularity)) { | ||
175 | baseViewPattern = "%Y-%m"; | ||
176 | baseViewGranularity = "MONTH"; | ||
177 | tempStartTime = startTime+"-01"; | ||
178 | tempEndTime = endTime+"-01"; | ||
179 | } | ||
180 | String baseViewName= "(SELECT a.time,b.id as depart_id,b.depart_name FROM (\r\n" + | ||
181 | "SELECT \r\n" + | ||
182 | " DATE_FORMAT(DATE_ADD('"+tempStartTime+"', INTERVAL t.help_topic_id "+baseViewGranularity+"), '"+baseViewPattern+"') AS time\r\n" + | ||
183 | "FROM \r\n" + | ||
184 | " mysql.help_topic t \r\n" + | ||
185 | "WHERE \r\n" + | ||
186 | " t.help_topic_id <= TIMESTAMPDIFF("+baseViewGranularity+", '"+tempStartTime+"', '"+tempEndTime+"')\r\n" + | ||
187 | ") a left join (select * from sys_depart where id in("+Arrays.stream(departIds.split(",")).map(id -> "'" + id + "'").collect(Collectors.joining(","))+")) b on 1=1)"; | ||
188 | |||
189 | int tag=1; | ||
190 | String sql = "select aa.time,aa.depart_id as departId,aa.depart_name as departName"+selectPart+" from "+baseViewName+" aa "; | ||
191 | for(String tempReportId : reportIdSet) { | ||
192 | String viewName = "view"+tag; | ||
193 | List<String> indexList = reportIndexGroup.get(tempReportId); | ||
194 | sql = sql +"left join "+ReportViewUtil.buildView(tempReportId, String.join(",", indexList), departIds, startTime, endTime) +viewName+ " on aa.time = "+viewName+".time and aa.depart_id = "+viewName+".depart_id "; | ||
195 | tag++; | ||
196 | } | ||
197 | System.out.println("======>>>>"+sql); | ||
198 | return masterDB.queryForList(sql); | ||
199 | } | ||
200 | public static void main(String[] args) { | ||
201 | String ids = "1,2,3,4"; | ||
202 | String str = Arrays.stream(ids.split(",")).map(id -> "'" + id + "'").collect(Collectors.joining(",")); | ||
203 | System.out.println(str); | ||
128 | } | 204 | } |
129 | 205 | ||
130 | @Override | 206 | @Override | ... | ... |
-
请 注册 或 登录 后发表评论