QuotaReportController.java 54 KB

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