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.domain.GSiteReservoirInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.ggroup.mapper.GSiteIrrigateInfoMapper;
import com.fastbee.ggroup.domain.GSiteIrrigateInfo;
import com.fastbee.ggroup.service.IGSiteIrrigateInfoService;

/**
 * 灌区基础信息Service业务层处理
 * 
 * @author kerwincui
 * @date 2024-11-04
 */
@Service
public class GSiteIrrigateInfoServiceImpl implements IGSiteIrrigateInfoService 
{
    @Autowired
    private GSiteIrrigateInfoMapper gSiteIrrigateInfoMapper;

    /**
     * 查询灌区基础信息
     * 
     * @param SiteId 灌区基础信息外键
     * @return 灌区基础信息
     */
    @Override
    public GSiteIrrigateInfo selectGSiteIrrigateInfoBySiteId(Long SiteId)
    {
        return gSiteIrrigateInfoMapper.selectGSiteIrrigateInfoBySiteId(SiteId);
    }
    /**
     * 修改灌区站点基础信息
     * @param gSiteIrrigateInfo 灌区站点基础信息
     * @return 结果
     */
    @Override
    public int updateGSiteIrrigateInfo(GSiteIrrigateInfo gSiteIrrigateInfo)
    {
        //必要参数校验
        if(Objects.isNull(gSiteIrrigateInfo.getSiteId())){
            throw new ServiceException("站点ID(siteId)字段不能为空！");
        }
        //检查是否有该条数据
        if(Objects.isNull(gSiteIrrigateInfoMapper.selectGSiteIrrigateInfoBySiteId(gSiteIrrigateInfo.getSiteId()))){
            //没有该条数据则新增
            gSiteIrrigateInfo.setCreateTime(DateUtils.getNowDate());
            return gSiteIrrigateInfoMapper.insert(gSiteIrrigateInfo);
        }
        gSiteIrrigateInfo.setUpdateTime(DateUtils.getNowDate());
        return gSiteIrrigateInfoMapper.updateGSiteIrrigateInfo(gSiteIrrigateInfo);
    }
}
