package cn.iocoder.yudao.module.inspection.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.payment.entity.OrderInfo;
import cn.iocoder.yudao.module.payment.service.OrderInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionInfo;
import cn.iocoder.yudao.module.inspection.service.AppInspectionOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin-api/appInspection/order")
public class AppOrderController extends BaseController {
    @Autowired
    private AppInspectionOrderService appInspectionOrderService;
    @Autowired
    private OrderInfoService orderInfoService;

    @GetMapping("/orderList")
    @TenantIgnore
    public CommonResult orderList(String status, String title,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<OrderInfo> page = new Page<>(pageNum, pageSize);
        IPage<OrderInfo> orderInfos = orderInfoService.orderListApp(page, status, title, "jc");
        return success(orderInfos);
    }
    @GetMapping("/orderDetail")
    public CommonResult orderDetail(Long orderId) {
        return CommonResult.success(appInspectionOrderService.orderDetailApp(orderId));
    }
    //获取检测的数据
    @GetMapping("/inspectionList")
    @TenantIgnore
    public CommonResult inspectionList(String status,
                                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<InspectionInfo> page = new Page<>(pageNum, pageSize);
        IPage<InspectionInfo> inspectionInfos = appInspectionOrderService.inspectionList(page,status);
        return success(inspectionInfos);
    }

    //获取检测的详细信息
    @GetMapping("/inspectionDetail")
    public CommonResult inspectionDetail(Long inspectionInfoId) {
        return CommonResult.success(appInspectionOrderService.inspectionDetail(inspectionInfoId));
    }

    //评论商品和星级
    @PostMapping("/reviewOrder")
    public CommonResult reviewOrder(String orderId,Integer starLevel,String reviewStr) throws Exception {
        orderInfoService.reviewOrder(orderId,starLevel,reviewStr);
        return CommonResult.ok();
    }
    //政府部门获取检测的数据统计
    @GetMapping("/statisticsTop")
    public CommonResult statisticsTop() {
        return success(appInspectionOrderService.statisticsTop());
    }

    //政府部门获取检测的数据统计
    @GetMapping("/statisticsMid")
    public CommonResult statisticsMid() {
        return success(appInspectionOrderService.statisticsMid());
    }

    //政府部门获取检测的数据统计
    @GetMapping("/statisticsZXT")
    public CommonResult statisticsZXT(Long partnerId,String type) {
        return success(appInspectionOrderService.statisticsZXT(partnerId,type));
    }
    //政府部门获取检测的数据统计
    @GetMapping("/statisticsOrder")
    public CommonResult statisticsOrder() {
        return success(appInspectionOrderService.statisticsOrder());
    }
    //政府部门获取检测的数据
    @GetMapping("/getPartnerList")
    public CommonResult getPartnerList(String partnerName) {
        return success(appInspectionOrderService.getPartnerList(partnerName));
    }

    //政府部门获取检测的数据
    @GetMapping("/governmentInspectionList")
    public CommonResult governmentInspectionList(String carNum,String status,String partnerId,
                                                 @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                                 @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<InspectionInfo> page = new Page<>(pageNum, pageSize);
        IPage<InspectionInfo> inspectionInfos = appInspectionOrderService.governmentInspectionList(page,carNum,status,partnerId);
        return success(inspectionInfos);
    }

}
