package com.ruoyi.project.inspection.controller;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.inspection.domain.TInspectionRecord;
import com.ruoyi.project.inspection.service.ITInspectionRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 巡检记录Controller
 *
 * @author ruoyi
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/inspection/record")
public class TInspectionRecordController extends BaseController
{
    @Autowired
    private ITInspectionRecordService tInspectionRecordService;

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

    /**
     * 导出巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:export')")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TInspectionRecord tInspectionRecord)
    {
        List<TInspectionRecord> list = tInspectionRecordService.selectTInspectionRecordList(tInspectionRecord);
        ExcelUtil<TInspectionRecord> util = new ExcelUtil<TInspectionRecord>(TInspectionRecord.class);
        return util.exportExcel(list, "record");
    }

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

    /**
     * 新增巡检记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:record:add')")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInspectionRecord tInspectionRecord)
    {
        //获取操作人员ID
        Long userId = getUserId();
        tInspectionRecord.setCreaterCode(userId.toString());
        tInspectionRecord.setCreatedate(new Date());
        return toAjax(tInspectionRecordService.insertTInspectionRecord(tInspectionRecord));
    }

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

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