Browse Source

优化同步gitlink用户

dev-active_learn
chenzhihang 10 months ago
parent
commit
882ded2276
18 changed files with 374 additions and 227 deletions
  1. +18
    -3
      ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteMmpService.java
  2. +1
    -5
      ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java
  3. +2
    -0
      ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java
  4. +11
    -22
      ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java
  5. +27
    -1
      ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteMmpFallbackFactory.java
  6. +39
    -68
      ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
  7. +39
    -6
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/git/GitLinkController.java
  8. +19
    -9
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java
  9. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java
  10. +69
    -11
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java
  11. +12
    -14
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java
  12. +5
    -5
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java
  13. +20
    -7
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/NewHttpUtils.java
  14. +13
    -21
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java
  15. +1
    -1
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java
  16. +6
    -5
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
  17. +80
    -34
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
  18. +11
    -14
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 18
- 3
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteMmpService.java View File

@@ -2,14 +2,29 @@ package com.ruoyi.system.api;


import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.factory.RemoteMmpFallbackFactory; import com.ruoyi.system.api.factory.RemoteMmpFallbackFactory;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;


@FeignClient(contextId = "remoteMmpService", value = ServiceNameConstants.MANAGEMENT_SERVICE, fallbackFactory = RemoteMmpFallbackFactory.class) @FeignClient(contextId = "remoteMmpService", value = ServiceNameConstants.MANAGEMENT_SERVICE, fallbackFactory = RemoteMmpFallbackFactory.class)
public interface RemoteMmpService { public interface RemoteMmpService {
@GetMapping("/gitLink/login") @GetMapping("/gitLink/login")
public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("ci4sUsername") String ci4sUsername, @RequestParam("username") String username, @RequestParam("password") String password);
public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("username") String username, @RequestParam("password") String password);


@PostMapping("/gitLink/createGitLinkUser")
public GenericsAjaxResult<String> createGitLinkUser(@RequestBody SysUser sysUser) throws Exception;

@PostMapping("/gitLink/resetPwd")
public GenericsAjaxResult<String> resetPwd(@RequestBody SysUser sysUser) throws Exception;

@PostMapping("/gitLink/resetEmail")
public GenericsAjaxResult<String> resetEmail(@RequestBody SysUser sysUser) throws Exception;

@PostMapping("/gitLink/resetPhoneNum")
public GenericsAjaxResult<String> resetPhoneNum(@RequestBody SysUser sysUser) throws Exception;

@DeleteMapping("/gitLink/deleteGitLinkUser")
public GenericsAjaxResult<String> deleteGitLinkUser(@RequestBody SysUser sysUser) throws Exception;
} }

+ 1
- 5
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java View File

@@ -1,11 +1,7 @@
package com.ruoyi.system.api; package com.ruoyi.system.api;


import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;


+ 2
- 0
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/Constant.java View File

@@ -58,4 +58,6 @@ public class Constant {
public final static String TaskType_ActiveLearn = "active_learn"; public final static String TaskType_ActiveLearn = "active_learn";
public final static String TaskType_Service = "service"; public final static String TaskType_Service = "service";
public final static String DelFlag = "2"; public final static String DelFlag = "2";

public final static String Code = "123123";
} }

+ 11
- 22
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java View File

@@ -75,6 +75,8 @@ public class SysUser extends BaseEntity {
*/ */
private String password; private String password;


private String originPassword;

/** /**
* 帐号状态(0正常 1停用) * 帐号状态(0正常 1停用)
*/ */
@@ -127,10 +129,6 @@ public class SysUser extends BaseEntity {
*/ */
private Long roleId; private Long roleId;


private String gitLinkUsername;

private String gitLinkPassword;

private Float credit; private Float credit;


public SysUser() { public SysUser() {
@@ -229,6 +227,14 @@ public class SysUser extends BaseEntity {
this.password = password; this.password = password;
} }


public String getOriginPassword() {
return originPassword;
}

public void setOriginPassword(String originPassword) {
this.originPassword = originPassword;
}

public String getStatus() { public String getStatus() {
return status; return status;
} }
@@ -301,22 +307,6 @@ public class SysUser extends BaseEntity {
this.roleId = roleId; this.roleId = roleId;
} }


public void setGitLinkUsername(String gitLinkUsername) {
this.gitLinkUsername = gitLinkUsername;
}

public String getGitLinkUsername() {
return gitLinkUsername;
}

public void setGitLinkPassword(String gitLinkPassword) {
this.gitLinkPassword = gitLinkPassword;
}

public String getGitLinkPassword() {
return gitLinkPassword;
}

public void setCredit(Float credit) { public void setCredit(Float credit) {
this.credit = credit; this.credit = credit;
} }
@@ -337,6 +327,7 @@ public class SysUser extends BaseEntity {
.append("sex", getSex()) .append("sex", getSex())
.append("avatar", getAvatar()) .append("avatar", getAvatar())
.append("password", getPassword()) .append("password", getPassword())
.append("originPassword", getOriginPassword())
.append("status", getStatus()) .append("status", getStatus())
.append("delFlag", getDelFlag()) .append("delFlag", getDelFlag())
.append("loginIp", getLoginIp()) .append("loginIp", getLoginIp())
@@ -347,8 +338,6 @@ public class SysUser extends BaseEntity {
.append("updateTime", getUpdateTime()) .append("updateTime", getUpdateTime())
.append("remark", getRemark()) .append("remark", getRemark())
.append("dept", getDept()) .append("dept", getDept())
.append("gitLinkUsername", getGitLinkUsername())
.append("gitLinkPassword", getGitLinkPassword())
.append("credit", getCredit()) .append("credit", getCredit())
.toString(); .toString();
} }


+ 27
- 1
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteMmpFallbackFactory.java View File

@@ -2,6 +2,7 @@ package com.ruoyi.system.api.factory;


import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.system.api.RemoteMmpService; import com.ruoyi.system.api.RemoteMmpService;
import com.ruoyi.system.api.domain.SysUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
@@ -17,9 +18,34 @@ public class RemoteMmpFallbackFactory implements FallbackFactory<RemoteMmpServic
log.error("管理平台服务调用失败:{}", throwable.getMessage()); log.error("管理平台服务调用失败:{}", throwable.getMessage());
return new RemoteMmpService() { return new RemoteMmpService() {
@Override @Override
public GenericsAjaxResult<String> gitLinkLogin(String ci4sUsername, String username, String password) {
public GenericsAjaxResult<String> gitLinkLogin(String username, String password) {
return GenericsAjaxResult.error("刷新gitLink登录信息失败"); return GenericsAjaxResult.error("刷新gitLink登录信息失败");
} }

@Override
public GenericsAjaxResult<String> createGitLinkUser(SysUser sysUser) throws Exception {
throw new Exception("新增gitLink用户失败:" + throwable.getMessage());
}

@Override
public GenericsAjaxResult<String> resetPwd(SysUser sysUser) throws Exception {
throw new Exception("修改gitLink用户密码失败:" + throwable.getMessage());
}

@Override
public GenericsAjaxResult<String> resetEmail(SysUser sysUser) throws Exception {
throw new Exception("修改gitLink用户邮箱失败:" + throwable.getMessage());
}

@Override
public GenericsAjaxResult<String> resetPhoneNum(SysUser sysUser) throws Exception {
throw new Exception("修改gitLink用户手机号失败:" + throwable.getMessage());
}

@Override
public GenericsAjaxResult<String> deleteGitLinkUser(SysUser sysUser) throws Exception {
throw new Exception("删除gitLink用户失败:" + throwable.getMessage());
}
}; };
} }
} }

