ソースを参照

feature 代码初始化

xiahan 5 ヶ月 前
コミット
dc1f192225
21 ファイル変更508 行追加340 行削除
  1. 6 0
      zhsw-common/pom.xml
  2. 0 58
      zhsw-common/src/main/java/com/rongwei/sfcommon/sys/dao/TenantDao.java
  3. 0 269
      zhsw-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/LoginLogicServiceImpl.java
  4. 1 1
      zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/LoginAuth.java
  5. 1 1
      zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/LoginAuthImpl.java
  6. 1 1
      zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/TenantFeginService.java
  7. 1 1
      zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/TenantFeginServiceImpl.java
  8. 16 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/dao/CommonBusinessDao.java
  9. 19 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/dao/SwUserManagementMapper.java
  10. 3 8
      zhsw-common/src/main/java/com/rongwei/sfcommon/sys/service/LoginLogicService.java
  11. 16 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/OwnerService.java
  12. 14 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/SwUserManagementService.java
  13. 148 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/LoginLogicServiceImpl.java
  14. 53 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/OwnerServiceImpl.java
  15. 23 0
      zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/SwUserManagementServiceImpl.java
  16. 15 0
      zhsw-common/src/main/resources/mybatis/CommonBusinessDao.xml
  17. 7 0
      zhsw-common/src/main/resources/mybatis/SwUserManagementMapper.xml
  18. 113 0
      zhsw-entity/src/main/java/com/rongwe/zhsw/domian/SwUserManagement.java
  19. 18 0
      zhsw-entity/src/main/java/com/rongwe/zhsw/vo/OwnerVo.java
  20. 11 1
      zhsw-server/src/main/java/com/rongwei/zhsw/controller/LoginLogicController.java
  21. 42 0
      zhsw-server/src/main/java/com/rongwei/zhsw/controller/OwnerController.java

+ 6 - 0
zhsw-common/pom.xml

@@ -23,6 +23,12 @@
             <artifactId>rw-admin-common</artifactId>
             <version>1.1-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>com.rongwei</groupId>
+            <artifactId>zhsw-entity</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 0 - 58
zhsw-common/src/main/java/com/rongwei/sfcommon/sys/dao/TenantDao.java

@@ -1,58 +0,0 @@
-package com.rongwei.sfcommon.sys.dao;
-
-import com.rongwei.rwadmincommon.system.domain.SysUserDo;
-import com.rongwei.rwcommon.base.BaseDao;
-import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
-import org.springframework.stereotype.Repository;
-
-import java.util.List;
-
-@Repository
-public interface TenantDao extends BaseDao<TenantDo> {
-
-    @Select("select * from zhsw_dev.sys_tenant where DELETED='0' and id = #{id} ")
-    TenantDo getById(@Param("id") String id);
-
-    @Select("select * from ${schema}.sys_user where DELETED='0'")
-    List<SysUserDo> userListBySchema(@Param("schema") String schema);
-
-    @Select("CREATE DATABASE IF NOT EXISTS ${dataBaseName} \n" +
-            "DEFAULT CHARACTER SET utf8mb4 \n" +
-            "DEFAULT COLLATE utf8mb4_general_ci")
-    void createTenantDataBase(@Param("dataBaseName") String dataBaseName);
-
-
-    /**
-     * 更新超级管理员的账号信息
-     * @param schema
-     * @param tenantid
-     */
-    @Update("update ${schema}.sys_user set TENANTID = #{tenantid},ACCOUNT = CONCAT('${schema}','admin') where ID ='8672bf72ab274bec83052868ae336b38' ")
-    void updateUserTenant(@Param("schema") String schema,@Param("tenantid") String tenantid);
-
-    /**
-     * 更新管理员的账号信息
-     * @param schema
-     * @param tenantid
-     * @param mobile
-     * @param name
-     */
-    @Update("update ${schema}.sys_user set TENANTID = #{tenantid},ACCOUNT = #{mobile},NAME = #{name},MOBILE = #{mobile} where ID = '3f9d36b25773416eb7abf65823845bd6'")
-    void updateUserInfo(@Param("schema") String schema,@Param("tenantid") String tenantid,@Param("mobile") String mobile,@Param("name") String name);
-
-    @Select("select database()")
-    String getThisDataBaseName();
-
-    @Select("SELECT SCHEMA_NAME FROM information_schema.SCHEMATA")
-    List<String> allSchemaName();
-    @Select("select TENANTCODE from zhsw_dev.sys_tenant where UNIFIEDSOCIALCREDITCODE = #{socialCreditUniformCode} ")
-    String getTenantCodeBySocialCreditUniformCode(String socialCreditUniformCode);
-
-    @Select("select UNIFIEDSOCIALCREDITCODE from zhsw_dev.sys_tenant where id = #{id} ")
-    String getSocialCreditUniformCodeByTenantCode(@Param("id") String id);
-
-    List<TenantDo> getTenantDosById(@Param("idList") List<String> ids);
-}

