package com.ruoyi.ibs.datavisual.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.ibs.datavisual.domain.dto.VisitTrajectoryDTO;
import com.ruoyi.ibs.datavisual.domain.entity.VisitTrajectory;
import com.ruoyi.ibs.datavisual.mapper.VisitTrajectoryMapper;
import com.ruoyi.ibs.datavisual.service.VisitTrajectoryService;
import com.ruoyi.ibs.grid.util.GPSUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 吴凯程
 * @Date 2025/4/24
 **/
@Service
public class VisitTrajectoryServiceImpl implements VisitTrajectoryService {
    @Resource
    private VisitTrajectoryMapper visitTrajectoryMapper;

    /**
     * @return
     */
    @Override
    public List<VisitTrajectory> getVisitTrajectoryList(VisitTrajectoryDTO visitTrajectoryDTO) {
        return visitTrajectoryMapper.getVisitTrajectory(visitTrajectoryDTO);
    }

    /**
     * @param date
     * @return
     */
    @Override
    public List<VisitTrajectory> getVisitTrajectoryListByDate(String date) {
        LambdaQueryWrapper<VisitTrajectory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(VisitTrajectory::getDate, date);
        return visitTrajectoryMapper.selectList(queryWrapper);
    }

    /**
     *
     */
    @Override
    public void updateVisitTrajectory() {
        LambdaQueryWrapper<VisitTrajectory> queryWrapper = new LambdaQueryWrapper<>();
        List<VisitTrajectory> visitTrajectories = visitTrajectoryMapper.selectList(queryWrapper);
        for (VisitTrajectory visitTrajectory : visitTrajectories) {
            double[] doubles = GPSUtil.gcj02ToBd09(Double.valueOf(visitTrajectory.getLng()), Double.valueOf(visitTrajectory.getLat()));
            visitTrajectory.setLng(String.valueOf(doubles[0]));
            visitTrajectory.setLat(String.valueOf(doubles[1]));
            visitTrajectoryMapper.updateById(visitTrajectory);
        }
    }
}
