diff --git a/pom.xml b/pom.xml index e9540c896..506d1c624 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ true true - 3.2.5 + 3.3.0 2023.0.1 3.0.3 3.5.6 @@ -151,13 +151,12 @@ 4.10.0 32.1.3-jre 8.3.8 - 0.0.4 + 0.0.9 1.0.13 1.0.2 3.3.4 3.1.3 - 2.6.21 - 1.0.3-M1 + 1.1.0-M1 3.21.5 4.1.82.Final 1.18.1 @@ -509,6 +508,11 @@ carp-module-system ${carp.version} + + cn.sliew + carp-module-datasource + ${carp.version} + cn.sliew milky-common diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java deleted file mode 100644 index 4423b648c..000000000 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.api.controller.admin; - -import cn.hutool.core.lang.tree.Tree; -import cn.hutool.core.lang.tree.TreeNodeConfig; -import cn.hutool.core.lang.tree.TreeUtil; -import cn.sliew.scaleph.api.annotation.Logging; -import cn.sliew.scaleph.common.dict.security.ResourceType; -import cn.sliew.scaleph.security.service.SecResourceWebService; -import cn.sliew.scaleph.security.service.dto.SecResourceWebDTO; -import cn.sliew.scaleph.security.service.param.SecResourceWebAddParam; -import cn.sliew.scaleph.security.service.param.SecResourceWebListParam; -import cn.sliew.scaleph.security.service.param.SecResourceWebUpdateParam; -import cn.sliew.scaleph.system.model.ResponseVO; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -//@RestController -@RequestMapping("/api/admin/resource/web") -@Tag(name = "系统管理-资源管理-Web") -public class SecResourceWebController { - - @Autowired - private SecResourceWebService secResourceWebService; - - @Logging - @GetMapping("list") - @Operation(summary = "分页查询 Web 资源树", description = "分页查询 Web 资源树") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).ROLE_GRANT)") - public ResponseEntity> listByPage(@Valid SecResourceWebListParam param) { - Page resourceWebDTOPage = secResourceWebService.listByPage(param); - return new ResponseEntity<>(resourceWebDTOPage, HttpStatus.OK); - } - - @Logging - @GetMapping - @Operation(summary = "查询 Web 资源树", description = "查询 Web 资源树") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).ROLE_GRANT)") - public ResponseEntity>> listAllPrivilege(@RequestParam("resourceType") ResourceType resourceType) { - List secResourceWebDTOS = secResourceWebService.listAll(resourceType); - TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); - treeNodeConfig.setIdKey("id"); - treeNodeConfig.setParentIdKey("pid"); - treeNodeConfig.setNameKey("name"); - treeNodeConfig.setWeightKey("path"); - List> treeList = - TreeUtil.build(secResourceWebDTOS, 0L, treeNodeConfig, (treeNode, tree) -> { - tree.setId(treeNode.getId()); - tree.setParentId(treeNode.getPid()); - tree.setName(treeNode.getName()); - tree.setWeight(treeNode.getPath()); - }); - - return new ResponseEntity<>(treeList, HttpStatus.OK); - } - - @Logging - @GetMapping("list/{pid}") - @Operation(summary = "查询 Web 资源树", description = "查询 Web 资源树") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).ROLE_GRANT)") - public ResponseEntity>> listByPid(@PathVariable("pid") Long pid) { - List secResourceWebDTOS = secResourceWebService.listByPid(pid, null); - return new ResponseEntity<>(ResponseVO.success(secResourceWebDTOS), HttpStatus.OK); - } - - @Logging - @PutMapping - @Operation(summary = "新增 Web 资源", description = "新增 Web 资源") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).STDATA_SYSTEM_ADD)") - public ResponseEntity add(@Validated @RequestBody SecResourceWebAddParam param) { - secResourceWebService.insert(param); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.CREATED); - } - - @Logging - @PostMapping - @Operation(summary = "修改 Web 资源", description = "修改 Web 资源") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).STDATA_SYSTEM_EDIT)") - public ResponseEntity editMetaSystem(@Validated @RequestBody SecResourceWebUpdateParam param) { - secResourceWebService.update(param); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @DeleteMapping(path = "/{id}") - @Operation(summary = "删除 Web 资源", description = "删除 Web 资源") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).STDATA_SYSTEM_DELETE)") - public ResponseEntity deleteMetaSystem(@PathVariable("id") Long id) { - secResourceWebService.deleteById(id); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @DeleteMapping(path = "/batch") - @Operation(summary = "批量删除 Web 资源", description = "批量删除 Web 资源") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).STDATA_SYSTEM_DELETE)") - public ResponseEntity deleteMetaSystem(@RequestBody List ids) { - secResourceWebService.deleteBatch(ids); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - -} diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java deleted file mode 100644 index 4f935e3c7..000000000 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.api.controller.admin; - -import cn.hutool.json.JSONUtil; -import cn.sliew.scaleph.api.annotation.Logging; -import cn.sliew.scaleph.dao.DataSourceConstants; -import cn.sliew.scaleph.security.service.SecDeptRoleService; -import cn.sliew.scaleph.security.service.SecRoleService; -import cn.sliew.scaleph.security.service.SecUserRoleService; -import cn.sliew.scaleph.security.service.SecUserService; -import cn.sliew.scaleph.security.service.dto.SecDeptRoleDTO; -import cn.sliew.scaleph.security.service.dto.SecRoleDTO; -import cn.sliew.scaleph.security.service.dto.SecUserDTO; -import cn.sliew.scaleph.security.service.dto.SecUserRoleDTO; -import cn.sliew.scaleph.security.service.param.SecRoleAddParam; -import cn.sliew.scaleph.security.service.param.SecRoleListParam; -import cn.sliew.scaleph.security.service.param.SecRoleUpdateParam; -import cn.sliew.scaleph.security.web.OnlineUserService; -import cn.sliew.scaleph.system.model.ResponseVO; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - *

- * 角色表 前端控制器 - *

- * - * @author liyu - */ -//@RestController -@RequestMapping("/api/admin/role") -@Tag(name = "系统管理-角色管理") -public class SecRoleController { - - @Autowired - private SecRoleService secRoleService; - @Autowired - private SecUserRoleService secUserRoleService; - @Autowired - private SecDeptRoleService secDeptRoleService; - @Autowired - private OnlineUserService onlineUserService; - @Autowired - private SecUserService secUserService; - - @Logging - @GetMapping("list") - @Operation(summary = "查询角色列表", description = "查询全部角色信息") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PagePrivilege).ADMIN_ROLE_SHOW)") - public ResponseEntity> listByPage(@Validated SecRoleListParam param) { - Page result = this.secRoleService.listByPage(param); - return new ResponseEntity<>(result, HttpStatus.OK); - } - - @Logging - @GetMapping - @Operation(summary = "查询角色列表", description = "查询全部角色信息") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PagePrivilege).ADMIN_ROLE_SHOW)") - public ResponseEntity> listAll() { - List list = this.secRoleService.listAll(); - return new ResponseEntity<>(list, HttpStatus.OK); - } - - @Logging - @PostMapping - @Operation(summary = "新增角色", description = "新增角色") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_ROLE_ADD)") - public ResponseEntity addRole(@Validated @RequestBody SecRoleAddParam param) { - this.secRoleService.insert(param); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.CREATED); - } - - @Logging - @PutMapping - @Operation(summary = "修改角色", description = "修改角色") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_ROLE_EDIT)") - public ResponseEntity editRole(@Validated @RequestBody SecRoleUpdateParam param) { - this.secRoleService.update(param); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.CREATED); - } - - @Logging - @DeleteMapping("/{id}") - @Operation(summary = "删除角色", description = "删除角色") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_ROLE_DELETE)") - public ResponseEntity deleteRole(@PathVariable("id") Long id) { - this.secRoleService.deleteById(id); - this.onlineUserService.disableOnlineCacheRole(id); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @DeleteMapping("/batch") - @Operation(summary = "批量删除角色", description = "批量删除角色") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_ROLE_DELETE)") - public ResponseEntity deleteBatch(@RequestBody List ids) { - secRoleService.deleteBatch(ids); - for (Long id : ids) { - this.onlineUserService.disableOnlineCacheRole(id); - } - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @PostMapping(path = "/grant") - @Operation(summary = "用户授权角色", description = "用户授权角色") - @Transactional(rollbackFor = Exception.class, transactionManager = DataSourceConstants.MASTER_TRANSACTION_MANAGER_FACTORY) - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_ROLE_AUTHORIZE)") - public ResponseEntity grantRole(@RequestParam("roleId") Long roleId, @RequestParam("roleId") String userIds) { - List userList = JSONUtil.toList(userIds, Long.class); - List oldUserList = this.secUserRoleService.listByRoleId(roleId); - List tmpList = new ArrayList<>(userList.size()); - tmpList.addAll(userList); - //grant new user - tmpList.removeAll( - oldUserList.stream().map(SecUserRoleDTO::getUserId).collect(Collectors.toList())); - for (Long userId : tmpList) { - SecUserRoleDTO userRole = new SecUserRoleDTO(); - userRole.setRoleId(roleId); - userRole.setUserId(userId); - this.secUserRoleService.insert(userRole); - } - //revoke removed user - for (SecUserRoleDTO userRole : oldUserList) { - if (!userList.contains(userRole.getUserId())) { - this.secUserRoleService.delete(userRole); - } - } - userList.forEach(d -> { - SecUserDTO user = this.secUserService.selectOne(d); - this.onlineUserService.disableOnlineCacheUser(user.getUserName()); - }); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @GetMapping("/dept") - @Operation(summary = "查询部门对应角色列表", description = "查询部门对应角色列表") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_DEPT_SELECT)") - public ResponseEntity> listRoleByDept(String grant, @RequestParam("deptId") Long deptId) { - List list = this.secRoleService.selectRoleByDept(grant, deptId); - return new ResponseEntity<>(list, HttpStatus.OK); - } - - @Logging - @GetMapping("/dept/grant") - @Operation(summary = "部门角色授权", description = "部门角色授权") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_DEPT_AUTHORIZE)") - public ResponseEntity grantDeptRole(@RequestParam("deptRole") SecDeptRoleDTO deptRole) { - this.secDeptRoleService.insert(deptRole); - List userList = this.secUserService.listByDept(deptRole.getDeptId(), "", "1"); - userList.forEach(user -> { - this.onlineUserService.disableOnlineCacheUser(user.getUserName()); - }); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @GetMapping("/dept/revoke") - @Operation(summary = "回收部门角色权限", description = "回收部门角色权限") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.ButtonPrivilege).ADMIN_DEPT_UNAUTHORIZE)") - public ResponseEntity revokeDeptRole(@RequestParam("deptRole") SecDeptRoleDTO deptRole) { - this.secDeptRoleService.delete(deptRole); - List userList = this.secUserService.listByDept(deptRole.getDeptId(), "", "1"); - userList.forEach(user -> { - this.onlineUserService.disableOnlineCacheUser(user.getUserName()); - }); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } -} diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java deleted file mode 100644 index ff7a602ec..000000000 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.api.controller.admin; - -import cn.sliew.scaleph.api.annotation.AnonymousAccess; -import cn.sliew.scaleph.api.annotation.Logging; -import cn.sliew.scaleph.api.vo.RegisterInfoVO; -import cn.sliew.scaleph.api.vo.TransferVO; -import cn.sliew.scaleph.cache.util.RedisUtil; -import cn.sliew.scaleph.common.constant.Constants; -import cn.sliew.scaleph.common.dict.security.UserStatus; -import cn.sliew.scaleph.common.enums.ErrorShowTypeEnum; -import cn.sliew.scaleph.common.enums.ResponseCodeEnum; -import cn.sliew.scaleph.common.util.I18nUtil; -import cn.sliew.scaleph.dao.DataSourceConstants; -import cn.sliew.scaleph.mail.service.EmailService; -import cn.sliew.scaleph.security.service.*; -import cn.sliew.scaleph.security.service.dto.SecRoleDTO; -import cn.sliew.scaleph.security.service.dto.SecUserActiveDTO; -import cn.sliew.scaleph.security.service.dto.SecUserDTO; -import cn.sliew.scaleph.security.service.dto.SecUserRoleDTO; -import cn.sliew.scaleph.security.service.param.SecLoginParam; -import cn.sliew.scaleph.security.service.param.SecUserParam; -import cn.sliew.scaleph.security.util.SecurityUtil; -import cn.sliew.scaleph.security.vo.OnlineUserVO; -import cn.sliew.scaleph.security.web.OnlineUserService; -import cn.sliew.scaleph.system.model.ResponseVO; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotNull; -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.text.RandomStringGenerator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - *

- * 用户基本信息表 前端控制器 - *

