From faae303cd25f90b1c732b6bc737ede8b8ab714a0 Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期一, 27 九月 2021 16:56:28 +0800
Subject: [PATCH] Merge branch 'test' into 'test_bak'

---
 springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 101 insertions(+), 5 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
index 268d340..cedecbf 100644
--- 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
@@ -3,6 +3,7 @@
 import static java.util.Objects.isNull;
 import static java.util.Objects.nonNull;
 
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -308,6 +309,9 @@
         loginUserInfoVO.setAccount(name);
         loginUserInfoVO.setType(sysUserDO.getType());
         loginUserInfoVO.setIsRealNamed(sysUserDO.getIdCard() != null);// 暂时 身份证判断实名制
+        if(sysUserDO.getCommunityId()!=null){
+            loginUserInfoVO.setCommunityId(sysUserDO.getCommunityId());
+        }
         List<SysRoleDO> roleDOList = roleDAO.selectByUserId(sysUserDO.getUserId());
         Set<String> set = new HashSet<>();
         if (!ObjectUtils.isEmpty(roleDOList)) {
@@ -1065,6 +1069,8 @@
                 throw new ServiceException("手机号已经存在");
             } else if (e.getMessage().contains("union_account_type")) {
                 throw new ServiceException("账户已经存在");
+            }else if(e.getMessage().contains("23000")){
+                throw new ServiceException("手机号已存在");
             }
 
         }
@@ -1087,6 +1093,8 @@
                     throw new ServiceException("手机号已经存在");
                 } else if (e.getMessage().contains("union_account_type")) {
                     throw new ServiceException("账户已经存在");
+                }else if(e.getMessage().contains("23000")){
+                    throw new ServiceException("手机号已存在");
                 }
 
             }
@@ -1101,7 +1109,47 @@
             sysUserRoleDO.setRoleId(roleDO.getRoleId());
             int insert1 = sysUserRoleDAO.insert(sysUserRoleDO);
             if (insert1 > 0) {
-                return R.ok();
+                return R.ok(userId);
+            }
+        }
+        return R.fail();
+    }
+
+    @Override
+    public R addUserBackstageProperty(AdministratorsUserVO administratorsUserVO) {
+        SysUserDO sysUserDO = new SysUserDO();
+        Long roleId = administratorsUserVO.getRoleId();
+        SysRoleDO roleDO = roleDAO.selectById(roleId);
+        if (ObjectUtils.isEmpty(roleDO)) {
+            return R.fail("角色不存在");
+        }
+        String encode = new BCryptPasswordEncoder().encode(administratorsUserVO.getPassword());
+        administratorsUserVO.setPassword(encode);
+        BeanUtils.copyProperties(administratorsUserVO, sysUserDO);
+        int insert = 0;
+        try {
+            insert = userDao.insert(sysUserDO);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("新增后台用户报错【{}】", e.getMessage());
+            if (e.getMessage().contains("union_phone_type")) {
+                throw new ServiceException("手机号已经存在");
+            } else if (e.getMessage().contains("union_account_type")) {
+                throw new ServiceException("账户已经存在");
+            }
+
+        }
+        if (insert > 0) {
+            SysUserDO sysUserDO1 = userDao
+                    .selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getType, administratorsUserVO.getType())
+                            .eq(SysUserDO::getAccount, administratorsUserVO.getAccount()));
+            Long userId = sysUserDO1.getUserId();
+            SysUserRoleDO sysUserRoleDO = new SysUserRoleDO();
+            sysUserRoleDO.setUserId(userId);
+            sysUserRoleDO.setRoleId(roleDO.getRoleId());
+            int insert1 = sysUserRoleDAO.insert(sysUserRoleDO);
+            if (insert1 > 0) {
+                return R.ok(userId);
             }
         }
         return R.fail();
