package com.ruoyi.inspection.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.QRCodeReader;
import com.ruoyi.inspection.domain.VoReturnInspectionRecordTable;
import com.ruoyi.inspection.domain.VoViewInspectionRecordTable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inspection.domain.InspectionRecordTable;
import com.ruoyi.inspection.service.IInspectionRecordTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 巡检记录Controller
 *
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/inspection/record")
public class InspectionRecordTableController extends BaseController {
    @Autowired
    private IInspectionRecordTableService inspectionRecordTableService;

    /**
     * 查询巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionRecordTable inspectionRecordTable) {
        startPage();
        List<InspectionRecordTable> list = inspectionRecordTableService.selectInspectionRecordTableList(inspectionRecordTable);
        return getDataTable(list);
    }

    /**
     * 导出巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:export')")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionRecordTable inspectionRecordTable) {
        List<InspectionRecordTable> list = inspectionRecordTableService.selectInspectionRecordTableLists(inspectionRecordTable);
        ExcelUtil<InspectionRecordTable> util = new ExcelUtil<InspectionRecordTable>(InspectionRecordTable.class);
        util.exportExcel(response, list, "巡检记录数据");
    }

    /**
     * 获取巡检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inspectionRecordTableService.selectInspectionRecordTableById(id));
    }

    /**
     * 新增巡检记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:add')")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionRecordTable inspectionRecordTable) {
        System.out.println("巡检记录数据");
        System.out.println(inspectionRecordTable);
        Date now = new Date(); // 获取当前时间
        inspectionRecordTable.setInspectionTime(now);
        return toAjax(inspectionRecordTableService.insertInspectionRecordTable(inspectionRecordTable));
    }

    /**
     * 修改巡检记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:edit')")
    @Log(title = "巡检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionRecordTable inspectionRecordTable) {
        return toAjax(inspectionRecordTableService.updateInspectionRecordTable(inspectionRecordTable));
    }

    /**
     * 删除巡检记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:remove')")
    @Log(title = "巡检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inspectionRecordTableService.deleteInspectionRecordTableByIds(ids));
    }


    /**
     * 查询巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:query')")
    @GetMapping("/view")
    public AjaxResult view(VoViewInspectionRecordTable voViewInspectionRecordTable) {
        return success(inspectionRecordTableService.selectInspectionRecordView(voViewInspectionRecordTable));
    }
}