- * - * @author liyu - */ -//@RestController -@RequestMapping("/api") -@Tag(name = "系统管理-用户管理") -public class SecUserController { - - @Value("${app.name}") - private String appName; - @Value("${app.host}") - private String appHost; - - @Autowired - private RedisUtil redisUtil; - @Autowired - private PasswordEncoder passwordEncoder; - @Autowired - private EmailService emailService; - @Autowired - private SecUserService secUserService; - @Autowired - private SecRoleService secRoleService; - @Autowired - private SecUserRoleService secUserRoleService; - @Autowired - private OnlineUserService onlineUserService; - @Autowired - private SecUserActiveService secUserActiveService; - @Autowired - private SecAuthenticateService secAuthenticateService; - - @AnonymousAccess - @PostMapping("/user/login") - @Operation(summary = "用户登录", description = "用户登录接口") - public ResponseEntity login(@Validated @RequestBody SecLoginParam param, HttpServletRequest request) { - ResponseVO responseVO = secAuthenticateService.login(request, param); - return new ResponseEntity<>(responseVO, HttpStatus.OK); - } - - @AnonymousAccess - @PostMapping("/user/logout") - @Operation(summary = "用户登出", description = "用户登出接口") - public ResponseEntity logout(String token) { - secAuthenticateService.logout(token); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @AnonymousAccess - @PostMapping("/user/passwd/edit") - public ResponseEntity editPassword(@NotNull String oldPassword, - @NotNull String password, - @NotNull String confirmPassword) { - String userName = SecurityUtil.getCurrentUserName(); - if (StringUtils.isEmpty(userName)) { - return new ResponseEntity<>( - ResponseVO.error(String.valueOf(HttpServletResponse.SC_UNAUTHORIZED), - I18nUtil.get("response.error.unauthorized")), HttpStatus.OK); - } - - if (password.equals(confirmPassword)) { - SecUserDTO user = this.secUserService.selectOne(userName); - if (this.passwordEncoder.matches(oldPassword, user.getPassword())) { - SecUserDTO secUserDTO = new SecUserDTO(); - secUserDTO.setId(user.getId()); - secUserDTO.setPassword(this.passwordEncoder.encode(password)); - this.secUserService.update(secUserDTO); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } else { - return new ResponseEntity<>( - ResponseVO.error(I18nUtil.get("response.error.oldPassword")), - HttpStatus.OK); - } - } else { - return new ResponseEntity<>( - ResponseVO.error(I18nUtil.get("response.error.notSamePassword")), - HttpStatus.OK); - } - } - - /** - * 发送激活码邮件 - * - * @param email 邮箱地址 - * @return ResponseVO - */ - @Logging - @GetMapping("/user/email/getAuth") - @Operation(summary = "获取邮箱验证码", description = "用户登录后,绑定获取邮箱绑定验证码") - public ResponseEntity sendActiveEmail(@Email String email) { - String userName = SecurityUtil.getCurrentUserName(); - if (StringUtils.hasText(userName)) { - SecUserActiveDTO activeDTO = new SecUserActiveDTO(); - activeDTO.setUserName(userName); - long time = System.currentTimeMillis() + 1000 * 60 * 10; - activeDTO.setExpiryTime(time); - activeDTO.setActiveCode(randomPasswordGenerate(6)); - this.secUserActiveService.insert(activeDTO); - String subject = appName + "邮箱绑定"; - String html = "

" + - "尊敬的用户:" + userName + - "

您本次邮箱变更/绑定的验证码为

" + activeDTO.getActiveCode() + - "


注意:请您在收到邮件10分钟内使用,否则该验证码将会失效" + - "

