package cn.wise.sc.energy.power.plant.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.wise.sc.energy.power.plant.business.domain.UnitInfo;
import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import cn.wise.sc.energy.power.plant.business.domain.vo.UnitInfoVo;
import cn.wise.sc.energy.power.plant.business.service.IUnitInfoService;
import cn.wise.sc.energy.power.plant.common.core.exception.ResponseEnum;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

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

/**
 * @description: 测点信息服务层实现
 * @author: qh
 * @create: 2020-07-14 16:39
 **/
@Service
public class UnitInfoServiceImpl extends BaseServiceImpl<String, UnitInfo> implements IUnitInfoService {

    @Override
    public List<EntityVo> getUnitInfoByDeviceId(String deviceId) {

        ResponseEnum.LICENCE_NOT_FOUND.assertNotEmpty(deviceId);

        UnitInfo unitInfoExample = new UnitInfo();
        unitInfoExample.setDeviceId(deviceId);
        List<UnitInfo> all = this.repository.findAll(Example.of(unitInfoExample));
        List<EntityVo> rts = new ArrayList<>(all.size());
        for (UnitInfo unitInfo : all) {
            EntityVo entityVo = new UnitInfoVo();
            BeanUtil.copyProperties(unitInfo,entityVo);
            rts.add(entityVo);
        }
        return rts;
    }
}
