From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期三, 27 五月 2020 09:59:29 +0800
Subject: [PATCH] merage

---
 src/main/java/com/highdatas/mdm/service/act/impl/IdentityServiceImpl.java |  126 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 111 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/service/act/impl/IdentityServiceImpl.java b/src/main/java/com/highdatas/mdm/service/act/impl/IdentityServiceImpl.java
index da51138..e2376eb 100644
--- a/src/main/java/com/highdatas/mdm/service/act/impl/IdentityServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/act/impl/IdentityServiceImpl.java
@@ -4,6 +4,8 @@
 import com.highdatas.mdm.mapper.TableInfoMapper;
 import com.highdatas.mdm.pojo.CodeMsg;
 import com.highdatas.mdm.pojo.Result;
+import com.highdatas.mdm.util.RedisClient;
+import lombok.extern.slf4j.Slf4j;
 import org.activiti.engine.IdentityService;
 import org.activiti.engine.RepositoryService;
 import org.activiti.engine.RuntimeService;
@@ -15,13 +17,16 @@
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
 @Service
+@Slf4j
 public class IdentityServiceImpl extends BaseServiceImpl implements com.highdatas.mdm.service.act.IdentityService{
 	@Autowired
 	IdentityService identityService;
@@ -31,12 +36,30 @@
 	RepositoryService repositoryService;
 	@Autowired
 	TableInfoMapper tableInfoMapper;
+	@Autowired
+	RedisClient redisClient;
 
+	/**
+	 *
+	 * @description:  鍚姩娴佺▼
+	 * @param businessId 涓氬姟id
+	 * @param key 娴佺▼key
+	 * @return: 瀹炰緥id
+	 *
+	 */
     @Override
 	public String startProcess(String businessId, String key) {
 		return startProcess(businessId, key, null, null);
 	}
-
+	/**
+	 *
+	 * @description:  鍚姩娴佺▼
+	 * @param businessId 涓氬姟id
+	 * @param key 娴佺▼key
+	 * @param variables 棰濆鍙傛暟
+	 * @return: 瀹炰緥id
+	 *
+	 */
     @Override
 	public String startProcess(String businessId, String key, String workflowStall, HashMap<String, Object> variables) {
     	TUser user = getOnlineUser();
@@ -61,19 +84,26 @@
         	variables.put("workflowstall", workflowStallInt);
         	
         	identityService.setAuthenticatedUserId(user.getUserId());
-
+			Date startDate = new Date();
             //get max version processDefinition
             List<Model> modelList = repositoryService.createModelQuery().modelKey(key).orderByModelVersion().desc().list();
+			Date endDate = new Date();
+			log.info("process load model:" + (endDate.getTime() - startDate.getTime()) +"ms");
             ProcessDefinition processDefinition = null;
             
             for (Model model : modelList) {
 				if (processDefinition == null && model.getDeploymentId() != null) {
 					String deploymentId = model.getDeploymentId();
 					processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
+					break;
 				}
 			}
-
+			startDate = new Date();
+			log.info("process load processDef:" + (startDate.getTime() - endDate.getTime()) +"ms");
             processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), businessId, variables);
+
+			endDate = new Date();
+			log.info("process start process :" + (endDate.getTime() - startDate.getTime()) +"ms");
 
             String processInstanceId = processInstance.getId();
             //TODO db
@@ -90,7 +120,15 @@
     	}
 	}
 
