package cn.edu.whu.boot.allocation.services.impl;

import cn.edu.whu.boot.allocation.entities.RouteLine;
import cn.edu.whu.boot.allocation.mapper.RouteLineMapper;
import cn.edu.whu.boot.allocation.services.RouteLineService;
import cn.edu.whu.boot.common.utils.collection.OtherUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RouteLineServiceImpl implements RouteLineService {

    private final RouteLineMapper routeLineMapper;

    public RouteLineServiceImpl(RouteLineMapper routeLineMapper) {
        this.routeLineMapper = routeLineMapper;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void insertRouteLine(String databaseName, RouteLine routeLine) {
        routeLine.setBegindate(OtherUtil.changeTimeString(routeLine.getBegindate()));
        routeLine.setStopdate(OtherUtil.changeTimeString(routeLine.getStopdate()));
        routeLine.setPrimaryKeySeq("\'" + databaseName + ".route_line_id_seq" + "\'");
        routeLineMapper.insert(databaseName, routeLine);
    }

    @Override
    public List<RouteLine> findByName(String databaseName , String name)
    {
        return routeLineMapper.findByName(databaseName, name);
    }

    @Override
    public List<RouteLine> findByNameAndTime(String databaseName , String name, String beginTime, String stopTime)
    {
        return routeLineMapper.findByNameAndTime(databaseName, name, beginTime, stopTime);
    }


}
