diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java index 60cfbad..26210d7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java @@ -209,8 +209,9 @@ public class AppController extends BaseController logger.info("add patient param is {} ", appPatientReq); TPatient tPatient = new TPatient(); BeanUtils.copyProperties(appPatientReq, tPatient); + tPatient.setDelFlag("0"); // 查询患者信息 - TPatient currentPatient = tPatientService.queryTPatient(tPatient); + TPatient currentPatient = tPatientService.queryTPatientByPhoneAndName(tPatient); if (Objects.nonNull(currentPatient)) { //患者信息已存在 新增诊断记录 @@ -268,6 +269,11 @@ public class AppController extends BaseController logger.info("modify patient param is {} ", appPatientReq); TPatient tPatient = new TPatient(); BeanUtils.copyProperties(appPatientReq, tPatient); + tPatient.setDelFlag("0"); + TPatient currentPatient = tPatientService.queryTPatientByPhoneAndName(tPatient); + if (Objects.nonNull(currentPatient) && currentPatient.getId().compareTo(appPatientReq.getId()) != 0) { + return AjaxResult.error("手机号下已存在该患者。"); + } return AjaxResult.success(tPatientService.updateTPatient(tPatient)); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java index 7611b93..a715d4e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java @@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.system.domain.req.GetOpenidReq; import com.ruoyi.system.domain.req.LoginForAppReq; import com.ruoyi.system.domain.req.LoginForMpReq; +import com.ruoyi.system.domain.req.LoginForMultiPatientReq; import com.ruoyi.system.domain.resp.GetOpenidResp; import com.ruoyi.system.service.IWechatService; import org.slf4j.Logger; @@ -52,6 +53,15 @@ public class WechatLoginController extends BaseController { return AjaxResult.success(map); } + @PostMapping("/for/multi/patient") + public AjaxResult loginForMultiPatient(@RequestBody @Validated LoginForMultiPatientReq req) { + logger.info("loginForMultiPatient req :{}", req); + String token = iWechatService.loginForMultiPatient(req); + Map map = new HashMap<>(); + map.put(Constants.TOKEN, token); + return AjaxResult.success(map); + } + @PostMapping("/get/unionid") public AjaxResult getWechatUnionInfo(@RequestBody @Validated GetOpenidReq getOpenidReq, HttpServletRequest request) { logger.info("wechat获取unionid, req = [{}]", getOpenidReq); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/LoginForMultiPatientReq.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/LoginForMultiPatientReq.java new file mode 100644 index 0000000..44e0d3b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/LoginForMultiPatientReq.java @@ -0,0 +1,39 @@ +package com.ruoyi.system.domain.req; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +public class LoginForMultiPatientReq implements Serializable { + private static final long serialVersionUID = -2077202239424966485L; + + @NotBlank(message = "openid不能为空") + private String openId; + + @NotNull(message = "患者id不能为空") + private Long patientId; + + public String getOpenId() { + return openId; + } + + public void setOpenId(String openId) { + this.openId = openId; + } + + public Long getPatientId() { + return patientId; + } + + public void setPatientId(Long patientId) { + this.patientId = patientId; + } + + @Override + public String toString() { + return "LoginForMultiPatientReq{" + + "openId='" + openId + '\'' + + ", patientId='" + patientId + '\'' + + '}'; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/GetOpenidResp.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/GetOpenidResp.java index 697e5ab..9296ca4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/GetOpenidResp.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/resp/GetOpenidResp.java @@ -1,6 +1,9 @@ package com.ruoyi.system.domain.resp; +import com.ruoyi.system.domain.TPatient; + import java.io.Serializable; +import java.util.List; public class GetOpenidResp implements Serializable { private static final long serialVersionUID = -8328911573370172974L; @@ -13,6 +16,18 @@ public class GetOpenidResp implements Serializable { private String unionid; + private List patients; + + private Boolean multiPatient = false; + + public List getPatients() { + return patients; + } + + public void setPatients(List patients) { + this.patients = patients; + } + public String getOpenid() { return openid; } @@ -44,4 +59,12 @@ public class GetOpenidResp implements Serializable { public void setUnionid(String unionid) { this.unionid = unionid; } + + public Boolean getMultiPatient() { + return multiPatient; + } + + public void setMultiPatient(Boolean multiPatient) { + this.multiPatient = multiPatient; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TPatientMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TPatientMapper.java index 77d5d4e..efbd1cb 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TPatientMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TPatientMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.TPatient; +import com.ruoyi.system.domain.req.LoginForMultiPatientReq; import com.ruoyi.system.domain.req.PcTPatintQueryByPageReq; import com.ruoyi.system.domain.resp.PcTPatientQueryByPageResp; import tk.mybatis.mapper.common.Mapper; @@ -62,9 +63,13 @@ public interface TPatientMapper */ public int deleteTPatientByIds(Long[] ids); - public TPatient queryTPatient(TPatient tPatient); + public TPatient queryTPatientByPhoneAndName(TPatient tPatient); List queryByPage(PcTPatintQueryByPageReq pcTPatintQueryByPageReq); int checkPhoneUnique(String phone); + + public List querySamePhonePatientsById(Long id); + + public TPatient queryPatientByOpenidAndPatientId(LoginForMultiPatientReq loginForMultiPatientReq); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITPatientService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITPatientService.java index d64a7d8..1d647e8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITPatientService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITPatientService.java @@ -65,5 +65,5 @@ public interface ITPatientService String checkPhoneUnique(String phone); - public TPatient queryTPatient(TPatient tPatient); + public TPatient queryTPatientByPhoneAndName(TPatient tPatient); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatService.java index 3d7fd89..cb88b58 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatService.java @@ -3,6 +3,7 @@ package com.ruoyi.system.service; import com.ruoyi.system.domain.req.GetOpenidReq; import com.ruoyi.system.domain.req.LoginForAppReq; import com.ruoyi.system.domain.req.LoginForMpReq; +import com.ruoyi.system.domain.req.LoginForMultiPatientReq; import com.ruoyi.system.domain.resp.GetOpenidResp; import javax.servlet.http.HttpServletRequest; @@ -16,4 +17,6 @@ public interface IWechatService { String loginForMp(LoginForMpReq req); String loginForApp(LoginForAppReq req); + + String loginForMultiPatient(LoginForMultiPatientReq req); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPatientServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPatientServiceImpl.java index 1f6e81c..f03804a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPatientServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TPatientServiceImpl.java @@ -136,7 +136,7 @@ public class TPatientServiceImpl implements ITPatientService } @Override - public TPatient queryTPatient(TPatient tPatient) { - return tPatientMapper.queryTPatient(tPatient); + public TPatient queryTPatientByPhoneAndName(TPatient tPatient) { + return tPatientMapper.queryTPatientByPhoneAndName(tPatient); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java index fc0d4c0..dbe166b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java @@ -17,6 +17,7 @@ import com.ruoyi.system.domain.TWechatUser; import com.ruoyi.system.domain.req.GetOpenidReq; import com.ruoyi.system.domain.req.LoginForAppReq; import com.ruoyi.system.domain.req.LoginForMpReq; +import com.ruoyi.system.domain.req.LoginForMultiPatientReq; import com.ruoyi.system.domain.resp.GetOpenidResp; import com.ruoyi.system.mapper.TDoctorMapper; import com.ruoyi.system.mapper.TPatientMapper; @@ -29,13 +30,11 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; @Service public class WechatServiceImpl implements IWechatService { @@ -86,11 +85,19 @@ public class WechatServiceImpl implements IWechatService { if (Objects.isNull(wechatUser.getUserId())) { resp.setBindFlag(false); } else { - // 已绑定信息 直接登录 + // 已绑定患者 resp.setBindFlag(true); - TPatient tPatient = tPatientMapper.selectTPatientById(wechatUser.getUserId()); - String token = buildTokenByPatient(tPatient); - resp.setToken(token); + // 查询该患者手机号是否存在多条数据 + List patients = tPatientMapper.querySamePhonePatientsById(wechatUser.getUserId()); + if (CollectionUtils.isEmpty(patients)) { + resp.setBindFlag(false); + } else if (!CollectionUtils.isEmpty(patients) && patients.size() == 1) { + String token = buildTokenByPatient(patients.get(0)); + resp.setToken(token); + } else { + resp.setMultiPatient(true); + resp.setPatients(patients); + } } resp.setOpenid(openid); return resp; @@ -120,7 +127,7 @@ public class WechatServiceImpl implements IWechatService { // 查询手机号是否存在患者信息 TPatient tPatient = new TPatient(); BeanUtils.copyProperties(req, tPatient); - TPatient currentPatient = tPatientMapper.queryTPatient(tPatient); + TPatient currentPatient = tPatientMapper.queryTPatientByPhoneAndName(tPatient); TWechatUser wechatUser = new TWechatUser(); if (Objects.nonNull(currentPatient)) { // 存在 需要把患者信息更新 并绑定openid @@ -205,6 +212,17 @@ public class WechatServiceImpl implements IWechatService { return token; } + @Override + public String loginForMultiPatient(LoginForMultiPatientReq req) { + TPatient tPatient = tPatientMapper.queryPatientByOpenidAndPatientId(req); + String token = ""; + if (Objects.nonNull(tPatient)) { + logger.info("query patient info :{}", tPatient); + token = buildTokenByPatient(tPatient); + } + return token; + } + private String queryOpenid(GetOpenidReq req){ String url = String.format(WechatKeys.MP_CODE_TO_OPENID_URL, appId, appSecret, req.getCode()); String json = HttpUtils.sendGet(url); diff --git a/ruoyi-system/src/main/resources/mapper/system/TPatientMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TPatientMapper.xml index b4f0a59..db491f8 100644 --- a/ruoyi-system/src/main/resources/mapper/system/TPatientMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/TPatientMapper.xml @@ -114,12 +114,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - phone = #{phone} - + + and delFlag = #{delFlag} + + + and phone = #{phone} + + + and name = #{name} + @@ -169,4 +175,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + +