package com.yijia.station.controller;

import java.util.Arrays;
import java.util.List;

import com.yijia.common.core.domain.entity.SysDept;
import com.yijia.common.core.domain.model.LoginUser;
import com.yijia.common.utils.SecurityUtils;
import com.yijia.station.domain.StationPic;
import com.yijia.station.service.IStationPicService;
import com.yijia.system.service.ISysDeptService;
import com.yijia.system.service.ISysUserService;
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/pay11")
public class StationPay111Controller extends BaseController
{
    @Autowired
    private IStationPayService stationPayService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
     * 查询油站支付设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StationPay stationPay)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            stationPay.setStationIdList(list);
            stationPay.setStationId(null);
        }
        startPage();
        List<StationPay> stationPayList = stationPayService.selectStationPayList(stationPay);
        return getDataTable(stationPayList);
    }

    /**
     * 导出油站支付设置列表
     */
    @Log(title = "油站支付设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationPay stationPay)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            stationPay.setStationIdList(list);
            stationPay.setStationId(null);
        }
        List<StationPay> stationPayList = stationPayService.selectStationPayList(stationPay);
        ExcelUtil<StationPay> util = new ExcelUtil<StationPay>(StationPay.class);
        return util.exportExcel(stationPayList, "pay");
    }

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

    /**
     * 查询油站支付设置信息
     * @param
     * @return
     */
    @GetMapping(value = "/queryOne")
    public AjaxResult queryOne(StationPay stationPay)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            stationPay.setStationIdList(list);
            stationPay.setStationId(null);
        }
        return AjaxResult.success(stationPayService.selectStationPayOne(stationPay));
    }

    /***
     * 根据油站id 查询出pay信息
     * @param
     * @return
     */
    @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.setStationId(list.get(0).getStationId());
           pay.setStationName(list.get(0).getStationName());
           pay.setCardEnabledFlag(list.get(0).getCardEnabledFlag());
           pay.setWsPrintFlag(list.get(0).getWsPrintFlag());
           pay.setPrintSetting(list.get(0).getPrintSetting());
           pay.setIntegralFlag(list.get(0).getIntegralFlag());
           pay.setIntegralPrintFlag(list.get(0).getIntegralPrintFlag());
           pay.setNotice(list.get(0).getNotice());
       }
        return AjaxResult.success(pay);
    }

    /**
     * 新增油站支付设置
     */
    @Log(title = "油站支付设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationPay stationPay)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        stationPay.setStationId(currentUser.getUser().getDeptId());
        if(stationPay.getIntegralFlag()==null ||stationPay.getIntegralFlag()==""){
            stationPay.setIntegralFlag("0");//默认积分功能关闭 1是开启0是关闭
        }
        if(stationPay.getIntegralPrintFlag()==null ||stationPay.getIntegralPrintFlag()==""){
            stationPay.setIntegralPrintFlag("0");//默认积分小票是否打印 1是开启0是关闭
        }
        if(stationPay.getCardEnabledFlag()==null ||stationPay.getCardEnabledFlag()==""){
            stationPay.setCardEnabledFlag("0");//默认电子卡功能关闭 1是开启0是关闭
        }
        if(stationPay.getWsPrintFlag()==null ||stationPay.getWsPrintFlag()==""){
            stationPay.setWsPrintFlag("0");//班结是否打印1是开启0是关闭
        }
        if(stationPay.getDiscountSetting()==null ||stationPay.getDiscountSetting()==""){
            stationPay.setDiscountSetting("0");//默认电子卡功能关闭 1是开启0是关闭
        }
        return toAjax(stationPayService.insertStationPay(stationPay));
    }

    /**
     * 修改油站支付设置
     */
    @Log(title = "油站支付设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationPay stationPay)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        stationPay.setStationId(currentUser.getUser().getDeptId());
        return toAjax(stationPayService.updateStationPay(stationPay));
    }

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

}