+ 39
- 68
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java View File

@@ -1,9 +1,6 @@
package com.ruoyi.auth.service; package com.ruoyi.auth.service;


import com.ruoyi.auth.form.AccessTokenVo; import com.ruoyi.auth.form.AccessTokenVo;
import com.ruoyi.system.api.RemoteMmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
@@ -16,18 +13,20 @@ import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.ip.IpUtils; import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.RemoteMmpService;
import com.ruoyi.system.api.RemoteUserService; import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/** /**
* 登录校验方法 * 登录校验方法
*
*
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
public class SysLoginService
{
public class SysLoginService {
@Autowired @Autowired
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;


@@ -42,93 +41,80 @@ public class SysLoginService


@Autowired @Autowired
private RemoteMmpService remoteMmpService; private RemoteMmpService remoteMmpService;

/** /**
* 登录 * 登录
*/ */
public LoginUser login(String username, String password)
{
public LoginUser login(String username, String password) {
// 用户名或密码为空 错误 // 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password))
{
if (StringUtils.isAnyBlank(username, password)) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
throw new ServiceException("用户/密码必须填写"); throw new ServiceException("用户/密码必须填写");
} }
// 密码如果不在指定范围内 错误 // 密码如果不在指定范围内 错误
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
{
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
throw new ServiceException("用户密码不在指定范围"); throw new ServiceException("用户密码不在指定范围");
} }
// 用户名不在指定范围内 错误 // 用户名不在指定范围内 错误
if (username.length() < UserConstants.USERNAME_MIN_LENGTH if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
throw new ServiceException("用户名不在指定范围"); throw new ServiceException("用户名不在指定范围");
} }
// IP黑名单校验 // IP黑名单校验
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
{
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
} }
// 查询用户信息 // 查询用户信息
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);


if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
{
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
throw new ServiceException("登录用户:" + username + " 不存在"); throw new ServiceException("登录用户:" + username + " 不存在");
} }


if (R.FAIL == userResult.getCode())
{
if (R.FAIL == userResult.getCode()) {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());
} }
LoginUser userInfo = userResult.getData(); LoginUser userInfo = userResult.getData();
SysUser user = userResult.getData().getSysUser(); SysUser user = userResult.getData().getSysUser();
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
} }
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
throw new ServiceException("对不起,您的账号:" + username + " 已停用"); throw new ServiceException("对不起,您的账号:" + username + " 已停用");
} }
passwordService.validate(user, password); passwordService.validate(user, password);
remoteMmpService.gitLinkLogin(username, user.getOriginPassword());
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
remoteMmpService.gitLinkLogin(username, user.getGitLinkUsername(),user.getGitLinkPassword());
return userInfo; return userInfo;
} }


public void logout(String loginName)
{
public void logout(String loginName) {
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功"); recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
} }


/** /**
* 注册 * 注册
*/ */
public void register(String username, String password)
{
public void register(String username, String password) {
// 用户名或密码为空 错误 // 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password))
{
if (StringUtils.isAnyBlank(username, password)) {
throw new ServiceException("用户/密码必须填写"); throw new ServiceException("用户/密码必须填写");
} }
if (username.length() < UserConstants.USERNAME_MIN_LENGTH if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
throw new ServiceException("账户长度必须在2到20个字符之间"); throw new ServiceException("账户长度必须在2到20个字符之间");
} }
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
{
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
throw new ServiceException("密码长度必须在5到20个字符之间"); throw new ServiceException("密码长度必须在5到20个字符之间");
} }


@@ -139,8 +125,7 @@ public class SysLoginService
sysUser.setPassword(SecurityUtils.encryptPassword(password)); sysUser.setPassword(SecurityUtils.encryptPassword(password));
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER); R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);


if (R.FAIL == registerResult.getCode())
{
if (R.FAIL == registerResult.getCode()) {
throw new ServiceException(registerResult.getMsg()); throw new ServiceException(registerResult.getMsg());
} }
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功"); recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
@@ -148,52 +133,45 @@ public class SysLoginService


public LoginUser loginByKey(String username, String key) { public LoginUser loginByKey(String username, String key) {
// 用户名或密码为空 错误 // 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, key))
{
if (StringUtils.isAnyBlank(username, key)) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/key必须填写"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/key必须填写");
throw new ServiceException("用户/key必须填写"); throw new ServiceException("用户/key必须填写");
} }
// 用户名不在指定范围内 错误 // 用户名不在指定范围内 错误
if (username.length() < UserConstants.USERNAME_MIN_LENGTH if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
throw new ServiceException("用户名不在指定范围"); throw new ServiceException("用户名不在指定范围");
} }
// IP黑名单校验 // IP黑名单校验
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
{
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
} }
// 查询用户信息 // 查询用户信息
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);


if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
{
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
throw new ServiceException("登录用户:" + username + " 不存在"); throw new ServiceException("登录用户:" + username + " 不存在");
} }


if (R.FAIL == userResult.getCode())
{
if (R.FAIL == userResult.getCode()) {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());
} }


LoginUser userInfo = userResult.getData(); LoginUser userInfo = userResult.getData();
SysUser user = userResult.getData().getSysUser(); SysUser user = userResult.getData().getSysUser();
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
} }
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
throw new ServiceException("对不起,您的账号:" + username + " 已停用"); throw new ServiceException("对不起,您的账号:" + username + " 已停用");
} }
if (!StringUtils.equals(key,"h1n2x3j4y5@")){
if (!StringUtils.equals(key, "h1n2x3j4y5@")) {
throw new ServiceException("对不起,您的key不正确"); throw new ServiceException("对不起,您的key不正确");
} }
return userInfo; return userInfo;
@@ -204,51 +182,44 @@ public class SysLoginService
String username = accountInfo.getUsername(); String username = accountInfo.getUsername();


// 用户名或密码为空 错误 // 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username))
{
if (StringUtils.isAnyBlank(username)) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
throw new ServiceException("用户/密码必须填写"); throw new ServiceException("用户/密码必须填写");
} }