+ 0 - 269
zhsw-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/LoginLogicServiceImpl.java

@@ -1,269 +0,0 @@
-package com.rongwei.sfcommon.sys.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.rongwei.commonservice.service.RedisService;
-
-import com.rongwei.rwadmincommon.system.domain.SysUserDo;
-import com.rongwei.rwadmincommon.system.domain.UserLoginVo;
-import com.rongwei.rwadmincommon.system.service.LoginUtilService;
-import com.rongwei.rwadmincommon.system.service.SysUserService;
-import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
-import com.rongwei.rwadmincommon.system.vo.SysUserVo;
-import com.rongwei.rwcommon.base.R;
-import com.rongwei.rwcommon.base.exception.CustomException;
-import com.rongwei.rwcommon.utils.Constants;
-import com.rongwei.rwcommon.utils.SecurityUtil;
-import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
-import com.rongwei.sfcommon.sys.dao.TenantDao;
-import com.rongwei.sfcommon.fegin.LoginAuth;
-import com.rongwei.sfcommon.sys.service.LoginLogicService;
-import lombok.SneakyThrows;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * LoginLogicServiceImpl class
- *
- * @author XH
- * @date 2021/12/13
- */
-@Service
-public class LoginLogicServiceImpl implements LoginLogicService {
-    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
-    @Autowired
-    private LoginUtilService loginUtilService;
-    @Autowired
-    private RedisService redisService;
-    @Autowired
-    private SysUserService sysUserService;
-    @Autowired
-    private TenantDao tenantDao;
-    @Autowired
-    private LoginAuth loginAuth;
-
-    @Value("${login.checkPhoneNumErrorMsg:手机号码未注册!}")
-    private String checkPhoneNumErrorMsg;
-    @Value("${login.primarySchemaId:1}")
-    private String primarySchemaId;
-
-    /**
-     * 移动端登录标识
-     */
-    private static final String MOBILE_CLIENT_TYPE = "YD";
-    private static final String MOBILE_LOGING_DEFAULT_ERROR = "没有找到该手机号绑定的账号";
-
-    /**
-     * 手机账号登录逻辑处理
-     *
-     * @param userLogin
-     * @return
-     */
-    @SneakyThrows
-    @Override
-    public R mobilePhoneLogin(UserLoginVo userLogin) {
-        // 登录验证码处理
-        loginUtilService.smsVerify(userLogin);
-        // 当前登录人的电话号码
-        String phoneNum = userLogin.getUsername();
-        if (StringUtils.isBlank(phoneNum)) {
-            log.error("登录手机号码为空");
-            throw new RuntimeException("请输入正确的手机号码");
-        }
-        // 从Redis 获取所有租户的用户信息
-        Map<String, List<SysUserDo>> allTenantUsers = (Map<String, List<SysUserDo>>) redisService.getRedisCatchObj("allTenantUsers");
-        if (allTenantUsers == null) {
-            log.error("无法获取租户和用户信息");
-            throw new RuntimeException("无法获取租户以及用户信息!请联系系统管理员");
-        }
-        // 获取需要展示的租户信息
-        TenantDo loginTenantDo = getTenantDo(userLogin, allTenantUsers, phoneNum);
-        // 切换至对应的Schema
-        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-        HttpServletRequest srequest = attributes.getRequest();
-        srequest.setAttribute(Constants.SAAS_LOGIN_TOKEN, loginTenantDo.getDskey());
-        // 从缓存中取出用户信息
-        SysUserDo loginUser = allTenantUsers.get(loginTenantDo.getId()).stream()
-                .filter(user -> phoneNum.equals(user.getMobile()))
-                .findFirst()
-                .orElse(null);
-        if (loginUser == null) {
-            log.error("无法获取登录的用户信息");
-            throw new RuntimeException("无法获取登录的用户信息");
-        }
-        SysUserVo sysUserVo = new SysUserVo();
-        BeanUtils.copyProperties(loginUser, sysUserVo);
-        // 设置租户信息
-        sysUserVo.setTenantDo(loginTenantDo);
-        // 生成token
-        JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(sysUserVo.getId(), sysUserVo.getAccount(), sysUserVo.getName());
-        jwtAuthenticationRequest.setExpire(-1);
-        Map<String, Object> tokenmap = loginAuth.getTokenInfo(jwtAuthenticationRequest);
-        String token = (String) tokenmap.get("token");
-        // 获取当前用户的角色  组织机构 和  权限
-        loginUtilService.setUserRoleAndOrg(sysUserVo);
-        // 菜单
-        Map<String, Object> map = new HashMap<>();
-        map.put("token", token);
-        map.put("userInfo", sysUserVo);
-        //redis缓存登录用户信息
-        redisService.setLoginUser(token, sysUserVo);
-        return R.ok(map);
-    }
-
-    /**
-     * 账号密码登录逻辑
-     * @param userLogin
-     * @return
-     */
-    @SneakyThrows
-    @Override
-    public R accountLogin(UserLoginVo userLogin) {
-        // Map<String, List<SysUserDo>> allTenantUsers = (Map<String, List<SysUserDo>>) redisService.getRedisCatchObj("allTenantUsers");
-        // 是否为融公社管理员登录
-//        if (userLogin.isCheckPrimaryLibrary()) {
-//            // 校验当前账号是否属于 主库
-//            // 获取主库中的用户信息
-//            List<SysUserDo> sysUserDos = allTenantUsers == null ? new ArrayList<>() : allTenantUsers.getOrDefault(primarySchemaId, new ArrayList<>());
-//            // 校验当前登录账号是否穿在
-//            boolean hasUser = sysUserDos.stream().anyMatch(user -> userLogin.getUsername().equals(user.getAccount()));
-//            // 不存在提示错误信息
-//            if (!hasUser) {
-//                log.error("当前登录账号:{} 在主库中不存在", userLogin.getUsername());
-//                throw new RuntimeException("账号或密码错误");
-//            }
-//            if (!allTenantUsers.containsKey(primarySchemaId)) {
-//                log.error("无法获取主库信息");
-//                throw new RuntimeException("无法获取主库信息!请联系系统管理员");
-//            }
-//            // 获取租户信息
-//            List<TenantDo> tenantDoList = tenantDao.getTenantDosById(Arrays.asList(primarySchemaId.split(",")));// (List<TenantDo>) redisService.getRedisCatchObj("allTenants");
-//            if (tenantDoList.isEmpty()) {
-//                log.error("无法通过id:{},获取到租户信息.", primarySchemaId);
-//                throw new RuntimeException("无法获取租户信息,请联系管理员!");
-//            }
-//            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-//            HttpServletRequest srequest = attributes.getRequest();
-//            srequest.setAttribute(Constants.SAAS_LOGIN_TOKEN, tenantDoList.get(0).getDskey());
-//        } else {
-            // 设置对应的Schema
-            loginUtilService.saasLoginToken(userLogin);
-     //   }
-        // 校验用户名正确性
-        SysUserDo sysUserDo = sysUserService.getOne(new LambdaQueryWrapper<SysUserDo>().eq(SysUserDo::getAccount,userLogin.getUsername()),true);
-        if (sysUserDo == null || StringUtils.isBlank(sysUserDo.getId())) {
-            // 防攻击,模糊提醒
-            throw new CustomException("用户名密码不正确");
-        }
-        if ("1".equals(sysUserDo.getEnabled())) {
-            throw new CustomException("此用户不可用,请联系管理员");
-        }
-        // 校验登录密码正确性
-        String secPas = SecurityUtil.getSaltMd5AndSha(userLogin.getPassword(), sysUserDo.getId());
-        if (!secPas.equals(sysUserDo.getPassword())) {
-            throw new CustomException("用户名密码不正确");
-        }
-        // token生成
-        JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(sysUserDo.getId(), sysUserDo.getAccount(), sysUserDo.getName());
-        if (userLogin.getClientType() != null && "YD".equals(userLogin.getClientType())) {
-            jwtAuthenticationRequest.setExpire(-1);
-        }
-        Map<String, Object> tokenmap = loginAuth.getTokenInfo(jwtAuthenticationRequest);
-        String token = (String) tokenmap.get("token");
-        if ("ServerAbnormal".equals(token)) {
-            throw new CustomException("认证服务异常");
-        }
-        // 组织返回给前端的用户信息
-        SysUserVo sysUserVo = new SysUserVo();
-        BeanUtils.copyProperties(sysUserDo, sysUserVo);
-        sysUserService.getUserRoleOrgPer(sysUserVo);
-        // 设置登录用户的租户信息
-        loginUtilService.setUserTenant(sysUserDo, sysUserVo);
-        // 菜单
-        Map<String, Object> map = new HashMap<>();
-        map.put("token", token);
-        map.put("userInfo", sysUserVo);
-        //redis缓存登录用户信息
-        redisService.setLoginUser(token, sysUserVo);
-        return R.ok(map);
-    }
-
-    /**
-     * 获取租户信息
-     *
-     * @return
-     */
-    private TenantDo getTenantDo(UserLoginVo userLogin, Map<String, List<SysUserDo>> allTenantUsers, String phoneNum) {
-        // 校验登录人的手机号在主库中是否存在
-        if (userLogin.isCheckPrimaryLibrary()) {
-            List<SysUserDo> primaryUsers = allTenantUsers.getOrDefault(primarySchemaId, new ArrayList<>());
-            boolean hasUser = primaryUsers.stream().anyMatch(user -> phoneNum.equals(user.getMobile()));
-            if (!hasUser) {
-                log.error("当前登录的手机号码在主库中不存在");
-                throw new RuntimeException(MOBILE_LOGING_DEFAULT_ERROR);
-            }
-            List<TenantDo> tenantDosById = tenantDao.getTenantDosById(Arrays.asList(primarySchemaId.split(",")));
-            if (tenantDosById.isEmpty()) {
-                log.error("无法通过id:{},获取到租户信息.", tenantDosById);
-                throw new RuntimeException("无法获取租户信息,请联系管理员!");
-            }
-            return tenantDosById.get(0);
-        }
-        List<SysUserDo> sysUserDos;
-        if (allTenantUsers == null) {
-            sysUserDos = new ArrayList<>();
-        } else {
-            // 从主库中获取手机号码相同的用户
-            if (userLogin.isCheckPrimaryLibrary()) {
-                sysUserDos = allTenantUsers.get(primarySchemaId)
-                        .stream()
-                        .filter(user -> primarySchemaId.equals(user.getTenantid()) && phoneNum.equals(user.getMobile()))
-                        .collect(Collectors.toList());
-            } else {
-                // 从所有住户表中获取手机号码相同的用户
-                sysUserDos = allTenantUsers.values().stream()
-                        .flatMap(Collection::stream)
-                        .filter(user -> phoneNum.equals(user.getMobile()))
-                        .collect(Collectors.toList());
-            }
-        }
-        if (sysUserDos.isEmpty()) {
-            log.error("当前手机号码:{},未注册", phoneNum);
-            throw new RuntimeException(checkPhoneNumErrorMsg);
-        }
-        // 筛选出用户所属于的租户ID
-        List<String> tenantIdList = sysUserDos.stream().map(SysUserDo::getTenantid).distinct().collect(Collectors.toList());
-        // 获取租户信息
-        List<TenantDo> tenantDoList = tenantDao.getTenantDosById(tenantIdList);// (List<TenantDo>) redisService.getRedisCatchObj("allTenants");
-        if (tenantDoList == null) {
-            log.error("无法从缓存中获取租户信息");
-            throw new RuntimeException("无法从缓存中获取租户信息,请联系管理员!");
-        }
-// modify at [ 2022-07-06 15:33:08 ] by zxw: 许总说,去掉移动端引导
-        // YD端登录需要筛选出已激活的租户信息 PC端登录不受限制 并按照创建时间 由小到大排序
-//        List<TenantDo> activateTenantList = tenantDoList.stream()
-//                .filter(tenantInfo -> {
-//                    if (MOBILE_CLIENT_TYPE.equals(userLogin.getClientType())) {
-//                        return "2".equals(tenantInfo.getTenantstatus()) && tenantIdList.contains(tenantInfo.getId());
-//                    }
-//                    return true;
-//                })
-//                .sorted(Comparator.comparing(BaseDo::getCreatedate))
-//                .collect(Collectors.toList());
-//        if (MOBILE_CLIENT_TYPE.equals(userLogin.getClientType()) && activateTenantList.isEmpty()) {
-//            log.error("当前用户:{}不存在已激活的租户信息 ", phoneNum);
-//            throw new RuntimeException("请登录网页版,完成初始化配置");
-//        }
-        return tenantDoList.get(0);
-    }
-}

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/LoginAuth.java

