package com.bz.rmcp.alarm.service.impl;

import com.bz.rmcp.alarm.service.DeviceMeasuringPointService;
import com.zcxk.rmcp.api.vo.MeasuringPointVo;
import com.zcxk.rmcp.core.dao.ProductMeasuringDictMapper;
import com.zcxk.rmcp.core.dao.ProductMeasuringPointMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linqingwei
 * @date 2021-08-06 18:33
 */
@Service
public class DeviceMeasuringPointServiceImpl implements DeviceMeasuringPointService {

    @Resource
    private ProductMeasuringPointMapper productMeasuringPointMapper;
    @Resource
    private ProductMeasuringDictMapper productMeasuringDictMapper;

    @Override
    @Cacheable(value = "CacheMeasuringPoint", key = "#productId",unless = "#result == null")
    public List<MeasuringPointVo> getMeasuringPoint(Integer productId) {
        List<MeasuringPointVo> list = productMeasuringPointMapper.getList(productId);
        list.forEach(measuringPointDto -> {
            measuringPointDto.setDictList(productMeasuringDictMapper.getList(measuringPointDto.getId()));
        });
        return list;
    }
}
