package com.camunda.demo.controller;
import io.swagger.annotations.ApiOperation;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.identity.*;
import org.camunda.bpm.engine.impl.identity.Account;
import org.camunda.bpm.engine.impl.persistence.entity.GroupEntity;
import org.camunda.bpm.engine.impl.persistence.entity.TenantEntity;
import org.camunda.bpm.engine.impl.persistence.entity.UserEntity;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.task.TaskQuery;
import org.camunda.commons.utils.IoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.File;
import java.lang.annotation.Native;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class BpmUserContorller {
@Autowired
IdentityService identityService;
@ApiOperation(value = "启动流程", notes = "根据流程定义key启动最新版本并且无租户的流程")
@RequestMapping(value = "/saveUser", method = RequestMethod.POST, consumes = "application/json")
public void saveUser(@RequestBody UserEntity userEntity) throws Exception{
userEntity.setId("zcc1");
userEntity.setEmail("zcc@qq.com");
userEntity.setFirstName("zcc");
userEntity.setLastName("zcc");
userEntity.setDbPassword("1");
userEntity.setSalt("1");
identityService.saveUser(userEntity);
}
@ApiOperation(value = "查询用户", notes = "查询用户")
@RequestMapping(value = "/UserQuery/{first}", method = RequestMethod.POST, consumes = "application/json")
public void createUserQuery(@PathVariable String first){
UserQuery userQuery = identityService.createUserQuery().userFirstName(first);
List<User> list = userQuery.list();
for (int i=0;i<list.size();i++){
User user = list.get(i);
System.out.println(user.getFirstName());
System.out.println(user.getLastName());
System.out.println(user.getId());
System.out.println(user.getPassword());
System.out.println(user.getEmail());
}
}
@ApiOperation(value = "启动流程", notes = "根据流程定义key启动最新版本并且无租户的流程")
@RequestMapping(value = "/deleteUser/{userId}", method = RequestMethod.GET, consumes = "application/json")
public void deleteUser(@PathVariable String userId){
identityService.deleteUser(userId);
}
@ApiOperation(value = "启动流程", notes = "根据流程定义key启动最新版本并且无租户的流程")
@RequestMapping(value = "/saveGroup", method = RequestMethod.POST, consumes = "application/json")
public void saveGroup(@RequestBody GroupEntity groupEntity) throws Exception{
groupEntity.setId("group1");
groupEntity.setName("项目1");
groupEntity.setType("工作流");
identityService.saveGroup(groupEntity);
}
@ApiOperation(value = "查询群组", notes = "查询群组")
@RequestMapping(value = "/groupQuery", method = RequestMethod.GET, consumes = "application/json")
public void createGroupQuery(){
GroupQuery groupQuery = identityService.createGroupQuery();
List<Group> list = groupQuery.list();
for (int i=0;i<list.size();i++){
Group group = list.get(i);
System.out.println(group.getId());
System.out.println(group.getName());
System.out.println(group.getType());
}
}
@ApiOperation(value = "查询群组", notes = "查询群组")
@RequestMapping(value = "/groupQueryMembership", method = RequestMethod.GET, consumes = "application/json")
public void createMembership(){
String userId="zcc2";String groupId="group1";
identityService.createMembership(userId,groupId);
}
@ApiOperation(value = "删除群组", notes = "删除群组")
@RequestMapping(value = "/deleteGroup", method = RequestMethod.POST, consumes = "application/json")
public void deleteGroup(){
String groupId="group1";
identityService.deleteGroup(groupId);
}
@ApiOperation(value = "保存租户", notes = "保存租户")
@RequestMapping(value = "/saveTenant", method = RequestMethod.POST, consumes = "application/json")
public void saveTenant(){
TenantEntity tenantEntity=new TenantEntity();
tenantEntity.setId("A");
tenantEntity.setName("A系统");
identityService.saveTenant(tenantEntity);
}
@ApiOperation(value = "创建租户和人之间到关系", notes = "创建租户和群组之间到关系")
@RequestMapping(value = "/createTenantUserMembership", method = RequestMethod.POST, consumes = "application/json")
public void createTenantUserMembership(){
String tenantId="A";String userId="zcc2";
identityService.createTenantUserMembership(tenantId,userId);
}
@ApiOperation(value = "创建租户和群组之间到关系")
@RequestMapping(value = "/createTenantGroupMembership", method = RequestMethod.POST, consumes = "application/json")
public void createTenantGroupMembership(){
String tenantId="A";String groupId="group1";
identityService.createTenantGroupMembership(tenantId,groupId);
}
@ApiOperation(value = "查询租户和人之间到关系")
@RequestMapping(value = "/createUserQueryMemberOfTenant", method = RequestMethod.POST, consumes = "application/json")
public void createUserQueryMemberOfTenant(){
String tenantId="A";
UserQuery userQuery = identityService.createUserQuery();
List<User> list = userQuery.memberOfTenant(tenantId).list();
for (int i=0;i<list.size();i++){
User user = list.get(i);
System.out.println(user.getFirstName());
System.out.println(user.getLastName());
System.out.println(user.getId());
System.out.println(user.getPassword());
System.out.println(user.getEmail());
}
}
@ApiOperation(value = "查询群组和租户间到关系")
@RequestMapping(value = "/createGroupQueryMemberOfTenant", method = RequestMethod.POST, consumes = "application/json")
public void createGroupQueryMemberOfTenant(){
String tenantId="A";
GroupQuery groupQuery = identityService.createGroupQuery();
List<Group> list = groupQuery.memberOfTenant(tenantId).list();
for (int i=0;i<list.size();i++){
Group group = list.get(i);
System.out.println(group.getId());
System.out.println(group.getName());
System.out.println(group.getType());
}
}
@ApiOperation(value = "更新用户信息")
@RequestMapping(value = "/setUserAccount", method = RequestMethod.POST, consumes = "application/json")
public void setUserAccount(){
String userId="zcc2";
String userPassword="1";
String accountName="zccAccountName";
String accountUsername="zccAccountUsername";
String accountPassword="zccAccountPassword";
Map<String, String> accountDetails=new HashMap<>();
accountDetails.put("a","a");
identityService.setUserAccount(userId,userPassword,accountName,accountUsername,accountPassword,accountDetails);
}
@ApiOperation(value = "查询用户相关信息")
@RequestMapping(value = "/getUserAccount", method = RequestMethod.POST, consumes = "application/json")
public void getUserAccount(){
String userId="zcc2";
String userPassword="1";
String accountName="zccAccountName";
Account userAccount = identityService.getUserAccount(userId, userPassword, accountName);
System.out.println("@@@@@");
System.out.println(userAccount);
}
@ApiOperation(value = "保存图片")
@RequestMapping(value = "/setUserPicture", method = RequestMethod.POST, consumes = "application/json")
public void setUserPicture(){
String userId="zcc2";
byte[] bytes = IoUtil.fileAsByteArray(new File("src/main/resources/2.jpg"));
Picture picture=new Picture(bytes,"jpg");
identityService.setUserPicture(userId,picture);
}
}