package com.fastbee.ggroup.service.impl;

import java.util.List;
import java.util.Objects;

import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.ggroup.mapper.GSiteReservoirInfoMapper;
import com.fastbee.ggroup.domain.GSiteReservoirInfo;
import com.fastbee.ggroup.service.IGSiteReservoirInfoService;

/**
 * 水库站点基础信息Service业务层处理
 * 
 * @author kerwincui
 * @date 2024-10-23
 */
@Service
public class GSiteReservoirInfoServiceImpl implements IGSiteReservoirInfoService 
{
    @Autowired
    private GSiteReservoirInfoMapper gSiteReservoirInfoMapper;



    /**
     * 根据站点的id查询水闸的站点信息
     * @param siteId 水闸站点的id
     * @return 水闸站点的信息
     */

    public GSiteReservoirInfo selectGSiteReservoirInfoBySiteId(Long siteId){
        return gSiteReservoirInfoMapper.selectGSiteReservoirInfoBySiteId(siteId);
    }

    /**
     * 修改水库站点基础信息
     * 
     * @param gSiteReservoirInfo 水库站点基础信息
     * @return 结果
     */
    @Override
    public int updateGSiteReservoirInfo(GSiteReservoirInfo gSiteReservoirInfo)
    {
        //必要参数校验
        if(Objects.isNull(gSiteReservoirInfo.getSiteId())){
            throw new ServiceException("站点ID(siteId)字段不能为空！");
        }
        //检查是否有该条数据
        if(Objects.isNull(gSiteReservoirInfoMapper.selectGSiteReservoirInfoBySiteId(gSiteReservoirInfo.getSiteId()))){
            //没有该条数据则新增
            gSiteReservoirInfo.setCreateTime(DateUtils.getNowDate());
            return gSiteReservoirInfoMapper.insert(gSiteReservoirInfo);
        }
        gSiteReservoirInfo.setUpdateTime(DateUtils.getNowDate());
        return gSiteReservoirInfoMapper.updateGSiteReservoirInfo(gSiteReservoirInfo);
    }

}
