package com.inspect.exec.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.exec.domain.PatrolTaskPointExecRecord;
import com.inspect.exec.service.IPatrolTaskPointExecRecordService;

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({"/point"})
public class PatrolTaskPointExecRecordController extends BaseController {
    private final IPatrolTaskPointExecRecordService patrolTaskPointExecRecordService;

    public PatrolTaskPointExecRecordController(IPatrolTaskPointExecRecordService patrolTaskPointExecRecordService) {
        this.patrolTaskPointExecRecordService = patrolTaskPointExecRecordService;
    }

    @RequiresPermissions({"point:point:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(PatrolTaskPointExecRecord patrolTaskPointExecRecord) {
        this.startPage();
        List<PatrolTaskPointExecRecord> list = this.patrolTaskPointExecRecordService.selectPatrolTaskPointExecRecordList(patrolTaskPointExecRecord);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"point:point:export"})
    @Log(
            title = "任务执行点位记录",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolTaskPointExecRecord patrolTaskPointExecRecord) {
        List<PatrolTaskPointExecRecord> list = this.patrolTaskPointExecRecordService.selectPatrolTaskPointExecRecordList(patrolTaskPointExecRecord);
        ExcelUtil<PatrolTaskPointExecRecord> util = new ExcelUtil<>(PatrolTaskPointExecRecord.class);
        util.exportExcel(response, list, "任务执行点位记录数据");
    }

    @RequiresPermissions({"point:point:query"})
    @GetMapping({"/{pointId}"})
    public AjaxResult getInfo(@PathVariable("pointId") Long pointId) {
        return AjaxResult.success(this.patrolTaskPointExecRecordService.selectPatrolTaskPointExecRecordByPointId(pointId));
    }

    @RequiresPermissions({"point:point:add"})
    @Log(
            title = "任务执行点位记录",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolTaskPointExecRecord patrolTaskPointExecRecord) {
        return this.toAjax(this.patrolTaskPointExecRecordService.insertPatrolTaskPointExecRecord(patrolTaskPointExecRecord));
    }

    @RequiresPermissions({"point:point:edit"})
    @Log(
            title = "任务执行点位记录",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolTaskPointExecRecord patrolTaskPointExecRecord) {
        return this.toAjax(this.patrolTaskPointExecRecordService.updatePatrolTaskPointExecRecord(patrolTaskPointExecRecord));
    }

    @RequiresPermissions({"point:point:remove"})
    @Log(
            title = "任务执行点位记录",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{pointIds}"})
    public AjaxResult remove(@PathVariable Long[] pointIds) {
        return this.toAjax(this.patrolTaskPointExecRecordService.deletePatrolTaskPointExecRecordByPointIds(pointIds));
    }
}
