Compare commits

..

2 Commits

@ -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));
}

@ -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);

@ -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 + '\'' +
'}';
}
}

@ -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<TPatient> patients;
private Boolean multiPatient = false;
public List<TPatient> getPatients() {
return patients;
}
public void setPatients(List<TPatient> 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;
}
}

@ -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<PcTPatientQueryByPageResp> queryByPage(PcTPatintQueryByPageReq pcTPatintQueryByPageReq);
int checkPhoneUnique(String phone);
public List<TPatient> querySamePhonePatientsById(Long id);
public TPatient queryPatientByOpenidAndPatientId(LoginForMultiPatientReq loginForMultiPatientReq);
}

@ -65,5 +65,5 @@ public interface ITPatientService
String checkPhoneUnique(String phone);
public TPatient queryTPatient(TPatient tPatient);
public TPatient queryTPatientByPhoneAndName(TPatient tPatient);
}

@ -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);
}

@ -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);
}
}

@ -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 {
@ -83,11 +82,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<TPatient> 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;
@ -117,7 +124,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
@ -202,6 +209,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);

@ -114,12 +114,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<select id="queryTPatient" parameterType="com.ruoyi.system.domain.TPatient" resultMap="TPatientResult">
<select id="queryTPatientByPhoneAndName" parameterType="com.ruoyi.system.domain.TPatient" resultMap="TPatientResult">
<include refid="selectTPatientVo"/>
<where>
<if test="phone != null and phone != ''">
phone = #{phone}
</if>
<if test="delFlag != null and delFlag != ''">
and delFlag = #{delFlag}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
</where>
</select>
@ -169,4 +175,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="checkPhoneUnique" parameterType="String" resultType="int">
select count(1) from t_patient where phone = #{phone} limit 1
</select>
<select id="querySamePhonePatientsById" parameterType="java.lang.Long" resultMap="TPatientResult">
<include refid="selectTPatientVo"/>
where del_flag = '0'
and phone = (select phone from t_patient where id = #{id})
</select>
<select id="queryPatientByOpenidAndPatientId" parameterType="com.ruoyi.system.domain.req.LoginForMultiPatientReq" resultMap="TPatientResult">
<include refid="selectTPatientVo"/>
where phone = (select phone from t_patient where id = (
SELECT
user_id
FROM
t_wechat_user
WHERE
openid = #{openId}
)) and id = #{patientId} and del_flag = '0'
</select>
</mapper>

Loading…
Cancel
Save