package com.ylx.web.controller.massage;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.annotation.Log;
import com.ylx.common.core.controller.BaseController;
import com.ylx.common.core.domain.R;
import com.ylx.common.core.domain.model.LoginUser;
import com.ylx.common.enums.BusinessType;
import com.ylx.common.utils.poi.ExcelUtil;
import com.ylx.order.domain.TOrder;
import com.ylx.order.service.TOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 订单表 前端控制器
 */
@RestController
@Slf4j
@Api(tags = {"财务管理"})
@RequestMapping("api/financial/v1")
public class TFinancialIncomeController extends BaseController {
    @Resource
    private TOrderService orderService;

    /**
     * PC收入明细
     *
     * @param page
     * @param order
     * @return R
     */
    @Log(title = "PC收入明细信息", businessType = BusinessType.OTHER)
    @ApiOperation("PC收入明细信息")
    @RequestMapping(value = "pc/getOrderIncome", method = RequestMethod.GET)
    public R getPcOrderIncome(Page<TOrder> page, TOrder order) {
        try {
            LoginUser loginUser = this.getLoginUser();
            log.info("登录用户信息：{}", JSON.toJSONString(loginUser));
//            order.setDeptId(loginUser.getDeptId().toString());
//            Page<TOrder> all = orderService.getPcOrderIncome(page, order);
            Page<TOrder> all = new Page<>();
            return R.ok(all);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @ApiOperation("导出")
    @PostMapping(value = "pc/export")
    public void export(HttpServletResponse response, Page<TOrder> page, TOrder param) {
        LoginUser loginUser = this.getLoginUser();
        log.info("登录用户信息：{}", JSON.toJSONString(loginUser));
//        param.setDeptId(loginUser.getDeptId().toString());
//        Page<TOrder> all = orderService.getAll(page, param);
        Page<TOrder> all = new Page<>();
        ExcelUtil<TOrder> util = new ExcelUtil<>(TOrder.class);
        util.exportExcel(response, all.getRecords(), "订单");
    }
}
