QuotaReportController.java 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. package com.yihu.quota.controller;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.github.abel533.echarts.Option;
  5. import com.yihu.ehr.constants.ApiVersion;
  6. import com.yihu.ehr.constants.ServiceApi;
  7. import com.yihu.ehr.model.echarts.ChartDataModel;
  8. import com.yihu.ehr.model.report.MQcDevice;
  9. import com.yihu.ehr.model.resource.MChartInfoModel;
  10. import com.yihu.ehr.model.resource.MRsResources;
  11. import com.yihu.ehr.query.common.model.DataList;
  12. import com.yihu.ehr.util.rest.Envelop;
  13. import com.yihu.quota.model.RsResourceQuota;
  14. import com.yihu.quota.model.TjQuota;
  15. import com.yihu.quota.model.dimension.TjQuotaDimensionMain;
  16. import com.yihu.quota.model.dimension.TjQuotaDimensionSlave;
  17. import com.yihu.quota.service.dimension.TjDimensionMainService;
  18. import com.yihu.quota.service.dimension.TjDimensionSlaveService;
  19. import com.yihu.quota.service.special.org.OrgHealthCategoryStatisticsService;
  20. import com.yihu.quota.service.quota.BaseStatistsService;
  21. import com.yihu.quota.service.quota.DeviceService;
  22. import com.yihu.quota.service.quota.QuotaService;
  23. import com.yihu.quota.service.resource.ResourceQuotaService;
  24. import com.yihu.quota.util.BasesicUtil;
  25. import com.yihu.quota.util.ReportOption;
  26. import com.yihu.quota.vo.DictModel;
  27. import com.yihu.quota.vo.SaveModel;
  28. import io.swagger.annotations.Api;
  29. import io.swagger.annotations.ApiOperation;
  30. import io.swagger.annotations.ApiParam;
  31. import org.apache.commons.lang.StringUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  34. import org.springframework.jdbc.core.JdbcTemplate;
  35. import org.springframework.web.bind.annotation.RequestMapping;
  36. import org.springframework.web.bind.annotation.RequestMethod;
  37. import org.springframework.web.bind.annotation.RequestParam;
  38. import org.springframework.web.bind.annotation.RestController;
  39. import java.text.NumberFormat;
  40. import java.text.SimpleDateFormat;
  41. import java.util.*;
  42. /**
  43. * @author janseny
  44. */
  45. @RestController
  46. @RequestMapping(ApiVersion.Version1_0)
  47. @Api(description = "指标报表统计 -指标报表统计控制入口")
  48. public class QuotaReportController extends BaseController {
  49. @Autowired
  50. private ObjectMapper objectMapper;
  51. @Autowired
  52. private TjDimensionMainService tjDimensionMainService;
  53. @Autowired
  54. private TjDimensionSlaveService tjDimensionSlaveService;
  55. @Autowired
  56. private QuotaService quotaService;
  57. @Autowired
  58. private JdbcTemplate jdbcTemplate;
  59. @Autowired
  60. private ResourceQuotaService resourceQuotaService;
  61. @Autowired
  62. private OrgHealthCategoryStatisticsService orgHealthCategoryStatisticsService;
  63. @Autowired
  64. private BaseStatistsService baseStatistsService;
  65. @Autowired
  66. private DeviceService deviceService;
  67. public static String orgHealthCategoryCode = "orgHealthCategoryCode";
  68. @RequestMapping(value = ServiceApi.TJ.GetYearDropdownList, method = RequestMethod.GET)
  69. @ApiOperation(value = "获取二维表查询年份下拉数据")
  70. public Envelop getDropdownList(
  71. @ApiParam(name = "type", value = "类型 1增量型报表 2 全量型报表")
  72. @RequestParam(value = "type" ,required = true ) int type,
  73. @ApiParam(name = "index", value = "索引")
  74. @RequestParam(value = "index" ,required = true ) String index) throws Exception {
  75. Envelop envelop = new Envelop();
  76. Map<String, List<String>> map = null;
  77. String sql = "select count(1) from "+ index +" group by date_histogram(field='quotaDate','interval'='year') order by quotaDate desc";
  78. map = baseStatistsService.getDataInfo(sql, "date_histogram(field=quotaDate,interval=year)");
  79. if (null != map && map.size() > 0) {
  80. Collections.sort(map.get("xData"), Collections.reverseOrder());
  81. if(type == 1){
  82. envelop.setObj(map.get("xData"));
  83. }else {
  84. Map<String,String> resultMap = new HashMap<>();
  85. for(String key : map.get("xData")){
  86. String filter = "quotaDate >= '" + key + "-01-01'" + " and quotaDate <= '" + key +"-12-31'";
  87. sql = "select count(1) from "+ index +" where " + filter + " group by date_histogram(field='quotaDate','interval'='month') order by quotaDate desc";
  88. System.out.println(sql);
  89. Map<String, List<String>> monthMap = baseStatistsService.getDataInfo(sql, "date_histogram(field=quotaDate,interval=month)");
  90. if(monthMap != null && monthMap.size() > 0){
  91. resultMap.put(key,monthMap.get("xData").get(0).toString());
  92. }
  93. }
  94. envelop.setObj(resultMap);
  95. }
  96. }
  97. envelop.setSuccessFlg(true);
  98. return envelop;
  99. }
  100. /**
  101. * 获取指标统计结果
  102. *
  103. * @param id
  104. * @return
  105. */
  106. @ApiOperation(value = "获取指标统计结果")
  107. @RequestMapping(value = ServiceApi.TJ.GetQuotaReport, method = RequestMethod.GET)
  108. public Envelop getQuotaReport(
  109. @ApiParam(name = "id", value = "指标任务ID", required = true)
  110. @RequestParam(value = "id", required = true) int id,
  111. @ApiParam(name = "filters", value = "检索条件", defaultValue = "")
  112. @RequestParam(value = "filters", required = false) String filters,
  113. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  114. @RequestParam(value = "dimension", required = false) String dimension
  115. ) {
  116. Envelop envelop = new Envelop();
  117. try {
  118. //To DO
  119. envelop.setSuccessFlg(true);
  120. return envelop;
  121. } catch (Exception e) {
  122. error(e);
  123. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  124. }
  125. envelop.setSuccessFlg(false);
  126. return envelop;
  127. }
  128. @ApiOperation(value = "获取统计报表一个视图下多个指标组合 二维表数据")
  129. @RequestMapping(value = ServiceApi.TJ.GetQuotaReportTwoDimensionalTable, method = RequestMethod.GET)
  130. public List<Map<String, Object>> getQuotaReportTwoDimensionalTable(
  131. @ApiParam(name = "quotaCodeStr", value = "指标Code,多个用,拼接", required = true)
  132. @RequestParam(value = "quotaCodeStr", required = true) String quotaCodeStr,
  133. @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  134. @RequestParam(value = "filter", required = false) String filter,
  135. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  136. @RequestParam(value = "dimension", required = false) String dimension,
  137. @ApiParam(name = "top", value = "获取前几条数据")
  138. @RequestParam(value = "top", required = false) String top
  139. ) {
  140. NumberFormat nf = NumberFormat.getInstance();
  141. nf.setGroupingUsed(false);
  142. nf.setMaximumFractionDigits(2);
  143. List<Map<String, Object>> dataList = new ArrayList<>();
  144. Map<String, List<Map<String, Object>>> quotaViewResult = new HashMap<>();
  145. List<String> quotaCodes = Arrays.asList(quotaCodeStr.split(","));
  146. String maxQuotaCode = "";
  147. int num = 0;
  148. try {
  149. for (String code : quotaCodes) {
  150. List<Map<String, Object>> quotaResult = baseStatistsService.getSimpleQuotaReport(code, filter, dimension,false, top);
  151. if (quotaResult.size() >= num) {
  152. num = quotaResult.size();
  153. maxQuotaCode = code;
  154. }
  155. quotaViewResult.put(code, quotaResult);
  156. }
  157. Map<String, List<Map<String, Object>>> otherQuotaViewResult = new HashMap<>();
  158. for (String key : quotaViewResult.keySet()) {
  159. if (key != maxQuotaCode) {
  160. otherQuotaViewResult.put(key, quotaViewResult.get(key));
  161. }
  162. }
  163. //以查询结果数据最多的指标为主,其他指标对应维度没有数据的补充0
  164. for (Map<String, Object> vMap : quotaViewResult.get(maxQuotaCode)) {
  165. vMap.put(maxQuotaCode, vMap.get("result")==null ? 0 : ("--".equals(vMap.get("result")) ? vMap.get("result") : nf.format(Double.valueOf(vMap.get("result").toString()))));
  166. for (String viewQuotaCode : otherQuotaViewResult.keySet()) {
  167. if(otherQuotaViewResult != null && otherQuotaViewResult.get(viewQuotaCode) != null && otherQuotaViewResult.get(viewQuotaCode).size()>0 ){
  168. for (Map<String, Object> quotaResultMap : otherQuotaViewResult.get(viewQuotaCode)) {
  169. if (quotaResultMap.get(dimension) != null && vMap.get(dimension) != null ) {
  170. if (vMap.get(dimension).toString().trim().equals(quotaResultMap.get(dimension).toString().trim())) {
  171. vMap.put(viewQuotaCode, quotaResultMap.get("result")==null ? 0 : ("--".equals(quotaResultMap.get("result")) ? quotaResultMap.get("result") : nf.format(Double.valueOf(quotaResultMap.get("result").toString()))));
  172. break;
  173. } else {
  174. if( !vMap.get(dimension).toString().equals("合计")){
  175. vMap.put(viewQuotaCode, 0);
  176. }
  177. }
  178. } else {
  179. vMap.put(viewQuotaCode, 0);
  180. }
  181. }
  182. }else {
  183. vMap.put(viewQuotaCode, 0);
  184. }
  185. }
  186. }
  187. List<Map<String, Object>> resultList = quotaViewResult.get(maxQuotaCode);
  188. if(dimension.equals(orgHealthCategoryCode)){//如果是特殊机构类型树状机构需要转成树状结构
  189. List<Map<String, Object>> orgHealthCategoryList = orgHealthCategoryStatisticsService.getOrgHealthCategoryTreeByPid(-1);
  190. // dataList = baseStatistsService.setResultAllDimenMap(maxQuotaCode, orgHealthCategoryList, resultList,null);
  191. //采用新的
  192. dataList = baseStatistsService.allCategoryResultMap(quotaCodes, orgHealthCategoryList, resultList);
  193. }else {
  194. dataList = resultList;
  195. }
  196. } catch (Exception e) {
  197. e.printStackTrace();
  198. }
  199. for(Map<String, Object> map : dataList){
  200. if(map.get("firstColumn") == null || map.get("firstColumn").toString().equals("null") || StringUtils.isEmpty(map.get("firstColumn").toString())){
  201. if(map.get("level")!= null && StringUtils.isNotEmpty(map.get("level").toString())){
  202. String level = map.get("level").toString();
  203. if (level.equals("1")){
  204. level = "一级";
  205. }else if (level.equals("2")){
  206. level = "二级";
  207. }else if (level.equals("3")){
  208. level = "三级";
  209. }else {
  210. level = "未指定";
  211. }
  212. map.put("firstColumn",level);
  213. }
  214. if(map.get("economic")!= null && StringUtils.isNotEmpty(map.get("economic").toString())){
  215. String economic = map.get("economic").toString();
  216. if (economic.equals("1021")){
  217. economic = "公立";
  218. }else if (economic.equals("1022")){
  219. economic = "非公立";
  220. }else {
  221. economic = "其他";
  222. }
  223. map.put("firstColumn",economic);
  224. }
  225. }
  226. }
  227. //计算合计
  228. if(dataList != null && dataList.size() > 0){
  229. Map<String, Object> sumMap = new HashMap<>();
  230. sumMap.put("firstColumn","合计");
  231. for (String code : quotaCodes) {
  232. String total = existsTotal(code,dataList);
  233. if( total.equals("false") || total.equals("--")){
  234. double sum = 0;
  235. sum = calculateSum(sum,code,dataList);
  236. sumMap.put(code, nf.format(sum));
  237. }else {
  238. sumMap.put(code, nf.format(Double.valueOf(total)));
  239. }
  240. }
  241. dataList.add(0,sumMap);
  242. if(dataList.get(dataList.size()-1).get("firstColumn") != null){
  243. if(dataList.get(dataList.size()-1).get("firstColumn").equals("合计")){
  244. dataList.remove(dataList.size()-1);
  245. }
  246. }
  247. }
  248. return dataList;
  249. }
  250. /**
  251. * 判断指标统计中 总计 是否已经计算过
  252. * @param code
  253. * @param dataList
  254. * @return
  255. */
  256. private String existsTotal(String code,List<Map<String, Object>> dataList){
  257. for(Map<String, Object> map : dataList){
  258. if(map.get("firstColumn") != null && map.get("firstColumn").toString().equals("合计") && map.get(code) != null){
  259. if(map.get(code).toString().equals("--")){
  260. return "false";
  261. }else {
  262. return map.get(code).toString();
  263. }
  264. }
  265. }
  266. return "false";
  267. }
  268. /**
  269. * 统计每列合计
  270. * @param sum
  271. * @param code
  272. * @param dataList
  273. * @return
  274. */
  275. private double calculateSum( double sum,String code,List<Map<String, Object>> dataList){
  276. for(Map<String, Object> map : dataList){
  277. if(map.get(code) != null){
  278. sum += Double.valueOf("--".equals(map.get(code)) ? "0" : map.get(code).toString());
  279. }
  280. }
  281. return sum;
  282. }
  283. @ApiOperation(value = "获取指标统计结果echart图表,支持多条组合")
  284. @RequestMapping(value = ServiceApi.TJ.GetMoreQuotaGraphicReportPreviews, method = RequestMethod.GET)
  285. public MChartInfoModel getQuotaGraphicReports(
  286. @ApiParam(name = "quotaIdStr", value = "指标ID,多个用,拼接", required = true)
  287. @RequestParam(value = "quotaIdStr" , required = true) String quotaIdStr,
  288. @ApiParam(name = "charstr", value = "多图表类型用,拼接,混合类型只支持柱状和线性", defaultValue = "1")
  289. @RequestParam(value = "charstr", required = true) String charstr,
  290. @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  291. @RequestParam(value = "filter", required = false) String filter,
  292. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  293. @RequestParam(value = "dimension", required = false) String dimension,
  294. @ApiParam(name = "title", value = "视图名称", defaultValue = "")
  295. @RequestParam(value = "title", required = false) String title,
  296. @ApiParam(name = "top", value = "获取前几条数据")
  297. @RequestParam(value = "top", required = false) String top,
  298. @ApiParam(name = "MRsResource json串")
  299. @RequestParam(value = "mRsResource", required = false) String mRsResource
  300. ) {
  301. String xName = "";
  302. String yName = "";
  303. List<String> quotaIds = Arrays.asList(quotaIdStr.split(","));
  304. List<String> charTypes = Arrays.asList(charstr.split(","));
  305. MChartInfoModel chartInfoModel = new MChartInfoModel();
  306. String dimensionName = dimension + "Name";
  307. if ("quotaName".equals(dimension)) {
  308. dimensionName = "quotaName";
  309. }
  310. try {
  311. Option option = null;
  312. List<List<Object>> optionData = new ArrayList<>();
  313. List<String> lineNames = new ArrayList<>();
  314. Map<String, Map<String, Object>> lineData = new LinkedHashMap<>();
  315. Map<String, String> xAxisMap = new LinkedHashMap<>();
  316. Integer i = 0;
  317. List<Map<String, Object>> listMap = new ArrayList<>();
  318. for (String quotaId : quotaIds) {
  319. Map<String, Object> dataMap = new LinkedHashMap<>();
  320. TjQuota tjQuota = quotaService.findOne(Integer.valueOf(quotaId));
  321. if (tjQuota != null) {
  322. List<Map<String, Object>> resultListMap = baseStatistsService.getSimpleQuotaReport(tjQuota.getCode(), filter, dimension,true, top);
  323. if (resultListMap != null && resultListMap.size() > 0) {
  324. for (Map<String, Object> map : resultListMap) {
  325. if (map != null && map.size() > 0) {
  326. if (map.containsKey("quotaName")) {
  327. map.put("quotaName",tjQuota.getName());
  328. }
  329. listMap.add(map);
  330. //第一种 ES库中有定义的维度 如org,slaveKey1
  331. //第二种 ES库中未定义的维度 如level,economic
  332. if (map.containsKey(dimensionName)) {
  333. if(map.get(dimensionName) != null){
  334. dataMap.put(map.get(dimensionName).toString(), map.get("result"));
  335. xAxisMap.put(map.get(dimensionName).toString(), map.get(dimension).toString());
  336. }
  337. } else {
  338. if(map.get(dimension) != null){
  339. dataMap.put(map.get(dimension).toString(), map.get("result"));
  340. xAxisMap.put(map.get(dimension).toString(), map.get(dimension).toString());
  341. }
  342. }
  343. }
  344. }
  345. }
  346. lineData.put("" + i, dataMap);
  347. lineNames.add(tjQuota.getName());
  348. i++;
  349. }
  350. }
  351. // lineNames.add(title);
  352. // lineData.put("", dataMap);
  353. Map<String, Object> quotaMap = new LinkedHashMap<>();
  354. ReportOption reportOption = new ReportOption();
  355. int size = 0;
  356. String quota = "0";
  357. if (lineData != null && lineData.size() > 0) {
  358. for (String key : lineData.keySet()) {
  359. int tempSize = lineData.get(key).size();
  360. if (tempSize > size) {
  361. size = tempSize;
  362. quota = key;
  363. quotaMap = lineData.get(key);
  364. }
  365. }
  366. for (String key : lineData.keySet()) {
  367. List<Object> dataList = new ArrayList<>();
  368. Map<String, Object> valMap = lineData.get(key);
  369. if (key != quota) {
  370. for (String name : quotaMap.keySet()) {
  371. if (valMap.containsKey(name)) {
  372. dataList.add(valMap.get(name));
  373. } else {
  374. dataList.add(0);
  375. }
  376. }
  377. } else {
  378. for (String name : valMap.keySet()) {
  379. dataList.add(valMap.get(name));
  380. }
  381. }
  382. optionData.add(dataList);
  383. }
  384. }
  385. Object[] xData = (Object[]) quotaMap.keySet().toArray(new Object[quotaMap.size()]);
  386. for (String typeStr : charTypes) {
  387. if (typeStr.equals("common")) {
  388. typeStr = "1";
  389. } else if (typeStr.equals("twoDimensional")) { // 这个需要与前端商榷 访问2次(二维表类型)
  390. return null;
  391. }
  392. int type = Integer.valueOf(typeStr);
  393. String dataMeasurement = "";
  394. if (StringUtils.isNotEmpty(mRsResource)) {
  395. MRsResources mRsResources = objectMapper.readValue(mRsResource, MRsResources.class);
  396. dataMeasurement = mRsResources.getDataMeasurement();
  397. String dataPosition = mRsResources.getDataPosition();
  398. if (StringUtils.isNotEmpty(dataPosition) && "x".equalsIgnoreCase(dataPosition)) {
  399. xName = "单位:" + mRsResources.getDataUnit();
  400. } else if (StringUtils.isNotEmpty(dataPosition) && "y".equalsIgnoreCase(dataPosition)) {
  401. yName = "单位:" + mRsResources.getDataUnit();
  402. }
  403. }
  404. if (type == ReportOption.bar) {
  405. option = reportOption.getLineEchartOptionMoreChart(title, xName, yName, xData, discountByMeasurement(optionData, dataMeasurement), lineNames, charTypes);
  406. } else if (type == ReportOption.line) {
  407. option = reportOption.getLineEchartOptionMoreChart(title, xName, yName, xData, discountByMeasurement(optionData, dataMeasurement), lineNames, charTypes);
  408. } else if (type == ReportOption.pie) {
  409. List<Map<String, Object>> datalist = new ArrayList<>();
  410. for (Map<String, Object> resultMap : listMap) {
  411. Map<String, Object> map = new HashMap<>();
  412. map.put("NAME", null == resultMap.get(dimensionName) ? resultMap.get(dimension) : resultMap.get(dimensionName));
  413. map.put("TOTAL", resultMap.get("result"));
  414. if(resultMap.get(dimensionName) != null){
  415. map.put("NAME",resultMap.get(dimensionName));
  416. }else {
  417. //非 指标中配置的维度 关联出来的字段
  418. if(dimensionName.equals("levelName")){
  419. if(resultMap.get(dimension).equals("1")){
  420. map.put("NAME","一级医院");
  421. }else if(resultMap.get(dimension).equals("2")){
  422. map.put("NAME","二级医院");
  423. }else if(resultMap.get(dimension).equals("3")){
  424. map.put("NAME","三级医院");
  425. }
  426. }
  427. }
  428. map.put("TOTAL",resultMap.get("result"));
  429. datalist.add(map);
  430. }
  431. option = reportOption.getPieEchartOption(title, "", "", datalist, lineNames.get(0), null);
  432. }
  433. }
  434. chartInfoModel.setOption(option.toString());
  435. chartInfoModel.setTitle(title);
  436. chartInfoModel.setxAxisMap(xAxisMap);
  437. return chartInfoModel;
  438. } catch (Exception e) {
  439. error(e);
  440. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  441. return null;
  442. }
  443. }
  444. // @ApiOperation(value = "获取指标统计结果echart图表,支持多条组合")
  445. // @RequestMapping(value = ServiceApi.TJ.GetMoreQuotaGraphicReportPreviews, method = RequestMethod.GET)
  446. // public MChartInfoModel getQuotaGraphicReports(
  447. // @ApiParam(name = "quotaIdStr", value = "指标ID,多个用,拼接", required = true)
  448. // @RequestParam(value = "quotaIdStr" , required = true) String quotaIdStr,
  449. // @ApiParam(name = "charstr", value = "多图表类型用,拼接,混合类型只支持柱状和线性", defaultValue = "1")
  450. // @RequestParam(value = "charstr" , required = true) String charstr,
  451. // @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  452. // @RequestParam(value = "filter", required = false) String filter,
  453. // @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  454. // @RequestParam(value = "dimension", required = false) String dimension,
  455. // @ApiParam(name = "title", value = "视图名称", defaultValue = "")
  456. // @RequestParam(value = "title", required = false) String title
  457. // ) {
  458. // List<String> quotaIds = Arrays.asList(quotaIdStr.split(","));
  459. // List<String> charTypes = Arrays.asList(charstr.split(","));
  460. // MChartInfoModel chartInfoModel = new MChartInfoModel();
  461. // try {
  462. // Option option = null;
  463. // List<List<Object>> optionData = new ArrayList<>();
  464. // List<String> lineNames = new ArrayList<>();
  465. // Map<String,Map<String, Object>> lineData = new LinkedHashMap<>();
  466. // Map<String, String> xAxisMap = new LinkedHashMap<>();
  467. // for(String quotaId:quotaIds){
  468. // Map<String, Object> dataMap = new LinkedHashMap<>();
  469. // TjQuota tjQuota = quotaService.findOne(Integer.valueOf(quotaId));
  470. // if(tjQuota != null){
  471. // String dictSql = getQuotaDimensionDictSql(tjQuota.getCode(),dimension);
  472. // Map<String,String> dimensionDicMap = new HashMap<>();
  473. // if(StringUtils.isNotEmpty(dictSql)){
  474. // BasesicUtil baseUtil = new BasesicUtil();
  475. // if(dimension.contains("slaveKey")){
  476. // //查询字典数据
  477. // List<DictModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(DictModel.class));
  478. // for (DictModel dictModel : dictDatas) {
  479. // String name = baseUtil.getFieldValueByName("name", dictModel);
  480. // String val = baseUtil.getFieldValueByName("code", dictModel).toLowerCase();
  481. // dimensionDicMap.put(val,name);
  482. // }
  483. // } else{
  484. // List<SaveModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(SaveModel.class));
  485. // if(dictDatas != null ) {
  486. // for (SaveModel saveModel : dictDatas) {
  487. // String name = baseUtil.getFieldValueByName(dimension + "Name", saveModel);
  488. // String val = baseUtil.getFieldValueByName(dimension,saveModel).toLowerCase();
  489. // dimensionDicMap.put(val,name);
  490. // }
  491. // }
  492. // }
  493. // }
  494. //
  495. // Map<String, Object> groupDataMap = new HashMap<>();
  496. // if(tjQuota.getResultGetType().trim().equals("1")){
  497. // //使用分组计算 返回结果实例: groupDataMap -> "4205000000-儿-1": 200 =>group by 三个字段
  498. // Map<String, Integer> resultDataMap = quotaService.searcherSumByGroupBySql(tjQuota, dimension, filter,"result","","");
  499. // for(String key: resultDataMap.keySet()){
  500. // groupDataMap.put(key,resultDataMap.get(key));
  501. // }
  502. // }else{//二次统计指标获取 结果接口
  503. // List<Map<String, Object>> listMap = baseStatistsService.getSimpleQuotaReport(tjQuota.getCode(), filter, dimension);
  504. // if(listMap != null && listMap.size() > 0){
  505. // for(Map<String, Object> map : listMap){
  506. // String keyName = "";
  507. // String val = "";
  508. // for (String key : map.keySet()) {
  509. // if ("result".equals(key)) {
  510. // val = map.get(key).toString();
  511. // } else {
  512. // keyName = map.get(key).toString();
  513. // }
  514. // }
  515. // groupDataMap.put(keyName, val);
  516. // }
  517. // }
  518. //
  519. // }
  520. //
  521. // for(String key : groupDataMap.keySet()){
  522. // key = key.toLowerCase();
  523. // dataMap.put(dimensionDicMap.containsKey(key)?dimensionDicMap.get(key):key,groupDataMap.get(key));
  524. // xAxisMap.put(dimensionDicMap.containsKey(key)?dimensionDicMap.get(key): key,key);
  525. // }
  526. // lineNames.add(tjQuota.getName());
  527. // lineData.put(tjQuota.getCode(), dataMap);
  528. // }
  529. // }
  530. // Map<String, Object> quotaMap = new LinkedHashMap<>();
  531. // ReportOption reportOption = new ReportOption();
  532. //
  533. // int size = 0;
  534. // String quota = "";
  535. // if(lineData != null && lineData.size() > 0){
  536. // for(String key : lineData.keySet()){
  537. // int tempSize = lineData.get(key).size();
  538. // if (tempSize > size){
  539. // size = tempSize;
  540. // quota = key;
  541. // quotaMap = lineData.get(key);
  542. // }
  543. // }
  544. // for(String key : lineData.keySet()){
  545. // List<Object> dataList = new ArrayList<>();
  546. // Map<String,Object> valMap = lineData.get(key);
  547. // if(key != quota){
  548. // for(String name :quotaMap .keySet()){
  549. // if(valMap.containsKey(name)){
  550. // dataList.add(valMap.get(name));
  551. // }else {
  552. // dataList.add(0);
  553. // }
  554. // }
  555. // }else{
  556. // for(String name :valMap .keySet()){
  557. // dataList.add(valMap.get(name));
  558. // }
  559. // }
  560. // optionData.add(dataList);
  561. // }
  562. // }
  563. // Object[] xData = (Object[])quotaMap.keySet().toArray(new Object[quotaMap.size()]);
  564. // option = reportOption.getLineEchartOptionMoreChart(title, "", "", xData, optionData, lineNames,charTypes);
  565. // chartInfoModel.setOption(option.toString());
  566. // chartInfoModel.setTitle(title);
  567. // chartInfoModel.setxAxisMap(xAxisMap);
  568. // return chartInfoModel;
  569. // } catch (Exception e) {
  570. // error(e);
  571. // invalidUserException(e, -1, "查询失败:" + e.getMessage());
  572. // return null;
  573. // }
  574. // }
  575. @ApiOperation(value = "指标统计分组查询")
  576. @RequestMapping(value = ServiceApi.TJ.GetQuotaGroupBy, method = RequestMethod.GET)
  577. public Envelop getQuotaGroupBy(
  578. @ApiParam(name = "id", value = "指标任务ID", required = true)
  579. @RequestParam(value = "id", required = true) int id,
  580. @ApiParam(name = "filters", value = "检索条件", defaultValue = "")
  581. @RequestParam(value = "filters", required = false) String filters,
  582. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  583. @RequestParam(value = "dimension", required = false) String dimension
  584. ) {
  585. Envelop envelop = new Envelop();
  586. try {
  587. TjQuota tjQuota = quotaService.findOne(id);
  588. Map<String, Integer> resultMap = quotaService.searcherSumByGroupBySql(tjQuota,dimension, filters,"result","","");
  589. envelop.setSuccessFlg(true);
  590. envelop.setObj(resultMap);
  591. return envelop;
  592. } catch (Exception e) {
  593. error(e);
  594. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  595. }
  596. envelop.setSuccessFlg(false);
  597. return envelop;
  598. }
  599. private String getQuotaDimensionDictSql(String quotaCode, String dimension) {
  600. String dictSql = "";
  601. //查询维度
  602. List<TjQuotaDimensionMain> dimensionMains = tjDimensionMainService.findTjQuotaDimensionMainByQuotaCode(quotaCode);
  603. if (dimensionMains != null && dimensionMains.size() > 0) {
  604. for (TjQuotaDimensionMain main : dimensionMains) {
  605. if (main.getMainCode().equals(dimension)) {
  606. dictSql = main.getDictSql();
  607. }
  608. }
  609. }
  610. if (StringUtils.isEmpty(dictSql)) {
  611. List<TjQuotaDimensionSlave> dimensionSlaves = tjDimensionSlaveService.findTjQuotaDimensionSlaveByQuotaCode(quotaCode);
  612. if (dimensionSlaves != null && dimensionSlaves.size() > 0) {
  613. int slave = Integer.valueOf(dimension.substring(dimension.length() - 1, dimension.length()));
  614. if (dimensionSlaves.size() >= slave) {
  615. dictSql = dimensionSlaves.get(slave - 1).getDictSql();
  616. }
  617. }
  618. }
  619. return dictSql;
  620. }
  621. @ApiOperation(value = "获取指标统计结果echart radar雷达图表")
  622. @RequestMapping(value = ServiceApi.TJ.GetQuotaRadarGraphicReportPreviews, method = RequestMethod.GET)
  623. public MChartInfoModel getQuotaRadarGraphicReports(
  624. @ApiParam(name = "quotaIdStr", value = "指标ID,多个用,拼接", required = true)
  625. @RequestParam(value = "quotaIdStr", required = true) String quotaIdStr,
  626. @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  627. @RequestParam(value = "filter", required = false) String filter,
  628. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "")
  629. @RequestParam(value = "dimension", required = false) String dimension,
  630. @ApiParam(name = "title", value = "名称", defaultValue = "")
  631. @RequestParam(value = "title", required = false) String title) {
  632. List<String> quotaIds = Arrays.asList(quotaIdStr.split(","));
  633. MChartInfoModel chartInfoModel = new MChartInfoModel();
  634. List<Integer> arrayNum = new ArrayList<>();
  635. Integer polorCount = 50;
  636. try {
  637. Option option = null;
  638. List<String> radarNames = new ArrayList<>();
  639. Map<String, Map<String, Object>> radarData = new HashMap<>();
  640. List<Map<String, Object>> listData = new ArrayList<>();
  641. Map<String, String> xAxisMap = new HashMap<>();
  642. for (String quotaId : quotaIds) {
  643. Map<String, Object> dataMap = new HashMap<>();
  644. TjQuota tjQuota = quotaService.findOne(Integer.valueOf(quotaId));
  645. if (null != tjQuota) {
  646. String dictSql = getQuotaDimensionDictSql(tjQuota.getCode(), dimension);
  647. Map<String, String> dimensionDicMap = new HashMap<>();
  648. dimensionDicMap = setDimensionMap(dictSql, dimension, dimensionDicMap);
  649. //使用分组计算 返回结果实例: groupDataMap -> "4205000000-儿-1": 200 =>group by 三个字段
  650. Map<String, Integer> groupDataMap = quotaService.searcherSumByGroupBySql(tjQuota, dimension, filter, "result", "", "");
  651. for (String key : groupDataMap.keySet()) {
  652. key = key.toLowerCase();
  653. dataMap.put(dimensionDicMap.containsKey(key) ? dimensionDicMap.get(key) : key, groupDataMap.get(key));
  654. xAxisMap.put(dimensionDicMap.containsKey(key) ? dimensionDicMap.get(key) : key, key);
  655. }
  656. radarNames.add(tjQuota.getName());
  657. radarData.put(tjQuota.getCode(), dataMap);
  658. }
  659. Integer num = getNum(dataMap);
  660. arrayNum.add(num);
  661. Map<String, Object> map = new HashMap();
  662. map.put(tjQuota.getName(), num);
  663. listData.add(map);
  664. }
  665. ReportOption reportOption = new ReportOption();
  666. Integer[] array = arrayNum.toArray(new Integer[arrayNum.size()]);
  667. Arrays.sort(array); // 进行升序排序
  668. polorCount += array[arrayNum.size() - 1]; // 雷达图极坐标
  669. option = reportOption.getRadarEchartOption(title, listData, polorCount);
  670. chartInfoModel.setOption(option.toString());
  671. chartInfoModel.setTitle(title);
  672. chartInfoModel.setxAxisMap(xAxisMap);
  673. return chartInfoModel;
  674. } catch (Exception e) {
  675. error(e);
  676. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  677. return null;
  678. }
  679. }
  680. @ApiOperation(value = "获取指标统计结果echart NestedPie图表")
  681. @RequestMapping(value = ServiceApi.TJ.GetQuotaNestedPieReportPreviews, method = RequestMethod.GET)
  682. public MChartInfoModel getQuotaNestedPieGraphicReports(
  683. @ApiParam(name = "resourceId", value = "资源ID", defaultValue = "")
  684. @RequestParam(value = "resourceId") String resourceId,
  685. @ApiParam(name = "quotaIdStr", value = "指标ID,多个用,拼接", required = true)
  686. @RequestParam(value = "quotaIdStr", required = true) String quotaIdStr,
  687. @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  688. @RequestParam(value = "filter", required = false) String filter,
  689. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "")
  690. @RequestParam(value = "dimension", required = false) String dimension,
  691. @ApiParam(name = "title", value = "名称", defaultValue = "")
  692. @RequestParam(value = "title", required = false) String title) {
  693. List<String> quotaIds = Arrays.asList(quotaIdStr.split(","));
  694. Option option = null;
  695. MChartInfoModel chartInfoModel = new MChartInfoModel();
  696. Map<String, String> xAxisMap = new HashMap<>();
  697. try {
  698. Integer quotaCount = resourceQuotaService.getQuotaCount(resourceId);
  699. // 获取最顶层的资源
  700. List<Integer> quotaId = new ArrayList<>();
  701. ChartDataModel chartDataModel = getChartDataModel(quotaId, quotaCount, resourceId, dimension, filter, xAxisMap);
  702. ReportOption reportOption = new ReportOption();
  703. option = reportOption.getNestedPieEchartOption(title, chartDataModel);
  704. chartInfoModel.setOption(option.toString());
  705. chartInfoModel.setTitle(title);
  706. chartInfoModel.setxAxisMap(xAxisMap);
  707. return chartInfoModel;
  708. } catch (Exception e) {
  709. error(e);
  710. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  711. return null;
  712. }
  713. }
  714. private ChartDataModel getChartDataModel(List<Integer> quotaId, Integer count, String resourceId, String dimension, String filter, Map<String, String> xAxisMap) throws Exception {
  715. ChartDataModel chartDataModel = new ChartDataModel();
  716. List<RsResourceQuota> resultList = resourceQuotaService.getChildrenByPidList(quotaId, resourceId);
  717. quotaId.clear();
  718. for (RsResourceQuota rq : resultList) {
  719. quotaId.add(Integer.valueOf(rq.getQuotaId()));
  720. }
  721. count = count - resultList.size();
  722. if (null != resultList && resultList.size() > 0) {
  723. List<Map<String, Object>> list = new ArrayList<>();
  724. for (RsResourceQuota rq : resultList) {
  725. RsResourceQuota parent = rq;
  726. TjQuota tjQuota = quotaService.findOne(Integer.valueOf(rq.getQuotaId()));
  727. Map<String, Object> dataMap = new HashMap<>();
  728. if (null != tjQuota) {
  729. String dictSql = getQuotaDimensionDictSql(tjQuota.getCode(), dimension);
  730. Map<String, String> dimensionDicMap = new HashMap<>();
  731. dimensionDicMap = setDimensionMap(dictSql, dimension, dimensionDicMap);
  732. //使用分组计算 返回结果实例: groupDataMap -> "4205000000-儿-1": 200 =>group by 三个字段
  733. Map<String, Integer> groupDataMap = quotaService.searcherSumByGroupBySql(tjQuota, dimension, filter, "result", "", "");
  734. for (String key : groupDataMap.keySet()) {
  735. key = key.toLowerCase();
  736. dataMap.put(dimensionDicMap.containsKey(key) ? dimensionDicMap.get(key) : key, groupDataMap.get(key));
  737. xAxisMap.put(dimensionDicMap.containsKey(key) ? dimensionDicMap.get(key) : key, key);
  738. }
  739. }
  740. Integer num = getNum(dataMap);
  741. List<Map<String, Object>> mapList = new ArrayList<>();
  742. Map<String, Object> map = new HashMap();
  743. map.put("NAME", tjQuota.getName());
  744. map.put("TOTAL", num);
  745. mapList.add(map);
  746. rq.setMapList(mapList);
  747. list.addAll(rq.getMapList());
  748. }
  749. chartDataModel.setList(list);
  750. }
  751. if (count > 0) {
  752. ChartDataModel chartDataModel2 = getChartDataModel(quotaId, count, resourceId, dimension, filter, xAxisMap);
  753. if (null != chartDataModel2) {
  754. chartDataModel.setChildren(chartDataModel2);
  755. }
  756. }
  757. return chartDataModel;
  758. }
  759. private Map<String, String> setDimensionMap(String dictSql, String dimension, Map<String, String> dimensionDicMap) {
  760. if (StringUtils.isNotEmpty(dictSql)) {
  761. BasesicUtil baseUtil = new BasesicUtil();
  762. if (dimension.contains("slaveKey")) {
  763. //查询字典数据
  764. List<DictModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(DictModel.class));
  765. for (DictModel dictModel : dictDatas) {
  766. String name = baseUtil.getFieldValueByName("name", dictModel);
  767. String val = baseUtil.getFieldValueByName("code", dictModel).toLowerCase();
  768. dimensionDicMap.put(val, name);
  769. }
  770. } else {
  771. List<SaveModel> dictDatas = jdbcTemplate.query(dictSql, new BeanPropertyRowMapper(SaveModel.class));
  772. if (dictDatas != null) {
  773. for (SaveModel saveModel : dictDatas) {
  774. String name = baseUtil.getFieldValueByName(dimension + "Name", saveModel);
  775. String val = baseUtil.getFieldValueByName(dimension, saveModel).toLowerCase();
  776. dimensionDicMap.put(val, name);
  777. }
  778. }
  779. }
  780. }
  781. return dimensionDicMap;
  782. }
  783. private Integer getNum(Map<String, Object> dataMap) {
  784. Integer num = 0;
  785. for (String key : dataMap.keySet()) {
  786. Integer result = null != dataMap.get(key) ? Integer.parseInt(dataMap.get(key).toString()) : 0;
  787. num += result;
  788. }
  789. return num;
  790. }
  791. @RequestMapping(value = "/tj/getCostAndNumOfOutPatient", method = RequestMethod.GET)
  792. @ApiOperation(value = "门急诊费用、人次")
  793. public Map<String, String> getCostOfOutPatient() {
  794. Map<String, String> map = new HashMap<>();
  795. String costOfOutPatient = baseStatistsService.getCostOfOutPatient();
  796. String numOfOutPatient = baseStatistsService.getNumOfOutPatient();
  797. map.put("costOfOutPatient", costOfOutPatient);
  798. map.put("numOfOutPatient", numOfOutPatient);
  799. return map;
  800. }
  801. @RequestMapping(value = "/tj/getCostAndNumOfInPatient", method = RequestMethod.GET)
  802. @ApiOperation(value = "入院费用、人次")
  803. public Map<String, String> getNumOfOutPatient() {
  804. Map<String, String> map = new HashMap<>();
  805. String costOfInPatient = baseStatistsService.getCostOfInPatient();
  806. String numOfInPatient = baseStatistsService.getNumOfInPatient();
  807. map.put("costOfInPatient", costOfInPatient);
  808. map.put("numOfInPatient", numOfInPatient);
  809. return map;
  810. }
  811. @RequestMapping(value = "/tj/getMedicalMonitorInfo", method = RequestMethod.GET)
  812. @ApiOperation(value = "医改监测信息")
  813. public Map<String, String> getMedicalMonitorInfo() {
  814. Map<String, String> map = new HashMap<>();
  815. String costOfMedicalMonitor = baseStatistsService.getCostOfMedicalMonitor();
  816. map.put("costOfMedicalMonitor", costOfMedicalMonitor);
  817. return map;
  818. }
  819. @ApiOperation(value = "首页费用组成")
  820. @RequestMapping(value = ServiceApi.TJ.GetCostComposeReports, method = RequestMethod.GET)
  821. public MChartInfoModel getCostComposeReports(
  822. @ApiParam(name = "quotaIdStr", value = "指标ID,多个用,拼接", required = true)
  823. @RequestParam(value = "quotaIdStr" , required = true) String quotaIdStr,
  824. @ApiParam(name = "charType", value = "图表类型用", defaultValue = "1")
  825. @RequestParam(value = "charType", required = true) String charType,
  826. @ApiParam(name = "filter", value = "过滤", defaultValue = "")
  827. @RequestParam(value = "filter", required = false) String filter,
  828. @ApiParam(name = "dimension", value = "维度字段", defaultValue = "quotaDate")
  829. @RequestParam(value = "dimension", required = false) String dimension,
  830. @ApiParam(name = "title", value = "视图名称", defaultValue = "")
  831. @RequestParam(value = "title", required = false) String title,
  832. @ApiParam(name = "top", value = "获取前几条数据")
  833. @RequestParam(value = "top", required = false) String top
  834. ) {
  835. List<String> quotaIds = Arrays.asList(quotaIdStr.split(","));
  836. MChartInfoModel chartInfoModel = new MChartInfoModel();
  837. String dimensionName = dimension + "Name";
  838. if ("quotaName".equals(dimension)) {
  839. dimensionName = "quotaName";
  840. }
  841. try {
  842. Option option = null;
  843. List<String> lineNames = new ArrayList<>();
  844. Map<String, Map<String, Object>> lineData = new LinkedHashMap<>();
  845. Map<String, String> xAxisMap = new LinkedHashMap<>();
  846. Integer i = 0;
  847. List<Map<String, Object>> listMap = new ArrayList<>();
  848. for (String quotaId : quotaIds) {
  849. Map<String, Object> dataMap = new LinkedHashMap<>();
  850. TjQuota tjQuota = quotaService.findOne(Integer.valueOf(quotaId));
  851. if (tjQuota != null) {
  852. List<Map<String, Object>> resultListMap = baseStatistsService.getSimpleQuotaReport(tjQuota.getCode(), filter, dimension,true, top);
  853. if (resultListMap != null && resultListMap.size() > 0) {
  854. for (Map<String, Object> map : resultListMap) {
  855. if (map != null && map.size() > 0) {
  856. if (map.containsKey("quotaName")) {
  857. map.put("quotaName",tjQuota.getName());
  858. }
  859. //第一种 ES库中有定义的维度 如org,slaveKey1
  860. //第二种 ES库中未定义的维度 如level,economic
  861. if (map.containsKey(dimensionName)) {
  862. if(map.get(dimensionName) != null){
  863. dataMap.put(map.get(dimensionName).toString(), map.get("result"));
  864. xAxisMap.put(map.get(dimensionName).toString(), map.get(dimension).toString());
  865. }
  866. } else {
  867. if(map.get(dimension) != null){
  868. dataMap.put(map.get(dimension).toString(), map.get("result"));
  869. xAxisMap.put(map.get(dimension).toString(), map.get(dimension).toString());
  870. }
  871. }
  872. }
  873. }
  874. }
  875. }
  876. lineData.put("" + i, dataMap);
  877. lineNames.add(tjQuota.getName());
  878. i++;
  879. }
  880. NumberFormat nf = NumberFormat.getInstance();
  881. nf.setGroupingUsed(false);
  882. nf.setMaximumFractionDigits(2);
  883. Set<String> hashSet = new HashSet<>(lineNames);
  884. Map<String, Object> newMap = new HashMap<>();
  885. for (Map<String, Object> data : lineData.values()) {
  886. for (Map.Entry<String, Object> lastMap : data.entrySet()) {
  887. if (newMap.containsKey(lastMap.getKey())) {
  888. double v = Double.parseDouble(newMap.get(lastMap.getKey()) + "") + Double.parseDouble(lastMap.getValue() + "");
  889. newMap.put(lastMap.getKey() + "", nf.format(v));
  890. } else {
  891. newMap.put(lastMap.getKey(), lastMap.getValue());
  892. }
  893. hashSet.add(lastMap.getKey());
  894. }
  895. }
  896. lineNames.clear();
  897. lineNames.addAll(hashSet);
  898. lineData.clear();
  899. for (int j = 0; j < lineNames.size(); j++) {
  900. String name = lineNames.get(j);
  901. Map<String, Object> tempMap = new HashMap<>();
  902. tempMap.put(name, newMap.get(name));
  903. lineData.put("" + j, tempMap);
  904. Map<String, Object> listMapCon = new HashMap<>();
  905. listMapCon.put("quotaName", name);
  906. listMapCon.put("result", newMap.get(name));
  907. listMap.add(listMapCon);
  908. }
  909. ReportOption reportOption = new ReportOption();
  910. if (charType.equals("common")) {
  911. charType = "1";
  912. } else if (charType.equals("twoDimensional")) {
  913. return null;
  914. }
  915. List<String> charTypes = Arrays.asList(charType);
  916. int type = Integer.valueOf(charType);
  917. if (type == ReportOption.bar) {
  918. return null; // 尚未拓展
  919. } else if (type == ReportOption.line) {
  920. return null; // 尚未拓展
  921. } else if (type == ReportOption.pie) {
  922. List<Map<String, Object>> datalist = new ArrayList<>();
  923. for (Map<String, Object> resultMap : listMap) {
  924. Map<String, Object> map = new HashMap<>();
  925. map.put("NAME", null == resultMap.get(dimensionName) ? resultMap.get(dimension) : resultMap.get(dimensionName));
  926. map.put("TOTAL", resultMap.get("result"));
  927. if(resultMap.get(dimensionName) != null){
  928. map.put("NAME",resultMap.get(dimensionName));
  929. }else {
  930. //非 指标中配置的维度 关联出来的字段
  931. if(dimensionName.equals("levelName")){
  932. if(resultMap.get(dimension).equals("1")){
  933. map.put("NAME","一级医院");
  934. }else if(resultMap.get(dimension).equals("2")){
  935. map.put("NAME","二级医院");
  936. }else if(resultMap.get(dimension).equals("3")){
  937. map.put("NAME","三级医院");
  938. }
  939. }
  940. }
  941. map.put("TOTAL",resultMap.get("result"));
  942. datalist.add(map);
  943. }
  944. option = reportOption.getPieEchartOption(title, "", "", datalist, lineNames.get(0), null);
  945. }
  946. chartInfoModel.setOption(option.toString());
  947. chartInfoModel.setTitle(title);
  948. chartInfoModel.setxAxisMap(xAxisMap);
  949. return chartInfoModel;
  950. } catch (Exception e) {
  951. error(e);
  952. invalidUserException(e, -1, "查询失败:" + e.getMessage());
  953. return null;
  954. }
  955. }
  956. @RequestMapping(value = ServiceApi.TJ.GetDeviceReports, method = RequestMethod.GET)
  957. @ApiOperation(value = "报表-卫生设备一览")
  958. public Envelop getDeviceReports(
  959. @ApiParam(name = "year", value = "年份", required = true)
  960. @RequestParam(value = "year" , required = true) String year,
  961. @ApiParam(name = "district", value = "区县编码")
  962. @RequestParam(value = "district", required = false) String district,
  963. @ApiParam(name = "organization", value = "机构名称或者组织机构代码", defaultValue = "")
  964. @RequestParam(value = "organization", required = false) String organization,
  965. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  966. @RequestParam(value = "size", required = false) int size,
  967. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  968. @RequestParam(value = "page", required = false) int page) throws Exception{
  969. Envelop envelop = new Envelop();
  970. List<MQcDevice> list = new ArrayList<>();
  971. DataList dataList = deviceService.listMQcDeviceByYearAndDistrictAndOrg(year,district,organization,page ,size);
  972. if(null!= dataList && null!=dataList.getList() && dataList.getList().size()>0){
  973. for(int i=0; i<dataList.getList().size(); i++){
  974. Map<String,Object> dataMap = (Map<String, Object>) dataList.getList().get(i);
  975. MQcDevice newEntity = objectMapper.readValue(toJson(dataMap), MQcDevice.class);
  976. list.add(newEntity);
  977. }
  978. }
  979. envelop.setDetailModelList(list);
  980. envelop.setSuccessFlg(true);
  981. envelop.setPageSize(size);
  982. envelop.setCurrPage(page);
  983. envelop.setTotalPage((int)dataList.getPage());
  984. envelop.setTotalCount((int)dataList.getCount());
  985. return envelop;
  986. }
  987. protected String toJson(Object obj) throws JsonProcessingException {
  988. objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
  989. return objectMapper.writeValueAsString(obj);
  990. }
  991. /**
  992. * 如果有计量单位,则把数值换算成相应的数值单位
  993. * @param optionData
  994. * @param dataMeasurement
  995. * @return
  996. */
  997. public List<List<Object>> discountByMeasurement(List<List<Object>> optionData, String dataMeasurement) {
  998. if (!StringUtils.isEmpty(dataMeasurement)) {
  999. NumberFormat nf = NumberFormat.getInstance();
  1000. nf.setGroupingUsed(false);
  1001. nf.setMaximumFractionDigits(2);
  1002. List<List<Object>> handleList = new ArrayList<>();
  1003. double v = Double.parseDouble(dataMeasurement);
  1004. optionData.forEach(one -> {
  1005. List<Object> list = new ArrayList<>();
  1006. one.forEach(item -> {
  1007. if(item != null && !item.toString().equals("--")){
  1008. item = nf.format(Double.parseDouble(item.toString()) / v);
  1009. list.add(item);
  1010. }else {
  1011. list.add(0);
  1012. }
  1013. });
  1014. handleList.add(list);
  1015. });
  1016. return handleList;
  1017. }
  1018. return optionData;
  1019. }
  1020. }