package com.huashe.park.core.service.impl;

import java.util.List;

import org.locationtech.jts.geom.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huashe.common.annotation.DataSource;
import com.huashe.common.enums.DataSourceType;
import com.huashe.park.common.geo.GeoUtils;
import com.huashe.park.core.mapper.BdFenceInfoMapper;
import com.huashe.park.core.service.IBdFenceInfoService;
import com.huashe.park.domain.entity.BdFenceInfo;

/**
 * 围栏基础信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@Service
@DataSource(DataSourceType.PKB)
public class BdFenceInfoServiceImpl implements IBdFenceInfoService {
    @Autowired
    private BdFenceInfoMapper bdFenceInfoMapper;

    /**
     * 查询围栏基础信息
     *
     * @param id 围栏基础信息主键
     * @return 围栏基础信息
     */
    @Override
    public BdFenceInfo selectBdFenceInfoById(Long id) {
        return bdFenceInfoMapper.selectBdFenceInfoById(id);
    }

    /**
     * 查询围栏基础信息列表
     *
     * @param bdFenceInfo 围栏基础信息
     * @return 围栏基础信息
     */
    @Override
    public List<BdFenceInfo> selectBdFenceInfoList(BdFenceInfo bdFenceInfo) {
        return bdFenceInfoMapper.selectBdFenceInfoList(bdFenceInfo);
    }

    /**
     * 新增围栏基础信息
     *
     * @param bdFenceInfo 围栏基础信息
     * @return 结果
     */
    @Override
    public int insertBdFenceInfo(BdFenceInfo bdFenceInfo) {
        Point polyCenter = GeoUtils.getPolyCenter(bdFenceInfo.getPoly());
        bdFenceInfo.setCenterLat(polyCenter.getY());
        bdFenceInfo.setCenterLng(polyCenter.getX());
        return bdFenceInfoMapper.insertBdFenceInfo(bdFenceInfo);
    }

    /**
     * 修改围栏基础信息
     *
     * @param bdFenceInfo 围栏基础信息
     * @return 结果
     */
    @Override
    public int updateBdFenceInfo(BdFenceInfo bdFenceInfo) {
        Point polyCenter = GeoUtils.getPolyCenter(bdFenceInfo.getPoly());
        bdFenceInfo.setCenterLat(polyCenter.getY());
        bdFenceInfo.setCenterLng(polyCenter.getX());
        return bdFenceInfoMapper.updateBdFenceInfo(bdFenceInfo);
    }

    /**
     * 批量删除围栏基础信息
     *
     * @param ids 需要删除的围栏基础信息主键
     * @return 结果
     */
    @Override
    public int deleteBdFenceInfoByIds(Long[] ids) {
        return bdFenceInfoMapper.deleteBdFenceInfoByIds(ids);
    }

    /**
     * 删除围栏基础信息信息
     *
     * @param id 围栏基础信息主键
     * @return 结果
     */
    @Override
    public int deleteBdFenceInfoById(Long id) {
        return bdFenceInfoMapper.deleteBdFenceInfoById(id);
    }
}
