package com.yijia.station.controller;

import java.util.List;

import com.yijia.common.core.domain.model.LoginUser;
import com.yijia.common.utils.SecurityUtils;
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.StationPic;
import com.yijia.station.service.IStationPicService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 油站支付管理图片Controller
 *
 * @author yijia
 * @date 2021-03-19
 */
@RestController
@RequestMapping("/station/pic")
public class StationPicController extends BaseController
{
    @Autowired
    private IStationPicService stationPicService;

    /**
     * 查询油站支付管理图片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StationPic stationPic)
    {
        startPage();
        List<StationPic> list = stationPicService.selectStationPicList(stationPic);
        return getDataTable(list);
    }

    /**
     * 导出油站支付管理图片列表
     */
    @Log(title = "油站支付管理图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationPic stationPic)
    {
        List<StationPic> list = stationPicService.selectStationPicList(stationPic);
        ExcelUtil<StationPic> util = new ExcelUtil<StationPic>(StationPic.class);
        return util.exportExcel(list, "pic");
    }

    /**
     * 获取油站支付管理图片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stationPicService.selectStationPicById(id));
    }

    /**
     * 新增油站支付管理图片
     */
    @Log(title = "油站支付管理图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationPic stationPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        stationPic.setStationId(currentUser.getUser().getDeptId());
        stationPic.setStationName(currentUser.getUser().getDept().getDeptName());
        return toAjax(stationPicService.insertStationPic(stationPic));
    }

    /**
     * 修改油站支付管理图片
     */
    @Log(title = "油站支付管理图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationPic stationPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        stationPic.setStationId(currentUser.getUser().getDeptId());
        stationPic.setStationName(currentUser.getUser().getDept().getDeptName());
        return toAjax(stationPicService.updateStationPic(stationPic));
    }

    /**
     * 删除油站支付管理图片
     */
    @Log(title = "油站支付管理图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stationPicService.deleteStationPicByIds(ids));
    }
}
