
package com.cmvr.inspection.service.impl;

import java.util.List;
import java.util.UUID;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmvr.common.utils.SecurityUtils;
import com.cmvr.inspection.domain.vo.InspectionMapVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cmvr.common.utils.DateUtils;
import com.cmvr.inspection.mapper.InspectionMapMapper;
import com.cmvr.inspection.domain.InspectionMap;
import com.cmvr.inspection.service.IInspectionMapService;

/**
 * 巡检地图Service业务层处理
 *
 * @author cmvr-iot
 * @since 2026-05-29
 */
@Service
public class InspectionMapServiceImpl extends ServiceImpl<InspectionMapMapper, InspectionMap> implements IInspectionMapService
{
    @Autowired
    private InspectionMapMapper inspectionMapMapper;

    /**
     * 查询巡检地图
     *
     * @param id 巡检地图主键
     * @return 巡检地图
     */
    @Override
    public InspectionMap selectInspectionMapById(String id)
    {
        return inspectionMapMapper.selectInspectionMapById(id);
    }

    /**
     * 查询巡检地图列表
     *
     * @param inspectionMap 巡检地图
     * @return 巡检地图
     */
    @Override
    public List<InspectionMapVo> selectInspectionMapList(InspectionMap inspectionMap)
    {
        return inspectionMapMapper.selectInspectionMapVoList(inspectionMap);
    }

    /**
     * 新增巡检地图
     *
     * @param inspectionMap 巡检地图
     * @return 结果
     */
    @Override
    public int insertInspectionMap(InspectionMap inspectionMap)
    {
        // 生成UUID作为主键
        if (inspectionMap.getId() == null || inspectionMap.getId().isEmpty()) {
            inspectionMap.setId(UUID.randomUUID().toString().replace("-", ""));
        }
        inspectionMap.setCreateTime(DateUtils.getNowDate());
        inspectionMap.setCreateBy(SecurityUtils.getUsername());
        return inspectionMapMapper.insertInspectionMap(inspectionMap);
    }

    /**
     * 修改巡检地图
     *
     * @param inspectionMap 巡检地图
     * @return 结果
     */
    @Override
    public int updateInspectionMap(InspectionMap inspectionMap)
    {
        inspectionMap.setUpdateTime(DateUtils.getNowDate());
        inspectionMap.setUpdateBy(SecurityUtils.getUsername());
        return inspectionMapMapper.updateInspectionMap(inspectionMap);
    }

    /**
     * 批量删除巡检地图
     *
     * @param ids 需要删除的巡检地图主键
     * @return 结果
     */
    @Override
    public int deleteInspectionMapByIds(String[] ids)
    {
        return inspectionMapMapper.deleteInspectionMapByIds(ids);
    }

    /**
     * 根据机器人ID查询地图列表
     *
     * @param robotId 机器人ID
     * @return 地图列表
     */
    @Override
    public List<InspectionMapVo> getMapsByRobotId(String robotId)
    {
        return inspectionMapMapper.selectMapsByRobotId(robotId);
    }

}