@@ -1,4 +1,4 @@
-package com.rongwei.sfcommon.fegin;
+package com.rongwei.zhsw.fegin;
 
 import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
 import org.springframework.cloud.openfeign.FeignClient;

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/LoginAuthImpl.java

@@ -1,4 +1,4 @@
-package com.rongwei.sfcommon.fegin;
+package com.rongwei.zhsw.fegin;
 
 import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
 import org.springframework.stereotype.Component;

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/TenantFeginService.java

@@ -1,4 +1,4 @@
-package com.rongwei.sfcommon.fegin;
+package com.rongwei.zhsw.fegin;
 
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/sfcommon/fegin/TenantFeginServiceImpl.java

@@ -1,4 +1,4 @@
-package com.rongwei.sfcommon.fegin;
+package com.rongwei.zhsw.fegin;
 
 import com.codingapi.txlcn.tc.support.DTXUserControls;
 import com.codingapi.txlcn.tracing.TracingContext;

+ 16 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/dao/CommonBusinessDao.java

@@ -0,0 +1,16 @@
+package com.rongwei.zhsw.sys.dao;
+
+import com.rongwe.zhsw.vo.OwnerVo;
+import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface CommonBusinessDao {
+
+    List<TenantDo> getById(@Param("id") String id);
+
+    List<OwnerVo> getOwnerInfoByDsId(@Param("dsId") String dsKey);
+}

