package com.izouma.awesomeadmin.activiti;

import com.izouma.awesomeadmin.model.SysRole;
import com.izouma.awesomeadmin.model.UserInfo;
import com.izouma.awesomeadmin.service.SysRoleService;
import com.izouma.awesomeadmin.service.UserInfoService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.GroupEntityManager;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class CustomGroupEntityManager extends GroupEntityManager {
    @Autowired
    private SysRoleService  sysRoleService;

    @Override
    public List<Group> findGroupsByUser(String userId) {
        List<Group> groupList = new ArrayList<>();
        for (SysRole sysRole : sysRoleService.getUserRoles(Integer.valueOf(userId))) {
            Group group = new GroupEntity();
            group.setId(sysRole.getId().toString());
            group.setName(sysRole.getName());
            group.setType("assignment");
            groupList.add(group);
        }
        return groupList;
    }
}
