package com.yijia.station.controller;

import java.util.Date;
import java.util.List;

import com.yijia.station.domain.StationOilPriceAdjust;
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.StationOilPrice;
import com.yijia.station.service.IStationOilPriceService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 油品价格Controller
 * 
 * @author yijia
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/station/price")
public class StationOilPriceController extends BaseController
{
    @Autowired
    private IStationOilPriceService stationOilPriceService;

    /**
     * 查询油品价格列表
     */
    @PreAuthorize("@ss.hasPermi('station:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(StationOilPrice stationOilPrice)
    {
        startPage();
        List<StationOilPrice> list = stationOilPriceService.selectStationOilPriceList(stationOilPrice);
        return getDataTable(list);
    }

    /**
     * 导出油品价格列表
     */
    @PreAuthorize("@ss.hasPermi('station:price:export')")
    @Log(title = "油品价格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationOilPrice stationOilPrice)
    {
        List<StationOilPrice> list = stationOilPriceService.selectStationOilPriceList(stationOilPrice);
        ExcelUtil<StationOilPrice> util = new ExcelUtil<StationOilPrice>(StationOilPrice.class);
        return util.exportExcel(list, "price");
    }

    /**
     * 获取油品价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('station:price:query')")
    @GetMapping(value = "/{oilPriceId}")
    public AjaxResult getInfo(@PathVariable("oilPriceId") Long oilPriceId)
    {
        return AjaxResult.success(stationOilPriceService.selectStationOilPriceById(oilPriceId));
    }

    /**
     * 新增油品价格
     */
    @PreAuthorize("@ss.hasPermi('station:price:add')")
    @Log(title = "油品价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationOilPrice stationOilPrice)
    {
        return toAjax(stationOilPriceService.insertStationOilPrice(stationOilPrice));
    }

    /**
     * 修改油品价格
     */
    @PreAuthorize("@ss.hasPermi('station:price:edit')")
    @Log(title = "油品价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationOilPrice stationOilPrice)
    {
        return toAjax(stationOilPriceService.updateStationOilPrice(stationOilPrice));
    }

    /**
     * 删除油品价格
     */
    @PreAuthorize("@ss.hasPermi('station:price:remove')")
    @Log(title = "油品价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oilPriceIds}")
    public AjaxResult remove(@PathVariable Long[] oilPriceIds)
    {
        return toAjax(stationOilPriceService.deleteStationOilPriceByIds(oilPriceIds));
    }
}
