forked from kidgrow-microservices-platform

houruijun
2020-08-20 e04727cd391a4c5953dfde7bfaab355b48897567
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;
@@ -19,6 +18,7 @@
import com.kidgrow.common.utils.AesUtils;
import com.kidgrow.common.utils.DateUtils;
import com.kidgrow.common.utils.Pinyin4jUtil;
import com.kidgrow.oprationcenter.feign.ProductOrderService;
import com.kidgrow.redis.util.RedisUtils;
import com.kidgrow.sms.feign.SmsChuangLanService;
import com.kidgrow.sms.model.ConstantSMS;
@@ -90,11 +90,18 @@
    private SysUserRoleMapper sysUserRoleMapper;
    @Autowired
    private SysOrganizationMapper sysOrganizationMapper;
    @Autowired
    private ProductOrderService productOrderService;
    @Override
    public LoginAppUser findByUsername(String username) {
        SysUser sysUser = this.selectByUsername(username);
        return getLoginAppUser(sysUser);
        if (sysUser == null) {
            return null;
        } else {
            return getLoginAppUser(sysUser);
        }
    }
    @Override
@@ -112,25 +119,22 @@
    /**
     * 获取登录用户的一系列信息 hrj 06-04修改
     *
     * @param sysUser
     * @param sysUserNew
     * @return
     */
    @Override
    public LoginAppUser getLoginAppUser(SysUser sysUser) {
    public LoginAppUser getLoginAppUser(SysUser sysUserNew) {
        LoginAppUser loginAppUser = new LoginAppUser();
        SysUser sysUserNew = this.baseMapper.selectById(sysUser);
        SysUser sysUser = this.baseMapper.selectById(sysUserNew);
        if (sysUser != null) {
            //返回的数据为什么要把密码也返回?清空!!
            loginAppUser.setPassword("");
            loginAppUser.setNewPassword("");
            loginAppUser.setOldPassword("");
            BeanUtils.copyProperties(sysUser, loginAppUser);
            //获取用户所属组织机构列表
            loginAppUser.setDefaultAuth(sysUserNew.getDefaultAuth());
            loginAppUser.setDefaultAuth(sysUser.getDefaultAuth());
            List<SysOrganization> sysOrganizations = organizationService.findListByUserId(sysUser.getId());
            //设置组织机构集合
            loginAppUser.setOrganizations(sysOrganizations);
            if (sysOrganizations != null) {
                loginAppUser.setOrganizations(sysOrganizations);
            }
            List<SysRole> sysRoles = roleUserService.findRolesByUserId(sysUser.getId());
            // 设置角色
            loginAppUser.setRoles(sysRoles);
@@ -145,15 +149,13 @@
                    loginAppUser.setPermissions(permissions);
                }
            }
            //是否医院管理员
            com.kidgrow.usercenter.model.SysDoctor sysDoctor = findDoctorByUserId(sysUser.getId());
            if (sysDoctor.getIsAdminUser() != null) {
                loginAppUser.setHAdminUser(sysDoctor.getIsAdminUser());
            }
            //医院信息 只有H端要返回的信息
            if (sysUser.getTenantId().toLowerCase().equals(CommonConstant.H_TENANT.toLowerCase())) {
                DoctorUserAll doctorUserAllVo = baseMapper.findDoctorUserAllData(sysUser.getId());
            //医院信息
            DoctorUserAll doctorUserAllVo = baseMapper.findDoctorUserAllData(sysUser.getId());
            if (doctorUserAllVo != null) {
                loginAppUser.setDoctorUserAllVO(doctorUserAllVo);
                //是否医院管理员
                loginAppUser.setHAdminUser(doctorUserAllVo.getIsAdminUser());
            }
        }
        return loginAppUser;
@@ -464,8 +466,8 @@
    @Override
    public ResultBody findCountByMap(Map<String, Object> map) {
        map.put("enable",1);
        map.put("is_del",0);
        map.put("enable", 1);
        map.put("is_del", 0);
        Integer integer = baseMapper.selectCountByMap(map);
        return ResultBody.ok().data(integer);
    }
@@ -712,11 +714,16 @@
                    sysDepartment.setServerUserTel("0");
                    sysDepartment.setServerUserName(createUserName);
                    boolean d = departmentService.save(sysDepartment);
                    if (!d) {
                    if (d) {
                        userRegVo.setDepartmentId(sysDepartment.getId());
                        //自动充入系统指定的试用套餐
                        if (!saveProductDetail(sysHospital.getId(), sysDepartment.getId(), sysHospital.getHospitalName(), sysDepartment.getDepartmentName())) {
                            isSuccess = false;
                            expMsg = "套餐充值失败";
                        }
                    } else {
                        isSuccess = false;
                        expMsg = "科室数据写入失败";
                    } else {
                        userRegVo.setDepartmentId(sysDepartment.getId());
                    }
                } else {
                    isSuccess = false;
@@ -729,6 +736,7 @@
        //业务执行中途出错
        if (isReg && !isSuccess) {
            //注册过程失败
            return ResultBody.failed(expMsg);
        }
        if (!isReg && departmetAccountsCount(userRegVo.getDepartmentId()) < 1) {
@@ -841,7 +849,8 @@
                                sysDoctor.setServerUserId(isReg ? createUserId : sysUserd.getId());
                                sysDoctor.setServerUserName(isReg ? createUserName : sysUserd.getUsername());
                                sysDoctor.setIsAdminUser(false);
                                sysDoctor.setEnabled(!isReg);
                                sysDoctor.setDoctorCcie(userRegVo.getDoctorCcie());
                                sysDoctor.setEnabled(true);
                                if (sysDoctorMapper.insert(sysDoctor) == 1) {
                                    //非自主注册的 返回信息带密码
                                    if (!isReg) {
@@ -885,6 +894,26 @@
            return ResultBody.ok().data(sysUser);
        }
    }
    /**
     * feign客户端调用写入试用套餐
     *
     * @param hospitalId
     * @param departmentId
     * @param hospitalName
     * @param departmentName
     * @return
     */
    private boolean saveProductDetail(Long hospitalId, Long departmentId, String hospitalName, String departmentName) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hospitalId", hospitalId);
        params.put("departmentId", departmentId);
        params.put("hospitalName", hospitalName);
        params.put("departmentName", departmentName);
        ResultBody resultBody = productOrderService.saveProductDetail(params);
        return (boolean) resultBody.getData();
    }
    /**
     * 获取医院科室下的所有H端有效的医生
     *
@@ -917,6 +946,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);
    }
@@ -932,20 +962,18 @@
        if (sysDepartment == null) {
            return 0;
        } else {
            Long sysHospitalId=HospitalIdByDepartmentId(depatmentId);
            if (sysHospitalId>0) {
            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().intValue();
                    int liveCount=accountCount - doctorCount;
                    int liveCount = accountCount - doctorCount;
                    return liveCount;
                } else {
                    return 0;
                }
            }
            else
            {
            } else {
                return 0;
            }
        }
@@ -1042,8 +1070,8 @@
        QueryWrapper<SysDoctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        List<SysDoctor> sysDoctors = sysDoctorMapper.selectList(queryWrapper);
        if(!sysDoctors.isEmpty()){
            sysDoctors.forEach(e->{
        if (!sysDoctors.isEmpty()) {
            sysDoctors.forEach(e -> {
                e.setIsDel(true);
                sysDoctorMapper.updateById(e);
            });