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.StationPay;
import com.yijia.station.service.IStationPayService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 油站支付设置Controller
 * 
 * @author yijia
 * @date 2020-12-10
 */
@RestController
@RequestMapping("/station/pay")
public class StationPayController extends BaseController
{
    @Autowired
    private IStationPayService stationPayService;

    /**
     * 查询油站支付设置列表
     */
    @PreAuthorize("@ss.hasPermi('station:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(StationPay stationPay)
    {
        startPage();
        List<StationPay> list = stationPayService.selectStationPayList(stationPay);
        return getDataTable(list);
    }

    /**
     * 导出油站支付设置列表
     */
    @PreAuthorize("@ss.hasPermi('station:pay:export')")
    @Log(title = "油站支付设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationPay stationPay)
    {
        List<StationPay> list = stationPayService.selectStationPayList(stationPay);
        ExcelUtil<StationPay> util = new ExcelUtil<StationPay>(StationPay.class);
        return util.exportExcel(list, "pay");
    }

    /**
     * 获取油站支付设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('station:pay:query')")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return AjaxResult.success(stationPayService.selectStationPayById(payId));
    }

    /**
     * 查询油站支付设置信息
     * @param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('station:pay:queryOne')")
    @GetMapping(value = "/queryOne")
    public AjaxResult queryOne(StationPay stationPay)
    {
        return AjaxResult.success(stationPayService.selectStationPayOne(stationPay));
    }

    /***
     * 根据油站id 查询出pay信息
     * @param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('station:pay:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getPayInfo(@PathVariable("stationId") Long stationId)
    {
        StationPay stationPay=new StationPay();
        stationPay.setStationId(stationId);
        int i=0;
       List<StationPay> list=stationPayService.selectStationPayList(stationPay);
        StationPay pay=new StationPay();
       if(list!=null&&list.size()==1){
           pay.setPayId(list.get(0).getPayId());
           pay.setPayMode(list.get(0).getPayMode());
           pay.setStationId(list.get(0).getStationId());
           pay.setStationName(list.get(0).getStationName());
           pay.setImagePhotosFlag(list.get(0).getImagePhotosFlag());
           pay.setCardEnabledFlag(list.get(0).getCardEnabledFlag());
           pay.setActivityPic(list.get(0).getActivityPic());
           pay.setPreferentialWayShareFlag(list.get(0).getPreferentialWayShareFlag());
           pay.setOtherPreferentialWay(list.get(0).getOtherPreferentialWay());
           pay.setPayCallbackPage(list.get(0).getPayCallbackPage());
           pay.setPayPrintNum(list.get(0).getPayPrintNum());
           pay.setPayCallbackPage(list.get(0).getPayCallbackPage());
           pay.setWsPrintFlag(list.get(0).getWsPrintFlag());
       }
        return AjaxResult.success(pay);
    }

    /**
     * 新增油站支付设置
     */
    @PreAuthorize("@ss.hasPermi('station:pay:add')")
    @Log(title = "油站支付设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationPay stationPay)
    {
        return toAjax(stationPayService.insertStationPay(stationPay));
    }

    /**
     * 修改油站支付设置
     */
    @PreAuthorize("@ss.hasPermi('station:pay:edit')")
    @Log(title = "油站支付设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationPay stationPay)
    {
        return toAjax(stationPayService.updateStationPay(stationPay));
    }

    /**
     * 删除油站支付设置
     */
    @PreAuthorize("@ss.hasPermi('station:pay:remove')")
    @Log(title = "油站支付设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds)
    {
        return toAjax(stationPayService.deleteStationPayByIds(payIds));
    }

}
