package cn.com.taiji.beidou.ship.track.service.impl;

import cn.com.taiji.beidou.common.utils.DateUtils;
import cn.com.taiji.beidou.ship.track.domain.ShipContainsReq;
import cn.com.taiji.beidou.ship.track.domain.ShipContainsResult;
import cn.com.taiji.beidou.ship.track.domain.ShipTrackReq;
import cn.com.taiji.beidou.ship.track.domain.ShipTrackResult;
import cn.com.taiji.beidou.ship.track.mapper.ShipTrackMapper;
import cn.com.taiji.beidou.ship.track.service.ShipTrackService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

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

/**
 * @Author CHEN
 * @Date 2023/1/12 18:07
 */
@Service
public class ShipTrackServiceImpl implements ShipTrackService {

    @Resource
    private ShipTrackMapper shipTrackMapper;

    @Override
    public List<ShipTrackResult> selectShipTrackDetail(ShipTrackReq shipTrackReq) {
        List<ShipTrackResult> results = shipTrackMapper.selectShipTrackDetail(shipTrackReq);
        //经纬度格式转换
//        results.stream().forEach(result->{
//            BigDecimal longitude = new BigDecimal(result.getLongitude());
//            result.setLongitude(latLng2Dfm(longitude.doubleValue()));
//            BigDecimal latitude = new BigDecimal(result.getLatitude());
//            result.setLatitude(latLng2Dfm(latitude.doubleValue()));
//        });

        return results;
    }
    @Override
    public List<ShipContainsResult> selectShipContainsResults(ShipContainsReq shipContainsReq) {
        shipContainsReq.setEndTime(DateUtils.dateTimeNow("YYYY-MM-dd HH-mm-ss"));
        List<ShipContainsResult> results = shipTrackMapper.selectShipContainsResults(shipContainsReq);
        for (ShipContainsResult shipTrackResult : results) {
            String location = StrUtil.format("POINT ({} {})", shipTrackResult.getLongitude(),shipTrackResult.getLatitude());
            shipTrackResult.setLocation(location);
        }
        return results;
    }

}
