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.stereotype.Service;
import com.fastbee.ggroup.mapper.GSiteRiverInfoMapper;
import com.fastbee.ggroup.domain.GSiteRiverInfo;
import com.fastbee.ggroup.service.IGSiteRiverInfoService;

/**
 * 河流基础信息Service业务层处理
 * 
 * @author kerwincui
 * &#064;date  2024-10-22
 */
@Service
public class GSiteRiverInfoServiceImpl implements IGSiteRiverInfoService
{
    private final GSiteRiverInfoMapper gSiteRiverInfoMapper;

    public GSiteRiverInfoServiceImpl(GSiteRiverInfoMapper gSiteRiverInfoMapper) {
        this.gSiteRiverInfoMapper = gSiteRiverInfoMapper;
    }

    /**
     * 查询河流基础信息
     * 
     * @param id 河流基础信息主键
     * @return 河流基础信息
     */
    @Override
    public GSiteRiverInfo selectGRiverInfoBySiteId(Long id)
    {
        return gSiteRiverInfoMapper.selectGRiverInfoBySiteId(id);
    }


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

}
