forked from kidgrow-microservices-platform

克 刘
2021-03-01 183f436c553b641770fdb2352452192c97009a84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
package com.kidgrow.usercenter.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kidgrow.common.constant.CommonConstant;
import com.kidgrow.common.constant.SecurityConstants;
import com.kidgrow.common.model.*;
import com.kidgrow.common.service.impl.SuperServiceImpl;
import com.kidgrow.common.utils.StringUtils;
import com.kidgrow.redis.util.RedisConstant;
import com.kidgrow.redis.util.RedisUtils;
import com.kidgrow.usercenter.mapper.*;
import com.kidgrow.usercenter.model.SysDepartment;
import com.kidgrow.usercenter.model.SysDoctor;
import com.kidgrow.usercenter.model.SysHospital;
import com.kidgrow.usercenter.model.SysRoleUser;
import com.kidgrow.usercenter.service.ISysDoctorService;
import com.kidgrow.usercenter.service.ISysUserOrgService;
import com.kidgrow.usercenter.service.ISysUserService;
import com.kidgrow.usercenter.vo.SysDoctorDto;
import com.kidgrow.usercenter.vo.SysDoctorVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @version 1.0
 * @Description: <br>
 * @Project: 用户中心<br>
 * @CreateDate: Created in 2020-04-02 14:02:50 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
@Slf4j
@Service
public class SysDoctorServiceImpl extends SuperServiceImpl<SysDoctorMapper, SysDoctor> implements ISysDoctorService {
    /**
     * 列表
     *
     * @param params
     * @return
     */
    @Autowired
    private ISysUserService iSysUserService;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private ISysUserOrgService sysUserOrgService;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private SysRoleOrganizationServiceImpl SysRoleOrganizationServiceImpl;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysHospitalMapper sysHospitalMapper;
    @Autowired
    private SysDepartmentMapper sysDepartmentMapper;
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    @Autowired
    private SysUserServiceImpl sysUserServiceImpl;
 
//    private final String HOSPITAL_ADMIN="hospital_admin";
 
    @Override
    public PageResult<SysDoctorDto> findList(Map<String, Object> params, SysUser user) {
        Page<SysDoctor> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
        //添加权限
        SysRoleOrganizationServiceImpl.getRoleOrg(params, user);
        List<SysDoctor> list = baseMapper.findList(page, params);
        List<SysDoctorDto> listvo = new ArrayList<>();
        list.forEach(e -> {
            SysDoctorDto vo = new SysDoctorDto();
            BeanCopier beanCopier = BeanCopier.create(SysDoctor.class, SysDoctorVo.class, false);
            beanCopier.copy(e, vo, null);
            //查询用户的登录账号;
            if (e.getUserId() != null) {
                SysUser sysUser = iSysUserService.getById(e.getUserId());
                if (sysUser != null) {
                    vo.setUsername(sysUser.getUsername());
                }
                QueryWrapper queryWrapper = new QueryWrapper();
                queryWrapper.eq("user_id", e.getUserId());
                List<SysRoleUser> roleUserList = sysUserRoleMapper.selectList(queryWrapper);
                List<Long> collect = roleUserList.stream().map(roleUser -> roleUser.getRoleId()).collect(Collectors.toList());
                vo.setRoles(collect);
            }
            listvo.add(vo);
        });
        return PageResult.<SysDoctorDto>builder().data(listvo).code(0).count(page.getTotal()).build();
    }
 
    /**
     * 根据SysDoctor对象当做查询条件进行查询
     *
     * @param sysDoctor
     * @return SysDoctor
     */
    @Override
    public SysDoctor findByObject(SysDoctor sysDoctor) {
        return baseMapper.findByObject(sysDoctor);
    }
 
    @Override
    public boolean delete(Long id) {
        //查询user表
        SysDoctor sysDoctor = baseMapper.selectById(id);
        if (sysDoctor != null && sysDoctor.getUserId() != null) {
            boolean b = iSysUserService.deleteNoContact(sysDoctor.getUserId());
        }
        sysDoctor.setIsDel(true);
        int i = baseMapper.updateById(sysDoctor);
        return true;
    }
 
    /**
     * 根据userid删除医生数据
     *
     * @param userId
     * @return
     */
    @Override
    public int deleteByUserId(Long userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        return baseMapper.deleteByMap(params);
    }
 
