微信后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
11 KiB

package com.ynxbd.common.service;
import com.ynxbd.common.bean.Dept;
import com.ynxbd.common.bean.Doctor;
import com.ynxbd.common.bean.ai.AIDept;
import com.ynxbd.common.bean.ai.AIDoctor;
import com.ynxbd.common.dao.RegisterDao;
import com.ynxbd.common.dao.his.HisRegisterDao;
import com.ynxbd.common.helper.common.DateHelper;
import com.ynxbd.common.helper.common.URLHelper;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.wx.config.AIGuidanceConfig;
import com.ynxbd.wx.config.WeChatConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class AIGuidanceService {
/**
* 查询医院详细信息
*
* @param hosId 医院id
* @return result
*/
public Result getHospDetail(String hosId) {
log.info("[智能导诊]查询医院详细信息 hosId={}", hosId);
if (ObjectUtils.isEmpty(hosId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Map<String, Object>> resultList = new ArrayList<>();
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) {
return Result.success(ResultEnum.AI_SUCCESS, resultList);
}
Map<String, Object> map = new HashMap<>();
map.put("hosId", AIGuidanceConfig.HOS_ID);
map.put("branchId", ""); // 如果有分院,则填写分院Id, 主院的分院Id为hosId本身
map.put("hosName", AIGuidanceConfig.HOS_NAME); // 如果是分院,则填写分院名称,否则填写主院名称
map.put("hosIntro", AIGuidanceConfig.HOS_INTRO);
map.put("hosLevel", AIGuidanceConfig.HOS_LEVEL);
map.put("hosAddress", AIGuidanceConfig.HOS_ADDRESS);
map.put("hosTelephone", AIGuidanceConfig.HOS_TELEPHONE);
map.put("hosImage", WeChatConfig.getBaseURL(true) + "config/logo.png");
map.put("appId", WeChatConfig.APP_ID); // 公众号appid
map.put("hosUrl", WeChatConfig.getWebReqURL(true) + "app.html"); // 公众号appid
map.put("originAppid", ""); // 小程序原始id
map.put("location", ""); // 经纬度,逗号分割
map.put("miniAppId", ""); // 经纬度,逗号分割
map.put("isHTML", false); // 经纬度,逗号分割
resultList.add(map);
return Result.success(ResultEnum.AI_SUCCESS, resultList);
}
/**
* 科室列表
*
* @param hosId 医院id
* @param branchId 分院id
* @return list
*/
public Result getDeptList(String hosId, String branchId) {
log.info("[智能导诊]科室列表查询 hosId={}, branchId={}", hosId, branchId);
if (ObjectUtils.isEmpty(hosId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<AIDept> dataList = new ArrayList<>();
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) { // 医院id校验
log.warn("[智能导诊]科室列表查询-hosId不匹配");
return Result.success(ResultEnum.AI_SUCCESS, dataList);
}
List<Dept> deptList;
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) { // 分时段
String curDate = DateHelper.getCurDate();
deptList = new HisRegisterDao().getTimeDeptList(curDate, DateHelper.getMoveDate(curDate, 7), "");
} else {
deptList = new RegService().queryHisRegDeptList();
}
String webReqURL = WeChatConfig.getWebReqURL(true);
AIDept addItem;
List<Dept> children;
for (Dept dept : deptList) {
addItem = createAIDept(webReqURL, dept);
if (addItem == null) {
continue;
}
dataList.add(addItem);
children = dept.getChildren();
if (children != null && !children.isEmpty()) {
for (Dept childDept : children) {
childDept.setSubDeptCode(childDept.getDeptCode());
childDept.setDeptCode(dept.getDeptCode());
addItem = createAIDept(webReqURL, childDept);
if (addItem == null) {
continue;
}
dataList.add(addItem);
}
}
}
return Result.success(ResultEnum.AI_SUCCESS, dataList);
}
private AIDept createAIDept(String webReqURL, Dept dept) {
AIDept item = new AIDept();
String subDeptCode = dept.getSubDeptCode();
boolean isSubDept = !ObjectUtils.isEmpty(subDeptCode);
String deptName = dept.getDeptName();
if (!ObjectUtils.isEmpty(dept.getDeptAlias())) {
deptName = dept.getDeptAlias();
}
item.setDeptId(dept.getDeptCode());
item.setDeptName(deptName);
item.setDeptIntro(dept.getDescription() == null ? "" : dept.getDescription()); // 科室简介
item.setDeptAddr(dept.getAddress() == null ? "" : dept.getAddress()); // 科室地址
item.setLevel(2);
item.setParentDeptId(isSubDept ? dept.getDeptCode() : "");
item.setFeatureFlag(0); // 是否特色科室
item.setTreatrange(""); // 诊疗范围
item.setIsHTML(true);
item.setDeptMiniWxUrl("");
item.setDeptMiniAlipayUrl("");
item.setDeptLifeAlipayUrl("");
item.setDeptEmbedAlipayUrl("");
try {
subDeptCode = isSubDept ? ("&subDeptCode=" + subDeptCode) : "";
item.setDeptUrl(webReqURL + "reg-reserve.html#/reg-doctor?deptCode=" + dept.getDeptCode() + "&deptName=" + URLHelper.encodeURL(deptName) + subDeptCode + "&hospitalArea=");
} catch (Exception e) {
log.error("[智能导诊]科室链接异常:{}", e.getMessage());
return null;
}
return item;
}
/**
* [医生列表]
*
* @param hosId 医院id
* @param branchId 分院id
* @param deptId 科室id
* @return list
*/
public Result getDoctorList(String hosId, String branchId, String deptId) {
log.info("[智能导诊]医生列表查询 hosId={}, branchId={}, deptId={}", hosId, branchId, deptId);
if (ObjectUtils.isEmpty(hosId) || ObjectUtils.isEmpty(deptId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) { // 医院id校验
log.warn("[智能导诊]医生列表查询-hosId不匹配");
return Result.success(ResultEnum.AI_SUCCESS, new ArrayList<>());
}
List<Doctor> doctorList;
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) { // 分时段
String curDate = DateHelper.getCurDate();
doctorList = new HisRegisterDao().queryHisTimeRegDoctorList(deptId, branchId, curDate, DateHelper.getMoveDate(curDate, 7));
} else {
HisRegisterDao hisRegisterDao = new HisRegisterDao();
doctorList = hisRegisterDao.queryHisResRegDoctorList(deptId, null);
List<Doctor> todayDoctorList = hisRegisterDao.queryHisRegTodayDoctorList(deptId, null);
for (Doctor doctor : todayDoctorList) {
Doctor findItem = doctorList.stream().filter(o -> o.getDoctCode().equals(doctor.getDoctCode())).findFirst().orElse(null);
if (findItem == null) {
doctorList.add(doctor);
}
}
}
List<AIDoctor> dataList = aiDoctorHandle(doctorList);
return Result.success(ResultEnum.AI_SUCCESS, dataList);
}
public List<AIDoctor> aiDoctorHandle(List<Doctor> doctorList) {
List<AIDoctor> resultList = new ArrayList<>();
String webReqURL = WeChatConfig.getWebReqURL(true);
doctorList = new DoctorService().doctorListFilter(doctorList);
RegisterDao registerDao = new RegisterDao();
List<Dept> wxDeptList = registerDao.selectDeptList();
String domain = WeChatConfig.getDomain(true);
String deptName, deptCode, headImg, doctCode;
Dept dept;
AIDoctor item;
for (Doctor doctor : doctorList) {
item = new AIDoctor();
doctCode = doctor.getDoctCode();
if (ObjectUtils.isEmpty(doctCode)) {
continue;
}
doctCode = doctCode.trim();
if ("*".equals(doctCode)) { // 任意医生
item.setDoctorId("0");
item.setDoctorSex(-1);
doctCode = "0";
} else {
item.setDoctorSex(-1);
}
deptCode = doctor.getDeptCode();
deptName = doctor.getDeptName();
item.setDoctorId(doctCode);
item.setDoctorName(doctor.getDoctName());
item.setDoctorJobTitle(doctor.getTitle() == null ? "" : doctor.getTitle()); // 职称
item.setDoctorGoodat(doctor.getSkill() == null ? "" : doctor.getSkill()); // 擅长
item.setDoctorIntro(ObjectUtils.isEmpty(doctor.getDescription()) ? "暂无介绍" : doctor.getDescription()); // 介绍
headImg = doctor.getHeadImg();
if (headImg != null && !ObjectUtils.isEmpty(headImg.trim())) {
if (!headImg.contains("data:image/")) { // 不是base64
item.setDoctorImage(domain + headImg); // 头像
}
}
item.setExtraData("{}"); // 额外信息
item.setIsHTML(true);
item.setDoctorMiniWxUrl("");
item.setDoctorMiniAlipayUrl("");
item.setDoctorLifeAlipayUrl("");
item.setDoctorEmbedAlipayUrl("");
dept = registerDao.deptFilter(wxDeptList, deptCode, deptName, null, null);
if (!ObjectUtils.isEmpty(dept.getDeptAlias())) {
deptName = dept.getDeptAlias();
}
try {
//reg-doct-source?date=2026-03-02&deptCode=0501&doctCode=1477&subDeptCode=0001&deptName=%25E5%25A6%2587%25E7%25A7%2591-%25E5%25A6%2587%25E7%25A7%2591%25E6%2599%25AE%25E9%2580%259A%25E9%2597%25A8%25E8%25AF%258A&doctName=%25E6%2598%258E%25E6%25BB%25A1%25E6%25B1%259F&hospitalArea=
Map<String, Object> map = new HashMap<>();
map.put("date", DateHelper.getCurDate());
map.put("deptCode", deptCode);
map.put("deptName", URLHelper.encodeURL(deptName));
map.put("doctName", URLHelper.encodeURL(doctor.getDoctName()));
map.put("doctCode", doctor.getDoctCode());
map.put("subDeptCode", "");
map.put("hospitalArea", "");
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) {
item.setDoctorUrl(webReqURL + "reg-reserve.html#/reg-doct-source" + URLHelper.mapParamsToUrl(map, true));
} else {
item.setDoctorUrl(webReqURL + "reg-reserve.html#/reg-doctor" + URLHelper.mapParamsToUrl(map, true));
}
} catch (Exception e) {
log.error(e.getMessage());
item.setDoctorUrl("");
}
resultList.add(item);
}
return resultList;
}
}