解决patient_info表中openid唯一性问题,修改注册、切换账号等接口;

This commit is contained in:
mengkuiliang 2023-10-31 13:56:32 +08:00
parent 7bce05f186
commit fb74d33304
5 changed files with 157 additions and 94 deletions

View File

@ -104,4 +104,13 @@ public interface ResidentPatientInfoMapper {
**/
PatientInfo getPatientInfoByPatientCode(String patientCode);
/**
* @Author mengkuiliang
* @Description 查询已登录的居民信息
* @Date 2023-10-30 030 16:39
* @Param [openid]
* @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo
**/
PatientInfo getLoginByOpenId(String openid);
}

View File

@ -80,6 +80,13 @@ public class PatientInfoBody extends BaseEntity {
@ApiModelProperty(value = "用户微信openid")
private String openid;
/**
* 同一微信绑定标识openid用于区分同一账号绑定的居民
*/
@ApiModelProperty(value = "同一微信绑定标识openid用于区分同一账号绑定的居民")
@Excel(name = "同一微信绑定标识openid用于区分同一账号绑定的居民")
private String bindOpenid;
/**
* 手机号码
*/

View File

@ -92,6 +92,13 @@ public class PatientInfo extends BaseEntity {
@Excel(name = "用户微信openid")
private String openid;
/**
* 同一微信绑定标识openid用于区分同一账号绑定的居民
*/
@ApiModelProperty(value = "同一微信绑定标识openid用于区分同一账号绑定的居民")
@Excel(name = "同一微信绑定标识openid用于区分同一账号绑定的居民")
private String bindOpenid;
/**
* 手机号码
*/

View File

@ -14,6 +14,7 @@ import com.xinelu.common.utils.uuid.IdUtils;
import com.xinelu.familydoctor.applet.mapper.ResidentPatientInfoMapper;
import com.xinelu.familydoctor.applet.pojo.body.PatientInfoBody;
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
import com.xinelu.familydoctor.applet.pojo.query.PatientInfoQuery;
import com.xinelu.familydoctor.applet.pojo.vo.SignInfoDetailVo;
import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService;
import com.xinelu.familydoctor.applet.utils.AppletAccessTokenUtils;
@ -25,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
@ -161,72 +163,106 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
@Override
@Transactional(rollbackFor = Exception.class)
public void register(PatientInfoBody body) {
if (ObjectUtils.isNotEmpty(body.getCardNo())) {
PatientInfo patientInfo;
// 修改
if (!StringUtils.isBlank(body.getPatientCode())) {
patientInfo = residentPatientInfoMapper.getPatientInfoByPatientCode(body.getPatientCode());
if (ObjectUtils.isNotEmpty(patientInfo)) {
BeanUtils.copyBeanProp(patientInfo, body);
if (body.getDiseaseList() != null) {
patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
patientInfo.setDisease("0");
if(StringUtils.isBlank(body.getCardNo())) {
throw new ServiceException("请求参数有误");
}
// 查询已登录的居民信息
PatientInfo loginPatientInfo = residentPatientInfoMapper.getLoginByOpenId(body.getOpenid());
PatientInfo patientInfo;
// 更新
if (!StringUtils.isBlank(body.getPatientCode())) {
patientInfo = residentPatientInfoMapper.getPatientInfoByPatientCode(body.getPatientCode());
if(patientInfo == null) {
throw new ServiceException("未查询到居民注册信息");
}
if(patientInfo.getDelFlag() != null && patientInfo.getDelFlag() == 1) {
throw new ServiceException("居民已解绑,不能更新数据");
}
if(!body.getOpenid().equals(patientInfo.getBindOpenid())) {
throw new ServiceException("该居民非当前账号绑定,不允许修改");
}
BeanUtils.copyBeanProp(patientInfo, body);
// 已绑定openid将该值置空
if(loginPatientInfo != null) {
patientInfo.setOpenid(null);
}
if (body.getDiseaseList() != null) {
patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
patientInfo.setDisease("0");
}
patientInfo.setLoginFlag(Long.valueOf(1));
patientInfo.setBindOpenid(body.getOpenid());
updatePatientInfo(patientInfo);
// 新增
} else {
patientInfo = residentPatientInfoMapper.isRegisterByCardNo(body.getCardNo());
if (patientInfo != null) {
if(patientInfo.getDelFlag() == null || patientInfo.getDelFlag() == 0) {
throw new ServiceException("该身份证号已被注册");
} else {
// 已解绑状态的更新
if(patientInfo.getDelFlag() == 1) {
patientInfo.setIsChecked("0");
// 已绑定openid将该值置空
patientInfo.setOpenid(loginPatientInfo != null? null: body.getOpenid());
patientInfo.setUnionid(body.getUnionid());
patientInfo.setPatientName(body.getPatientName());
patientInfo.setPhone(body.getPhone());
patientInfo.setAddress(body.getAddress());
patientInfo.setUpdateTime(new Date());
patientInfo.setUpdateBy(body.getCardNo());
patientInfo.setHeadPictureUrl(body.getHeadPictureUrl());
patientInfo.setDelFlag(0);
patientInfo.setLoginFlag(Long.valueOf(1));
if (body.getDiseaseList() != null) {
patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
patientInfo.setDisease("0");
}
patientInfo.setBindOpenid(body.getOpenid());
patientInfo.setBindingTime(new Date());
residentPatientInfoMapper.updatePatientInfo(patientInfo);
}
patientInfo.setLoginFlag(Long.valueOf(1));
updatePatientInfo(patientInfo);
}
// 注册
} else {
// 获取当前微信绑定的居民
List<PatientInfo> list = residentPatientInfoMapper.getList(body.getOpenid(), body.getCityCode());
patientInfo = residentPatientInfoMapper.isRegisterByCardNo(body.getCardNo());
if (patientInfo == null) {
PatientInfo entity = new PatientInfo();
BeanUtils.copyBeanProp(entity, body);
if (body.getDiseaseList() != null) {
entity.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
entity.setDisease("0");
}
entity.setPatientCode(IdUtils.fastSimpleUUID());
entity.setBindingTime(new Date());
entity.setIsChecked((list == null || list.size() == 0) ? "1" : "0");
entity.setCreateTime(new Date());
entity.setCreateBy(body.getCardNo());
entity.setLoginFlag(Long.valueOf(1));
residentPatientInfoMapper.insertPatientInfo(entity);
// 新增的话重新查询居民信息获取patientId
patientInfo = residentPatientInfoMapper.getPatientInfoByPatientCode(entity.getPatientCode());
} else {
if (!StringUtils.isBlank(patientInfo.getOpenid())) {
throw new ServiceException("该身份证号已被注册");
}
patientInfo.setIsChecked((list == null || list.size() == 0) ? "1" : "0");
patientInfo.setOpenid(body.getOpenid());
patientInfo.setUnionid(body.getUnionid());
patientInfo.setPatientName(body.getPatientName());
patientInfo.setPhone(body.getPhone());
patientInfo.setAddress(body.getAddress());
patientInfo.setUpdateTime(new Date());
patientInfo.setUpdateBy(body.getCardNo());
patientInfo.setHeadPictureUrl(body.getHeadPictureUrl());
patientInfo.setDelFlag(0);
patientInfo.setLoginFlag(Long.valueOf(1));
if (body.getDiseaseList() != null) {
patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
patientInfo.setDisease("0");
}
residentPatientInfoMapper.updatePatientInfo(patientInfo);
PatientInfo entity = new PatientInfo();
BeanUtils.copyBeanProp(entity, body);
// 已绑定openid将该值置空
if(loginPatientInfo != null) {
entity.setOpenid(null);
}
if (body.getDiseaseList() != null) {
entity.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
entity.setDisease("0");
}
entity.setPatientCode(IdUtils.fastSimpleUUID());
entity.setBindingTime(new Date());
entity.setIsChecked("0");
entity.setCreateTime(new Date());
entity.setCreateBy(body.getCardNo());
entity.setLoginFlag(Long.valueOf(1));
entity.setDelFlag(0);
entity.setBindOpenid(body.getOpenid());
residentPatientInfoMapper.insertPatientInfo(entity);
// 新增的话重新查询居民信息获取patientId
patientInfo = residentPatientInfoMapper.getPatientInfoByPatientCode(entity.getPatientCode());
}
if(patientInfo != null) {
// 记录收货地址信息
this.insertReceiveAddress(patientInfo);
}
// 记录收货地址信息
if(patientInfo != null) {
// 如果置空了重新赋值
if(StringUtils.isBlank(patientInfo.getOpenid())) {
patientInfo.setOpenid(body.getOpenid());
}
this.insertReceiveAddress(patientInfo);
}
}
@ -254,28 +290,6 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
}
}
// 获取签约信息
private String getSignInfo(String region, String identity) {
if (!StringUtils.isBlank(region)) {
try {
// 查询签约信息
String result = (String) httpService.get(SpringUtils.getFdUrl(region) + "/resident/signinfo/detail/" + identity, null, String.class);
JSONObject jsonObject = JSONObject.parseObject(result);
if ("1".equals(jsonObject.get("code"))) {
if (jsonObject.getJSONObject("data") != null) {
SignInfoDetailVo signInfo = JSONObject.parseObject(jsonObject.getJSONObject("data").toJSONString(), SignInfoDetailVo.class);
if (signInfo != null) {
return signInfo.getSignNo();
}
}
}
} catch (Exception e) {
log.error("注册完善信息-更新签约标识出错:{}", e.getMessage());
}
}
return null;
}
/**
* @return void
* @Author mengkuiliang
@ -286,13 +300,13 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
@Override
public void unbinding(String patientCode) {
PatientInfo register = residentPatientInfoMapper.selectPatientInfoByCode(patientCode);
if (register == null || StringUtils.isBlank(register.getOpenid())) {
if (register == null || String.valueOf(register.getDelFlag()).equals("1")) {
return;
}
register.setIsChecked("0");
register.setOpenid("");
register.setUpdateTime(new Date());
register.setUpdateBy(register.getCreateBy());
register.setOpenid(null);
register.setDelFlag(1);
register.setBindOpenid("");
residentPatientInfoMapper.updatePatientInfo(register);
}
@ -322,15 +336,19 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
if (register == null) {
throw new ServiceException("该账号未注册不能切换");
} else {
if (StringUtils.isBlank(register.getOpenid())) {
if (StringUtils.isBlank(register.getBindOpenid())) {
throw new ServiceException("该账号未注册不能切换");
}
if (!openid.equals(register.getOpenid())) {
if (!openid.equals(register.getBindOpenid())) {
throw new ServiceException("该账号已被其他人绑定不能切换");
}
residentPatientInfoMapper.switchResident(openid, patientCode);
}
return residentPatientInfoMapper.selectPatientInfoByCode(patientCode);
PatientInfo patientInfo = residentPatientInfoMapper.selectPatientInfoByCode(patientCode);
if(patientInfo != null && StringUtils.isBlank(patientInfo.getOpenid())) {
patientInfo.setOpenid(openid);
}
return patientInfo;
}
/** 判断2个参数是否一样 */
@ -349,7 +367,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
return null;
}
PatientInfo patientInfo = null;
// 获取当前选中的
// 获取当前登录的居民
List<PatientInfo> currentList = list.stream().filter(p -> p.getIsChecked().equals("1")).collect(Collectors.toList());
if (currentList.size() > 0) {
if (!StringUtils.isBlank(currentList.get(0).getDisease())) {
@ -366,6 +384,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
list.get(0).setDiseaseList(Arrays.asList(list.get(0).getDisease().split(",")));
}
list.get(0).setIsChecked("1");
list.get(0).setOpenid(openid);
patientInfo = list.get(0);
}
return patientInfo;
@ -431,4 +450,4 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
HashMap.put("cityCode", cityCode);
return HashMap;
}
}
}

View File

@ -14,6 +14,7 @@
<result property="userId" column="user_id"/>
<result property="unionid" column="unionid"/>
<result property="openid" column="openid"/>
<result property="bindOpenid" column="bind_openid"/>
<result property="phone" column="phone"/>
<result property="address" column="address"/>
<result property="urgentContactName" column="urgent_contact_name"/>
@ -60,6 +61,7 @@
user_id,
unionid,
openid,
bind_openid,
phone,
address,
urgent_contact_name,
@ -110,6 +112,9 @@
<if test="openid != null and openid != ''">
and openid = #{openid}
</if>
<if test="bindOpenid != null and bindOpenid != ''">
and bind_openid = #{bindOpenid}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
@ -153,6 +158,9 @@
</if>
<if test="openid != null">openid,
</if>
<if test="bindOpenid != null">
bind_openid,
</if>
<if test="phone != null">phone,
</if>
<if test="address != null">address,
@ -243,6 +251,9 @@
</if>
<if test="openid != null">#{openid},
</if>
<if test="bindOpenid != null">
#{bindOpenid},
</if>
<if test="phone != null">#{phone},
</if>
<if test="address != null">#{address},
@ -340,6 +351,9 @@
<if test="openid != null">openid =
#{openid},
</if>
<if test="bindOpenid != null">
bind_openid = #{bindOpenid},
</if>
<if test="phone != null">phone =
#{phone},
</if>
@ -462,7 +476,7 @@
<!-- 获取已注册列表 -->
<select id="getList" resultType="com.xinelu.familydoctor.applet.pojo.entity.PatientInfo">
<include refid="selectPatientInfoVo"/>
where openid = #{openid} and del_flag = 0
where bind_openid = #{openid} and del_flag = 0
<if test="cityCode != null and cityCode != '' and cityCode != 'null'">
and city_code = #{cityCode}
</if>
@ -479,19 +493,20 @@
<update id="switchResident">
update patient_info
set is_checked = (case when patient_code = #{patientCode} then '1' else '0' end)
where openid = #{openid}
where bind_openid = #{openid} and del_flag = 0
</update>
<!-- 更新选中标识 -->
<update id="updateChecked">
update patient_info set is_checked = #{isChecked} where patient_code = #{patientCode}
update patient_info set is_checked = #{isChecked}
where patient_code = #{patientCode}
</update>
<!-- 获取注册详细信息 -->
<select id="selectPatientInfoByPhone" parameterType="String" resultMap="PatientInfoResult">
<include refid="selectPatientInfoVo"/>
where phone = #{pnone}
and login_flag = '1'
and login_flag = '1' and del_flag = 0
</select>
<select id="getPatientInfoByPatientCode" resultMap="PatientInfoResult">
@ -499,4 +514,10 @@
where patient_code = #{patientCode}
and del_flag = 0
</select>
<!-- 查询已登录的居民信息 -->
<select id="getLoginByOpenId" resultType="com.xinelu.familydoctor.applet.pojo.entity.PatientInfo">
<include refid="selectPatientInfoVo"/>
where openid = #{openid} limit 1
</select>
</mapper>