BaseStatistsService.java 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937
  1. package com.yihu.quota.service.quota;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.ehr.util.datetime.DateUtil;
  4. import com.yihu.quota.dao.jpa.TjQuotaDao;
  5. import com.yihu.quota.dao.jpa.TjQuotaGovProvisionDao;
  6. import com.yihu.quota.etl.extract.es.EsResultExtract;
  7. import com.yihu.quota.etl.model.EsConfig;
  8. import com.yihu.quota.etl.util.ElasticsearchUtil;
  9. import com.yihu.quota.model.jpa.TjQuota;
  10. import com.yihu.quota.model.jpa.dimension.TjQuotaDimensionMain;
  11. import com.yihu.quota.model.jpa.dimension.TjQuotaDimensionSlave;
  12. import com.yihu.quota.model.jpa.save.TjQuotaDataSave;
  13. import com.yihu.quota.model.jpa.source.TjQuotaDataSource;
  14. import com.yihu.quota.service.dimension.TjDimensionMainService;
  15. import com.yihu.quota.service.dimension.TjDimensionSlaveService;
  16. import com.yihu.quota.service.orgHealthCategory.OrgHealthCategoryStatisticsService;
  17. import com.yihu.quota.service.save.TjDataSaveService;
  18. import com.yihu.quota.service.singledisease.SingleDiseaseService;
  19. import com.yihu.quota.service.source.TjDataSourceService;
  20. import com.yihu.quota.util.BasesicUtil;
  21. import com.yihu.quota.vo.DictModel;
  22. import com.yihu.quota.vo.SaveModel;
  23. import net.sf.json.JSONObject;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  29. import org.springframework.jdbc.core.JdbcTemplate;
  30. import org.springframework.stereotype.Service;
  31. import java.math.BigDecimal;
  32. import java.text.NumberFormat;
  33. import java.text.SimpleDateFormat;
  34. import java.util.*;
  35. /**
  36. * Created by janseny on 2018/01/15.
  37. */
  38. @Service
  39. public class BaseStatistsService {
  40. Logger log = LoggerFactory.getLogger(BaseStatistsService.class);
  41. @Autowired
  42. private TjQuotaDao quotaDao;
  43. @Autowired
  44. private EsResultExtract esResultExtract;
  45. @Autowired
  46. private TjDimensionMainService tjDimensionMainService;
  47. @Autowired
  48. private TjDimensionSlaveService tjDimensionSlaveService;
  49. @Autowired
  50. private JdbcTemplate jdbcTemplate;
  51. @Autowired
  52. private OrgHealthCategoryStatisticsService orgHealthCategoryStatisticsService;
  53. @Autowired
  54. private TjDataSourceService dataSourceService;
  55. @Autowired
  56. private ObjectMapper objectMapper;
  57. @Autowired
  58. private QuotaService quotaService;
  59. @Autowired
  60. private ElasticsearchUtil elasticsearchUtil;
  61. @Autowired
  62. private SingleDiseaseService singleDiseaseService;
  63. @Autowired
  64. private TjQuotaGovProvisionDao tjQuotaGovProvisionDao;
  65. @Autowired
  66. private TjDataSaveService dataSaveService;
  67. private static String orgHealthCategory = "orgHealthCategory";
  68. public static String orgHealthCategoryCode = "orgHealthCategoryCode";
  69. public static String resultField = "result";
  70. public static String quotaDateField = "quotaDate";
  71. public static String firstColumnField = "firstColumn";
  72. /**
  73. * 特殊机构类型 根据 上级基础指标code 获取基础数据集
  74. * @param code
  75. * @param filter
  76. * @param dimension
  77. * @return
  78. * @throws Exception
  79. */
  80. public List<Map<String, Object>> getOrgHealthCategoryQuotaResultList(String code,String dimension,String filter, String top) throws Exception {
  81. List<Map<String, Object>> dimenListResult = getOrgHealthCategoryAggregationResult(code, dimension, filter, top);
  82. return dimenListResult;
  83. }
  84. /**
  85. * 根据指标code 和维度及条件 分组获取指标查询结果集
  86. * @param code
  87. * @param filter
  88. * @param dimension
  89. * @return
  90. * @throws Exception
  91. */
  92. public List<Map<String, Object>> getQuotaResultList(String code,String dimension,String filter,String dateType, String top) throws Exception {
  93. code = getBasicQuota(code);
  94. List<Map<String, Object>> dimenListResult = new ArrayList<>();
  95. if(StringUtils.isNotEmpty(dateType)){
  96. dimenListResult = getTimeAggregationResult(code, dimension, filter, dateType);
  97. }else {
  98. dimenListResult = getAggregationResult(code, dimension, filter, top);
  99. }
  100. return dimenListResult;
  101. }
  102. /**
  103. * 查找指标的最底层指标code
  104. * @param quotaCode
  105. * @return
  106. */
  107. public String getBasicQuota(String quotaCode){
  108. String code = quotaCode;
  109. TjQuota tjQuota = quotaService.findByCode(quotaCode);
  110. if( tjQuota != null && StringUtils.isNotEmpty(tjQuota.getResultGetType())){
  111. if (tjQuota.getResultGetType().equals("2")){//二次统计
  112. TjQuotaDataSource quotaDataSorce = dataSourceService.findSourceByQuotaCode(quotaCode);
  113. if(quotaDataSorce != null){
  114. JSONObject obj = new JSONObject().fromObject(quotaDataSorce.getConfigJson());
  115. EsConfig esConfig= (EsConfig) JSONObject.toBean(obj,EsConfig.class);
  116. if(StringUtils.isNotEmpty(esConfig.getSuperiorBaseQuotaCode()) && StringUtils.isEmpty(esConfig.getEspecialType()) ){
  117. code = esConfig.getSuperiorBaseQuotaCode();
  118. }
  119. }
  120. }
  121. }
  122. return code;
  123. }
  124. public List<Map<String, Object>> addQuota(String addFirstQuotaCode,String firstFilter, String addSecondQuotaCode, String secondFilter,String operation ,String dimension,String dateType, String top) throws Exception {
  125. List<Map<String, Object>> firstList = getQuotaResultList(addFirstQuotaCode,dimension,firstFilter,dateType, top);
  126. List<Map<String, Object>> secondList = getQuotaResultList(addSecondQuotaCode,dimension,secondFilter,dateType, top);
  127. dimension = StringUtils.isNotEmpty(dateType)? (StringUtils.isNotEmpty(dimension)? dimension +";"+dateType : dateType):dimension;
  128. List<Map<String, Object>> addition = addition(dimension, firstList, secondList, Integer.valueOf(operation));
  129. if (StringUtils.isNotEmpty(top)) {
  130. addition = sortResultList(addition, top);
  131. }
  132. return addition;
  133. }
  134. public List<Map<String, Object>> addition(String dimension, List<Map<String, Object>> firstList, List<Map<String, Object>> secondList,int operation){
  135. List<Map<String, Object>> addResultList = new ArrayList<>();
  136. NumberFormat nf = NumberFormat.getInstance();
  137. nf.setGroupingUsed(false);
  138. nf.setMaximumFractionDigits(2);
  139. List<Map<String, Object>> otherList = new ArrayList<>();
  140. otherList = secondList;
  141. String [] moleDimensions = dimension.split(";");
  142. for(Map<String, Object> firstMap :firstList) {
  143. if (null != firstMap && firstMap.size() > 0 ) {
  144. Map<String, Object> map = new HashMap<>();
  145. double firstResultVal = Double.valueOf(firstMap.get("result") == null ? "0" : firstMap.get(resultField).toString());
  146. map.put(firstColumnField, firstMap.get(firstColumnField));
  147. String firstKeyVal = "";
  148. for(int i = 0 ;i < moleDimensions.length ; i++){
  149. if(i == 0){
  150. firstKeyVal = firstMap.get(moleDimensions[i]).toString();
  151. }else {
  152. firstKeyVal = firstKeyVal + "-" + firstMap.get(moleDimensions[i]).toString() ;
  153. }
  154. map.put(moleDimensions[i], firstMap.get(moleDimensions[i]).toString());
  155. if(moleDimensions[i].equals("town") || moleDimensions[i].equals("org") ){
  156. if(firstMap.get(moleDimensions[i] + "Code") != null){
  157. map.put(moleDimensions[i]+ "Code", firstMap.get(moleDimensions[i] + "Code").toString());
  158. }
  159. }
  160. }
  161. boolean pflag = true;
  162. for(Map<String, Object> secondMap :secondList) {
  163. String secondKeyVal = "";
  164. String [] dimeDimensions = dimension.split(";");
  165. for(int i = 0 ;i < dimeDimensions.length ; i++){
  166. if(i == 0){
  167. secondKeyVal = secondMap.get(dimeDimensions[i]).toString();
  168. }else {
  169. secondKeyVal = secondKeyVal + "-" + secondMap.get(dimeDimensions[i]).toString() ;
  170. }
  171. }
  172. if(firstKeyVal.equals(secondKeyVal) || "quotaName".equals(dimension)){ // 如果维度是quotaName,则进入逻辑
  173. double point = 0;
  174. double dimeResultVal = Double.valueOf(secondMap.get(resultField).toString());
  175. BigDecimal first = new BigDecimal(Double.toString(firstResultVal));
  176. BigDecimal second = new BigDecimal(Double.toString(dimeResultVal));
  177. if(operation == 1){ //1 加法 默认
  178. point = first.add(second).doubleValue();
  179. }else if(operation == 2){ //2 减法
  180. point = first.subtract(second).doubleValue();
  181. }
  182. map.put(resultField,nf.format(point));
  183. addResultList.add(map);
  184. pflag = false;
  185. otherList.remove(secondMap);
  186. break;
  187. }
  188. }
  189. if(pflag){
  190. map.put(resultField, nf.format(firstResultVal));
  191. addResultList.add(map);
  192. }
  193. }
  194. }
  195. if (null != otherList && otherList.size() > 0) {
  196. for(Map<String, Object> secondMap : otherList) {
  197. Map<String, Object> map = new HashMap<>();
  198. map.put(firstColumnField, secondMap.get(firstColumnField));
  199. for(int i = 0 ;i < moleDimensions.length ; i++){
  200. map.put(moleDimensions[i], secondMap.get(moleDimensions[i]).toString());
  201. }
  202. double point = 0;
  203. double secondResultVal = Double.valueOf(secondMap.get("result") == null ? "0" : secondMap.get(resultField).toString());
  204. if (secondResultVal != 0) {
  205. if(operation == 1){ //1 加法 默认
  206. point = secondResultVal ;
  207. }else if(operation == 2){ //2 减法
  208. point = -secondResultVal;
  209. }
  210. }
  211. map.put(resultField, nf.format(point));
  212. addResultList.add(map);
  213. }
  214. }
  215. //检查后面指标的维度是否全部有 累加进去
  216. /*Map<String, Object> addResuDimenMap = new HashMap<>();
  217. for(int k = 0;k < addResultList.size();k++) {
  218. Map<String, Object> addResultMap = addResultList.get(k);
  219. String addDimenStr = "";
  220. for (int i = 0; i < moleDimensions.length; i++) {
  221. addDimenStr += addResultMap.get(moleDimensions[i]).toString() + "-";
  222. }
  223. addResuDimenMap.put(addDimenStr,addDimenStr);
  224. }
  225. for(Map<String, Object> secondMap :secondList) {
  226. String secondDimenStr = "";
  227. String addDimenStr = "";
  228. for(int i = 0 ;i < moleDimensions.length ; i++){
  229. secondDimenStr += secondMap.get(moleDimensions[i]).toString() + "-";
  230. }
  231. if( !addResuDimenMap.containsKey(secondDimenStr)){
  232. if( !addDimenStr.equals(secondDimenStr)){
  233. Map<String, Object> map = new HashMap<>();
  234. float dimeResultVal = Float.valueOf(secondMap.get(resultField).toString());
  235. map.put(resultField,df.format(dimeResultVal));
  236. map.put(firstColumnField, secondMap.get(firstColumnField));
  237. for(int i = 0 ;i < moleDimensions.length ; i++){
  238. map.put(moleDimensions[i], secondMap.get(moleDimensions[i]).toString());
  239. }
  240. addResultList.add(map);
  241. }
  242. }
  243. }*/
  244. return addResultList;
  245. }
  246. public List<Map<String, Object>> sortResultList(List<Map<String, Object>> listMap, String top) {
  247. if (null != listMap && listMap.size() > 0) {
  248. Collections.sort(listMap, new Comparator<Map<String, Object>>() {
  249. @Override
  250. public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  251. // 根据result进行降序
  252. double result = Double.parseDouble(o1.get("result") + "");
  253. double result2 = Double.parseDouble(o2.get("result") + "");
  254. double v = result2 - result;
  255. return v > 0 ? 1 : v == 0 ? 0 : -1;
  256. }
  257. });
  258. if (StringUtils.isNotEmpty(top)) {
  259. int t = Integer.parseInt(top);
  260. listMap = listMap.subList(0, listMap.size() > t ? t :listMap.size());
  261. }
  262. }
  263. return listMap;
  264. }
  265. /**
  266. * 两个维度相同指标除法运算
  267. * @param molecular
  268. * @param denominator
  269. * @param dimension
  270. * @param molecularFilter
  271. * @param denominatorFilters
  272. * @param operation
  273. * @param operationValue
  274. * @return
  275. * @throws Exception
  276. */
  277. public List<Map<String, Object>> divisionQuota(String molecular, String denominator, String dimension,
  278. String molecularFilter,String denominatorFilters,String operation,String operationValue,String dateType, String top) throws Exception {
  279. if(StringUtils.isEmpty(dimension) && StringUtils.isNotEmpty(dateType)){
  280. dimension = dateType;
  281. }
  282. List<Map<String, Object>> moleList = getSimpleQuotaReport(molecular, molecularFilter,dimension ,false , top);
  283. List<Map<String, Object>> denoList = getSimpleQuotaReport(denominator,denominatorFilters,dimension,false, null);
  284. dimension = StringUtils.isNotEmpty(dateType)? (StringUtils.isNotEmpty(dimension)? dimension +";"+dateType : dateType):dimension;
  285. return division(dimension,moleList,denoList,Integer.valueOf(operation),Integer.valueOf(operationValue));
  286. }
  287. /**
  288. * 指标除法运算 分母按年份获取总数
  289. * @param molecular 分子
  290. * @param dimension 分母
  291. * @param molecularFilter 分子条件
  292. * @param denominatorFilter 分母条件
  293. * @param operation
  294. * @param operationValue
  295. * @return
  296. * @throws Exception
  297. */
  298. public List<Map<String, Object>> divisionQuotaDenoConstant(String molecular, String dimension,String molecularFilter,String denominatorFilter,
  299. String operation,String operationValue,String dateType , String top) throws Exception {
  300. Double denominatorVal = 0.0;
  301. List<Map<String, Object>> moleList = getQuotaResultList(molecular,dimension,molecularFilter,dateType, top);
  302. String year = DateUtil.getYearFromYMD(new Date());
  303. String town = "";
  304. if(StringUtils.isNotEmpty(denominatorFilter)){
  305. String [] filter = denominatorFilter.split("and");
  306. if(filter.length > 0 ){
  307. for(String key : filter){
  308. if(key.contains(quotaDateField)){
  309. year = key.substring(key.indexOf("'")+1,key.indexOf("'")+5);//quotaDate >= '2018-03-01'
  310. }
  311. if(key.contains("town")){
  312. town = key.substring(key.indexOf("=")+1);
  313. }
  314. }
  315. }
  316. }
  317. Long sumValue = null;
  318. if(StringUtils.isNotEmpty(town)){
  319. sumValue = tjQuotaGovProvisionDao.getSumByDistrict(Long.parseLong(town),year);
  320. }else {
  321. sumValue = tjQuotaGovProvisionDao.getSumByDistrict(year);
  322. }
  323. // 获取分母的数值
  324. if(sumValue != null && sumValue.doubleValue() != 0){
  325. denominatorVal = sumValue.doubleValue();
  326. return divisionDenoConstant(dimension, moleList, denominatorVal, Integer.valueOf(operation), Integer.valueOf(operationValue));
  327. }else {
  328. return null;
  329. }
  330. }
  331. /**
  332. * 指标结果相除
  333. * 除法运算 分母按年份获取总数
  334. * @param dimension 维度
  335. * @param moleList 分子
  336. * @param denominatorVal 分母 数值
  337. * @param operation 运算方式 1 乘法 2 除法
  338. * @param operationValue 运算参数值
  339. *
  340. */
  341. public List<Map<String, Object>> divisionDenoConstant(String dimension, List<Map<String, Object>> moleList, Double denominatorVal,int operation,int operationValue) {
  342. List<Map<String, Object>> divisionResultList = new ArrayList<>();
  343. for (Map<String, Object> moleMap : moleList) {
  344. Map<String, Object> map = new HashMap<>();
  345. double moleResultVal = Double.valueOf(moleMap.get(resultField).toString());
  346. String moleKeyVal = "";
  347. String [] moleDimensions = dimension.split(";");
  348. for(int i = 0 ;i < moleDimensions.length ; i++){
  349. if(i == 0){
  350. moleKeyVal = moleMap.get(moleDimensions[i]).toString();
  351. }else {
  352. moleKeyVal = moleKeyVal + "-" + moleMap.get(moleDimensions[i]).toString() ;
  353. }
  354. map.put(moleDimensions[i], moleMap.get(moleDimensions[i]).toString());
  355. map.put(moleDimensions[i]+"Name", moleMap.get(moleDimensions[i]).toString());
  356. }
  357. if (moleResultVal == 0) {
  358. map.put(resultField,0);
  359. divisionResultList.add(map);
  360. } else {
  361. double point = 0;
  362. NumberFormat df = NumberFormat.getInstance();
  363. df.setGroupingUsed(false);
  364. df.setMaximumFractionDigits(2);
  365. if (operation == 1) {
  366. point = (moleResultVal / denominatorVal) * operationValue;
  367. } else if (operation == 2) {
  368. point = (moleResultVal / denominatorVal) / operationValue;
  369. }
  370. map.put(resultField, df.format(point));
  371. divisionResultList.add(map);
  372. }
  373. }
  374. return divisionResultList;
  375. }
  376. /**
  377. * 指标结果相除
  378. * @param dimension 维度
  379. * @param moleList 分子
  380. * @param denoList 分母
  381. * @param operation 运算方式 1 乘法 2 除法
  382. * @param operationValue 运算参数值
  383. *
  384. */
  385. public List<Map<String, Object>> division(String dimension, List<Map<String, Object>> moleList, List<Map<String, Object>> denoList,int operation,int operationValue){
  386. List<Map<String, Object>> divisionResultList = new ArrayList<>();
  387. for(Map<String, Object> moleMap :moleList) {
  388. if (null != moleMap && moleMap.size() > 0 ) {
  389. Map<String, Object> map = new HashMap<>();
  390. double moleResultVal = Double.valueOf(moleMap.get(resultField) == null ? "0" : moleMap.get(resultField).toString());
  391. String moleKeyVal = "";
  392. String [] moleDimensions = dimension.split(";");
  393. for(int i = 0 ;i < moleDimensions.length ; i++){
  394. if(i == 0){
  395. moleKeyVal = moleMap.get(moleDimensions[i]).toString();
  396. }else {
  397. moleKeyVal = moleKeyVal + "-" + moleMap.get(moleDimensions[i]).toString() ;
  398. }
  399. map.put(firstColumnField, moleMap.get(firstColumnField));
  400. map.put(moleDimensions[i], moleMap.get(moleDimensions[i]).toString());
  401. map.put(moleDimensions[i]+"Name", moleMap.get(moleDimensions[i]).toString());
  402. if("town".equals(moleDimensions[i]) || "org".equals(moleDimensions[i])) {
  403. if(moleMap.get(moleDimensions[i] + "Code") != null) {
  404. map.put(moleDimensions[i]+ "Code", moleMap.get(moleDimensions[i] + "Code").toString());
  405. }
  406. }
  407. }
  408. if (moleResultVal == 0) {
  409. map.put(resultField,0);
  410. divisionResultList.add(map);
  411. } else {
  412. for(Map<String, Object> denoMap :denoList) {
  413. String dimenKeyVal = "";
  414. String [] dimeDimensions = dimension.split(";");
  415. for(int i = 0 ;i < dimeDimensions.length ; i++){
  416. if(i == 0){
  417. dimenKeyVal = denoMap.get(dimeDimensions[i]).toString();
  418. }else {
  419. dimenKeyVal = dimenKeyVal + "-" + denoMap.get(dimeDimensions[i]).toString() ;
  420. }
  421. }
  422. if(moleKeyVal.equals(dimenKeyVal)){
  423. double point = 0;
  424. NumberFormat df = NumberFormat.getInstance();
  425. df.setGroupingUsed(false);
  426. df.setMaximumFractionDigits(2);
  427. float dimeResultVal = Float.valueOf(denoMap.get(resultField).toString());
  428. if(dimeResultVal != 0){
  429. if(operation == 1){
  430. point = (moleResultVal/dimeResultVal) * operationValue;
  431. }else if(operation == 2){
  432. point = (moleResultVal/dimeResultVal) / operationValue;
  433. }
  434. }
  435. map.put(resultField,df.format(point));
  436. divisionResultList.add(map);
  437. break;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. return divisionResultList;
  444. }
  445. /**
  446. * 特殊机构类别 根据条件查询结果
  447. * @param code
  448. * @param filters
  449. * @param dateType 日期类型
  450. * @param isTrunTree 是否转为机构类型树状机构
  451. * @throws Exception
  452. */
  453. public List<Map<String, Object>> getOrgHealthCategory(String code,String filters,String dateType,boolean isTrunTree, String top) throws Exception {
  454. List<Map<String, Object>> dimenListResult = new ArrayList<>();
  455. if(dateType != null && (dateType.contains("year") || dateType.contains("quarter")|| dateType.contains("month") || dateType.contains("day"))){
  456. dimenListResult = getTimeAggregationResult(code,orgHealthCategoryCode,filters,dateType);//dimension 维度为 year,month,day
  457. }else {
  458. dimenListResult = getAggregationResult(code, orgHealthCategoryCode, filters, top);
  459. }
  460. if(isTrunTree){
  461. List<Map<String, Object>> orgHealthCategoryList = orgHealthCategoryStatisticsService.getOrgHealthCategoryTreeByPid(-1);
  462. List<Map<String, Object>> resultList = setResult(code,orgHealthCategoryList,dimenListResult,dateType);
  463. return resultList;
  464. }else {
  465. return dimenListResult;
  466. }
  467. }
  468. /**
  469. * 递归循环 查询机构类型对应的名称和父节点
  470. * @param orgHealthCategoryList
  471. * @param dimenListResult
  472. * @param
  473. * @return
  474. */
  475. public List<Map<String,Object>> setResult(String quotaCode,List<Map<String,Object>> orgHealthCategoryList,List<Map<String, Object>> dimenListResult,String dateType){
  476. List<Map<String,Object>> result = new ArrayList<>();
  477. for(int i=0 ; i < orgHealthCategoryList.size() ; i++ ){
  478. Map<String,Object> mapCategory = orgHealthCategoryList.get(i);
  479. String code = mapCategory.get("code").toString();
  480. boolean notExitFalg = true;
  481. for(Map<String, Object> dimenMap : dimenListResult){
  482. boolean flag = false;
  483. if(dimenMap.get(orgHealthCategoryCode) != null){
  484. flag = dimenMap.get(orgHealthCategoryCode).equals(code);
  485. }
  486. if(dimenMap.get(code) != null || flag ){
  487. // mapCategory.putAll(dimenMap);
  488. if(dimenMap.containsKey(code)){
  489. mapCategory.put(code,dimenMap.get(code));
  490. mapCategory.put(resultField,dimenMap.get(resultField)!=null ? dimenMap.get(resultField):dimenMap.get(code));
  491. }
  492. if(StringUtils.isNotEmpty(dateType)){
  493. mapCategory.put(dimenMap.get(dateType).toString(),dimenMap.get(resultField));
  494. }
  495. mapCategory.put(quotaCode,dimenMap.get(resultField));
  496. break;
  497. }
  498. }
  499. if(notExitFalg){
  500. mapCategory.put(resultField,0);
  501. mapCategory.put(quotaCode,0);
  502. }
  503. mapCategory.put(firstColumnField,mapCategory.get("text"));
  504. result.add(mapCategory);
  505. if(mapCategory.get("children") != null){
  506. List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
  507. mapCategory.put("children",setResult(quotaCode,childrenOrgHealthCategoryList,dimenListResult,dateType));
  508. }
  509. }
  510. return result;
  511. }
  512. // /**
  513. // * 递归循环 查询机构类型对应的名称和父节点
  514. // * @param orgHealthCategoryList
  515. // * @param dimenListResult
  516. // * @param
  517. // * @return
  518. // */
  519. // public List<Map<String,Object>> setResultAllDimenMap(String quotaCode,List<Map<String,Object>> orgHealthCategoryList,List<Map<String, Object>> dimenListResult,String dateType){
  520. // List<Map<String,Object>> result = new ArrayList<>();
  521. // for(int i=0 ; i < orgHealthCategoryList.size() ; i++ ){
  522. // Map<String,Object> mapCategory = orgHealthCategoryList.get(i);
  523. // String code = mapCategory.get("code").toString();
  524. // boolean notExitFalg = true;
  525. // for(Map<String, Object> dimenMap : dimenListResult){
  526. // boolean flag = false;
  527. // if(dimenMap.get(orgHealthCategoryCode) != null){
  528. // flag = dimenMap.get(orgHealthCategoryCode).equals(code);
  529. // }
  530. // if(dimenMap.get(code) != null || flag ){
  531. // //补充所有信息
  532. // mapCategory.putAll(dimenMap);
  533. // if(dimenMap.containsKey(code)){
  534. // mapCategory.put(code,dimenMap.get(code));
  535. // mapCategory.put(resultField,dimenMap.get(resultField)!=null ? dimenMap.get(resultField):dimenMap.get(code));
  536. // }
  537. // if(StringUtils.isNotEmpty(dateType)){
  538. // mapCategory.put(dimenMap.get(dateType).toString(),dimenMap.get(resultField));
  539. // }
  540. // mapCategory.put(quotaCode,dimenMap.get(resultField));
  541. // notExitFalg = false;
  542. // break;
  543. // }
  544. // }
  545. // if(notExitFalg){
  546. // mapCategory.put(resultField,0);
  547. // mapCategory.put(quotaCode,0);
  548. // }
  549. // mapCategory.put(firstColumnField,mapCategory.get("text"));
  550. // result.add(mapCategory);
  551. // if(mapCategory.get("children") != null){
  552. // List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
  553. // mapCategory.put("children",setResultAllDimenMap(quotaCode, childrenOrgHealthCategoryList, dimenListResult, dateType));
  554. // }
  555. // }
  556. // return result;
  557. // }
  558. /**
  559. * 递归循环 计算各目录结构的值
  560. * @param orgHealthCategoryList
  561. * @param dimenListResult
  562. * @param
  563. * @return
  564. */
  565. public List<Map<String,Object>> allCategoryResultMap(List<String> quotaCodes,List<Map<String,Object>> orgHealthCategoryList,List<Map<String, Object>> dimenListResult ){
  566. List<Map<String,Object>> resultMap = new ArrayList<>();
  567. for(int i=0 ; i < orgHealthCategoryList.size() ; i++ ){
  568. Map<String,Object> mapCategory = orgHealthCategoryList.get(i);
  569. Map<String,Object> map = new HashMap<>();
  570. double parentResult = 0;
  571. mapCategory.put(firstColumnField,mapCategory.get("text"));
  572. map = getParentAllChildren(quotaCodes,mapCategory,map, dimenListResult,parentResult);
  573. if(map == null || map.size() == 0 ){
  574. for(String quotaCode : quotaCodes){
  575. map.put(quotaCode,0);
  576. }
  577. map.put(resultField,0);
  578. }
  579. mapCategory.putAll(map);
  580. resultMap.add(mapCategory);
  581. if(mapCategory.get("children") != null){
  582. List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
  583. mapCategory.put("children",allCategoryResultMap(quotaCodes,childrenOrgHealthCategoryList,dimenListResult));
  584. }
  585. }
  586. return resultMap;
  587. }
  588. //获取该节点下所有末节点的结果和
  589. public Map<String,Object> getParentAllChildren(List<String> quotaCodes, Map<String,Object> mapCategory,Map<String,Object> returnMap, List<Map<String, Object>> dimenListResult, double parentResult ){
  590. try {
  591. NumberFormat df = NumberFormat.getInstance();
  592. df.setGroupingUsed(false);
  593. df.setMaximumFractionDigits(2);
  594. boolean childrenFlag = false;
  595. if(mapCategory.get("children") != null){
  596. List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
  597. if(childrenOrgHealthCategoryList != null && childrenOrgHealthCategoryList.size() > 0){
  598. childrenFlag = true;
  599. }
  600. }
  601. if(childrenFlag){
  602. List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
  603. for(int j=0 ; j < childrenOrgHealthCategoryList.size() ; j++ ){
  604. Map<String,Object> childrenMapCategory = childrenOrgHealthCategoryList.get(j);
  605. returnMap = getParentAllChildren(quotaCodes ,childrenMapCategory,returnMap, dimenListResult,parentResult);
  606. }
  607. }else{
  608. for(Map<String, Object> dimenMap :dimenListResult){
  609. if(dimenMap.get(orgHealthCategoryCode) != null && dimenMap.get(resultField) != null){
  610. if(dimenMap.get(orgHealthCategoryCode).equals(mapCategory.get("code"))){
  611. double result = Double.parseDouble(dimenMap.get(resultField).toString());
  612. double oldResult = 0;
  613. if(returnMap.get(resultField) != null){
  614. oldResult = Double.parseDouble(returnMap.get(resultField).toString());
  615. }
  616. returnMap.put(resultField,df.format(result + oldResult));
  617. for(String quotaCode : quotaCodes){
  618. double quotaResult = Double.parseDouble(dimenMap.get(quotaCode).toString());
  619. double oldQuotaResult = 0;
  620. if( returnMap.get(quotaCode) != null ){
  621. oldQuotaResult = Double.parseDouble(returnMap.get(quotaCode).toString());
  622. }
  623. returnMap.put(quotaCode,df.format(quotaResult + oldQuotaResult));
  624. }
  625. break;
  626. }
  627. }
  628. }
  629. }
  630. }catch (Exception e){
  631. throw new NumberFormatException("统计数据转换异常");
  632. }
  633. return returnMap;
  634. }
  635. /**
  636. * 时间聚合查询指标结果
  637. * @param code
  638. * @param dimension 多维度 ; 分开
  639. * @param filter
  640. * @throws Exception
  641. */
  642. public List<Map<String, Object>> getTimeAggregationResult(String code,String dimension, String filter,String dateDime) throws Exception {
  643. TjQuota tjQuota= quotaDao.findByCode(code);
  644. Map<String,String> dimensionDicMap = getDimensionDicMap(code,dimension);
  645. List<String> dimenList = getDimenList(dimension);
  646. String groupDimension = joinDimen(dimension);
  647. List<Map<String, Object>> dimenListResult = esResultExtract.searcherSumByGroupByTime(tjQuota, groupDimension, filter, dateDime);
  648. List<Map<String, Object>> resultList = new ArrayList<>();
  649. String dateHist = "date_histogram(field=quotaDate,interval="+ dateDime +")";
  650. for(Map<String, Object> map : dimenListResult){
  651. Map<String,Object> dataMap = new HashMap<>();
  652. for(String key :map.keySet()){
  653. if(key.equals(dateHist)) {
  654. String value = "";
  655. if (dateDime.equals("year")) {
  656. value = map.get(key).toString().substring(0, 4);
  657. } else if (dateDime.contains("quarter")) {
  658. String y = map.get(key).toString().substring(0, 4);
  659. String q = map.get(key).toString().substring(5, 7);
  660. if(q.contains("01")){
  661. value = y + "年1季度";
  662. }else if(q.contains("04")){
  663. value = y + "年2季度";
  664. }else if(q.contains("07")){
  665. value = y + "年3季度";
  666. }else if(q.contains("10")){
  667. value = y + "年4季度";
  668. }
  669. } else if (dateDime.contains("month")) {
  670. value = map.get(key).toString().substring(0, 7);
  671. } else if (dateDime.contains("week")) {
  672. value = map.get(key).toString().substring(0, 7);
  673. } else if (dateDime.contains("day")) {
  674. value = map.get(key).toString().substring(0, 10);
  675. }
  676. dataMap.put(dateDime, value);
  677. }
  678. if(dimenList.contains(key)){
  679. if(dimensionDicMap.get(map.get(key).toString().toLowerCase()) != null){
  680. String dictVal = dimensionDicMap.get(map.get(key).toString().toLowerCase());
  681. dataMap.put(key+"Name",dictVal);
  682. dataMap.put(key,map.get(key).toString());
  683. dataMap.put(firstColumnField, dictVal);
  684. }else {
  685. if(key.equals(quotaDateField)){
  686. String dateFormat = "yyyy-MM-dd";
  687. if (dateDime.equals("year")) {
  688. dateFormat = "yyyy";
  689. }else if(dateDime.equals("month")){
  690. dateFormat = "yyyy-MM";
  691. }
  692. SimpleDateFormat format = new SimpleDateFormat(dateFormat);
  693. Long time = new Long(Long.valueOf(map.get(key).toString()));
  694. String quotaDate = format.format(time);
  695. dataMap.put(key, quotaDate);
  696. }else {
  697. dataMap.put(key,map.get(key));
  698. }
  699. }
  700. }
  701. //维度为特殊机构类型时
  702. if(key.equals(orgHealthCategoryCode)){
  703. dataMap.put(map.get(orgHealthCategoryCode).toString(),map.get(orgHealthCategoryCode));
  704. dataMap.put(firstColumnField,map.get("text"));
  705. }
  706. if(key.equals("SUM(result)")){
  707. NumberFormat nf = NumberFormat.getInstance();
  708. nf.setGroupingUsed(false);
  709. nf.setMaximumFractionDigits(2);
  710. dataMap.put(resultField, nf.format(map.get(key)));
  711. }
  712. }
  713. resultList.add(dataMap);
  714. }
  715. return resultList;
  716. }
  717. /**
  718. * 获取聚合查询指标结果
  719. * @param code
  720. * @param dimension 多维度 ; 分开
  721. * @param filter
  722. * @throws Exception
  723. */
  724. public List<Map<String, Object>> getOrgHealthCategoryAggregationResult(String code,String dimension, String filter, String top) throws Exception {
  725. TjQuota tjQuota= quotaDao.findByCode(code);
  726. String groupDimension = "";
  727. if(dimension.contains(";")){
  728. String[] dimens = dimension.split(";");
  729. for(int i =0 ;i<dimens.length ;i++){
  730. groupDimension += dimens[i] + ",";
  731. }
  732. groupDimension = groupDimension.substring(0,groupDimension.length()-1);
  733. }else {
  734. groupDimension = dimension;
  735. }
  736. List<Map<String, Object>> dimenListResult = null;
  737. if (StringUtils.isNotEmpty(top)) {
  738. dimenListResult = esResultExtract.searcherSumGroup(tjQuota, groupDimension, filter, resultField, groupDimension, "asc", "1000");
  739. if (dimenListResult != null && dimenListResult.size() > 0) {
  740. dimenListResult = dimenListResult.subList(0, dimenListResult.size() > Integer.parseInt(top) ? Integer.parseInt(top) : dimenListResult.size());
  741. }
  742. }else {
  743. dimenListResult = esResultExtract.searcherSumGroup(tjQuota, groupDimension, filter, resultField, groupDimension, "asc", top);
  744. }
  745. List<Map<String, Object>> resultList = new ArrayList<>();
  746. for(Map<String, Object> map : dimenListResult){
  747. Map<String,Object> dataMap = new HashMap<>();
  748. boolean quotaFlag = false;
  749. for(String key :map.keySet()){
  750. //维度为特殊机构类型时
  751. if(key.equals(orgHealthCategoryCode)){
  752. dataMap.put(map.get(orgHealthCategoryCode).toString(),map.get(orgHealthCategoryCode));
  753. }
  754. if(key.equals("SUM(result)")){
  755. NumberFormat nf = NumberFormat.getInstance();
  756. nf.setGroupingUsed(false);
  757. nf.setMaximumFractionDigits(2);
  758. dataMap.put(resultField, nf.format(map.get(key)));
  759. }
  760. if(key.equals(quotaDateField)){
  761. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  762. Long time = new Long(Long.valueOf(map.get(key).toString()));
  763. String quotaDate = format.format(time);
  764. dataMap.put(quotaDateField, quotaDate);
  765. quotaFlag = true;
  766. }
  767. }
  768. if(quotaFlag){
  769. map.remove(quotaDateField);
  770. }
  771. dataMap.putAll(map);
  772. resultList.add(dataMap);
  773. }
  774. return resultList;
  775. }
  776. /**
  777. * 获取 特殊机构类别 聚合查询指标结果
  778. * @param code
  779. * @param dimension 多维度 ; 分开
  780. * @param filter
  781. * @throws Exception
  782. */
  783. public List<Map<String, Object>> getAggregationResult(String code,String dimension, String filter, String top) throws Exception {
  784. TjQuota tjQuota= quotaDao.findByCode(code);
  785. Map<String,String> dimensionDicMap = getDimensionDicMap(code,dimension);
  786. List<String> dimenList = getDimenList(dimension);
  787. String groupDimension = joinDimen(dimension);
  788. List<TjQuotaDimensionSlave> slaves = tjDimensionSlaveService.findTjQuotaDimensionSlaveByQuotaCode(code);
  789. for(TjQuotaDimensionSlave slave :slaves) {
  790. if (slave.getSlaveCode().equals("dept")) {
  791. String dimenName = dimension + "Name not in('其他') ";
  792. if(StringUtils.isEmpty(filter)){
  793. filter = dimenName;
  794. }else {
  795. filter += " and " + dimenName;
  796. }
  797. }
  798. }
  799. List<Map<String, Object>> dimenListResult = null;
  800. if (StringUtils.isNotEmpty(top)) {
  801. dimenListResult = esResultExtract.searcherSumGroup(tjQuota, groupDimension, filter, resultField, groupDimension, "asc", "1000");
  802. if (dimenListResult != null && dimenListResult.size() > 0) {
  803. dimenListResult = dimenListResult.subList(0, dimenListResult.size() > Integer.parseInt(top) ? Integer.parseInt(top) : dimenListResult.size());
  804. }
  805. }else {
  806. dimenListResult = esResultExtract.searcherSumGroup(tjQuota, groupDimension, filter, resultField, groupDimension, "asc", top);
  807. }
  808. List<Map<String, Object>> resultList = new ArrayList<>();
  809. for(Map<String, Object> map : dimenListResult){
  810. Map<String,Object> dataMap = new HashMap<>();
  811. for(String key :map.keySet()){
  812. if(dimenList.contains(key)){
  813. if(dimensionDicMap.get(map.get(key).toString().toLowerCase()) != null){
  814. dataMap.put(key,dimensionDicMap.get(map.get(key).toString().toLowerCase()));
  815. dataMap.put(key+"Name",dimensionDicMap.get(map.get(key).toString().toLowerCase()));
  816. dataMap.put(key+"Code",map.get(key).toString());
  817. dataMap.put(firstColumnField,dimensionDicMap.get(map.get(key).toString().toLowerCase()));
  818. }else {
  819. dataMap.put(key,map.get(key));
  820. }
  821. }
  822. //维度为特殊机构类型时
  823. if(key.equals(orgHealthCategoryCode)){
  824. dataMap.put(map.get(orgHealthCategoryCode).toString(),map.get(orgHealthCategoryCode));
  825. dataMap.put(firstColumnField,map.get("text"));
  826. }
  827. if(key.equals("SUM(result)")){
  828. NumberFormat nf = NumberFormat.getInstance();
  829. nf.setGroupingUsed(false);
  830. nf.setMaximumFractionDigits(2);
  831. dataMap.put(resultField, nf.format(map.get(key)));
  832. }
  833. }
  834. resultList.add(dataMap);
  835. }
  836. if (StringUtils.isEmpty(top) && "town".equals(dimension)) {
  837. resultList = noDataDimenDictionary(resultList,dimension,filter);
  838. }
  839. for(TjQuotaDimensionSlave slave :slaves){
  840. if(slave.getSlaveCode().equals("sex") ){
  841. resultList = filteUnKnowSex(resultList, dimension);
  842. }
  843. }
  844. if(dimension.equals("level")){
  845. resultList = filteUnKnowLeve(resultList, dimension);
  846. }
  847. return resultList;
  848. }
  849. /**
  850. * 过滤未说明的性别,和其他为0的数据
  851. * @param dataList
  852. * @return
  853. */
  854. public List<Map<String, Object>> filteUnKnowSex(List<Map<String, Object>> dataList,String dimension){
  855. List<Map<String, Object>> resultList = new ArrayList<>();
  856. for(Map<String,Object> map : dataList){
  857. if(map.get(dimension) !=null){
  858. if( !map.get(dimension).toString().contains("未说明")){
  859. if(map.get(resultField) !=null){
  860. if(!map.get(dimension).toString().contains("未知") || ! map.get(resultField).toString().equals("0") ){
  861. resultList.add(map);
  862. }
  863. }
  864. }
  865. }
  866. }
  867. return resultList;
  868. }
  869. /**
  870. * 过滤未知的等级
  871. * @param dataList
  872. * @return
  873. */
  874. public List<Map<String, Object>> filteUnKnowLeve(List<Map<String, Object>> dataList,String dimension){
  875. List<Map<String, Object>> resultList = new ArrayList<>();
  876. for(Map<String,Object> map : dataList){
  877. if(map.get(dimension) !=null){
  878. if( !(map.get(dimension).toString().contains("未知") || map.get(dimension).toString().contains("9")) ){
  879. resultList.add(map);
  880. }
  881. }
  882. }
  883. return resultList;
  884. }
  885. /**
  886. * 查询结果 对无数据的字典项补0
  887. * @param dataList 数据集合
  888. * @param dimen 维度
  889. * @return
  890. */
  891. public List<Map<String, Object>> noDataDimenDictionary(List<Map<String, Object>> dataList,String dimen,String filter){
  892. Map<String, Object> dictMap = new HashMap<>();
  893. if(dimen.equals("town")){
  894. String sql = "";
  895. if(dimen.equals("town") ){
  896. sql = "SELECT id as code,name as name from address_dict where pid = '361100'";
  897. List<Map<String, Object>> dictDataList = jdbcTemplate.queryForList(sql);
  898. if(null != dictDataList) {
  899. for(int i = 0 ; i < dictDataList.size();i++){
  900. if(null != dictDataList.get(i).get("code") && null != dictDataList.get(i).get("name")){
  901. dictMap.put(dictDataList.get(i).get("code").toString(),dictDataList.get(i).get("name").toString());
  902. }
  903. }
  904. }
  905. }
  906. List<Map<String, Object>> resultList = new ArrayList<>();
  907. for(String code : dictMap.keySet()){
  908. Map<String,Object> oneMap = new HashMap<>();
  909. String result = "0";
  910. for(Map<String,Object> map : dataList){
  911. if(map.get(dimen) !=null && map.get(dimen).equals(dictMap.get(code))){
  912. result = map.get(resultField).toString();
  913. break;
  914. }
  915. }
  916. oneMap.put(firstColumnField,dictMap.get(code));
  917. oneMap.put(dimen,dictMap.get(code));
  918. oneMap.put(dimen+"Name",dictMap.get(code));
  919. oneMap.put(dimen+"Code",code);
  920. oneMap.put(resultField,result);
  921. resultList.add(oneMap);
  922. }
  923. return resultList;
  924. }
  925. return dataList;
  926. }
  927. /**
  928. * 拼接维度分组
  929. * @param dimension
  930. * @return
  931. */
  932. public String joinDimen(String dimension){
  933. String groupDimension = "";
  934. if(dimension.contains(";")){
  935. String[] dimens = dimension.split(";");
  936. for(int i =0 ;i<dimens.length ;i++){
  937. groupDimension += dimens[i] + ",";
  938. }
  939. groupDimension = groupDimension.substring(0,groupDimension.length()-1);
  940. }else {
  941. groupDimension = dimension;
  942. }
  943. return groupDimension;
  944. }
  945. /**
  946. * 获取维度List
  947. * @param dimension
  948. * @return 多维度 ;隔开
  949. */
  950. public List<String> getDimenList(String dimension){
  951. List<String> dimenList = new ArrayList<>();
  952. if(dimension.contains(";")){
  953. String[] dimens = dimension.split(";");
  954. for(int i =0 ;i<dimens.length ;i++){
  955. dimenList.add(dimens[i]);
  956. }
  957. }else {
  958. dimenList.add(dimension);
  959. }
  960. return dimenList;
  961. }
  962. /**
  963. * 获取指标维度字典项
  964. * @param quotaCode
  965. * @param dimension 多维度 ;隔开
  966. * @return
  967. */
  968. public Map<String,String> getDimensionDicMap(String quotaCode ,String dimension){
  969. Map<String,String> dimensionDicMap = new HashMap<>();
  970. String[] dimens = dimension.split(";");
  971. for(int i =0 ;i<dimens.length ;i++){
  972. String dictSql = getQuotaDimensionDictSql(quotaCode, dimens[i]);
  973. if(StringUtils.isNotEmpty(dictSql)){
  974. Map<String,String> dicMap = getDimensionMap(dictSql, dimens[i]);
  975. for(String key :dicMap.keySet()){
  976. dimensionDicMap.put(key.toLowerCase(),dicMap.get(key));
  977. }
  978. }
  979. }
  980. return dimensionDicMap;
  981. }
  982. /**
  983. * 获取维度的字典 sql -- 针对于查询结果 从ES库查询结果
  984. * @param quotaCode
  985. * @param dimension
  986. * @return
  987. */
  988. private String getQuotaDimensionDictSql(String quotaCode, String dimension) {
  989. boolean mainFlag = dimension.contains("province") || dimension.contains("city") ||dimension.contains("town")
  990. ||dimension.contains("org") ||dimension.contains("dept") ||dimension.contains("year") ||dimension.contains("quarter")
  991. ||dimension.contains("month") ||dimension.contains("day") || dimension.contains(quotaDateField) ;
  992. String dictSql = "";
  993. //查询维度 sql
  994. if( mainFlag){
  995. List<TjQuotaDimensionMain> dimensionMains = tjDimensionMainService.findTjQuotaDimensionMainByQuotaCode(quotaCode);
  996. if(dimensionMains != null && dimensionMains.size() > 0){
  997. for(TjQuotaDimensionMain main:dimensionMains){
  998. if(main.getMainCode().equals(dimension)){
  999. dictSql = main.getDictSql();
  1000. }
  1001. }
  1002. }
  1003. }else {
  1004. if(StringUtils.isEmpty(dictSql)) {
  1005. List<TjQuotaDimensionSlave> dimensionSlaves = tjDimensionSlaveService.findTjQuotaDimensionSlaveByQuotaCode(quotaCode);
  1006. if (dimensionSlaves != null && dimensionSlaves.size() > 0) {
  1007. if(StringUtils.isNotEmpty(dimension)){
  1008. String n = dimension.substring(dimension.length() - 1, dimension.length());
  1009. if(StringUtils.isNotEmpty(n) && (n.equals("1") || n.equals("2") || n.equals("3") || n.equals("4")) ){
  1010. int slave = Integer.valueOf(n);
  1011. if(dimensionSlaves.size() >= slave){
  1012. dictSql = dimensionSlaves.get(slave-1).getDictSql();
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. return dictSql;
  1020. }
  1021. /**
  1022. *获取字典项数据集
  1023. * @param dictSql
  1024. * @param dimension
  1025. * @return
  1026. */
  1027. public Map<String,String> getDimensionMap(String dictSql, String dimension) {
  1028. Map<String,String> dimensionDicMap = new HashMap<>();
  1029. if(StringUtils.isNotEmpty(dictSql)) {
  1030. BasesicUtil baseUtil = new BasesicUtil();
  1031. boolean main = dimension.contains("province") || dimension.contains("city") ||dimension.contains("town")
  1032. ||dimension.contains("org") ||dimension.contains("dept") ||dimension.contains("year") ||dimension.contains("month")
  1033. ||dimension.contains("quarter") ||dimension.contains("day");
  1034. if( main){
  1035. //主纬度字典项
  1036. List<SaveModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(SaveModel.class));
  1037. if(dictDatas != null ) {
  1038. for (SaveModel saveModel : dictDatas) {
  1039. String name = baseUtil.getFieldValueByName(dimension + "Name", saveModel);
  1040. String val = baseUtil.getFieldValueByName(dimension, saveModel);
  1041. if(StringUtils.isNotEmpty(val) && StringUtils.isNotEmpty(name)){
  1042. dimensionDicMap.put(val.toLowerCase(),name);
  1043. }
  1044. }
  1045. }
  1046. } else{
  1047. //查询细维度字典数据
  1048. List<DictModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(DictModel.class));
  1049. for (DictModel dictModel : dictDatas) {
  1050. String name = baseUtil.getFieldValueByName("name", dictModel);
  1051. String val = baseUtil.getFieldValueByName("code", dictModel).toLowerCase();
  1052. dimensionDicMap.put(val,name);
  1053. }
  1054. }
  1055. }
  1056. return dimensionDicMap;
  1057. }
  1058. /**
  1059. * 获取单个指标结果
  1060. * @param code
  1061. * @param filters 外部传入条件
  1062. * @param dimension
  1063. * @return
  1064. * @throws Exception
  1065. */
  1066. public List<Map<String, Object>> getSimpleQuotaReport(String code,String filters,String dimension,boolean isTrunTree, String top) throws Exception {
  1067. String dateType = "";
  1068. //指标的展示维度,由视图中决定
  1069. if(dimension.trim().equals("year")){
  1070. dateType = "year";
  1071. dimension = "";
  1072. }else if(dimension.trim().equals("quarter")){
  1073. dateType = "quarter";
  1074. dimension = "";
  1075. }else if(dimension.trim().equals("month")){
  1076. dateType = "month";
  1077. dimension = "";
  1078. }else if(dimension.trim().equals("day")){
  1079. dateType = "day";
  1080. dimension = "";
  1081. }
  1082. List<Map<String, Object>> result = new ArrayList<>();
  1083. TjQuotaDataSource quotaDataSource = dataSourceService.findSourceByQuotaCode(code);
  1084. JSONObject obj = new JSONObject().fromObject(quotaDataSource.getConfigJson());
  1085. EsConfig esConfig= (EsConfig) JSONObject.toBean(obj,EsConfig.class);
  1086. String configFilter = esConfig.getFilter();
  1087. if(StringUtils.isNotEmpty(configFilter) && quotaDataSource.getSourceCode().equals("1")){//数据源为ES库
  1088. TjQuotaDataSave quotaDataSave = dataSaveService.findByQuota(code);
  1089. if(quotaDataSave != null && StringUtils.isNotEmpty(quotaDataSave.getConfigJson())){
  1090. JSONObject objSave = new JSONObject().fromObject(quotaDataSave.getConfigJson());
  1091. EsConfig esConfigSave = (EsConfig) JSONObject.toBean(objSave,EsConfig.class);
  1092. if(StringUtils.isEmpty(esConfig.getIndex()) || esConfig.getIndex().equals(esConfigSave.getIndex()) ){
  1093. if(StringUtils.isNotEmpty(filters)){
  1094. filters += " and " + configFilter;
  1095. }else {
  1096. filters = configFilter;
  1097. }
  1098. }
  1099. }else {
  1100. if(StringUtils.isNotEmpty(filters)){
  1101. filters += " and " + configFilter;
  1102. }else {
  1103. filters = configFilter;
  1104. }
  1105. }
  1106. }
  1107. // 判断该指标是否需要同比, 需要的话拼接时间条件
  1108. if (StringUtils.isNotEmpty(esConfig.getIncrementFlag())) {
  1109. filters = filtersExchangeHandle(filters, esConfig);
  1110. log.info("filters = {}", filters);
  1111. }
  1112. String molecularFilter = filters;
  1113. String denominatorFilter = filters;
  1114. if (StringUtils.isNotEmpty(esConfig.getGrowthFlag())) {
  1115. //增幅运算(环比和同比)
  1116. result = getGrowthByQuota(dimension, filters, esConfig, dateType);
  1117. } else {
  1118. if (StringUtils.isNotEmpty(esConfig.getDateComparisonType())) {
  1119. //时间条件处理
  1120. filters = getdateComparisonTypeFilter(esConfig,filters);
  1121. }
  1122. if( (StringUtils.isNotEmpty(esConfig.getEspecialType())) && esConfig.getEspecialType().equals(orgHealthCategory)){
  1123. // //特殊机构类型查询输出结果 只有查询条件没有维度 默认是 机构类型维度
  1124. // result = getOrgHealthCategory(code,filters,dateType,isTrunTree, top);
  1125. }else if( (StringUtils.isNotEmpty(esConfig.getMolecular())) && StringUtils.isNotEmpty(esConfig.getDenominator())){//除法
  1126. //除法指标查询输出结果
  1127. molecularFilter = handleFilter(esConfig.getMolecularFilter(), molecularFilter);
  1128. denominatorFilter = handleFilter(esConfig.getDenominatorFilter(), denominatorFilter);
  1129. if (StringUtils.isNotEmpty(esConfig.getDivisionType()) && esConfig.getDivisionType().equals("2")) {
  1130. result = divisionQuotaDenoConstant(esConfig.getMolecular(), dimension, molecularFilter, denominatorFilter,esConfig.getPercentOperation(), esConfig.getPercentOperationValue(), dateType, top);
  1131. } else {
  1132. result = divisionQuota(esConfig.getMolecular(), esConfig.getDenominator(), dimension, molecularFilter, denominatorFilter, esConfig.getPercentOperation(), esConfig.getPercentOperationValue(),dateType, top);
  1133. }
  1134. //计算除法 合计
  1135. String moleQuotaCode = getBasicQuota(esConfig.getMolecular());
  1136. moleQuotaCode = " quotaCode='" + moleQuotaCode.replaceAll("_", "") + "' ";
  1137. String denoQuotaCode = getBasicQuota(esConfig.getDenominator());
  1138. denoQuotaCode = " quotaCode='" + denoQuotaCode.replaceAll("_", "") + "' ";
  1139. if(StringUtils.isEmpty(molecularFilter)){
  1140. molecularFilter = moleQuotaCode;
  1141. }else {
  1142. molecularFilter += " and " + moleQuotaCode;
  1143. }
  1144. if(StringUtils.isEmpty(denominatorFilter)){
  1145. denominatorFilter = denoQuotaCode;
  1146. }else {
  1147. denominatorFilter += " and " + denoQuotaCode;
  1148. }
  1149. String moleTotalSql = "select sum(result) result from medical_service_index where " + molecularFilter;
  1150. String denoTotalSql = "select sum(result) result from medical_service_index where " + denominatorFilter;
  1151. double moleTotal = 0;
  1152. double denoTotal = 0;
  1153. List<Map<String, Object>> moleListMap = elasticsearchUtil.excuteDataModel(moleTotalSql.toString());
  1154. if(moleListMap != null && moleListMap.size() > 0){
  1155. if(moleListMap.get(0).get("result") != null){
  1156. moleTotal = Double.valueOf(moleListMap.get(0).get("result").toString());
  1157. }
  1158. }
  1159. List<Map<String, Object>> denoListMap = elasticsearchUtil.excuteDataModel(denoTotalSql.toString());
  1160. if(denoListMap != null && denoListMap.size() > 0){
  1161. if(denoListMap.get(0).get("result") != null){
  1162. denoTotal = Double.valueOf(denoListMap.get(0).get("result").toString());
  1163. }
  1164. }
  1165. double point = 0;
  1166. NumberFormat df = NumberFormat.getInstance();
  1167. df.setGroupingUsed(false);
  1168. df.setMaximumFractionDigits(2);
  1169. int operation = Integer.valueOf(esConfig.getPercentOperation());
  1170. int operationValue = Integer.valueOf(esConfig.getPercentOperationValue());
  1171. if(denoTotal - 0 != 0){
  1172. if(moleTotal != 0){
  1173. if(operation == 1){
  1174. point = (moleTotal/denoTotal) * operationValue;
  1175. }else if(operation == 2){
  1176. point = (moleTotal/denoTotal) / operationValue;
  1177. }
  1178. }
  1179. }
  1180. Map<String, Object> totalMap = new HashMap<>();
  1181. totalMap.put(resultField,df.format(point));
  1182. totalMap.put(dimension,"合计");
  1183. totalMap.put(firstColumnField,"合计");
  1184. result.add(totalMap);
  1185. }else if(StringUtils.isNotEmpty(esConfig.getAddOperation())){
  1186. String firstFilter = handleFilter(esConfig.getAddFirstFilter(), filters);
  1187. String secondFilter = handleFilter(esConfig.getAddSecondFilter(), filters);
  1188. result = addQuota(esConfig.getAddFirstQuotaCode(), firstFilter, esConfig.getAddSecondQuotaCode(), secondFilter, esConfig.getAddOperation(),dimension,dateType, top);
  1189. }else if(StringUtils.isNotEmpty(esConfig.getSuperiorBaseQuotaCode())) {
  1190. //二次统计 指标查询
  1191. result = getQuotaResultList(esConfig.getSuperiorBaseQuotaCode(), dimension,filters,dateType, top);
  1192. }else {
  1193. //普通基础指标查询
  1194. result = getQuotaResultList(code, dimension,filters,dateType, top);
  1195. }
  1196. }
  1197. return result;
  1198. }
  1199. //时间对比类型 时的 查询条件处理
  1200. public String getdateComparisonTypeFilter(EsConfig esConfig,String filters){
  1201. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  1202. Calendar c = Calendar.getInstance();
  1203. Map<String,String> filterMap = new HashMap<>();
  1204. if(StringUtils.isNotEmpty(filters)){
  1205. String [] filter = filters.split("and");
  1206. String year = "";
  1207. String month = "";
  1208. String day = "";
  1209. if(filter.length > 0 ){
  1210. for(String key : filter){
  1211. filterMap.put(key,key);
  1212. Date date = new Date();
  1213. if(key.contains(quotaDateField)){
  1214. //quotaDate >= '2018-03-01'
  1215. String dateStr = key.substring(key.indexOf("'")+1,key.lastIndexOf("'"));
  1216. date = DateUtil.parseDate(dateStr,DateUtil.DEFAULT_DATE_YMD_FORMAT);
  1217. }
  1218. if(esConfig.getDateComparisonType().equals("lastYear")){
  1219. c.setTime(date);
  1220. c.add(Calendar.YEAR, -1);
  1221. Date lastYear = c.getTime();
  1222. filterMap.put(key,format.format(lastYear));
  1223. }else if(esConfig.getDateComparisonType().equals("lastMonth")) {
  1224. c.setTime(date);
  1225. c.add(Calendar.MONTH, -1);
  1226. Date lastYear = c.getTime();
  1227. filterMap.put(key,format.format(lastYear));
  1228. }else if(esConfig.getDateComparisonType().equals("lastDay")) {
  1229. c.setTime(date);
  1230. c.add(Calendar.DATE, -1);
  1231. Date lastYear = c.getTime();
  1232. filterMap.put(key,format.format(lastYear));
  1233. }
  1234. }
  1235. }
  1236. filters = "";
  1237. if(filterMap != null && filterMap.size() > 0){
  1238. for(String key : filterMap.keySet()){
  1239. if(StringUtils.isEmpty(filters)){
  1240. filters = filterMap.get(key);
  1241. }else {
  1242. filters = " and " + filterMap.get(key);
  1243. }
  1244. }
  1245. }
  1246. }
  1247. return filters;
  1248. }
  1249. public String handleFilter(String secondFilter, String resultFilter) {
  1250. if (StringUtils.isNotEmpty(secondFilter)) {
  1251. if (StringUtils.isEmpty(resultFilter)) {
  1252. resultFilter = secondFilter;
  1253. } else {
  1254. resultFilter += " and " + secondFilter;
  1255. }
  1256. }
  1257. return resultFilter;
  1258. }
  1259. /**
  1260. * 门急诊费用
  1261. * @return
  1262. */
  1263. public String getCostOfOutPatient() {
  1264. String sum = "0";
  1265. String sql = "select sum(result) from medical_service_index where quotaCode='HC041047'";
  1266. List<Map<String, Object>> listData = elasticsearchUtil.excuteDataModel(sql);
  1267. NumberFormat nf = NumberFormat.getInstance();
  1268. nf.setGroupingUsed(false);
  1269. nf.setMaximumFractionDigits(2);
  1270. if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
  1271. for (Map<String, Object> map : listData) {
  1272. sum = nf.format(map.get("SUM(result)"));
  1273. }
  1274. }
  1275. return sum;
  1276. }
  1277. /**
  1278. * 门急诊人次
  1279. * @return
  1280. */
  1281. public String getNumOfOutPatient() {
  1282. int sum = 0;
  1283. String sql = "select sum(result) from medical_service_index where quotaCode='HC041008'";
  1284. List<Map<String, Object>> listData = singleDiseaseService.parseIntegerValue(sql);
  1285. NumberFormat nf = NumberFormat.getInstance();
  1286. nf.setGroupingUsed(false);
  1287. nf.setMaximumFractionDigits(2);
  1288. if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
  1289. for (Map<String, Object> map : listData) {
  1290. String value = nf.format(map.get("SUM(result)"));
  1291. sum += Integer.parseInt(value);
  1292. }
  1293. }
  1294. return sum + "";
  1295. }
  1296. /**
  1297. * 入院费用
  1298. * @return
  1299. */
  1300. public String getCostOfInPatient() {
  1301. String sum = "0";
  1302. String sql = "select sum(result) from medical_service_index where quotaCode='HC041068'";
  1303. List<Map<String, Object>> listData = elasticsearchUtil.excuteDataModel(sql);
  1304. NumberFormat nf = NumberFormat.getInstance();
  1305. nf.setGroupingUsed(false);
  1306. nf.setMaximumFractionDigits(2);
  1307. if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
  1308. for (Map<String, Object> map : listData) {
  1309. sum = nf.format(map.get("SUM(result)"));
  1310. }
  1311. }
  1312. return sum;
  1313. }
  1314. /**
  1315. * 入院人次
  1316. * @return
  1317. */
  1318. public String getNumOfInPatient() {
  1319. int sum = 0;
  1320. String sql = "select sum(result) from medical_service_index where quotaCode='HC041000'";
  1321. List<Map<String, Object>> listData = singleDiseaseService.parseIntegerValue(sql);
  1322. NumberFormat nf = NumberFormat.getInstance();
  1323. nf.setGroupingUsed(false);
  1324. nf.setMaximumFractionDigits(2);
  1325. if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
  1326. for (Map<String, Object> map : listData) {
  1327. String value = nf.format(map.get("SUM(result)"));
  1328. sum += Integer.parseInt(value);
  1329. }
  1330. }
  1331. return sum + "";
  1332. }
  1333. public String getCostOfMedicalMonitor() {
  1334. NumberFormat nf = NumberFormat.getInstance();
  1335. nf.setGroupingUsed(false);
  1336. nf.setMaximumFractionDigits(2);
  1337. // 获取门急诊费用
  1338. Double costOfOutPatient = Double.parseDouble(getCostOfOutPatient());
  1339. // 获取入院费用
  1340. Double costOfInPatient = Double.parseDouble(getCostOfInPatient());
  1341. // 医疗费用监测 = 获取门急诊费用 + 获取入院费用
  1342. Double costOfMedicalMonitor = costOfInPatient + costOfOutPatient;
  1343. return nf.format(costOfMedicalMonitor);
  1344. }
  1345. /**
  1346. * 数据查询
  1347. * @return
  1348. */
  1349. public Map<String, List<String>> getDataInfo(String sql ,String xdataName) {
  1350. List<Map<String, Object>> listData = parseIntegerValue(sql);
  1351. Map<String, List<String>> map = new HashMap<>();
  1352. List<String> xData = new ArrayList<>();
  1353. List<String> valueData = new ArrayList<>();
  1354. if (null != listData && listData.size() >0 && listData.get(0) !=null ) {
  1355. listData.forEach(one -> {
  1356. if(xdataName.contains("date_histogram")){
  1357. if(xdataName.contains("year")){
  1358. xData.add(one.get(xdataName).toString().substring(0,4) + "");
  1359. }else if(xdataName.contains("quarter")){
  1360. String quarter = "";
  1361. if(one.get(xdataName) != null){
  1362. String value = one.get(xdataName).toString();
  1363. String y = value.substring(0, 4);
  1364. String q = value.substring(5, 7);
  1365. if(q.contains("01")){
  1366. quarter = y + "年1季度";
  1367. }else if(q.contains("04")) {
  1368. value = y + "年2季度";
  1369. }else if(q.contains("07")){
  1370. quarter = y + "年3季度";
  1371. }else if(q.contains("10")){
  1372. quarter = y + "年4季度";
  1373. }
  1374. xData.add(quarter);
  1375. }
  1376. }else if(xdataName.contains("month")){
  1377. xData.add(one.get(xdataName).toString().substring(0,7) + "");
  1378. }
  1379. }else {
  1380. xData.add(one.get(xdataName) + "");
  1381. }
  1382. valueData.add(one.get("count") + "");
  1383. });
  1384. map.put("xData", xData);
  1385. map.put("valueData", valueData);
  1386. }
  1387. return map;
  1388. }
  1389. /**
  1390. * 对查询结果key包含count、sum的value去掉小数点
  1391. * @param sql
  1392. * @return
  1393. */
  1394. public List<Map<String, Object>> parseIntegerValue(String sql) {
  1395. List<Map<String, Object>> listData = elasticsearchUtil.excuteDataModel(sql);
  1396. List<Map<String, Object>> handleData = new ArrayList<>();
  1397. listData.forEach(item -> {
  1398. Map<String, Object> myMap = new HashMap<>();
  1399. item.forEach((k,v) -> {
  1400. if (k.contains("COUNT") || k.contains("SUM") || k.contains("count")) {
  1401. v = (int) Double.parseDouble(v + "");
  1402. }
  1403. myMap.put(k,v);
  1404. });
  1405. handleData.add(myMap);
  1406. });
  1407. return handleData;
  1408. }
  1409. /**
  1410. * 百分比 增幅运算 维度不是时间维度
  1411. * @param dimension
  1412. * @param moleList
  1413. * @param denoList
  1414. * @param operation
  1415. * @param operationValue
  1416. * @return
  1417. */
  1418. public List<Map<String, Object>> divisionPercent(String dimension, List<Map<String, Object>> moleList, List<Map<String, Object>> denoList,int operation,int operationValue){
  1419. List<Map<String, Object>> divisionResultList = new ArrayList<>();
  1420. for(Map<String, Object> denoMap : denoList) {
  1421. if (null != denoMap && denoMap.size() > 0 ) {
  1422. Map<String, Object> map = new HashMap<>();
  1423. double denoResultVal = Double.valueOf(denoMap.get(resultField) == null ? "0" : denoMap.get(resultField).toString());
  1424. String denoKeyVal = "";
  1425. String [] denoDimensions = dimension.split(";");
  1426. for(int i = 0 ;i < denoDimensions.length ; i++){
  1427. if(i == 0){
  1428. denoKeyVal = denoMap.get(denoDimensions[i]).toString();
  1429. }else {
  1430. denoKeyVal = denoKeyVal + "-" + denoMap.get(denoDimensions[i]).toString() ;
  1431. }
  1432. map.put(firstColumnField, denoMap.get(firstColumnField));
  1433. map.put(denoDimensions[i], denoMap.get(denoDimensions[i]).toString());
  1434. }
  1435. if (denoResultVal == 0) {
  1436. map.put(resultField, "--");
  1437. divisionResultList.add(map);
  1438. } else {
  1439. if(moleList != null && moleList.size() > 0){
  1440. for(Map<String, Object> moleMap :moleList) {
  1441. String moleKeyVal = "";
  1442. String [] moleDimensions = dimension.split(";");
  1443. for(int i = 0 ;i < moleDimensions.length ; i++){
  1444. if(i == 0){
  1445. moleKeyVal = moleMap.get(moleDimensions[i]).toString();
  1446. }else {
  1447. moleKeyVal = moleKeyVal + "-" + moleMap.get(moleDimensions[i]).toString() ;
  1448. }
  1449. }
  1450. if(denoKeyVal.equals(moleKeyVal)){
  1451. double point = 0;
  1452. NumberFormat nf = NumberFormat.getInstance();
  1453. nf.setGroupingUsed(false);
  1454. nf.setMaximumFractionDigits(2);
  1455. float moleResultVal = Float.valueOf(moleMap.get(resultField).toString());
  1456. point = ((moleResultVal - denoResultVal)/denoResultVal) * operationValue;
  1457. map.put(resultField, nf.format(point));
  1458. divisionResultList.add(map);
  1459. break;
  1460. }
  1461. }
  1462. }else {
  1463. map.put(resultField, 0);
  1464. divisionResultList.add(map);
  1465. }
  1466. }
  1467. }
  1468. }
  1469. return divisionResultList;
  1470. }
  1471. /**
  1472. * 计算增幅 环比和 同比
  1473. * @param dimension 不为空时,查询固定某个月或者某年的增幅
  1474. * @param filters 外部过滤条件 如 quotaDate >= '2018-03-01' and quotaDate <= '2018-03-31'
  1475. * @param esConfig 指标内部配置
  1476. * @param dateType 不为空时,查询某个时间区间的增幅
  1477. * @return
  1478. * @throws Exception
  1479. */
  1480. public List<Map<String, Object>> getGrowthByQuota(String dimension, String filters, EsConfig esConfig, String dateType) throws Exception {
  1481. List<Map<String, Object>> resultList = new LinkedList<>();
  1482. String startQuotaDate = "";
  1483. String endQuotaDate = "";
  1484. String noDateFilter = "";
  1485. if(StringUtils.isNotEmpty(esConfig.getDenominatorFilter()) ){
  1486. noDateFilter = esConfig.getDenominatorFilter();
  1487. }
  1488. if (StringUtils.isNotEmpty(filters) && filters.contains(quotaDateField)) {// 外部指定时间
  1489. String params [] = filters.split("and ");
  1490. for(int i =0 ;i< params.length ;i++){
  1491. String quotaDateParam = params[i];
  1492. if(quotaDateParam.contains(quotaDateField)){
  1493. boolean b = quotaDateParam.indexOf("'") > -1;
  1494. int start = b ? quotaDateParam.indexOf("'") : quotaDateParam.indexOf("\"");//查询条件不是' ,就是"
  1495. if(quotaDateParam.contains(">")){
  1496. startQuotaDate = quotaDateParam.substring(start + 1, start + 11);
  1497. }
  1498. if(quotaDateParam.contains("<")){
  1499. endQuotaDate = quotaDateParam.substring(start + 1, start + 11);
  1500. }
  1501. }else{
  1502. if(StringUtils.isNotEmpty(noDateFilter)){
  1503. noDateFilter += " and " + quotaDateParam;
  1504. }else {
  1505. noDateFilter = quotaDateParam;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1511. Calendar lastDate = Calendar.getInstance();
  1512. String molecularFilter = "";
  1513. String denominatorFilter = "";
  1514. String growthFlag = esConfig.getGrowthFlag();
  1515. if(StringUtils.isEmpty(dateType)){
  1516. if ("1".equals(growthFlag)) { // 年增幅 没有传时间条件默认当前年份
  1517. int now;
  1518. int beforeNow;
  1519. now = lastDate.get(Calendar.YEAR);
  1520. if (StringUtils.isNotEmpty(endQuotaDate)) {// 外部指定时间
  1521. now = Integer.parseInt(endQuotaDate.substring(0,4));
  1522. }
  1523. beforeNow = now - 1;
  1524. molecularFilter = "quotaDate >= '" + now + "-01-01' and quotaDate <= '" + now + "-12-31'";
  1525. denominatorFilter = "quotaDate >= '" + beforeNow + "-01-01' and quotaDate <= '" + beforeNow + "-12-31'";
  1526. } else if ("2".equals(growthFlag)) { // 月增幅 没有传时间条件默认当前月份
  1527. // 如果有时间过滤条件,则按时间条件计算
  1528. if (StringUtils.isNotEmpty(endQuotaDate)) {
  1529. lastDate.setTime(sdf.parse(endQuotaDate));
  1530. }
  1531. lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1532. String firstDay = sdf.format(lastDate.getTime());
  1533. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1534. String lastDay = sdf.format(lastDate.getTime());
  1535. lastDate.add(Calendar.MONTH, -1);
  1536. lastDate.set(Calendar.DAY_OF_MONTH, 1);
  1537. String preMonthFirstDay = sdf.format(lastDate.getTime());
  1538. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1539. String preMonthLastDay = sdf.format(lastDate.getTime());
  1540. log.info("firstDay = {}, lastDay = {}", firstDay, lastDay);
  1541. log.info("preMonthFirstDay = {}, preMonthLastDay = {}", preMonthFirstDay, preMonthLastDay);
  1542. molecularFilter = "quotaDate >= '" + firstDay + "' and quotaDate <= '" + lastDay + "'";
  1543. denominatorFilter = "quotaDate >= '" + preMonthFirstDay + "' and quotaDate <= '" + preMonthLastDay + "'";
  1544. } else if ("3".equals(growthFlag)) { // 季度增幅 没有传时间条件默认当前季度
  1545. // 如果有时间过滤条件,则按时间条件计算
  1546. if (StringUtils.isNotEmpty(endQuotaDate)) {
  1547. lastDate.setTime(sdf.parse(endQuotaDate));
  1548. }
  1549. String firstDay = "";
  1550. String lastDay = "";
  1551. int currentMonth = lastDate.get(Calendar.MONTH) + 1;
  1552. if (currentMonth >= 1 && currentMonth <= 3){
  1553. lastDate.set(Calendar.MONTH, 0);
  1554. }else if (currentMonth >= 4 && currentMonth <= 6){
  1555. lastDate.set(Calendar.MONTH, 3);
  1556. } else if (currentMonth >= 7 && currentMonth <= 9){
  1557. lastDate.set(Calendar.MONTH, 6);
  1558. } else if (currentMonth >= 10 && currentMonth <= 12){
  1559. lastDate.set(Calendar.MONTH, 9);
  1560. }
  1561. lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1562. firstDay = sdf.format(lastDate.getTime());//这个季度第一天
  1563. lastDate.add(Calendar.MONTH, 3);
  1564. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1565. lastDay = sdf.format(lastDate.getTime());//这个季度最后一天
  1566. lastDate.add(Calendar.MONTH, -6);//前一个季度第一天
  1567. lastDate.set(Calendar.DAY_OF_MONTH, 1);
  1568. lastDate.add(Calendar.MONTH, 3);
  1569. String preMonthFirstDay = sdf.format(lastDate.getTime());
  1570. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1571. String preMonthLastDay = sdf.format(lastDate.getTime());
  1572. log.info("firstDay = {}, lastDay = {}", firstDay, lastDay);
  1573. log.info("preMonthFirstDay = {}, preMonthLastDay = {}", preMonthFirstDay, preMonthLastDay);
  1574. molecularFilter = "quotaDate >= '" + firstDay + "' and quotaDate <= '" + lastDay + "'";
  1575. denominatorFilter = "quotaDate >= '" + preMonthFirstDay + "' and quotaDate <= '" + preMonthLastDay + "'";
  1576. }
  1577. if (StringUtils.isNotEmpty(esConfig.getMolecularFilter())) {
  1578. molecularFilter += " and " + esConfig.getMolecularFilter();
  1579. }
  1580. if (StringUtils.isNotEmpty(esConfig.getDenominatorFilter())) {
  1581. denominatorFilter += " and " + esConfig.getDenominatorFilter();
  1582. }
  1583. if(StringUtils.isNotEmpty(noDateFilter)){
  1584. molecularFilter += " and " + noDateFilter;
  1585. denominatorFilter += " and " + noDateFilter;
  1586. }
  1587. List<Map<String, Object>> moleList = getSimpleQuotaReport(esConfig.getMolecular(), molecularFilter,dimension ,false , null);
  1588. List<Map<String, Object>> denoList = getSimpleQuotaReport(esConfig.getDenominator(),denominatorFilter,dimension,false, null);
  1589. resultList = divisionPercent(dimension, moleList, denoList, 1, 100);
  1590. return resultList;
  1591. }else {
  1592. String dateFilter = "";
  1593. //按时间维度 增幅,即时间区间增幅
  1594. int nowYear;
  1595. int beforeYear;
  1596. Date firstMonth = new Date();
  1597. Date endMonth = new Date();
  1598. nowYear = lastDate.get(Calendar.YEAR);
  1599. beforeYear = nowYear - 4;
  1600. if ("1".equals(growthFlag)) { // 年增幅 没有传时间条件默认当前年份 向前推3年
  1601. if (StringUtils.isNotEmpty(startQuotaDate)) {// 外部指定时间
  1602. beforeYear = Integer.parseInt(startQuotaDate.substring(0,4))-1;
  1603. }
  1604. if (StringUtils.isNotEmpty(endQuotaDate)) {// 外部指定时间
  1605. nowYear = Integer.parseInt(endQuotaDate.substring(0,4));
  1606. dateFilter = "quotaDate >= '" + beforeYear + "-01-01' and quotaDate <= '" + nowYear + "-12-31'";
  1607. }
  1608. } else if ("2".equals(growthFlag)) { // 月增幅 没有传时间条件默认当前月份 计算前6个月数据 计算向前推7个月
  1609. lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1610. endMonth =lastDate.getTime();
  1611. lastDate.add(Calendar.MONTH, - 7);
  1612. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1613. firstMonth = lastDate.getTime();
  1614. // 如果有时间过滤条件,则按时间条件计算
  1615. if (StringUtils.isNotEmpty(startQuotaDate)) {
  1616. if (StringUtils.isNotEmpty(startQuotaDate)) {// 外部指定时间
  1617. firstMonth = sdf.parse(startQuotaDate);
  1618. lastDate.setTime(firstMonth);
  1619. lastDate.add(Calendar.MONTH, -1);//向前推一个月 用于计算最后一个月增幅
  1620. firstMonth = lastDate.getTime();
  1621. }
  1622. if (StringUtils.isNotEmpty(endQuotaDate)) {// 外部指定时间
  1623. endMonth = sdf.parse(endQuotaDate);
  1624. }
  1625. }
  1626. dateFilter = "quotaDate >= '" + sdf.format(firstMonth) + "' and quotaDate <= '" + sdf.format(endMonth) + "'";
  1627. }else if ("3".equals(growthFlag)) { // 季度增幅 没有传时间条件默认当前季度,计算查询向前推一个季度
  1628. int currentMonth = lastDate.get(Calendar.MONTH) + 1;
  1629. if (currentMonth >= 1 && currentMonth <= 3){
  1630. lastDate.set(Calendar.MONTH, 0);
  1631. }else if (currentMonth >= 4 && currentMonth <= 6){
  1632. lastDate.set(Calendar.MONTH, 3);
  1633. } else if (currentMonth >= 7 && currentMonth <= 9){
  1634. lastDate.set(Calendar.MONTH, 6);
  1635. } else if (currentMonth >= 10 && currentMonth <= 12){
  1636. lastDate.set(Calendar.MONTH, 9);
  1637. }
  1638. lastDate.set(Calendar.MONTH, 3);//此季度最后一天
  1639. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1640. endMonth =lastDate.getTime();
  1641. lastDate.set(Calendar.MONTH, -6);//向前推一个季度 向前推3个月
  1642. lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1643. firstMonth = lastDate.getTime();
  1644. // 如果有时间过滤条件,则按时间条件计算
  1645. if (StringUtils.isNotEmpty(startQuotaDate)) {
  1646. if (StringUtils.isNotEmpty(startQuotaDate)) {// 外部指定时间
  1647. firstMonth = sdf.parse(startQuotaDate);
  1648. lastDate.setTime(firstMonth);
  1649. lastDate.add(Calendar.MONTH, -3);//向前推一季度 用于计算最后一个季度增幅
  1650. firstMonth = lastDate.getTime();
  1651. }
  1652. if (StringUtils.isNotEmpty(endQuotaDate)) {// 外部指定时间
  1653. endMonth = sdf.parse(endQuotaDate);
  1654. }
  1655. }
  1656. dateFilter = "quotaDate >= '" + sdf.format(firstMonth) + "' and quotaDate <= '" + sdf.format(endMonth) + "'";
  1657. }
  1658. if(StringUtils.isNotEmpty(noDateFilter)){
  1659. filters = dateFilter + " and " + noDateFilter;
  1660. }else{
  1661. filters = dateFilter;
  1662. }
  1663. dimension = dateType;
  1664. List<Map<String, Object>> dataList = getSimpleQuotaReport(esConfig.getMolecular(), filters,dimension ,false , null);
  1665. NumberFormat df = NumberFormat.getInstance();
  1666. df.setGroupingUsed(false);
  1667. df.setMaximumFractionDigits(2);
  1668. if(dataList != null && dataList.size() > 0){
  1669. if(dateType.toLowerCase().equals("year")){
  1670. for(int i = nowYear ; i > beforeYear ;i--){
  1671. double current = 0;
  1672. double last = 0;
  1673. Map<String,Object> map = new HashMap<>();
  1674. map.put(dimension, i);
  1675. for(Map<String,Object> dataMap : dataList){
  1676. int y = Integer.valueOf(dataMap.get(dimension).toString());
  1677. if( y == i ){
  1678. map.put(firstColumnField, dataMap.get(firstColumnField));
  1679. current = Double.valueOf(dataMap.get(resultField).toString());
  1680. }
  1681. if( y == i-1 ){
  1682. last = Double.valueOf(dataMap.get(resultField).toString());
  1683. }
  1684. }
  1685. if(last == 0){
  1686. map.put(resultField,"--");
  1687. }else {
  1688. double precent = (current - last)/last*100;
  1689. map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
  1690. }
  1691. resultList.add(map);
  1692. if(i-beforeYear <= 0){
  1693. break;
  1694. }
  1695. }
  1696. }else if(dateType.toLowerCase().equals("quarter")){
  1697. String startQuarter = "";
  1698. String endQuarter = "";
  1699. lastDate.setTime(firstMonth);
  1700. Date firstDate = lastDate.getTime();
  1701. int currentMonth = lastDate.get(Calendar.MONTH) + 1;
  1702. if (currentMonth >= 1 && currentMonth <= 3){
  1703. startQuarter = sdf.format(firstDate).substring(0,4)+"年1季度";
  1704. }else if (currentMonth >= 4 && currentMonth <= 6){
  1705. startQuarter = sdf.format(firstDate).substring(0,4)+"年2季度";
  1706. } else if (currentMonth >= 7 && currentMonth <= 9){
  1707. startQuarter = sdf.format(firstDate).substring(0,4)+"年3季度";
  1708. } else if (currentMonth >= 10 && currentMonth <= 12){
  1709. startQuarter = sdf.format(firstDate).substring(0,4)+"年4季度";
  1710. }
  1711. lastDate.setTime(endMonth);
  1712. Date downDate = lastDate.getTime();
  1713. if (currentMonth >= 1 && currentMonth <= 3){
  1714. endQuarter = sdf.format(downDate).substring(0,4)+"年1季度";
  1715. }else if (currentMonth >= 4 && currentMonth <= 6){
  1716. endQuarter = sdf.format(downDate).substring(0,4)+"年2季度";
  1717. } else if (currentMonth >= 7 && currentMonth <= 9){
  1718. endQuarter = sdf.format(downDate).substring(0,4)+"年3季度";
  1719. } else if (currentMonth >= 10 && currentMonth <= 12){
  1720. endQuarter = sdf.format(downDate).substring(0,4)+"年4季度";
  1721. }
  1722. String lastQuarter = "";
  1723. while ( !startQuarter.equals(lastQuarter)){
  1724. int eYear = Integer.valueOf(endQuarter.substring(0, 4));
  1725. int eQuarter = Integer.valueOf(endQuarter.substring(5, 6));
  1726. endQuarter = eYear+ "年" + eQuarter + "季度";
  1727. if( !endQuarter.equals(startQuarter)){
  1728. if(eQuarter == 1){
  1729. eYear--;
  1730. eQuarter = 4;
  1731. }else {
  1732. eQuarter--;
  1733. }
  1734. }
  1735. lastQuarter = eYear + "年" + eQuarter + "季度";
  1736. double current = 0;
  1737. double last = 0;
  1738. Map<String,Object> map = new HashMap<>();
  1739. for(Map<String,Object> dataMap : dataList){
  1740. if(dataMap.get(dimension) != null){
  1741. String val = dataMap.get(dimension).toString();
  1742. if(val.equals(endQuarter) ){
  1743. map.put(firstColumnField, endQuarter);
  1744. map.put(dimension, endQuarter);
  1745. current = Double.valueOf(dataMap.get(resultField).toString());
  1746. }
  1747. if(val.equals(lastQuarter) ){
  1748. last = Double.valueOf(dataMap.get(resultField).toString());
  1749. }
  1750. }
  1751. }
  1752. if(last == 0){
  1753. map.put(resultField,"--");
  1754. }else {
  1755. double precent = (current - last)/last*100;
  1756. if(precent == 0){
  1757. map.put(resultField,0);
  1758. }else {
  1759. map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
  1760. }
  1761. }
  1762. resultList.add(map);
  1763. endQuarter = lastQuarter;
  1764. }
  1765. }else if(dateType.toLowerCase().equals("month")){
  1766. String starthMonthStr = sdf.format(firstMonth).substring(0,7);
  1767. String endMonthStr = sdf.format(endMonth).substring(0,7);
  1768. while ( !starthMonthStr.equals(endMonthStr)){
  1769. double current = 0;
  1770. double last = 0;
  1771. Map<String,Object> map = new HashMap<>();
  1772. String nowMonthStr = endMonthStr;
  1773. String lastMontStr = "";
  1774. if( !starthMonthStr.equals(endMonthStr)){
  1775. Calendar calendar = Calendar.getInstance();
  1776. calendar.setTime(sdf.parse(endMonthStr + "-01"));
  1777. calendar.add(Calendar.MONTH, -1);//当前时间前去一个月,即一个月前的时间
  1778. lastMontStr = sdf.format(calendar.getTime()).substring(0,7);
  1779. }else {
  1780. lastMontStr = starthMonthStr;
  1781. }
  1782. for(Map<String,Object> dataMap : dataList){
  1783. if(dataMap.get(dimension) != null){
  1784. String val = dataMap.get(dimension).toString();
  1785. if(val.equals(nowMonthStr) ){
  1786. map.put(firstColumnField, val);
  1787. map.put(dimension, val);
  1788. current = Double.valueOf(dataMap.get(resultField).toString());
  1789. }
  1790. if(val.equals(lastMontStr) ){
  1791. last = Double.valueOf(dataMap.get(resultField).toString());
  1792. }
  1793. }
  1794. }
  1795. if(last == 0){
  1796. map.put(resultField,"--");
  1797. }else {
  1798. double precent = (current - last)/last*100;
  1799. if(precent == 0){
  1800. map.put(resultField,0);
  1801. }else {
  1802. map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
  1803. }
  1804. }
  1805. resultList.add(map);
  1806. endMonthStr = lastMontStr;
  1807. }
  1808. }
  1809. }
  1810. if(resultList != null ){
  1811. Collections.reverse(resultList); // 倒序排列
  1812. }
  1813. return resultList;
  1814. }
  1815. }
  1816. public String filtersExchangeHandle(String filters, EsConfig esConfig) {
  1817. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1818. Calendar lastDate = Calendar.getInstance();
  1819. lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1820. String firstDay = sdf.format(lastDate.getTime());
  1821. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1822. String lastDay = sdf.format(lastDate.getTime());
  1823. lastDate.add(Calendar.MONTH, -1);
  1824. lastDate.set(Calendar.DAY_OF_MONTH, 1);
  1825. String preMonthFirstDay = sdf.format(lastDate.getTime());
  1826. lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
  1827. String preMonthLastDay = sdf.format(lastDate.getTime());
  1828. // 如果有时间过滤条件,则按时间条件计算
  1829. if (StringUtils.isNotEmpty(filters) && filters.contains(quotaDateField)) {
  1830. Calendar cal = Calendar.getInstance();
  1831. boolean b = filters.indexOf("'") > -1;
  1832. int start = b ? filters.indexOf("'") : filters.indexOf("\"");
  1833. String condition = filters.substring(start + 1, start + 5); // 获取年份
  1834. int year = Integer.parseInt(condition);
  1835. String condition2 = filters.substring(filters.indexOf("-") + 1, filters.indexOf("-") + 3); // 获取月份
  1836. int month = Integer.parseInt(condition2);
  1837. cal.set(Calendar.YEAR, year);
  1838. cal.set(Calendar.MONTH, month - 1);
  1839. cal.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
  1840. firstDay = sdf.format(cal.getTime());
  1841. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
  1842. lastDay = sdf.format(cal.getTime());
  1843. cal.add(Calendar.MONTH, -1);
  1844. cal.set(Calendar.DAY_OF_MONTH, 1);
  1845. preMonthFirstDay = sdf.format(cal.getTime());
  1846. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
  1847. preMonthLastDay = sdf.format(cal.getTime());
  1848. }
  1849. if ("1".equals(esConfig.getIncrementFlag())) {
  1850. // 上月
  1851. filters = "quotaDate >= '" + preMonthFirstDay + "' and quotaDate <= '" + preMonthLastDay + "'";
  1852. } else if ("2".equals(esConfig.getIncrementFlag())) {
  1853. // 当前月
  1854. filters = "quotaDate >= '" + firstDay + "' and quotaDate <= '" + lastDay + "'";
  1855. }
  1856. if (StringUtils.isNotEmpty(esConfig.getFilter())) {
  1857. filters += " and " + esConfig.getFilter();
  1858. }
  1859. return filters;
  1860. }
  1861. }