"; - String[] sendTo = {email}; - emailService.sendHtmlEmail(sendTo, subject, html); - } - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - /** - * 用户登录后,绑定邮箱地址 - * - * @param authCode 验证码 - * @return ResponseVO - */ - @Logging - @GetMapping("/user/email/auth") - @Transactional(rollbackFor = Exception.class, transactionManager = DataSourceConstants.MASTER_TRANSACTION_MANAGER_FACTORY) - public ResponseEntity getEmailAuthCode(@NotNull String authCode, @Email String email) { - String userName = SecurityUtil.getCurrentUserName(); - if (StringUtils.hasText(userName)) { - SecUserActiveDTO userActive = this.secUserActiveService.selectOne(userName, authCode); - if (userActive == null || System.currentTimeMillis() > userActive.getExpiryTime()) { - return new ResponseEntity<>( - ResponseVO.error(I18nUtil.get("response.error.authCode.expired")), - HttpStatus.OK); - } else { - SecUserDTO user = new SecUserDTO(); - user.setUserName(userName); - user.setEmail(email); - user.setStatus(UserStatus.ENABLED); - this.secUserActiveService.updateByUserAndCode(userActive); - this.secUserService.updateByUserName(user); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - } else { - return new ResponseEntity<>( - ResponseVO.error(String.valueOf(HttpServletResponse.SC_UNAUTHORIZED), - I18nUtil.get("response.error.unauthorized")), HttpStatus.OK); - } - } - - /** - * 根据token获取redis中的用户信息 - * - * @param token token - * @return 用户及权限角色信息 - */ - @AnonymousAccess - @GetMapping("/user/get/{token}") - @Operation(summary = "查询用户权限", description = "根据token信息查询用户所有权限") - public ResponseEntity getOnlineUserInfo(@PathVariable(value = "token") String token) { - OnlineUserVO onlineUser = this.onlineUserService.getAllPrivilegeByToken(token); - ResponseVO info = ResponseVO.success(); - info.setData(onlineUser); - return new ResponseEntity<>(info, HttpStatus.OK); - } - - /** - * 用户注册 - * - * @param registerInfo 用户注册信息 - * @return OperateInfo - */ - @Logging - @AnonymousAccess - @PostMapping("/user/register") - @Operation(summary = "用户注册", description = "用户注册接口") - @Transactional(rollbackFor = Exception.class, transactionManager = DataSourceConstants.MASTER_TRANSACTION_MANAGER_FACTORY) - public ResponseEntity register(@Validated @RequestBody RegisterInfoVO registerInfo) { - //校验验证码是否一致 - String authCode = (String) redisUtil.get(registerInfo.getUuid()); - redisUtil.delKeys(registerInfo.getUuid()); - if (StringUtils.hasText(authCode) && authCode.equalsIgnoreCase(registerInfo.getAuthCode())) { - //校验两次输入密码是否一致 - if (registerInfo.getPassword().equals(registerInfo.getConfirmPassword())) { - Date date = new Date(); - SecUserDTO secUserDTO = new SecUserDTO(); - secUserDTO.setUserName(registerInfo.getUserName().toLowerCase()); - secUserDTO.setEmail(registerInfo.getEmail().toLowerCase()); - String password = passwordEncoder.encode(registerInfo.getPassword()); - secUserDTO.setPassword(password); - secUserDTO.setStatus(UserStatus.ENABLED); - this.sendConfirmEmail(secUserDTO, null); - this.secUserService.insert(secUserDTO); - //授权普通用户角色 - SecUserDTO userInfo = this.secUserService.selectOne(secUserDTO.getUserName()); - SecRoleDTO secRoleDTO = secRoleService.selectOne(Constants.ROLE_NORMAL); - SecUserRoleDTO secUserRoleDTO = new SecUserRoleDTO(); - secUserRoleDTO.setUserId(userInfo.getId()); - secUserRoleDTO.setRoleId(secRoleDTO.getId()); - secUserRoleDTO.setCreateTime(date); - secUserRoleDTO.setUpdateTime(date); - this.secUserRoleService.insert(secUserRoleDTO); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.CREATED); - } else { - //前台有验证提示,此处只做返回,不展示 - return new ResponseEntity<>( - ResponseVO.error(ResponseCodeEnum.ERROR_CUSTOM.getCode(), - I18nUtil.get("response.error"), ErrorShowTypeEnum.SILENT), HttpStatus.OK); - } - } else { - return new ResponseEntity<>(ResponseVO.error(ResponseCodeEnum.ERROR_CUSTOM.getCode(), - I18nUtil.get("response.error.authCode"), ErrorShowTypeEnum.ERROR_MESSAGE), - HttpStatus.OK); - } - } - - @Logging - @PostMapping("/admin/user") - @Operation(summary = "新增用户", description = "新增用户") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).USER_ADD)") - public ResponseEntity addUser(@Validated @RequestBody SecUserDTO secUserDTO) { - Date date = new Date(); - String randomPassword = RandomStringUtils.randomAlphanumeric(10); - secUserDTO.setPassword(this.passwordEncoder.encode(randomPassword)); - secUserDTO.setStatus(UserStatus.ENABLED); - this.secUserService.insert(secUserDTO); - this.sendConfirmEmail(secUserDTO, randomPassword); - //授权普通用户角色 - SecUserDTO userInfo = this.secUserService.selectOne(secUserDTO.getUserName()); - SecRoleDTO secRoleDTO = secRoleService.selectOne(Constants.ROLE_NORMAL); - SecUserRoleDTO secUserRoleDTO = new SecUserRoleDTO(); - secUserRoleDTO.setUserId(userInfo.getId()); - secUserRoleDTO.setRoleId(secRoleDTO.getId()); - secUserRoleDTO.setCreateTime(date); - secUserRoleDTO.setUpdateTime(date); - this.secUserRoleService.insert(secUserRoleDTO); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.CREATED); - } - - - @Logging - @PutMapping("/admin/user") - @Operation(summary = "修改用户", description = "修改用户") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).USER_EDIT)") - public ResponseEntity editUser(@Validated @RequestBody SecUserDTO secUserDTO) { - this.secUserService.update(secUserDTO); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - - @Logging - @DeleteMapping("/admin/user/{id}") - @Operation(summary = "删除用户", description = "根据id删除用户") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).USER_DELETE)") - public ResponseEntity deleteUser(@PathVariable("id") String id) { - this.secUserService.deleteById(Long.valueOf(id)); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @PostMapping("/admin/user/batch") - @Operation(summary = "批量删除用户", description = "根据id列表批量删除用户") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).USER_DELETE)") - public ResponseEntity deleteBatchUser(@RequestBody Map map) { - this.secUserService.deleteBatch(map); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @GetMapping("/admin/user") - @Operation(summary = "分页查询用户", description = "分页查询用户") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).USER_SELECT)") - public ResponseEntity> listUser(SecUserParam secUserParam) { - Page page = this.secUserService.listByPage(secUserParam); - return new ResponseEntity<>(page, HttpStatus.OK); - } - - /** - * 随机生成密码 - * - * @param length 密码长度 - * @return 密码 - */ - private String randomPasswordGenerate(int length) { - //随机生成密码 - char[][] pairs = {{'a', 'z'}, {'A', 'Z'}, {'0', '9'}}; - RandomStringGenerator rsg = new RandomStringGenerator.Builder().withinRange(pairs).build(); - return rsg.generate(length); - } - - /** - * 向用户邮箱发送邮件,确认用户注册信息 - * - * @param secUserDTO 用户信息 - */ - private void sendConfirmEmail(SecUserDTO secUserDTO, String password) { - String subject = appName + "注册确认"; - String html = "

" + - "尊敬的用户:
感谢您注册" + appName + ",账号" + secUserDTO.getUserName() + "已开通"; - if (!StringUtils.isEmpty(password)) { - html = html + ",初始密码为:" + password; - } - html = html + "。
登录后请及时修改密码。" + - "

"; - - String[] sendTo = {secUserDTO.getEmail()}; - this.emailService.sendHtmlEmail(sendTo, subject, html); - } - - /** - * 验证用户名是否存在 - * - * @param userName 用户名 - * @return true/false - */ - @Logging - @AnonymousAccess - @GetMapping("/user/validation/userName") - @Operation(summary = "判断用户是否存在", description = "根据用户名,判断用户是否存在") - public ResponseEntity isUserNameExists(String userName) { - SecUserDTO user = this.secUserService.selectOne(userName); - return new ResponseEntity<>(user == null, HttpStatus.OK); - } - - /** - * 验证用户邮箱是否存在 - * - * @param email 邮箱地址 - * @return true/false - */ - @Logging - @AnonymousAccess - @GetMapping("/user/validation/email") - @Operation(summary = "判断邮箱是否存在", description = "根据邮箱,判断用户是否存在") - public ResponseEntity isEmailExists(String email) { - SecUserDTO user = this.secUserService.selectByEmail(email); - return new ResponseEntity<>(user == null, HttpStatus.OK); - } - - @Logging - @GetMapping("/user/info") - @Operation(summary = "根据用户名查询用户信息", description = "根据用户名查询用户信息") - public ResponseEntity listUserByUserName() { - String userName = SecurityUtil.getCurrentUserName(); - if (StringUtils.hasText(userName)) { - SecUserDTO userinfo = this.secUserService.selectOne(userName); - return new ResponseEntity<>(userinfo, HttpStatus.OK); - } else { - return new ResponseEntity<>(new SecUserDTO(), HttpStatus.OK); - } - } - - /** - * 配合前端穿梭框查询用户列表 - * - * @param userName 用户名 - * @param roleId 角色id - * @param direction 1:target 0:source - * @return user list - */ - @Logging - @PostMapping("/user/role") - @Operation(summary = "查询角色下用户列表", description = "配合前端穿梭框查询用户列表") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).ROLE_GRANT)") - public ResponseEntity> listUserByUserAndRole(String userName, Long roleId, String direction) { - List result = new ArrayList<>(); - List userList = this.secUserService.listByRole(roleId, userName, direction); - userList.forEach(d -> { - result.add(new TransferVO(String.valueOf(d.getId()), d.getUserName())); - }); - return new ResponseEntity<>(result, HttpStatus.OK); - } - - /** - * 配合前端穿梭框查询用户列表 - * - * @param userName 用户名 - * @param deptId dept id - * @param direction 1:target 0:source - * @return user list - */ - @Logging - @PostMapping("/user/dept") - @Operation(summary = "查询部门下用户列表", description = "配合前端穿梭框查询用户列表") - @PreAuthorize("@svs.validate(T(cn.sliew.scaleph.common.constant.PrivilegeConstants).DEPT_GRANT)") - public ResponseEntity> listUserByUserAndDept(String userName, Long deptId, String direction) { - List result = new ArrayList<>(); - List userList = this.secUserService.listByDept(deptId, userName, direction); - userList.forEach(d -> { - result.add(new TransferVO(String.valueOf(d.getId()), d.getUserName())); - }); - return new ResponseEntity<>(result, HttpStatus.OK); - } -} diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/CategoryController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/CategoryController.java deleted file mode 100644 index 2aee753c1..000000000 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/CategoryController.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.api.controller.ds; - -import cn.sliew.scaleph.api.annotation.Logging; -import cn.sliew.scaleph.ds.service.DsCategoryService; -import cn.sliew.scaleph.ds.service.dto.DsCategoryDTO; -import cn.sliew.scaleph.ds.service.dto.DsTypeDTO; -import cn.sliew.scaleph.ds.service.param.DsTypeListParam; -import cn.sliew.scaleph.system.model.ResponseVO; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@Tag(name = "数据源管理-分类管理") -@RestController -@RequestMapping(path = "/api/ds/category") -public class CategoryController { - - @Autowired - private DsCategoryService dsCategoryService; - - @Logging - @GetMapping - @Operation(summary = "查询分类列表", description = "查询分类列表") - public ResponseEntity>> list() { - List result = dsCategoryService.list(); - return new ResponseEntity<>(ResponseVO.success(result), HttpStatus.OK); - } - - @Logging - @GetMapping("type") - @Operation(summary = "查询数据源类型", description = "查询数据源类型") - public ResponseEntity>> listTypes(@Valid DsTypeListParam param) { - List result = dsCategoryService.listTypes(param); - return new ResponseEntity<>(ResponseVO.success(result), HttpStatus.OK); - } - -} diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/InfoController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/InfoController.java deleted file mode 100644 index f2d4d1d59..000000000 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ds/InfoController.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.api.controller.ds; - -import cn.sliew.scaleph.api.annotation.Logging; -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.ds.modal.AbstractDataSource; -import cn.sliew.scaleph.ds.service.DsInfoService; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; -import cn.sliew.scaleph.ds.service.param.DsInfoListParam; -import cn.sliew.scaleph.system.model.ResponseVO; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@Tag(name = "数据源管理-数据源") -@RestController -@RequestMapping(path = "/api/ds/info") -public class InfoController { - - @Autowired - private DsInfoService dsInfoService; - - @Logging - @GetMapping - @Operation(summary = "查询数据源列表", description = "查询数据源列表") - public ResponseEntity> list(@Valid DsInfoListParam param) { - final Page result = dsInfoService.list(param); - return new ResponseEntity<>(result, HttpStatus.OK); - } - - @Logging - @GetMapping("{type}") - @Operation(summary = "查询指定数据源列表", description = "查询指定数据源列表") - public ResponseEntity>> listByType(@PathVariable("type") DataSourceType type) { - final List result = dsInfoService.listByType(type); - return new ResponseEntity<>(ResponseVO.success(result), HttpStatus.OK); - } - - @Logging - @GetMapping("/detail/{id}") - @Operation(summary = "获取数据源详情", description = "获取数据源详情") - public ResponseEntity> get(@PathVariable("id") Long id) { - final DsInfoDTO result = dsInfoService.selectOne(id, false); - return new ResponseEntity<>(ResponseVO.success(result), HttpStatus.OK); - } - - @Logging - @PutMapping - @Operation(summary = "新增数据源", description = "新增数据源") - public ResponseEntity insert(@Valid @RequestBody AbstractDataSource dataSource) { - dsInfoService.insert(dataSource); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @PostMapping("{id}") - @Operation(summary = "修改数据源", description = "修改数据源") - public ResponseEntity update(@PathVariable("id") Long id, @Valid @RequestBody AbstractDataSource dataSource) { - dsInfoService.update(id, dataSource); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @DeleteMapping("{id}") - @Operation(summary = "删除数据源", description = "删除数据源") - public ResponseEntity delete(@PathVariable("id") Long id) { - dsInfoService.deleteById(id); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - - @Logging - @DeleteMapping("batch") - @Operation(summary = "批量删除数据源", description = "批量删除数据源") - public ResponseEntity deleteBatch(@RequestBody List ids) { - dsInfoService.deleteBatch(ids); - return new ResponseEntity<>(ResponseVO.success(), HttpStatus.OK); - } - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategory.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategory.java deleted file mode 100644 index aa5bff11c..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.entity.master.ds; - -import cn.sliew.scaleph.dao.entity.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - *

- * data source category - *

- */ -@Data -@EqualsAndHashCode -@TableName("ds_category") -public class DsCategory extends BaseDO { - - private static final long serialVersionUID = 1L; - - @TableField("`name`") - private String name; - - @TableField("`order`") - private Integer order; - - @TableField("remark") - private String remark; - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategoryTypeRelation.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategoryTypeRelation.java deleted file mode 100644 index d0ba9b909..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsCategoryTypeRelation.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.entity.master.ds; - -import cn.sliew.scaleph.dao.entity.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - *

- * data source category and type relation - *

- */ -@Data -@EqualsAndHashCode -@TableName("ds_category_type_relation") -public class DsCategoryTypeRelation extends BaseDO { - - private static final long serialVersionUID = 1L; - - @TableField("ds_category_id") - private Long dsCategoryId; - - @TableField("ds_type_id") - private Long dsTypeId; - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfo.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfo.java deleted file mode 100644 index 3dfda2750..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfo.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.entity.master.ds; - -import cn.sliew.scaleph.dao.entity.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - *

- * data source info - *

- */ -@Data -@EqualsAndHashCode -@TableName("ds_info") -public class DsInfo extends BaseDO { - - private static final long serialVersionUID = 1L; - - @TableField("ds_type_id") - private Long dsTypeId; - - @TableField("version") - private String version; - - @TableField("`name`") - private String name; - - @TableField("props") - private String props; - - @TableField("additional_props") - private String additionalProps; - - @TableField("remark") - private String remark; - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfoVO.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfoVO.java deleted file mode 100644 index 360954ec0..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsInfoVO.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.entity.master.ds; - -import cn.sliew.scaleph.dao.entity.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode -@TableName("ds_info") -public class DsInfoVO extends BaseDO { - - private static final long serialVersionUID = 1L; - - @TableField(value = "ds_type_id", exist = false) - private DsType dsType; - - @TableField("version") - private String version; - - @TableField("`name`") - private String name; - - @TableField("props") - private String props; - - @TableField("additional_props") - private String additionalProps; - - @TableField("remark") - private String remark; - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsType.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsType.java deleted file mode 100644 index ad8b925f9..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/entity/master/ds/DsType.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.entity.master.ds; - -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.dao.entity.BaseDO; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - *

- * data source type - *

- */ -@Data -@EqualsAndHashCode -@TableName("ds_type") -public class DsType extends BaseDO { - - private static final long serialVersionUID = 1L; - - @TableField("`type`") - private DataSourceType type; - - @TableField("logo") - private String logo; - - @TableField("`order`") - private Integer order; - - @TableField("remark") - private String remark; - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.java deleted file mode 100644 index a17001c19..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.ds; - -import cn.sliew.scaleph.dao.entity.master.ds.DsCategory; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.springframework.stereotype.Repository; - -/** - *

- * data source category Mapper 接口 - *

- */ -@Repository -public interface DsCategoryMapper extends BaseMapper { - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.java deleted file mode 100644 index 381921667..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.ds; - -import cn.sliew.scaleph.dao.entity.master.ds.DsCategoryTypeRelation; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.springframework.stereotype.Repository; - -/** - *

- * data source category and type relation Mapper 接口 - *

- */ -@Repository -public interface DsCategoryTypeRelationMapper extends BaseMapper { - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.java deleted file mode 100644 index 936d51f37..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.ds; - -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfo; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfoVO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - *

- * data source info Mapper 接口 - *

- */ -@Repository -public interface DsInfoMapper extends BaseMapper { - - Page list(Page page, @Param("dsType") DataSourceType dsType, @Param("name") String name); - - List listByTypes(@Param("type") DataSourceType type); - - DsInfoVO getById(@Param("id") Long id); - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.java deleted file mode 100644 index af41523ba..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.ds; - -import cn.sliew.scaleph.dao.entity.master.ds.DsType; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - *

- * data source type Mapper 接口 - *

- */ -@Repository -public interface DsTypeMapper extends BaseMapper { - - List listTypes(@Param("categoryId") Long categoryId, @Param("type") String type); - -} diff --git a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.xml b/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.xml deleted file mode 100644 index 649f938f6..000000000 --- a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryMapper.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - id, creator, create_time, editor, update_time, - `name`, `order`, remark - - - diff --git a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.xml b/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.xml deleted file mode 100644 index b7b4aabd0..000000000 --- a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsCategoryTypeRelationMapper.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - id, creator, create_time, editor, update_time, - ds_category_id, ds_type_id - - - diff --git a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.xml b/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.xml deleted file mode 100644 index ff6ed41a5..000000000 --- a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsInfoMapper.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id, creator, create_time, editor, update_time, - ds_type_id, version, `name`, props, additional_props, remark - - - - - - - - - diff --git a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.xml b/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.xml deleted file mode 100644 index 1dec1dcf4..000000000 --- a/scaleph-dao/src/main/resources/cn/sliew/scaleph/dao/mapper/master/ds/DsTypeMapper.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - id, creator, create_time, editor, update_time, - `type`, logo, `order`, remark - - - - diff --git a/scaleph-datasource/pom.xml b/scaleph-datasource/pom.xml index 97560e82b..dec5f71c6 100644 --- a/scaleph-datasource/pom.xml +++ b/scaleph-datasource/pom.xml @@ -37,6 +37,11 @@ scaleph-resource
+ + cn.sliew + carp-module-datasource + + com.datastrato.gravitino client-java-runtime diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/gravitino/GravitinoInitializer.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/gravitino/GravitinoInitializer.java index 2e39a9bb3..621123541 100644 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/gravitino/GravitinoInitializer.java +++ b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/gravitino/GravitinoInitializer.java @@ -18,12 +18,12 @@ package cn.sliew.scaleph.ds.gravitino; +import cn.sliew.carp.framework.common.dict.datasource.DataSourceType; +import cn.sliew.carp.module.datasource.service.CarpDsInfoService; +import cn.sliew.carp.module.datasource.service.dto.DsInfoDTO; import cn.sliew.milky.common.util.JacksonUtil; -import cn.sliew.scaleph.common.dict.job.DataSourceType; import cn.sliew.scaleph.ds.modal.AbstractDataSource; import cn.sliew.scaleph.ds.modal.jdbc.JdbcDataSource; -import cn.sliew.scaleph.ds.service.DsInfoService; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; import com.datastrato.gravitino.Catalog; import com.datastrato.gravitino.NameIdentifier; import com.datastrato.gravitino.client.GravitinoAdminClient; @@ -46,7 +46,7 @@ public class GravitinoInitializer implements InitializingBean { @Autowired private GravitinoAdminClient adminClient; @Autowired - private DsInfoService dsInfoService; + private CarpDsInfoService dsInfoService; @Override public void afterPropertiesSet() throws Exception { diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsCategoryService.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsCategoryService.java deleted file mode 100644 index f6b8e118b..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsCategoryService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service; - -import cn.sliew.scaleph.ds.service.dto.DsCategoryDTO; -import cn.sliew.scaleph.ds.service.dto.DsTypeDTO; -import cn.sliew.scaleph.ds.service.param.DsTypeListParam; - -import java.util.List; - -public interface DsCategoryService { - - List list(); - - List listTypes(DsTypeListParam param); - -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsInfoService.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsInfoService.java deleted file mode 100644 index 91f48dab7..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/DsInfoService.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service; - -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.ds.modal.AbstractDataSource; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; -import cn.sliew.scaleph.ds.service.param.DsInfoListParam; -import cn.sliew.scaleph.resource.service.ResourceDescriptor; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; - -import java.util.List; - -public interface DsInfoService extends ResourceDescriptor { - - Page list(DsInfoListParam param); - - List listByType(DataSourceType type); - - DsInfoDTO selectOne(Long id, boolean decrypt); - - int insert(AbstractDataSource dataSource); - - int update(Long id, AbstractDataSource dataSource); - - int deleteById(Long id); - - int deleteBatch(List ids); - -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsCategoryConvert.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsCategoryConvert.java deleted file mode 100644 index 6c93505be..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsCategoryConvert.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.convert; - -import cn.sliew.scaleph.common.convert.BaseConvert; -import cn.sliew.scaleph.dao.entity.master.ds.DsCategory; -import cn.sliew.scaleph.ds.service.dto.DsCategoryDTO; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; - -@Mapper(uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface DsCategoryConvert extends BaseConvert { - DsCategoryConvert INSTANCE = Mappers.getMapper(DsCategoryConvert.class); - -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoConvert.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoConvert.java deleted file mode 100644 index 3c03575b2..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoConvert.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.convert; - -import cn.sliew.milky.common.util.JacksonUtil; -import cn.sliew.scaleph.common.codec.CodecUtil; -import cn.sliew.scaleph.common.convert.BaseConvert; -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.common.util.BeanUtil; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfo; -import cn.sliew.scaleph.ds.modal.PropValuePair; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; -import cn.sliew.scaleph.ds.service.dto.DsTypeDTO; -import cn.sliew.scaleph.ds.service.param.DsInfoListParam; -import cn.sliew.scaleph.resource.service.param.ResourceListParam; -import com.fasterxml.jackson.core.type.TypeReference; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; -import org.springframework.beans.BeanUtils; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import java.util.Map; - -@Mapper(uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface DsInfoConvert extends BaseConvert { - DsInfoConvert INSTANCE = Mappers.getMapper(DsInfoConvert.class); - - @Override - default DsInfoDTO toDto(DsInfo entity) { - DsInfoDTO dto = new DsInfoDTO(); - BeanUtils.copyProperties(entity, dto); - DsTypeDTO dsType = new DsTypeDTO(); - dsType.setId(entity.getDsTypeId()); - dto.setDsType(dsType); - if (StringUtils.hasText(entity.getProps())) { - String jsonProps = CodecUtil.decodeFromBase64(entity.getProps()); - dto.setProps(JacksonUtil.parseJsonString(jsonProps, new TypeReference>() {})); - } - if (StringUtils.hasText(entity.getAdditionalProps())) { - String jsonAdditionalProps = CodecUtil.decodeFromBase64(entity.getAdditionalProps()); - dto.setAdditionalProps(JacksonUtil.parseJsonArray(jsonAdditionalProps, PropValuePair.class)); - } - return dto; - } - - @Override - default DsInfo toDo(DsInfoDTO dto) { - DsInfo record = new DsInfo(); - BeanUtils.copyProperties(dto, record); - record.setDsTypeId(dto.getDsType().getId()); - if (CollectionUtils.isEmpty(dto.getProps()) == false) { - String jsonProps = JacksonUtil.toJsonString(dto.getProps()); - record.setProps(CodecUtil.encodeToBase64(jsonProps)); - } - if (CollectionUtils.isEmpty(dto.getAdditionalProps()) == false) { - String jsonAdditionalProps = JacksonUtil.toJsonString(dto.getAdditionalProps()); - record.setAdditionalProps(CodecUtil.encodeToBase64(jsonAdditionalProps)); - } - return record; - } - - default DsInfoListParam convert(ResourceListParam param) { - DsInfoListParam target = BeanUtil.copy(param, new DsInfoListParam()); - target.setDsType(DataSourceType.of(param.getLabel())); - return target; - } -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoVOConvert.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoVOConvert.java deleted file mode 100644 index d26843355..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsInfoVOConvert.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.convert; - -import cn.sliew.milky.common.util.JacksonUtil; -import cn.sliew.scaleph.common.codec.CodecUtil; -import cn.sliew.scaleph.common.convert.BaseConvert; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfoVO; -import cn.sliew.scaleph.ds.modal.PropValuePair; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; -import com.fasterxml.jackson.core.type.TypeReference; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; -import org.springframework.beans.BeanUtils; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import java.util.Map; - -@Mapper(uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface DsInfoVOConvert extends BaseConvert { - DsInfoVOConvert INSTANCE = Mappers.getMapper(DsInfoVOConvert.class); - - @Override - default DsInfoDTO toDto(DsInfoVO entity) { - DsInfoDTO dto = new DsInfoDTO(); - BeanUtils.copyProperties(entity, dto); - if (StringUtils.hasText(entity.getProps())) { - String jsonProps = CodecUtil.decodeFromBase64(entity.getProps()); - dto.setProps(JacksonUtil.parseJsonString(jsonProps, new TypeReference>() {})); - } - if (StringUtils.hasText(entity.getAdditionalProps())) { - String jsonAdditionalProps = CodecUtil.decodeFromBase64(entity.getAdditionalProps()); - dto.setAdditionalProps(JacksonUtil.parseJsonArray(jsonAdditionalProps, PropValuePair.class)); - } - dto.setDsType(DsTypeConvert.INSTANCE.toDto(entity.getDsType())); - return dto; - } - - @Override - default DsInfoVO toDo(DsInfoDTO dto) { - DsInfoVO record = new DsInfoVO(); - BeanUtils.copyProperties(dto, record); - if (CollectionUtils.isEmpty(dto.getProps()) == false) { - String jsonProps = JacksonUtil.toJsonString(dto.getProps()); - record.setProps(CodecUtil.encodeToBase64(jsonProps)); - } - if (CollectionUtils.isEmpty(dto.getAdditionalProps()) == false) { - String jsonAdditionalProps = JacksonUtil.toJsonString(dto.getAdditionalProps()); - record.setAdditionalProps(CodecUtil.encodeToBase64(jsonAdditionalProps)); - } - record.setDsType(DsTypeConvert.INSTANCE.toDo(dto.getDsType())); - return record; - } -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsTypeConvert.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsTypeConvert.java deleted file mode 100644 index f76e3c6f0..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/convert/DsTypeConvert.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.convert; - -import cn.sliew.scaleph.common.convert.BaseConvert; -import cn.sliew.scaleph.dao.entity.master.ds.DsType; -import cn.sliew.scaleph.ds.service.dto.DsTypeDTO; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; - -@Mapper(uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface DsTypeConvert extends BaseConvert { - DsTypeConvert INSTANCE = Mappers.getMapper(DsTypeConvert.class); - -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsCategoryServiceImpl.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsCategoryServiceImpl.java deleted file mode 100644 index ed96935a6..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsCategoryServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.impl; - -import cn.sliew.scaleph.dao.entity.master.ds.DsCategory; -import cn.sliew.scaleph.dao.entity.master.ds.DsType; -import cn.sliew.scaleph.dao.mapper.master.ds.DsCategoryMapper; -import cn.sliew.scaleph.dao.mapper.master.ds.DsTypeMapper; -import cn.sliew.scaleph.ds.service.DsCategoryService; -import cn.sliew.scaleph.ds.service.convert.DsCategoryConvert; -import cn.sliew.scaleph.ds.service.convert.DsTypeConvert; -import cn.sliew.scaleph.ds.service.dto.DsCategoryDTO; -import cn.sliew.scaleph.ds.service.dto.DsTypeDTO; -import cn.sliew.scaleph.ds.service.param.DsTypeListParam; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class DsCategoryServiceImpl implements DsCategoryService { - - @Autowired - private DsCategoryMapper dsCategoryMapper; - @Autowired - private DsTypeMapper dsTypeMapper; - - public List list() { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(DsCategory.class) - .orderByAsc(DsCategory::getOrder); - List categories = dsCategoryMapper.selectList(queryWrapper); - return DsCategoryConvert.INSTANCE.toDto(categories); - } - - @Override - public List listTypes(DsTypeListParam param) { - List dsTypes = dsTypeMapper.listTypes(param.getCategoryId(), param.getType()); - return DsTypeConvert.INSTANCE.toDto(dsTypes); - } -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsInfoServiceImpl.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsInfoServiceImpl.java deleted file mode 100644 index 6f83dba47..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/impl/DsInfoServiceImpl.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.impl; - -import cn.sliew.scaleph.common.codec.CodecUtil; -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfo; -import cn.sliew.scaleph.dao.entity.master.ds.DsInfoVO; -import cn.sliew.scaleph.dao.mapper.master.ds.DsInfoMapper; -import cn.sliew.scaleph.ds.modal.AbstractDataSource; -import cn.sliew.scaleph.ds.service.DsInfoService; -import cn.sliew.scaleph.ds.service.convert.DsInfoConvert; -import cn.sliew.scaleph.ds.service.convert.DsInfoVOConvert; -import cn.sliew.scaleph.ds.service.dto.DsInfoDTO; -import cn.sliew.scaleph.ds.service.param.DsInfoListParam; -import cn.sliew.scaleph.resource.service.enums.ResourceType; -import cn.sliew.scaleph.resource.service.param.ResourceListParam; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static cn.sliew.milky.common.check.Ensures.checkState; - -@Service -public class DsInfoServiceImpl implements DsInfoService { - - @Autowired - private DsInfoMapper dsInfoMapper; - - @Override - public ResourceType getResourceType() { - return ResourceType.DATASOURCE; - } - - @Override - public Page list(ResourceListParam param) { - DsInfoListParam dsInfoListParam = DsInfoConvert.INSTANCE.convert(param); - return list(dsInfoListParam); - } - - @Override - public DsInfoDTO getRaw(Long id) { - return selectOne(id, true); - } - - @Override - public Page list(DsInfoListParam param) { - Page page = new Page<>(param.getCurrent(), param.getPageSize()); - Page dsInfoPage = dsInfoMapper.list(page, param.getDsType(), param.getName()); - Page result = new Page<>(dsInfoPage.getCurrent(), dsInfoPage.getSize(), dsInfoPage.getTotal()); - List dsInfoDTOS = DsInfoVOConvert.INSTANCE.toDto(dsInfoPage.getRecords()); - result.setRecords(dsInfoDTOS); - return result; - } - - @Override - public List listByType(DataSourceType type) { - List dsInfoVOS = dsInfoMapper.listByTypes(type); - return DsInfoVOConvert.INSTANCE.toDto(dsInfoVOS); - } - - @Override - public DsInfoDTO selectOne(Long id, boolean decrypt) { - DsInfoVO vo = dsInfoMapper.getById(id); - checkState(vo != null, () -> "data source info not exists for id: " + id); - DsInfoDTO dsInfoDTO = DsInfoVOConvert.INSTANCE.toDto(vo); - if (decrypt) { - Map props = new HashMap<>(); - for (Map.Entry entry : dsInfoDTO.getProps().entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - if (Objects.nonNull(value) - && value instanceof String - && CodecUtil.isEncryptedStr((String) value)) { - props.put(key, CodecUtil.decrypt((String) value)); - } else { - props.put(key, value); - } - } - dsInfoDTO.setProps(props); - } - return dsInfoDTO; - } - - @Override - public int insert(AbstractDataSource dataSource) { - DsInfo record = DsInfoConvert.INSTANCE.toDo(dataSource.toDsInfo()); - return dsInfoMapper.insert(record); - } - - @Override - public int update(Long id, AbstractDataSource dataSource) { - DsInfo record = DsInfoConvert.INSTANCE.toDo(dataSource.toDsInfo()); - record.setId(id); - return dsInfoMapper.updateById(record); - } - - @Override - public int deleteById(Long id) { - return dsInfoMapper.deleteById(id); - } - - @Override - public int deleteBatch(List ids) { - return dsInfoMapper.deleteBatchIds(ids); - } -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsInfoListParam.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsInfoListParam.java deleted file mode 100644 index 31f1f255f..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsInfoListParam.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.param; - -import cn.sliew.scaleph.common.dict.job.DataSourceType; -import cn.sliew.scaleph.system.model.PaginationParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode -public class DsInfoListParam extends PaginationParam { - - @Schema(description = "data source type") - private DataSourceType dsType; - - @Schema(description = "name") - private String name; -} diff --git a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsTypeListParam.java b/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsTypeListParam.java deleted file mode 100644 index d0832b271..000000000 --- a/scaleph-datasource/src/main/java/cn/sliew/scaleph/ds/service/param/DsTypeListParam.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.ds.service.param; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode -public class DsTypeListParam { - - @Schema(description = "ds category id") - private Long categoryId; - - @Schema(description = "ds type") - private String type; -} diff --git a/scaleph-ui-react/src/components/TableTransfer.tsx b/scaleph-ui-react/src/components/TableTransfer.tsx new file mode 100644 index 000000000..2b5b95ba6 --- /dev/null +++ b/scaleph-ui-react/src/components/TableTransfer.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import {GetProp, Table, TableColumnsType, TableProps, Transfer, TransferProps} from 'antd'; + +type TransferItem = GetProp[number]; +type TableRowSelection = TableProps['rowSelection']; + +export interface DataType { + id?: number; + name?: string; + status?: string; + remark?: string; + checkOut?: number; +} + +interface TableTransferProps extends TransferProps { + dataSource: DataType[]; + leftColumns: TableColumnsType; + rightColumns: TableColumnsType; +} +const TableTransfer: React.FC = (props) => { + const { leftColumns, rightColumns, ...restProps } = props; + return ( + + {({ + direction, + filteredItems, + onItemSelect, + onItemSelectAll, + selectedKeys: listSelectedKeys, + disabled: listDisabled, + }) => { + const columns = direction === 'left' ? leftColumns : rightColumns; + const rowSelection: TableRowSelection = { + getCheckboxProps: () => ({ disabled: listDisabled }), + onChange(selectedRowKeys) { + onItemSelectAll(selectedRowKeys, 'replace'); + }, + selectedRowKeys: listSelectedKeys, + selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT, Table.SELECTION_NONE], + }; + + return ( + ({ + onClick: () => { + if (itemDisabled || listDisabled) { + return; + } + onItemSelect(key, !listSelectedKeys.includes(key)); + }, + })} + /> + ); + }} + + ); +}; + +export default React.memo(TableTransfer); diff --git a/scaleph-ui-react/src/constants/dictType.ts b/scaleph-ui-react/src/constants/dictType.ts index 229437ef3..97f6479af 100644 --- a/scaleph-ui-react/src/constants/dictType.ts +++ b/scaleph-ui-react/src/constants/dictType.ts @@ -11,6 +11,9 @@ export const DICT_TYPE = { carpSecResourceDataType: 'sec_resource_data_type', carpSecResourceStatus: 'sec_resource_status', + carpDataSourceType: 'datasource_type', + carpDataSourceRedisMode: 'datasource_redis_mode', + roleType: 'role_type', roleStatus: 'role_status', userType: 'user_type', diff --git a/scaleph-ui-react/src/locales/zh-CN/pages/admin.ts b/scaleph-ui-react/src/locales/zh-CN/pages/admin.ts index 846a7d8a7..63b039849 100644 --- a/scaleph-ui-react/src/locales/zh-CN/pages/admin.ts +++ b/scaleph-ui-react/src/locales/zh-CN/pages/admin.ts @@ -21,10 +21,10 @@ export default { 'pages.admin.user.granted': '已授权', 'pages.admin.role': '角色', - 'pages.admin.role.code': '角色编码', - 'pages.admin.role.name': '角色名称', - 'pages.admin.role.type': '角色类型', - 'pages.admin.role.status': '角色状态', + 'pages.admin.role.code': '编码', + 'pages.admin.role.name': '名称', + 'pages.admin.role.type': '类型', + 'pages.admin.role.status': '状态', 'pages.admin.resource': '资源管理', 'pages.admin.resource.type': '资源类型', @@ -35,8 +35,6 @@ export default { 'pages.admin.resource.web.order': '排序', 'pages.admin.resource.status': '状态', - - 'pages.admin.resource.web.name': '名称', 'pages.admin.resource.web.menuName': '目录', @@ -52,6 +50,15 @@ export default { 'pages.admin.resource.data': '数据资源', 'pages.admin.security.authorization.role2users': '角色分配用户', + 'pages.admin.security.authorization.role2users.authorized': '已授权用户', + 'pages.admin.security.authorization.role2users.unauthorized': '未授权用户', + 'pages.admin.security.authorization.role2ResourceWebs': '角色配置web资源', + 'pages.admin.security.authorization.user2Roles': '用户授权角色', + 'pages.admin.security.authorization.user2Roles.authorized': '已授权角色', + 'pages.admin.security.authorization.user2Roles.unauthorized': '未授权角色', + 'pages.admin.security.authorization.resourceWeb2Roles': 'Web 资源分配角色', + 'pages.admin.security.authorization.resourceWeb2Roles.authorized': '已授权角色', + 'pages.admin.security.authorization.resourceWeb2Roles.unauthorized': '未授权角色', 'pages.admin.dept': '部门管理', 'pages.admin.dept.deptName': '名称', diff --git a/scaleph-ui-react/src/locales/zh-CN/pages/metadata.ts b/scaleph-ui-react/src/locales/zh-CN/pages/metadata.ts index f7c380cc0..d0e144300 100644 --- a/scaleph-ui-react/src/locales/zh-CN/pages/metadata.ts +++ b/scaleph-ui-react/src/locales/zh-CN/pages/metadata.ts @@ -3,6 +3,7 @@ export default { 'pages.metadata.dataSource.category': '分类', 'pages.metadata.dataSource.type.logo': '类型 LOGO', + 'pages.metadata.dataSource.info': '数据源', 'pages.metadata.dataSource.info.name': '数据源', 'pages.metadata.dataSource.info.type': '类型', 'pages.metadata.dataSource.info.version': '版本', diff --git a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/ResourceWebAssignRoleForm.tsx b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/ResourceWebAssignRoleForm.tsx new file mode 100644 index 000000000..f47f74f21 --- /dev/null +++ b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/ResourceWebAssignRoleForm.tsx @@ -0,0 +1,171 @@ +import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import {Button, Card, message, Modal, Space, TableColumnsType} from 'antd'; +import {useIntl} from '@umijs/max'; +import mainHeight from '@/models/useMainSize'; +import {ModalFormProps} from "@/typings"; +import {SecResourceWeb} from '@/services/admin/typings'; +import TableTransfer, {DataType} from "@/components/TableTransfer"; +import {AuthorizationService} from "@/services/admin/security/authorization.service"; + +const ResourceWebAssignRoleForm: React.FC> = ({data, visible, onCancel, onOK}) => { + const intl = useIntl(); + const containerInfo = mainHeight('.ant-layout-content'); + const [roleLists, setRoleLists] = useState([]); + + // 角色表格列配置 + const tableColumns: TableColumnsType = [ + { + dataIndex: 'name', + title: intl.formatMessage({id: 'pages.admin.role.name'}), + width: 300, + }, + { + dataIndex: 'desc', + title: intl.formatMessage({id: 'app.common.data.remark'}), + width: 300, + }, + ]; + + // 合并数组 + function mergeArrays(unauthorized: DataType[], authorized: DataType[]): DataType[] { + unauthorized.forEach((obj, index) => { + obj.checkOut = 0; + }); + authorized.forEach((obj, index) => { + obj.checkOut = 1; + }); + return [...unauthorized, ...authorized]; + } + + // 异步获取数据 + const fetchData = useCallback(async () => { + try { + const unauthorized = await AuthorizationService.listUnauthorizedRolesByResourceWebId({resourceWebId: data?.id}) + .then(response => { + return response.data?.records.map(role => { + const dataType: DataType = { + id: role.id, + name: role.name, + status: role.status?.label, + remark: role.remark + } + return dataType; + }) + }); + const authorized = await AuthorizationService.listAuthorizedRolesByResourceWebId({resourceWebId: data?.id}) + .then(response => { + return response.data?.records.map(role => { + const dataType: DataType = { + id: role.id, + name: role.name, + status: role.status?.label, + remark: role.remark + } + return dataType; + }) + }); + if (unauthorized && authorized) { + const mergedArray = mergeArrays(unauthorized, authorized); + setRoleLists(mergedArray); + } + } catch (error) { + console.error(error); + } + }, [data]); + + useEffect(() => { + if (data) { + fetchData(); + } + }, [data, fetchData]); + + // 页面标题 + const returnTitle = useMemo(() => { + return ( + + {` ${intl.formatMessage({id: `menu.${data?.value}`})}-资源分配详情`} + + ); + }, [data, intl]); + + // 获取选中数据的 id 数组 + const originTargetKeys = useMemo(() => { + return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id); + }, [roleLists]); + + // 过滤方法 + const handleFilter = useCallback((inputValue, item) => { + return item?.name.indexOf(inputValue) !== -1; + }, []); + + // 角色转移事件处理 + const handleChange = useCallback( + async (targetKeys, direction, moveKeys) => { + const roleIds = moveKeys.map((item: string | number) => +item); + const params = { + resourceWebId: data?.id, + roleIds: roleIds, + }; + if (direction === 'right') { + // 绑定角色资源 + await AuthorizationService.authorizeResourceWeb2Roles(params).then((res) => { + if (res?.success) { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + } + }); + } else { + // 删除绑定的角色资源 + await AuthorizationService.unauthorizeResourceWeb2Roles(params).then((res) => { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + }); + } + fetchData(); + }, + [data, fetchData, intl], + ); + + return ( + + {intl.formatMessage({id: 'app.common.operate.close.label'})} + , + ]} + > +
+ + record.id} + onChange={handleChange} + filterOption={handleFilter} + listStyle={{ + width: 500, + }} + leftColumns={tableColumns} + rightColumns={tableColumns} + /> + +
+
+ ); +}; + +export default ResourceWebAssignRoleForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/TransferTable.tsx b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/TransferTable.tsx index aabaa9dd4..ac99ae1b3 100644 --- a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/TransferTable.tsx +++ b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/TransferTable.tsx @@ -1,6 +1,7 @@ import React from 'react'; -import { Table, Transfer } from 'antd'; -import { difference } from 'lodash'; // 注意这里改为大写的Difference +import {Transfer} from 'antd'; +import {ProTable} from "@ant-design/pro-components"; +import {difference} from 'lodash'; // 注意这里改为大写的Difference // 定义组件的Props类型 interface Props { @@ -10,35 +11,35 @@ interface Props { } // 使用React.FC声明函数组件,并传入Props类型 -const TableTransfer: React.FC = ({ leftColumns, rightColumns, ...restProps }) => ( +const TableTransfer: React.FC = ({leftColumns, rightColumns, ...restProps}) => ( {({ - direction, - filteredItems, - onItemSelectAll, - onItemSelect, - selectedKeys: listSelectedKeys, - disabled: listDisabled, - }) => { + direction, + filteredItems, + onItemSelectAll, + onItemSelect, + selectedKeys: listSelectedKeys, + disabled: listDisabled, + }) => { const columns = direction === 'left' ? leftColumns : rightColumns; // 表格行选择配置 const rowSelection = { onSelectAll(selected: boolean, selectedRows: any[]) { - const treeSelectedKeys = selectedRows.map(({ key }) => key); + const treeSelectedKeys = selectedRows.map(({key}) => key); const diffKeys = selected ? difference(treeSelectedKeys, listSelectedKeys) : difference(listSelectedKeys, treeSelectedKeys); onItemSelectAll(diffKeys, selected); }, - onSelect: ({ id }: { id: string }, selected: boolean) => { + onSelect: ({id}: { id: string }, selected: boolean) => { onItemSelect(id, selected); }, selectedRowKeys: listSelectedKeys, }; return ( -
= ({ leftColumns, rightColumns, ...restProp pagination={{ defaultPageSize: 20, }} - style={{ pointerEvents: listDisabled ? 'none' : null }} + style={{pointerEvents: listDisabled ? 'none' : null}} /> ); }} diff --git a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/WebAssugnRoles.tsx b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/WebAssugnRoles.tsx deleted file mode 100644 index d3cbc34a5..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/components/WebAssugnRoles.tsx +++ /dev/null @@ -1,170 +0,0 @@ -import mainHeight from '@/models/useMainSize'; -import { SecResourceWeb } from '@/services/admin/typings'; -import { AuthService } from '@/services/auth'; -import { Button, Card, Form, message, Modal, Space } from 'antd'; -import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { useIntl } from '@umijs/max'; -import TableTransfer from './TransferTable'; - -// 定义组件 Props 类型 -interface ModalFormParentProps { - data: T; - visible: boolean; - onVisibleChange?: (visible: boolean) => void; - onCancel: () => void; - onOK?: (values: any) => void; -} - -const WebResourceForm: React.FC> = ({ - data, - visible, - onVisibleChange, - onCancel, -}) => { - const intl = useIntl(); - const [form] = Form.useForm(); - const containerInfo = mainHeight('.ant-layout-content'); - const [roleLists, setRoleLists] = useState([]); - - // 角色表格列配置 - const tableColumns = [ - { - dataIndex: 'name', - title: '角色名称', - width: 300, - }, - { - dataIndex: 'desc', - title: '描述', - width: 300, - }, - ]; - - // 角色类型定义 - interface Role { - id: string; - name: string; - resourceAuthorized: number; - checkOut?: number; - } - - // 合并数组 - function mergeArrays(array1: Role[], array2: Role[]): Role[] { - array1.forEach((obj, index) => { - obj.checkOut = 0; - }); - array2.forEach((obj, index) => { - obj.checkOut = 1; - }); - return [...array1, ...array2]; - } - - // 异步获取数据 - const fetchData = useCallback(async () => { - try { - const res1 = await AuthService.unauthorizedRoles({ resourceWebId: data?.id }); - const res2 = await AuthService.authorizedRoles({ resourceWebId: data?.id }); - if (res1?.records && res2?.records) { - const mergedArray = mergeArrays(res1.records, res2.records); - setRoleLists(mergedArray); - } - } catch (error) { - console.error(error); - } - }, [data]); - - useEffect(() => { - if (data) { - fetchData(); - } - }, [data, fetchData]); - - // 页面标题 - const returnTitle = useMemo(() => { - return ( - - {` ${intl.formatMessage({ id: `menu.${data?.name}` })}-资源分配详情`} - - ); - }, [data, intl]); - - // 获取选中角色的 id 数组 - const originTargetKeys = useMemo(() => { - return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id); - }, [roleLists]); - - // 过滤方法 - const handleFilter = useCallback((inputValue, item) => { - return item?.name.indexOf(inputValue) !== -1; - }, []); - - // 角色转移事件处理 - const handleChange = useCallback( - async (targetKeys, direction, moveKeys) => { - const roleIds = moveKeys.map((item: string | number) => +item); - const params = { - resourceWebId: data?.id, - roleIds: roleIds, - }; - if (direction === 'right') { - // 绑定角色资源 - await AuthService.resourceWebRoles(params).then((res) => { - if (res?.success) { - message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2); - } - }); - } else { - // 删除绑定的角色资源 - await AuthService.resourceWebRolesDelete(params).then((res) => { - message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2); - }); - } - fetchData(); - }, - [data, fetchData, intl], - ); - - return ( - - {intl.formatMessage({ id: 'app.common.operate.close.label' })} - , - ]} - > -
- - record.id} - onChange={handleChange} - filterOption={handleFilter} - listStyle={{ - width: 500, - }} - leftColumns={tableColumns} - rightColumns={tableColumns} - /> - -
-
- ); -}; - -export default WebResourceForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/index.tsx b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/index.tsx index 1fcca9774..3cde962ec 100644 --- a/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/index.tsx +++ b/scaleph-ui-react/src/pages/Admin/Security/Resource/Web/index.tsx @@ -4,12 +4,12 @@ import {DeleteOutlined, EditOutlined, FormOutlined, PlusOutlined} from '@ant-des import {ActionType, PageContainer, ProColumns, ProFormInstance, ProTable} from '@ant-design/pro-components'; import {useAccess, useIntl} from '@umijs/max'; import {PRIVILEGE_CODE} from '@/constants/privilegeCode'; -import WebAssugnRoles from '@/pages/Admin/Security/Resource/Web/components/WebAssugnRoles'; import WebResourceForm from '@/pages/Admin/Security/Resource/Web/components/WebResourceForm'; import {PrivilegeService} from '@/services/admin/privilege.service'; import {ResourceWebService} from '@/services/admin/security/resourceWeb.service'; import {SecResourceWeb} from '@/services/admin/typings'; import {isEmpty} from 'lodash'; +import ResourceWebAssignRoleForm from "@/pages/Admin/Security/Resource/Web/components/ResourceWebAssignRoleForm"; const WebResourceWeb: React.FC = () => { const intl = useIntl(); @@ -39,7 +39,6 @@ const WebResourceWeb: React.FC = () => { { title: intl.formatMessage({id: 'pages.admin.resource.type'}), dataIndex: 'type', - width: 120, render: (dom, entity) => { return {entity.type?.label}; }, @@ -238,11 +237,11 @@ const WebResourceWeb: React.FC = () => { )} {webAssignRoles.visiable && ( - setWebAssignRoles({visiable: false, data: {}})} - onVisibleChange={(visiable) => { - setWebAssignRoles({visiable: visiable, data: {}}); + onOK={(values) => { + setWebAssignRoles({visiable: false, data: {}}); actionRef.current?.reload(); }} data={webAssignRoles.data} diff --git a/scaleph-ui-react/src/pages/Admin/Security/Role/components/ResourceWebs.tsx b/scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignResourceWebForm.tsx similarity index 61% rename from scaleph-ui-react/src/pages/Admin/Security/Role/components/ResourceWebs.tsx rename to scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignResourceWebForm.tsx index 22088fc58..08daa3da6 100644 --- a/scaleph-ui-react/src/pages/Admin/Security/Role/components/ResourceWebs.tsx +++ b/scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignResourceWebForm.tsx @@ -1,38 +1,32 @@ -import {SecResourceWeb} from '@/services/admin/typings'; -import {AuthService} from '@/services/auth'; +import React, {useCallback, useEffect, useState} from 'react'; import {message, Modal, Tree} from 'antd'; import type {TreeProps} from 'antd/es/tree'; -import React, {useCallback, useEffect, useState} from 'react'; import {useIntl} from '@umijs/max'; -import {ResponseBody} from '@/typings'; +import {ModalFormProps} from '@/typings'; +import {SecResourceWeb, SecRole} from '@/services/admin/typings'; +import {AuthorizationService} from "@/services/admin/security/authorization.service"; -// 定义组件 Props 类型 -interface ModalFormParentProps { - data: T; - visible: boolean; - onVisibleChange?: (visible: boolean) => void; - onCancel: () => void; - onOK?: (values: any) => void; +// 树节点类型 +interface TreeNode { + key: number; + title: string; + authorized?: string | number; + children?: TreeNode[]; } -// WebResourceForm 组件 -const WebResourceForm: React.FC> = ({ - data, - visible, - onCancel, - }) => { +const RoleAssignResourceWebForm: React.FC> = ({data, visible, onCancel}) => { const intl = useIntl(); - const [roleLists, setRoleLists] = useState([]); + const [treeData, setTreeData] = useState([]); const [menuId, setMenuId] = useState([]); const [menuIdTotal, setMenuIdTotal] = useState([]); // 数据转换函数 - function convertData(data: any[] | ResponseBody): any[] { - return data.map((item) => { - const newItem = { - title: item.name, - key: String(item.id), - authorized: item.authorized.value, + function convertData(secResourceWebList: SecResourceWeb[]): any[] { + return secResourceWebList.map((item) => { + const newItem: TreeNode = { + key: item.id, + title: item.label, + authorized: item.authorized?.value }; if (item.children && item.children.length > 0) { newItem.children = convertData(item.children); @@ -41,16 +35,8 @@ const WebResourceForm: React.FC> = ({ }); } - // 树节点类型 - interface TreeNode { - title: string; - key: number; - authorized: boolean; - children?: TreeNode[]; - } - // 根据权限值查找节点的键 - function findKeysByAuthorized(data: TreeNode[], authorizedValue: boolean): number[] { + function findKeysByAuthorized(data: TreeNode[], authorizedValue: string): number[] { const result: number[] = []; function traverse(node: TreeNode) { @@ -69,10 +55,10 @@ const WebResourceForm: React.FC> = ({ // 异步获取数据 const fetchData = useCallback(async () => { try { - const res1 = await AuthService.requestResourceWebs({roleId: data?.id}); - const treeData = convertData(res1); + const secResourceWebList = await AuthorizationService.requestResourceWebs({roleId: data?.id}).then(response => response.data); + const treeData = convertData(secResourceWebList); const filteredIds = findKeysByAuthorized(treeData, '1'); - setRoleLists(res1 || []); + setTreeData(treeData || []); setMenuId(filteredIds || []); setMenuIdTotal(filteredIds || []); } catch (error) { @@ -97,7 +83,7 @@ const WebResourceForm: React.FC> = ({ const extraValues = menuId.filter((item) => !menuIdTotal.includes(item)); // 批量为角色绑定 if (diffValues.length !== 0) { - await AuthService.requestDeleteRoleResourceWebs({ + await AuthorizationService.requestDeleteRoleResourceWebs({ roleId: data?.id, resourceWebIds: diffValues, }).then((res) => { @@ -108,7 +94,7 @@ const WebResourceForm: React.FC> = ({ } if (extraValues.length !== 0) { - await AuthService.requestRoleResourceWebs({ + await AuthorizationService.requestRoleResourceWebs({ roleId: data?.id, resourceWebIds: extraValues, }).then((res) => { @@ -123,7 +109,7 @@ const WebResourceForm: React.FC> = ({ return ( > = ({ checkable onCheck={onCheck} checkedKeys={menuId} - treeData={roleLists} + treeData={treeData} defaultExpandAll - fieldNames={{ - title: 'name', - key: 'id', - children: 'children', - }} /> ); }; -export default WebResourceForm; +export default RoleAssignResourceWebForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignUserForm.tsx b/scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignUserForm.tsx new file mode 100644 index 000000000..2744e85ea --- /dev/null +++ b/scaleph-ui-react/src/pages/Admin/Security/Role/components/RoleAssignUserForm.tsx @@ -0,0 +1,167 @@ +import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import {Button, Card, message, Modal, Space, TableColumnsType} from 'antd'; +import {useIntl} from '@umijs/max'; +import mainHeight from '@/models/useMainSize'; +import {ModalFormProps} from "@/typings"; +import {SecRole} from '@/services/admin/typings'; +import TableTransfer, {DataType} from "@/components/TableTransfer"; +import {AuthorizationService} from "@/services/admin/security/authorization.service"; + +const RoleAssignUserForm: React.FC> = ({data, visible, onCancel}) => { + const intl = useIntl(); + const containerInfo = mainHeight('.ant-layout-content'); + const [userLists, setUserLists] = useState([]); + + // 角色表格列配置 + const tableColumns: TableColumnsType = [ + { + dataIndex: 'name', + title: intl.formatMessage({id: 'pages.admin.user.nickName'}), + width: 300, + }, + { + dataIndex: 'desc', + title: intl.formatMessage({id: 'app.common.data.remark'}), + width: 300, + }, + ]; + + // 合并数组 + function mergeArrays(unauthorized: DataType[], authorized: DataType[]): DataType[] { + unauthorized.forEach((obj, index) => { + obj.checkOut = 0; + }); + authorized.forEach((obj, index) => { + obj.checkOut = 1; + }); + return [...unauthorized, ...authorized]; + } + + // 异步获取数据 + const fetchData = useCallback(async () => { + try { + const unauthorized = await AuthorizationService.listUnauthorizedUsersByRoleId({roleId: data?.id}) + .then(response => { + return response.data?.records.map(user => { + const dataType: DataType = { + id: user.id, + name: user.nickName, + remark: user.remark + } + return dataType; + }) + }); + const authorized = await AuthorizationService.listAuthorizedUsersByRoleId({roleId: data?.id}) + .then(response => { + return response.data?.records.map(user => { + const dataType: DataType = { + id: user.id, + name: user.nickName, + remark: user.remark + } + return dataType; + }) + }); + if (unauthorized && authorized) { + const mergedArray = mergeArrays(unauthorized, authorized); + setUserLists(mergedArray); + } + } catch (error) { + console.error(error); + } + }, [data]); + + useEffect(() => { + if (data) { + fetchData(); + } + }, [data, fetchData]); + + // 页面标题 + const returnTitle = useMemo(() => { + return ( + + {` ${data?.name}-角色分配详情`} + + ); + }, [data, intl]); + + // 获取选中数据的 id 数组 + const originTargetKeys = useMemo(() => { + return userLists?.filter((item) => item.checkOut === 1).map((item) => item.id); + }, [userLists]); + + // 过滤方法 + const handleFilter = useCallback((inputValue, item) => { + return item?.name.indexOf(inputValue) !== -1; + }, []); + + // 角色转移事件处理 + const handleChange = useCallback( + async (targetKeys, direction, moveKeys) => { + const userIds = moveKeys.map((item: string | number) => +item); + const params = { + roleId: data?.id, + userIds: userIds, + }; + if (direction === 'right') { + // 批量为角色绑定用户 + await AuthorizationService.authorizeRole2Users(params).then((res) => { + if (res?.success) { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + } + }); + } else { + // 批量为角色解除用户绑定 + await AuthorizationService.unauthorizeRole2Users(params).then((res) => { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + }); + } + fetchData(); + }, + [data, fetchData, intl], + ); + + return ( + + {intl.formatMessage({id: 'app.common.operate.close.label'})} + , + ]} + > + + record.id} + onChange={handleChange} + filterOption={handleFilter} + listStyle={{ + width: 500, + }} + leftColumns={tableColumns} + rightColumns={tableColumns} + /> + + + ); +}; + +export default RoleAssignUserForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/Role/components/WebAssugnRoles.tsx b/scaleph-ui-react/src/pages/Admin/Security/Role/components/WebAssugnRoles.tsx deleted file mode 100644 index 76c8fd263..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/Role/components/WebAssugnRoles.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import React, {useCallback, useEffect, useMemo, useState} from 'react'; -import {Card, message, Modal} from 'antd'; -import {useIntl} from '@umijs/max'; -import mainHeight from '@/models/useMainSize'; -import TableTransfer from '@/pages/Admin/Security/Resource/Web/components/TransferTable'; -import {SecRole} from '@/services/admin/typings'; -import {AuthService} from '@/services/auth'; -import {AuthorizationService} from "@/services/admin/security/authorization.service"; -import {ModalFormProps} from "@/typings"; - -const WebResourceForm: React.FC> = ({data, visible, onCancel, onOK}) => { - const intl = useIntl(); - const containerInfo = mainHeight('.ant-layout-content'); - const [roleLists, setRoleLists] = useState([]); - - // 角色表格列配置 - const tableColumns = [ - { - dataIndex: 'nickName', - title: intl.formatMessage({id: 'pages.admin.user.nickName'}), - width: 300, - }, - { - dataIndex: 'remark', - title: intl.formatMessage({id: 'app.common.data.remark'}), - width: 300, - }, - ]; - - // 角色类型定义 - interface Role { - id: string; - name: string; - resourceAuthorized: number; - checkOut?: number; - } - - // 合并数组 - function mergeArrays(array1: Role[], array2: Role[]): Role[] { - array1.forEach((obj, index) => { - obj.checkOut = 0; - }); - array2.forEach((obj, index) => { - obj.checkOut = 1; - }); - return [...array1, ...array2]; - } - - // 异步获取数据 - const fetchData = useCallback(async () => { - try { - const res1 = await AuthorizationService.requestUnauthorizedUsers({roleId: data?.id}); - const res2 = await AuthorizationService.requestAuthorizedUsers({roleId: data?.id}); - if (res1?.success && res1?.data && res2?.success && res2?.data) { - const mergedArray = mergeArrays(res1?.data?.records, res2?.data?.records); - setRoleLists(mergedArray); - } - } catch (error) { - console.error(error); - } - }, [data]); - - useEffect(() => { - if (data) { - fetchData(); - } - }, [data, fetchData]); - - // 获取选中角色的 id 数组 - const originTargetKeys = useMemo(() => { - return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id); - }, [roleLists]); - - // 过滤方法 - const handleFilter = useCallback((inputValue, item) => { - return item?.name.indexOf(inputValue) !== -1; - }, []); - - // 角色转移事件处理 - const handleChange = useCallback( - async (targetKeys, direction, moveKeys) => { - const roleIds = moveKeys.map((item: string | number) => +item); - const params = { - roleId: data?.id, - userIds: roleIds, - }; - if (direction === 'right') { - // 批量为角色绑定用户 - await AuthorizationService.rolesUser(params).then((res) => { - if (res?.success) { - message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); - } - }); - } else { - // 批量为角色解除用户绑定 - await AuthorizationService.deleteRolesUser(params).then((res) => { - message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); - }); - } - fetchData(); - }, - [data, fetchData, intl], - ); - - return ( - - - record.id} - onChange={handleChange} - filterOption={handleFilter} - listStyle={{ - width: 500, - }} - leftColumns={tableColumns} - rightColumns={tableColumns} - /> - - - ); -}; - -export default WebResourceForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/Role/index.tsx b/scaleph-ui-react/src/pages/Admin/Security/Role/index.tsx index e5404dc85..8b7f641c7 100644 --- a/scaleph-ui-react/src/pages/Admin/Security/Role/index.tsx +++ b/scaleph-ui-react/src/pages/Admin/Security/Role/index.tsx @@ -9,8 +9,8 @@ import {SysDictService} from "@/services/admin/system/sysDict.service"; import {RoleService} from '@/services/admin/security/role.service'; import {SecRole} from '@/services/admin/typings'; import RoleForm from '@/pages/Admin/Security/Role/components/RoleForm'; -import WebAssugnRoles from './components/WebAssugnRoles'; -import ResourceWebs from './components/ResourceWebs'; +import RoleAssignUserForm from "@/pages/Admin/Security/Role/components/RoleAssignUserForm"; +import RoleAssignResourceWebForm from "@/pages/Admin/Security/Role/components/RoleAssignResourceWebForm"; const RoleWeb: React.FC = () => { const intl = useIntl(); @@ -23,15 +23,15 @@ const RoleWeb: React.FC = () => { data: SecRole; }>({visiable: false, data: {}}); - const [webAssignRoles, setWebAssignRoles] = useState<{ + const [roleAssignUser, setRoleAssignUser] = useState<{ visiable: boolean; data: SecRole; }>({visiable: false, parent: {}, data: {}}); - const [resourceWebs, setResourceWebs] = useState<{ + const [roleAssginResourceWeb, setRoleAssginResourceWeb] = useState<{ visiable: boolean; data: SecRole; - }>({visiable: false, parent: {}, data: {}}); + }>({visiable: false, data: {}}); const tableColumns: ProColumns[] = [ { @@ -101,7 +101,7 @@ const RoleWeb: React.FC = () => { shape="default" type="link" icon={} - onClick={() => setWebAssignRoles({visiable: true, data: record})} + onClick={() => setRoleAssignUser({visiable: true, data: record})} /> )} @@ -111,7 +111,7 @@ const RoleWeb: React.FC = () => { shape="default" type="link" icon={} - onClick={() => setResourceWebs({visiable: true, data: record})} + onClick={() => setRoleAssginResourceWeb({visiable: true, data: record})} /> )} @@ -233,23 +233,18 @@ const RoleWeb: React.FC = () => { data={roleFormData.data} /> )} - {webAssignRoles.visiable && ( - setWebAssignRoles({visiable: false, data: {}})} - onOK={(values) => setWebAssignRoles({visiable: false, data: {}})} - data={webAssignRoles.data} + {roleAssignUser.visiable && ( + setRoleAssignUser({visiable: false, data: {}})} + data={roleAssignUser.data} /> )} - {resourceWebs.visiable && ( - setResourceWebs({visiable: false, data: {}})} - onVisibleChange={(visiable) => { - setResourceWebs({visiable: visiable, data: {}}); - actionRef.current?.reload(); - }} - data={resourceWebs.data} + {roleAssginResourceWeb.visiable && ( + setRoleAssginResourceWeb({visiable: false, data: {}})} + data={roleAssginResourceWeb.data} /> )} diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/components/DeptGrant.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/components/DeptGrant.tsx deleted file mode 100644 index 1cf06d2aa..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/User/components/DeptGrant.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { DeptService } from '@/services/admin/security/dept.service'; -import { SecDept, SecUser } from '@/services/admin/typings'; -import { UserService } from '@/services/admin/security/user.service'; -import { message, Modal, Transfer } from 'antd'; -import { useEffect, useState } from 'react'; -import { useIntl } from '@umijs/max'; -import {ModalFormProps} from '@/typings'; - -const DeptGrant: React.FC> = ({ - data, - visible, - onVisibleChange, - onCancel, -}) => { - const intl = useIntl(); - const [targetKeys, setTargetKeys] = useState([]); - const [selectedKeys, setSelectedKeys] = useState([]); - const [userList, setUserList] = useState([]); - - useEffect(() => { - //all user list limit 100000 - UserService.listUserByPage({ current: 1, pageSize: 100000 }).then((resp) => { - setUserList(resp.data); - }); - //user granted with dept id - UserService.listByUserNameAndDept('', data.id + '', '1').then((resp) => { - setTargetKeys(resp.map((item) => item.value)); - }); - }, []); - - const onSelectChange = (sourceSelectedKeys: string[], targetSelectedKeys: string[]) => { - setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]); - }; - - const onChange = (nextTargetKeys: string[]) => { - setTargetKeys(nextTargetKeys); - }; - - return ( - { - DeptService.grantDeptToUsers(data.id + '', targetKeys).then((d) => { - if (d.success) { - message.success(intl.formatMessage({ id: 'app.common.operate.success' })); - } - }); - onVisibleChange(false); - }} - > - item.userName + ''} - rowKey={(item) => item.id + ''} - > - - ); -}; - -export default DeptGrant; diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleForm.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleForm.tsx deleted file mode 100644 index 77f34410e..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleForm.tsx +++ /dev/null @@ -1,135 +0,0 @@ -import {useEffect, useState} from 'react'; -import {Form, Input, message, Modal, Select} from 'antd'; -import {useIntl} from '@umijs/max'; -import {DICT_TYPE} from '@/constants/dictType'; -import {DictDataService} from '@/services/admin/dictData.service'; -import {RoleService} from '@/services/admin/security/role.service'; -import {SecRole} from '@/services/admin/typings'; -import {Dict, ModalFormProps} from '@/typings'; - -const RoleForm: React.FC> = ({ - data, - visible, - onVisibleChange, - onCancel - }) => { - const intl = useIntl(); - const [form] = Form.useForm(); - const [roleStatusList, setRoleStatusList] = useState([]); - - useEffect(() => { - DictDataService.listDictDataByType2(DICT_TYPE.roleStatus).then((d) => { - setRoleStatusList(d); - }); - }, []); - - return ( - { - form.validateFields().then((values) => { - let role: SecRole = { - id: values.id, - roleCode: values.roleCode, - roleName: values.roleName, - roleStatus: {value: values.roleStatus}, - roleDesc: values.roleDesc, - }; - data.id - ? RoleService.updateRole({...role}).then((d) => { - if (d.success) { - message.success(intl.formatMessage({id: 'app.common.operate.edit.success'})); - onVisibleChange(false); - } - }) - : RoleService.addRole({...role}).then((d) => { - if (d.success) { - message.success(intl.formatMessage({id: 'app.common.operate.new.success'})); - onVisibleChange(false); - } - }); - }); - }} - > -
- - - - - - - - - - - - - - -
- ); -}; - -export default RoleForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleGrant.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleGrant.tsx deleted file mode 100644 index 9cbbb2cfe..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/User/components/RoleGrant.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import {useEffect, useState} from 'react'; -import {message, Modal, Transfer} from 'antd'; -import {useIntl} from '@umijs/max'; -import {RoleService} from '@/services/admin/security/role.service'; -import {SecRole, SecUser} from '@/services/admin/typings'; -import {UserService} from '@/services/admin/security/user.service'; -import {ModalFormProps} from '@/typings'; - -const RoleGrant: React.FC> = ({ - data, - visible, - onVisibleChange, - onCancel - }) => { - const intl = useIntl(); - const [targetKeys, setTargetKeys] = useState([]); - const [selectedKeys, setSelectedKeys] = useState([]); - const [userList, setUserList] = useState([]); - - useEffect(() => { - //all user list limit 100000 - UserService.listUserByPage({current: 1, pageSize: 100000}).then((resp) => { - setUserList(resp.data); - }); - //user granted with role id - UserService.listByUserNameAndRole('', data.id + '', '1').then((resp) => { - setTargetKeys(resp.map((item) => item.value)); - }); - }, []); - - const onSelectChange = (sourceSelectedKeys: string[], targetSelectedKeys: string[]) => { - setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]); - }; - - const onChange = (nextTargetKeys: string[]) => { - setTargetKeys(nextTargetKeys); - }; - - return ( - { - RoleService.grantRoleToUsers(data.id + '', targetKeys).then((d) => { - if (d.success) { - message.success(intl.formatMessage({id: 'app.common.operate.success'})); - } - }); - onVisibleChange(false); - }} - > - item.userName + ''} - rowKey={(item) => item.id + ''} - > - - ); -}; - -export default RoleGrant; diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/components/UserAssignRoleForm.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/components/UserAssignRoleForm.tsx new file mode 100644 index 000000000..b840ba2d9 --- /dev/null +++ b/scaleph-ui-react/src/pages/Admin/Security/User/components/UserAssignRoleForm.tsx @@ -0,0 +1,171 @@ +import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import {Button, Card, message, Modal, Space, TableColumnsType, Tag} from 'antd'; +import {useIntl} from '@umijs/max'; +import mainHeight from '@/models/useMainSize'; +import {ModalFormProps} from "@/typings"; +import {SecUser} from '@/services/admin/typings'; +import TableTransfer, {DataType} from "@/components/TableTransfer"; +import {AuthorizationService} from "@/services/admin/security/authorization.service"; + +const UserAssignRoleForm: React.FC> = ({data, visible, onCancel}) => { + const intl = useIntl(); + const containerInfo = mainHeight('.ant-layout-content'); + const [roleLists, setRoleLists] = useState([]); + + // 角色表格列配置 + const tableColumns: TableColumnsType = [ + { + dataIndex: 'name', + title: intl.formatMessage({id: 'pages.admin.role.name'}), + width: 300, + }, + { + dataIndex: 'desc', + title: intl.formatMessage({id: 'app.common.data.remark'}), + width: 300, + }, + ]; + + // 合并数组 + function mergeArrays(unauthorized: DataType[], authorized: DataType[]): any { + unauthorized.forEach((obj, index: any) => { + obj.checkOut = 0; + }); + authorized.forEach((obj, index: any) => { + obj.checkOut = 1; + }); + return [...unauthorized, ...authorized]; + } + + // 异步获取数据 + const fetchData = useCallback(async () => { + try { + const unauthorized = await AuthorizationService.listUnauthorizedRolesByUserId({userId: data?.id}) + .then(response => { + return response.data?.records.map(role => { + const dataType: DataType = { + id: role.id, + name: role.name, + status: role.status?.label, + remark: role.remark + } + return dataType; + }) + }); + const authorized = await AuthorizationService.listAuthorizedRolesByUserId({userId: data?.id}) + .then(response => { + return response.data?.records.map(role => { + const dataType: DataType = { + id: role.id, + name: role.name, + status: role.status?.label, + remark: role.remark + } + return dataType; + }) + }); + if (unauthorized && authorized) { + const mergedArray = mergeArrays(unauthorized, authorized); + setRoleLists(mergedArray); + } + } catch (error) { + console.error(error); + } + }, [data]); + + useEffect(() => { + if (data) { + fetchData(); + } + }, [data, fetchData]); + + // 页面标题 + const returnTitle = useMemo(() => { + return ( + + {` ${data?.nickName}-用户授权详情`} + + ); + }, [data, intl]); + + // 获取选中角色的 id 数组 + const originTargetKeys = useMemo(() => { + return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id); + }, [roleLists]); + + // 过滤方法 + const handleFilter = useCallback((inputValue, item) => { + return item?.name.indexOf(inputValue) !== -1; + }, []); + + // 角色转移事件处理 + const handleChange = useCallback( + async (targetKeys, direction, moveKeys) => { + const roleIds = moveKeys.map((item: string | number) => +item); + const params = { + userId: data?.id, + roleIds: roleIds, + }; + if (direction === 'right') { + // 批量为角色绑定用户 + await AuthorizationService.authorizeUser2Roles(params).then((res) => { + if (res?.success) { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + } + }); + } else { + // 批量为角色解除用户绑定 + await AuthorizationService.unauthorizeUser2Roles(params).then((res) => { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'}), 2); + }); + } + fetchData(); + }, + [data, fetchData, intl], + ); + + return ( + + {intl.formatMessage({id: 'app.common.operate.close.label'})} + , + ]} + > +
+ + record.id} + onChange={handleChange} + filterOption={handleFilter} + listStyle={{ + width: 500, + }} + leftColumns={tableColumns} + rightColumns={tableColumns} + /> + +
+
+ ); +}; + +export default UserAssignRoleForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/components/UserRoles.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/components/UserRoles.tsx deleted file mode 100644 index 495c8aaef..000000000 --- a/scaleph-ui-react/src/pages/Admin/Security/User/components/UserRoles.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { Button, Card, Form, message, Modal, Space } from 'antd'; -import { useIntl } from '@umijs/max'; -import mainHeight from '@/models/useMainSize'; -import TableTransfer from '@/pages/Admin/Security/Resource/Web/components/TransferTable'; -import { SecResourceWeb } from '@/services/admin/typings'; -import { AuthService } from '@/services/auth'; - -// 定义组件 Props 类型 -interface ModalFormParentProps { - data: T; - visible: boolean; - onVisibleChange?: (visible: boolean) => void; - onCancel: () => void; - onOK?: (values: any) => void; -} - -const WebResourceForm: React.FC> = ({ - data, - visible, - onVisibleChange, - onCancel, -}) => { - const intl = useIntl(); - const [form] = Form.useForm(); - const containerInfo = mainHeight('.ant-layout-content'); - const [roleLists, setRoleLists] = useState([]); - - // 角色表格列配置 - const tableColumns = [ - { - dataIndex: 'name', - title: '角色名称', - width: 300, - }, - { - dataIndex: 'status.label', - title: '角色状态', - width: 300, - render: (text: any, record: { status: { label: boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null | undefined; }; }) => ( - {record.status.label} - ), - }, - ]; - - // 角色类型定义 - interface Role { - id: string; - name: string; - resourceAuthorized: number; - checkOut?: number; - } - - // 合并数组 - function mergeArrays(array1: any, array2: any): any { - array1.forEach((obj: { checkOut: number; }, index: any) => { - obj.checkOut = 0; - }); - array2.forEach((obj: { checkOut: number; }, index: any) => { - obj.checkOut = 1; - }); - return [...array1, ...array2]; - } - // 异步获取数据 - const fetchData = useCallback(async () => { - try { - const res1 = await AuthService.requestUnauthorizedRoles({ userId: data?.id }); - const res2 = await AuthService.requestUserAuthorizedRoles({ userId: data?.id }); - if (res1 && res2) { - const mergedArray = mergeArrays(res1, res2); - setRoleLists(mergedArray); - } - } catch (error) { - console.error(error); - } - }, [data]); - - useEffect(() => { - if (data) { - fetchData(); - } - }, [data, fetchData]); - - // 页面标题 - const returnTitle = useMemo(() => { - return ( - - {` ${intl.formatMessage({ id: `menu.${data?.userName}` })}-${intl.formatMessage({ id: 'app.common.operate.new.roles' })}`} - - ); - }, [data, intl]); - - // 获取选中角色的 id 数组 - const originTargetKeys = useMemo(() => { - return roleLists?.filter((item) => item.checkOut === 1).map((item) => item.id); - }, [roleLists]); - - // 过滤方法 - const handleFilter = useCallback((inputValue, item) => { - return item?.name.indexOf(inputValue) !== -1; - }, []); - - // 角色转移事件处理 - const handleChange = useCallback( - async (targetKeys, direction, moveKeys) => { - const roleIds = moveKeys.map((item: string | number) => +item); - const params = { - userId: data?.id, - roleIds: roleIds, - }; - if (direction === 'right') { - // 批量为角色绑定用户 - await AuthService.requestUserRoles(params).then((res) => { - if (res?.success) { - message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2); - } - }); - } else { - // 批量为角色解除用户绑定 - await AuthService.requestDeleteUserRoles(params).then((res) => { - message.success(intl.formatMessage({ id: 'app.common.operate.edit.success' }), 2); - }); - } - fetchData(); - }, - [data, fetchData, intl], - ); - - return ( - - {intl.formatMessage({ id: 'app.common.operate.close.label' })} - , - ]} - > -
- - record.id} - onChange={handleChange} - filterOption={handleFilter} - listStyle={{ - width: 500, - }} - leftColumns={tableColumns} - rightColumns={tableColumns} - /> - -
-
- ); -}; - -export default WebResourceForm; diff --git a/scaleph-ui-react/src/pages/Admin/Security/User/index.tsx b/scaleph-ui-react/src/pages/Admin/Security/User/index.tsx index 83c2be3f1..dee51edab 100644 --- a/scaleph-ui-react/src/pages/Admin/Security/User/index.tsx +++ b/scaleph-ui-react/src/pages/Admin/Security/User/index.tsx @@ -1,36 +1,30 @@ import {useAccess, useIntl} from '@umijs/max'; -import React, {useEffect, useRef, useState} from 'react'; +import React, {useRef, useState} from 'react'; import {Button, message, Modal, Space, Tag, Tooltip,} from 'antd'; import {DeleteOutlined, EditOutlined, FormOutlined} from '@ant-design/icons'; import {ActionType, PageContainer, ProColumns, ProFormInstance, ProTable} from '@ant-design/pro-components'; import {DICT_TYPE} from '@/constants/dictType'; import {PRIVILEGE_CODE} from '@/constants/privilegeCode'; import {SysDictService} from "@/services/admin/system/sysDict.service"; -import {DeptService} from '@/services/admin/security/dept.service'; -import {RoleService} from '@/services/admin/security/role.service'; -import {SecRole, SecUser} from '@/services/admin/typings'; +import {SecUser} from '@/services/admin/typings'; import {UserService} from '@/services/admin/security/user.service'; -import {TreeNode} from '@/typings'; import UserForm from "@/pages/Admin/Security/User/components/UserForm"; - +import UserAssignRoleForm from "@/pages/Admin/Security/User/components/UserAssignRoleForm"; const User: React.FC = () => { const intl = useIntl(); const access = useAccess(); const actionRef = useRef(); const formRef = useRef(); - const [roleList, setRoleList] = useState([]); - const [deptTreeList, setDeptTreeList] = useState([]); const [selectedRows, setSelectedRows] = useState([]); - const [userFormData, setUserFormData] = useState<{ visible: boolean; data: SecUser }>({ visible: false, data: {}, }); - const [webAssignRoles, setWebAssignRoles] = useState<{ + const [userAssignRole, setUserAssignRole] = useState<{ visiable: boolean; - data: SecRole; - }>({visiable: false, parent: {}, data: {}}); + data: SecUser; + }>({visiable: false, data: {}}); const tableColumns: ProColumns[] = [ { @@ -106,7 +100,7 @@ const User: React.FC = () => { shape="default" type="link" icon={} - onClick={() => setWebAssignRoles({visiable: true, data: record})} + onClick={() => setUserAssignRole({visiable: true, data: record})} /> )} @@ -159,37 +153,6 @@ const User: React.FC = () => { }, ]; - //init data - useEffect(() => { - refreshRoles(); - refreshDepts(); - }, []); - - const refreshRoles = () => { - RoleService.listAllRole().then((d) => { - setRoleList(d); - }); - }; - - const refreshDepts = () => { - DeptService.listAllDept().then((d) => { - setDeptTreeList(DeptService.buildTree(d)); - }); - }; - - let keys: React.Key[] = []; - const buildExpandKeys = (data: TreeNode[], value: string): React.Key[] => { - data.forEach((dept) => { - if (dept.children) { - buildExpandKeys(dept.children, value); - } - if (dept.title?.toString().includes(value)) { - keys.push(dept.key + ''); - } - }); - return keys; - }; - return ( @@ -271,6 +234,15 @@ const User: React.FC = () => { data={userFormData.data} /> ) : null} + {userAssignRole.visiable ? ( + { + setUserAssignRole({visiable: false, data: {}}); + }} + data={userAssignRole.data} + /> + ) : null} ); }; diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/DataSourceUpdateForm.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/DataSourceUpdateForm.tsx new file mode 100644 index 000000000..2cd295ec0 --- /dev/null +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/DataSourceUpdateForm.tsx @@ -0,0 +1,54 @@ +import React from "react"; +import {Form, message, Modal} from 'antd'; +import {ProForm, ProFormText} from "@ant-design/pro-components"; +import {useIntl} from '@umijs/max'; +import {ModalFormProps} from '@/typings'; +import {DsInfo} from "@/services/datasource/typings"; +import {DsInfoService} from "@/services/datasource/info.service"; +import DataSourceForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/DataSourceForm"; + +const DataSourceUpdateForm: React.FC> = ({data, visible, onOK, onCancel}) => { + const intl = useIntl(); + const [form] = Form.useForm(); + + return ( + { + form.validateFields().then((values) => { + DsInfoService.update(data.id, {...values}).then((resp) => { + if (resp.success) { + message.success(intl.formatMessage({id: 'app.common.operate.edit.success'})); + if (onOK) { + onOK(values); + } + } + }) + }); + }} + > + + + + ); +}; + +export default DataSourceUpdateForm; diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/DataSourceType.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/DataSourceType.tsx index 74678e0d8..8217e3fa4 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/DataSourceType.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/DataSourceType.tsx @@ -1,9 +1,9 @@ +import {useEffect, useRef, useState} from "react"; +import {useModel} from "@umijs/max"; +import {Image} from "antd"; import {ActionType, ProFormInstance, ProList, ProListMetas} from "@ant-design/pro-components"; import {DsType} from "@/services/datasource/typings"; -import {useEffect, useRef, useState} from "react"; import {DsCategoryService} from "@/services/datasource/category.service"; -import {Image} from "antd"; -import {useModel} from "@umijs/max"; const DataSourceTypeWeb: React.FC<{ categoryId?: number, onTypeSelect: () => void }> = ({ categoryId, diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Cassandra.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Cassandra.tsx index 31bc4327c..d2544d56c 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Cassandra.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Cassandra.tsx @@ -1,64 +1,20 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const CassandraForm: React.FC = () => { +const CassandraForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { initialValue={"localhost:9042"} /> diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/ClickHouse.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/ClickHouse.tsx index 77a3e5b6c..e6d57c8c7 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/ClickHouse.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/ClickHouse.tsx @@ -1,85 +1,41 @@ -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {useIntl, useModel} from "@umijs/max"; -import {DsCategoryService} from "@/services/datasource/category.service"; -import {useEffect} from "react"; -import {Form} from "antd"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const ClickHouseForm: React.FC = () => { +const ClickHouseForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + = ({prefix, type}) => { + const intl = useIntl(); + const form = Form.useFormInstance() + + useEffect(() => { + form.setFieldValue([prefix, "type"], type?.type?.value) + form.setFieldValue("dsTypeId", type?.id) + }, []) + + return ( + + + ); +} + +export default CommonItem; diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/DataHub.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/DataHub.tsx index 6dbbf19c6..33e56d736 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/DataHub.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/DataHub.tsx @@ -1,76 +1,32 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const DataHubForm: React.FC = () => { +const DataHubForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const DataSourceForm: React.FC = ({prefix, type}) => { - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - const formView = (type?: DsType) => { + const formView = () => { if (type?.type.value) { switch (type?.type.value) { case 'MySQL': @@ -44,63 +39,63 @@ const DataSourceForm: React.FC = () => { case 'GBase8a': case 'Greenplum': case 'Phoenix': - return + return case 'Ftp': - return + return case 'Sftp': - return + return case 'OSS': - return + return case 'OSSJindo': - return + return case 'S3': - return + return case 'HDFS': - return + return case 'Hive': - return + return case 'Redis': - return + return case 'Elasticsearch': - return + return case 'MongoDB': - return + return case 'Cassandra': - return + return case 'Kafka': - return + return case 'Pulsar': - return + return case 'DataHub': - return + return case 'Doris': - return + return case 'StarRocks': - return + return case 'ClickHouse': - return + return case 'Kudu': - return + return case 'MaxCompute': - return + return case 'IoTDB': - return + return case 'Neo4j': - return + return case 'InfluxDB': - return + return case 'Socket': - return + return case 'Http': - return + return default: - return + return } } return
动态渲染数据源表单失败
} - return (
{formView(dsType)}
); + return (
{formView()}
); } export default DataSourceForm; diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Doris.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Doris.tsx index 6ba1fe5fc..ec42f789c 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Doris.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Doris.tsx @@ -1,64 +1,20 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormDigit, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const DorisForm: React.FC = () => { +const DorisForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { initialValue={"localhost:8030"} /> { +const ElasticsearchForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Ftp.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Ftp.tsx index 587849caa..561c89c36 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Ftp.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/Ftp.tsx @@ -1,71 +1,27 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormDigit, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const FtpForm: React.FC = () => { +const FtpForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { }} /> { +const GenericForm: React.FC = ({prefix, type}) => { const intl = useIntl(); const formRef = useRef(); @@ -14,10 +15,16 @@ const GenericForm: React.FC = () => { })); useEffect(() => { - formRef.current?.setFieldValue("dsTypeId", dsType?.id) + formRef.current?.setFieldValue("type", type?.type?.value) + formRef.current?.setFieldValue("dsTypeId", type?.id) }, [dsType]) const columns: ProFormColumnsType[] = [ + { + dataIndex: [prefix, 'type'], + valueType: 'text', + hideInForm: true + }, { title: intl.formatMessage({id: 'pages.metadata.dataSource.step.props.type'}), dataIndex: 'dsTypeId', diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/HDFS.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/HDFS.tsx index 94a3c24c6..ed36f80a9 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/HDFS.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/HDFS.tsx @@ -1,69 +1,25 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const HDFSForm: React.FC = () => { +const HDFSForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const HiveForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const HttpForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
+ { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - - { options={["GET", "POST"]} /> { +const InfluxDBForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/IoTDB.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/IoTDB.tsx index ee9d564a6..7da9cfbd3 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/IoTDB.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/IoTDB.tsx @@ -1,77 +1,33 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const IoTDBForm: React.FC = () => { +const IoTDBForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const JdbcForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const KafkaForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const KuduForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const MaxComputeForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const MongoDBForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const Neo4jForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/OSS.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/OSS.tsx index e8c28aa39..f542d4006 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/OSS.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/StepForms/Props/OSS.tsx @@ -1,82 +1,38 @@ -import {useIntl, useModel} from "@umijs/max"; -import {Form} from "antd"; -import {useEffect} from "react"; -import {ProCard, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components"; -import {DsCategoryService} from "@/services/datasource/category.service"; +import {useIntl} from "@umijs/max"; +import React from "react"; +import {ProCard, ProFormText} from "@ant-design/pro-components"; +import {DataSourceProps} from "@/services/datasource/typings"; +import CommonItem from "@/pages/Metadata/DataSource/Info/StepForms/Props/CommonProps"; -const OSSForm: React.FC = () => { +const OSSForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const OSSJindoForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const PulsarForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const RedisForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { }} /> DictDataService.listDictDataByType2(DICT_TYPE.redisMode)} + request={() => SysDictService.listDictByDefinition(DICT_TYPE.carpDataSourceRedisMode)} /> - - {({mode}) => { + + {(depValues) => { + const prefixValue = depValues[prefix] + const mode = prefixValue['mode'] if (mode == 'cluster') { return ( { +const S3Form: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const SftpForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { }} /> { +const SocketForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { +const StarRocksForm: React.FC = ({prefix, type}) => { const intl = useIntl(); - const form = Form.useFormInstance() - - const {dsType} = useModel('dataSourceType', (model) => ({ - dsType: model.dsType - })); - - useEffect(() => { - form.setFieldValue("dsTypeId", dsType?.id) - }, [dsType]) return (
- { - return DsCategoryService.listTypes({}).then((response) => { - if (response.data) { - return response.data.map((item) => { - return {label: item.type.label, value: item.id, item: item}; - }); - } - return [] - }) - }} - /> - - - + { initialValue={"localhost:8030"} /> { } }} onFinish={(values) => { - const dsInfo = {...values, type: dsType?.type.value} + const dsInfo = {...values} return DsInfoService.add(dsInfo).then((response) => { if (response.success) { history.back() @@ -61,7 +61,7 @@ const DataSourceStepForms: React.FC = () => { wrapperCol={{span: 21}} layout={'horizontal'} style={{width: 1000}}> - + diff --git a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/index.tsx b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/index.tsx index c0329993b..e5d30a670 100644 --- a/scaleph-ui-react/src/pages/Metadata/DataSource/Info/index.tsx +++ b/scaleph-ui-react/src/pages/Metadata/DataSource/Info/index.tsx @@ -1,13 +1,14 @@ import {history, useAccess, useIntl} from "@umijs/max"; -import {useRef, useState} from "react"; +import React, {useRef, useState} from "react"; import {Button, Image, message, Modal, Space, Tooltip} from "antd"; -import {DeleteOutlined} from "@ant-design/icons"; +import {DeleteOutlined, EditOutlined} from "@ant-design/icons"; import {ActionType, PageContainer, ProColumns, ProFormInstance, ProTable} from "@ant-design/pro-components"; import {PRIVILEGE_CODE} from "@/constants/privilegeCode"; import {DICT_TYPE} from "@/constants/dictType"; +import {SysDictService} from "@/services/admin/system/sysDict.service"; import {DsInfo} from "@/services/datasource/typings"; import {DsInfoService} from "@/services/datasource/info.service"; -import {DictDataService} from "@/services/admin/dictData.service"; +import DataSourceUpdateForm from "@/pages/Metadata/DataSource/Info/DataSourceUpdateForm"; const DataSourceListWeb: React.FC = () => { const intl = useIntl(); @@ -15,6 +16,10 @@ const DataSourceListWeb: React.FC = () => { const actionRef = useRef(); const formRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); + const [formData, setFormData] = useState<{ visible: boolean; data: DsInfo }>({ + visible: false, + data: {} + }); const tableColumns: ProColumns[] = [ { @@ -45,7 +50,7 @@ const DataSourceListWeb: React.FC = () => { return entity.dsType?.type.label }, request: (params, props) => { - return DictDataService.listDictDataByType2(DICT_TYPE.datasourceType) + return SysDictService.listDictByDefinition(DICT_TYPE.carpDataSourceType) } }, { @@ -81,11 +86,22 @@ const DataSourceListWeb: React.FC = () => { render: (_, record) => ( <> + {access.canAccess(PRIVILEGE_CODE.userEdit) && ( + + + + )} {access.canAccess(PRIVILEGE_CODE.datadevResourceDelete) && (