+ 19 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/dao/SwUserManagementMapper.java

@@ -0,0 +1,19 @@
+package com.rongwei.zhsw.sys.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.rongwe.zhsw.domian.SwUserManagement;
+
+/**
+* @author libai
+* @description 针对表【sw_user_management(用户管理)】的数据库操作Mapper
+* @createDate 2025-03-07 11:13:50
+* @Entity generator.domain.SwUserManagement
+*/
+public interface SwUserManagementMapper extends BaseMapper<SwUserManagement> {
+
+}
+
+
+
+

+ 3 - 8
zhsw-common/src/main/java/com/rongwei/sfcommon/sys/service/LoginLogicService.java

@@ -1,4 +1,4 @@
-package com.rongwei.sfcommon.sys.service;
+package com.rongwei.zhsw.sys.service;
 
 import com.rongwei.rwadmincommon.system.domain.UserLoginVo;
 import com.rongwei.rwcommon.base.R;
@@ -10,17 +10,12 @@ import com.rongwei.rwcommon.base.R;
  * @date 2021/12/13
  */
 public interface LoginLogicService {
-    /**
-     * 手机号码登录
-     * @param userLogin
-     * @return
-     */
-    R mobilePhoneLogin(UserLoginVo userLogin);
-
     /**
      * 账号密码登录
      * @param userLogin
      * @return
      */
     R accountLogin(UserLoginVo userLogin);
+
+    R wechatLogin();
 }

