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.common.utils.ValidationUtils;
import org.springframework.stereotype.Service;
import com.fastbee.ggroup.mapper.GSiteMonitorInfoMapper;
import com.fastbee.ggroup.domain.GSiteMonitorInfo;
import com.fastbee.ggroup.service.IGSiteMonitorInfoService;

/**
 * 站点基础信息Service业务层处理
 * 
 * @author kerwincui
 * &#064;date  2024-10-10
 */
@Service
public class GSiteMonitorInfoServiceImpl implements IGSiteMonitorInfoService
{

    private final GSiteMonitorInfoMapper gSiteMonitorInfoMapper;

    public GSiteMonitorInfoServiceImpl(GSiteMonitorInfoMapper gSiteMonitorInfoMapper) {
        this.gSiteMonitorInfoMapper = gSiteMonitorInfoMapper;
    }


    /**
     * 查询站点基础信息
     * 
     * @param id 站点基础信息主键
     * @return 站点基础信息
     */
    @Override
    public GSiteMonitorInfo selectGSiteInfoById(Long id)
    {
        return gSiteMonitorInfoMapper.selectGSiteInfoBySiteId(id);
    }





    /**
     * 修改站点基础信息
     * 
     * @param gSiteMonitorInfo 站点基础信息
     * @return 结果
     */
    @Override
    public int updateGSiteInfo(GSiteMonitorInfo gSiteMonitorInfo)
    {
        //参数校验
        if(Objects.isNull(gSiteMonitorInfo.getSiteId())){
            throw new ServiceException("站点ID(siteId)字段不能为空！");
        }
        if(!ValidationUtils.isMobile(gSiteMonitorInfo.getManagerPhone())){
            throw new ServiceException("站点管理员手机号(managerPhone)格式不正确！");
        }
        //检查是否有该条数据
        if(Objects.isNull(gSiteMonitorInfoMapper.selectGSiteInfoBySiteId(gSiteMonitorInfo.getSiteId()))){
            //没有该条数据，则新增
            gSiteMonitorInfo.setCreateTime(DateUtils.getNowDate());
            return gSiteMonitorInfoMapper.insert(gSiteMonitorInfo);
        }
        gSiteMonitorInfo.setUpdateTime(DateUtils.getNowDate());
        return gSiteMonitorInfoMapper.updateGSiteInfo(gSiteMonitorInfo);
    }



}
