package com.jd.lightapplication.controller;

import com.jd.lightapplication.common.lang.R;
import com.jd.lightapplication.model.InspectionRecord;
import com.jd.lightapplication.model.dto.InspectionRecordAddDto;
import com.jd.lightapplication.model.dto.InspectionRecordQueryDto;
import com.jd.lightapplication.model.vo.InspectionRecordVo;
import com.jd.lightapplication.service.InspectionRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.annotation.Resource;


@Slf4j
@RestController()
@RequestMapping("/api/inspection/record")
@Api(tags="巡检记录表")
public class InspectionRecordController {

    @Resource
    private InspectionRecordService inspectionRecordService;

    @GetMapping("/list")
    @ApiOperation(value = "1、分页查询")
    public R queryPageBean(Page page, InspectionRecordQueryDto inspectionRecordQueryDto) {
        return R.success(inspectionRecordService.queryByPage(page,inspectionRecordQueryDto));
    }

    @PostMapping("/addBean")
    @ApiOperation(value = "2、新增")
    public R addBean(@RequestBody InspectionRecordAddDto inspectionRecordAddDto) {
        inspectionRecordService.save(inspectionRecordAddDto);
        return R.success();
    }

    @PostMapping("/updateBean")
    @ApiOperation(value = "3、修改")
    public R updateBean(@RequestBody InspectionRecord inspectionRecord) {
        inspectionRecordService.updateById(inspectionRecord);
        return R.success();
    }

    @PostMapping("/deleteById")
    @ApiOperation(value = "4、删除")
    public R deleteById(long id) {
        inspectionRecordService.removeById(id);
        return R.success();
    }

    @GetMapping("/queryDetails")
    @ApiOperation(value = "5、根据巡检记录id查询巡检详情")
    public R queryDetails(long id) {
        return R.success(inspectionRecordService.queryDetails(id));
    }

}