From e2fbec6f82a6163dcc37810d377845e6686ac2cb Mon Sep 17 00:00:00 2001
From: zhaoxiaohao <913652501@qq.com>
Date: Mon, 22 Jun 2020 15:13:59 +0800
Subject: [PATCH] 修改重置密码的接口

---
 kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java |  132 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 113 insertions(+), 19 deletions(-)

diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java
index 6ee3454..d006946 100644
--- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java
+++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java
@@ -1,39 +1,33 @@
 package com.kidgrow.usercenter.service.impl;
 
-import com.alibaba.fastjson.JSON;
-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.SysDoctorMapper;
 import com.kidgrow.usercenter.mapper.SysRoleMapper;
-import com.kidgrow.usercenter.mapper.SysRoleOrganizationMapper;
 import com.kidgrow.usercenter.mapper.SysUserRoleMapper;
-import com.kidgrow.usercenter.model.SysRoleOrganization;
+import com.kidgrow.usercenter.model.SysDoctor;
 import com.kidgrow.usercenter.model.SysRoleUser;
-import com.kidgrow.usercenter.service.ISysRoleOrganizationService;
+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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.kidgrow.common.service.impl.SuperServiceImpl;
-
-import java.util.*;
-
-import org.apache.commons.collections4.MapUtils;
-import lombok.extern.slf4j.Slf4j;
-
-import com.kidgrow.usercenter.model.SysDoctor;
-import com.kidgrow.usercenter.mapper.SysDoctorMapper;
-import com.kidgrow.usercenter.service.ISysDoctorService;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.*;
 
 /**
  * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
@@ -116,6 +110,17 @@
         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);
+    }
     @Override
     public ResultBody enable(Map<String, Object> params) {
         Long aLong = MapUtils.getLong(params,"id");
@@ -139,7 +144,7 @@
     }
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public boolean saveOrUpdateSer(SysDoctorDto sysDoctor, HttpServletRequest request,SysUser user) {
         String id = request.getHeader(SecurityConstants.USER_ID_HEADER);
         if(null==sysDoctor){
@@ -153,8 +158,8 @@
                 sysUser.setNickname(sysDoctor.getHospitalName());
                 sysUser.setHeadImgUrl(sysDoctor.getDoctorLogo());
                 sysUser.setMobile(sysDoctor.getDoctorTel());
-                sysUser.setType("doctor");
-                sysUser.setTenantId("hospital");
+                sysUser.setType(CommonConstant.H_DOCTOR);
+                sysUser.setTenantId(CommonConstant.H_TENANT);
                 sysUser.setCreateTime(new Date());
                 SysUser byId = iSysUserService.getById(id);
                 if(byId!=null){
@@ -232,4 +237,93 @@
         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);
+            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()) {
+                    //现将操作人员设为非管理
+//                    sysDoctor=new SysDoctor();
+                    sysDoctor.setIsAdminUser(false);
+                    if(baseMapper.updateById(sysDoctor)>0)
+                    {
+                        //再将新用户设为管理
+                        sysDoctor=baseMapper.selectById(id);
+                        if (sysDoctor != null) {
+                            if (!sysDoctor.getIsAdminUser()) {
+//                                sysDoctor=new SysDoctor();
+                                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);
+        }
+    }
 }

--
Gitblit v1.8.0