package org.jeecg.modules.activiti.model.converter;


import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.activiti.engine.impl.persistence.entity.UserEntityImpl;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.RoleVO;
import org.jeecg.common.system.vo.UserVO;

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

/**
 *
 * 工作流用户转换
 *
 * @author LEN
 * @since 2019/6/14 18:17
 */

public class ActivitiConverter {

    public static UserEntity toActivitiUser(UserVO UserVO) {
        UserEntity userEntity = new UserEntityImpl();
        userEntity.setId(UserVO.getId());
        userEntity.setFirstName(UserVO.getRealname());
        userEntity.setLastName(UserVO.getRealname());
        userEntity.setPassword(UserVO.getPassword());
        userEntity.setEmail(UserVO.getEmail());
        userEntity.setRevision(1);
        return userEntity;
    }

    /**
     * 通过角色
     * @param roleDTO
     * @return
     */
    public static GroupEntity toActivitiGroup(RoleVO roleDTO) {
        GroupEntity groupEntity = new GroupEntityImpl();
        groupEntity.setRevision(1);
        groupEntity.setType("assignment");
        groupEntity.setName(roleDTO.getRoleName());
        groupEntity.setId(roleDTO.getId());
        return groupEntity;
    }

    public static List<Group> toActivitiGroups(List<RoleVO> roleCodeList) {
        List<Group> groups = new ArrayList<>();
        for (RoleVO roleDTO : roleCodeList) {
            GroupEntity groupEntity = toActivitiGroup(roleDTO);
            groups.add(groupEntity);
        }
        return groups;
    }

}