// 用户名不在指定范围内 错误 // 用户名不在指定范围内 错误
if (username.length() < UserConstants.USERNAME_MIN_LENGTH if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
throw new ServiceException("用户名不在指定范围"); throw new ServiceException("用户名不在指定范围");
} }
// IP黑名单校验 // IP黑名单校验
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
{
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
} }
// 查询用户信息 // 查询用户信息
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);


if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
{
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
throw new ServiceException("登录用户:" + username + " 不存在"); throw new ServiceException("登录用户:" + username + " 不存在");
// register(username, "123456");
// register(username, "123456");
// userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); // userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
} }


if (R.FAIL == userResult.getCode())
{
if (R.FAIL == userResult.getCode()) {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());
} }


LoginUser userInfo = userResult.getData(); LoginUser userInfo = userResult.getData();
SysUser user = userResult.getData().getSysUser(); SysUser user = userResult.getData().getSysUser();
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
} }
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
throw new ServiceException("对不起,您的账号:" + username + " 已停用"); throw new ServiceException("对不起,您的账号:" + username + " 已停用");
} }


+ 39
- 6
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/git/GitLinkController.java View File

@@ -3,12 +3,10 @@ package com.ruoyi.platform.controller.git;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.service.GitService; import com.ruoyi.platform.service.GitService;
import com.ruoyi.system.api.domain.SysUser;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource; import javax.annotation.Resource;


@@ -22,7 +20,42 @@ public class GitLinkController extends BaseController {


@GetMapping("/login") @GetMapping("/login")
@ApiOperation("刷新giotLink用户信息") @ApiOperation("刷新giotLink用户信息")
public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("ci4sUsername") String ci4sUsername, @RequestParam("username") String username, @RequestParam("password") String password) {
return genericsSuccess(gitService.login(ci4sUsername, username, password));
public GenericsAjaxResult<String> gitLinkLogin(@RequestParam("username") String username, @RequestParam("password") String password) {
return genericsSuccess(gitService.login(username, password));
}

@PostMapping("/createGitLinkUser")
@ApiOperation("新增gitLink用户")
public GenericsAjaxResult<String> createGitLinkUser(@RequestBody SysUser sysUser) throws Exception {
gitService.createUser(sysUser);
return GenericsAjaxResult.success("新增成功");
}

@PostMapping("/resetPwd")
@ApiOperation("更改gitLink用户密码")
public GenericsAjaxResult<String> resetPwd(@RequestBody SysUser sysUser) throws Exception {
gitService.resetPwd(sysUser);
return GenericsAjaxResult.success("修改成功");
}

@PutMapping("/resetEmail")
@ApiOperation("更改gitLink用户邮箱")
public GenericsAjaxResult<String> resetEmail(@RequestBody SysUser sysUser) throws Exception {
gitService.resetEmail(sysUser);
return GenericsAjaxResult.success("修改成功");
}

@PutMapping("/resetPhoneNum")
@ApiOperation("更改gitLink用户手机号")
public GenericsAjaxResult<String> resetPhoneNum(@RequestBody SysUser sysUser) throws Exception {
gitService.resetPhoneNum(sysUser);
return GenericsAjaxResult.success("修改成功");
}

@DeleteMapping("/deleteGitLinkUser")
@ApiOperation("删除gitLink用户")
public GenericsAjaxResult<String> deleteGitLinkUser(@RequestBody SysUser sysUser) throws Exception {
gitService.deleteUser(sysUser);
return GenericsAjaxResult.success("删除成功");
} }
} }

+ 19
- 9
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/GitService.java View File

@@ -1,31 +1,41 @@
package com.ruoyi.platform.service; package com.ruoyi.platform.service;


import com.ruoyi.platform.vo.GitProjectVo; import com.ruoyi.platform.vo.GitProjectVo;
import com.ruoyi.system.api.domain.SysUser;


import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


public interface GitService { public interface GitService {
//登录方法,返回token //登录方法,返回token
String login(String ci4sUsername, String username, String password);
String login(String username, String password);


String checkoutToken(); String checkoutToken();


//输入token,项目名,tag,创建新项目,返回项目地址 //输入token,项目名,tag,创建新项目,返回项目地址
Map createProject(String token,GitProjectVo gitProjectVo) throws Exception;
Map createProject(String token, GitProjectVo gitProjectVo) throws Exception;


void createBranch(String token,String owner, String projectName, String branchName, String oldBranchName) throws Exception;
void createBranch(String token, String owner, String projectName, String branchName, String oldBranchName) throws Exception;


void createTopic(String token,Integer id, String topicName) throws Exception;
void createTopic(String token, Integer id, String topicName) throws Exception;


List<Map<String, Object>> getBrancheList(String token,String owner, String projectName) throws Exception;
List<Map<String, Object>> getBrancheList(String token, String owner, String projectName) throws Exception;


void deleteProject(String token,String owner, String projectName) throws Exception;
void deleteProject(String token, String owner, String projectName) throws Exception;


void deleteBranch(String token,String owner, String projectName, String branchName, String localPath) throws Exception;
void deleteBranch(String token, String owner, String projectName, String branchName, String localPath) throws Exception;


Map getUserInfo(String token) throws Exception; Map getUserInfo(String token) throws Exception;


Map getProjectDetail(String owner, String identifier, String token) throws IOException;
Map getProjectDetail(String owner, String identifier, String token) throws Exception;

void createUser(SysUser sysUser) throws Exception;

void resetPwd(SysUser sysUser) throws Exception;

void resetEmail(SysUser sysUser) throws Exception;

void resetPhoneNum(SysUser sysUser) throws Exception;

void deleteUser(SysUser sysUser) throws Exception;
} }

+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java View File

