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 com.fastbee.ggroup.mapper.GSiteSluiceInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.ggroup.domain.GSiteSluiceInfo;
import com.fastbee.ggroup.service.IGSiteSluiceInfoService;

/**
 * 水闸基本信息Service业务层处理
 * 
 * @author kerwincui
 * @date 2024-10-31
 */
@Service
public class GSiteSluiceInfoServiceImpl implements IGSiteSluiceInfoService 
{
    @Autowired
    private GSiteSluiceInfoMapper gSiteSluiceInfoMapper;


    /**
     * 根据站点的id查询水闸的站点信息
     *
     * @param siteId 水闸站点的id
     * @return 水闸站点的信息
     */
    @Override
    public GSiteSluiceInfo selectGSiteSluiceInfoBySiteId(Long siteId)
    {
        return gSiteSluiceInfoMapper.selectGSiteSluiceInfoBySiteId(siteId);
    }


    /**
     *
     * @param gSiteSluiceInfo 修改水闸的基本信息
     * @return
     */
    @Override
    public int updateGSiteSluiceInfo(GSiteSluiceInfo gSiteSluiceInfo){
        if (Objects.isNull(gSiteSluiceInfo.getSiteId())){
            throw new ServiceException("站点ID(siteId)字段不能为空！");
        }
        if (Objects.isNull(gSiteSluiceInfoMapper.selectGSiteSluiceInfoById(gSiteSluiceInfo.getId()))){
            gSiteSluiceInfo.setCreateTime(DateUtils.getNowDate());
            return gSiteSluiceInfoMapper.insertGSiteSluiceInfo(gSiteSluiceInfo);
        }
        gSiteSluiceInfo.setUpdateTime(DateUtils.getNowDate());
        return gSiteSluiceInfoMapper.updateGSiteSluiceInfo(gSiteSluiceInfo);
    }

}