+	/**
+	 *
+	 * @description:  娣诲姞宸ヤ綔娴佺敤鎴�
+	 * @param id 鐢ㄦ埛id
+	 * @return: 娣诲姞缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result addUser(String id) {
 		User preUser = identityService.createUserQuery().userId(id).singleResult();
 		if (preUser != null) {
@@ -107,7 +145,15 @@
 
 	}
 
+	/**
+	 *
+	 * @description:  娣诲姞宸ヤ綔娴佽鑹�
+	 * @param id 瑙掕壊id
+	 * @return: 娣诲姞缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result addRole(String id) {
 		Group preGroup = identityService.createGroupQuery().groupId(id).singleResult();
 		if (preGroup != null) {
@@ -123,7 +169,16 @@
 		}
 	}
 
+	/**
+	 *
+	 * @description:  娣诲姞宸ヤ綔娴佺敤鎴凤紝瑙掕壊鍏宠仈
+	 * @param roleId 瑙夊緱id
+	 * @param userId 鐢ㄦ埛id
+	 * @return: 娣诲姞缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result addUserRole(String roleId, String userId) {
     	try {
 			User user = identityService.createUserQuery().userId(userId).singleResult();
@@ -143,14 +198,31 @@
 			return Result.error(new CodeMsg(3002, e.getMessage()));
 		}
 	}
-
+	/**
+	 *
+	 * @description:  鍒犻櫎宸ヤ綔娴佺敤鎴�
+	 * @param id 鐢ㄦ埛id
+	 * @return: 鍒犻櫎缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result deleteUser(String id) {
 		try {
 			User user = identityService.createUserQuery().userId(id).singleResult();
 			if (user == null) {
 				return Result.error(new CodeMsg(3001, "褰撳墠鐢ㄦ埛涓嶅瓨鍦�"));
 			}
+			List<Map<String, Object>> maps = tableInfoMapper.selectActMemberShipByUser(id);
+			for (Map<String, Object> map : maps) {
+				Object group_id_ = map.get("GROUP_ID_");
+				Object user_id_ = map.get("USER_ID_");
+				if (user_id_ == null || group_id_ == null) {
+					continue;
+				}
+				identityService.deleteMembership(user_id_.toString(), group_id_.toString());
+			}
+			redisClient.delByCharacter(id);
 			identityService.deleteUser(id);
 			return Result.success(null);
 		}catch (Exception e){
@@ -159,13 +231,30 @@
 		}
 
 	}
-
+	/**
+	 *
+	 * @description:  鍒犻櫎宸ヤ綔娴佽鑹�
+	 * @param id 瑙掕壊id
+	 * @return: 鍒犻櫎缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result deleteRole(String id) {
 		try {
 			Group group = identityService.createGroupQuery().groupId(id).singleResult();
 			if (group == null) {
 				return Result.error(new CodeMsg(3001, "褰撳墠瑙掕壊涓嶅瓨鍦�"));
+			}
+			List<Map<String, Object>> maps = tableInfoMapper.selectActMemberShipByRole(id);
+			for (Map<String, Object> map : maps) {
+				Object group_id_ = map.get("GROUP_ID_");
+				Object user_id_ = map.get("USER_ID_");
+				if (user_id_ == null || group_id_ == null) {
+					continue;
+				}
+				identityService.deleteMembership(user_id_.toString(), group_id_.toString());
+				redisClient.delByCharacter(user_id_.toString());
 			}
 			identityService.deleteGroup(id);
 			return Result.success(null);
@@ -175,23 +264,24 @@
 		}
 	}
 
-
+	/**
+	 *
+	 * @description:  鍒犻櫎宸ヤ綔娴佺敤鎴� 瑙掕壊鍏宠仈
+	 * @param userId 鐢ㄦ埛id
+	 * @param roleId 瑙掕壊id
+	 * @return: 鍒犻櫎缁撴灉
+	 *
+	 */
 	@Override
+	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
 	public Result deleteUserRole(String roleId, String userId) {
 		try {
-			User user = identityService.createUserQuery().userId(userId).singleResult();
-			if (user == null) {
-				return Result.error(new CodeMsg(3001, "褰撳墠鐢ㄦ埛涓嶅瓨鍦�,璇峰厛鍒涘缓鐢ㄦ埛"));
-			}
-			Group group = identityService.createGroupQuery().groupId(roleId).singleResult();
-			if (user == null) {
-				return Result.error(new CodeMsg(3001, "褰撳墠瑙掕壊涓嶅瓨鍦�,璇峰厛瑙掕壊鐢ㄦ埛"));
-			}
 
             Map<String, String> memberShip = tableInfoMapper.selectActMemberShip(userId, roleId);
             if (memberShip == null) {
                 return Result.success(null);
             }
+			redisClient.delByCharacter(userId);
 			identityService.deleteMembership(userId,roleId);
 			return Result.success(null);
 		}
@@ -200,7 +290,13 @@
 			return Result.error(new CodeMsg(3002, e.getMessage()));
 		}
 	}
-
+	/**
+	 *
+	 * @description:  閫氳繃user鑾峰彇鍏宠仈鐨勮鑹�
+	 * @param userId 鐢ㄦ埛id
+	 * @return: 瑙掕壊id鍒楄〃
+	 *
+	 */
 	@Override
 	public List<String> getRoleByUser(String userId) {
 		List<Group> list = identityService.createGroupQuery().groupMember(userId).list();

--
Gitblit v1.8.0