@@ -529,7 +529,7 @@ public class ExperimentServiceImpl implements ExperimentService {


private void insertModelDependencyNew(Map<String, Object> dependendcy, Map<String, Object> trainInfo, Map<String, Object> output, String metricRecord, Integer experimentInsId, Long workflowId, Integer experimentId, String experimentName, String globalParam) { private void insertModelDependencyNew(Map<String, Object> dependendcy, Map<String, Object> trainInfo, Map<String, Object> output, String metricRecord, Integer experimentInsId, Long workflowId, Integer experimentId, String experimentName, String globalParam) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkUsername = loginUser.getSysUser().getUserName();
Iterator<Map.Entry<String, Object>> dependendcyIterator = dependendcy.entrySet().iterator(); Iterator<Map.Entry<String, Object>> dependendcyIterator = dependendcy.entrySet().iterator();
Map<String, Object> modelTrain = (Map<String, Object>) trainInfo.get("model_train"); Map<String, Object> modelTrain = (Map<String, Object>) trainInfo.get("model_train");
Map<String, Object> modelEvaluate = (Map<String, Object>) trainInfo.get("model_evaluate"); Map<String, Object> modelEvaluate = (Map<String, Object>) trainInfo.get("model_evaluate");


+ 69
- 11
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java View File

@@ -6,6 +6,8 @@ import com.ruoyi.platform.utils.JacksonUtil;
import com.ruoyi.platform.utils.JsonUtils; import com.ruoyi.platform.utils.JsonUtils;
import com.ruoyi.platform.utils.NewHttpUtils; import com.ruoyi.platform.utils.NewHttpUtils;
import com.ruoyi.platform.vo.GitProjectVo; import com.ruoyi.platform.vo.GitProjectVo;
import com.ruoyi.system.api.constant.Constant;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@@ -43,7 +45,7 @@ public class GitServiceImpl implements GitService {
private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class);


@Override @Override
public String login(String ci4sUsername, String username, String password) {
public String login(String username, String password) {
// 构建请求参数 // 构建请求参数
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("grant_type", "password"); params.put("grant_type", "password");
@@ -71,8 +73,8 @@ public class GitServiceImpl implements GitService {
} }
// 将access_token存入Redis // 将access_token存入Redis
Jedis jedis = new Jedis(redisHost, redisPort); Jedis jedis = new Jedis(redisHost, redisPort);
jedis.set(ci4sUsername + "_gitToken", accessToken);
jedis.set(ci4sUsername + "_gitUserInfo", userReq);
jedis.set(username + "_gitToken", accessToken);
jedis.set(username + "_gitUserInfo", userReq);
return accessToken; return accessToken;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("gitlink用户信息出错"); throw new RuntimeException("gitlink用户信息出错");
@@ -84,23 +86,21 @@ public class GitServiceImpl implements GitService {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String token = jedis.get(ci4sUsername + "_gitToken"); String token = jedis.get(ci4sUsername + "_gitToken");
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String gitLinkPassword = loginUser.getSysUser().getOriginPassword();


if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
login(ci4sUsername, gitLinkUsername, gitLinkPassword);
login(ci4sUsername, gitLinkPassword);
token = jedis.get(ci4sUsername + "_gitToken"); token = jedis.get(ci4sUsername + "_gitToken");
} else { } else {
try { try {
Map userInfo = getUserInfo(token); Map userInfo = getUserInfo(token);
if (userInfo == null || (userInfo.get("status") != null && 401 == (Integer) userInfo.get("status"))) { if (userInfo == null || (userInfo.get("status") != null && 401 == (Integer) userInfo.get("status"))) {
login(ci4sUsername, gitLinkUsername, gitLinkPassword);
login(ci4sUsername, gitLinkPassword);
token = jedis.get(ci4sUsername + "_gitToken"); token = jedis.get(ci4sUsername + "_gitToken");
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

} }
return token; return token;
} }
@@ -149,7 +149,7 @@ public class GitServiceImpl implements GitService {


@Override @Override
public void deleteProject(String token, String owner, String projectName) throws Exception { public void deleteProject(String token, String owner, String projectName) throws Exception {
httpUtils.sendDeleteWithToken(gitendpoint + "/api/" + owner + "/" + projectName + ".json", null, token);
httpUtils.sendDeleteWithToken(gitendpoint + "/api/" + owner + "/" + projectName + ".json", null, token, null);
} }


@Override @Override
@@ -160,7 +160,7 @@ public class GitServiceImpl implements GitService {
} catch (IOException | GitAPIException e) { } catch (IOException | GitAPIException e) {
log.error("Exception occurred while creating local branch based on master", e); log.error("Exception occurred while creating local branch based on master", e);
} }
httpUtils.sendDeleteWithToken(gitendpoint + "/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", null, token);
httpUtils.sendDeleteWithToken(gitendpoint + "/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", null, token, null);
} }


@Override @Override
@@ -174,7 +174,7 @@ public class GitServiceImpl implements GitService {
} }


@Override @Override
public Map getProjectDetail(String owner, String identifier, String token) throws IOException {
public Map getProjectDetail(String owner, String identifier, String token) throws Exception {
String userReq = httpUtils.sendGetWithToken(gitendpoint + "/api/" + owner + "/" + identifier + "/detail.json", null, token); String userReq = httpUtils.sendGetWithToken(gitendpoint + "/api/" + owner + "/" + identifier + "/detail.json", null, token);
if (StringUtils.isEmpty(userReq)) { if (StringUtils.isEmpty(userReq)) {
return null; return null;
@@ -182,4 +182,62 @@ public class GitServiceImpl implements GitService {
Map<String, Object> runResMap = JsonUtils.jsonToMap(userReq); Map<String, Object> runResMap = JsonUtils.jsonToMap(userReq);
return runResMap; return runResMap;
} }

@Override
public void createUser(SysUser sysUser) throws Exception {
String token = checkoutToken();
Map<String, Object> resMap = new HashMap<>();
resMap.put("phone", sysUser.getPhonenumber());
resMap.put("email", sysUser.getEmail());
resMap.put("username", sysUser.getUserName());
resMap.put("password", sysUser.getPassword());
resMap.put("password_confirmation", sysUser.getPassword());
httpUtils.sendPostWithToken(gitendpoint + "/api/accounts/remote_register.json", null, token, JsonUtils.objectToJson(resMap));
}

@Override
public void resetPwd(SysUser sysUser) throws Exception {
String token = checkoutToken();
Map<String, Object> resMap = new HashMap<>();
resMap.put("login", sysUser.getUserName());
resMap.put("password", sysUser.getPassword());
resMap.put("new_password_repeat", sysUser.getPassword());
resMap.put("old_password", decrypt(sysUser.getOriginPassword()));
httpUtils.sendPostWithToken(gitendpoint + "/api/accounts/change_password.json", null, token, JsonUtils.objectToJson(resMap));
}

@Override
public void resetEmail(SysUser sysUser) throws Exception {
String token = login(sysUser.getUserName(), sysUser.getOriginPassword());
Map<String, Object> resMap = new HashMap<>();
resMap.put("email", sysUser.getEmail());
resMap.put("password", decrypt(sysUser.getOriginPassword()));
resMap.put("code", Constant.Code);
httpUtils.sendPatchWithToken(gitendpoint + "/api/v1/" + sysUser.getUserName() + "/update_email.json", null, token, JsonUtils.objectToJson(resMap));
}

@Override
public void resetPhoneNum(SysUser sysUser) throws Exception {
String token = login(sysUser.getUserName(), sysUser.getOriginPassword());
Map<String, Object> resMap = new HashMap<>();
resMap.put("phone", sysUser.getPhonenumber());
resMap.put("password", decrypt(sysUser.getOriginPassword()));
resMap.put("code", Constant.Code);
httpUtils.sendPatchWithToken(gitendpoint + "/api/v1/" + sysUser.getUserName() + "/update_phone.json", null, token, JsonUtils.objectToJson(resMap));
}

@Override
public void deleteUser(SysUser sysUser) throws Exception {
String token = login(sysUser.getUserName(), sysUser.getOriginPassword());
String result = httpUtils.sendPostWithToken(gitendpoint + "/api/v1/" + sysUser.getUserName() + "/check_user_can_delete.json", null, token, null);
Map<String, Object> resultMap = JsonUtils.jsonToMap(result);
if ((boolean) resultMap.get("can_delete")) {
Map<String, Object> resMap = new HashMap<>();
resMap.put("memo", "用户注销");
resMap.put("password", decrypt(sysUser.getOriginPassword()));
httpUtils.sendDeleteWithToken(gitendpoint + "/api/v1/" + sysUser.getUserName() + ".json", null, token, JsonUtils.objectToJson(resMap));
} else {
throw new Exception("用户不可删除:" + resultMap.get("message"));
}
}
} }

+ 12
- 14
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java View File

@@ -562,9 +562,9 @@ public class ModelsServiceImpl implements ModelsService {
String token = gitService.checkoutToken(); String token = gitService.checkoutToken();
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword);
String gitLinkUsername = loginUser.getSysUser().getUserName();
String gitLinkPassword = loginUser.getSysUser().getOriginPassword();
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkPassword);
String decryptGitLinkPassword = decrypt(gitLinkPassword); String decryptGitLinkPassword = decrypt(gitLinkPassword);
Integer userId = (Integer) userInfo.get("user_id"); Integer userId = (Integer) userInfo.get("user_id");


@@ -689,9 +689,9 @@ public class ModelsServiceImpl implements ModelsService {
public String newCreateVersion(ModelsVo modelsVo) throws Exception { public String newCreateVersion(ModelsVo modelsVo) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword);
String gitLinkUsername = loginUser.getSysUser().getUserName();
String gitLinkPassword = loginUser.getSysUser().getOriginPassword();
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkPassword);
gitLinkPassword = decrypt(gitLinkPassword); gitLinkPassword = decrypt(gitLinkPassword);


ci4sUsername = Boolean.TRUE.equals(modelsVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername(); ci4sUsername = Boolean.TRUE.equals(modelsVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername();
@@ -925,10 +925,9 @@ public class ModelsServiceImpl implements ModelsService {
public Page<ModelsVo> newPersonalQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception { public Page<ModelsVo> newPersonalQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String gitLinkPassword = loginUser.getSysUser().getOriginPassword();


Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword);
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkPassword);
String token = (String) userInfo.get("token"); String token = (String) userInfo.get("token");


//拼接查询url //拼接查询url
@@ -955,10 +954,9 @@ public class ModelsServiceImpl implements ModelsService {
public Page<ModelsVo> newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception { public Page<ModelsVo> newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();
String gitLinkPassword = loginUser.getSysUser().getOriginPassword();


Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword);
Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkPassword);
String token = (String) userInfo.get("token"); String token = (String) userInfo.get("token");


//拼接查询url //拼接查询url
@@ -1326,11 +1324,11 @@ public class ModelsServiceImpl implements ModelsService {
modelDependency1TreeVo.setChildModelList(childModelList); modelDependency1TreeVo.setChildModelList(childModelList);
} }


Map<String, Object> getUserInfo(String ci4sUsername, String gitLinkUsername, String gitLinkPassword) throws Exception {
Map<String, Object> getUserInfo(String ci4sUsername, String gitLinkPassword) throws Exception {
Jedis jedis = new Jedis(redisHost, redisPort); Jedis jedis = new Jedis(redisHost, redisPort);
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
if (userReq == null) { if (userReq == null) {
gitService.login(ci4sUsername, gitLinkUsername, gitLinkPassword);
gitService.login(ci4sUsername, gitLinkPassword);
userReq = jedis.get(ci4sUsername + "_gitUserInfo"); userReq = jedis.get(ci4sUsername + "_gitUserInfo");
} }
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq);


+ 5
- 5
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -94,8 +94,8 @@ public class NewDatasetServiceImpl implements NewDatasetService {
Jedis jedis = new Jedis(redisHost, redisPort); Jedis jedis = new Jedis(redisHost, redisPort);
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword());
String gitLinkUsername = loginUser.getSysUser().getUserName();
String gitLinkPassword = decrypt(loginUser.getSysUser().getOriginPassword());
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
// 得到用户操作的路径 // 得到用户操作的路径
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq);
@@ -201,8 +201,8 @@ public class NewDatasetServiceImpl implements NewDatasetService {
Jedis jedis = new Jedis(redisHost, redisPort); Jedis jedis = new Jedis(redisHost, redisPort);
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
String ci4sUsername = loginUser.getUsername(); String ci4sUsername = loginUser.getUsername();
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = decrypt(loginUser.getSysUser().getGitLinkPassword());
String gitLinkUsername = loginUser.getSysUser().getUserName();
String gitLinkPassword = decrypt(loginUser.getSysUser().getOriginPassword());
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); String userReq = jedis.get(ci4sUsername + "_gitUserInfo");
ci4sUsername = Boolean.TRUE.equals(datasetVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername(); ci4sUsername = Boolean.TRUE.equals(datasetVo.getIsPublic()) ? Constant.Item_Public : loginUser.getUsername();
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq);
@@ -337,7 +337,7 @@ public class NewDatasetServiceImpl implements NewDatasetService {
} }


@Override @Override
public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) {
public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception {
String token = gitService.checkoutToken(); String token = gitService.checkoutToken();
// 拼接查询url // 拼接查询url
String url = gitendpoint + "/api/projects.json?sort_direction=updated_on&sort_by=desc&category_id=" + Constant.Git_Category_Id; String url = gitendpoint + "/api/projects.json?sort_direction=updated_on&sort_by=desc&category_id=" + Constant.Git_Category_Id;


+ 20
- 7
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/NewHttpUtils.java View File

@@ -1,4 +1,5 @@
package com.ruoyi.platform.utils; package com.ruoyi.platform.utils;

import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.methods.*; import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIBuilder;
@@ -20,6 +21,7 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map;


@Component @Component
public class NewHttpUtils { public class NewHttpUtils {
@@ -61,27 +63,31 @@ public class NewHttpUtils {
} }
} }


public static String sendGet(String url, String param) {
public static String sendGet(String url, String param) throws Exception {
return sendRequest(new HttpGet(), url, param, null, null); return sendRequest(new HttpGet(), url, param, null, null);
} }


public static String sendPost(String url, String param, String body) {
public static String sendPost(String url, String param, String body) throws Exception {
return sendRequest(new HttpPost(), url, param, null, body); return sendRequest(new HttpPost(), url, param, null, body);
} }


public static String sendGetWithToken(String url, String param, String token) {
public static String sendGetWithToken(String url, String param, String token) throws Exception {
return sendRequest(new HttpGet(), url, param, token, null); return sendRequest(new HttpGet(), url, param, token, null);
} }


public static String sendPostWithToken(String url, String param, String token, String body) {
public static String sendPostWithToken(String url, String param, String token, String body) throws Exception {
return sendRequest(new HttpPost(), url, param, token, body); return sendRequest(new HttpPost(), url, param, token, body);
} }


public static String sendDeleteWithToken(String url, String param, String token) {
return sendRequest(new HttpDelete(), url, param, token, null);
public static String sendDeleteWithToken(String url, String param, String token, String body) throws Exception {
return sendRequest(new HttpDelete(), url, param, token, body);
}

public static String sendPatchWithToken(String url, String param, String token, String body) throws Exception {
return sendRequest(new HttpPatch(), url, param, token, body);
} }


private static String sendRequest(HttpRequestBase request, String url, String param, String token, String body) {
private static String sendRequest(HttpRequestBase request, String url, String param, String token, String body) throws Exception {
if (httpClient == null) { if (httpClient == null) {
throw new IllegalStateException("HttpClient is not initialized"); throw new IllegalStateException("HttpClient is not initialized");
} }
@@ -121,11 +127,18 @@ public class NewHttpUtils {
throw new IOException("HTTP request failed with response code: " + statusCode); throw new IOException("HTTP request failed with response code: " + statusCode);
} }
log.info("Response: " + result); log.info("Response: " + result);
Map<String, Object> resultMap = JsonUtils.jsonToMap(result);
Integer status = (Integer) resultMap.get("status");
if (status != null && status != 0) {
throw new Exception((String) resultMap.get("message"));
}
} }
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
log.error("URISyntaxException, url=" + url + ", param=" + param, e); log.error("URISyntaxException, url=" + url + ", param=" + param, e);
throw e;
} catch (IOException e) { } catch (IOException e) {
log.error("IOException, url=" + url + ", param=" + param, e); log.error("IOException, url=" + url + ", param=" + param, e);
throw e;
} }
return result; return result;
} }


