Преглед изворни кода

[task-906] 事务代理中增加按角色代理功能

Li Yuan пре 2 година
родитељ
комит
9b753bba60
13 измењених фајлова са 160 додато и 21 уклоњено
  1. 8 1
      ibps-bpmn-root/modules/bpmn-biz/src/main/java/com/lc/ibps/bpmn/repository/BpmAgentRepository.java
  2. 35 1
      ibps-bpmn-root/modules/bpmn-biz/src/main/java/com/lc/ibps/bpmn/repository/impl/BpmAgentRepositoryImpl.java
  3. 10 1
      ibps-bpmnbase-root/modules/bpmn-model/src/main/java/com/lc/ibps/bpmn/persistence/entity/BpmAgentPo.java
  4. 58 0
      ibps-bpmnbase-root/modules/bpmn-model/src/main/java/com/lc/ibps/bpmn/persistence/handler/JsonArrayTypeHandler.java
  5. 12 3
      ibps-bpmnbase-root/modules/bpmn-model/src/main/resources/com/lc/ibps/bpmn/persistence/mapping/BpmAgent.map.xml
  6. 1 1
      ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/repository/ResourcesRepository.java
  7. 5 2
      ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/repository/impl/ResourcesRepositoryImpl.java
  8. 1 1
      ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/service/impl/ResourcesQueryService.java
  9. 4 1
      ibps-provider-base-root/modules/provider-bpmn-api/src/main/java/com/lc/ibps/bpmn/api/IBpmAgentService.java
  10. 2 1
      ibps-provider-base-root/modules/provider-platform-api/src/main/java/com/lc/ibps/common/api/IResourcesService.java
  11. 12 0
      ibps-provider-root/modules/provider-bpmn/src/main/java/com/lc/ibps/bpmn/provider/BpmAgentProvider.java
  12. 1 1
      ibps-provider-root/modules/provider-business/src/main/resources/config/application-app.yml
  13. 11 8
      ibps-provider-root/modules/provider-platform-default/src/main/java/com/lc/ibps/common/provider/ResourcesProvider.java

+ 8 - 1
ibps-bpmn-root/modules/bpmn-biz/src/main/java/com/lc/ibps/bpmn/repository/BpmAgentRepository.java

@@ -33,5 +33,12 @@ public interface BpmAgentRepository extends IRepository<String, BpmAgentPo,BpmAg
 	 * @return 
 	 */
 	public List<BpmAgentPo> findByType(String agentType, String delegator, String procDefKey);
-	
+
+	/**
+	 * 根据代理人查询角色代理信息
+	 *
+	 * @param agentId 代理人Id
+	 * @return
+	 */
+	public List<String> findRolesByAgentId(String agentId);
 }

+ 35 - 1
ibps-bpmn-root/modules/bpmn-biz/src/main/java/com/lc/ibps/bpmn/repository/impl/BpmAgentRepositoryImpl.java

@@ -1,9 +1,15 @@
 package com.lc.ibps.bpmn.repository.impl;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.annotation.Resource;
 
+import com.lc.ibps.base.core.util.time.DateFormatUtil;
+import com.lc.ibps.base.core.util.time.DateUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.stereotype.Repository;
 
 import com.lc.ibps.api.base.constants.CacheKeyConstants;
@@ -103,5 +109,33 @@ public class BpmAgentRepositoryImpl extends AbstractRepository<String, BpmAgentP
 		
 		return list;
 	}
