package com.inspect.taskftp.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.taskftp.domain.PatrolTaskFtp;
import com.inspect.taskftp.service.IPatrolTaskFtpService;

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({"/taskftp"})
public class PatrolTaskFtpController extends BaseController {
    private final IPatrolTaskFtpService patrolTaskFtpService;

    public PatrolTaskFtpController(IPatrolTaskFtpService patrolTaskFtpService) {
        this.patrolTaskFtpService = patrolTaskFtpService;
    }

    @RequiresPermissions({"taskftp:taskftp:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(PatrolTaskFtp patrolTaskFtp) {
        this.startPage();
        List<PatrolTaskFtp> list = this.patrolTaskFtpService.selectPatrolTaskFtpList(patrolTaskFtp);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"taskftp:taskftp:export"})
    @Log(
            title = "taskftp",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolTaskFtp patrolTaskFtp) {
        List<PatrolTaskFtp> list = this.patrolTaskFtpService.selectPatrolTaskFtpList(patrolTaskFtp);
        ExcelUtil<PatrolTaskFtp> util = new ExcelUtil<>(PatrolTaskFtp.class);
        util.exportExcel(response, list, "taskFtp data");
    }

    @RequiresPermissions({"taskftp:taskftp:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.patrolTaskFtpService.selectPatrolTaskFtpByLineId(lineId));
    }

    @RequiresPermissions({"taskftp:taskftp:add"})
    @Log(
            title = "taskftp",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolTaskFtp patrolTaskFtp) {
        return this.toAjax(this.patrolTaskFtpService.insertPatrolTaskFtp(patrolTaskFtp));
    }

    @RequiresPermissions({"taskftp:taskftp:edit"})
    @Log(
            title = "taskftp",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolTaskFtp patrolTaskFtp) {
        return this.toAjax(this.patrolTaskFtpService.updatePatrolTaskFtp(patrolTaskFtp));
    }

    @RequiresPermissions({"taskftp:taskftp:remove"})
    @Log(
            title = "taskftp",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.patrolTaskFtpService.deletePatrolTaskFtpByLineIds(lineIds));
    }
}