+ 16 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/OwnerService.java

@@ -0,0 +1,16 @@
+package com.rongwei.zhsw.sys.service;
+
+import com.rongwei.rwcommon.base.R;
+
+import java.util.Map;
+
+/**
+ * OwnerService class
+ *
+ * @author XH
+ * @date 2025/03/07
+ */
+
+public interface OwnerService {
+    R refreshOwner(Map<String, String> refreshPara);
+}

+ 14 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/SwUserManagementService.java

@@ -0,0 +1,14 @@
+package com.rongwei.zhsw.sys.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwe.zhsw.domian.SwUserManagement;
+
+/**
+* @author libai
+* @description 针对表【sw_user_management(用户管理)】的数据库操作Service
+* @createDate 2025-03-07 11:13:50
+*/
+public interface SwUserManagementService extends IService<SwUserManagement> {
+
+}

+ 148 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/LoginLogicServiceImpl.java

@@ -0,0 +1,148 @@
+package com.rongwei.zhsw.sys.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.rongwei.commonservice.service.RedisService;
+
+import com.rongwei.rwadmincommon.system.domain.SysUserDo;
+import com.rongwei.rwadmincommon.system.domain.UserLoginVo;
+import com.rongwei.rwadmincommon.system.service.LoginUtilService;
+import com.rongwei.rwadmincommon.system.service.SysUserService;
+import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.Constants;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
+import com.rongwei.zhsw.sys.dao.CommonBusinessDao;
+import com.rongwei.zhsw.fegin.LoginAuth;
+import com.rongwei.zhsw.sys.service.LoginLogicService;
+import lombok.SneakyThrows;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * LoginLogicServiceImpl class
+ *
+ * @author XH
+ * @date 2021/12/13
+ */
+@Service
+public class LoginLogicServiceImpl implements LoginLogicService {
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+    @Autowired
+    private LoginUtilService loginUtilService;
+    @Autowired
+    private RedisService redisService;
+    @Autowired
+    private SysUserService sysUserService;
+    @Autowired
+    private CommonBusinessDao CommonBusinessDao;
+    @Autowired
+    private LoginAuth loginAuth;
+
+    @Value("${login.checkPhoneNumErrorMsg:手机号码未注册!}")
+    private String checkPhoneNumErrorMsg;
+    @Value("${login.primarySchemaId:1}")
+    private String primarySchemaId;
+
+    /**
+     * 移动端登录标识
+     */
+    private static final String MOBILE_CLIENT_TYPE = "YD";
+    private static final String MOBILE_LOGING_DEFAULT_ERROR = "没有找到该手机号绑定的账号";
+
+    /**
+     * 账号密码登录逻辑
+     * @param userLogin
+     * @return
+     */
+    @SneakyThrows
+    @Override
+    public R accountLogin(UserLoginVo userLogin) {
+        // Map<String, List<SysUserDo>> allTenantUsers = (Map<String, List<SysUserDo>>) redisService.getRedisCatchObj("allTenantUsers");
+        // 是否为融公社管理员登录
+//        if (userLogin.isCheckPrimaryLibrary()) {
+//            // 校验当前账号是否属于 主库
+//            // 获取主库中的用户信息
+//            List<SysUserDo> sysUserDos = allTenantUsers == null ? new ArrayList<>() : allTenantUsers.getOrDefault(primarySchemaId, new ArrayList<>());
+//            // 校验当前登录账号是否穿在
+//            boolean hasUser = sysUserDos.stream().anyMatch(user -> userLogin.getUsername().equals(user.getAccount()));
+//            // 不存在提示错误信息
+//            if (!hasUser) {
+//                log.error("当前登录账号:{} 在主库中不存在", userLogin.getUsername());
+//                throw new RuntimeException("账号或密码错误");
+//            }
+//            if (!allTenantUsers.containsKey(primarySchemaId)) {
+//                log.error("无法获取主库信息");
+//                throw new RuntimeException("无法获取主库信息!请联系系统管理员");
+//            }
+//            // 获取租户信息
+//            List<TenantDo> tenantDoList = tenantDao.getTenantDosById(Arrays.asList(primarySchemaId.split(",")));// (List<TenantDo>) redisService.getRedisCatchObj("allTenants");
+//            if (tenantDoList.isEmpty()) {
+//                log.error("无法通过id:{},获取到租户信息.", primarySchemaId);
+//                throw new RuntimeException("无法获取租户信息,请联系管理员!");
+//            }
+//            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+//            HttpServletRequest srequest = attributes.getRequest();
+//            srequest.setAttribute(Constants.SAAS_LOGIN_TOKEN, tenantDoList.get(0).getDskey());
+//        } else {
+            // 设置对应的Schema
+            loginUtilService.saasLoginToken(userLogin);
+     //   }
+        // 校验用户名正确性
+        SysUserDo sysUserDo = sysUserService.getOne(new LambdaQueryWrapper<SysUserDo>().eq(SysUserDo::getAccount,userLogin.getUsername()),true);
+        if (sysUserDo == null || StringUtils.isBlank(sysUserDo.getId())) {
+            // 防攻击,模糊提醒
+            throw new CustomException("用户名密码不正确");
+        }
+        if ("1".equals(sysUserDo.getEnabled())) {
+            throw new CustomException("此用户不可用,请联系管理员");
+        }
+        // 校验登录密码正确性
+        String secPas = SecurityUtil.getSaltMd5AndSha(userLogin.getPassword(), sysUserDo.getId());
+        if (!secPas.equals(sysUserDo.getPassword())) {
+            throw new CustomException("用户名密码不正确");
+        }
+        // token生成
+        JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(sysUserDo.getId(), sysUserDo.getAccount(), sysUserDo.getName());
+        if (userLogin.getClientType() != null && "YD".equals(userLogin.getClientType())) {
+            jwtAuthenticationRequest.setExpire(-1);
+        }
+        Map<String, Object> tokenmap = loginAuth.getTokenInfo(jwtAuthenticationRequest);
+        String token = (String) tokenmap.get("token");
+        if ("ServerAbnormal".equals(token)) {
+            throw new CustomException("认证服务异常");
+        }
+        // 组织返回给前端的用户信息
+        SysUserVo sysUserVo = new SysUserVo();
+        BeanUtils.copyProperties(sysUserDo, sysUserVo);
+        sysUserService.getUserRoleOrgPer(sysUserVo);
+        // 设置登录用户的租户信息
+        loginUtilService.setUserTenant(sysUserDo, sysUserVo);
+        // 菜单
+        Map<String, Object> map = new HashMap<>();
+        map.put("token", token);
+        map.put("userInfo", sysUserVo);
+        //redis缓存登录用户信息
+        redisService.setLoginUser(token, sysUserVo);
+        return R.ok(map);
+    }
+
+    @Override
+    public R wechatLogin() {
+        return null;
+    }
+
+}