+ 13
- 21
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java View File

@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;


import static com.ruoyi.common.security.utils.SecurityUtils.*;
import static com.ruoyi.common.security.utils.SecurityUtils.encrypt;


/** /**
* 用户信息 * 用户信息
@@ -74,7 +74,7 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.EXPORT) @Log(title = "用户管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:user:export") @RequiresPermissions("system:user:export")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, SysUser user) {
public void export(HttpServletResponse response, @RequestBody SysUser user) {
List<SysUser> list = userService.selectUserList(user); List<SysUser> list = userService.selectUserList(user);
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
util.exportExcel(response, list, "用户数据"); util.exportExcel(response, list, "用户数据");
@@ -146,7 +146,8 @@ public class SysUserController extends BaseController {
Set<String> roles = permissionService.getRolePermission(user); Set<String> roles = permissionService.getRolePermission(user);
// 权限集合 // 权限集合
Set<String> permissions = permissionService.getMenuPermission(user); Set<String> permissions = permissionService.getMenuPermission(user);
remoteMmpService.gitLinkLogin(user.getUserName(), user.getGitLinkUsername(),user.getGitLinkPassword());
String originPwd = userService.getOriginPwd(user.getUserName());
remoteMmpService.gitLinkLogin(user.getUserName(), originPwd);
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("user", user); ajax.put("user", user);
ajax.put("roles", roles); ajax.put("roles", roles);
@@ -181,19 +182,15 @@ public class SysUserController extends BaseController {
@RequiresPermissions("system:user:add") @RequiresPermissions("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.INSERT) @Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user) {
public AjaxResult add(@Validated @RequestBody SysUser user) throws Exception {
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在");
} }
user.setCreateBy(SecurityUtils.getUsername()); user.setCreateBy(SecurityUtils.getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
user.setGitLinkPassword(encrypt(user.getGitLinkPassword()));
return toAjax(userService.insertUser(user)); return toAjax(userService.insertUser(user));
} }


@@ -203,7 +200,7 @@ public class SysUserController extends BaseController {
@RequiresPermissions("system:user:edit") @RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody SysUser user) {
public AjaxResult edit(@Validated @RequestBody SysUser user) throws Exception {
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
@@ -212,16 +209,8 @@ public class SysUserController extends BaseController {
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} else if (StringUtils.isNotEmpty(user.getGitLinkUsername()) && !userService.checktGitLinkUsernameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,gitLink用户名已存在");
} }
user.setUpdateBy(SecurityUtils.getUsername()); user.setUpdateBy(SecurityUtils.getUsername());
if (StringUtils.isNotEmpty(user.getPassword())) {
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
}
if (StringUtils.isNotEmpty(user.getGitLinkPassword())) {
user.setGitLinkPassword(encrypt(user.getGitLinkPassword()));
}
return toAjax(userService.updateUser(user)); return toAjax(userService.updateUser(user));
} }


@@ -231,7 +220,7 @@ public class SysUserController extends BaseController {
@RequiresPermissions("system:user:remove") @RequiresPermissions("system:user:remove")
@Log(title = "用户管理", businessType = BusinessType.DELETE) @Log(title = "用户管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{userIds}") @DeleteMapping("/{userIds}")
public AjaxResult remove(@PathVariable Long[] userIds) {
public AjaxResult remove(@PathVariable Long[] userIds) throws Exception {
if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) { if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) {
return error("当前用户不能删除"); return error("当前用户不能删除");
} }
@@ -244,11 +233,9 @@ public class SysUserController extends BaseController {
@RequiresPermissions("system:user:edit") @RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd") @PutMapping("/resetPwd")
public AjaxResult resetPwd(@RequestBody SysUser user) {
public AjaxResult resetPwd(@RequestBody SysUser user) throws Exception {
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.resetPwd(user)); return toAjax(userService.resetPwd(user));
} }


@@ -299,4 +286,9 @@ public class SysUserController extends BaseController {
public AjaxResult deptTree(SysDept dept) { public AjaxResult deptTree(SysDept dept) {
return success(deptService.selectDeptTreeList(dept)); return success(deptService.selectDeptTreeList(dept));
} }

@GetMapping("/getOriginPwd")
public R<String> getOriginPwd(@RequestParam(value = "username") String username) {
return R.ok(userService.getOriginPwd(username));
}
} }

+ 1
- 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java View File

@@ -125,5 +125,5 @@ public interface SysUserMapper
*/ */
public SysUser checkEmailUnique(String email); public SysUser checkEmailUnique(String email);


