瀏覽代碼

参与人组部门和角色适配

ljy121 1 年之前
父節點
當前提交
7553d1f0be

+ 1 - 1
zjugis-framework/zjugis-spring-boot-starter-security/src/main/java/com/zjugis/framework/security/core/util/SecurityFrameworkUtils.java

@@ -112,7 +112,7 @@ public class SecurityFrameworkUtils {
      * @param userType 用户类型
      * @return 模拟的 LoginUser
      */
-    private LoginUser mockLoginUser(HttpServletRequest request, String token, Integer userType) {
+    public static LoginUser mockLoginUser(HttpServletRequest request, String token, Integer userType) {
 
         // 必须以 mockSecret 开头
         if (!token.startsWith("test")) {

+ 3 - 4
zjugis-module-system/zjugis-module-system-api/src/main/java/com/zjugis/module/system/api/permission/RoleApi.java

@@ -2,9 +2,9 @@ package com.zjugis.module.system.api.permission;
 
 import com.zjugis.framework.common.pojo.CommonResult;
 import com.zjugis.module.system.enums.ApiConstants;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -21,5 +21,4 @@ public interface RoleApi {
     @Operation(summary = "校验角色是否合法")
     @Parameter(name = "ids", description = "角色编号数组", example = "1,2", required = true)
     CommonResult<Boolean> validRoleList(@RequestParam("ids") Collection<Long> ids);
-
-}
+}

+ 20 - 0
zjugis-module-system/zjugis-module-system-api/src/main/java/com/zjugis/module/system/api/permission/dto/RoleRespDto.java

@@ -0,0 +1,20 @@
+package com.zjugis.module.system.api.permission.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class RoleRespDto {
+
+    private Long id;
+
+    private String name;
+
+    private Integer sort;
+
+    private Integer type;
+
+}

+ 1 - 1
zjugis-module-system/zjugis-module-system-biz/src/main/resources/application-local.yaml

@@ -64,7 +64,7 @@ spring:
 
   # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
   redis:
-    host: 120.26.0.82 # 地址
+    host: 127.0.0.1 # 地址
     port: 6379 # 端口
     database: 0 # 数据库索引
     password: zdww1402 # 密码,建议生产环境开启

+ 4 - 4
zjugis-module-system/zjugis-module-system-biz/src/main/resources/bootstrap-local.yaml

@@ -3,9 +3,9 @@
 spring:
   cloud:
     nacos:
-      server-addr: 10.10.10.7:8848
+      server-addr: 127.0.0.1:8848
       discovery:
-        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
+#        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
         # 命名空间。这里使用 dev 开发环境
         metadata:
           version: 1.0.0 # 服务实例的版本号,可用于灰度发布
@@ -17,8 +17,8 @@ spring:
     nacos:
       # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
       config:
-        server-addr: 10.10.10.7:8848 # Nacos 服务器地址
-        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
+        server-addr: 127.0.0.1:8848 # Nacos 服务器地址
+#        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
         # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
         group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
         name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name

+ 4 - 0
zjugis-workflow/pom.xml

@@ -217,6 +217,10 @@
             <artifactId>zjugis-spring-boot-starter-rpc</artifactId>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>io.github.openfeign</groupId>
+            <artifactId>feign-httpclient</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 4 - 0
zjugis-workflow/src/main/java/com/zjugis/z_workflow/ZWorkflowApplication.java

@@ -4,6 +4,8 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -13,6 +15,8 @@ import java.util.TimeZone;
 @SpringBootApplication
 @EnableTransactionManagement
 @EnableAsync
+@EnableFeignClients
+@EnableDiscoveryClient
 @ComponentScan({"com.zjugis.z_workflow.*"})
 public class ZWorkflowApplication extends SpringBootServletInitializer {
 	public static void main(String[] args) {

+ 0 - 7
zjugis-workflow/src/main/java/com/zjugis/z_workflow/controller/DefaultController.java

@@ -1,8 +1,6 @@
 package com.zjugis.z_workflow.controller;
 
 
-import com.zjugis.framework.security.core.LoginUser;
-import com.zjugis.framework.web.core.util.WebFrameworkUtils;
 import com.zjugis.z_workflow.base.model.BaseController;
 import com.zjugis.z_workflow.service.IFlowMaterialsService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -10,8 +8,6 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import static com.zjugis.framework.security.core.util.SecurityFrameworkUtils.setLoginUser;
-
 
 @Controller
 public class DefaultController extends BaseController {
@@ -23,9 +19,6 @@ public class DefaultController extends BaseController {
 	@RequestMapping
 	public String index() {
         Long userId = 1L;
-        LoginUser loginUser = new LoginUser().setId(userId).setUserType(2)
-                .setTenantId(WebFrameworkUtils.getTenantId(request));
-        setLoginUser(loginUser,request);
 		return "ok";
 	}
 

+ 7 - 0
zjugis-workflow/src/main/java/com/zjugis/z_workflow/controller/TParticipantFilterController.java

@@ -2,6 +2,7 @@ package com.zjugis.z_workflow.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.zjugis.framework.security.core.LoginUser;
 import com.zjugis.z_workflow.base.model.BaseController;
 import com.zjugis.z_workflow.base.model.Grid;
 import com.zjugis.z_workflow.base.spring.resovler.ParamModel;
@@ -29,6 +30,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 import java.util.*;
 
+import static com.zjugis.framework.security.core.util.SecurityFrameworkUtils.mockLoginUser;
+import static com.zjugis.framework.security.core.util.SecurityFrameworkUtils.setLoginUser;
 import static com.zjugis.z_workflow.entity.enumeration.CondEventTypeEnum.FLOW;
 import static com.zjugis.z_workflow.exception.enums.TransferExceptionEnum.*;
 
@@ -392,6 +395,8 @@ public class TParticipantFilterController extends BaseController {
 	@ResponseBody
 	@RequestMapping(method = RequestMethod.POST)
 	public String getTreeList(Integer filterFirstType) {
+		LoginUser test1 = mockLoginUser(request, "test1", 2);
+		setLoginUser(test1,request);
 		try {
 			//根据参与人过滤类型获取枚举
 			ParticipantFilterTypeEnum filterType = ParticipantFilterTypeEnum.getTypeByIndex(filterFirstType);
@@ -452,6 +457,8 @@ public class TParticipantFilterController extends BaseController {
 	@RequestMapping
 	public String getRoleList(@ParamModel RoleDto roleDto, long page, long rows) {
 		try {
+            LoginUser test1 = mockLoginUser(request, "test1", 2);
+            setLoginUser(test1,request);
 			IPage<RoleDto> dataPage = callInterfaceService.getRoleList(roleDto, page, rows);
 			Grid<RoleDto> grid = new Grid<RoleDto>(page, dataPage.getSize(), dataPage.getTotal(), dataPage.getRecords());
 

+ 20 - 0
zjugis-workflow/src/main/java/com/zjugis/z_workflow/remote/DeptClient.java

@@ -0,0 +1,20 @@
+package com.zjugis.z_workflow.remote;
+
+import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.module.system.api.dept.dto.DeptRespDTO;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.util.List;
+
+/**
+ * @author ljy
+ * @version 1.0
+ * @date 2023/11/1 0:02
+ */
+@FeignClient(value = "system-server",path = "/admin-api/system/dept")
+public interface DeptClient {
+
+    @GetMapping("/list-all-simple")
+    CommonResult<List<DeptRespDTO>> getSimpleDeptList();
+}

+ 29 - 0
zjugis-workflow/src/main/java/com/zjugis/z_workflow/remote/RoleClient.java

@@ -0,0 +1,29 @@
+package com.zjugis.z_workflow.remote;
+
+import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.framework.common.pojo.PageResult;
+import com.zjugis.module.system.api.permission.dto.RoleRespDto;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+/**
+ * @author ljy
+ * @version 1.0
+ * @date 2023/10/31 18:23
+ */
+@FeignClient(value = "system-server",path = "/admin-api/system/role")
+public interface RoleClient {
+
+    @GetMapping("/list-all-simple")
+    public CommonResult<List<RoleRespDto>> getSimpleRoleList();
+
+    @GetMapping("/get")
+    public CommonResult<RoleRespDto> get(@RequestParam("id") Long id);
+
+    @GetMapping("/page")
+    public CommonResult<PageResult<RoleRespDto>> getRolePage(@RequestParam("pageNo") long pageNo, @RequestParam("pageSize") long pageSize, @RequestParam("code") String code, @RequestParam("name") String name );
+
+}

+ 50 - 52
zjugis-workflow/src/main/java/com/zjugis/z_workflow/service/CallInterfaceService.java

@@ -6,12 +6,18 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.framework.common.pojo.PageResult;
+import com.zjugis.module.system.api.dept.dto.DeptRespDTO;
+import com.zjugis.module.system.api.permission.dto.RoleRespDto;
 import com.zjugis.z_workflow.base.utils.JsonUtils;
 import com.zjugis.z_workflow.base.utils.Select;
 import com.zjugis.z_workflow.base.utils.ServiceApiUtils;
 import com.zjugis.z_workflow.dto.*;
 import com.zjugis.z_workflow.entity.CodeTemplate;
 import com.zjugis.z_workflow.entity.Form;
+import com.zjugis.z_workflow.remote.DeptClient;
+import com.zjugis.z_workflow.remote.RoleClient;
 import com.zjugis.z_workflow.utils.*;
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.util.Strings;
@@ -45,6 +51,12 @@ public class CallInterfaceService {
     @Autowired
     CodeTemplateService codeTemplateService;
 
+    @Autowired
+    private RoleClient roleClient;
+	@Autowired
+	private DeptClient deptClient;
+
+
 
 
 	/**
@@ -75,33 +87,24 @@ public class CallInterfaceService {
 	 **/
 	public List<zTree> getDepartmentList(int iDeptUsers, Boolean iOpen, Integer informal) {
 		List<zTree> treeList = new ArrayList();
-		//参数
-		Map<String, Object> map = new HashMap<>();
-		map.put("dID", "");//部门ID,默认传空
-		map.put("iChild", "1");//是否包含子部门(1:包含 0:不包含)
-		map.put("iPosition", "0");//是否包含职位(1:包含 0:不包含)
-		map.put("iPositionUsers", "0");//是否包含职位人员(1:包含 0:不包含)
-		map.put("iDeptUsers", iDeptUsers);//是否包含部门人员(1:包含 0:不包含)
-		if (!Objects.isNull(informal)) {
-			map.put("informal", informal);//0:正式部门,1:非正式部门,null:全部
-		}
 		//获取接口返回数据
-		JSONArray arrayResult = callInterfaceReturnList("z_user_org_right", "DepartmentApi/getOrgTree", map);
-		if (Objects.isNull(arrayResult)) {
+		CommonResult<List<DeptRespDTO>> result = deptClient.getSimpleDeptList();
+		List<DeptRespDTO> list = result.getData();
+		if (list == null || list.isEmpty()) {
 			return treeList;
 		}
 		//遍历数据,转换为需要的格式
-		int arraySize = arrayResult.size();
+		int arraySize = list.size();
 		if (arraySize > 0) {
 			zTree ztree;
-			JSONObject jsonObj;
+			DeptRespDTO dept;
 			for (int i = 0; i < arraySize; i++) {
-				jsonObj = arrayResult.getJSONObject(i);
+				dept = list.get(i);
 				ztree = new zTree();
-				ztree.setId(jsonObj.getString("id"));
-				ztree.setName(jsonObj.getString("name"));
-				ztree.setPid(jsonObj.getString("pid"));
-				ztree.setType(jsonObj.getInteger("type"));
+				ztree.setId(String.valueOf(dept.getId()));
+				ztree.setName(dept.getName());
+				ztree.setPid(dept.getParentId() == 0?"":String.valueOf(dept.getParentId()));
+				ztree.setType(1);
 				if (ztree.getType() == 1) {
 					ztree.setAllowSelect(true);
 				} else {
@@ -238,23 +241,22 @@ public class CallInterfaceService {
 	 **/
 	public List<zTree> getRoleList() {
 		List<zTree> treeList = new ArrayList();
-		//参数
-		Map<String, Object> map = new HashMap<>();
 		//获取接口返回数据
-		JSONArray arrayResult = callInterfaceReturnList("z_user_org_right", "RoleApi/getList", map);
-		if (arrayResult == null) {
+        CommonResult<List<RoleRespDto>> result = roleClient.getSimpleRoleList();
+        List<RoleRespDto> arrayResult = result.getData();
+        if (arrayResult == null) {
 			return treeList;
 		}
 		//遍历数据,转换为需要的格式
 		int arraySize = arrayResult.size();
 		if (arraySize > 0) {
 			zTree ztree;
-			JSONObject jsonObj;
+            RoleRespDto role;
 			for (int i = 0; i < arraySize; i++) {
-				jsonObj = arrayResult.getJSONObject(i);
+                role = arrayResult.get(i);
 				ztree = new zTree();
-				ztree.setId(jsonObj.getString("id"));
-				ztree.setName(jsonObj.getString("name"));
+				ztree.setId(String.valueOf(role.getId()));
+				ztree.setName(role.getName());
 				ztree.setType(1);
 				ztree.setAllowSelect(true);
 				treeList.add(ztree);
@@ -337,31 +339,28 @@ public class CallInterfaceService {
 	 **/
 	public IPage<RoleDto> getRoleList(RoleDto roleDto, long page, long rows) {
 		IPage<RoleDto> rolePage = new Page<RoleDto>(page, rows);
-		//参数
-		Map<String, Object> map = new HashMap<>();
-		map.put("role", JSON.toJSONString(roleDto));//序列化查询对象
-		map.put("page", "{\"page\":\"" + page + "\",\"rows\":\"" + rows + "\"}");//分页对象
-		//获取接口返回数据
-		JSONObject objectResult = callInterfaceReturnPageList("z_user_org_right", "RoleApi/getList", map);
-		if (objectResult == null) {
+        //获取接口返回数据
+        CommonResult<PageResult<RoleRespDto>> result = roleClient.getRolePage(page, rows, null, roleDto.getName());
+		PageResult<RoleRespDto> pageResult = result.getData();
+        if (pageResult == null) {
 			return rolePage;
 		}
 		//将JSONObject转换为需要的分页数据
-		int total = Integer.parseInt(String.valueOf(objectResult.get("records")));//总记录数
-		JSONArray records = JSONArray.parseArray(String.valueOf(objectResult.get("rows")));//列表数据
-		List<RoleDto> roleList = new ArrayList<>();
-		if (records.size() > 0) {
+		int total = Math.toIntExact(pageResult.getTotal());//总记录数
+        List<RoleRespDto> records = pageResult.getList();//列表数据
+        List<RoleDto> roleList = new ArrayList<>();
+		if (!records.isEmpty()) {
 			RoleDto roleInfo;
-			JSONObject jsonObj;
-			for (int i = 0; i < records.size(); i++) {
-				roleInfo = new RoleDto();
-				jsonObj = records.getJSONObject(i);
-				roleInfo.setId(jsonObj.getString("id"));
-				roleInfo.setName(jsonObj.getString("name"));
-				roleInfo.setClassify(jsonObj.getString("classify"));
-				roleInfo.setIndexCode(jsonObj.getInteger("indexCode"));
-				roleList.add(roleInfo);
-			}
+            RoleRespDto role;
+            for (RoleRespDto record : records) {
+                roleInfo = new RoleDto();
+                role = record;
+                roleInfo.setId(String.valueOf(role.getId()));
+                roleInfo.setName(role.getName());
+                roleInfo.setClassify(String.valueOf(role.getType()));
+                roleInfo.setIndexCode(role.getSort());
+                roleList.add(roleInfo);
+            }
 		}
 		rolePage.setTotal(total);
 		rolePage.setRecords(roleList);
@@ -377,13 +376,12 @@ public class CallInterfaceService {
 	public String getRoleName(String id) {
 		//参数
 		Map<String, Object> map = new HashMap<>();
-		map.put("id", id);//部门ID
 		//获取接口返回数据
-		JSONObject objResult = callInterfaceReturnObj("z_user_org_right", "RoleApi/getRoleById", map);
-		if (objResult == null) {
+        CommonResult<RoleRespDto> role = roleClient.get(Long.valueOf(id));
+        if (role == null) {
 			return Strings.EMPTY;
 		}
-		return objResult.getString("name");
+		return role.getData().getName();
 	}
 
 	/**

+ 5 - 5
zjugis-workflow/src/main/resources/bootstrap-local.yaml

@@ -3,14 +3,14 @@ spring:
     name: workflow
   cloud:
     nacos:
-      server-addr: 10.10.10.7:8848
+      server-addr: 127.0.0.1:8848
       discovery:
         service: workflow
-        server-addr: 10.10.10.7:8848
-        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
+        server-addr: 127.0.0.1:8848
+#        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557
       config:
-        server-addr: 10.10.10.7:8848 # Nacos 服务器地址
-        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557        # 命名空间。这里使用 dev 开发环境
+        server-addr: 127.0.0.1:8848 # Nacos 服务器地址
+#        namespace: d62c66f5-9ddc-40e9-9716-65f65557a557        # 命名空间。这里使用 dev 开发环境
         group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
         name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
         file-extension: yaml