@@ -2120,7 +2168,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R addGridUser(EventGridMemberAddDTO eventGridMemberAddDTO) {
-
+        //todo 网格
         SysRoleDO gridMemberDefaultRole = roleDAO.selectOne(
             new QueryWrapper<SysRoleDO>().lambda().eq(SysRoleDO::getRoleKey, Constants.GRID_DEFAULT_ROLE_KEY));
         if (gridMemberDefaultRole == null) {
@@ -2508,6 +2556,33 @@
         return R.ok(false);
     }
 
+    @Override
+    public R resetPassword(Long userId) {
+        SysUserDO sysUserDO = new SysUserDO();
+        sysUserDO.setUserId(userId);
+        String encode = new BCryptPasswordEncoder().encode("admin123456");
+        sysUserDO.setPassword(encode);
+        int update = userDao.updateById(sysUserDO);
+        if (update > 0) {
+            return R.ok();
+        }
+        return R.fail();
+    }
+
+    @Override
+    public R resetPasswordPatch(Long[] userId,String password) {
+        if(userId!=null){
+            for(Long user:userId){
+                SysUserDO sysUserDO = new SysUserDO();
+                sysUserDO.setUserId(user);
+                String encode = new BCryptPasswordEncoder().encode(password);
+                sysUserDO.setPassword(encode);
+                userDao.updateById(sysUserDO);
+            }
+        }
+        return R.ok();
+    }
+
     /**
      * 便民服务新增商家账号
      * @param convenientMerchantDTO
@@ -2516,11 +2591,13 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R addConvenientMerchantUser(ConvenientMerchantDTO convenientMerchantDTO) {
+        // todo 便民
+        log.error("catTimeStamp进入addConvenientMerchantUser", Instant.now().toEpochMilli());
         SysUserDO sysUserDO = new SysUserDO();
         Long communityId = 0L;
         // 新增社区高级管理员角色
         SysRoleDO sysRoleDO = new SysRoleDO();
-        sysRoleDO.setCommunityId(0L);
+        sysRoleDO.setCommunityId(communityId);
         sysRoleDO.setRoleName(convenientMerchantDTO.getName());
         sysRoleDO.setRoleKey(Constants.CONVENIENT_MERCHANT_ROLE_KEY + convenientMerchantDTO.getAccount());
         sysRoleDO.setRoleSort(0);
@@ -2535,15 +2612,18 @@
             if (e.getMessage().contains("unique_role_name_community_id")) {
                 return R.fail("商家名称已被占用");
             } else {
-                return R.fail("建立商家角色失败");
+                return R.fail("建立商家角色失败,商家名称可能已被占用!");
             }
         }
+        log.error("catTimeStamp-SysRoleDO创建完成", Instant.now().toEpochMilli());
         // 新角色设置所有权限
         MenuRoleVO menuRoleVO = new MenuRoleVO();
         menuRoleVO.setIsAll(1);
         menuRoleVO.setCommunityId(communityId);
         menuRoleVO.setRoleId(sysRoleDO.getRoleId());
         this.putMenuRole(menuRoleVO);
+
+        log.error("catTimeStamp-MenuRoleVO创建完成", Instant.now().toEpochMilli());
 
         // sys_user 表
         String encode = new BCryptPasswordEncoder().encode(convenientMerchantDTO.getPassword());
@@ -2557,6 +2637,7 @@
         sysUserDO.setPassword(encode);
         try {
             userDao.insert(sysUserDO);
+            log.error("catTimeStamp-sysUserDO创建完成", Instant.now().toEpochMilli());
             return R.ok(sysUserDO.getUserId());
         } catch (Exception e) {
             e.printStackTrace();
@@ -2599,7 +2680,22 @@
 
     @Override
     public R disableOrEnableMerchantUsers(DisableOrEnableConvenientMerchantDTO disableOrEnableConvenientMerchantDTO) {
-        userDao.disableOrEnableMerchantUsers(disableOrEnableConvenientMerchantDTO.getType(), disableOrEnableConvenientMerchantDTO.getIds());
+        userDao.disableOrEnableMerchantUsers(disableOrEnableConvenientMerchantDTO.getType(), disableOrEnableConvenientMerchantDTO.getUserIds());
         return R.ok();
     }
+    
+    /**
+     * 根据openid维护社区团队里是否注册
+     * @param openid    用户微信唯一标识
+     */
+    @Override
+    public void judgeCommunityTeam(String openid){
+        //查询用户信息
+        SysUserDO userDO = this.userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getOpenid,openid));
+        if(userDO != null && StringUtils.isNotEmpty(userDO.getPhone())){
+            if(this.userDao.getCommunityTeamCount(userDO.getPhone()) > 0){
+                this.userDao.judgeCommunityTeam(userDO.getPhone());
+            }
+        }
+    }
 }

--
Gitblit v1.7.1