    /**
     * 统计医生的数量
     *
     * @param datatype 业务类型
     *                 0 自注册医生
     *                 1 签约医生
     *                 2 医答医生
     *                 3 C端医生
     *                 4 H端医生
     *                 5 待审核医生
     * @return
     */
    @Override
    public int chartDoctor(int datatype) {
        return baseMapper.chartDoctor(datatype);
    }
 
    @Override
    public ResultBody enable(Map<String, Object> params) {
        Long aLong = MapUtils.getLong(params, "id");
        SysDoctor sysDoctor = baseMapper.selectById(aLong);
        Boolean enabled = MapUtils.getBoolean(params, "enabled");
        if (sysDoctor != null && sysDoctor.getUserId() != null) {
            SysUser byId = iSysUserService.getById(sysDoctor.getUserId());
            if (byId != null) {
                byId.setEnabled(enabled);
                iSysUserService.updateById(byId);
            }
        }
        if (sysDoctor != null) {
 
            sysDoctor.setEnabled(enabled);
            baseMapper.updateById(sysDoctor);
        } else {
            return ResultBody.failed("禁用失败");
        }
        return ResultBody.ok(0, "禁用成功");
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody saveOrUpdateSer(SysDoctorDto sysDoctor, HttpServletRequest request, SysUser user) {
        String id = request.getHeader(SecurityConstants.USER_ID_HEADER);
        if (null == sysDoctor) {
            return ResultBody.failed("请填写信息");
        } else {
            Boolean flag = false;
            if (sysDoctor.getDoctorType() != 2) {
                if (sysDoctor.getRoles() == null || sysDoctor.getRoles().size() <= 0) {
                    return ResultBody.failed("选择一个角色");
                }
            }
            SysHospital sysHospital = sysHospitalMapper.selectById(sysDoctor.getHospitalId());
            SysDepartment sysDepartment = sysDepartmentMapper.selectById(sysDoctor.getDepartmentId());
            if (sysDoctor.getId() == null) {
                /**
                 * 限制只有创建医生的个数
                 *
                 */
                if (sysUserServiceImpl.departmetAccountsCount(sysDoctor.getDepartmentId()) <= 0) {
                    return ResultBody.failed("该部门创建人数已经达到上限");
                }
                Long sysUserId = null;
                //保存部门信息
                ResultBody resultBody = this.saveFenjiekou(sysDoctor, id, sysHospital, sysDepartment, null);
                if (resultBody.getCode() == 0) {
                    sysUserId = (Long) resultBody.getData();
                } else {
                    return resultBody;
                }
                //保存doctor的数据
                SysDoctor sysDoc = new SysDoctor();
                BeanCopier beanCopier = BeanCopier.create(SysDoctorDto.class, SysDoctor.class, false);
                beanCopier.copy(sysDoctor, sysDoc, null);
                sysDoc.setUserId(sysUserId);
                if (user.getOrganizations() != null) {
                    List<SysOrganization> organizations = user.getOrganizations();
                    sysDoc.setCreateUserOrgCode(organizations.get(organizations.size() - 1).getOrgCode());
                }
                baseMapper.insert(sysDoc);
            } else {
                //更新
                SysDoctor getOne = baseMapper.selectById(sysDoctor.getId());
                if (getOne.getDoctorType() != 2 && sysDoctor.getDoctorType() != 2) {
                    QueryWrapper queryrole = new QueryWrapper();
                    queryrole.eq("user_id", getOne.getUserId());
                    List<SysRoleUser> list = sysUserRoleMapper.selectList(queryrole);
                    //如果是本来是管理员的话,不用走判读管理员的方法
                    if (!list.isEmpty()) {
                        List<Long> collect = list.stream().map(e -> e.getRoleId()).collect(Collectors.toList());
                        if (!collect.contains(CommonConstant.HOSPITAL_ADMIN_ID)) {
                            /**
                             * 管理员只有一个
                             */
                            if (isSupperRole(sysDoctor)) {
                                return ResultBody.failed("该部门已经有管理员");
                            }
                        }
                    } else {
                        /**
                         * 管理员只有一个
                         */
                        if (isSupperRole(sysDoctor)) {
                            return ResultBody.failed("该部门已经有管理员");
                        }
                    }
                    Map<String, Object> columnMap = new HashMap<>();
                    columnMap.put("user_id", getOne.getUserId());
                    boolean b = sysUserOrgService.removeByMap(columnMap);
                    //保存将sys_user_org
                    SysUserOrg sysUserOrg = new SysUserOrg();
                    sysUserOrg.setUserId(getOne.getUserId());
                    sysUserOrg.setEnabled(true);
                    sysUserOrg.setFromId(sysDoctor.getDepartmentId());
                    sysUserOrg.setFromLevel(CommonConstant.SYSTEM_ORG_DEP_LEVEL);
                    sysUserOrg.setOrgId(sysDepartment.getOrgId());
                    sysUserOrg.setCreateTime(new Date());
                    List<SysUserOrg> sysUserOrgs=new ArrayList<>();
                    sysUserOrgs.add(sysUserOrg);
                    sysUserOrgService.saveOrUpdate(sysUserOrg);
                    SysUserOrg sysGongsi = new SysUserOrg();
                    sysGongsi.setUserId(getOne.getUserId());
                    sysGongsi.setOrgId(sysHospital.getOrgId());
                    sysGongsi.setFromId(sysDoctor.getHospitalId());
                    sysGongsi.setFromLevel(CommonConstant.SYSTEM_ORG_HOS_LEVEL);
                    sysGongsi.setEnabled(true);
                    sysUserOrgs.add(sysGongsi);
                    sysUserOrgService.saveOrUpdate(sysGongsi);
                    baseMapper.updateById(sysDoctor);
                    if (redisUtils.hHasKey(RedisConstant.USER_ORGANIZATION, getOne.getUserId().toString())) {
                        redisUtils.hdel(RedisConstant.USER_ORGANIZATION, getOne.getUserId().toString());
                    }
                    redisUtils.hset(RedisConstant.USER_ORGANIZATION, getOne.getUserId().toString(), sysUserOrgs);
                    //角色更换
                    QueryWrapper queryWrapper = new QueryWrapper();
                    queryWrapper.eq("user_id", getOne.getUserId());
                    int delete = sysUserRoleMapper.delete(queryWrapper);
                    sysDoctor.getRoles().forEach(e -> {
                        SysRoleUser sysRoleUser = new SysRoleUser();
                        sysRoleUser.setRoleId(e);
                        sysRoleUser.setUserId(getOne.getUserId());
                        int insert = sysUserRoleMapper.insert(sysRoleUser);
                    });
                } else if (getOne.getDoctorType() == 2 && sysDoctor.getDoctorType() != 2) {
                    /**
                     * 管理员只有一个
                     */
                    if (isSupperRole(sysDoctor)) {
                        return ResultBody.failed("该部门已经有管理员");
                    }
                    ResultBody resultBody = this.saveFenjiekou(sysDoctor, id, sysHospital, sysDepartment, getOne);
                    Long sysUserId = null;
                    if (resultBody.getCode() == 0) {
                        sysUserId = (Long) resultBody.getData();
                    } else {
                        return resultBody;
                    }
                    sysDoctor.setUserId(sysUserId);
                    baseMapper.updateById(sysDoctor);
                } else if (getOne.getDoctorType() != 2 && sysDoctor.getDoctorType() == 2) {
                    //将组织删除
                    Map<String, Object> columnMap = new HashMap<>();
                    columnMap.put("user_id", getOne.getUserId());
                    boolean b = sysUserOrgService.removeByMap(columnMap);
                    SysUser byId = iSysUserService.getById(getOne.getUserId());
                    //将角色删除
                    QueryWrapper queryWrapper = new QueryWrapper();
                    queryWrapper.eq("user_id", getOne.getUserId());
                    int delete = sysUserRoleMapper.delete(queryWrapper);
                    if (byId != null) {
                        byId.setDel(true);
                        boolean b1 = iSysUserService.updateById(byId);
                    }
                    redisUtils.hdel(RedisConstant.USER_ORGANIZATION, getOne.getUserId().toString());
                    sysDoctor.setUserId(null);
                    baseMapper.updateById(sysDoctor);
                    //将用户删除
                    SysUser sysUser = new SysUser();
                    sysUser.setId(getOne.getUserId());
                    sysUser.setDel(true);
                    sysUserMapper.deleteById(sysUser);
                } else if (getOne.getDoctorType() == 2 && sysDoctor.getDoctorType() == 2) {
                    baseMapper.updateById(sysDoctor);
                }
            }
        }
        return ResultBody.ok();
    }
 
    //是否可以使是超管角色
    public Boolean isSupperRole(SysDoctorDto sysDoctor) {
        Boolean flag = false;
        /**
         * 限制管理员只有一个
         */
        if (sysDoctor.getDoctorType() != 2) {
            if (sysDoctor.getRoles().contains(CommonConstant.HOSPITAL_ADMIN_ID)) {
                //查询一个部门下的所有医生
                QueryWrapper wrapper = new QueryWrapper();
                wrapper.eq("is_del", 0);
                wrapper.eq("enabled", 1);
                wrapper.eq("department_id", sysDoctor.getDepartmentId());
                List<SysDoctor> doctoerList = this.baseMapper.selectList(wrapper);
                if (doctoerList.size() > 0) {
                    //查询role——user
                    List<Long> collect = doctoerList.stream().map(e -> e.getUserId()).collect(Collectors.toList());
                    wrapper = new QueryWrapper();
                    wrapper.in("user_id", collect);
                    List<SysRoleUser> list = this.sysUserRoleMapper.selectList(wrapper);
                    for (SysRoleUser sysRoleUser : list) {
                        if (sysRoleUser.getRoleId().equals(CommonConstant.HOSPITAL_ADMIN_ID)) {
                            flag = true;
                        }
                    }
                }
            }
        }
        return flag;
    }
 
    //保存的分接口
    public ResultBody saveFenjiekou(SysDoctorDto sysDoctor, String id, SysHospital sysHospital, SysDepartment sysDepartment, SysDoctor getOne) {
        Long sysUserId = null;
        /**
         * 管理员只有一个
         */
        if (isSupperRole(sysDoctor)) {
            return ResultBody.failed("该部门已经有管理员");
        }
        if (sysDoctor.getDoctorType() != 2) {
            SysUser sysUser = new SysUser();
            //保存
            sysUser.setUsername(sysDoctor.getUsername());
            sysUser.setPassword(passwordEncoder.encode(sysDoctor.getPassword()));
            sysUser.setNickname(sysDoctor.getDoctorName());
            sysUser.setHeadImgUrl(sysDoctor.getDoctorLogo());
            sysUser.setMobile(sysDoctor.getDoctorTel());
            sysUser.setType(UserType.DOCTOR.name());
            sysUser.setTenantId(CommonConstant.H_TENANT);
            sysUser.setCreateTime(new Date());
            sysUser.setDefaultAuth(true);
            SysUser byId = iSysUserService.getById(id);
            if (byId != null) {
                sysUser.setCreateUserId(byId.getId());
                sysUser.setCreateUserName(byId.getUsername());
            }
            //做判断是否注册过手机号;
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("username", sysDoctor.getDoctorTel());
            queryWrapper.eq("enabled", 1);
            queryWrapper.eq("is_del", 0);
            Integer integer = sysUserMapper.selectCount(queryWrapper);
            if (integer > 0) {
                return ResultBody.failed("该手机号已经注册");
            }
            if (getOne != null && getOne.getUserId() != null) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", getOne.getUserId());
                map.put("enabled", 1);
                map.put("is_del", 1);
                List<SysUser> sysUsers = sysUserMapper.selectByMap(map);
                if (sysUsers != null && !sysUsers.isEmpty()) {
                    sysUser.setId(sysUsers.get(sysUsers.size() - 1).getId());
                }
            }
            if (sysUser.getId() != null) {
                //更新
                sysUser.setDel(false);
                iSysUserService.updateById(sysUser);
            } else {
                //保存
                iSysUserService.save(sysUser);
            }
            sysUserId = sysUser.getId();
            //保存一个角色
            sysDoctor.getRoles().forEach(e -> {
                SysRoleUser sysRoleUser = new SysRoleUser();
                sysRoleUser.setRoleId(e);
                sysRoleUser.setUserId(sysUser.getId());
                int insert = sysUserRoleMapper.insert(sysRoleUser);
            });
            List<SysUserOrg> sysUserOrgs=new ArrayList<>();
            //保存将sys_user_org 保存部门
            SysUserOrg sysUserOrg = new SysUserOrg();
            sysUserOrg.setUserId(sysUser.getId());
            sysUserOrg.setFromId(sysDoctor.getDepartmentId());
            sysUserOrg.setFromLevel(CommonConstant.SYSTEM_ORG_DEP_LEVEL);
            sysUserOrg.setOrgId(sysDepartment.getOrgId());
            sysUserOrgs.add(sysUserOrg);
            //保存公司
            sysUserOrgService.saveOrUpdate(sysUserOrg);
            SysUserOrg sysGongsi = new SysUserOrg();
            sysGongsi.setUserId(sysUser.getId());
            sysGongsi.setOrgId(sysHospital.getOrgId());
            sysGongsi.setFromId(sysDoctor.getHospitalId());
            sysGongsi.setFromLevel(CommonConstant.SYSTEM_ORG_DEP_LEVEL);
            sysUserOrgService.saveOrUpdate(sysGongsi);
            sysUserOrgs.add(sysGongsi);
            //保存到Redis
            boolean hset = redisUtils.hset(RedisConstant.USER_ORGANIZATION, sysUserOrg.getUserId().toString(), sysUserOrgs);
        }
        return ResultBody.ok().data(sysUserId);
    }
 
