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

/**
 * 订单支付Controller
 *
 * @author yijia
 * @date 2020-12-10
 */
@RestController
@RequestMapping("/station/order")
public class PayOrderController extends BaseController
{
    @Autowired
    private IPayOrderService payOrderService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询订单支付列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        startPage();
        payOrder.setStatus("1");
        List<PayOrder> payOrderList = payOrderService.selectPayOrderList(payOrder);
        return getDataTable(payOrderList);
    }
    /**
     * 查询订单支付列表
     */
    @GetMapping("/listInfo")
    public TableDataInfo listInfo(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOrderType("1");
        payOrder.setStatus("1");
        List<PayOrder> payOrderList = payOrderService.selectPayOrderList(payOrder);
        return getTable(payOrderList);
    }

    /**
     * 查询总金额，总升数
     * @param payOrder
     * @return
     */
    @GetMapping("/selectDaySources")
    public AjaxResult selectDaySources(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        PayOrder order = payOrderService.selectDaySources(payOrder);
        return AjaxResult.success(order);
    }

    /***
     * 根据油品分类，查询油品的总金额，总升数
     * @param payOrder
     * @return
     */
    @GetMapping("/selectOilTypeSources")
    public TableDataInfo selectOilTypeSources(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder> orderList = payOrderService.selectOilTypeSources(payOrder);
        return getTable(orderList);
    }

    /***
     * 根据油品分类，查询油品的总金额，总升数
     * @param payOrder
     * @return
     */
    @GetMapping("/dayOilTypeSources")
    public TableDataInfo dayOilTypeSources(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder> orderList = payOrderService.dayOilTypeSources(payOrder);
        return getTable(orderList);
    }
    /***
     * 根据油品分类，查询油品的总金额，总升数
     * @param payOrder
     * @return
     */
    @GetMapping("/selectOverViewData")
    public AjaxResult selectOverViewData(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        PayOrder order = payOrderService.selectOverViewData(payOrder);
        return AjaxResult.success(order);
    }

    /**
     * 日报数据详细
     */
    @GetMapping("/selectDayReportDetail")
    public TableDataInfo selectDayReportDetail(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        //默认当前登陆人的ID 5冯总油站
        startPage();
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.selectDayReport(payOrder);
        return getDataTable(orderList);
    }

    /***
     * 根据油品分类，查询油品的总金额，总升数
     * @param payOrder
     * @return
     */
    @GetMapping("/selectDayReport")
    public TableDataInfo selectDayReport(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
       List<PayOrder>  orderList = payOrderService.selectDayReport(payOrder);
        return getTable(orderList);
    }

    /**
     * 导出订单支付列表
     */
    @Log(title = "订单支付", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder> payOrderList = payOrderService.selectPayOrderExport(payOrder);
        ExcelUtil<PayOrder> util = new ExcelUtil<PayOrder>(PayOrder.class);

        return util.exportExcel(payOrderList, "order");
    }


    /**
     * 获取订单支付详细信息
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(payOrderService.selectPayOrderById(orderId));
    }

    /**
     * 获取92号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata92")
    public TableDataInfo listQydata92(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("92#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }
    /**
     * 获取95号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata95")
    public TableDataInfo listQydata95(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("95#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }
    /**
     * 获取97号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata98")
    public TableDataInfo listQydata98(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("98#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }

    /**
     * 获取97号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata20")
    public TableDataInfo listQydata20(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("-20#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }
    /**
     * 获取97号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata0")
    public TableDataInfo listQydata0(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("0#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }
    /**
     * 获取97号汽油数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listQydata10")
    public TableDataInfo listQydata10(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setOilName("-10#");
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listQydata(payOrder);
        return getTable(orderList);
    }
    /**
     * 获取x轴数据
     * @param payOrder
     * @return
     */
    @GetMapping("/listXdata")
    public TableDataInfo listXdata(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            payOrder.setStationIdList(list);
            payOrder.setStationId(null);
        }
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        List<PayOrder>  orderList = payOrderService.listXdata(payOrder);
        return getTable(orderList);
    }
    /**
     * 查询油站第一笔订单的数据
     */
    @GetMapping("/getPayOrderInfoMin")
    public AjaxResult getPayOrderInfoMin(PayOrder payOrder)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        payOrder.setStationId(currentUser.getUser().getDeptId());
        payOrder.setStatus("1");
        payOrder.setOrderType("1");
        return  AjaxResult.success(payOrderService.getPayOrderInfoMin(payOrder));
    }
    /**
     * 新增订单支付
     */
    @Log(title = "订单支付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayOrder payOrder)
    {
        return toAjax(payOrderService.insertPayOrder(payOrder));
    }

    /**
     * 修改订单支付
     */
    @Log(title = "订单支付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayOrder payOrder)
    {
        return toAjax(payOrderService.updatePayOrder(payOrder));
    }

    /**
     * 删除订单支付
     */
    @Log(title = "订单支付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(payOrderService.deletePayOrderByIds(orderIds));
    }
}
