diff --git a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/RemoteIntegrationService.java b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/RemoteIntegrationService.java new file mode 100644 index 0000000..ece0c0f --- /dev/null +++ b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/RemoteIntegrationService.java @@ -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); +} diff --git a/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/factory/RemoteIntegrationFallbackFactory.java b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/factory/RemoteIntegrationFallbackFactory.java new file mode 100644 index 0000000..83f7716 --- /dev/null +++ b/hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/factory/RemoteIntegrationFallbackFactory.java @@ -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 +{ + 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()); + } + }; + } +} diff --git a/hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 1e2636c..7aabbdf 100644 --- a/hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/hxhq-api/hxhq-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -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 \ No newline at end of file diff --git a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java index 1385688..130746c 100644 --- a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java +++ b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/constant/ServiceNameConstants.java @@ -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"; } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java index b1bb646..d8bab4d 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java @@ -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());