forked from kidgrow-microservices-platform

kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java
@@ -87,6 +87,9 @@
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    @Autowired
    private SysOrganizationMapper sysOrganizationMapper;
    @Override
    public LoginAppUser findByUsername(String username) {
        SysUser sysUser = this.selectByUsername(username);
@@ -307,9 +310,7 @@
                        return ResultBody.failed("用户信息验证失败,请提供正确的手机号和密码!");
                    }
                }
            }
            else
            {
            } else {
                return ResultBody.failed("无效的验证码");
            }
        } else {
@@ -361,11 +362,11 @@
    @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);
        }
@@ -384,6 +385,7 @@
                roleUserService.saveBatch(roleUsers);
            }
        }
        sysUser.setPassword(defaultPassWord);
        return result ? ResultBody.ok().data(sysUser).msg("操作成功") : ResultBody.failed("操作失败");
    }
@@ -687,6 +689,7 @@
                SysHospital sysHospital = new SysHospital();
                sysHospital.setHospitalName(userRegVo.getHospitalName());
                sysHospital.setOrgId(organizationHos);
                //注册的用户所在医院默认是试用状态
                sysHospital.setHospitalState(0);
                sysHospital.setCreateUserId(createUserId);
                sysHospital.setCreateUserName(createUserName);
@@ -696,7 +699,6 @@
                    userRegVo.setHospitalId(sysHospital.getId());
                    //保存科室数据
                    SysDepartment sysDepartment = new SysDepartment();
                    sysDepartment.setHospitalId(sysHospital.getId());
                    sysDepartment.setOrgId(organizationDep);
                    sysDepartment.setDepartmentName(userRegVo.getDepartmentName());
                    sysDepartment.setSaleUserId(createUserId);
@@ -790,8 +792,7 @@
                            }
                        } 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());
@@ -835,9 +836,7 @@
                                sysDoctor.setCreateUserName(isReg ? createUserName : sysUserd.getUsername());
                                if (isReg) {
                                    sysDoctor.setDoctorState(false);
                                }
                                else
                                {
                                } else {
                                    sysDoctor.setDoctorState(true);
                                }
                                sysDoctor.setDoctorTel(userRegVo.getMobile());
@@ -980,7 +979,9 @@
        if (sysDepartment == null) {
            return 0;
        } else {
            List<HospitalDoctorListVo> hospitalDoctorListVos = baseMapper.hospitalDoctorList(sysDepartment.getHospitalId(), depatmentId, CommonConstant.HOSPITAL_DOCTOR_ID, CommonConstant.HOSPITAL_ADMIN_ID);
            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();
@@ -989,25 +990,66 @@
                return 0;
            }
        }
            else
            {
                return 0;
    }
//    private Integer departmetAccountsCount(Long depatmentId) {
//        SysDepartment sysDepartment = departmentService.getById(depatmentId);
//        if (sysDepartment == null) {
//            return 0;
//        } else {
        }
    }
    /**
     * 根据部门的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("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;
//                    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不存在
@@ -1036,11 +1078,11 @@
    /**
     * 检查手机号是注册用户还是正式用户
     *
     * @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)
@@ -1051,14 +1093,10 @@
                    return ResultBody.ok().data(true);
                }
                return ResultBody.ok().data(false);
            }
            else
            {
            } else {
                return ResultBody.failed("用户数据有误!");
            }
        }
        else
        {
        } else {
            return ResultBody.failed("必要参数有误!");
        }
    }