package com.inspect.img.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.img.domain.InspectionReportImg;
import com.inspect.img.service.IInspectionReportImgService;

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({"/img"})
public class InspectionReportImgController extends BaseController {
    private final IInspectionReportImgService inspectionReportImgService;

    public InspectionReportImgController(IInspectionReportImgService inspectionReportImgService) {
        this.inspectionReportImgService = inspectionReportImgService;
    }

    @RequiresPermissions({"system:img:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(InspectionReportImg inspectionReportImg) {
        this.startPage();
        List<InspectionReportImg> list = this.inspectionReportImgService.selectInspectionReportImgList(inspectionReportImg);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"system:img:export"})
    @Log(
            title = "巡视报告图片资源",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, InspectionReportImg inspectionReportImg) {
        List<InspectionReportImg> list = this.inspectionReportImgService.selectInspectionReportImgList(inspectionReportImg);
        ExcelUtil<InspectionReportImg> util = new ExcelUtil<>(InspectionReportImg.class);
        util.exportExcel(response, list, "巡视报告图片资源数据");
    }

    @RequiresPermissions({"system:img:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.inspectionReportImgService.selectInspectionReportImgByLineId(lineId));
    }

    @RequiresPermissions({"system:img:add"})
    @Log(
            title = "巡视报告图片资源",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody InspectionReportImg inspectionReportImg) {
        return this.toAjax(this.inspectionReportImgService.insertInspectionReportImg(inspectionReportImg));
    }

    @RequiresPermissions({"system:img:edit"})
    @Log(
            title = "巡视报告图片资源",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody InspectionReportImg inspectionReportImg) {
        return this.toAjax(this.inspectionReportImgService.updateInspectionReportImg(inspectionReportImg));
    }

    @RequiresPermissions({"system:img:remove"})
    @Log(
            title = "巡视报告图片资源",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.inspectionReportImgService.deleteInspectionReportImgByLineIds(lineIds));
    }
}
