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.github.pagehelper.PageHelper;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.core.page.TableDataInfo;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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 TableDataInfo orderList(String status, String title, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderInfo> orderInfos = orderInfoService.orderListApp(status, title, "jc");
        return getDataTable(orderInfos);
    }
    @GetMapping("/orderDetail")
    public CommonResult orderDetail(Long orderId) {
        return CommonResult.success(appInspectionOrderService.orderDetailApp(orderId));
    }
    //获取检测的数据
    @GetMapping("/inspectionList")
    @TenantIgnore
    public TableDataInfo inspectionList(String status,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<InspectionInfo> inspectionInfos = appInspectionOrderService.inspectionList(status);
        return getDataTable(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 TableDataInfo governmentInspectionList(String carNum,String status,String partnerId,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<InspectionInfo> inspectionInfos = appInspectionOrderService.governmentInspectionList(carNum,status,partnerId);
        return getDataTable(inspectionInfos);
    }

}