    @Override
    public List<SysDoctor> findByMap(Map<String, Object> map) {
        map.put("enabled", 1);
        map.put("is_del", 0);
        return baseMapper.selectByMap(map);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody setAdminDoctor(Map<String, Object> params) {
        Long id = MapUtils.getLong(params, "id");
        Long adminId = MapUtils.getLong(params, "adminId");
        if (id > 0 && adminId > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("user_id", adminId);
            map.put("is_admin_user", 1);
            map.put("is_del", 0);
            map.put("enabled", 1);
            List<SysDoctor> sysDoctors = baseMapper.selectByMap(map);
            if (sysDoctors == null || sysDoctors.size() <= 0) {
                return ResultBody.failed("当前操作用户不是管理员");
            }
            SysDoctor sysDoctor = sysDoctors.get(0);
            //先检查操作用户是否管理员
            if (sysDoctor != null) {
                if (sysDoctor.getIsAdminUser()) {
                    //将超级管理员的角色设为普通角色
                    SysRoleUser sysRoleUser = new SysRoleUser();
                    sysRoleUser.setUserId(adminId);
                    sysRoleUser.setRoleId(CommonConstant.HOSPITAL_DOCTOR_ID);
                    QueryWrapper queryWrapper = new QueryWrapper();
                    queryWrapper.eq("user_id", adminId);
//                    queryWrapper.eq("role_id", CommonConstant.HOSPITAL_ADMIN_ID);
                    int delete = sysUserRoleMapper.delete(queryWrapper);
                    int update = sysUserRoleMapper.insert(sysRoleUser);
                    //现将操作人员设为非管理角色
                    sysDoctor.setIsAdminUser(false);
                    if (baseMapper.updateById(sysDoctor) > 0) {
                        //再将新用户设为管理
                        sysDoctor = baseMapper.selectById(id);
                        if (sysDoctor != null) {
                            if (!sysDoctor.getIsAdminUser()) {
                                //现将普通人员设为管理角色
                                sysRoleUser = new SysRoleUser();
                                sysRoleUser.setUserId(sysDoctor.getUserId());
                                sysRoleUser.setRoleId(CommonConstant.HOSPITAL_ADMIN_ID);
                                queryWrapper = new QueryWrapper();
                                queryWrapper.eq("user_id", sysDoctor.getUserId());
//                                queryWrapper.eq("role_id", CommonConstant.HOSPITAL_DOCTOR_ID);
                                sysUserRoleMapper.delete(queryWrapper);
                                sysUserRoleMapper.insert(sysRoleUser);
                                sysDoctor.setIsAdminUser(true);
                                if (baseMapper.updateById(sysDoctor) > 0) {
                                    return ResultBody.ok().data(true).msg("管理员设置成功!");
                                } else {
                                    return ResultBody.failed("设为管理失败!").data(false);
                                }
                            } else {
                                return ResultBody.failed("设为管理失败,改用户就是管理员!").data(false);
                            }
                        } else {
                            return ResultBody.failed("用户信息有误!").data(false);
                        }
                    } else {
                        return ResultBody.failed("设为管理失败!").data(false);
                    }
                } else {
                    return ResultBody.failed("当前操作用户不是管理员!").data(false);
                }
            } else {
                return ResultBody.failed("用户信息有误!").data(false);
            }
 
        } else {
            return ResultBody.failed("业务参数有误!").data(false);
        }
    }
 
    /**
     * 判断用户名是否管理员
     *
     * @param userName
     * @return
     */
    @Override
    public ResultBody userIsAdmin(String userName) {
        if (StringUtils.isNotBlank(userName)) {
            SysDoctor sysDoctor = baseMapper.userIsAdmin(userName);
            if (sysDoctor != null) {
                return ResultBody.ok().data(sysDoctor.getIsAdminUser());
            } else {
                return ResultBody.failed().data(false);
            }
        } else {
            return ResultBody.failed("用户名不能为空!").data(false);
        }
    }
}