package com.tofly.xrtygis.custom.service.impl;

import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.xrtygis.custom.entity.dto.WaterparamsDto;
import com.tofly.xrtygis.custom.service.CustomWaterparamService;
import com.tofly.xrtygis.entity.Waterparams;
import com.tofly.xrtygis.service.WaterparamsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 20126
 */
@Service
@AllArgsConstructor
public class CustomWaterparamServiceImpl implements CustomWaterparamService {

    private final WaterparamsService waterparamsService;

    /**
     * 批量添加水质参数配置信息
     *
     * @param dto dto
     * @return true
     */
    @Override
    public boolean insertWaterparams(WaterparamsDto dto) {
        List<Waterparams> waterparams = dto.getWaterparams();
        if (null == waterparams || waterparams.size() == 0 ){
            throw new ToflyDeniedException("传入数据为空");
        }
        for (Waterparams waterparam : waterparams) {
            waterparamsService.save(waterparam);
        }
        return true;
    }

    /**
     * 批量修改水质参数配置信息
     *
     * @param dto dto
     * @return true
     */
    @Override
    public boolean updateWaterparams(WaterparamsDto dto) {
        List<Waterparams> waterparams = dto.getWaterparams();
        if (null == waterparams || waterparams.size() == 0 ){
            throw new ToflyDeniedException("传入数据为空");
        }
        for (Waterparams waterparam : waterparams) {
            waterparamsService.updateById(waterparam);
        }
        return true;
    }
}
