package com.inspect.insreportdata.controller;

import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;
import com.inspect.insreportdata.domain.InspectionReportData;
import com.inspect.insreportdata.service.IInspectionReportDataService;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

@RestController
@RequestMapping({"/insreportdata"})
public class InspectionReportDataController extends BaseController {
    private final IInspectionReportDataService inspectionReportDataService;

   public InspectionReportDataController(IInspectionReportDataService inspectionReportDataService) {
      this.inspectionReportDataService = inspectionReportDataService;
   }

   @RequiresPermissions({"system:insreportdata:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(InspectionReportData inspectionReportData) {
        this.startPage();
        List<InspectionReportData> list = this.inspectionReportDataService.selectInspectionReportDataList(inspectionReportData);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"system:insreportdata:export"})
    @Log(
            title = "巡视报告巡视记录数据",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, InspectionReportData inspectionReportData) {
        List<InspectionReportData> list = this.inspectionReportDataService.selectInspectionReportDataList(inspectionReportData);
        ExcelUtil<InspectionReportData> util = new ExcelUtil<>(InspectionReportData.class);
        util.exportExcel(response, list, "巡视报告巡视记录数据数据");
    }

    @RequiresPermissions({"system:insreportdata:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.inspectionReportDataService.selectInspectionReportDataByLineId(lineId));
    }

    @RequiresPermissions({"system:insreportdata:add"})
    @Log(
            title = "巡视报告巡视记录数据",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody InspectionReportData inspectionReportData) {
        return this.toAjax(this.inspectionReportDataService.insertInspectionReportData(inspectionReportData));
    }

    @RequiresPermissions({"system:insreportdata:edit"})
    @Log(
            title = "巡视报告巡视记录数据",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody InspectionReportData inspectionReportData) {
        return this.toAjax(this.inspectionReportDataService.updateInspectionReportData(inspectionReportData));
    }

    @RequiresPermissions({"system:insreportdata:remove"})
    @Log(
            title = "巡视报告巡视记录数据",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.inspectionReportDataService.deleteInspectionReportDataByLineIds(lineIds));
    }
}
