package com.bonus.sgzb.material.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.bonus.sgzb.material.domain.RepairAuditDetails;
import com.bonus.sgzb.material.domain.RepairPart;
import com.bonus.sgzb.material.domain.RepairRecord;
import com.bonus.sgzb.material.service.IRepairAuditDetailsService;
import com.bonus.sgzb.material.vo.RepairAuditDetailsVO;
import com.bonus.sgzb.material.vo.ScrapApplyDetailsVO;
import com.bonus.sgzb.material.vo.ScrapAudit;
import io.swagger.annotations.ApiOperation;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;

/**
 * 修试审核详细
 *
 * @author bonus
 * @date 2023-12-16
 */
@RestController
@RequestMapping("/details")
public class RepairAuditDetailsController extends BaseController {
    @Autowired
    private IRepairAuditDetailsService repairAuditDetailsService;

    /**
     * 查询修试审核任务列表
     */
    @ApiOperation("查询修试审核任务列表")
    @GetMapping("/questList")
    public TableDataInfo questList(RepairAuditDetails repairAuditDetails) {
        startPage();
        Map<String, Object> params = repairAuditDetails.getParams();
        if (params != null && !params.isEmpty()) {
            String beginTime = (String) params.get("beginTime");
            String endTime = (String) params.get("endTime");
            params.put("beginTime", beginTime + " 00:00:00");
            params.put("endTime", endTime + " 23:59:59");
            repairAuditDetails.setParams(params);
        }
        List<ScrapApplyDetailsVO> list = repairAuditDetailsService.selectRepairQuestList(repairAuditDetails);
        return getDataTable(list);
    }

    /**
     * 导出修试审核任务列表
     */
    @Log(title = "导出修试审核任务列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairAuditDetails bean) {
        Map<String, Object> params = bean.getParams();
        if (!params.isEmpty()) {
            String beginTime = (String) params.get("beginTime");
            String endTime = (String) params.get("endTime");
            params.put("beginTime", beginTime + " 00:00:00");
            params.put("endTime", endTime + " 23:59:59");
            bean.setParams(params);
        }
        List<RepairAuditDetailsVO> list = repairAuditDetailsService.exportRepairQuestList(bean);
        ExcelUtil<RepairAuditDetailsVO> util = new ExcelUtil<RepairAuditDetailsVO>(RepairAuditDetailsVO.class);
        util.exportExcel(response, list, "修试审核任务列表");
    }

    /**
     * 查看修饰审核任务详细列表
     */
    @ApiOperation("查看修饰审核任务详细列表")
    @GetMapping("/getRepairAuditList")
    public TableDataInfo getRepairAuditList(RepairAuditDetails repairAuditDetails) {
        startPage();
        List<RepairAuditDetails> list = repairAuditDetailsService.getRepairAuditList(repairAuditDetails);
        return getDataTable(list);
    }

    /**
     * 查看维修记录
     */
    @ApiOperation("查看维修记录")
    @GetMapping("/getRepairRecord")
    public TableDataInfo getRepairRecord(RepairAuditDetails repairAuditDetails) {
        startPage();
        List<RepairRecord> list = repairAuditDetailsService.getRepairRecord(repairAuditDetails);
        return getDataTable(list);
    }

    /**
     * 查看配件记录
     */
    @ApiOperation("查看配件记录")
    @GetMapping("/getPartRecord")
    public TableDataInfo getPartRecord(RepairAuditDetails repairAuditDetails) {
        startPage();
        List<RepairPart> list = repairAuditDetailsService.getPartRecord(repairAuditDetails);
        return getDataTable(list);
    }


    /**
     * 修饰任务审核
     */
    @ApiOperation("修饰任务审核")
    @Log(title = "修饰任务审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody ScrapAudit scrapAudit) throws Exception {
        return toAjax(repairAuditDetailsService.auditRepair(scrapAudit));
    }


}
