package com.inspect.metadata.patrolpointmnt.controller;

import com.inspect.metadata.patrolpointmnt.domain.BasedataPatrolType;
import com.inspect.metadata.patrolpointmnt.service.IBasedataPatrolTypeService;
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 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;

@RestController
@RequestMapping({"/patrolpointmnt/patroltype"})
public class BasedataPatrolTypeController extends BaseController {
    private final IBasedataPatrolTypeService basedataPatrolTypeService;

    public BasedataPatrolTypeController(IBasedataPatrolTypeService basedataPatrolTypeService) {
        this.basedataPatrolTypeService = basedataPatrolTypeService;
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataPatrolType basedataPatrolType) {
        this.startPage();
        List<BasedataPatrolType> list = this.basedataPatrolTypeService.selectBasedataPatrolTypeList(basedataPatrolType);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:export"})
    @Log(
            title = "巡视类型",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataPatrolType basedataPatrolType) {
        List<BasedataPatrolType> list = this.basedataPatrolTypeService.selectBasedataPatrolTypeList(basedataPatrolType);
        ExcelUtil<BasedataPatrolType> util = new ExcelUtil<>(BasedataPatrolType.class);
        util.exportExcel(response, list, "巡视类型数据");
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:query"})
    @GetMapping({"/{patrolTypeId}"})
    public AjaxResult getInfo(@PathVariable("patrolTypeId") Long patrolTypeId) {
        return AjaxResult.success(this.basedataPatrolTypeService.selectBasedataPatrolTypeByPatrolTypeId(patrolTypeId));
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:add"})
    @Log(
            title = "巡视类型",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataPatrolType basedataPatrolType) {
        return this.toAjax(this.basedataPatrolTypeService.insertBasedataPatrolType(basedataPatrolType));
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:edit"})
    @Log(
            title = "巡视类型",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataPatrolType basedataPatrolType) {
        return this.toAjax(this.basedataPatrolTypeService.updateBasedataPatrolType(basedataPatrolType));
    }

    @RequiresPermissions({"basedata/patrolpointmnt:patroltype:remove"})
    @Log(
            title = "巡视类型",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{patrolTypeIds}"})
    public AjaxResult remove(@PathVariable Long[] patrolTypeIds) {
        return this.toAjax(this.basedataPatrolTypeService.deleteBasedataPatrolTypeByPatrolTypeIds(patrolTypeIds));
    }
}
