package com.inspect.patrol.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.patrol.domain.PatrolLinkageStrategy;
import com.inspect.patrol.service.IPatrolLinkageStrategyService;
import io.swagger.annotations.Api;

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;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Api("联动策略")
@RestController
@RequestMapping({"/strategy"})
public class PatrolLinkageStrategyController extends BaseController {
    private final IPatrolLinkageStrategyService patrolLinkageStrategyService;

    public PatrolLinkageStrategyController(IPatrolLinkageStrategyService patrolLinkageStrategyService) {
        this.patrolLinkageStrategyService = patrolLinkageStrategyService;
    }

    @GetMapping({"/list"})
    public TableDataInfo list(PatrolLinkageStrategy patrolLinkageStrategy) {
        this.startPage();
        List<PatrolLinkageStrategy> list = this.patrolLinkageStrategyService.selectPatrolLinkageStrategyList(patrolLinkageStrategy);
        return this.getDataTable(list);
    }

    @Log(
            title = "联动点(hongww)",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolLinkageStrategy patrolLinkageStrategy) {
        List<PatrolLinkageStrategy> list = this.patrolLinkageStrategyService.selectPatrolLinkageStrategyList(patrolLinkageStrategy);
        ExcelUtil<PatrolLinkageStrategy> util = new ExcelUtil<>(PatrolLinkageStrategy.class);
        util.exportExcel(response, list, "联动点(hongww)数据");
    }

    @GetMapping({"/{linkageStrategyId}"})
    public AjaxResult getInfo(@PathVariable("linkageStrategyId") Long linkageStrategyId) {
        return AjaxResult.success(this.patrolLinkageStrategyService.selectPatrolLinkageStrategyByLinkageStrategyId(linkageStrategyId));
    }

    @Log(
            title = "联动点(hongww)",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolLinkageStrategy patrolLinkageStrategy) {
        return this.toAjax(this.patrolLinkageStrategyService.insertPatrolLinkageStrategy(patrolLinkageStrategy));
    }

    @Log(
            title = "联动点(hongww)",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolLinkageStrategy patrolLinkageStrategy) {
        return this.toAjax(this.patrolLinkageStrategyService.updatePatrolLinkageStrategy(patrolLinkageStrategy));
    }

    @Log(
            title = "联动点(hongww)",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{linkageStrategyIds}"})
    public AjaxResult remove(@PathVariable Long[] linkageStrategyIds) {
        return this.toAjax(this.patrolLinkageStrategyService.deletePatrolLinkageStrategyByLinkageStrategyIds(linkageStrategyIds));
    }
}