+ 53 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/OwnerServiceImpl.java

@@ -0,0 +1,53 @@
+package com.rongwei.zhsw.sys.service.impl;
+
+import com.rongwe.zhsw.vo.OwnerVo;
+import com.rongwei.commonservice.service.impl.RedisServiceImpl;
+import com.rongwei.rwadmincommon.system.dao.CommonDao;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
+import com.rongwei.zhsw.sys.dao.CommonBusinessDao;
+import com.rongwei.zhsw.sys.service.OwnerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * OwnerService class
+ *
+ * @author XH
+ * @date 2025/03/07
+ */
+@Service
+public class OwnerServiceImpl implements OwnerService {
+    private static final Logger log = LoggerFactory.getLogger(OwnerServiceImpl.class);
+
+    @Autowired
+    private CommonBusinessDao CommonBusinessDao;
+    @Autowired
+    private RedisServiceImpl redisService;
+    // 业主对应的租户ID
+    public static final String redis_owner_key="owner_%s";
+
+    @Override
+    public R refreshOwner(Map<String, String> refreshPara) {
+        log.debug("开始执行刷新业主的操作:{}",refreshPara);
+        String dsId = refreshPara.getOrDefault("dsId", "");
+        List<TenantDo> tenantDos = CommonBusinessDao.getById(dsId);
+        tenantDos.forEach(tenantDo -> {
+           try {
+               List<OwnerVo> ownerInfoByDsId = CommonBusinessDao.getOwnerInfoByDsId(tenantDo.getDskey());
+               redisService.redisCatchInit(String.format(redis_owner_key,tenantDo.getDskey()), ownerInfoByDsId, 0);
+           }catch (Exception e){
+               log.error("获取:{}下的业主信息失败",tenantDo.getDskey());
+           }
+        });
+        return R.ok();
+    }
+
+
+
+}

