| | |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.common.utils.Pinyin4jUtil; |
| | | import com.kidgrow.redis.util.RedisUtils; |
| | | import com.kidgrow.sms.feign.SmsChuangLanService; |
| | | import com.kidgrow.sms.model.ConstantSMS; |
| | | import com.kidgrow.usercenter.mapper.SysDoctorMapper; |
| | | import com.kidgrow.usercenter.mapper.SysRoleMenuMapper; |
| | | import com.kidgrow.usercenter.mapper.SysUserMapper; |
| | | import com.kidgrow.usercenter.mapper.*; |
| | | import com.kidgrow.usercenter.model.SysDoctor; |
| | | import com.kidgrow.usercenter.model.*; |
| | | import com.kidgrow.usercenter.service.*; |
| | | import com.kidgrow.usercenter.vo.HospitalDoctorListVo; |
| | | import com.kidgrow.usercenter.vo.UserRegVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | |
| | | @Autowired |
| | | private SysDoctorMapper sysDoctorMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper sysRoleMapper; |
| | | @Autowired |
| | | private SysUserRoleMapper sysUserRoleMapper; |
| | | @Override |
| | | public LoginAppUser findByUsername(String username) { |
| | | SysUser sysUser = this.selectByUsername(username); |
| | |
| | | @Override |
| | | public LoginAppUser getLoginAppUser(SysUser sysUser) { |
| | | LoginAppUser loginAppUser = new LoginAppUser(); |
| | | SysUser sysUserNew = this.baseMapper.selectById(sysUser); |
| | | if (sysUser != null) { |
| | | //返回的数据为什么要把密码也返回?清空!! |
| | | loginAppUser.setPassword(""); |
| | | loginAppUser.setNewPassword(""); |
| | | loginAppUser.setOldPassword(""); |
| | | |
| | | BeanUtils.copyProperties(sysUser, loginAppUser); |
| | | //获取用户所属组织机构列表 |
| | | loginAppUser.setDefaultAuth(sysUserNew.getDefaultAuth()); |
| | | List<SysOrganization> sysOrganizations = organizationService.findListByUserId(sysUser.getId()); |
| | | //设置组织机构集合 |
| | | loginAppUser.setOrganizations(sysOrganizations); |
| | |
| | | //是否医院管理员 |
| | | com.kidgrow.usercenter.model.SysDoctor sysDoctor = findDoctorByUserId(sysUser.getId()); |
| | | if (sysDoctor.getIsAdminUser() != null) { |
| | | sysUser.setHAdminUser(sysDoctor.getIsAdminUser()); |
| | | loginAppUser.setHAdminUser(sysDoctor.getIsAdminUser()); |
| | | } |
| | | //医院信息 只有H端要返回的信息 |
| | | if (sysUser.getTenantId() == CommonConstant.H_TENANT) { |
| | | sysUser.setDoctorUserAllVO(baseMapper.findDoctorUserAllData(sysUser.getId())); |
| | | if (sysUser.getTenantId().toLowerCase().equals(CommonConstant.H_TENANT.toLowerCase())) { |
| | | DoctorUserAll doctorUserAllVo = baseMapper.findDoctorUserAllData(sysUser.getId()); |
| | | loginAppUser.setDoctorUserAllVO(doctorUserAllVo); |
| | | } |
| | | } |
| | | return loginAppUser; |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody updatePassword(Long id, String oldPassword, String newPassword, Boolean isdefault) { |
| | | SysUser sysUser = baseMapper.selectById(id); |
| | |
| | | user.setPassword(passwordEncoder.encode(newPassword)); |
| | | if (isdefault) { |
| | | user.setDefaultAuth(true); |
| | | }else { |
| | | user.setDefaultAuth(false); |
| | | } |
| | | baseMapper.updateById(user); |
| | | if (isdefault) { |
| | |
| | | |
| | | if (id > 0 && StringUtils.isNotBlank(oldTel) && StringUtils.isNotBlank(newTel) && StringUtils.isNotBlank(authCode) && StringUtils.isNotBlank(userPassword)) { |
| | | //检查验证码 |
| | | Object hget = redisUtils.hget(ConstantSMS.PHONE_SMS, newTel); |
| | | if (hget != null) { |
| | | JSONObject redisJson = JSON.parseObject(JSON.toJSONString(hget)); |
| | | Object verificationCodeObject = redisJson.get("verificationCode"); |
| | | //核对验证码 |
| | | if (authCode.equals(verificationCodeObject)) { |
| | | if (CheckVerificationCode(ConstantSMS.PHONE_SMS, newTel, authCode)) { |
| | | //查询手机号是否已经存在 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", newTel); |
| | | List<SysUser> sysUsersList = baseMapper.selectByMap(selectMap); |
| | | if (sysUsersList.size() > 0) { |
| | | return ResultBody.failed("该手机号已经存在!"); |
| | | } else { |
| | | //验证旧手机号和密码 |
| | | SysUser sysUser = baseMapper.selectById(id); |
| | | if (passwordEncoder.matches(userPassword, sysUser.getPassword()) && sysUser.getMobile().equals((oldTel))) { |
| | | Object date = redisJson.get("endTime"); |
| | | long time = DateUtils.parseDate(date.toString()).getTime(); |
| | | long timeNow = new Date().getTime(); |
| | | if (timeNow <= time) { |
| | | //查询手机号是否已经存在 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", newTel); |
| | | List<SysUser> sysUsersList = baseMapper.selectByMap(selectMap); |
| | | if (sysUsersList.size() > 0) { |
| | | return ResultBody.failed("该手机号已经存在!"); |
| | | } else { |
| | | //验证通过,修改手机号 |
| | | SysUser user = new SysUser(); |
| | | user.setId(id); |
| | | user.setMobile(newTel); |
| | | user.setUsername(newTel); |
| | | //修改doctor表 |
| | | com.kidgrow.usercenter.model.SysDoctor sysDoctorModel = findDoctorByUserId(user.getId()); |
| | | com.kidgrow.usercenter.model.SysDoctor newsysDoctorModel = new com.kidgrow.usercenter.model.SysDoctor(); |
| | | if (sysDoctorModel != null) { |
| | | //理论上只有一个,如果有多个 只取第一个 |
| | | newsysDoctorModel.setId(sysDoctorModel.getId()); |
| | | newsysDoctorModel.setDoctorTel(newTel); |
| | | sysDoctorMapper.updateById(newsysDoctorModel); |
| | | } |
| | | if (baseMapper.updateById(user) > 0) { |
| | | //将Redis清除 |
| | | redisUtils.hdel(ConstantSMS.PHONE_SMS, newTel); |
| | | return ResultBody.ok().msg("手机号修改成功!"); |
| | | } else { |
| | | return ResultBody.failed("手机号修改失败!"); |
| | | } |
| | | } |
| | | } else { |
| | | return ResultBody.failed("手机验证码已过期!"); |
| | | //验证通过,修改手机号 |
| | | SysUser user = new SysUser(); |
| | | user.setId(id); |
| | | user.setMobile(newTel); |
| | | user.setUsername(newTel); |
| | | //修改doctor表 |
| | | com.kidgrow.usercenter.model.SysDoctor sysDoctorModel = findDoctorByUserId(user.getId()); |
| | | com.kidgrow.usercenter.model.SysDoctor newsysDoctorModel = new com.kidgrow.usercenter.model.SysDoctor(); |
| | | if (sysDoctorModel != null) { |
| | | //理论上只有一个,如果有多个 只取第一个 |
| | | newsysDoctorModel.setId(sysDoctorModel.getId()); |
| | | newsysDoctorModel.setDoctorTel(newTel); |
| | | sysDoctorMapper.updateById(newsysDoctorModel); |
| | | } |
| | | } else { |
| | | if (baseMapper.updateById(user) > 0) { |
| | | //将Redis清除 |
| | | redisUtils.hdel(ConstantSMS.PHONE_SMS, newTel); |
| | | return ResultBody.ok().msg("手机号修改成功!"); |
| | | } else { |
| | | return ResultBody.failed("手机号修改失败!"); |
| | | } |
| | | }else { |
| | | return ResultBody.failed("用户信息验证失败,请提供正确的手机号和密码!"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("手机验证码有误!"); |
| | | } |
| | | } else { |
| | | //redis获取失败 |
| | | return ResultBody.failed("请重新获取验证码!"); |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed("无效的验证码"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("必须参数有误!"); |
| | |
| | | return result ? ResultBody.ok().data(sysUser).msg("操作成功") : ResultBody.failed("操作失败"); |
| | | } |
| | | |
| | | /** |
| | | * 删除用户 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public boolean delUser(Long id) { |
| | | //删除角色数据 |
| | | roleUserService.deleteUserRole(id, null); |
| | | //删除组织对应数据 |
| | | organizationService.deleteByUserId(id); |
| | | //删除医生数据 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("userId", id); |
| | | sysDoctorMapper.deleteByMap(params); |
| | | //删除用户数据 |
| | | return baseMapper.deleteById(id) > 0; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 验证手机验证码 |
| | | * |
| | | * @param constantSMS |
| | | * @param phone |
| | | * @param inputCode |
| | | * @return |
| | | */ |
| | | public boolean CheckVerificationCode(String constantSMS, String phone, String inputCode) { |
| | | //获取缓存中的验证码对象 |
| | | Object hget = redisUtils.hget(constantSMS, phone); |
| | | if (hget != null) { |
| | | //序列化验证码 |
| | | JSONObject redisJson = JSON.parseObject(JSON.toJSONString(hget)); |
| | | //拿取验证码 |
| | | String verificationCodeObject = redisJson.get("verificationCode").toString(); |
| | | //核对验证码 |
| | | if (inputCode.equals(verificationCodeObject)) { |
| | | Object date = redisJson.get("endTime"); |
| | | long time = DateUtils.parseDate(date.toString()).getTime(); |
| | | Date dateNow = new Date(); |
| | | long timeNow = dateNow.getTime(); |
| | | return (timeNow <= time); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号 修改密码 |
| | | * |
| | | * @param map |
| | |
| | | if (newPass == null || "".equals(newPass.trim())) { |
| | | return ResultBody.failed("请输入正确的密码"); |
| | | } |
| | | Object hget = redisUtils.hget(ConstantSMS.PASSWORD_SMS, map.get("phone").toString()); |
| | | if (hget != null) { |
| | | JSONObject redisJson = JSON.parseObject(JSON.toJSONString(hget)); |
| | | Object verificationCodeObject = redisJson.get("verificationCode"); |
| | | if (verificationCode.equals(verificationCodeObject)) { |
| | | Object date = redisJson.get("endTime"); |
| | | long time = DateUtils.parseDate(date.toString()).getTime(); |
| | | Date dateNow = new Date(); |
| | | long timeNow = dateNow.getTime(); |
| | | if (timeNow <= time) { |
| | | //查询表 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | if (sysUsers.size() > 0) { |
| | | SysUser user = new SysUser(); |
| | | user.setId(sysUsers.get(0).getId()); |
| | | user.setPassword(passwordEncoder.encode(newPass)); |
| | | baseMapper.updateById(user); |
| | | //将Redis 清除 |
| | | redisUtils.hdel(ConstantSMS.PASSWORD_SMS, phone); |
| | | return ResultBody.ok(); |
| | | } else { |
| | | return ResultBody.failed("暂无该手机号信息"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("验证码超时"); |
| | | } |
| | | if (CheckVerificationCode(ConstantSMS.PASSWORD_SMS, map.get("phone").toString(), verificationCode)) { |
| | | //查询表 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | if (sysUsers.size() > 0) { |
| | | SysUser user = new SysUser(); |
| | | user.setId(sysUsers.get(0).getId()); |
| | | user.setPassword(passwordEncoder.encode(newPass)); |
| | | baseMapper.updateById(user); |
| | | //将Redis 清除 |
| | | redisUtils.hdel(ConstantSMS.PASSWORD_SMS, phone); |
| | | return ResultBody.ok(); |
| | | } else { |
| | | return ResultBody.failed("验证码错误"); |
| | | return ResultBody.failed("暂无该手机号信息"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("该手机号没有验证码"); |
| | | return ResultBody.failed("无效的验证码"); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param userRegVo |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody doctorUserReg(UserRegVo userRegVo) { |
| | | public ResultBody doctorUserReg(UserRegVo userRegVo, SysUser sysUserd) { |
| | | if(sysUserd.getId()==null){ |
| | | sysUserd = this.baseMapper.selectById(userRegVo.getUserId()); |
| | | } |
| | | //检查手机号是否已经注册 H端登录名和手机号存一样的值 |
| | | if (phoneIsUsed(userRegVo.getMobile())) { |
| | | return ResultBody.failed("该手机号已经注册"); |
| | | } |
| | | //检查判断是注册 还是添加用户,注册用户先走基本数据建设 |
| | | if (StringUtils.isBlank(userRegVo.getHospitalId().toString())) { |
| | | userRegVo.setDoctorState(true); |
| | | //添加医院组织结构数据 |
| | | List<SysOrganization> sysOrganizationList = new ArrayList<SysOrganization>(); |
| | | SysOrganization sysOrganizationHos = new SysOrganization(); |
| | | sysOrganizationHos.setOrgAttr(1); |
| | | sysOrganizationHos.setOrgLevel(1); |
| | | sysOrganizationHos.setOrgName(userRegVo.getHospitalName()); |
| | | sysOrganizationList.add(sysOrganizationHos); |
| | | |
| | | //添加科室组织数据 |
| | | SysOrganization sysOrganizationDe = new SysOrganization(); |
| | | sysOrganizationDe.setOrgAttr(2); |
| | | sysOrganizationDe.setOrgLevel(2); |
| | | sysOrganizationDe.setOrgName(userRegVo.getDepartmentName()); |
| | | sysOrganizationList.add(sysOrganizationDe); |
| | | //批量写入 |
| | | boolean orgRe = organizationService.saveBatch(sysOrganizationList); |
| | | if (orgRe) { |
| | | //创建人id |
| | | Long createUserId = CommonConstant.CREATE_USER_ID; |
| | | //创建人名称 |
| | | String createUserName = CommonConstant.CREATE_USER_NAME; |
| | | //是否注册用户 |
| | | Boolean isReg = false; |
| | | //业务成功 |
| | | Boolean isSuccess = true; |
| | | //业务失败提示信息 |
| | | String expMsg = ""; |
| | | //系统内置的注册医院和科室的组织数据 |
| | | Long organizationHos = CommonConstant.HOSPITAL_ORG_ID; |
| | | Long organizationDep = CommonConstant.DEPARTMENT_ORG_ID; |
| | | //检查判断是注册 还是添加用户,注册用户先走基本数据建设 医院/科室 |
| | | SysUserOrg sysUserOrgH = new SysUserOrg(); |
| | | SysUserOrg sysUserOrgD = new SysUserOrg(); |
| | | SysDictionaries sysDictionaries = new SysDictionaries(); |
| | | SysDoctor sysDoctor = new SysDoctor(); |
| | | if (userRegVo.getHospitalId() == null) { |
| | | isReg = true; |
| | | if (CheckVerificationCode(ConstantSMS.REGISTER_SMS, userRegVo.getMobile(), userRegVo.getVerification())) { |
| | | userRegVo.setDoctorState(true); |
| | | //写医院数据 |
| | | SysHospital sysHospital = new SysHospital(); |
| | | sysHospital.setHospitalName(userRegVo.getHospitalName()); |
| | | sysHospital.setOrgId(sysOrganizationHos.getId()); |
| | | sysHospital.setAccountsCount(1); |
| | | sysHospital.setOrgId(organizationHos); |
| | | sysHospital.setHospitalState(0); |
| | | sysHospital.setCreateUserId(0L); |
| | | sysHospital.setCreateUserName("自主注册"); |
| | | sysHospital.setCreateUserId(createUserId); |
| | | sysHospital.setCreateUserName(createUserName); |
| | | |
| | | boolean h = hospitalService.save(sysHospital); |
| | | if (h) { |
| | |
| | | //保存科室数据 |
| | | SysDepartment sysDepartment = new SysDepartment(); |
| | | sysDepartment.setHospitalId(sysHospital.getId()); |
| | | sysDepartment.setOrgId(sysOrganizationDe.getId()); |
| | | sysDepartment.setOrgId(organizationDep); |
| | | sysDepartment.setDepartmentName(userRegVo.getDepartmentName()); |
| | | sysDepartment.setSaleUserId(0L); |
| | | sysDepartment.setSaleUserName("自主注册"); |
| | | sysDepartment.setSaleUserId(createUserId); |
| | | sysDepartment.setAccountsCount(1); |
| | | sysDepartment.setSaleUserName(createUserName); |
| | | sysDepartment.setSaleUserTel("0"); |
| | | sysDepartment.setServerUserId(0L); |
| | | sysDepartment.setServerUserId(createUserId); |
| | | sysDepartment.setServerUserTel("0"); |
| | | sysDepartment.setServerUserName(createUserName); |
| | | boolean d = departmentService.save(sysDepartment); |
| | | if (!d) { |
| | | return ResultBody.failed("科室数据写入失败"); |
| | | isSuccess = false; |
| | | expMsg = "科室数据写入失败"; |
| | | } else { |
| | | userRegVo.setDepartmentId(sysDepartment.getId()); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("医院数据写入失败"); |
| | | isSuccess = false; |
| | | expMsg = "医院数据写入失败"; |
| | | } |
| | | } else { |
| | | return ResultBody.failed("组织数据写入失败"); |
| | | return ResultBody.failed("无效的验证码"); |
| | | } |
| | | } |
| | | |
| | | //业务执行中途出错 手动撤回数据 |
| | | if (isReg && !isSuccess) { |
| | | RollBackData(userRegVo.getHospitalId(), |
| | | userRegVo.getDepartmentId(), 0L, 0L, |
| | | 0L, 0L, 0L); |
| | | return ResultBody.failed(expMsg); |
| | | } |
| | | if (!isReg && departmetAccountsCount(userRegVo.getDepartmentId()) < 1) { |
| | | return ResultBody.failed("当前科室可创建账户数量已满"); |
| | | } |
| | | //添加用户数据 如果没有输入密码,将会创建一个默认密码返回 |
| | | String defaultPassWord = ""; |
| | |
| | | if (StringUtils.isBlank(userRegVo.getPassword())) { |
| | | defaultPassWord = com.kidgrow.common.utils.RandomValueUtils.getRandom(6); |
| | | sysUser.setPassword(passwordEncoder.encode(defaultPassWord)); |
| | | sysUser.setDefaultAuth(true); |
| | | userRegVo.setPassword(defaultPassWord); |
| | | } else { |
| | | sysUser.setPassword(passwordEncoder.encode(userRegVo.getPassword())); |
| | | sysUser.setDefaultAuth(false); |
| | | } |
| | | sysUser.setNickname(userRegVo.getNickname()); |
| | | sysUser.setSex(userRegVo.getSex()); |
| | |
| | | sysUser.setType(UserType.DOCTOR.name()); |
| | | } |
| | | sysUser.setHAdminUser(false); |
| | | sysUser.setDefaultAuth(false); |
| | | sysUser.setOpenId(userRegVo.getOpenId()); |
| | | sysUser.setDel(false); |
| | | sysUser.setTenantId("hospital"); |
| | | boolean u = this.save(sysUser); |
| | | SysRoleUser sysRoleUser = new SysRoleUser(); |
| | | if (u) { |
| | | //写入职务数据 |
| | | if (StringUtils.isNotBlank(userRegVo.getDoctorRank())) { |
| | | //检查医生职务是否存在 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("dictionaries_name", userRegVo.getDoctorRank()); |
| | | List<SysDictionaries> dictionariesList = sysDictionariesService.findAll(selectMap); |
| | | if (dictionariesList.size() > 0) { |
| | | for (int i = dictionariesList.size() - 1; i >= 0; i--) { |
| | | if (dictionariesList.get(i).getDictionariesName().equals(userRegVo.getDoctorRank())) { |
| | | userRegVo.setDoctorRankId(dictionariesList.get(i).getId()); |
| | | break; |
| | | //保存角色用户绑定信息 sys_role_user |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("code", CommonConstant.HOSPITAL_DOCTOR_CODE); |
| | | map.put("enabled", 1); |
| | | map.put("is_del", 0); |
| | | List<SysRole> sysRoles = sysRoleMapper.selectByMap(map); |
| | | if (sysRoles.size() > 0) { |
| | | //保存角色和用户绑定关系数据 |
| | | SysRole sysRole = sysRoles.get(0); |
| | | sysRoleUser.setRoleId(sysRole.getId()); |
| | | sysRoleUser.setUserId(sysUser.getId()); |
| | | int insert = sysUserRoleMapper.insert(sysRoleUser); |
| | | if (insert > 0) { |
| | | //写入职务数据 |
| | | if (StringUtils.isNotBlank(userRegVo.getDoctorRank())) { |
| | | //检查医生职务是否存在 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("dictionariesName", userRegVo.getDoctorRank()); |
| | | List<SysDictionaries> dictionariesList = sysDictionariesService.findAll(selectMap); |
| | | boolean dicBool = false; |
| | | if (dictionariesList.size() > 0) { |
| | | for (int i = dictionariesList.size() - 1; i >= 0; i--) { |
| | | if (dictionariesList.get(i).getDictionariesName().equals(userRegVo.getDoctorRank())) { |
| | | userRegVo.setDoctorRankId(dictionariesList.get(i).getId()); |
| | | dicBool = true; |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | //创建字典数据 |
| | | sysDictionaries.setDictionariesKey(DictionariesConstants.DOCTOR_RANK); |
| | | sysDictionaries.setDictionariesClassId(DictionariesConstants.DOCTOR_RANK_ID.toString()); |
| | | //将名称汉字转为拼音 |
| | | sysDictionaries.setDictionariesKey(Pinyin4jUtil.makeStringByStringSet(Pinyin4jUtil.getPinyin(userRegVo.getDoctorRank(), true))); |
| | | sysDictionaries.setDictionariesName(userRegVo.getDoctorRank()); |
| | | sysDictionaries.setCreateUserId(createUserId); |
| | | sysDictionaries.setCreateUserName(createUserName); |
| | | dicBool = sysDictionariesService.save(sysDictionaries); |
| | | } |
| | | |
| | | if (dicBool) { |
| | | userRegVo.setDoctorRankId(sysDictionaries.getId()); |
| | | //写用户组织关系表 |
| | | List<SysUserOrg> sysUserOrgList = new ArrayList<SysUserOrg>(); |
| | | |
| | | sysUserOrgH.setUserId(sysUser.getId()); |
| | | sysUserOrgH.setOrgId(organizationHos); |
| | | sysUserOrgH.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysUserOrgH.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | sysUserOrgList.add(sysUserOrgH); |
| | | |
| | | sysUserOrgD.setUserId(sysUser.getId()); |
| | | sysUserOrgD.setOrgId(organizationDep); |
| | | sysUserOrgD.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysUserOrgD.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | sysUserOrgList.add(sysUserOrgD); |
| | | boolean uOrg = iSysUserOrgService.saveBatch(sysUserOrgList); |
| | | if (uOrg) { |
| | | //写入医生数据 |
| | | sysDoctor.setUserId(sysUser.getId()); |
| | | sysDoctor.setHospitalId(userRegVo.getHospitalId()); |
| | | sysDoctor.setHospitalName(userRegVo.getHospitalName()); |
| | | sysDoctor.setDepartmentId(userRegVo.getDepartmentId()); |
| | | sysDoctor.setDepartmentName(userRegVo.getDepartmentName()); |
| | | sysDoctor.setDoctorRank(userRegVo.getDoctorRank()); |
| | | sysDoctor.setDoctorRankId(userRegVo.getDoctorRankId()); |
| | | sysDoctor.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysDoctor.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | if (isReg) { |
| | | sysDoctor.setDoctorState(false); |
| | | } |
| | | else |
| | | { |
| | | sysDoctor.setDoctorState(true); |
| | | } |
| | | sysDoctor.setDoctorTel(userRegVo.getMobile()); |
| | | sysDoctor.setDoctorName(userRegVo.getNickname()); |
| | | sysDoctor.setServerUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysDoctor.setServerUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | if (sysDoctorMapper.insert(sysDoctor) == 1) { |
| | | //非自主注册的 返回信息带密码 |
| | | if (!isReg) { |
| | | sysUser.setPassword(userRegVo.getPassword()); |
| | | } else { |
| | | sysUser.setPassword(""); |
| | | } |
| | | } else { |
| | | isSuccess = false; |
| | | expMsg = "医生数据写入失败"; |
| | | } |
| | | } else { |
| | | isSuccess = false; |
| | | expMsg = "用户组织数据写入失败"; |
| | | } |
| | | } else { |
| | | isSuccess = false; |
| | | expMsg = "职称数据写入失败"; |
| | | } |
| | | } else { |
| | | //没有职务数据 |
| | | isSuccess = false; |
| | | expMsg = "没有职称数据"; |
| | | } |
| | | } else { |
| | | //创建字典数据 |
| | | SysDictionaries sysDictionaries = new SysDictionaries(); |
| | | sysDictionaries.setDictionariesKey(DictionariesConstants.DOCTOR_RANK); |
| | | sysDictionaries.setDictionariesClassId(DictionariesConstants.DOCTOR_RANK_ID.toString()); |
| | | //将名称汉字转为拼音 |
| | | sysDictionaries.setDictionariesKey("temp"); |
| | | sysDictionaries.setDictionariesName(userRegVo.getDoctorRank()); |
| | | sysDictionaries.setCreateUserId(0L); |
| | | sysDictionaries.setCreateUserName("自动创建"); |
| | | boolean d = sysDictionariesService.save(sysDictionaries); |
| | | if (d) { |
| | | userRegVo.setDoctorRankId(sysDictionaries.getId()); |
| | | } |
| | | isSuccess = false; |
| | | expMsg = "角色绑定数据写入失败"; |
| | | } |
| | | } |
| | | //写入医生数据 |
| | | SysDoctor sysDoctor = new SysDoctor(); |
| | | sysDoctor.setUserId(sysUser.getId()); |
| | | sysDoctor.setHospitalId(userRegVo.getHospitalId()); |
| | | sysDoctor.setHospitalName(userRegVo.getHospitalName()); |
| | | sysDoctor.setDepartmentId(userRegVo.getDepartmentId()); |
| | | sysDoctor.setDepartmentName(userRegVo.getDepartmentName()); |
| | | sysDoctor.setDoctorRank(userRegVo.getDoctorRank()); |
| | | sysDoctor.setDoctorRankId(userRegVo.getDoctorRankId()); |
| | | sysDoctor.setCreateUserId(0L); |
| | | sysDoctor.setCreateUserName("自主注册"); |
| | | sysDoctor.setDoctorState(userRegVo.getDoctorState()); |
| | | sysDoctor.setDoctorTel(userRegVo.getMobile()); |
| | | sysDoctor.setDoctorName(userRegVo.getNickname()); |
| | | sysDoctor.setServerUserId(0L); |
| | | sysDoctor.setServerUserName("自主注册"); |
| | | if (sysDoctorMapper.insert(sysDoctor) == 1) { |
| | | sysUser.setPassword(userRegVo.getPassword()); |
| | | return ResultBody.ok(200, "注册成功").data(sysUser); |
| | | } else { |
| | | return ResultBody.failed("医生数据写入失败"); |
| | | isSuccess = false; |
| | | expMsg = "对应角色没有数据"; |
| | | } |
| | | } else { |
| | | return ResultBody.failed("用户数据写入失败"); |
| | | isSuccess = false; |
| | | expMsg = "用户数据写入失败"; |
| | | } |
| | | /***返回数据***/ |
| | | if (!isSuccess) { |
| | | //撤回数据 |
| | | RollBackData(0L, |
| | | 0L, sysUser.getId(), sysUserOrgH.getId(), |
| | | sysUserOrgH.getId(), sysDictionaries.getId(), |
| | | sysDoctor.getId()); |
| | | return ResultBody.failed(expMsg); |
| | | } else { |
| | | return ResultBody.ok().data(sysUser); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 手动撤回数据,需要撤回那个,给那个id传值,不需要的传0 |
| | | * |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @param userId |
| | | * @param userOrgIdH |
| | | * @param userOrgIdD |
| | | * @param dicId |
| | | * @param doctorId |
| | | */ |
| | | private void RollBackData(Long hospitalId, Long departmentId, |
| | | Long userId, Long userOrgIdH, Long userOrgIdD, |
| | | Long dicId, Long doctorId) { |
| | | if (hospitalId > 0) { |
| | | hospitalService.removeById(hospitalId); |
| | | } |
| | | if (departmentId > 0) { |
| | | departmentService.removeById(departmentId); |
| | | } |
| | | if (userId > 0) { |
| | | baseMapper.deleteById(userId); |
| | | sysUserRoleMapper.deleteById(userId); |
| | | } |
| | | if (userOrgIdH > 0) { |
| | | sysUserRoleMapper.deleteById(userOrgIdH); |
| | | } |
| | | if (userOrgIdD > 0) { |
| | | sysUserRoleMapper.deleteById(userOrgIdD); |
| | | } |
| | | if (dicId > 0) { |
| | | sysDictionariesService.removeById(dicId); |
| | | } |
| | | if (doctorId > 0) { |
| | | sysDoctorMapper.deleteById(doctorId); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取医院科室下的所有H端有效的医生 |
| | | * |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody hospitalDoctorList(Long hospitalId, Long departmentId,Boolean isIncluddel) { |
| | | if (hospitalId > 0 && departmentId > 0) { |
| | | List<HospitalDoctorListVo> listVoList; |
| | | if(isIncluddel){ |
| | | listVoList= baseMapper.hospitalDoctorListAndDel(hospitalId, departmentId,CommonConstant.HOSPITAL_DOCTOR_ID,CommonConstant.HOSPITAL_ADMIN_ID); |
| | | }else { |
| | | listVoList=baseMapper.hospitalDoctorList(hospitalId, departmentId,CommonConstant.HOSPITAL_DOCTOR_ID,CommonConstant.HOSPITAL_ADMIN_ID); |
| | | } |
| | | return ResultBody.ok().data(listVoList); |
| | | } else { |
| | | return ResultBody.failed("医院数据有误"); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param phone |
| | | * @return |
| | | */ |
| | | private boolean phoneIsUsed(String phone) { |
| | | public boolean phoneIsUsed(String phone) { |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | selectMap.put("is_del", 0); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | return (sysUsers.size() > 0); |
| | | } |
| | | |
| | | /** |
| | | * 检查科室有效剩余账户数量 |
| | | * |
| | | * @param depatmentId |
| | | * @return |
| | | */ |
| | | public Integer departmetAccountsCount(Long depatmentId) { |
| | | SysDepartment sysDepartment = departmentService.getById(depatmentId); |
| | | if (sysDepartment == null) { |
| | | return 0; |
| | | } else { |
| | | List<HospitalDoctorListVo> hospitalDoctorListVos = baseMapper.hospitalDoctorList(sysDepartment.getHospitalId(), depatmentId, CommonConstant.HOSPITAL_DOCTOR_ID, CommonConstant.HOSPITAL_ADMIN_ID); |
| | | if (hospitalDoctorListVos != null) { |
| | | int doctorCount = hospitalDoctorListVos.size(); |
| | | int accountCount = sysDepartment.getAccountsCount(); |
| | | return (accountCount - doctorCount); |
| | | } else { |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | // private Integer departmetAccountsCount(Long depatmentId) { |
| | | // SysDepartment sysDepartment = departmentService.getById(depatmentId); |
| | | // if (sysDepartment == null) { |
| | | // return 0; |
| | | // } else { |
| | | // Map<String, Object> selectMap = new HashMap<>(); |
| | | // selectMap.put("department_id", depatmentId); |
| | | // selectMap.put("enabled", 1); |
| | | // List<SysDoctor> sysDoctorList = sysDoctorMapper.selectByMap(selectMap); |
| | | // if (sysDoctorList != null) { |
| | | // int doctorCount = sysDoctorList.size(); |
| | | // int accountCount = sysDepartment.getAccountsCount(); |
| | | // return (accountCount - doctorCount); |
| | | // } else { |
| | | // return 0; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 检查用户登录名是否已经注册 true存在 false不存在 |
| | |
| | | return new com.kidgrow.usercenter.model.SysDoctor(); |
| | | } |
| | | |
| | | public ResultBody userIsAdmin(String userName) { |
| | | |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("username", userName); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | |
| | | return null; |
| | | /** |
| | | * 检查手机号是注册用户还是正式用户 |
| | | * @param userTel |
| | | * @return |
| | | */ |
| | | public ResultBody isRegUser(String userTel) |
| | | { |
| | | if (StringUtils.isNotBlank(userTel)) { |
| | | List<SysUser> users = baseMapper.selectList( |
| | | new QueryWrapper<SysUser>().eq("username", userTel) |
| | | ); |
| | | if (users != null&&users.size()==1) { |
| | | SysUser sysUser=users.get(0); |
| | | if (sysUser.getCreateUserId()==CommonConstant.CREATE_USER_ID&&sysUser.getCreateUserName().equals(CommonConstant.CREATE_USER_NAME)) { |
| | | return ResultBody.ok().data(true); |
| | | } |
| | | return ResultBody.ok().data(false); |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed("用户数据有误!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed("必要参数有误!"); |
| | | } |
| | | } |
| | | } |