-	
+
+	@Override
+	public List<String> findRolesByAgentId(String agentId) {
+		List<BpmAgentPo> bpmAgentList = findByKey("findRulesByAgentId", null,
+				b().a("agenterId" ,agentId).a("isEnabled", BpmAgentPo.ENABLED).p());
+		List<String> roles = new ArrayList<>();
+
+		if(CollectionUtils.isNotEmpty(bpmAgentList)){
+			String EffectiveDateStr = null;
+			String expiryDateStr = null;
+			String currDateStr = DateFormatUtil.getCurrentDate();
+			for(Iterator<BpmAgentPo> iterator = bpmAgentList.iterator(); iterator.hasNext();){
+				BpmAgentPo bpmAgentPo = iterator.next();
+				if(CollectionUtils.isNotEmpty(bpmAgentPo.getBpmAgentRoleList())){
+					EffectiveDateStr = DateFormatUtil.formatDate(bpmAgentPo.getEffectiveTime());
+					expiryDateStr = DateFormatUtil.formatDate(bpmAgentPo.getExpiryTime());
+					// 不在代理有效期内的移除
+					if(DateUtil.compare(currDateStr, EffectiveDateStr)
+							|| DateUtil.compare(expiryDateStr, currDateStr)){
+						continue;
+					}
+					roles.addAll(bpmAgentPo.getBpmAgentRoleList());
+				}
+			}
+		}
+
+		return roles;
+	}
+
 }

+ 10 - 1
ibps-bpmnbase-root/modules/bpmn-model/src/main/java/com/lc/ibps/bpmn/persistence/entity/BpmAgentPo.java

