diff --git a/cloud-common/cloud-common-core/libs/openapi-sdk-java-1.0-RELEASE.jar b/cloud-common/cloud-common-core/libs/openapi-sdk-java-1.0-RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..07d3838522ac7af1d5e452c12e8801407c7b4807 Binary files /dev/null and b/cloud-common/cloud-common-core/libs/openapi-sdk-java-1.0-RELEASE.jar differ diff --git a/cloud-common/cloud-common-core/pom.xml b/cloud-common/cloud-common-core/pom.xml index ff0d896f5b9ebbd4ff6b5d59c2579dc022a09d98..32d609195fbc9bc62f2985bfb447f41fca3f6683 100644 --- a/cloud-common/cloud-common-core/pom.xml +++ b/cloud-common/cloud-common-core/pom.xml @@ -80,5 +80,13 @@ org.springframework.boot spring-boot-starter-data-redis + + + com.ngarihealth + openapi-sdk-java + 1.0-RELEASE + system + ${project.basedir}/libs/openapi-sdk-java-1.0-RELEASE.jar + \ No newline at end of file diff --git a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/SecurityConstants.java b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/SecurityConstants.java index ba5a761128dbc4ddde982231886361064c76b426..ff18d8b7c0e690741e4c09d224692299256be6aa 100644 --- a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/SecurityConstants.java +++ b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/SecurityConstants.java @@ -136,6 +136,10 @@ public interface SecurityConstants { * openid */ String DETAILS_APPID = "appid"; + /** + * 医院代码 + */ + String HOSPITAL_CODE = "hospitalCode"; /** * 租户ID 字段 */ diff --git a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/enums/LoginTypeEnum.java b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/enums/LoginTypeEnum.java index 4059a586ce5cf4bc77baecbdf27a586bacc4ad89..7b328989475c66fcc98f1a895db5f60498ac38d3 100644 --- a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/enums/LoginTypeEnum.java +++ b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/constant/enums/LoginTypeEnum.java @@ -27,6 +27,11 @@ public enum LoginTypeEnum { */ SSB("ssb", "随申办token"), + /** + * 公众号香山中医医院 + */ + WOA_XSZY("woa_xszy", "香山中医医院公众号"), + /** * H5登录 */ @@ -51,4 +56,13 @@ public enum LoginTypeEnum { * 描述 */ private final String description; + + public static LoginTypeEnum match(String type) { + for (LoginTypeEnum loginType : LoginTypeEnum.values()) { + if (loginType.getType().equals(type)) { + return loginType; + } + } + return null; + } } diff --git a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/dto/XSZYUserInfo.java b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/dto/XSZYUserInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..95a0b2835dcb6c2c1683596d9bf24ce9e3231189 --- /dev/null +++ b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/dto/XSZYUserInfo.java @@ -0,0 +1,48 @@ +package cn.sh.stc.sict.cloud.common.core.dto; + + +import lombok.Data; + +/** + * 公众号-香山中医医院用户信息 + */ +@Data +public class XSZYUserInfo { + + /** + * 用户ID + */ + private String userId; + + /** + * 就诊人ID + */ + private String mpiId; + + /** + * 姓名 + */ + private String patientName; + + /** + * 证件号 + */ + private String certificate; + + /** + * 证件类型 + */ + private String certificateType; + + /** + * 手机号 + */ + private String mobile; + + /** + * 医院编码 + */ + private String hospitalCode; + + +} diff --git a/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/util/WoaUtil.java b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/util/WoaUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..fc5649bc79cdbd43d977e02373671a802a1ea9b0 --- /dev/null +++ b/cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/util/WoaUtil.java @@ -0,0 +1,76 @@ +package cn.sh.stc.sict.cloud.common.core.util; + +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.convert.Convert; +import cn.sh.stc.sict.cloud.common.core.constant.Constant; +import cn.sh.stc.sict.cloud.common.core.dto.XSZYUserInfo; +import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; +import ngari.openapi.Client; +import ngari.openapi.JSONResponseBean; +import ngari.openapi.Request; +import ngari.openapi.Response; + +/** + * 医院公众号工具类 + *

+ * 注意事项: + * 1.医院编码是否传递 + * 2.手机号必须有,作为用户身份的唯一标识 + */ +@Slf4j +@UtilityClass +public class WoaUtil { + + // 香山中医医院公众号用户信息获取接口地址(纳里) + private final static String XSZY_USER_URL = "https://openapi.ngarihealth.com/openapi/gateway"; + + // 接口授权信息 + private final static String APP_KEY = "ngari635f7f4b0e980e63"; + private final static String APP_SECRET = "0e980e634196fcde"; + + // 获取用户信息服务ID + private final static String SERVICE_ID = "openapi.authenticationService"; + // 获取用户信息方法 + private final static String METHOD = "apiGetUserInfo"; + + // 响应头请求唯一ID + private final static String RESPONSE_HEADER_REQUEST_ID = "X-Ca-Request-Id"; + + // 香山中医医院编码 + private final static String XSZY_HOSPITAL_CODE = "42502905200"; + + /** + * 获取用户信息 + * + * @param ngCode 纳里授权码 + * @return + */ + public XSZYUserInfo getXszyUserInfo(String ngCode) { + + //如果开启加密,则必填 + String encodingAesKey = ""; + Client client = new Client(XSZY_USER_URL, APP_KEY, APP_SECRET, encodingAesKey); + + try { + // 入参说明[授权码,是否回调,拓展参数] + Request request = new Request(SERVICE_ID, METHOD, ListUtil.toList(ngCode, false, null)); + Response response = client.execute(request); + if (response.isSuccess()) { + JSONResponseBean result = response.getJsonResponseBean(); + XSZYUserInfo xszyUserInfo = Convert.convert(XSZYUserInfo.class, result.getBody()); + // 设置医院编码 + xszyUserInfo.setHospitalCode(XSZY_HOSPITAL_CODE); + return xszyUserInfo; + } else { + log.error("香山中医医院公众号token获取用户信息异常-1,requestId = [{}],caError = [{}],error = [{}]", response.getHeader(RESPONSE_HEADER_REQUEST_ID), response.getCaErrorMsg(), response.getErrorMessage()); + return null; + } + } catch (Exception ex) { + log.error("香山中医医院公众号token获取用户信息异-2!"); + log.error(ex.getMessage(), ex); + return null; + } + } + +} diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictUserAuthenticationConverter.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictUserAuthenticationConverter.java index 5f972c0385c05ba4cf8d4e953c7a00f29d09e2d3..c773919a0f43efdc4aaf8154bc26211d453ddf30 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictUserAuthenticationConverter.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictUserAuthenticationConverter.java @@ -19,56 +19,57 @@ import java.util.Map; * @Date */ public class SictUserAuthenticationConverter implements UserAuthenticationConverter { - private static final String N_A = "N/A"; + private static final String N_A = "N/A"; - /** - * Extract information about the user to be used in an access token (i.e. for resource servers). - * - * @param authentication an authentication representing a user - * @return a map of key values representing the unique information about the user - */ - @Override - public Map convertUserAuthentication(Authentication authentication) { - Map response = new LinkedHashMap<>(); - response.put(USERNAME, authentication.getName()); - if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { - response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities())); - } - return response; - } + /** + * Extract information about the user to be used in an access token (i.e. for resource servers). + * + * @param authentication an authentication representing a user + * @return a map of key values representing the unique information about the user + */ + @Override + public Map convertUserAuthentication(Authentication authentication) { + Map response = new LinkedHashMap<>(); + response.put(USERNAME, authentication.getName()); + if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { + response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities())); + } + return response; + } - /** - * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map. - * - * @param map a map of user information - * @return an Authentication representing the user or null if there is none - */ - @Override - public Authentication extractAuthentication(Map map) { - if (map.containsKey(USERNAME)) { - Collection authorities = getAuthorities(map); + /** + * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map. + * + * @param map a map of user information + * @return an Authentication representing the user or null if there is none + */ + @Override + public Authentication extractAuthentication(Map map) { + if (map.containsKey(USERNAME)) { + Collection authorities = getAuthorities(map); - String username = (String) map.get(USERNAME); - Long id = (Long) map.get(SecurityConstants.DETAILS_USER_ID); - String name = (String) map.get(SecurityConstants.DETAILS_NAME); - String openid = (String) map.get(SecurityConstants.DETAILS_OPENID); - String appid = (String) map.get(SecurityConstants.DETAILS_APPID); - SictUser user = new SictUser(id, "", openid, appid, username, N_A, true - , true, true, true, authorities); - return new UsernamePasswordAuthenticationToken(user, N_A, authorities); - } - return null; - } + String username = (String) map.get(USERNAME); + Long id = (Long) map.get(SecurityConstants.DETAILS_USER_ID); + String name = (String) map.get(SecurityConstants.DETAILS_NAME); + String openid = (String) map.get(SecurityConstants.DETAILS_OPENID); + String appid = (String) map.get(SecurityConstants.DETAILS_APPID); + String hospitalCode = (String) map.get(SecurityConstants.HOSPITAL_CODE); + SictUser user = new SictUser(id, "", openid, appid, hospitalCode, username, N_A, true + , true, true, true, authorities); + return new UsernamePasswordAuthenticationToken(user, N_A, authorities); + } + return null; + } - private Collection getAuthorities(Map map) { - Object authorities = map.get(AUTHORITIES); - if (authorities instanceof String) { - return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities); - } - if (authorities instanceof Collection) { - return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils - .collectionToCommaDelimitedString((Collection) authorities)); - } - throw new IllegalArgumentException("Authorities must be either a String or a Collection"); - } + private Collection getAuthorities(Map map) { + Object authorities = map.get(AUTHORITIES); + if (authorities instanceof String) { + return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities); + } + if (authorities instanceof Collection) { + return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils + .collectionToCommaDelimitedString((Collection) authorities)); + } + throw new IllegalArgumentException("Authorities must be either a String or a Collection"); + } } diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUser.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUser.java index dc4a258721f79030cd7927311a563ee6261e1790..e0f1dd06104ac809d801425d4af8a6504d815de0 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUser.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUser.java @@ -35,6 +35,13 @@ public class SictUser extends User { @Setter private String appId; + /** + * 医院公众号登陆的用户包含医院代码 + */ + @Getter + @Setter + private String hospitalCode; + @Getter @Setter private transient String token; @@ -44,6 +51,7 @@ public class SictUser extends User { * {@link DaoAuthenticationProvider}. * * @param id 用户ID + * @param hospitalCode 医院代码 * @param username the username presented to the * DaoAuthenticationProvider * @param password the password that should be presented to the @@ -62,6 +70,7 @@ public class SictUser extends User { String phone, String openId, String appId, + String hospitalCode, String username, String password, boolean enabled, @@ -74,5 +83,6 @@ public class SictUser extends User { this.phone = phone; this.openId = openId; this.appId = appId; + this.hospitalCode = hospitalCode; } } diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUserDetailsServiceImpl.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUserDetailsServiceImpl.java index 0e72e0b181a1d85a736e875856c072ea3164e29c..1bf5b4c6f4e325530f9168d1e8473c834dc8a5f3 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUserDetailsServiceImpl.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/service/SictUserDetailsServiceImpl.java @@ -129,15 +129,15 @@ public class SictUserDetailsServiceImpl implements SictUserDetailsService { if (StrUtil.isBlank(user.getUserName())) { user.setUserName(user.getId().toString()); } - String userName = user.getUserName() + StringPool.COLON + info.getAppId(); String password = SecurityConstants.BCRYPT + user.getPasswd(); // 登录失败5次锁定半小时 boolean nonLockd = !Constant.BYTE_YES.equals(user.getStatus()); - return new SictUser(user.getId(), user.getPhone(), info.getOpenId(), info.getAppId(), userName, password, enabled, + return new SictUser(user.getId(), user.getPhone(), info.getOpenId(), info.getAppId(), info.getHospitalCode(), userName, password, enabled, true, true, nonLockd, authorities); } + private static String getAppId() { String appId = ""; try { diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/util/SecurityUtils.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/util/SecurityUtils.java index e1850c656c051c0b98d81122e738e81d1799506b..fcc3f5c2ce0c48e8c20b5a97c0565ba701473113 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/util/SecurityUtils.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/util/SecurityUtils.java @@ -179,6 +179,7 @@ public class SecurityUtils { current.setOpenId(user.getOpenId()); current.setAppId(user.getAppId()); current.setPhone(user.getPhone()); + current.setHospitalCode(user.getHospitalCode()); } current.setToken(token); return current; diff --git a/pom.xml b/pom.xml index c3be02bf6dad4e0874672b1c663a55fc2be4d638..cec714b3aa0a60d2e89107a83b9b917a04e6b488 100644 --- a/pom.xml +++ b/pom.xml @@ -171,6 +171,9 @@ org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} + + true + diff --git a/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java b/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java index 5f25a56ef67f6496528cf0998eacfa0437fd7859..27ccefceb9c83339a55fb5411abe1170cac8b85c 100644 --- a/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java +++ b/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java @@ -19,6 +19,10 @@ public class CurrentUser implements Serializable { private String appId; private String idNum; private String phone; + /** + * 医院公众号登陆的用户包含医院代码 + */ + private String hospitalCode; private Date createTime; private Byte gender; private Date registerTime; diff --git a/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/UserInfo.java b/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/UserInfo.java index 1d5407f9729589665bc6ad1beda227a44e948f2d..64834bc89d5312c3ea24867a0498421d48b79ba3 100644 --- a/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/UserInfo.java +++ b/smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/UserInfo.java @@ -14,6 +14,11 @@ public class UserInfo { private String openId; private String appId; + /** + * 医院公众号登陆的用户包含医院代码 + */ + private String hospitalCode; + /** * 用户基本信息 */ diff --git a/smart-health-modules/cloud-upms/cloud-upms-biz/src/main/java/cn/sh/stc/sict/cloud/upms/service/impl/SysUserBaseServiceImpl.java b/smart-health-modules/cloud-upms/cloud-upms-biz/src/main/java/cn/sh/stc/sict/cloud/upms/service/impl/SysUserBaseServiceImpl.java index 3d533ee352ee666479ee9e9251c5263042da40d2..ca00fe857c9f4ff96907b27b9de87e8716a826b0 100644 --- a/smart-health-modules/cloud-upms/cloud-upms-biz/src/main/java/cn/sh/stc/sict/cloud/upms/service/impl/SysUserBaseServiceImpl.java +++ b/smart-health-modules/cloud-upms/cloud-upms-biz/src/main/java/cn/sh/stc/sict/cloud/upms/service/impl/SysUserBaseServiceImpl.java @@ -10,8 +10,10 @@ import cn.sh.stc.sict.cloud.common.core.constant.RedisCacheConstant; import cn.sh.stc.sict.cloud.common.core.constant.UserConstant; import cn.sh.stc.sict.cloud.common.core.constant.enums.LoginTypeEnum; import cn.sh.stc.sict.cloud.common.core.dto.WDUserInfo; +import cn.sh.stc.sict.cloud.common.core.dto.XSZYUserInfo; import cn.sh.stc.sict.cloud.common.core.util.NumberUtil; import cn.sh.stc.sict.cloud.common.core.util.SsbUtil; +import cn.sh.stc.sict.cloud.common.core.util.WoaUtil; import cn.sh.stc.sict.cloud.upms.dao.SysUserBaseMapper; import cn.sh.stc.sict.cloud.upms.dto.UserDTO; import cn.sh.stc.sict.cloud.upms.dto.UserInfo; @@ -35,6 +37,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Slf4j @@ -77,18 +80,81 @@ public class SysUserBaseServiceImpl extends ServiceImpl appId = {}, inStr = {}", appId, inStr); // code = 011Eg6Ga1UOXeA0R5wHa16dkab2Eg6G7 String[] split = inStr.split(StringPool.AT); - if (LoginTypeEnum.SMS.getType().equals(split[0])) { + LoginTypeEnum loginType = Optional.ofNullable(LoginTypeEnum.match(split[0])).orElse(LoginTypeEnum.WECHAT); + switch (loginType) { // 手机号登录 - return this.getByPhone(split[2]); - } else if (LoginTypeEnum.SSB.getType().equals(split[0])) { - return this.getBySSBToken(split[0], split[2]); - } else { + case SMS: + return this.getByPhone(split[2]); + // 随身办登陆 + case SSB: + return this.getBySSBToken(split[0], split[2]); + // 香山中医院公众号登陆 + // inStr = 公众号标识符@公众号appId@token@hospitalCode + case WOA_XSZY: + return this.getByXszyWoa(split); // 微信登录 - WxOAuth2AccessToken token = wxMpService.getOAuth2Service().getAccessToken(split[2]); - return this.getByOpenId(token.getOpenId()); + default: + WxOAuth2AccessToken token = wxMpService.getOAuth2Service().getAccessToken(split[2]); + return this.getByOpenId(token.getOpenId()); } } + + /** + * 获取香山中医医院公众号的用户信息 + * + * @param infoArray 登陆信息 ["公众号标识符", "公众号appId", "token"] + * @return + */ + private UserInfo getByXszyWoa(String[] infoArray) { + String source = infoArray[0]; + String token = infoArray[2]; + + XSZYUserInfo xszyUserInfo = WoaUtil.getXszyUserInfo(token); + log.error("woa.login.xszyUser = {}", JSONUtil.toJsonStr(xszyUserInfo)); + if (ObjectUtil.isNull(xszyUserInfo) || StrUtil.isBlank(xszyUserInfo.getUserId())) { + return null; + } + + // 根据用户ID和手机号查询当前用户是否已注册过 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysUserBase::getOpenId, xszyUserInfo.getUserId()) + .or() + .eq(SysUserBase::getPhone, xszyUserInfo.getMobile()) + .orderByDesc(SysUserBase::getUpdateTime) + .last("limit 1"); + SysUserBase user = this.getOne(wrapper); + + // 未注册用户默认注册 + if (user == null) { + user = new SysUserBase(); + user.setUserName(xszyUserInfo.getMobile()); + user.setOpenId(xszyUserInfo.getUserId()); + user.setName(xszyUserInfo.getPatientName()); + // 证件类型为1时,证件号为身份证号 + if (Constant.STRING_YES.equals(xszyUserInfo.getCertificateType())) { + user.setIdCard(xszyUserInfo.getCertificate()); + } + //user.setSex(userInfo.getGender()); + user.setHeadimg(Constant.DEFAULT_AVATAR_IMG); + user.setSource(source); + user.setStatus(Constant.BYTE_NO); + user.setPasswd(ENCODER.encode(Constant.DEFAULT_PASSWORD)); + user.setPhone(xszyUserInfo.getMobile()); + + this.save(user); + } + + UserInfo info = new UserInfo(); + info.setSysUserBase(user); + info.setOpenId(xszyUserInfo.getUserId()); + + // 设置香山中医医院医疗机构代码,后续查询只显示当前医疗机构下的查询结果 + info.setHospitalCode(xszyUserInfo.getHospitalCode()); + return info; + } + + private UserInfo getBySSBToken(String source, String token) { WDUserInfo wdUser = SsbUtil.getUserInfo(token); log.error("ssb.login.wdUser = {}", JSONUtil.toJsonStr(wdUser)); diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpHzjlController.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpHzjlController.java index a581f81f646430deac9a6613d0ed1a5e87982fa6..d1d827f33548db199c881699af2d5f07b6ba9a59 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpHzjlController.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpHzjlController.java @@ -4,25 +4,22 @@ package cn.sh.stc.sict.theme.hpgp.controller.mobile; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; +import cn.sh.stc.sict.cloud.common.core.util.R; import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils; import cn.sh.stc.sict.cloud.upms.dto.CurrentUser; import cn.sh.stc.sict.theme.hpgp.model.HpgpBusyIdlePrediction; +import cn.sh.stc.sict.theme.hpgp.service.HpHzjlService; import cn.sh.stc.sict.theme.hphy.model.HpDocInfo; import cn.sh.stc.sict.theme.hphy.model.HphyPatientBase; import cn.sh.stc.sict.theme.hphy.service.HphyPatientBaseService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import cn.sh.stc.sict.cloud.common.core.util.R; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import cn.sh.stc.sict.theme.hpgp.model.HpHzjl; -import cn.sh.stc.sict.theme.hpgp.service.HpHzjlService; -import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; -import java.io.Serializable; import java.util.List; /** @@ -56,7 +53,7 @@ public class HpHzjlController { log.error("patient = {}", JSONUtil.toJsonStr(patient)); return new R().error("患者信息异常!"); } - List result = hpHzjlService.listByCertId(patient.getCertId()); + List result = hpHzjlService.listByCertIdAndHosCode(patient.getCertId(), current.getHospitalCode()); return new R(result); } @@ -75,7 +72,7 @@ public class HpHzjlController { return new R().error("患者信息异常!"); } - List result = hpHzjlService.listDoctorByCertId(patient.getCertId()); + List result = hpHzjlService.listDoctorByCertIdAndHosCode(patient.getCertId(), current.getHospitalCode()); return new R(result); } } diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpgpBusyIdlePredictionController.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpgpBusyIdlePredictionController.java index e331af21e5c40962a86cc958a8e2f30f2cd454aa..e75aa9c5dacc94aacee07d555dba551256cad1b4 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpgpBusyIdlePredictionController.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpgpBusyIdlePredictionController.java @@ -2,11 +2,13 @@ package cn.sh.stc.sict.theme.hpgp.controller.mobile; import cn.sh.stc.sict.cloud.common.core.util.R; +import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils; import cn.sh.stc.sict.theme.hpgp.service.HpgpBusyIdlePredictionService; import com.baomidou.mybatisplus.extension.api.ApiController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController; * @author zhangly * @since 2022-01-14 09:56:44 */ +@Slf4j @Api(value = "[C] 黄浦全科导诊——忙闲预测维护接口", tags = "[C] 黄浦全科导诊——忙闲预测维护接口") @RestController @RequestMapping("/hpgp/c/busyidleprediction") @@ -29,8 +32,8 @@ public class HpgpBusyIdlePredictionController extends ApiController { private final HpgpBusyIdlePredictionService hpgpBusyIdlePredictionService; @GetMapping - public R busyIdlePrediction(@ApiParam("标准科室名称") @RequestParam("deptName") String deptName){ - return new R<>().success(hpgpBusyIdlePredictionService.busyIdlePrediction(deptName)); + public R busyIdlePrediction(@ApiParam("标准科室名称") @RequestParam("deptName") String deptName) { + return new R<>().success(hpgpBusyIdlePredictionService.busyIdlePrediction(SecurityUtils.getCurrentUser().getHospitalCode(), deptName)); } } 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 597e714946d440d9e7e4ebfbfa074509d8a8c042..6b4189c2385a6839780e9fb9fd63ca0e20104f19 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 @@ -16,9 +16,13 @@ import java.util.List; public interface HpgpDepartmentRankMapper extends BaseMapper { /** * 根据标准科室名称查询医院科室排名 - * @param deptName 标准科室名称 - * @param size 查询记录数 默认3条 + * + * @param hospitalCode 医疗机构代码 + * @param deptName 标准科室名称 + * @param size 查询记录数 默认3条 * @return */ - List getRankByStandardDept(@Param("deptName") String deptName, @Param("size") int size); + List getRankByHosAndStandardDept(@Param("hospitalCode") String hospitalCode, + @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/dao/HpgpKsHotMapper.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpKsHotMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..f5aefabb8da93ca50c1682e59716725b517a89f4 --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/dao/HpgpKsHotMapper.java @@ -0,0 +1,14 @@ +package cn.sh.stc.sict.theme.hpgp.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import cn.sh.stc.sict.theme.hpgp.model.HpgpKsHot; + +/** + * (HpgpKsHot)表数据库访问层 + * + * @author gao + * @since 2022-11-07 10:33:21 + */ +public interface HpgpKsHotMapper extends BaseMapper { + +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpKsHot.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpKsHot.java new file mode 100644 index 0000000000000000000000000000000000000000..817a54ade0ed996c879f95f2f2bb8bfea9ca8eb7 --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/model/HpgpKsHot.java @@ -0,0 +1,46 @@ +package cn.sh.stc.sict.theme.hpgp.model; + + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.io.Serializable; + +/** + * (HpgpKsHot)表实体类 + * + * @author makejava + * @since 2022-11-07 10:33:21 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class HpgpKsHot extends Model { + //医疗结构代码(ALL表示全区) + @ApiModelProperty(hidden=false, value="医疗结构代码(ALL表示全区)") + private String gzh; + + @ApiModelProperty(hidden=false, value="标准科室") + private String standardDept; + + @ApiModelProperty(hidden=false, value="医院代码") + private String hospitalCode; + + @ApiModelProperty(hidden=false, value="医院名称") + private String hospitalName; + + @ApiModelProperty(hidden=false, value="一级科室代码") + private String oneDeptCode; + + @ApiModelProperty(hidden=false, value="科室代码") + private String deptCode; + + @ApiModelProperty(hidden=false, value="科室名称") + private String deptName; + //科室排名 + @ApiModelProperty(hidden=false, value="科室排名") + private byte rankScore; + + + +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpHzjlService.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpHzjlService.java index 2f256bcee1bb0afe481bd16d8c6bd7bbcb40366f..48e65431bf44a375f70e7416605c0e51c9ce1734 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpHzjlService.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpHzjlService.java @@ -1,9 +1,9 @@ package cn.sh.stc.sict.theme.hpgp.service; +import cn.sh.stc.sict.theme.hpgp.model.HpHzjl; import cn.sh.stc.sict.theme.hpgp.model.HpgpBusyIdlePrediction; import cn.sh.stc.sict.theme.hphy.model.HpDocInfo; import com.baomidou.mybatisplus.extension.service.IService; -import cn.sh.stc.sict.theme.hpgp.model.HpHzjl; import java.util.List; @@ -15,7 +15,22 @@ import java.util.List; */ public interface HpHzjlService extends IService { - List listByCertId(String certId); + /** + * 根据身份证号和医院查找最后三次不同科室就诊记录,并计算忙闲 + * 如果未找到,则推送三个热门科室 + * + * @param certId 身份证号 + * @param hospCode 医疗机构代码(医院编码) + * @return + */ + List listByCertIdAndHosCode(String certId, + String hospCode); - List listDoctorByCertId(String certId); + /** + * @param certId 身份证号 + * @param hospCode 医疗机构代码(医院编码) + * @return + */ + List listDoctorByCertIdAndHosCode(String certId, + String hospCode); } 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 99176c3b8266c9c08b541214c4f099a8e93e3c51..498ef1562ad548d35a5a44dd28954b3b65e26a62 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 @@ -19,10 +19,14 @@ public interface HpgpBusyIdlePredictionService extends IService busyIdlePrediction(String deptName); + List busyIdlePrediction(String hospitalCode, String deptName); void statisticResourceInfo(HpgpDepartmentRank dept, Date startDate, Date endDate, Byte flag); diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpKsHotService.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpKsHotService.java new file mode 100644 index 0000000000000000000000000000000000000000..e2677e590ede3bc76fec637298416232dee3ecd0 --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/HpgpKsHotService.java @@ -0,0 +1,24 @@ +package cn.sh.stc.sict.theme.hpgp.service; + +import cn.sh.stc.sict.theme.hpgp.model.HpgpKsHot; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + * (HpgpKsHot)表服务接口 + * + * @author gao + * @since 2022-11-07 10:33:21 + */ +public interface HpgpKsHotService extends IService { + + /** + * 根据医疗机构代码查询热门科室 + * + * @param yljgdm 医疗机构代码 + * @return + */ + List listHotDept(String yljgdm); + +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpHzjlServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpHzjlServiceImpl.java index 85418886b9a30689c72bf518a15fa7a0a690bd5c..7179aa563d9d48e21bd544551854704fbb314c9a 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpHzjlServiceImpl.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpHzjlServiceImpl.java @@ -4,20 +4,23 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.sh.stc.sict.theme.hpgp.dao.HpHzjlMapper; +import cn.sh.stc.sict.theme.hpgp.model.HpHzjl; 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.model.HpgpKsHot; +import cn.sh.stc.sict.theme.hpgp.service.HpHzjlService; import cn.sh.stc.sict.theme.hpgp.service.HpgpBusyIdlePredictionService; import cn.sh.stc.sict.theme.hpgp.service.HpgpDepartmentRankService; +import cn.sh.stc.sict.theme.hpgp.service.HpgpKsHotService; import cn.sh.stc.sict.theme.hphy.model.HpDocInfo; -import cn.sh.stc.sict.theme.hphy.model.HphyDoctor; import cn.sh.stc.sict.theme.hphy.service.HpDocInfoService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import cn.sh.stc.sict.theme.hpgp.dao.HpHzjlMapper; -import cn.sh.stc.sict.theme.hpgp.model.HpHzjl; -import cn.sh.stc.sict.theme.hpgp.service.HpHzjlService; import lombok.AllArgsConstructor; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -36,22 +39,26 @@ public class HpHzjlServiceImpl extends ServiceImpl impleme private final HpgpDepartmentRankService hpgpDepartmentRankService; private final HpgpBusyIdlePredictionService hpgpBusyIdlePredictionService; private final HpDocInfoService hpDocInfoService; + private final HpgpKsHotService hpgpKsHotService; /** * 根据身份证号查找最后三次不同科室就诊记录,并计算忙闲 * 如果未找到,则推送三个热门科室 * - * @param certId + * @param certId 身份证号 + * @param hospitalCode 医疗机构代码(医院编码) * @return */ @Override - public List listByCertId(String certId) { + public List listByCertIdAndHosCode(String certId, + String hospitalCode) { List result = new ArrayList<>(); DateTime startTime = DateUtil.tomorrow(); DateTime endTime = DateUtil.offsetDay(startTime, 6); LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.eq(HpHzjl::getZjhm, certId) + .eq(StrUtil.isNotBlank(hospitalCode), HpHzjl::getYljgdm, hospitalCode) .groupBy(HpHzjl::getJzksbm) .orderByDesc(HpHzjl::getJzksrq) .last("limit 10"); @@ -70,9 +77,13 @@ public class HpHzjlServiceImpl extends ServiceImpl impleme result.addAll(hpgpBusyIdlePredictionService.listByDeptRank(dept, startTime, endTime)); } } + + // 历史科室查询结果为空时,采用热点科室数据 if (CollUtil.isEmpty(result)) { - List rankList = hpgpDepartmentRankService.listHotDept(); - rankList.forEach(rank -> { + List hotList = hpgpKsHotService.listHotDept(hospitalCode); + hotList.forEach(hot -> { + HpgpDepartmentRank rank = new HpgpDepartmentRank(); + BeanUtils.copyProperties(hot, rank); result.addAll(hpgpBusyIdlePredictionService.listByDeptRank(rank, startTime, endTime)); }); } @@ -81,9 +92,11 @@ public class HpHzjlServiceImpl extends ServiceImpl impleme } @Override - public List listDoctorByCertId(String certId) { + public List listDoctorByCertIdAndHosCode(String certId, + String hospitalCode) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.eq(HpHzjl::getZjhm, certId) + .eq(StrUtil.isNotBlank(hospitalCode), HpHzjl::getYljgdm, hospitalCode) .groupBy(HpHzjl::getYljgdm, HpHzjl::getJzksbm, HpHzjl::getZzysgh) .orderByDesc(HpHzjl::getJzksrq) .last("limit 10"); @@ -97,7 +110,7 @@ public class HpHzjlServiceImpl extends ServiceImpl impleme .eq(HpDocInfo::getResourceName, r.getZzysxm()) .last("limit 1"); HpDocInfo one = hpDocInfoService.getOne(dw); - if(ObjectUtil.isNotNull(one)){ + if (ObjectUtil.isNotNull(one)) { doctorList.add(one); } }); 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 9afa8b320fbf2d18684e21b02747f19854216699..4ff1a8444d4918b44de0a440ab736cb8b4e5bbe1 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 @@ -22,7 +22,6 @@ 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.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.*; @@ -42,24 +41,85 @@ public class HpgpBusyIdlePredictionServiceImpl extends ServiceImpl busyIdlePrediction(String deptName) { - // 查询科室排名 - // 组装医院代码、科室代码 - // 查询医院忙闲 - List rankList = departmentRankMapper.getRankByStandardDept(deptName, 3); + public List busyIdlePrediction(String hospitalCode, + String deptName) { + + // 查询当前医院有号的三个科室 + if (StrUtil.isNotBlank(hospitalCode)) { + return busyIdlePredictionByHosCodeAndDeptName(hospitalCode, deptName); + } + + // 在科室排名表中查询排名前三的科室展示 + return busyIdlePredictionByDeptName(deptName); + } + + /** + * 按科室名称查询全区排名前3的科室 + * + * @param deptName 科室名称 + * @return HpgpBusyIdlePrediction {@link HpgpBusyIdlePrediction} + */ + private List busyIdlePredictionByDeptName(String deptName) { + List rankList = departmentRankMapper.getRankByHosAndStandardDept(null, deptName, 3); if (CollectionUtil.isEmpty(rankList)) { return null; } + + return busyIdlePrediction(rankList); + } + + + /** + * 查询当前医院有号的三个科室 + * + * @param hospitalCode 医院编码 + * @param deptName 部门名称 + * @return HpgpBusyIdlePrediction {@link HpgpBusyIdlePrediction} + */ + private List busyIdlePredictionByHosCodeAndDeptName(String hospitalCode, + String deptName) { + List rankList = departmentRankMapper.getRankByHosAndStandardDept(hospitalCode, deptName, 0); + if (CollectionUtil.isEmpty(rankList)) { + return null; + } + + List hpgpBusyIdlePredictionList = busyIdlePrediction(rankList); + + // 当前医院近七天有号的三个科室 + List deptCodeList = hpgpBusyIdlePredictionList.stream() + // 按科室分组,并统计每个科室可预约号源总量 + .collect(Collectors.groupingBy(HpgpBusyIdlePrediction::getDeptCode, + Collectors.summingInt(item -> Optional.ofNullable(item.getRemainNum()).orElse(0)))) + .entrySet().stream() + // 按可预约号源进行排序,取排名前三的科室 + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .map(Map.Entry::getKey) + .limit(3) + .collect(Collectors.toList()); + + return hpgpBusyIdlePredictionList.stream().filter(item -> deptCodeList.contains(item.getDeptCode())).collect(Collectors.toList()); + + } + + /** + * 按医院和科室详情查询近一周各科室忙闲情况 + * + * @param deptList 科室集 + * @return HpgpBusyIdlePrediction {@link HpgpBusyIdlePrediction} + */ + private List busyIdlePrediction(List deptList) { DateTime startTime = DateUtil.tomorrow(); DateTime endTime = DateUtil.offsetDay(startTime, 6); List result = new ArrayList<>(); - rankList.forEach(rank -> { + deptList.forEach(rank -> { + // 查询医院忙闲 result.addAll(this.listByDeptRank(rank, startTime, endTime)); }); return result; } + private HpgpBusyIdlePrediction getNoneSourcePredictionInfo(HpgpDepartmentRank rank, Date i) { HpgpBusyIdlePrediction vo = new HpgpBusyIdlePrediction(); vo.setDeptCode(rank.getDeptCode()); diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpKsHotServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpKsHotServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..f82b9ae9e01000efd9edae764de4fdcd70e31101 --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/service/impl/HpgpKsHotServiceImpl.java @@ -0,0 +1,31 @@ +package cn.sh.stc.sict.theme.hpgp.service.impl; + +import cn.hutool.core.util.StrUtil; +import cn.sh.stc.sict.theme.hpgp.dao.HpgpKsHotMapper; +import cn.sh.stc.sict.theme.hpgp.model.HpgpKsHot; +import cn.sh.stc.sict.theme.hpgp.service.HpgpKsHotService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * (HpgpKsHot)表服务实现类 + * + * @author gao + * @since 2022-11-07 10:33:21 + */ +@Service("hpgpKsHotService") +public class HpgpKsHotServiceImpl extends ServiceImpl implements HpgpKsHotService { + + @Override + public List listHotDept(String yljgdm) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(HpgpKsHot::getGzh, StrUtil.isBlank(yljgdm) ? "ALL" : yljgdm) + .orderByAsc(HpgpKsHot::getRankScore) + .last("limit 3"); + return this.list(wrapper); + } +} diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/HphyPatientBaseController.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/HphyPatientBaseController.java index 200fd21864b2ab2bc8b3b9a760f8822aa3142d89..11daa84a82c455a22c2fbc76f78c38decfe3cf86 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/HphyPatientBaseController.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/controller/mp/HphyPatientBaseController.java @@ -8,9 +8,11 @@ import cn.sh.stc.sict.cloud.common.core.constant.Constant; import cn.sh.stc.sict.cloud.common.core.constant.enums.LoginTypeEnum; import cn.sh.stc.sict.cloud.common.core.dto.WDUserCardInfo; import cn.sh.stc.sict.cloud.common.core.dto.WDUserInfo; +import cn.sh.stc.sict.cloud.common.core.dto.XSZYUserInfo; 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.cloud.common.core.util.SsbUtil; +import cn.sh.stc.sict.cloud.common.core.util.WoaUtil; import cn.sh.stc.sict.cloud.common.log.annotation.SysLog; import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils; import cn.sh.stc.sict.cloud.upms.dto.CurrentUser; @@ -143,7 +145,7 @@ public class HphyPatientBaseController { // 根据手机号去重 if (ObjectUtil.isNull(base) || NumberUtil.isNullOrZero(base.getId())) { base = hphyPatientBaseService.getByPhone(current.getPhone(), true); - if(NumberUtil.isNotNullOrZero(base.getId())){ + if (ObjectUtil.isNotNull(base) && NumberUtil.isNotNullOrZero(base.getId())) { HphyPatientBase update = new HphyPatientBase(); update.setOpenId(current.getOpenId()); update.setId(base.getId()); @@ -151,6 +153,7 @@ public class HphyPatientBaseController { } } if (ObjectUtil.isNull(base) || NumberUtil.isNullOrZero(base.getId())) { + // 随身办 if (LoginTypeEnum.SSB.getType().equals(source)) { WDUserInfo userInfo = SsbUtil.getUserInfo(token); log.error("wdUser = {}", userInfo); @@ -158,6 +161,12 @@ public class HphyPatientBaseController { base = hphyPatientBaseService.saveSSbInfo(current, userInfo, cardList); hpPatientCardService.save(base, cardList); } + // 香山中医医院公众号 + if (LoginTypeEnum.WOA_XSZY.getType().equals(source)) { + XSZYUserInfo xszyUserInfo = WoaUtil.getXszyUserInfo(token); + log.error("woaXszyUser = {}", xszyUserInfo); + base = hphyPatientBaseService.saveWoaXszyInfo(current, xszyUserInfo); + } } if (ObjectUtil.isNull(base) || NumberUtil.isNullOrZero(base.getId())) { diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HphyPatientBaseService.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HphyPatientBaseService.java index 4f0b9ba4d932c2e445c1996a6d9c58e313aca723..f312b30f353ce80ec5f7cf5b8a86c1f986875135 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HphyPatientBaseService.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HphyPatientBaseService.java @@ -2,6 +2,7 @@ package cn.sh.stc.sict.theme.hphy.service; import cn.sh.stc.sict.cloud.common.core.dto.WDUserCardInfo; import cn.sh.stc.sict.cloud.common.core.dto.WDUserInfo; +import cn.sh.stc.sict.cloud.common.core.dto.XSZYUserInfo; import cn.sh.stc.sict.cloud.upms.dto.CurrentUser; import com.baomidou.mybatisplus.extension.service.IService; import cn.sh.stc.sict.theme.hphy.model.HphyPatientBase; @@ -21,6 +22,15 @@ public interface HphyPatientBaseService extends IService { HphyPatientBase saveSSbInfo(CurrentUser current, WDUserInfo userInfo, List cardList); + /** + * 保存香山中医医院公众号用户 + * + * @param current 当前用户 + * @param userInfo 公众号用户详情 + * @return XSZYUserInfo {@link XSZYUserInfo} + */ + HphyPatientBase saveWoaXszyInfo(CurrentUser current, XSZYUserInfo userInfo); + void savePatient(HphyPatientBase patient); HphyPatientBase getCurrentBase(); diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HphyPatientBaseServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HphyPatientBaseServiceImpl.java index 7973dd2ccdf5e8254adaa494654437bf2eee8293..7560ba8b2d77ea96a7b9ffdcdb0476fb2071e6e8 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HphyPatientBaseServiceImpl.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HphyPatientBaseServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.sh.stc.sict.cloud.common.core.constant.Constant; import cn.sh.stc.sict.cloud.common.core.dto.WDUserCardInfo; import cn.sh.stc.sict.cloud.common.core.dto.WDUserInfo; +import cn.sh.stc.sict.cloud.common.core.dto.XSZYUserInfo; import cn.sh.stc.sict.cloud.common.core.util.NumberUtil; import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils; import cn.sh.stc.sict.cloud.upms.dto.CurrentUser; @@ -69,6 +70,39 @@ public class HphyPatientBaseServiceImpl extends ServiceImpl 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, @@ -22,10 +22,25 @@ dr.rank_score rankScore, d.one_dept_code oneDeptCode, d.dept_code subDeptCode - from hpgp_department_rank dr - join hp_dept_info d on (dr.hospital_code = d.hos_org_code and dr.one_dept_code = d.one_dept_code and dr.dept_code = d.dept_code) - where dr.standard_dept = #{deptName} + from hpgp_department_rank_1028 dr + join hp_dept_info_copy1 d on (dr.hospital_code = d.hos_org_code and dr.one_dept_code = d.one_dept_code and dr.dept_code = d.dept_code) + + + + AND dr.hospital_code = #{hospitalCode} + AND dr.rank_score = 0 + + + AND dr.rank_score != 0 + + + + AND dr.standard_dept = #{deptName} + + order by dr.rank_score asc - limit #{size} + + limit #{size} + diff --git a/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpKsHotMapper.xml b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpKsHotMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..def6d99760ff0406ec59813b78308e081e27d3cc --- /dev/null +++ b/smart-health-modules/theme-schema/src/main/resources/mapper/hpgp/HpgpKsHotMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + gzh, standard_dept, hospital_code, hospital_name, one_dept_code, dept_code, dept_name, rank_score +