From def38240262b4403377d4c16beac3ea048f1e658 Mon Sep 17 00:00:00 2001 From: huanghongfa <18228131219@163.com> Date: 星期日, 20 十二月 2020 13:25:39 +0800 Subject: [PATCH] 修改目录结构 --- springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java | 567 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 567 insertions(+), 0 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..5349eef --- /dev/null +++ b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java @@ -0,0 +1,567 @@ +package com.panzhihua.service_user.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.panzhihua.common.constants.UserConstants; +import com.panzhihua.common.model.vos.LoginUserInfoVO; +import com.panzhihua.common.model.vos.R; +import com.panzhihua.common.model.vos.partybuilding.ActivityManagerVO; +import com.panzhihua.common.model.vos.user.ChangePasswordVO; +import com.panzhihua.common.model.vos.user.ComMngFamilyInfoVO; +import com.panzhihua.common.model.vos.user.UserPhoneVO; +import com.panzhihua.service_user.dao.ComMngFamilyInfoDAO; +import com.panzhihua.service_user.dao.ComMngUserTagDAO; +import com.panzhihua.service_user.dao.RoleDAO; +import com.panzhihua.service_user.dao.UserDao; +import com.panzhihua.service_user.model.dos.ComMngFamilyInfoDO; +import com.panzhihua.service_user.model.dos.ComMngUserTagDO; +import com.panzhihua.service_user.model.dos.SysRoleDO; +import com.panzhihua.service_user.model.dos.SysUserDO; +import com.panzhihua.service_user.service.UserService; +import org.springframework.beans.BeanUtils; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @program: springcloud_k8s_panzhihuazhihuishequ + * @description: 用户 + * @author: huang.hongfa weixin hhf9596 qq 959656820 + * @create: 2020-11-24 09:13 + **/ +@Service +public class UserServiceImpl implements UserService { + @Resource + private UserDao userDao; + @Resource + private RoleDAO roleDAO; + @Resource + private ComMngUserTagDAO comMngUserTagDAO; + @Resource + private ComMngFamilyInfoDAO comMngFamilyInfoDAO; + @Resource + private StringRedisTemplate stringRedisTemplate; + + + /** + * 小程序微信用户信息更新 + * + * @param openid 小程序唯一ID + * @param sessionKey 会话密钥 + * @param unionid 用户在开放平台的唯一标识符 + * @return token + */ + @Override + public R updateInsertUser(String openid, String sessionKey, String unionid) { + SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getOpenid, openid)); + boolean empty = ObjectUtils.isEmpty(sysUserDO); + int num = 0; + if (empty) { + SysUserDO sysUserDO1 = new SysUserDO(); + Date date = new Date(); + String encode = new BCryptPasswordEncoder().encode(UserConstants.PASSWORD); + sysUserDO1.setOpenid(openid); + sysUserDO1.setUnionid(unionid); + sysUserDO1.setSessionKey(sessionKey); + sysUserDO1.setCreateAt(date); + sysUserDO1.setLastLoginTime(date); + sysUserDO1.setPassword(encode); + sysUserDO1.setType(1); + num = userDao.insert(sysUserDO1); + } else { + String encode = new BCryptPasswordEncoder().encode(UserConstants.PASSWORD); + sysUserDO.setUnionid(unionid); + sysUserDO.setSessionKey(sessionKey); + sysUserDO.setPassword(encode); + sysUserDO.setType(1); + num = userDao.updateById(sysUserDO); + } + if (num > 0) { + return R.ok(); + } else { + return R.fail("登录失败"); + } + } + + /** + * 维护小程序用户基本信息 头像 昵称 性别 + * + * @param userId 数据库用户ID + * @param nickName 昵称 + * @param gender 性别 + * @param avatarUrl 头像 + * @return 维护结果 + */ + @Override + public R updateUserWeiXinInfo(Long userId, String nickName, int gender, String avatarUrl) { + SysUserDO sysUserDO = new SysUserDO(); + sysUserDO.setSex(gender); + sysUserDO.setNickName(nickName); + sysUserDO.setImageUrl(avatarUrl); + sysUserDO.setUserId(userId); + int i = userDao.updateById(sysUserDO); + if (i > 0) { + return R.ok(); + } else { + return R.fail("维护微信基本信息失败"); + } + } + + /** + * 维护微信用户手机号 + * + * @param userId 数据库ID + * @param purePhoneNumber 没有区号的手机号 + * @return 维护结果 + */ + @Override + public R updateUserWeiXinPhone(Long userId, String purePhoneNumber) { + SysUserDO sysUserDO = new SysUserDO(); + sysUserDO.setPhone(purePhoneNumber); + sysUserDO.setUserId(userId); + int i = userDao.updateById(sysUserDO); + if (i > 0) { + return R.ok(); + } else { + return R.fail("维护微信手机号失败"); + } + } + + /** + * 认证中心获取平台用户信息 + * + * @param name 登录账户 + * @param type 用户类型 用户类型 1 小程序 2 运营平台 3 社区平台 + * @return 用户基本信息、角色 + */ + @Override + public R<LoginUserInfoVO> getUserInfo(String name, int type) { + SysUserDO sysUserDO = null; + if (1 == type) { + sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getType, type).eq(SysUserDO::getOpenid, name)); + } else { + LambdaQueryWrapper<SysUserDO> wrapper = new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getType, type); + wrapper.and(sysUserDOLambdaQueryWrapper ->sysUserDOLambdaQueryWrapper .eq(SysUserDO::getAccount, name).or().eq(SysUserDO::getPhone, name)); + sysUserDO = userDao.selectOne(wrapper); + } + boolean empty = ObjectUtils.isEmpty(sysUserDO); + if (empty) { + return R.fail(); + } + LoginUserInfoVO loginUserInfoVO=new LoginUserInfoVO(); + loginUserInfoVO.setUserId(sysUserDO.getUserId()); + loginUserInfoVO.setName(sysUserDO.getName()); + loginUserInfoVO.setPassword(sysUserDO.getPassword()); + loginUserInfoVO.setStatus(sysUserDO.getStatus()); + loginUserInfoVO.setAccount(name); + loginUserInfoVO.setType(sysUserDO.getType()); + List<SysRoleDO> roleDOList=roleDAO.selectByUserId(sysUserDO.getUserId()); + Set<String> set=new HashSet<>(); + if (!ObjectUtils.isEmpty(roleDOList)) { + roleDOList.forEach(sysRoleDO -> { + set.add(sysRoleDO.getRoleKey()); + }); + } + return R.ok(loginUserInfoVO); + } + + /** + * 三端获取用户信息 + * + * @param userId 用户ID + * @return 用户基本信息、角色 + */ + @Override + public R<LoginUserInfoVO> getUserInfo(String userId) { + SysUserDO sysUserDO = userDao.selectById(userId); + boolean empty = ObjectUtils.isEmpty(sysUserDO); + if (empty) { + return R.fail(); + } + LoginUserInfoVO loginUserInfoVO=new LoginUserInfoVO(); + BeanUtils.copyProperties(sysUserDO,loginUserInfoVO); + List<SysRoleDO> roleDOList=roleDAO.selectByUserId(sysUserDO.getUserId()); + Set<String> set=new HashSet<>(); + if (!ObjectUtils.isEmpty(roleDOList)) { + roleDOList.forEach(sysRoleDO -> { + set.add(sysRoleDO.getRoleKey()); + }); + loginUserInfoVO.setRoles(set); + } + return R.ok(loginUserInfoVO); + } + + /** + * 修改用户登录密码 + * + * @param changePasswordVO 新密码 + * @return 修改结果 + */ + @Override + public R changePassword(ChangePasswordVO changePasswordVO) { + Long userId = changePasswordVO.getUserId(); + String newPassword = changePasswordVO.getNewPassword(); + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setUserId(userId); + String encode = new BCryptPasswordEncoder().encode(newPassword); + sysUserDO.setPassword(encode); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 某社区后台人员查询 + * + * @param param 名字 + * @param communityId 社区id + * @return 人员集合 + */ + @Override + public R listActivityManager(String param, Long communityId) { + LambdaQueryWrapper<SysUserDO> queryWrapper=new LambdaQueryWrapper<>(); + List<ActivityManagerVO> activityManagerVOS=new ArrayList<>(); + queryWrapper = new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getCommunityId, communityId).eq(SysUserDO::getStatus, 1).eq(SysUserDO::getType,3); + if (!ObjectUtils.isEmpty(param)) { + queryWrapper = queryWrapper.eq(SysUserDO::getName, param); + } + List<SysUserDO> sysUserDOS = userDao.selectList(queryWrapper); + if (!ObjectUtils.isEmpty(sysUserDOS)) { + sysUserDOS.forEach(sysUserDO -> { + ActivityManagerVO activityManagerVO=new ActivityManagerVO(); + activityManagerVO.setManagerId(sysUserDO.getUserId()); + activityManagerVO.setName(sysUserDO.getName()); + activityManagerVOS.add(activityManagerVO); + }); + } + return R.ok(activityManagerVOS); + } + + /** + * 分页查询人脸识别 + * + * @param loginUserInfoVO 查询参数 + * @return 分页集合 + */ + @Override + public R pageUserFace(LoginUserInfoVO loginUserInfoVO) { + Page page = new Page<>(); + Long pageNum = loginUserInfoVO.getPageNum(); + Long pageSize = loginUserInfoVO.getPageSize(); + if (ObjectUtils.isEmpty(pageNum)||0==pageNum) { + pageNum = 1l; + } + if (ObjectUtils.isEmpty(pageSize)||0==pageSize) { + pageSize = 10l; + } + page.setSize(pageSize); + page.setCurrent(pageNum); + IPage<LoginUserInfoVO> iPage = userDao.pageUserFace(page, loginUserInfoVO); + return R.ok(iPage); + } + + /** + * 编辑人脸采集数据通过、驳回、删除 + * + * @param loginUserInfoVO 操作信息 + * @return 操作结果 + */ + @Override + public R putUserFace(LoginUserInfoVO loginUserInfoVO) { + int operationType = loginUserInfoVO.getOperationType().intValue(); + Long userId = loginUserInfoVO.getUserId(); + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setUserId(userId); + switch (operationType){ + case 1: + sysUserDO.setFaceState(1); + break; + case 2: + sysUserDO.setFaceState(3); + break; + case 3: + break; + default: + break; + } + int num=0; + if (operationType==3) { + num=userDao.deleteById(userId); + } else { + num=userDao.updateById(sysUserDO); + } + if (num>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 分页查询人口管理 + * + * @param loginUserInfoVO 查询参数 + * @return 分页数据 + */ + @Override + public R pageUser(LoginUserInfoVO loginUserInfoVO) { + Page page = new Page<>(); + Long pageNum = loginUserInfoVO.getPageNum(); + Long pageSize = loginUserInfoVO.getPageSize(); + if (ObjectUtils.isEmpty(pageNum)||0==pageNum) { + pageNum = 1l; + } + if (ObjectUtils.isEmpty(pageSize)||0==pageSize) { + pageSize = 10l; + } + page.setSize(pageSize); + page.setCurrent(pageNum); + IPage<LoginUserInfoVO> iPage = userDao.pageUser(page, loginUserInfoVO); + return R.ok(iPage); + } + + /** + * 查询所有人员标签 + * + * @return 标签集合 + */ + @Override + public R listTag() { + List<String> list=new ArrayList<>(); + List<ComMngUserTagDO> comMngUserTagDOS = comMngUserTagDAO.selectList(null); + if (!ObjectUtils.isEmpty(comMngUserTagDOS)) { + list=comMngUserTagDOS.stream().map(comMngUserTagDO -> comMngUserTagDO.getTagName()).collect(Collectors.toList()); + } + return R.ok(list); + } + + /** + * 人员详情 + * + * @param userId 用户id + * @return 人员详情 + */ + @Override + public R detailUser(Long userId) { + SysUserDO sysUserDO = userDao.selectById(userId); + if (ObjectUtils.isEmpty(sysUserDO)) { + return R.fail("人员不存在"); + } + LoginUserInfoVO loginUserInfoVO=new LoginUserInfoVO(); + BeanUtils.copyProperties(sysUserDO,loginUserInfoVO); + List<ComMngFamilyInfoDO> comMngFamilyInfoDOS = comMngFamilyInfoDAO.selectList(new QueryWrapper<ComMngFamilyInfoDO>().lambda().eq(ComMngFamilyInfoDO::getUserId, userId)); + if (!ObjectUtils.isEmpty(comMngFamilyInfoDOS)) { + List<ComMngFamilyInfoVO>comMngFamilyInfoVOS=new ArrayList<>(); + comMngFamilyInfoDOS.forEach(comMngFamilyInfoDO -> { + ComMngFamilyInfoVO comMngFamilyInfoVO=new ComMngFamilyInfoVO(); + BeanUtils.copyProperties(comMngFamilyInfoDO,comMngFamilyInfoVO); + comMngFamilyInfoVOS.add(comMngFamilyInfoVO); + }); + loginUserInfoVO.setComMngFamilyInfoVOS(comMngFamilyInfoVOS); + } + return R.ok(loginUserInfoVO); + } + + /** + * 设置用户标签 + * + * @param loginUserInfoVO 标签信息 + * @return 设置结果 + */ + @Override + public R putUserTag(LoginUserInfoVO loginUserInfoVO) { + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setUserId(loginUserInfoVO.getUserId()); + sysUserDO.setTags(loginUserInfoVO.getTags()); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 修改用户志愿者状态 + * + * @param phone 志愿者手机号 + * @param type + */ + @Override + public R putUserIsVolunteer(String phone, int type) { + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setIsVolunteer(type); + int update = userDao.update(sysUserDO, new UpdateWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone)); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 用户绑定社区、小区 + * + * @param loginUserInfoVO 社区小区数据 + * @return 绑定结果 + */ + @Override + public R putUserCommunityArea(LoginUserInfoVO loginUserInfoVO) { + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setCommunityId(loginUserInfoVO.getCommunityId()); + sysUserDO.setAreaId(loginUserInfoVO.getAreaId()); + sysUserDO.setUserId(loginUserInfoVO.getUserId()); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 用户实名认证 + * + * @param loginUserInfoVO 认证数据 + * @return 认证结果 + */ + @Override + public R putUserAuthentication(LoginUserInfoVO loginUserInfoVO) { + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setName(loginUserInfoVO.getName()); + sysUserDO.setIdCard(loginUserInfoVO.getIdCard()); + sysUserDO.setSex(loginUserInfoVO.getSex()); + sysUserDO.setBirthday(loginUserInfoVO.getBirthday()); + sysUserDO.setJob(loginUserInfoVO.getJob()); + sysUserDO.setUserId(loginUserInfoVO.getUserId()); + sysUserDO.setFaceUrl(loginUserInfoVO.getFaceUrl()); + sysUserDO.setFaceState(0); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 修改用户手机号 + * + * @param userPhoneVO 手机号信息 + * @return 修改结果 + */ + @Override + public R putUserphone(UserPhoneVO userPhoneVO) { + String oldPhone = userPhoneVO.getOldPhone(); + String newPhone = userPhoneVO.getNewPhone(); + String smsCode = userPhoneVO.getSmsCode(); + if (oldPhone.equals(newPhone)) { + return R.fail("新旧手机号不能重复"); + } + String key = UserConstants.PHONE_PUT + newPhone; + Boolean hasKey = stringRedisTemplate.hasKey(key); + if (!hasKey) { + return R.fail("重新发送验证码"); + } + SysUserDO sysUserDO1 = userDao.selectById(userPhoneVO.getUserId()); + String phone = sysUserDO1.getPhone(); + if (!phone.equals(oldPhone)) { + return R.fail("旧手机号错误"); + } + ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue(); + String code = valueOperations.get(key); + if (!code.equals(smsCode)) { + return R.fail("验证码错误"); + } + SysUserDO sysUserDO=new SysUserDO(); + sysUserDO.setUserId(userPhoneVO.getUserId()); + sysUserDO.setPhone(newPhone); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 修改用户信息 + * + * @param loginUserInfoVO 修改内容 + * @return 修改结果 + */ + @Override + public R putUser(LoginUserInfoVO loginUserInfoVO) { + SysUserDO sysUserDO=new SysUserDO(); + BeanUtils.copyProperties(loginUserInfoVO,sysUserDO); + int update = userDao.updateById(sysUserDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 家庭成员列表 + * + * @param userId 登录用户 + * @return 成员集合 + */ + @Override + public R listFamily(Long userId) { + List<ComMngFamilyInfoVO>comMngFamilyInfoVOS=new ArrayList<>(); + List<ComMngFamilyInfoDO> comMngFamilyInfoDOS = comMngFamilyInfoDAO.selectList(new QueryWrapper<ComMngFamilyInfoDO>().lambda().eq(ComMngFamilyInfoDO::getUserId, userId)); + if (!ObjectUtils.isEmpty(comMngFamilyInfoDOS)) { + comMngFamilyInfoDOS.forEach(comMngFamilyInfoDO -> { + ComMngFamilyInfoVO comMngFamilyInfoVO=new ComMngFamilyInfoVO(); + BeanUtils.copyProperties(comMngFamilyInfoDO,comMngFamilyInfoVO); + comMngFamilyInfoVOS.add(comMngFamilyInfoVO); + }); + } + return R.ok(comMngFamilyInfoVOS); + } + + /** + * 新增家庭成员 + * + * @param comMngFamilyInfoVO 家庭成员基本信息 + * @return 增加结果 + */ + @Override + public R addFamily(ComMngFamilyInfoVO comMngFamilyInfoVO) { + ComMngFamilyInfoDO comMngFamilyInfoDO=new ComMngFamilyInfoDO(); + BeanUtils.copyProperties(comMngFamilyInfoVO,comMngFamilyInfoDO); + int insert = comMngFamilyInfoDAO.insert(comMngFamilyInfoDO); + if (insert>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 编辑家庭成员 + * + * @param comMngFamilyInfoVO 家庭成员信息 + * @return 编辑结果 + */ + @Override + public R putFamily(ComMngFamilyInfoVO comMngFamilyInfoVO) { + ComMngFamilyInfoDO comMngFamilyInfoDO=new ComMngFamilyInfoDO(); + BeanUtils.copyProperties(comMngFamilyInfoDO,comMngFamilyInfoVO); + int update = comMngFamilyInfoDAO.updateById(comMngFamilyInfoDO); + if (update>0) { + return R.ok(); + } + return R.fail(); + } + + public static void main(String[] args) { + String encode = new BCryptPasswordEncoder().encode("123456"); + System.out.println(encode); + } +} -- Gitblit v1.7.1