Commit 83f99c5b273aa053d2d23fdd74e49859f2451aa5
1 parent
e433e4f3c5
Exists in
master
and in
6 other branches
健康统计
Showing 3 changed files with 418 additions and 37 deletions
platform-dal/src/main/java/com/lyms/platform/pojo/HealthChargeModel.java
View file @
83f99c5
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/AreaCountController.java
View file @
83f99c5
| ... | ... | @@ -274,6 +274,45 @@ |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | + /** | |
| 278 | + * 健康管理统计详情list | |
| 279 | + * | |
| 280 | + * @param query | |
| 281 | + */ | |
| 282 | + @RequestMapping(value = "/healthManagerDetail/list",method = RequestMethod.POST) | |
| 283 | + @ResponseBody | |
| 284 | + @TokenRequired | |
| 285 | + public BaseResponse healthManagerDetailList(@RequestBody @Valid HealthManagerListRequest query, HttpServletRequest request){ | |
| 286 | + LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 287 | + query.setUserId(loginState.getId()); | |
| 288 | + try { | |
| 289 | + return areaCountFacade.healthManagerDetailList(query); | |
| 290 | + }catch (Exception e){ | |
| 291 | + logger.error("健康管理统计详情失败",e); | |
| 292 | + BaseResponse baseResponse = new BaseResponse(); | |
| 293 | + baseResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
| 294 | + baseResponse.setErrormsg("增健康管理统计详情失败"); | |
| 295 | + return baseResponse; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * 增值服务统计detailList 导出 | |
| 302 | + * | |
| 303 | + * @param param | |
| 304 | + */ | |
| 305 | + @RequestMapping(value = "/healthManagerDetail/export",method = RequestMethod.GET) | |
| 306 | + @TokenRequired | |
| 307 | + public void healthManagerDetailExport(HealthManagerListRequest param, HttpServletRequest request, HttpServletResponse response){ | |
| 308 | + LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 309 | + param.setUserId(loginState.getId()); | |
| 310 | + try { | |
| 311 | + areaCountFacade.healthManagerDetailExport(param, response); | |
| 312 | + }catch (Exception e){ | |
| 313 | + logger.error("增值服务统计导出失败", e); | |
| 314 | + } | |
| 315 | + } | |
| 277 | 316 | |
| 278 | 317 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
View file @
83f99c5
| 1 | 1 | package com.lyms.platform.operate.web.facade; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | 5 | import com.lyms.platform.beans.AddressBean; |
| 5 | 6 | import com.lyms.platform.biz.service.*; |
| 6 | 7 | import com.lyms.platform.common.base.PageInfo; |
| ... | ... | @@ -39,6 +40,7 @@ |
| 39 | 40 | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| 40 | 41 | import org.springframework.data.mongodb.core.aggregation.AggregationOperation; |
| 41 | 42 | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| 43 | +import org.springframework.data.mongodb.core.aggregation.SortOperation; | |
| 42 | 44 | import org.springframework.data.mongodb.core.query.Criteria; |
| 43 | 45 | import org.springframework.data.mongodb.core.query.Query; |
| 44 | 46 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| ... | ... | @@ -51,6 +53,7 @@ |
| 51 | 53 | import java.time.temporal.TemporalAdjusters; |
| 52 | 54 | import java.util.*; |
| 53 | 55 | import java.util.concurrent.*; |
| 56 | +import java.util.stream.Collectors; | |
| 54 | 57 | |
| 55 | 58 | import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; |
| 56 | 59 | |
| 57 | 60 | |
| 58 | 61 | |
| 59 | 62 | |
| 60 | 63 | |
| 61 | 64 | |
| 62 | 65 | |
| 63 | 66 | |
| 64 | 67 | |
| 65 | 68 | |
| 66 | 69 | |
| 67 | 70 | |
| 68 | 71 | |
| 69 | 72 | |
| 70 | 73 | |
| 71 | 74 | |
| ... | ... | @@ -1401,70 +1404,409 @@ |
| 1401 | 1404 | startTime = getStartDate(); |
| 1402 | 1405 | endTime = new Date(); |
| 1403 | 1406 | } |
| 1407 | + List<String> hospitalIds = getHospitalIds(query); | |
| 1408 | + if (CollectionUtils.isEmpty(hospitalIds)){ | |
| 1409 | + return baseResponse; | |
| 1410 | + } | |
| 1404 | 1411 | |
| 1405 | - String hospitalId = query.getHospitalId(); | |
| 1406 | - String provinceId = query.getProvinceId(); | |
| 1407 | - String cityId = query.getCityId(); | |
| 1408 | - String areaId = query.getAreaId(); | |
| 1412 | + HealthChargeQuery healthChargeQuery = getHealthChargeQuery(query, startTime, endTime, hospitalIds); | |
| 1413 | + | |
| 1414 | + List<HashMap> columnarResults = getColumnarResultsByGroup(healthChargeQuery); | |
| 1415 | + if (CollectionUtils.isNotEmpty(columnarResults)){ | |
| 1416 | + for (HashMap map : columnarResults){ | |
| 1417 | + String month = map.get("month").toString(); | |
| 1418 | + String year = map.get("year").toString(); | |
| 1419 | + String dateName = year +"-"+ month; | |
| 1420 | + map.put("dateName", dateName); | |
| 1421 | + | |
| 1422 | + HealthChargeQuery chargeQuery = new HealthChargeQuery(); | |
| 1423 | + BeanUtils.copy(healthChargeQuery, chargeQuery); | |
| 1424 | + int length = month.length(); | |
| 1425 | + if (length == 1){ | |
| 1426 | + month = "0"+month; | |
| 1427 | + } | |
| 1428 | + dateName = year + "-" + month; | |
| 1429 | + Date monthStart = DateUtil.yyyyMMParse(dateName); | |
| 1430 | + Date monthEnd = getMonthEnd(monthStart); | |
| 1431 | + chargeQuery.setCreatedStart(monthStart); | |
| 1432 | + chargeQuery.setCreatedEnd(monthEnd); | |
| 1433 | + Integer tzCount = countByType(chargeQuery, 1, false); | |
| 1434 | + Integer xtCount = countByType(chargeQuery, 2, false); | |
| 1435 | + Integer xyCount = countByType(chargeQuery, 3, false); | |
| 1436 | + Integer babyCount = countByType(chargeQuery, 5, false); | |
| 1437 | + HashMap<String, Object> hashMap = new HashMap<>(16); | |
| 1438 | + hashMap.put("tzNumber",tzCount); | |
| 1439 | + hashMap.put("xtNumber",xtCount); | |
| 1440 | + hashMap.put("xyNumber",xyCount); | |
| 1441 | + hashMap.put("babyNumber",babyCount); | |
| 1442 | + map.put("dateVal", hashMap); | |
| 1443 | + } | |
| 1444 | + } | |
| 1445 | + List<HashMap> results = getResults(healthChargeQuery); | |
| 1446 | + | |
| 1447 | + if (CollectionUtils.isNotEmpty(results)){ | |
| 1448 | + for (HashMap map: results){ | |
| 1449 | + String id = map.get("_id").toString(); | |
| 1450 | + if (id != null){ | |
| 1451 | + // 1体重 2 血糖 3 血压 4妊高症(暂时不需要) 5-儿童 | |
| 1452 | + HealthChargeQuery chargeQuery = new HealthChargeQuery(); | |
| 1453 | + BeanUtils.copy(healthChargeQuery, chargeQuery); | |
| 1454 | + ArrayList<String> arrayList = new ArrayList<>(); | |
| 1455 | + arrayList.add(id); | |
| 1456 | + chargeQuery.setHospitalIds(arrayList); | |
| 1457 | + Integer tzCount = countByType(chargeQuery, 1, true); | |
| 1458 | + Integer xtCount = countByType(chargeQuery, 2, true); | |
| 1459 | + Integer xyCount = countByType(chargeQuery, 3, true); | |
| 1460 | + Integer babyCount = countByType(chargeQuery, 5, true); | |
| 1461 | + | |
| 1462 | + Organization organization = organizationService.getOrganization(Integer.parseInt(id)); | |
| 1463 | + if (organization != null){ | |
| 1464 | + String oProvinceId = organization.getProvinceId(); | |
| 1465 | + String oCityId = organization.getCityId(); | |
| 1466 | + String oAreaId = organization.getAreaId(); | |
| 1467 | + BasicConfig province = basicConfigService.getOneBasicConfigById(oProvinceId); | |
| 1468 | + BasicConfig city = basicConfigService.getOneBasicConfigById(oCityId); | |
| 1469 | + BasicConfig area = basicConfigService.getOneBasicConfigById(oAreaId); | |
| 1470 | + map.put("provinceId", oProvinceId); | |
| 1471 | + map.put("cityId", oCityId); | |
| 1472 | + map.put("areaId", oAreaId); | |
| 1473 | + map.put("provinceName", province.getName()); | |
| 1474 | + map.put("cityName", city.getName()); | |
| 1475 | + map.put("areaName", area.getName()); | |
| 1476 | + map.put("hospitalName",organization.getName()); | |
| 1477 | + map.put("tzNumber",tzCount); | |
| 1478 | + map.put("xtNumber",xtCount); | |
| 1479 | + map.put("xyNumber",xyCount); | |
| 1480 | + map.put("babyNumber",babyCount); | |
| 1481 | + map.put("count", tzCount + xtCount + xyCount + babyCount); | |
| 1482 | + } | |
| 1483 | + } | |
| 1484 | + } | |
| 1485 | + } | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + HashMap<String, Object> hashMap = new HashMap<>(16); | |
| 1489 | + hashMap.put("columnarResults",columnarResults); | |
| 1490 | + hashMap.put("results", results); | |
| 1491 | + baseResponse.setObject(hashMap); | |
| 1492 | + | |
| 1493 | + return baseResponse; | |
| 1494 | + } | |
| 1495 | + | |
| 1496 | + private HealthChargeQuery getHealthChargeQuery(HealthManagerListRequest query, Date startTime, Date endTime, List<String> hospitalIds) { | |
| 1409 | 1497 | String reportNameType = query.getReportNameType(); |
| 1410 | 1498 | String interpretDoctorId = query.getInterpretDoctorId(); |
| 1411 | 1499 | String reportSource = query.getReportSource(); |
| 1412 | 1500 | String reportType = query.getReportType(); |
| 1413 | 1501 | String settleStatus = query.getSettleStatus(); |
| 1414 | - | |
| 1415 | - List<String> hospitalIds = new ArrayList<>(); | |
| 1416 | - if (StringUtils.isNotEmpty(hospitalId)){ | |
| 1417 | - hospitalIds.add(hospitalId); | |
| 1418 | - }else { | |
| 1419 | - hospitalIds = getCurrentUserHospPermissions(query.getUserId(), StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, | |
| 1420 | - StringUtils.isEmpty(areaId) ? null : areaId); | |
| 1421 | - } | |
| 1422 | - if (CollectionUtils.isEmpty(hospitalIds)){ | |
| 1423 | - return baseResponse; | |
| 1424 | - } | |
| 1425 | - | |
| 1426 | 1502 | HealthChargeQuery healthChargeQuery = new HealthChargeQuery(); |
| 1427 | 1503 | healthChargeQuery.setCreatedStart(startTime); |
| 1428 | 1504 | healthChargeQuery.setCreatedEnd(endTime); |
| 1429 | 1505 | healthChargeQuery.setYn(YnEnums.YES.getId()); |
| 1430 | - if (StringUtils.isNotEmpty(reportNameType)){ | |
| 1506 | + if (StringUtils.isNotEmpty(reportNameType)) { | |
| 1431 | 1507 | healthChargeQuery.setHealthType(Integer.parseInt(reportNameType)); |
| 1432 | 1508 | } |
| 1433 | - if (StringUtils.isNotEmpty(interpretDoctorId)){ | |
| 1509 | + if (StringUtils.isNotEmpty(interpretDoctorId)) { | |
| 1434 | 1510 | healthChargeQuery.setDoctorId(interpretDoctorId); |
| 1435 | 1511 | } |
| 1436 | - if (StringUtils.isNotEmpty(reportSource)){ | |
| 1512 | + if (StringUtils.isNotEmpty(reportSource)) { | |
| 1437 | 1513 | healthChargeQuery.setSource(Integer.parseInt(reportSource)); |
| 1438 | 1514 | } |
| 1439 | - if (StringUtils.isNotEmpty(reportType)){ | |
| 1515 | + if (StringUtils.isNotEmpty(reportType)) { | |
| 1440 | 1516 | healthChargeQuery.setType(Integer.parseInt(reportType)); |
| 1441 | 1517 | } |
| 1442 | - if (StringUtils.isNotEmpty(settleStatus)){ | |
| 1518 | + if (StringUtils.isNotEmpty(settleStatus)) { | |
| 1443 | 1519 | healthChargeQuery.setStatus(Integer.parseInt(settleStatus)); |
| 1444 | 1520 | } |
| 1445 | - if (CollectionUtils.isNotEmpty(hospitalIds)){ | |
| 1521 | + if (CollectionUtils.isNotEmpty(hospitalIds)) { | |
| 1446 | 1522 | healthChargeQuery.setHospitalIds(hospitalIds); |
| 1447 | 1523 | } |
| 1524 | + return healthChargeQuery; | |
| 1525 | + } | |
| 1448 | 1526 | |
| 1449 | - AggregationOperation match = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
| 1450 | - AggregationOperation group = Aggregation.group("day","month","year","healthType").count().as("count"); | |
| 1527 | + /** | |
| 1528 | + * 月份的最后时间 | |
| 1529 | + * | |
| 1530 | + * @param date | |
| 1531 | + * @return | |
| 1532 | + */ | |
| 1533 | + public Date getMonthEnd(Date date) { | |
| 1534 | + Calendar c = Calendar.getInstance(); | |
| 1535 | + c.setTime(date); | |
| 1536 | + | |
| 1537 | + //设置为当月最后一天 | |
| 1538 | + c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH)); | |
| 1539 | + //将小时至23 | |
| 1540 | + c.set(Calendar.HOUR_OF_DAY, 23); | |
| 1541 | + //将分钟至59 | |
| 1542 | + c.set(Calendar.MINUTE, 59); | |
| 1543 | + //将秒至59 | |
| 1544 | + c.set(Calendar.SECOND,59); | |
| 1545 | + //将毫秒至999 | |
| 1546 | + c.set(Calendar.MILLISECOND, 999); | |
| 1547 | + // 获取本月最后一天的时间戳 | |
| 1548 | + | |
| 1549 | + return new Date(c.getTimeInMillis()); | |
| 1550 | + } | |
| 1551 | + | |
| 1552 | + /** | |
| 1553 | + * 根据类型获取总数 | |
| 1554 | + * | |
| 1555 | + * @param chargeQuery | |
| 1556 | + * @param i | |
| 1557 | + * @return | |
| 1558 | + */ | |
| 1559 | + private Integer countByType(HealthChargeQuery chargeQuery, int i, boolean isGroup) { | |
| 1560 | + chargeQuery.setHealthType(i); | |
| 1561 | + List<HashMap> mapList; | |
| 1562 | + Integer count = 0; | |
| 1563 | + if (isGroup){ | |
| 1564 | + mapList = getResults(chargeQuery); | |
| 1565 | + } else { | |
| 1566 | + mapList = getResultsNoGroup(chargeQuery); | |
| 1567 | + } | |
| 1568 | + if (CollectionUtils.isNotEmpty(mapList)) { | |
| 1569 | + HashMap hashMap = mapList.get(0); | |
| 1570 | + String countStr = hashMap.get("count").toString(); | |
| 1571 | + count = Integer.parseInt(countStr); | |
| 1572 | + } | |
| 1573 | + | |
| 1574 | + return count; | |
| 1575 | + } | |
| 1576 | + | |
| 1577 | + /** | |
| 1578 | + * 根据类型和医院分组查询 | |
| 1579 | + * | |
| 1580 | + * @param healthChargeQuery | |
| 1581 | + * @return | |
| 1582 | + */ | |
| 1583 | + private List<HashMap> getResults(HealthChargeQuery healthChargeQuery) { | |
| 1584 | + AggregationOperation queryParam1 = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
| 1585 | + AggregationOperation group = Aggregation.group("hospitalId").count().as("count"); | |
| 1586 | + Aggregation aggregation2 = Aggregation.newAggregation(queryParam1, group ); | |
| 1587 | + AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation2, "lyms_health_charge", HashMap.class); | |
| 1588 | + return result.getMappedResults(); | |
| 1589 | + } | |
| 1590 | + | |
| 1591 | + /** | |
| 1592 | + * | |
| 1593 | + * @param healthChargeQuery | |
| 1594 | + * @return | |
| 1595 | + */ | |
| 1596 | + private List<HashMap> getResultsNoGroup(HealthChargeQuery healthChargeQuery) { | |
| 1597 | + AggregationOperation queryParam1 = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
| 1598 | + AggregationOperation group = Aggregation.group().count().as("count"); | |
| 1599 | + Aggregation aggregation2 = Aggregation.newAggregation(queryParam1, group); | |
| 1600 | + AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation2, "lyms_health_charge", HashMap.class); | |
| 1601 | + return result.getMappedResults(); | |
| 1602 | + } | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + private List<HashMap> getColumnarResults(HealthChargeQuery healthChargeQuery) { | |
| 1606 | + AggregationOperation queryParam = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
| 1607 | + AggregationOperation group = Aggregation.group("month","year","healthType","hospitalId").count().as("count"); | |
| 1451 | 1608 | AggregationOperation month = project(). |
| 1452 | - andExpression("dayOfMonth(created)").as("day"). | |
| 1453 | - andExpression("month(created)").as("month"). | |
| 1454 | - andExpression("year(created)").as("year"). | |
| 1455 | - andExpression("healthType").as("healthType"); | |
| 1456 | - Aggregation aggregation = Aggregation.newAggregation(match, month, group ); | |
| 1609 | + //andExpression("dayOfMonth(created)").as("day"). | |
| 1610 | + andExpression("month(created)").as("month"). | |
| 1611 | + andExpression("year(created)").as("year"). | |
| 1612 | + andExpression("healthType").as("healthType"). | |
| 1613 | + andExpression("hospitalId").as("hospitalId"); | |
| 1614 | + AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC, "year", "month"); | |
| 1615 | + Aggregation aggregation = Aggregation.newAggregation(queryParam, month, group, sort); | |
| 1457 | 1616 | AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation, "lyms_health_charge", HashMap.class); |
| 1458 | - List<HashMap> mappedResults = result.getMappedResults(); | |
| 1617 | + return result.getMappedResults(); | |
| 1618 | + } | |
| 1459 | 1619 | |
| 1460 | - AggregationOperation group2 = Aggregation.group("healthType").count().as("count"); | |
| 1461 | - Aggregation aggregation2 = Aggregation.newAggregation(match, group2 ); | |
| 1462 | - AggregationResults<HashMap> result2 = mongoTemplate.aggregate(aggregation2, "lyms_health_charge", HashMap.class); | |
| 1463 | - List<HashMap> mappedResults2 = result2.getMappedResults(); | |
| 1620 | + /** | |
| 1621 | + * 针对柱状图查询结果集 | |
| 1622 | + * | |
| 1623 | + * @param healthChargeQuery | |
| 1624 | + * @return | |
| 1625 | + */ | |
| 1626 | + private List<HashMap> getColumnarResultsByGroup(HealthChargeQuery healthChargeQuery) { | |
| 1627 | + AggregationOperation queryParam = Aggregation.match(healthChargeQuery.convertToQuery().getCriteria()); | |
| 1628 | + AggregationOperation group = Aggregation.group("month","year").count().as("count"); | |
| 1629 | + AggregationOperation month = project(). | |
| 1630 | + //andExpression("dayOfMonth(created)").as("day"). | |
| 1631 | + andExpression("month(created)").as("month"). | |
| 1632 | + andExpression("year(created)").as("year"); | |
| 1633 | + AggregationOperation sort = Aggregation.sort(Sort.Direction.ASC, "year", "month"); | |
| 1634 | + Aggregation aggregation = Aggregation.newAggregation(queryParam, month, group, sort); | |
| 1635 | + AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation, "lyms_health_charge", HashMap.class); | |
| 1636 | + return result.getMappedResults(); | |
| 1637 | + } | |
| 1464 | 1638 | |
| 1465 | - baseResponse.setObject(mappedResults2); | |
| 1639 | + /** | |
| 1640 | + * 统计详情 list | |
| 1641 | + * | |
| 1642 | + * @param query | |
| 1643 | + * @return | |
| 1644 | + */ | |
| 1645 | + public BaseResponse healthManagerDetailList(HealthManagerListRequest query) { | |
| 1646 | + Date startTime = query.getStartTime(); | |
| 1647 | + Date endTime = query.getEndTime(); | |
| 1648 | + if (startTime == null || endTime == null){ | |
| 1649 | + startTime = getStartDate(); | |
| 1650 | + endTime = new Date(); | |
| 1651 | + } | |
| 1466 | 1652 | |
| 1467 | - return baseResponse; | |
| 1653 | + List<String> hospitalIds = getHospitalIds(query); | |
| 1654 | + | |
| 1655 | + HealthChargeQuery healthChargeQuery = getHealthChargeQuery(query, startTime, endTime, hospitalIds); | |
| 1656 | + List<HealthChargeModel> healthChargeModels = healthChargeService.queryHealthChargeList(healthChargeQuery); | |
| 1657 | + LinkedList<Map<String, Object>> linkedList = new LinkedList<>(); | |
| 1658 | + if (CollectionUtils.isNotEmpty(healthChargeModels)){ | |
| 1659 | + for (HealthChargeModel model : healthChargeModels){ | |
| 1660 | + HashMap<String, Object> map = getStringObjectHashMap(model); | |
| 1661 | + linkedList.add(map); | |
| 1662 | + | |
| 1663 | + } | |
| 1664 | + } | |
| 1665 | + | |
| 1666 | + BaseListResponse baseListResponse = new BaseListResponse(); | |
| 1667 | + baseListResponse.setData(linkedList); | |
| 1668 | + baseListResponse.setPageInfo(healthChargeQuery.getPageInfo()); | |
| 1669 | + return baseListResponse; | |
| 1670 | + } | |
| 1671 | + | |
| 1672 | + private List<String> getHospitalIds(HealthManagerListRequest query) { | |
| 1673 | + String hospitalId = query.getHospitalId(); | |
| 1674 | + String provinceId = query.getProvinceId(); | |
| 1675 | + String cityId = query.getCityId(); | |
| 1676 | + String areaId = query.getAreaId(); | |
| 1677 | + | |
| 1678 | + List<String> hospitalIds = new ArrayList<>(); | |
| 1679 | + if (StringUtils.isNotEmpty(hospitalId)) { | |
| 1680 | + hospitalIds.add(hospitalId); | |
| 1681 | + } else { | |
| 1682 | + hospitalIds = getCurrentUserHospPermissions(query.getUserId(), StringUtils.isEmpty(provinceId) ? null : provinceId, StringUtils.isEmpty(cityId) ? null : cityId, | |
| 1683 | + StringUtils.isEmpty(areaId) ? null : areaId); | |
| 1684 | + } | |
| 1685 | + return hospitalIds; | |
| 1686 | + } | |
| 1687 | + | |
| 1688 | + /** | |
| 1689 | + * 挑选需要的数据 | |
| 1690 | + * | |
| 1691 | + * @param model | |
| 1692 | + * @return | |
| 1693 | + */ | |
| 1694 | + private HashMap<String, Object> getStringObjectHashMap(HealthChargeModel model) { | |
| 1695 | + Date createDate = model.getCreated(); | |
| 1696 | + String babyForeignId = model.getBabyForeignId(); | |
| 1697 | + String name = "", healthTypeName = "", typeName = "", sourceName = "", doctorName = ""; | |
| 1698 | + if (babyForeignId != null) { | |
| 1699 | + BabyModel babyModel = mongoTemplate.findOne(Query.query(Criteria.where("_id").is(babyForeignId)), BabyModel.class); | |
| 1700 | + if (babyModel != null) { | |
| 1701 | + name = babyModel.getName(); | |
| 1702 | + } | |
| 1703 | + } | |
| 1704 | + healthTypeName = getHealthTypeName(model, healthTypeName); | |
| 1705 | + typeName = getTypeName(model, typeName); | |
| 1706 | + Integer source = model.getSource(); | |
| 1707 | + if (source != null) { | |
| 1708 | + if (source == 1) { | |
| 1709 | + sourceName = "院内报告"; | |
| 1710 | + } | |
| 1711 | + if (source == 2) { | |
| 1712 | + sourceName = "临时报告"; | |
| 1713 | + } | |
| 1714 | + } | |
| 1715 | + String doctorId = model.getDoctorId(); | |
| 1716 | + if (StringUtils.isNotEmpty(doctorId)) { | |
| 1717 | + Users users = usersService.getUsers(Integer.parseInt(doctorId)); | |
| 1718 | + if (users != null) { | |
| 1719 | + doctorName = users.getName(); | |
| 1720 | + } | |
| 1721 | + } | |
| 1722 | + HashMap<String, Object> map = new HashMap<>(16); | |
| 1723 | + map.put("createDate", createDate); | |
| 1724 | + map.put("patientName", name); | |
| 1725 | + map.put("healthType", healthTypeName); | |
| 1726 | + map.put("type", typeName); | |
| 1727 | + map.put("source", sourceName); | |
| 1728 | + map.put("doctorName", doctorName); | |
| 1729 | + map.put("status", model.getStatus() == 1 ? "未结算" : "已结算"); | |
| 1730 | + return map; | |
| 1731 | + } | |
| 1732 | + | |
| 1733 | + /** | |
| 1734 | + * 导出 | |
| 1735 | + * | |
| 1736 | + * @param query | |
| 1737 | + * @param response | |
| 1738 | + */ | |
| 1739 | + public void healthManagerDetailExport(HealthManagerListRequest query, HttpServletResponse response) throws Exception { | |
| 1740 | + Date startTime = query.getStartTime(); | |
| 1741 | + Date endTime = query.getEndTime(); | |
| 1742 | + if (startTime == null || endTime == null){ | |
| 1743 | + startTime = getStartDate(); | |
| 1744 | + endTime = new Date(); | |
| 1745 | + } | |
| 1746 | + | |
| 1747 | + String hospitalId = query.getHospitalId(); | |
| 1748 | + List<String> hospitalIds = new ArrayList<>(); | |
| 1749 | + if (StringUtils.isNotEmpty(hospitalId)){ | |
| 1750 | + hospitalIds.add(hospitalId); | |
| 1751 | + }else { | |
| 1752 | + hospitalIds = getCurrentUserHospPermissions(query.getUserId(), | |
| 1753 | + StringUtils.isEmpty(query.getProvinceId()) ? null : query.getProvinceId(), StringUtils.isEmpty(query.getCityId()) ? null : query.getCityId(), | |
| 1754 | + StringUtils.isEmpty(query.getAreaId()) ? null : query.getAreaId()); | |
| 1755 | + } | |
| 1756 | + | |
| 1757 | + HealthChargeQuery healthChargeQuery = getHealthChargeQuery(query, startTime, endTime, hospitalIds); | |
| 1758 | + | |
| 1759 | + List<HealthChargeModel> healthChargeModels = healthChargeService.queryHealthChargeList(healthChargeQuery); | |
| 1760 | + LinkedList<Map<String, Object>> linkedList = new LinkedList<>(); | |
| 1761 | + | |
| 1762 | + if (CollectionUtils.isNotEmpty(healthChargeModels)){ | |
| 1763 | + for (HealthChargeModel model : healthChargeModels){ | |
| 1764 | + HashMap<String, Object> map = getStringObjectHashMap(model); | |
| 1765 | + linkedList.add(map); | |
| 1766 | + | |
| 1767 | + } | |
| 1768 | + Map<String, String> names = new LinkedHashMap<>(); | |
| 1769 | + names.put("createDate","购买日期"); | |
| 1770 | + names.put("patientName", "姓名"); | |
| 1771 | + names.put("healthType", "报告名称"); | |
| 1772 | + names.put("type", "报告类型"); | |
| 1773 | + names.put("source", "报告来源"); | |
| 1774 | + names.put("doctorName","报告解读人"); | |
| 1775 | + names.put("status","结算状态"); | |
| 1776 | + ResponseUtil.responseExcel(names,linkedList,response); | |
| 1777 | + } | |
| 1778 | + } | |
| 1779 | + | |
| 1780 | + private String getTypeName(HealthChargeModel model, String typeName) { | |
| 1781 | + Integer type = model.getType(); | |
| 1782 | + if (type != null){ | |
| 1783 | + if (type == 1){ | |
| 1784 | + typeName = "1普通报告"; | |
| 1785 | + } | |
| 1786 | + if (type == 2){ | |
| 1787 | + typeName = "高危报告"; | |
| 1788 | + } | |
| 1789 | + } | |
| 1790 | + return typeName; | |
| 1791 | + } | |
| 1792 | + | |
| 1793 | + private String getHealthTypeName(HealthChargeModel model, String healthTypeName) { | |
| 1794 | + Integer healthType = model.getHealthType(); | |
| 1795 | + if (healthType != null){ | |
| 1796 | + if (healthType == 1){ | |
| 1797 | + healthTypeName = "体重报告"; | |
| 1798 | + } | |
| 1799 | + if (healthType == 2){ | |
| 1800 | + healthTypeName = "血糖报告"; | |
| 1801 | + } | |
| 1802 | + if (healthType == 3){ | |
| 1803 | + healthTypeName = "血压报告"; | |
| 1804 | + } | |
| 1805 | + if (healthType == 5){ | |
| 1806 | + healthTypeName = "儿童膳食报告"; | |
| 1807 | + } | |
| 1808 | + } | |
| 1809 | + return healthTypeName; | |
| 1468 | 1810 | } |
| 1469 | 1811 | } |