From c291d99d6c38d19af375a32087c19987e2eb746f Mon Sep 17 00:00:00 2001 From: fshenye <12345678> Date: Thu, 30 Jun 2022 17:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E5=BF=99=E9=97=B2=E9=A2=84?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hpgp/dao/HpgpDepartmentRankMapper.java | 3 +- .../hpgp/model/HpgpBusyIdlePrediction.java | 40 ++++---- .../HpgpBusyIdlePredictionService.java | 3 +- .../HpgpBusyIdlePredictionServiceImpl.java | 94 +++++++++++++++---- .../sict/theme/hpgp/vo/DeptPredictionVO.java | 31 ++++++ .../sh/stc/sict/theme/hpgp/vo/DeptRankVO.java | 10 ++ .../hphy/controller/mp/WDController.java | 8 ++ .../service/impl/HpDeptInfoServiceImpl.java | 7 ++ .../stc/sict/theme/hphy/wd/NumSourceInfo.java | 4 +- .../stc/sict/theme/hphy/wd/WanDaHttpUtil.java | 5 +- .../src/main/resources/logback-spring.xml | 2 +- .../hpgp/HpgpBusyIdlePredictionMapper.xml | 3 +- .../mapper/hpgp/HpgpDepartmentRankMapper.xml | 18 +++- 13 files changed, 177 insertions(+), 51 deletions(-) create mode 100644 smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptPredictionVO.java create mode 100644 smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptRankVO.java diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpDepartmentRankMapper.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpDepartmentRankMapper.java index 8c1bb85..597e714 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpDepartmentRankMapper.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpDepartmentRankMapper.java @@ -1,6 +1,7 @@ package cn.sh.stc.sict.theme.hpgp.dao; import cn.sh.stc.sict.theme.hpgp.model.HpgpDepartmentRank; +import cn.sh.stc.sict.theme.hpgp.vo.DeptRankVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; @@ -19,5 +20,5 @@ public interface HpgpDepartmentRankMapper extends BaseMapper * @param size 查询记录数 默认3条 * @return */ - List getRankByStandardDept(@Param("deptName") String deptName, @Param("size") int size); + List getRankByStandardDept(@Param("deptName") String deptName, @Param("size") int size); } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpBusyIdlePrediction.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpBusyIdlePrediction.java index a6cf4f6..a286e5d 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpBusyIdlePrediction.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpBusyIdlePrediction.java @@ -18,24 +18,22 @@ import java.io.Serializable; @Data @EqualsAndHashCode(callSuper = true) public class HpgpBusyIdlePrediction extends Model { -//医院代码 -@ApiModelProperty(hidden = false, value = "医院代码") -private String hospitalCode; -//医院名称 -@ApiModelProperty(hidden = false, value = "医院名称") -private String hospitalName; -//科室代码 -@ApiModelProperty(hidden = false, value = "科室代码") -private String deptCode; -//科室名称 -@ApiModelProperty(hidden = false, value = "科室名称") -private String deptName; -//预测日期 -@ApiModelProperty(hidden = false, value = "预测日期") -private Date predictionDate; -//忙闲评分 -@ApiModelProperty(hidden = false, value = "忙闲评分") -private Integer score; - - - } + //医院代码 + @ApiModelProperty(hidden = false, value = "医院代码") + private String hospitalCode; + //医院名称 + @ApiModelProperty(hidden = false, value = "医院名称") + private String hospitalName; + //科室代码 + @ApiModelProperty(hidden = false, value = "科室代码") + private String deptCode; + //科室名称 + @ApiModelProperty(hidden = false, value = "科室名称") + private String deptName; + //预测日期 + @ApiModelProperty(hidden = false, value = "预测日期") + private Date predictionDate; + //忙闲评分 + @ApiModelProperty(hidden = false, value = "忙闲评分") + private Integer score; +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpBusyIdlePredictionService.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpBusyIdlePredictionService.java index f83447f..b81c3c7 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpBusyIdlePredictionService.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpBusyIdlePredictionService.java @@ -1,6 +1,7 @@ package cn.sh.stc.sict.theme.hpgp.service; import cn.sh.stc.sict.theme.hpgp.model.HpgpBusyIdlePrediction; +import cn.sh.stc.sict.theme.hpgp.vo.DeptPredictionVO; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -19,5 +20,5 @@ public interface HpgpBusyIdlePredictionService extends IService busyIdlePrediction(String deptName); + List busyIdlePrediction(String deptName); } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpBusyIdlePredictionServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpBusyIdlePredictionServiceImpl.java index 6ab7b45..ee9e01e 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpBusyIdlePredictionServiceImpl.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpBusyIdlePredictionServiceImpl.java @@ -1,20 +1,30 @@ package cn.sh.stc.sict.theme.hpgp.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.db.DaoTemplate; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONUtil; +import cn.sh.stc.sict.cloud.common.core.util.NumberUtil; +import cn.sh.stc.sict.cloud.common.core.util.R; import cn.sh.stc.sict.theme.hpgp.dao.HpgpBusyIdlePredictionMapper; import cn.sh.stc.sict.theme.hpgp.dao.HpgpDepartmentRankMapper; import cn.sh.stc.sict.theme.hpgp.model.HpgpBusyIdlePrediction; import cn.sh.stc.sict.theme.hpgp.model.HpgpDepartmentRank; import cn.sh.stc.sict.theme.hpgp.service.HpgpBusyIdlePredictionService; +import cn.sh.stc.sict.theme.hpgp.vo.DeptPredictionVO; +import cn.sh.stc.sict.theme.hpgp.vo.DeptRankVO; +import cn.sh.stc.sict.theme.hphy.wd.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -23,31 +33,81 @@ import java.util.stream.Collectors; * @author zhangly * @since 2022-01-14 09:56:43 */ +@Slf4j @AllArgsConstructor @Service("hpgpBusyIdlPredictionService") public class HpgpBusyIdlePredictionServiceImpl extends ServiceImpl implements HpgpBusyIdlePredictionService { private final HpgpDepartmentRankMapper departmentRankMapper; @Override - public List busyIdlePrediction(String deptName) { + public List busyIdlePrediction(String deptName) { // 查询科室排名 // 组装医院代码、科室代码 // 查询医院忙闲 - List deptRank = departmentRankMapper.getRankByStandardDept(deptName, 3); - if (CollectionUtil.isEmpty(deptRank)) { + List rankList = departmentRankMapper.getRankByStandardDept(deptName, 3); + if (CollectionUtil.isEmpty(rankList)) { return null; } - Set hospitalCodes = deptRank.stream().map(HpgpDepartmentRank::getHospitalCode).collect(Collectors.toSet()); - Set deptCodes = deptRank.stream().map(HpgpDepartmentRank::getDeptCode).collect(Collectors.toSet()); - - DateTime today = DateUtil.date(); - DateTime nextDay = DateUtil.offsetDay(DateUtil.date(), 7); - return this.list( - new LambdaQueryWrapper() - .in(HpgpBusyIdlePrediction::getHospitalCode, hospitalCodes) - .in(HpgpBusyIdlePrediction::getDeptCode, deptCodes) - .gt(HpgpBusyIdlePrediction::getPredictionDate, today) - .le(HpgpBusyIdlePrediction::getPredictionDate, nextDay) - ); + DateTime startTime = DateUtil.date(); + DateTime endTime = DateUtil.offsetDay(DateUtil.date(), 7); + List result = new ArrayList<>(); + rankList.forEach(rank -> { + List rankResult = new ArrayList<>(); + DeptInfo deptInfo = new DeptInfo(); + deptInfo.setHosOrgCode(rank.getHospitalCode()); + deptInfo.setOneDeptCode(rank.getOneDeptCode()); + deptInfo.setDeptCode(rank.getSubDeptCode()); + List outPatInfo = WanDaHttpUtil.getResourceOutPatInfo(deptInfo); + if (CollUtil.isNotEmpty(outPatInfo)) { + Map dateResultMap = new HashMap<>(); + outPatInfo.forEach(pat -> { + NumSourceInfo numSourceInfo = new NumSourceInfo(); + numSourceInfo.setHosOrgCode(rank.getHospitalCode()); + numSourceInfo.setOneDeptCode(rank.getOneDeptCode()); + numSourceInfo.setDeptCode(rank.getSubDeptCode()); + numSourceInfo.setStartTime(DateUtil.format(startTime, DatePattern.NORM_DATE_FORMAT)); + numSourceInfo.setEndTime(DateUtil.format(endTime, DatePattern.NORM_DATE_FORMAT)); + numSourceInfo.setOrderType(WanDaConstant.ORDER_TYPE_CLINC); + numSourceInfo.setPatient_type(WanDaConstant.PATIENT_TYPE_NORMAL); + numSourceInfo.setResourceCode(pat.getResourceCode()); + List orderNumInfo = WanDaHttpUtil.getOrderNumInfo(numSourceInfo); + if (CollUtil.isNotEmpty(orderNumInfo)) { + Map> dateMap = orderNumInfo.stream().collect(Collectors.groupingBy(NumSourceInfo::getScheduleDate)); + dateMap.forEach((date, numList) -> { + DeptPredictionVO vo = dateResultMap.getOrDefault(date, new DeptPredictionVO()); + vo.setDeptCode(rank.getDeptCode()); + vo.setDeptName(rank.getDeptName()); + vo.setHospitalName(rank.getHospitalName()); + vo.setHospitalCode(rank.getHospitalCode()); + vo.setPredictionDate(DateUtil.parseDate(date)); + int reserveOrderNum = numList.stream().mapToInt(NumSourceInfo::getReserveOrderNum).sum(); + vo.setReserveOrderNum(NumberUtil.isNullOrZero(vo.getReserveOrderNum()) ? reserveOrderNum : vo.getReserveOrderNum() + reserveOrderNum); + int remain = numList.stream().mapToInt(NumSourceInfo::getRemainNum).sum(); + vo.setRemainNum(NumberUtil.isNullOrZero(vo.getRemainNum()) ? remain : vo.getRemainNum() + remain); + vo.setScoreByNum(); + dateResultMap.put(date, vo); + }); + } + }); + dateResultMap.forEach((k, v) -> { + rankResult.add(v); + }); + } + // 生成无号源信息 + if (CollUtil.isEmpty(rankResult)) { + for (Date i = DateUtil.offsetDay(startTime, 1); DateUtil.compare(i, endTime) < 1; i = DateUtil.offsetDay(i, 1)) { + DeptPredictionVO vo = new DeptPredictionVO(); + vo.setDeptCode(rank.getDeptCode()); + vo.setDeptName(rank.getDeptName()); + vo.setHospitalName(rank.getHospitalName()); + vo.setHospitalCode(rank.getHospitalCode()); + vo.setPredictionDate(i); + vo.setScoreByNum(); + result.add(vo); + } + } + result.addAll(rankResult); + }); + return result; } } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptPredictionVO.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptPredictionVO.java new file mode 100644 index 0000000..92a5021 --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptPredictionVO.java @@ -0,0 +1,31 @@ +package cn.sh.stc.sict.theme.hpgp.vo; + +import cn.sh.stc.sict.cloud.common.core.util.NumberUtil; +import cn.sh.stc.sict.theme.hpgp.model.HpgpBusyIdlePrediction; +import lombok.Data; + +@Data +public class DeptPredictionVO extends HpgpBusyIdlePrediction { + private Integer reserveOrderNum; + private Integer remainNum; + + // 可用号源 / 号源 + // >=0.5 0- 闲 -绿色 + // 0.2-0.5 1-忙碌-黄色 + // <=0.2 2-非常忙碌-红色 + // 无号院 -1 灰色 + public void setScoreByNum() { + if (NumberUtil.isNotNullOrZero(this.reserveOrderNum)) { + double roate = this.remainNum * 1.0 / this.reserveOrderNum; + if (roate >= 0.5) { + this.setScore(0); + } else if (roate > 0.2 && roate < 0.5) { + this.setScore(1); + } else { + this.setScore(2); + } + } else { + this.setScore(-1); + } + } +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptRankVO.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptRankVO.java new file mode 100644 index 0000000..d603b8a --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/vo/DeptRankVO.java @@ -0,0 +1,10 @@ +package cn.sh.stc.sict.theme.hpgp.vo; + +import cn.sh.stc.sict.theme.hpgp.model.HpgpDepartmentRank; +import lombok.Data; + +@Data +public class DeptRankVO extends HpgpDepartmentRank { + private String oneDeptCode; + private String subDeptCode; +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/WDController.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/WDController.java index 6900df1..92ef373 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/WDController.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/WDController.java @@ -6,7 +6,11 @@ import cn.hutool.core.util.RandomUtil; import cn.sh.stc.sict.cloud.common.core.constant.Constant; import cn.sh.stc.sict.cloud.common.core.util.R; import cn.sh.stc.sict.cloud.common.core.util.ValidateCodeUtil; +import cn.sh.stc.sict.theme.hpgp.model.HpgpDepartmentRank; +import cn.sh.stc.sict.theme.hpgp.service.HpgpDepartmentRankService; +import cn.sh.stc.sict.theme.hphy.service.HpDeptInfoService; import cn.sh.stc.sict.theme.hphy.wd.*; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -29,6 +33,10 @@ public class WDController { @Autowired private StringRedisTemplate redisTemplate; + @Autowired + private HpgpDepartmentRankService hpgpDepartmentRankService; + @Autowired + private HpDeptInfoService hpDeptInfoService; /** * 0. 发短信 diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDeptInfoServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDeptInfoServiceImpl.java index ca6b770..f9d6915 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDeptInfoServiceImpl.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDeptInfoServiceImpl.java @@ -9,6 +9,9 @@ import cn.sh.stc.sict.theme.hphy.model.HpDocInfo; import cn.sh.stc.sict.theme.hphy.model.HpHosInfo; import cn.sh.stc.sict.theme.hphy.service.HpDeptInfoService; import cn.sh.stc.sict.theme.hphy.vo.DeptDoctorsVO; +import cn.sh.stc.sict.theme.hphy.wd.DeptInfo; +import cn.sh.stc.sict.theme.hphy.wd.DoctInfo; +import cn.sh.stc.sict.theme.hphy.wd.WanDaHttpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; @@ -57,6 +60,10 @@ public class HpDeptInfoServiceImpl extends ServiceImpl doctors = hpDocInfoMapper.selectList(docWrapper); + // 查询可预约医生信息 + DeptInfo info = new DeptInfo(); + List resourceDoctInfo = WanDaHttpUtil.getResourceDoctInfo(info); + return new DeptDoctorsVO(hosInfo, deptInfo, doctors); } } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/NumSourceInfo.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/NumSourceInfo.java index ae3ba84..f65b3f6 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/NumSourceInfo.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/NumSourceInfo.java @@ -31,6 +31,6 @@ public class NumSourceInfo { private String visitCost; private String scheduleDate; private String timeRange; - private String remainNum; - private String reserveOrderNum; + private Integer remainNum; + private Integer reserveOrderNum; } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/WanDaHttpUtil.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/WanDaHttpUtil.java index ab49f2b..f9e701f 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/WanDaHttpUtil.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/wd/WanDaHttpUtil.java @@ -197,7 +197,6 @@ public class WanDaHttpUtil { */ public List getOrderNumInfo(NumSourceInfo numSourceInfo) { String xml = WanDaUtil.GetOrderNumInfoServiceXML(numSourceInfo); - System.out.println(xml); String body = HttpRequest.post(URL) .body(xml) .execute() @@ -207,7 +206,7 @@ public class WanDaHttpUtil { log.error("号源查询 失败"); return null; } - log.info("号源查询:body = {}", body); + // log.info("号源查询:body = {}", body); String returnXml = getReturn(body, "GetOrderNumInfoService"); if (Constant.STRING_NO.equals(getCode(returnXml))) { Document document = XmlUtil.readXML(returnXml); @@ -450,7 +449,7 @@ public class WanDaHttpUtil { log.error("查询门诊信息失败"); return null; } - log.info("查询门诊信息:body = {}", body); + // log.info("查询门诊信息:body = {}", body); String returnXml = getReturn(body, "GetResourceOutPatInfoService"); return serialOutPatInfo(returnXml); } diff --git a/smart-health-modules/theme-schema/src/main/resources/logback-spring.xml b/smart-health-modules/theme-schema/src/main/resources/logback-spring.xml index c7f769b..66c1dd8 100644 --- a/smart-health-modules/theme-schema/src/main/resources/logback-spring.xml +++ b/smart-health-modules/theme-schema/src/main/resources/logback-spring.xml @@ -63,7 +63,7 @@ - + diff --git a/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpBusyIdlePredictionMapper.xml b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpBusyIdlePredictionMapper.xml index 3d2d7c0..7100030 100644 --- a/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpBusyIdlePredictionMapper.xml +++ b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpBusyIdlePredictionMapper.xml @@ -13,5 +13,6 @@ hospital_code - , hospital_name, dept_code, dept_name, prediction_date, score + , hospital_name, dept_code, dept_name, prediction_date, score + diff --git a/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpDepartmentRankMapper.xml b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpDepartmentRankMapper.xml index c821770..d1fe064 100644 --- a/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpDepartmentRankMapper.xml +++ b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpDepartmentRankMapper.xml @@ -13,9 +13,19 @@ standard_dept , hospital_code, hospital_name, dept_code, dept_name, rank_score - + select dr.standard_dept standardDept, + dr.hospital_code hospitalCode, + dr.hospital_name hospitalName, + dr.dept_code deptCode, + dr.dept_name deptName, + dr.rank_score rankScore, + d.one_dept_code oneDeptCode, + d.dept_code subDeptCode + from hpgp_department_rank dr + left join hp_dept_info d on (dr.hospital_code = d.hos_org_code and dr.dept_code = d.dept_code) + where dr.standard_dept = #{deptName} + order by dr.rank_score asc + limit #{size} -- 2.22.0