package com.ktg.iscs.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.bean.BeanUtils;
import com.ktg.iscs.domain.IsMapPoint;
import com.ktg.iscs.domain.dto.mapPoint.MapPointParamDTO;
import com.ktg.iscs.mapper.IsMapPointMapper;
import com.ktg.iscs.service.IIsMapPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 地图点位数据Service业务层处理
 *
 * @author cgj
 * @date 2025-03-11
 */
@Service
public class IsMapPointServiceImpl extends ServiceImpl<IsMapPointMapper, IsMapPoint> implements IIsMapPointService {

    @Autowired
    private IsMapPointMapper isMapPointMapper;

    @Override
    public Page<IsMapPoint> getIsMapPointPage(Page<IsMapPoint> page, IsMapPoint isMapPoint) {
        Page<IsMapPoint> isMapPointPage = isMapPointMapper.getIsMapPointPage(page, isMapPoint);
        return isMapPointPage;
    }

    @Override
    public List<IsMapPoint> getIsMapPointList(IsMapPoint isMapPoint) {
        return isMapPointMapper.getIsMapPointList(isMapPoint);
    }

    @Override
    public Boolean updateMapPointList(MapPointParamDTO dto) {
        // 1.绑定
        if (!dto.getBindingPoints().isEmpty()) {
            List<IsMapPoint> bindingBean = BeanUtils.toBean(dto.getBindingPoints(), IsMapPoint.class);
            for (IsMapPoint isMapPoint : bindingBean) {
                save(isMapPoint);
            }
            // saveBatch(bindingBean);
        }
        // 2.移动
        if (!dto.getMovePoints().isEmpty()) {
            List<IsMapPoint> moveBean = BeanUtils.toBean(dto.getMovePoints(), IsMapPoint.class);
            for (IsMapPoint isMapPoint : moveBean) {
                updateById(isMapPoint);
            }
            // updateBatchById(moveBean);
        }
        // 3.解绑
        if (!dto.getUnbindingPoints().isEmpty()) {
            List<IsMapPoint> moveBean = BeanUtils.toBean(dto.getUnbindingPoints(), IsMapPoint.class);
            for (IsMapPoint isMapPoint : moveBean) {
                removeById(isMapPoint.getId());
            }
            // removeBatchByIds(moveBean);
        }
        return true;
    }

}
