package com.fastbee.data.controller.xunjian;

import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.xunjian.domain.XjInspectionRecords;
import com.fastbee.xunjian.service.IXjInspectionRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 记录Controller
 *
 * @author kenlixunjian
 * @date 2023-08-04
 */
@RestController
@RequestMapping("/inspection/records")
public class XjInspectionRecordsController extends BaseController
{
    @Autowired
    private IXjInspectionRecordsService klxjInspectionRecordsService;

    /**
     * 查询记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(XjInspectionRecords klxjInspectionRecords)
    {
        startPage();
        List<XjInspectionRecords> list = klxjInspectionRecordsService.selectXjInspectionRecordsList(klxjInspectionRecords);
        return getDataTable(list);
    }


    /**
     * 导出记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:records:export')")
    @Log(title = "记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XjInspectionRecords klxjInspectionRecords)
    {
        List<XjInspectionRecords> list = klxjInspectionRecordsService.selectXjInspectionRecordsList(klxjInspectionRecords);
        ExcelUtil<XjInspectionRecords> util = new ExcelUtil<XjInspectionRecords>(XjInspectionRecords.class);
        util.exportExcel(response, list, "记录数据");
    }

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

    /**
     * 新增记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:records:add')")
    @Log(title = "记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XjInspectionRecords klxjInspectionRecords)
    {
        return toAjax(klxjInspectionRecordsService.insertXjInspectionRecords(klxjInspectionRecords));
    }

    /**
     * 修改记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:records:edit')")
    @Log(title = "记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XjInspectionRecords klxjInspectionRecords)
    {
        return toAjax(klxjInspectionRecordsService.updateXjInspectionRecords(klxjInspectionRecords));
    }

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