+ 23 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/sys/service/impl/SwUserManagementServiceImpl.java

@@ -0,0 +1,23 @@
+package com.rongwei.zhsw.sys.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.rongwe.zhsw.domian.SwUserManagement;
+import com.rongwei.zhsw.sys.dao.SwUserManagementMapper;
+import com.rongwei.zhsw.sys.service.SwUserManagementService;
+import org.springframework.stereotype.Service;
+
+/**
+* @author libai
+* @description 针对表【sw_user_management(用户管理)】的数据库操作Service实现
+* @createDate 2025-03-07 11:13:50
+*/
+@Service
+public class SwUserManagementServiceImpl extends ServiceImpl<SwUserManagementMapper, SwUserManagement>
+    implements SwUserManagementService {
+
+}
+
+
+
+

+ 15 - 0
zhsw-common/src/main/resources/mybatis/CommonBusinessDao.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.rongwei.zhsw.sys.dao.CommonBusinessDao">
+    <select id="getById" resultType="com.rongwei.rwcommonentity.commonservers.domain.TenantDo">
+        select * from zhsw_dev.sys_tenant where DELETED='0'
+        <if test="id != null and id != ''">
+            AND ID = #{id}
+        </if>
+    </select>
+    <select id="getOwnerInfoByDsId" resultType="com.rongwe.zhsw.vo.OwnerVo">
+        select ID as id ,WECHATSIGN as weChatSign,#{dsId}as dsKey,STATUS as status  from ${dsId}.sw_user_management where DELETED='0'
+    </select>
+</mapper>

