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.PatrolLinkageMessage;
import com.inspect.patrol.service.IPatrolLinkageMessageService;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

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
@RestController
@RequestMapping({"/message"})
public class PatrolLinkageMessageController extends BaseController {
    private final IPatrolLinkageMessageService patrolLinkageMessageService;

    public PatrolLinkageMessageController(IPatrolLinkageMessageService patrolLinkageMessageService) {
        this.patrolLinkageMessageService = patrolLinkageMessageService;
    }

    @GetMapping({"/list"})
    public TableDataInfo list(PatrolLinkageMessage patrolLinkageMessage) {
        this.startPage();
        List<PatrolLinkageMessage> list = this.patrolLinkageMessageService.selectPatrolLinkageMessageList(patrolLinkageMessage);
        return this.getDataTable(list);
    }

    @Log(title = "联动报文", businessType = BizType.EXPORT)
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolLinkageMessage patrolLinkageMessage) {
        List<PatrolLinkageMessage> list = this.patrolLinkageMessageService.selectPatrolLinkageMessageList(patrolLinkageMessage);
        ExcelUtil<PatrolLinkageMessage> util = new ExcelUtil<>(PatrolLinkageMessage.class);
        util.exportExcel(response, list, "联动报文数据");
    }

    @GetMapping({"/{linkageMessageId}"})
    public AjaxResult getInfo(@PathVariable("linkageMessageId") Long linkageMessageId) {
        return AjaxResult.success(this.patrolLinkageMessageService.selectPatrolLinkageMessageByLinkageMessageId(linkageMessageId));
    }

    @Log(title = "联动报文", businessType = BizType.UPDATE)
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolLinkageMessage patrolLinkageMessage) {
        return this.toAjax(this.patrolLinkageMessageService.updatePatrolLinkageMessage(patrolLinkageMessage));
    }

    @Log(title = "联动报文", businessType = BizType.DELETE)
    @PostMapping({"/remove/{linkageMessageIds}"})
    public AjaxResult remove(@PathVariable Long[] linkageMessageIds) {
        return this.toAjax(this.patrolLinkageMessageService.deletePatrolLinkageMessageByLinkageMessageIds(linkageMessageIds));
    }
}