public SysUser checktGitLinkUsernameUnique(String gitLinkUsername);
String getOriginPwd(Long userId);
} }

+ 6
- 5
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java View File

@@ -90,7 +90,6 @@ public interface ISysUserService
*/ */
public boolean checkEmailUnique(SysUser user); public boolean checkEmailUnique(SysUser user);


public boolean checktGitLinkUsernameUnique(SysUser user);


/** /**
* 校验用户是否允许操作 * 校验用户是否允许操作
@@ -112,7 +111,7 @@ public interface ISysUserService
* @param user 用户信息 * @param user 用户信息
* @return 结果 * @return 结果
*/ */
public int insertUser(SysUser user);
public int insertUser(SysUser user) throws Exception;


/** /**
* 注册用户信息 * 注册用户信息
@@ -128,7 +127,7 @@ public interface ISysUserService
* @param user 用户信息 * @param user 用户信息
* @return 结果 * @return 结果
*/ */
public int updateUser(SysUser user);
public int updateUser(SysUser user) throws Exception;


/** /**
* 用户授权角色 * 用户授权角色
@@ -169,7 +168,7 @@ public interface ISysUserService
* @param user 用户信息 * @param user 用户信息
* @return 结果 * @return 结果
*/ */
public int resetPwd(SysUser user);
public int resetPwd(SysUser user) throws Exception;


