package com.yijia.station.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.station.domain.StationInfo;
import com.yijia.station.service.IStationInfoService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 油站信息Controller
 * 
 * @author yijia
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/station/info")
public class StationInfoController extends BaseController
{
    @Autowired
    private IStationInfoService stationInfoService;

    /**
     * 查询油站信息列表
     */
    @PreAuthorize("@ss.hasPermi('station:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(StationInfo stationInfo)
    {
        startPage();
        List<StationInfo> list = stationInfoService.selectStationInfoList(stationInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('station:info:selectStationInfo')")
    @GetMapping("/selectStationInfo")
    public TableDataInfo selectStationInfo(StationInfo stationInfo)
    {
        List<StationInfo> list = stationInfoService.selectStationInfoList(stationInfo);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('station:info:uploadSignImg')")
    @PostMapping("/uploadSignImg")
    public TableDataInfo uploadSignImg() {
        System.out.println("2222223");
        return null;
    }

    /**
     * 导出油站信息列表
     */
    @PreAuthorize("@ss.hasPermi('station:info:export')")
    @Log(title = "油站信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationInfo stationInfo)
    {
        List<StationInfo> list = stationInfoService.selectStationInfoList(stationInfo);
        ExcelUtil<StationInfo> util = new ExcelUtil<StationInfo>(StationInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取油站信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('station:info:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId)
    {
        return AjaxResult.success(stationInfoService.selectStationInfoById(stationId));
    }

    /**
     * 新增油站信息
     */
    @PreAuthorize("@ss.hasPermi('station:info:add')")
    @Log(title = "油站信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationInfo stationInfo)
    {
        return toAjax(stationInfoService.insertStationInfo(stationInfo));
    }

    /**
     * 修改油站信息
     */
    @PreAuthorize("@ss.hasPermi('station:info:edit')")
    @Log(title = "油站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationInfo stationInfo)
    {
        return toAjax(stationInfoService.updateStationInfo(stationInfo));
    }

    /**
     * 删除油站信息
     */
    @PreAuthorize("@ss.hasPermi('station:info:remove')")
    @Log(title = "油站信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Long[] stationIds)
    {
        return toAjax(stationInfoService.deleteStationInfoByIds(stationIds));
    }
}
