package jnpf.attendance.service.impl;

import cn.hutool.core.bean.BeanUtil;
import jnpf.attendance.service.RV1109MachineService;
import jnpf.base.ActionResult;
import jnpf.permission.V2UserApi;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.vo.v2.user.UserBoundVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * RV1109考勤机服务实现
 *
 * @author yanwenfu
 * @create 2024-04-09
 */
@Service
public class RV1109MachineServiceImpl implements RV1109MachineService {

    @Resource
    private V2UserApi v2UserApi;

    @Override
    public UserEntity getUserInfoById(String userId, String tenantId) {

//        List<UserEntity> userEntityList = userApi.getUserListNoData(Stream.of(userId).collect(Collectors.toList()), tenantId);
        ActionResult<List<UserBoundVO>> allUserInfoBatch = v2UserApi.getAllUserInfoBatch(Stream.of(userId).collect(Collectors.toList()), tenantId);
        if (200 != allUserInfoBatch.getCode() || allUserInfoBatch.getData().isEmpty()) {
            return null;
        }
//        return userEntityList.get(0);
        UserBoundVO userBoundVO = allUserInfoBatch.getData().get(0);
        UserEntity userEntity = BeanUtil.copyProperties(userBoundVO, UserEntity.class);
        userEntity.setRealName(userBoundVO.getUserName());
        return userEntity;
    }
}
