| | |
| | | package com.kidgrow.usercenter.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | | import com.kidgrow.common.context.ClientContextHolder; |
| | | import com.kidgrow.common.lock.DistributedLock; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.redis.util.RedisUtils; |
| | | import com.kidgrow.sms.feign.SmsChuangLanService; |
| | | import com.kidgrow.sms.model.ConstantSMS; |
| | | import com.kidgrow.usercenter.mapper.SysRoleMenuMapper; |
| | | import com.kidgrow.usercenter.mapper.SysUserMapper; |
| | | import com.kidgrow.usercenter.model.SysRoleUser; |
| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | |
| | | @Service |
| | | public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | private final static String LOCK_KEY_USERNAME = CommonConstant.LOCK_KEY_PREFIX+"username:"; |
| | | |
| | | @Autowired |
| | | private PasswordEncoder passwordEncoder; |
| | | |
| | |
| | | private ISysOrganizationService organizationService; |
| | | @Autowired |
| | | private ISysUserOrgService iSysUserOrgService; |
| | | |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | @Autowired |
| | | private SmsChuangLanService smsChuangLanService; |
| | | |
| | | @Autowired |
| | | private DistributedLock lock; |
| | | |
| | | |
| | | @Override |
| | | public LoginAppUser findByUsername(String username) { |
| | |
| | | |
| | | /** |
| | | * 根据用户名查询用户 |
| | | * |
| | | * @param username |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据手机号查询用户 |
| | | * |
| | | * @param mobile |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据openId查询用户 |
| | | * |
| | | * @param openId |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取当前用的 组织下的所有人员 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | |
| | | Integer integer = baseMapper.selectCountByMap(map); |
| | | return ResultBody.ok().data(integer); |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号 修改密码 |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody passwordByPhone(Map<String, Object> map) { |
| | | //手机号,type,验证码,新密码 |
| | | String phone = MapUtils.getString(map, "phone"); |
| | | if (phone == null || "".equals(phone.trim())) { |
| | | return ResultBody.failed("请输入手机号"); |
| | | } |
| | | String verificationCode = MapUtils.getString(map, "verificationCode"); |
| | | if (verificationCode == null || "".equals(verificationCode.trim())) { |
| | | return ResultBody.failed("请输入验证码"); |
| | | } |
| | | String newPass = MapUtils.getString(map, "newPass"); |
| | | if (newPass == null || "".equals(newPass.trim())) { |
| | | return ResultBody.failed("请输入正确的密码"); |
| | | } |
| | | Object hget = redisUtils.hget(ConstantSMS.PASSWORD_SMS, map.get("phone").toString()); |
| | | if (hget != null) { |
| | | JSONObject redisJson = JSON.parseObject(JSON.toJSONString(hget)); |
| | | Object verificationCodeObject = redisJson.get("verificationCode"); |
| | | if (verificationCode.equals(verificationCodeObject)) { |
| | | Object date = redisJson.get("endTime"); |
| | | long time = DateUtils.parseDate(date.toString()).getTime(); |
| | | Date dateNow = new Date(); |
| | | long timeNow = dateNow.getTime(); |
| | | if (timeNow <= time) { |
| | | //查询表 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | if (sysUsers.size() > 0) { |
| | | SysUser user = new SysUser(); |
| | | user.setId(sysUsers.get(0).getId()); |
| | | user.setPassword(passwordEncoder.encode(newPass)); |
| | | baseMapper.updateById(user); |
| | | //将Redis 清除 |
| | | redisUtils.hdel(ConstantSMS.PASSWORD_SMS, phone); |
| | | return ResultBody.ok(); |
| | | } else { |
| | | return ResultBody.failed("暂无该手机号信息"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("验证码超时"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("验证码错误"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("该手机号没有验证码"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号 注册验证 |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody registerByPhone(Map<String, Object> map) { |
| | | //手机号,type,验证码,新密码 |
| | | String phone = MapUtils.getString(map, "phone"); |
| | | if (phone == null || "".equals(phone.trim())) { |
| | | return ResultBody.failed("请输入手机号"); |
| | | } |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | if(sysUsers.size()>0){ |
| | | return ResultBody.failed("该手机号已经注册"); |
| | | } |
| | | Map<String, Object> mapDto=new HashMap(); |
| | | mapDto.put("phone",phone); |
| | | mapDto.put("type",ConstantSMS.REGISTER_SMS); |
| | | return smsChuangLanService.sendVerificationCode(mapDto); |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号修改 手机号 |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody updatePhone(Map<String, Object> map,SysUser sysUser) { |
| | | String password = MapUtils.getString(map, "password"); |
| | | if (StringUtils.isBlank(password)) { |
| | | return ResultBody.failed("请输入密码"); |
| | | } |
| | | String phone = MapUtils.getString(map, "phone"); |
| | | if (StringUtils.isBlank(phone)) { |
| | | return ResultBody.failed("请输入新手机号"); |
| | | } |
| | | String verificationCode = MapUtils.getString(map, "verificationCode"); |
| | | if (StringUtils.isBlank(verificationCode)) { |
| | | return ResultBody.failed("请输入验证码"); |
| | | } |
| | | if (!passwordEncoder.matches(sysUser.getPassword(),password)) { |
| | | return ResultBody.failed("密码错误"); |
| | | } |
| | | Object hget = redisUtils.hget(ConstantSMS.PHONE_SMS, map.get("phone").toString()); |
| | | if (hget != null) { |
| | | JSONObject redisJson = JSON.parseObject(JSON.toJSONString(hget)); |
| | | Object verificationCodeObject = redisJson.get("verificationCode"); |
| | | if (verificationCode.equals(verificationCodeObject)) { |
| | | Object date = redisJson.get("endTime"); |
| | | long time = DateUtils.parseDate(date.toString()).getTime(); |
| | | Date dateNow = new Date(); |
| | | long timeNow = dateNow.getTime(); |
| | | if (timeNow <= time) { |
| | | //查询表 |
| | | Map<String, Object> selectMap = new HashMap<>(); |
| | | selectMap.put("mobile", phone); |
| | | List<SysUser> sysUsers = baseMapper.selectByMap(selectMap); |
| | | if (sysUsers.size() > 0) { |
| | | return ResultBody.failed("该手机号已经注册"); |
| | | } else { |
| | | SysUser user = new SysUser(); |
| | | user.setId(sysUser.getId()); |
| | | user.setMobile(phone); |
| | | baseMapper.updateById(user); |
| | | //将Redis 清除 |
| | | redisUtils.hdel(ConstantSMS.PHONE_SMS, phone); |
| | | return ResultBody.ok(); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("验证码超时"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("验证码错误"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed("该手机号没有验证码"); |
| | | } |
| | | } |
| | | } |