Browse Source

feat: [用户管理] 增加对接测试代码

master
memorylkf 1 month ago
parent
commit
5fb196daa7
5 changed files with 96 additions and 0 deletions
  1. +35
    -0
      hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/RemoteIntegrationService.java
  2. +41
    -0
      hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/factory/RemoteIntegrationFallbackFactory.java
  3. +1
    -0
      hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  4. +5
    -0
      hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java
  5. +14
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java

+ 35
- 0
hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/RemoteIntegrationService.java View File

@ -0,0 +1,35 @@
package com.hxhq.system.api;
import com.hxhq.common.core.constant.ServiceNameConstants;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.system.api.factory.RemoteIntegrationFallbackFactory;
import com.hxhq.system.api.factory.RemoteUserFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* 对接服务
*
* @author hxhq
*/
@FeignClient(contextId = "remoteIntegrationService", value = ServiceNameConstants.FILE_INTEGRATION, fallbackFactory = RemoteIntegrationFallbackFactory.class)
public interface RemoteIntegrationService
{
/**
* AD账号密码鉴权
* @param username
* @param password
* @return
*/
@PostMapping("/ad/validate")
AjaxResult validate(@RequestParam("username") String username,
@RequestParam("password") String password);
/**
* 验证AD账号是否存在
* @param username
* @return
*/
@GetMapping("/ad/exists")
AjaxResult checkAccountExists(@RequestParam("username") String username);
}

+ 41
- 0
hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/factory/RemoteIntegrationFallbackFactory.java View File

@ -0,0 +1,41 @@
package com.hxhq.system.api.factory;
import com.hxhq.common.core.domain.R;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.system.api.RemoteIntegrationService;
import com.hxhq.system.api.RemoteUserService;
import com.hxhq.system.api.domain.SysUser;
import com.hxhq.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 用户服务降级处理
*
* @author hxhq
*/
@Component
public class RemoteIntegrationFallbackFactory implements FallbackFactory<RemoteIntegrationService>
{
private static final Logger log = LoggerFactory.getLogger(RemoteIntegrationFallbackFactory.class);
@Override
public RemoteIntegrationService create(Throwable throwable)
{
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteIntegrationService()
{
@Override
public AjaxResult validate(String username, String password) {
return AjaxResult.error("验证用户用户名密码失败"+ throwable.getMessage());
}
@Override
public AjaxResult checkAccountExists(String username) {
return AjaxResult.error("检查用户失败"+ throwable.getMessage());
}
};
}
}

+ 1
- 0
hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports View File

@ -1,3 +1,4 @@
com.hxhq.system.api.factory.RemoteUserFallbackFactory
com.hxhq.system.api.factory.RemoteLogFallbackFactory
com.hxhq.system.api.factory.RemoteFileFallbackFactory
com.hxhq.system.api.factory.RemoteIntegrationFallbackFactory

+ 5
- 0
hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java View File

@ -21,4 +21,9 @@ public class ServiceNameConstants
* 文件服务的serviceid
*/
public static final String FILE_SERVICE = "hxhq-file";
/**
* 对接服务的serviceid
*/
public static final String FILE_INTEGRATION = "hxhq-integration";
}

+ 14
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java View File

@ -16,6 +16,8 @@ import com.hxhq.business.form.common.SignForm;
import com.hxhq.business.service.IStudyService;
import com.hxhq.common.core.exception.ServiceException;
import com.hxhq.common.core.utils.ServletUtils;
import com.hxhq.system.api.RemoteIntegrationService;
import com.hxhq.system.api.RemoteUserService;
import com.hxhq.system.dto.UserExportDto;
import com.hxhq.system.form.UserSaveForm;
import com.hxhq.system.service.*;
@ -84,6 +86,9 @@ public class SysUserController extends BaseController
@Autowired
private ISysMenuService sysMenuService;
@Autowired
private RemoteIntegrationService remoteIntegrationService;
/**
* 获取用户列表
*/
@ -291,6 +296,12 @@ public class SysUserController extends BaseController
return ajax;
}
@GetMapping("/checkExist")
public AjaxResult checkExist(@PathVariable("username") String username){
AjaxResult exists = remoteIntegrationService.checkAccountExists(username);
return exists;
}
/**
* 新增用户
*/
@ -299,6 +310,9 @@ public class SysUserController extends BaseController
@PostMapping
public AjaxResult add(@Validated @RequestBody UserSaveForm form)
{
// AjaxResult exists = remoteIntegrationService.checkAccountExists(form.getUser().getUserName());
// AjaxResult exists = remoteIntegrationService.validate(form.getUser().getUserName(),form.getUser().getPassword());
// return exists;
SysUser user = form.getUser();
deptService.checkDeptDataScope(user.getDeptId());
roleService.checkRoleDataScope(user.getRoleIds());

Loading…
Cancel
Save