| | |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.common.utils.AesUtils; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.common.utils.Pinyin4jUtil; |
| | | import com.kidgrow.redis.util.RedisUtils; |
| | |
| | | private SysRoleMapper sysRoleMapper; |
| | | @Autowired |
| | | private SysUserRoleMapper sysUserRoleMapper; |
| | | @Autowired |
| | | private SysOrganizationMapper sysOrganizationMapper; |
| | | |
| | | @Override |
| | | public LoginAppUser findByUsername(String username) { |
| | |
| | | @Override |
| | | public LoginAppUser getLoginAppUser(SysUser sysUser) { |
| | | LoginAppUser loginAppUser = new LoginAppUser(); |
| | | SysUser sysUserNew = this.baseMapper.selectById(sysUser); |
| | | if (sysUser != null) { |
| | | //返回的数据为什么要把密码也返回?清空!! |
| | | loginAppUser.setPassword(""); |
| | |
| | | |
| | | BeanUtils.copyProperties(sysUser, loginAppUser); |
| | | //获取用户所属组织机构列表 |
| | | loginAppUser.setDefaultAuth(sysUserNew.getDefaultAuth()); |
| | | List<SysOrganization> sysOrganizations = organizationService.findListByUserId(sysUser.getId()); |
| | | //设置组织机构集合 |
| | | loginAppUser.setOrganizations(sysOrganizations); |
| | |
| | | public SysUser selectByUsername(String username) { |
| | | String clientId = ClientContextHolder.getClient(); |
| | | List<SysUser> users = baseMapper.selectList( |
| | | new QueryWrapper<SysUser>().eq("username", username).eq("tenant_id", clientId) |
| | | //new QueryWrapper<SysUser>().eq("username", username).eq("tenant_id", clientId) |
| | | new QueryWrapper<SysUser>().eq("username", username) |
| | | ); |
| | | return getUser(users); |
| | | } |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody updatePassword(Long id, String oldPassword, String newPassword, Boolean isdefault) { |
| | | public ResultBody updatePassword(Long id, String oldPassword, String newPassword, Boolean isdefault) throws Exception { |
| | | |
| | | SysUser sysUser = baseMapper.selectById(id); |
| | | if (StrUtil.isNotBlank(oldPassword)) { |
| | | oldPassword = AesUtils.desEncrypt(oldPassword).trim(); |
| | | if (!passwordEncoder.matches(oldPassword, sysUser.getPassword())) { |
| | | return ResultBody.failed("旧密码错误!"); |
| | | } |
| | | } |
| | | if (StrUtil.isBlank(newPassword)) { |
| | | newPassword = com.kidgrow.common.utils.RandomValueUtils.getRandom(6); |
| | | } else { |
| | | newPassword = AesUtils.desEncrypt(newPassword).trim(); |
| | | } |
| | | SysUser user = new SysUser(); |
| | | user.setId(id); |
| | | user.setPassword(passwordEncoder.encode(newPassword)); |
| | | if (isdefault) { |
| | | user.setDefaultAuth(true); |
| | | } else { |
| | | user.setDefaultAuth(false); |
| | | } |
| | | baseMapper.updateById(user); |
| | | if (isdefault) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResultBody updateUserTel(Map<String, Object> params) { |
| | | public ResultBody updateUserTel(Map<String, Object> params) throws Exception { |
| | | Long id = MapUtils.getLong(params, "id"); |
| | | String oldTel = MapUtils.getString(params, "oldTel"); |
| | | String newTel = MapUtils.getString(params, "newTel"); |
| | | String authCode = MapUtils.getString(params, "authCode"); |
| | | String userPassword = MapUtils.getString(params, "userPassword"); |
| | | String newTel = AesUtils.desEncrypt(MapUtils.getString(params, "newTel")).trim(); |
| | | String authCode = AesUtils.desEncrypt(MapUtils.getString(params, "authCode")).trim(); |
| | | String userPassword = AesUtils.desEncrypt(MapUtils.getString(params, "userPassword")).trim(); |
| | | |
| | | if (id > 0 && StringUtils.isNotBlank(oldTel) && StringUtils.isNotBlank(newTel) && StringUtils.isNotBlank(authCode) && StringUtils.isNotBlank(userPassword)) { |
| | | //检查验证码 |
| | |
| | | } else { |
| | | //验证旧手机号和密码 |
| | | SysUser sysUser = baseMapper.selectById(id); |
| | | userPassword = AesUtils.desEncrypt(userPassword); |
| | | if (passwordEncoder.matches(userPassword, sysUser.getPassword()) && sysUser.getMobile().equals((oldTel))) { |
| | | //验证通过,修改手机号 |
| | | SysUser user = new SysUser(); |
| | |
| | | } else { |
| | | return ResultBody.failed("手机号修改失败!"); |
| | | } |
| | | }else { |
| | | } else { |
| | | return ResultBody.failed("用户信息验证失败,请提供正确的手机号和密码!"); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | return ResultBody.failed("无效的验证码"); |
| | | } |
| | | } else { |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody saveOrUpdateUser(SysUser sysUser) { |
| | | String defaultPassWord = com.kidgrow.common.utils.RandomValueUtils.getRandom(6); |
| | | if (sysUser.getId() == null) { |
| | | if (StringUtils.isBlank(sysUser.getType())) { |
| | | sysUser.setType(UserType.BACKEND.name()); |
| | | } |
| | | String defaultPassWord = com.kidgrow.common.utils.RandomValueUtils.getRandom(6); |
| | | sysUser.setPassword(passwordEncoder.encode(defaultPassWord)); |
| | | sysUser.setEnabled(Boolean.TRUE); |
| | | } |
| | |
| | | roleUserService.saveBatch(roleUsers); |
| | | } |
| | | } |
| | | sysUser.setPassword(defaultPassWord); |
| | | return result ? ResultBody.ok().data(sysUser).msg("操作成功") : ResultBody.failed("操作失败"); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody passwordByPhone(Map<String, Object> map) { |
| | | public ResultBody passwordByPhone(Map<String, Object> map) throws Exception { |
| | | //手机号,type,验证码,新密码 |
| | | String phone = MapUtils.getString(map, "phone"); |
| | | if (phone == null || "".equals(phone.trim())) { |
| | |
| | | if (newPass == null || "".equals(newPass.trim())) { |
| | | return ResultBody.failed("请输入正确的密码"); |
| | | } |
| | | if (CheckVerificationCode(ConstantSMS.PASSWORD_SMS, map.get("phone").toString(), verificationCode)) { |
| | | phone = AesUtils.desEncrypt(phone.trim()); |
| | | verificationCode = AesUtils.desEncrypt(verificationCode.trim()); |
| | | newPass = AesUtils.desEncrypt(newPass.trim()); |
| | | if (CheckVerificationCode(ConstantSMS.PASSWORD_SMS, phone, verificationCode)) { |
| | | //查询表 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody doctorUserReg(UserRegVo userRegVo, SysUser sysUserd) { |
| | | if(sysUserd.getId()==null){ |
| | | public ResultBody doctorUserReg(UserRegVo userRegVo, SysUser sysUserd) throws Exception { |
| | | if (sysUserd.getId() == null) { |
| | | sysUserd = this.baseMapper.selectById(userRegVo.getUserId()); |
| | | } |
| | | userRegVo.setPassword(AesUtils.desEncrypt(userRegVo.getPassword()).trim()); |
| | | userRegVo.setUsername(AesUtils.desEncrypt(userRegVo.getUsername()).trim()); |
| | | //检查手机号是否已经注册 H端登录名和手机号存一样的值 |
| | | if (phoneIsUsed(userRegVo.getMobile())) { |
| | | return ResultBody.failed("该手机号已经注册"); |
| | | } |
| | | //创建人id |
| | | Long createUserId = CommonConstant.CREATE_USER_ID; |
| | | //创建人id |
| | | //创建人名称 |
| | | String createUserName = CommonConstant.CREATE_USER_NAME; |
| | | //是否注册用户 |
| | | Boolean isReg = false; |
| | |
| | | SysHospital sysHospital = new SysHospital(); |
| | | sysHospital.setHospitalName(userRegVo.getHospitalName()); |
| | | sysHospital.setOrgId(organizationHos); |
| | | //注册的用户所在医院默认是试用状态 |
| | | sysHospital.setHospitalState(0); |
| | | sysHospital.setCreateUserId(createUserId); |
| | | sysHospital.setCreateUserName(createUserName); |
| | |
| | | userRegVo.setHospitalId(sysHospital.getId()); |
| | | //保存科室数据 |
| | | SysDepartment sysDepartment = new SysDepartment(); |
| | | sysDepartment.setHospitalId(sysHospital.getId()); |
| | | sysDepartment.setOrgId(organizationDep); |
| | | sysDepartment.setDepartmentName(userRegVo.getDepartmentName()); |
| | | sysDepartment.setSaleUserId(createUserId); |
| | |
| | | } |
| | | } else { |
| | | //创建字典数据 |
| | | sysDictionaries.setDictionariesKey(DictionariesConstants.DOCTOR_RANK); |
| | | sysDictionaries.setDictionariesClassId(DictionariesConstants.DOCTOR_RANK_ID.toString()); |
| | | sysDictionaries.setDictionariesClassId(DictionariesConstants.DOCTOR_RANK); |
| | | //将名称汉字转为拼音 |
| | | sysDictionaries.setDictionariesKey(Pinyin4jUtil.makeStringByStringSet(Pinyin4jUtil.getPinyin(userRegVo.getDoctorRank(), true))); |
| | | sysDictionaries.setDictionariesName(userRegVo.getDoctorRank()); |
| | |
| | | |
| | | sysUserOrgH.setUserId(sysUser.getId()); |
| | | sysUserOrgH.setOrgId(organizationHos); |
| | | sysUserOrgH.setFromLevel(CommonConstant.SYSTEM_ORG_HOS_LEVEL); |
| | | sysUserOrgH.setFromId(userRegVo.getHospitalId()); |
| | | sysUserOrgH.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysUserOrgH.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | sysUserOrgList.add(sysUserOrgH); |
| | | |
| | | sysUserOrgD.setUserId(sysUser.getId()); |
| | | sysUserOrgD.setOrgId(organizationDep); |
| | | sysUserOrgD.setFromId(userRegVo.getDepartmentId()); |
| | | sysUserOrgD.setFromLevel(CommonConstant.SYSTEM_ORG_DEP_LEVEL); |
| | | sysUserOrgD.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysUserOrgD.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | sysUserOrgList.add(sysUserOrgD); |
| | |
| | | sysDoctor.setDepartmentName(userRegVo.getDepartmentName()); |
| | | sysDoctor.setDoctorRank(userRegVo.getDoctorRank()); |
| | | sysDoctor.setDoctorRankId(userRegVo.getDoctorRankId()); |
| | | sysDoctor.setDoctorType(CommonConstant.H_DOCTOR_TYPE); |
| | | sysDoctor.setCreateUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysDoctor.setCreateUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | if (isReg) { |
| | | sysDoctor.setDoctorState(false); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | sysDoctor.setDoctorState(true); |
| | | } |
| | | sysDoctor.setDoctorTel(userRegVo.getMobile()); |
| | | sysDoctor.setDoctorName(userRegVo.getNickname()); |
| | | sysDoctor.setServerUserId(isReg ? createUserId : sysUserd.getId()); |
| | | sysDoctor.setServerUserName(isReg ? createUserName : sysUserd.getUsername()); |
| | | sysDoctor.setIsAdminUser(false); |
| | | sysDoctor.setEnabled(!isReg); |
| | | if (sysDoctorMapper.insert(sysDoctor) == 1) { |
| | | //非自主注册的 返回信息带密码 |
| | | if (!isReg) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取医院科室下的所有有效的医生 |
| | | * 获取医院科室下的所有H端有效的医生 |
| | | * |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody hospitalDoctorList(Long hospitalId, Long departmentId) { |
| | | public ResultBody hospitalDoctorList(Long hospitalId, Long departmentId, Boolean isIncluddel) { |
| | | if (hospitalId > 0 && departmentId > 0) { |
| | | List<HospitalDoctorListVo> listVoList = baseMapper.hospitalDoctorList(hospitalId, departmentId); |
| | | 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 |
| | | */ |
| | | private Integer departmetAccountsCount(Long depatmentId) { |
| | | public 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 { |
| | | Long sysHospitalId=HospitalIdByDepartmentId(depatmentId); |
| | | if (sysHospitalId>0) { |
| | | List<HospitalDoctorListVo> hospitalDoctorListVos = baseMapper.hospitalDoctorList(sysHospitalId, 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; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据部门的id获取所属医院id |
| | | * |
| | | * @return |
| | | */ |
| | | public Long HospitalIdByDepartmentId(Long departmentId) { |
| | | Long hospitalId = -1L; |
| | | SysDepartment sysDepartment = departmentService.getById(departmentId); |
| | | if (sysDepartment != null) { |
| | | //先获取科室的组织数据 |
| | | SysOrganization sysOrganization = sysOrganizationMapper.selectById(sysDepartment.getOrgId()); |
| | | if (sysOrganization != null) { |
| | | //获取上级组织id |
| | | sysOrganization = sysOrganizationMapper.selectById(sysOrganization.getOrgParentId()); |
| | | if (sysOrganization != null) { |
| | | //根据组织id获取上级医院id |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("org_id", sysOrganization.getId()); |
| | | List<SysHospital> sysHospitalList = hospitalService.listByMap(selectMap); |
| | | if (sysHospitalList != null && sysHospitalList.size() > 0) { |
| | | //取第一个 |
| | | hospitalId = sysHospitalList.get(0).getId(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return hospitalId; |
| | | } |
| | | /** |
| | | * 根据部门的id获取所属医院id |
| | | * |
| | | * @return |
| | | */ |
| | | // public List<Long> DepartmentIdListByhospitalId(Long hospitalId) { |
| | | // List<Long> hospitalIdList =new ArrayList<Long>(); |
| | | // SysHospital sysHospital = hospitalService.getById(hospitalId); |
| | | // if (sysHospital != null) { |
| | | // //先获取医院的组织数据 |
| | | // SysOrganization sysOrganization = sysOrganizationMapper.selectById(sysHospital.getOrgId()); |
| | | // if (sysOrganization != null) { |
| | | // //根据组织id获取下级科室组织id |
| | | // Map<String, Object> selectMap = new HashMap<>(); |
| | | // selectMap.put("org_parent_id", sysOrganization.getId()); |
| | | // List<SysOrganization> sysDepartmentList = sysOrganizationMapper.selectByMap(selectMap); |
| | | // if (sysDepartmentList != null && sysDepartmentList.size() > 0) { |
| | | // //hospitalIdList=sysDepartmentList.stream().sorted(Comparator.comparing(SysOrganization::getCreateTime).reversed()).map(SysOrganization::getId).collect(Collectors.toList()); |
| | | // sysDepartmentList.stream().sorted(Comparator.comparing(SysOrganization::getCreateTime).reversed()).map(SysOrganization::getId).collect(Collectors.toList()).get(0); |
| | | // } |
| | | // } |
| | | // } |
| | | // return hospitalIdList; |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 检查用户登录名是否已经注册 true存在 false不存在 |
| | |
| | | |
| | | /** |
| | | * 检查手机号是注册用户还是正式用户 |
| | | * |
| | | * @param userTel |
| | | * @return |
| | | */ |
| | | public ResultBody isRegUser(String userTel) |
| | | { |
| | | 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)) { |
| | | 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 |
| | | { |
| | | } else { |
| | | return ResultBody.failed("用户数据有误!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | return ResultBody.failed("必要参数有误!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResultBody jiaMipython(String password) { |
| | | String encode = passwordEncoder.encode(password); |
| | | return ResultBody.ok().data(encode); |
| | | } |
| | | } |