/** /**
* 重置用户密码 * 重置用户密码
@@ -194,7 +193,7 @@ public interface ISysUserService
* @param userIds 需要删除的用户ID * @param userIds 需要删除的用户ID
* @return 结果 * @return 结果
*/ */
public int deleteUserByIds(Long[] userIds);
public int deleteUserByIds(Long[] userIds) throws Exception;


/** /**
* 导入用户数据 * 导入用户数据
@@ -205,4 +204,6 @@ public interface ISysUserService
* @return 结果 * @return 结果
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);

String getOriginPwd(String username);
} }

+ 80
- 34
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java View File

@@ -5,9 +5,11 @@ import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanValidators; import com.ruoyi.common.core.utils.bean.BeanValidators;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.RemoteAuthService; import com.ruoyi.system.api.RemoteAuthService;
import com.ruoyi.system.api.RemoteMmpService;
import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.constant.Constant;
import com.ruoyi.system.api.domain.SysRole; import com.ruoyi.system.api.domain.SysRole;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
@@ -29,6 +31,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;


import static com.ruoyi.common.security.utils.SecurityUtils.decrypt;
import static com.ruoyi.common.security.utils.SecurityUtils.encrypt;

/** /**
* 用户 业务层处理 * 用户 业务层处理
* *
@@ -62,6 +67,9 @@ public class SysUserServiceImpl implements ISysUserService {
@Autowired @Autowired
protected RemoteAuthService remoteAuthService; protected RemoteAuthService remoteAuthService;


@Autowired
protected RemoteMmpService remoteMmpService;

/** /**
* 根据条件分页查询用户列表 * 根据条件分页查询用户列表
* *
@@ -198,16 +206,6 @@ public class SysUserServiceImpl implements ISysUserService {
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
} }


@Override
public boolean checktGitLinkUsernameUnique(SysUser user) {
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
SysUser info = userMapper.checktGitLinkUsernameUnique(user.getGitLinkUsername());
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}

/** /**
* 校验用户是否允许操作 * 校验用户是否允许操作
* *
@@ -245,22 +243,29 @@ public class SysUserServiceImpl implements ISysUserService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user) {
// 新增用户信息
int rows = userMapper.insertUser(user);
// 新增用户岗位关联
insertUserPost(user);
// 新增用户与角色管理
insertUserRole(user);
public int insertUser(SysUser user) throws Exception {


// 新增gitlink用户
GenericsAjaxResult<String> gitLinkResult = remoteMmpService.createGitLinkUser(user);
if (gitLinkResult.getCode() != 200) {
throw new Exception(gitLinkResult.getMsg());
}

user.setOriginPassword(encrypt(user.getPassword()));
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
// 新增oauth2用户 // 新增oauth2用户
remoteAuthService.add(user); remoteAuthService.add(user);


// todo 新增gitlink用户
// todo 新增火石平台用户


// todo 新增label studio用户
// 新增用户信息
int rows = userMapper.insertUser(user);


// todo 新增火石平台用户
// 新增用户岗位关联
insertUserPost(user);

// 新增用户与角色管理
insertUserRole(user);


return rows; return rows;
} }
@@ -284,8 +289,10 @@ public class SysUserServiceImpl implements ISysUserService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int updateUser(SysUser user) {
public int updateUser(SysUser user) throws Exception {
Long userId = user.getUserId(); Long userId = user.getUserId();
SysUser oldUser = userMapper.selectUserById(userId);

// 删除用户与角色关联 // 删除用户与角色关联
userRoleMapper.deleteUserRoleByUserId(userId); userRoleMapper.deleteUserRoleByUserId(userId);
// 新增用户与角色管理 // 新增用户与角色管理
@@ -295,12 +302,35 @@ public class SysUserServiceImpl implements ISysUserService {
// 新增用户与岗位管理 // 新增用户与岗位管理
insertUserPost(user); insertUserPost(user);


// 更新oauth2用户
remoteAuthService.edit(user);
// 更新gitlink用户
if (!oldUser.getEmail().equals(user.getEmail())) {
GenericsAjaxResult<String> result = remoteMmpService.resetEmail(user);
if (result.getCode() != 200) {
throw new Exception(result.getMsg());
}
}

if (!oldUser.getPhonenumber().equals(user.getPhonenumber())) {
GenericsAjaxResult<String> result = remoteMmpService.resetPhoneNum(user);
if (result.getCode() != 200) {
throw new Exception(result.getMsg());
}
}

if (StringUtils.isNotEmpty(user.getPassword()) && !decrypt(oldUser.getOriginPassword()).equals(user.getPassword())) {
GenericsAjaxResult<String> result = remoteMmpService.resetPwd(user);
if (result.getCode() != 200) {
throw new Exception(result.getMsg());
}
}


// todo 更新gitlink用户
if (StringUtils.isNotEmpty(user.getPassword())) {
user.setOriginPassword(encrypt(user.getPassword()));
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
}


// todo 更新label studio用户
// 更新oauth2用户
remoteAuthService.edit(user);


// todo 更新火石平台用户 // todo 更新火石平台用户


@@ -361,13 +391,20 @@ public class SysUserServiceImpl implements ISysUserService {
* @return 结果 * @return 结果
*/ */
@Override @Override
public int resetPwd(SysUser user) {
// 更新oauth2用户
remoteAuthService.edit(user);

// todo 更新gitlink用户
public int resetPwd(SysUser user) throws Exception {
SysUser sysUser = userMapper.selectUserById(user.getUserId());
user.setUserName(sysUser.getUserName());
// 更新gitlink用户密码
GenericsAjaxResult<String> gitLinkResult = remoteMmpService.resetPwd(user);
if (gitLinkResult.getCode() != 200) {
throw new Exception(gitLinkResult.getMsg());
}


// todo 更新label studio用户
user.setOriginPassword(encrypt(user.getPassword()));
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
user.setUpdateBy(SecurityUtils.getUsername());
// 更新oauth2用户密码
remoteAuthService.edit(user);


// todo 更新火石平台用户 // todo 更新火石平台用户


@@ -459,7 +496,7 @@ public class SysUserServiceImpl implements ISysUserService {
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds) {
public int deleteUserByIds(Long[] userIds) throws Exception {
for (Long userId : userIds) { for (Long userId : userIds) {
checkUserAllowed(new SysUser(userId)); checkUserAllowed(new SysUser(userId));
checkUserDataScope(userId); checkUserDataScope(userId);
@@ -471,13 +508,16 @@ public class SysUserServiceImpl implements ISysUserService {


for (Long userId : userIds) { for (Long userId : userIds) {
SysUser user = userMapper.selectUserById(userId); SysUser user = userMapper.selectUserById(userId);
user.setOriginPassword(userMapper.getOriginPwd(userId));
user.setDelFlag(Constant.DelFlag); user.setDelFlag(Constant.DelFlag);
// 删除oauth2用户 // 删除oauth2用户
remoteAuthService.edit(user); remoteAuthService.edit(user);


// todo 删除gitlink用户 // todo 删除gitlink用户

// todo 删除label studio用户
GenericsAjaxResult<String> gitLinkResult = remoteMmpService.deleteGitLinkUser(user);
if (gitLinkResult.getCode() != 200) {
throw new Exception(gitLinkResult.getMsg());
}


// todo 删除火石平台用户 // todo 删除火石平台用户
} }
@@ -542,4 +582,10 @@ public class SysUserServiceImpl implements ISysUserService {
} }
return successMsg.toString(); return successMsg.toString();
} }

@Override
public String getOriginPwd(String username) {
SysUser sysUser = userMapper.selectUserByUserName(username);
return userMapper.getOriginPwd(sysUser.getUserId());
}
} }

+ 11
- 14
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml View File

@@ -14,6 +14,7 @@
<result property="sex" column="sex"/> <result property="sex" column="sex"/>
<result property="avatar" column="avatar"/> <result property="avatar" column="avatar"/>
<result property="password" column="password"/> <result property="password" column="password"/>
<result property="originPassword" column="origin_password"/>
<result property="status" column="status"/> <result property="status" column="status"/>
<result property="delFlag" column="del_flag"/> <result property="delFlag" column="del_flag"/>
<result property="loginIp" column="login_ip"/> <result property="loginIp" column="login_ip"/>
@@ -23,7 +24,6 @@
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/> <result property="remark" column="remark"/>
<result property="gitLinkUsername" column="git_link_username"/>
<result property="gitLinkPassword" column="git_link_password"/> <result property="gitLinkPassword" column="git_link_password"/>
<result property="credit" column="credit"/> <result property="credit" column="credit"/>
<association property="dept" javaType="SysDept" resultMap="deptResult"/> <association property="dept" javaType="SysDept" resultMap="deptResult"/>
@@ -58,9 +58,8 @@
u.avatar, u.avatar,
u.phonenumber, u.phonenumber,
u.password, u.password,
u.git_link_username,
u.git_link_password,
TRUNCATE(u.credit, 1) as credit,
u.origin_password,
ROUND(u.credit, 1) as credit,
u.sex, u.sex,
u.status, u.status,
u.del_flag, u.del_flag,
@@ -90,7 +89,7 @@


<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status,
u.git_link_username, TRUNCATE(u.credit, 1) as credit,
ROUND(u.credit, 1) as credit,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@@ -125,7 +124,7 @@
</select> </select>


<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, TRUNCATE(u.credit, 1) as credit, u.git_link_username
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, ROUND(u.credit, 1) as credit
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
@@ -142,7 +141,7 @@
</select> </select>


<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time , TRUNCATE(u.credit, 1) as credit, u.git_link_username
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time , ROUND(u.credit, 1) as credit
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
@@ -191,11 +190,8 @@
and del_flag = '0' limit 1 and del_flag = '0' limit 1
</select> </select>


<select id="checktGitLinkUsernameUnique" resultType="com.ruoyi.system.api.domain.SysUser">
select user_id, git_link_username
from sys_user
where git_link_username = #{gitLinkUsername}
and del_flag = '0' limit 1
<select id="getOriginPwd" resultType="java.lang.String">
select origin_password from sys_user where user_id = #{userId}
</select> </select>


<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
@@ -209,10 +205,10 @@
<if test="phonenumber != null and phonenumber != ''">phonenumber,</if> <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
<if test="sex != null and sex != ''">sex,</if> <if test="sex != null and sex != ''">sex,</if>
<if test="password != null and password != ''">password,</if> <if test="password != null and password != ''">password,</if>
<if test="originPassword != null and originPassword != ''">origin_password,</if>
<if test="status != null and status != ''">status,</if> <if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if> <if test="remark != null and remark != ''">remark,</if>
<if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username,</if>
<if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if> <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if>
<if test="credit != null">credit,</if> <if test="credit != null">credit,</if>
create_time create_time
@@ -226,6 +222,7 @@
<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if> <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
<if test="sex != null and sex != ''">#{sex},</if> <if test="sex != null and sex != ''">#{sex},</if>
<if test="password != null and password != ''">#{password},</if> <if test="password != null and password != ''">#{password},</if>
<if test="originPassword != null and originPassword != ''">#{originPassword},</if>
<if test="status != null and status != ''">#{status},</if> <if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="remark != null and remark != ''">#{remark},</if>
@@ -247,12 +244,12 @@
<if test="sex != null and sex != ''">sex = #{sex},</if> <if test="sex != null and sex != ''">sex = #{sex},</if>
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if> <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
<if test="password != null and password != ''">password = #{password},</if> <if test="password != null and password != ''">password = #{password},</if>
<if test="originPassword != null and originPassword != ''">origin_password = #{originPassword},</if>
<if test="status != null and status != ''">status = #{status},</if> <if test="status != null and status != ''">status = #{status},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if> <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if> <if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username = #{gitLinkUsername},</if>
<if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if>
<if test="credit != null">credit = #{credit},</if> <if test="credit != null">credit = #{credit},</if>
update_time = sysdate() update_time = sysdate()


Loading…
Cancel
Save