package com.bonus.material.comprehensive.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.comprehensive.entity.RentDetailDto;
import com.bonus.material.device.domain.DevInfo;
import com.bonus.material.device.domain.vo.DevInfoVo;
import com.bonus.material.device.service.DevInfoService;
import com.bonus.material.order.domain.OrderInfoDto;
import com.bonus.material.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：liang.chao
 * 综合查询
 */
@Api(tags = "综合查询")
@RestController
@RequestMapping("/comprehensive")
public class ComprehensiveController extends BaseController {

    @Resource
    private DevInfoService devInfoService;

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "综合查询-装备信息")
    @GetMapping("/devList")
    public AjaxResult getDevList(DevInfoVo devInfo) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<DevInfoVo> list = devInfoService.getDevList(devInfo);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 在租装备信息查询
     */
    @ApiOperation(value = "综合查询-在租装备信息查询")
    @GetMapping("/getLeaseDevList")
    public AjaxResult getLeaseDevList(DevInfoVo devInfo) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<DevInfoVo> list = devInfoService.getLeaseDevList(devInfo);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    @ApiOperation(value = "综合查询-设备租赁明细")
    @GetMapping("/rentDetails")
    public AjaxResult getRentDetails(DevInfoVo devInfo) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<RentDetailDto> list = orderService.getRentDetails(devInfo);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    @ApiOperation(value = "综合查询-订单信息查询")
    @GetMapping("/orderDetails")
    public AjaxResult getOrderDetails(OrderInfoDto orderInfoDto) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<OrderInfoDto> list = orderService.getOrderInfos(orderInfoDto);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    @ApiOperation(value = "订单确认--同意")
    @PostMapping("/orderConfirm/{orderId}")
    public AjaxResult orderConfirm(@PathVariable String orderId) {
        return orderService.orderConfirm(orderId);
    }

    @ApiOperation(value = "订单确认--驳回")
    @PostMapping("/orderReject/{orderId}")
    public AjaxResult orderReject(@PathVariable String orderId) {
        return orderService.orderReject(orderId);
    }

    @ApiOperation(value = "订单确认--驳回")
    @GetMapping("/getCategoryList")
    public AjaxResult getCategoryList(String keyWord) {
        return orderService.getCategoryList(keyWord);
    }


}
