package com.railway.web.controller.business.baseinfo;


import com.railway.business.baseinfo.domain.BusPrevent;
import com.railway.business.baseinfo.domain.BusZzdzxx;
import com.railway.business.baseinfo.domain.vo.BusPreventQueryVo;
import com.railway.business.baseinfo.domain.vo.BusSmartQueryVo;
import com.railway.business.baseinfo.service.IBusPreventService;
import com.railway.business.baseinfo.service.IBusZzdzxxService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wuhonghao
 */
@Api(tags = "智能查询 - 九防台账")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/prevent")
public class BusPreventController extends BaseController {

    private final IBusPreventService busPreventService;
    private final IBusZzdzxxService busZzdzxxService;

    public BusPreventController(IBusPreventService busPreventService,IBusZzdzxxService busZzdzxxService) {
        this.busPreventService = busPreventService;
        this.busZzdzxxService = busZzdzxxService;
    }

    @ApiOperation(value = "智能查询")
    @GetMapping(value = "smartQuery")
    public TableDataInfo smartQuery(BusSmartQueryVo busSmartQueryVo) {
        //如果传入查询条件为支柱号则将支柱号转化为公里标
        if(busSmartQueryVo.getPillarCode()!=null){
            BusZzdzxx busZzdzxx = new BusZzdzxx();
            busZzdzxx.setPillarCode(busSmartQueryVo.getPillarCode());
            busZzdzxx.setXingbie(busSmartQueryVo.getXingbie());
            busZzdzxx.setStationId(busSmartQueryVo.getStationId());
            List<BusZzdzxx> list = busZzdzxxService.getList(busZzdzxx);
            if(list!=null&&list.size()==1){
                busSmartQueryVo.setMarker(list.get(0).getMarker());
            }else{
                return null;
            }
        }
        if(busSmartQueryVo.getPillarArea()==null||busSmartQueryVo.getPillarArea().equals("")){
            busSmartQueryVo.setPillarArea("500");
        }

        startPage();
        List<BusPrevent> list = busPreventService.smartQuery(busSmartQueryVo);
        return getDataTable(list);
    }

}