@@ -33,7 +33,8 @@ public class BpmAgentPo extends BpmAgentTbl{
 	 protected String procDefId;/*流程id*/
 	 @ApiModelProperty(value = "流程名称")
 	 protected String procDefName;/*流程名称*/
-	 
+	@ApiModelProperty(value = "代理角色列表")
+	private List<String> bpmAgentRoleList = new ArrayList<String>();;
 	private boolean delBeforeSave = true;
 	public boolean isDelBeforeSave() {
 		return delBeforeSave;
@@ -79,4 +80,12 @@ public class BpmAgentPo extends BpmAgentTbl{
 	public void setProcDefId(String procDefId) {
 		this.procDefId = procDefId;
 	}
+
+	public List<String> getBpmAgentRoleList() {
+		return bpmAgentRoleList;
+	}
+
+	public void setBpmAgentRoleList(List<String> bpmAgentRoleList) {
+		this.bpmAgentRoleList = bpmAgentRoleList;
+	}
 }

+ 58 - 0
ibps-bpmnbase-root/modules/bpmn-model/src/main/java/com/lc/ibps/bpmn/persistence/handler/JsonArrayTypeHandler.java

@@ -0,0 +1,58 @@
+package com.lc.ibps.bpmn.persistence.handler;
+
+
+
+import cn.hutool.json.JSONUtil;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+public class JsonArrayTypeHandler extends BaseTypeHandler {
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
+            throws SQLException {
+        ps.setString(i, JSONUtil.toJsonStr(parameter));
+    }
+
+
+    @Override
+    public List getNullableResult(ResultSet rs, String columnName)
+
+            throws SQLException {
+
+        String sqlJson = rs.getString(columnName);
+        if (null != sqlJson){
+            return JSONUtil.toList(JSONUtil.parseArray(sqlJson), Object.class);
+        }
+        return null;
+
+    }
+
+    @Override
+    public List getNullableResult(ResultSet rs, int columnIndex)
+            throws SQLException {
+        String sqlJson = rs.getString(columnIndex);
+        if (null != sqlJson){
+            return JSONUtil.toList(JSONUtil.parseArray(sqlJson), Object.class);
+        }
+        return null;
+    }
+
+
+    @Override
+    public List getNullableResult(CallableStatement cs, int columnIndex)
+            throws SQLException {
+        String sqlJson = cs.getString(columnIndex);
+        if (null != sqlJson){
+            return JSONUtil.toList(JSONUtil.parseArray(sqlJson), Object.class);
+        }
+        return null;
+    }
+
+}

+ 12 - 3
ibps-bpmnbase-root/modules/bpmn-model/src/main/resources/com/lc/ibps/bpmn/persistence/mapping/BpmAgent.map.xml

@@ -15,17 +15,18 @@
 		<result property="createBy" column="CREATE_BY_" jdbcType="VARCHAR"/>
 		<result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP"/>
 		<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR"/>
+		<result property="bpmAgentRoleList" column="AGENT_RULES_" javaType="java.util.List" typeHandler="com.lc.ibps.bpmn.persistence.handler.JsonArrayTypeHandler"/>
 	</resultMap>
 	
 	<sql id="columns">
-		ID_,TITLE_,DELEGATOR_ID_,AGENTER_ID_,PROC_DEF_KEY_,IS_ENABLED_,EFFECTIVE_TIME_,EXPIRY_TIME_,AGENT_TYPE_,CREATE_BY_,CREATE_TIME_,TENANT_ID_
+		ID_,TITLE_,DELEGATOR_ID_,AGENTER_ID_,PROC_DEF_KEY_,IS_ENABLED_,EFFECTIVE_TIME_,EXPIRY_TIME_,AGENT_TYPE_,CREATE_BY_,CREATE_TIME_,TENANT_ID_,AGENT_RULES_
 	</sql>
 	
 	<insert id="create" parameterType="com.lc.ibps.bpmn.persistence.entity.BpmAgentPo">
 		INSERT INTO IBPS_BPM_AGENT
 		(<include refid="columns"/>)
 		VALUES 
-		(#{id,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{delegatorId,jdbcType=VARCHAR}, #{agenterId,jdbcType=VARCHAR}, #{procDefKey,jdbcType=VARCHAR}, #{isEnabled,jdbcType=VARCHAR}, #{effectiveTime,jdbcType=TIMESTAMP}, #{expiryTime,jdbcType=TIMESTAMP}, #{agentType,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR})
+		(#{id,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{delegatorId,jdbcType=VARCHAR}, #{agenterId,jdbcType=VARCHAR}, #{procDefKey,jdbcType=VARCHAR}, #{isEnabled,jdbcType=VARCHAR}, #{effectiveTime,jdbcType=TIMESTAMP}, #{expiryTime,jdbcType=TIMESTAMP}, #{agentType,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR}, #{bpmAgentRoleList,jdbcType=VARCHAR,typeHandler=com.lc.ibps.bpmn.persistence.handler.JsonArrayTypeHandler})
 	</insert>
 	
 	<select id="get"   parameterType="java.lang.String" resultMap="BpmAgentPo">
@@ -47,6 +48,13 @@
 		AND ID_ IN (SELECT AGENT_ID_ FROM IBPS_BPM_AGENT_DEF WHERE PROC_DEF_KEY_ = #{procDefKey})
 		</if>
 	</select>
+
+	<select id="findRulesByAgentId"   parameterType="java.util.Map" resultMap="BpmAgentPo">
+		SELECT <include refid="columns"/> FROM IBPS_BPM_AGENT
+		WHERE
+		AGENTER_ID_=#{agenterId}
+		AND IS_ENABLED_=#{isEnabled}
+	</select>
 	
 	<select id="findIdsByType"   parameterType="java.util.Map" resultMap="BpmAgentPo">
 		SELECT ID_ FROM IBPS_BPM_AGENT 
@@ -105,7 +113,8 @@
 		EXPIRY_TIME_=#{expiryTime,jdbcType=TIMESTAMP},
 		AGENT_TYPE_=#{agentType,jdbcType=VARCHAR},
 		CREATE_BY_=#{createBy,jdbcType=VARCHAR},
-		CREATE_TIME_=#{createTime,jdbcType=TIMESTAMP}
+		CREATE_TIME_=#{createTime,jdbcType=TIMESTAMP},
+		AGENT_RULES_=#{bpmAgentRoleList,jdbcType=VARCHAR,typeHandler=com.lc.ibps.bpmn.persistence.handler.JsonArrayTypeHandler}
 		WHERE
 		ID_=#{id}
 	</update>

+ 1 - 1
ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/repository/ResourcesRepository.java

@@ -23,7 +23,7 @@ public interface ResourcesRepository extends IRepository<String, ResourcesPo, Re
 	 *            *
 	 * @return
 	 */
-	List<ResourcesPo> getByUserIdSystemId(String userId, boolean isSuper, String systemId);
+	List<ResourcesPo> getByUserIdSystemId(String userId, boolean isSuper, String systemId, List<String> agentRoles);
 	
 	/**
 	 * 获取用户所拥有的所有资源

+ 5 - 2
ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/repository/impl/ResourcesRepositoryImpl.java

@@ -195,7 +195,7 @@ public class ResourcesRepositoryImpl extends AbstractRepository<String, Resource
 	}
 
 	@Override
-	public List<ResourcesPo> getByUserIdSystemId(String userId, boolean isSuper, String systemId) {
+	public List<ResourcesPo> getByUserIdSystemId(String userId, boolean isSuper, String systemId, List<String> agentRoles) {
 		if (StringUtil.isEmpty(userId)) {
 			return Collections.emptyList();
 		}
@@ -217,12 +217,15 @@ public class ResourcesRepositoryImpl extends AbstractRepository<String, Resource
 			
 			// 查询用户所有角色
 			userRoles = roleRepository.findUserRolesByUserId(userId);
-			if (BeanUtils.isEmpty(userRoles)) {
+			if (BeanUtils.isEmpty(userRoles) && BeanUtils.isEmpty(agentRoles)) {
 				return Collections.emptyList();
 			}
 		}
 
 		List<String> roleIds = new ArrayList<String>();
+
+		if(BeanUtils.isNotEmpty(agentRoles)) 	roleIds.addAll(agentRoles);
+
 		for (DefaultPartyRolePo userRole : userRoles) {
 			if(BeanUtils.isEmpty(userRole)) {
 				continue;

+ 1 - 1
ibps-common-root/modules/org-biz/src/main/java/com/lc/ibps/org/auth/service/impl/ResourcesQueryService.java

@@ -43,7 +43,7 @@ public class ResourcesQueryService implements IResourcesQueryService {
 
 	@Override
 	public String findByUserIdSystemId(String userId, boolean isSuper, String systemId) {
-		List<ResourcesPo> list = resourcesRepository.getByUserIdSystemId(userId, isSuper, systemId);
+		List<ResourcesPo> list = resourcesRepository.getByUserIdSystemId(userId, isSuper, systemId,null);
 		return BeanUtils.isEmpty(list) ? null : JacksonUtil.toJsonString(list);
 	}
 

+ 4 - 1
ibps-provider-base-root/modules/provider-bpmn-api/src/main/java/com/lc/ibps/bpmn/api/IBpmAgentService.java

@@ -59,7 +59,10 @@ public interface IBpmAgentService {
 	public APIResult<BpmAgentPo> get(
 			@NotBlank(message = "{com.lc.ibps.bpmn.provider.public.id}")
 			@RequestParam(name="id", required = false)  String id) ;
-	
+
+	@RequestMapping(value = "/roles",method = {RequestMethod.GET})
+	public APIResult<String> roles();
+
 	/**
 	 * 批量删除【流程代理】记录
 	 * @param ids

+ 2 - 1
ibps-provider-base-root/modules/provider-platform-api/src/main/java/com/lc/ibps/common/api/IResourcesService.java

@@ -98,7 +98,8 @@ public interface IResourcesService {
 	@RequestMapping(value = "/getMenuData", method = { RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
 	public APIResult<List<ResourcesPo>> getMenuData(
 			@NotBlank(message = "{com.lc.ibps.org.auth.systemId}") 
-			@RequestParam(name = "systemId", required = true) String systemId);
+			@RequestParam(name = "systemId", required = true) String systemId,
+			@RequestParam(name = "roles", required = false) String roles);
 	
 	/**
 	 * 

+ 12 - 0
ibps-provider-root/modules/provider-bpmn/src/main/java/com/lc/ibps/bpmn/provider/BpmAgentProvider.java

@@ -4,6 +4,8 @@ import java.util.List;
 
 import javax.annotation.Resource;
 
+import com.lc.ibps.api.base.model.User;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -105,6 +107,16 @@ public class BpmAgentProvider extends GenericProvider implements IBpmAgentServic
 		return result;
 	}
 
+	@ApiOperation(value = "代理角色列表", notes = "根据当前用户查询代理角色列表")
+	@Override
+	public APIResult<String> roles() {
+		APIResult<String> result = new APIResult<>();
+		User user = ContextUtil.getCurrentUser();
+		List<String> roles = bpmAgentRepository.findRolesByAgentId(user.getUserId());
+		result.setData(StringUtils.join(roles,","));
+		return result;
+	}
+
 	/**
 	 * 保存【流程代理】信息
 	 * @param bpmAgentPo

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/resources/config/application-app.yml

@@ -117,7 +117,7 @@ bpm:
         enabled: ${BPM_TASK_PENDDING_OPTIMIZE_ENABLED:true}
   delegator:
     #流程代理任务-委托人是否可见,true|false
-    visible: ${BPM_DELEGATOR_VISIBLE:false}
+    visible: ${BPM_DELEGATOR_VISIBLE:true}
   lock:
     #流程锁定任务-其他候选人是否可见,true|false
     visible: ${BPM_LOCK_VISIBLE:false}

+ 11 - 8
ibps-provider-root/modules/provider-platform-default/src/main/java/com/lc/ibps/common/provider/ResourcesProvider.java

@@ -1,14 +1,12 @@
 package com.lc.ibps.common.provider;
 
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import javax.annotation.Resource;
 
+import com.lc.ibps.bpmn.persistence.entity.BpmAgentPo;
+import org.apache.commons.lang3.StringUtils;
 import org.dom4j.Document;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -108,7 +106,6 @@ public class ResourcesProvider extends GenericProvider implements IResourcesServ
 			po.setSystemId(systemId);
 			RoleResource roleResource = roleResourceRepository.newInstance(po);
 			roleResource.updateRoleRes(resIds);
-
 			result.setMessage(I18nUtil.getMessage("com.lc.ibps.common.provider.ResourcesProvider.updateResource"));
 		} catch (Exception e) {
 			setExceptionResult(result, StateEnum.ERROR_SYSTEM_RESOURCES.getCode(), I18nUtil.getMessage(StateEnum.ERROR_SYSTEM_RESOURCES.getCode()+""), e);
@@ -174,14 +171,20 @@ public class ResourcesProvider extends GenericProvider implements IResourcesServ
 	@Override
 	public APIResult<List<ResourcesPo>> getMenuData(
 			@ApiParam(name = "systemId", value = "所属子系统Id", required = true)
-			@RequestParam(name = "systemId", required = true) String systemId) {
+			@RequestParam(name = "systemId", required = true) String systemId,
+			@ApiParam(name = "roles", value = "代理角色", required = false)
+			@RequestParam(name = "roles", required = false) String roles) {
 		APIResult<List<ResourcesPo>> result = new APIResult<>();
 		try {
 			logger.debug("com.lc.ibps.common.provider.ResourcesProvider.findByParentIdAndSystemId()--->systemId={} ",
 					 systemId);
 			User user = ContextUtil.getCurrentUser();
+			List<String> agentRoles = null;
+			if(StringUtils.isNotBlank(roles)){
+				agentRoles = Arrays.asList(roles.split(","));
+			}
 			List<ResourcesPo> list = resourcesRepository.getByUserIdSystemId(user.getUserId(), user.isSuper(),
-					systemId);
+					systemId,agentRoles);
 			result.setData(list);
 		} catch (Exception e) {
 			setExceptionResult(result, StateEnum.ERROR_SYSTEM_RESOURCES.getCode(), I18nUtil.getMessage(StateEnum.ERROR_SYSTEM_RESOURCES.getCode()+""), e);