+ 7 - 0
zhsw-common/src/main/resources/mybatis/SwUserManagementMapper.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.rongwei.zhsw.sys.dao.SwUserManagementMapper">
+</mapper>
+

+ 113 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/domian/SwUserManagement.java

@@ -0,0 +1,113 @@
+package com.rongwe.zhsw.domian;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.rongwei.rwcommon.base.BaseDo;
+import lombok.Data;
+
+/**
+ * 用户管理
+ * @TableName sw_user_management
+ */
+@TableName(value ="sw_user_management")
+@Data
+public class SwUserManagement extends BaseDo {
+    /**
+     * 主键
+     */
+    @TableId
+    private String id;
+
+    /**
+     * 租户ID
+     */
+    private String tenantid;
+
+    /**
+     * 扩展json格式配置
+     */
+    private String roption;
+
+    /**
+     * 户号
+     */
+    private String usernumber;
+
+    /**
+     * 户名
+     */
+    private String username;
+
+    /**
+     * 用水类型
+     */
+    private String watertype;
+
+    /**
+     * 小区/村落/街道名称
+     */
+    private String villagename;
+
+    /**
+     * 详细地址
+     */
+    private String address;
+
+    /**
+     * 手机号
+     */
+    private String phonenumber;
+
+    /**
+     * 状态
+     */
+    private String status;
+
+    /**
+     * 册号
+     */
+    private String volumeno;
+
+    /**
+     * 账户余额
+     */
+    private BigDecimal accountbalance;
+
+    /**
+     * 微信绑定状态
+     */
+    private String wechatbindstatus;
+
+    /**
+     * 用户类别ID
+     */
+    private String usertypeid;
+
+    /**
+     * 册号ID
+     */
+    private String volumenoid;
+
+    /**
+     * 用户类别
+     */
+    private String usertype;
+
+    /**
+     * 最后一次抄表日期
+     */
+    private Date lastmeterreaddate;
+
+    /**
+     * 最后一次抄表读数
+     */
+    private BigDecimal lastmeterreading;
+
+    /**
+     * 微信标识
+     */
+    private String wechatsign;
+}

+ 18 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/vo/OwnerVo.java

@@ -0,0 +1,18 @@
+package com.rongwe.zhsw.vo;
+
+import lombok.Data;
+
+/**
+ * OwnerVo class
+ *
+ * @author XH
+ * @date 2025/03/07
+ */
+@Data
+public class OwnerVo {
+    // 用户ID
+    private String id;
+    private String dsKey;
+    private String weChatSign;
+    private String status;
+}

+ 11 - 1
zhsw-server/src/main/java/com/rongwei/zhsw/controller/LoginLogicController.java

@@ -3,7 +3,7 @@ package com.rongwei.zhsw.controller;
 
 import com.rongwei.rwadmincommon.system.domain.UserLoginVo;
 import com.rongwei.rwcommon.base.R;
-import com.rongwei.sfcommon.sys.service.LoginLogicService;
+import com.rongwei.zhsw.sys.service.LoginLogicService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,4 +38,14 @@ public class LoginLogicController {
         return loginLogicService.accountLogin(userLogin);
     }
 
+    /**
+     * Core+ 通过账号密码登录和校验方法
+     *
+     * @param userLogin
+     * @return
+     */
+    @PostMapping("/wechat")
+    private R wechatLogin(@RequestBody UserLoginVo userLogin) {
+        return loginLogicService.accountLogin(userLogin);
+    }
 }

+ 42 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/controller/OwnerController.java

@@ -0,0 +1,42 @@
+package com.rongwei.zhsw.controller;
+
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.zhsw.sys.service.OwnerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * OwnerController class
+ *
+ * @author XH
+ * @date 2025/03/07
+ */
+@RestController
+@RequestMapping("/owner")
+public class OwnerController {
+
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+    @Autowired
+    private OwnerService ownerService;
+
+
+    /**
+     * Core+ 通过账号密码登录和校验方法
+     *
+     * @param data
+     * @return
+     */
+    @PostMapping("/refresh")
+    private R refreshOwner(@RequestBody Map<String, String> refreshPara) {
+        return ownerService.refreshOwner(refreshPara);
+    }
+
+}