forked from kidgrow-microservices-platform

dougang
2020-08-15 247aa0db4e8e91508085e70ba8bbb094782861fc
kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java
@@ -4,7 +4,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kidgrow.common.constant.CommonConstant;
import com.kidgrow.common.constant.DictionariesConstants;
@@ -727,11 +726,8 @@
            }
        }
        //业务执行中途出错  手动撤回数据
        //业务执行中途出错
        if (isReg && !isSuccess) {
            RollBackData(userRegVo.getHospitalId(),
                    userRegVo.getDepartmentId(), 0L, 0L,
                    0L, 0L, 0L);
            return ResultBody.failed(expMsg);
        }
        if (!isReg && departmetAccountsCount(userRegVo.getDepartmentId()) < 1) {
@@ -761,7 +757,7 @@
        sysUser.setDefaultAuth(false);
        sysUser.setOpenId(userRegVo.getOpenId());
        sysUser.setDel(false);
        sysUser.setTenantId("hospital");
        sysUser.setTenantId(CommonConstant.H_TENANT);
        boolean u = this.save(sysUser);
        SysRoleUser sysRoleUser = new SysRoleUser();
        if (u) {
@@ -883,55 +879,11 @@
        }
        /***返回数据***/
        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端有效的医生
     *
@@ -964,6 +916,7 @@
        Map<String, Object> selectMap = new HashMap<>();
        selectMap.put("mobile", phone);
        selectMap.put("is_del", 0);
        selectMap.put("tenant_id", "hospital");
        List<SysUser> sysUsers = baseMapper.selectByMap(selectMap);
        return (sysUsers.size() > 0);
    }
@@ -1026,31 +979,6 @@
        }
        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不存在