diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/mapper/ResidentPatientInfoMapper.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/mapper/ResidentPatientInfoMapper.java index e656909..5bc9ab1 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/mapper/ResidentPatientInfoMapper.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/mapper/ResidentPatientInfoMapper.java @@ -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); + } diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/body/PatientInfoBody.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/body/PatientInfoBody.java index 1b23687..1ebf219 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/body/PatientInfoBody.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/body/PatientInfoBody.java @@ -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; + /** * 手机号码 */ diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/entity/PatientInfo.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/entity/PatientInfo.java index c73c8ca..0bdbaa9 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/entity/PatientInfo.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/pojo/entity/PatientInfo.java @@ -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; + /** * 手机号码 */ diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java index fce191d..70b2eba 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java @@ -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 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 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; } -} \ No newline at end of file +} diff --git a/xinelu-familydoctor/src/main/resources/mapper/register/ResidentPatientInfoMapper.xml b/xinelu-familydoctor/src/main/resources/mapper/register/ResidentPatientInfoMapper.xml index 7c11c77..014532b 100644 --- a/xinelu-familydoctor/src/main/resources/mapper/register/ResidentPatientInfoMapper.xml +++ b/xinelu-familydoctor/src/main/resources/mapper/register/ResidentPatientInfoMapper.xml @@ -14,6 +14,7 @@ + @@ -60,6 +61,7 @@ user_id, unionid, openid, + bind_openid, phone, address, urgent_contact_name, @@ -110,6 +112,9 @@ and openid = #{openid} + + and bind_openid = #{bindOpenid} + and phone = #{phone} @@ -153,6 +158,9 @@ openid, + + bind_openid, + phone, address, @@ -243,6 +251,9 @@ #{openid}, + + #{bindOpenid}, + #{phone}, #{address}, @@ -340,6 +351,9 @@ openid = #{openid}, + + bind_openid = #{bindOpenid}, + phone = #{phone}, @@ -462,7 +476,7 @@ where phone = #{pnone} - and login_flag = '1' + and login_flag = '1' and del_flag = 0 + + +