| | |
| | | package com.highdatas.mdm.service.act.impl; |
| | | |
| | | import com.highdatas.mdm.entity.TUser; |
| | | import com.highdatas.mdm.mapper.TableInfoMapper; |
| | | import com.highdatas.mdm.pojo.CodeMsg; |
| | | import com.highdatas.mdm.pojo.Result; |
| | | import org.activiti.engine.IdentityService; |
| | | import org.activiti.engine.RepositoryService; |
| | | import org.activiti.engine.RuntimeService; |
| | | import org.activiti.engine.identity.Group; |
| | | import org.activiti.engine.identity.User; |
| | | import org.activiti.engine.repository.Model; |
| | | import org.activiti.engine.repository.ProcessDefinition; |
| | | import org.activiti.engine.runtime.ProcessInstance; |
| | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class IdentityServiceImpl extends BaseServiceImpl implements com.highdatas.mdm.service.act.IdentityService{ |
| | |
| | | RuntimeService runtimeService; |
| | | @Autowired |
| | | RepositoryService repositoryService; |
| | | |
| | | @Autowired |
| | | TableInfoMapper tableInfoMapper; |
| | | |
| | | @Override |
| | | public String startProcess(String businessId, String key) { |
| | |
| | | processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); |
| | | } |
| | | } |
| | | |
| | | |
| | | processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), businessId, variables); |
| | | |
| | | String processInstanceId = processInstance.getId(); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Result addUser(String id) { |
| | | User preUser = identityService.createUserQuery().userId(id).singleResult(); |
| | | if (preUser != null) { |
| | | return Result.error(new CodeMsg(6002, "已有相同id的用户存在")); |
| | | } |
| | | try { |
| | | User user = identityService.newUser(id); |
| | | identityService.saveUser(user); |
| | | return Result.success(null); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(6002, e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Result addRole(String id) { |
| | | Group preGroup = identityService.createGroupQuery().groupId(id).singleResult(); |
| | | if (preGroup != null) { |
| | | return Result.error(new CodeMsg(6002, "已有相同id的角色存在")); |
| | | } |
| | | try { |
| | | Group group = identityService.newGroup(id); |
| | | identityService.saveGroup(group); |
| | | return Result.success(null); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(6002, e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Result addUserRole(String roleId, String userId) { |
| | | try { |
| | | User user = identityService.createUserQuery().userId(userId).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); |
| | | } |
| | | identityService.createMembership(userId,roleId); |
| | | return Result.success(null); |
| | | } |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(3002, e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Result deleteUser(String id) { |
| | | try { |
| | | User user = identityService.createUserQuery().userId(id).singleResult(); |
| | | if (user == null) { |
| | | return Result.error(new CodeMsg(3001, "当前用户不存在")); |
| | | } |
| | | identityService.deleteUser(id); |
| | | return Result.success(null); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(3002, e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Result deleteRole(String id) { |
| | | try { |
| | | Group group = identityService.createGroupQuery().groupId(id).singleResult(); |
| | | if (group == null) { |
| | | return Result.error(new CodeMsg(3001, "当前角色不存在")); |
| | | } |
| | | identityService.deleteGroup(id); |
| | | return Result.success(null); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(3002, e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | 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); |
| | | } |
| | | identityService.deleteMembership(userId,roleId); |
| | | return Result.success(null); |
| | | } |
| | | catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(new CodeMsg(3002, e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |