package cn.iocoder.yudao.module.smartfactory.api.factoryInfo;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.api.factoryInfo.dto.FactoryInfoDTO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class FactoryInfoApiImpl implements FactoryInfoApi {

    @Resource
    private FactoryInfoService factoryInfoService;

    @Override
    public CommonResult<FactoryInfoDTO> getFactoryInfo(Long factoryId) {

        FactoryInfoDO factoryInfoDO = factoryInfoService.getFactoryInfo(factoryId);
        return success(BeanUtils.toBean(factoryInfoDO, FactoryInfoDTO.class));
    }

    @Override
    public CommonResult<List<FactoryInfoDTO>> getFactoryInfoList(Collection<Long> factoryId) {

        List<FactoryInfoDO> factoryInfoDOS = factoryInfoService.getFactoryList(factoryId);
        return success(BeanUtils.toBean(factoryInfoDOS, FactoryInfoDTO.class));
    }
}
