package com.inspect.metadata.montdata.controller;

import com.inspect.metadata.montdata.domain.BasedataMontNestRunData;
import com.inspect.metadata.montdata.service.IBasedataMontNestRunDataService;
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.annotation.Resource;
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({"/montdata/nestrundata"})
public class BasedataMontNestRunDataController extends BaseController {
    @Resource
    private IBasedataMontNestRunDataService basedataMontNestRunDataService;

    @RequiresPermissions({"basedata/montdata:nestrundata:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataMontNestRunData basedataMontNestrundata) {
        this.startPage();
        List<BasedataMontNestRunData> list = this.basedataMontNestRunDataService.selectBasedataMontNestRunDataList(basedataMontNestrundata);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata/montdata:nestrundata:export"})
    @Log(
            title = "机巢运行数据",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataMontNestRunData basedataMontNestrundata) {
        List<BasedataMontNestRunData> list = this.basedataMontNestRunDataService.selectBasedataMontNestRunDataList(basedataMontNestrundata);
        ExcelUtil<BasedataMontNestRunData> util = new ExcelUtil<>(BasedataMontNestRunData.class);
        util.exportExcel(response, list, "机巢运行数据数据");
    }

    @RequiresPermissions({"basedata/montdata:nestrundata:query"})
    @GetMapping({"/{mont_nestrundata_id}"})
    public AjaxResult getInfo(@PathVariable("mont_nestrundata_id") Long montNestRunDataId) {
        return AjaxResult.success(this.basedataMontNestRunDataService.selectBasedataMontNestRunDataByMontNestRunDataId(montNestRunDataId));
    }

    @RequiresPermissions({"basedata/montdata:nestrundata:add"})
    @Log(
            title = "机巢运行数据",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataMontNestRunData basedataMontNestrundata) {
        return this.toAjax(this.basedataMontNestRunDataService.insertBasedataMontNestRunData(basedataMontNestrundata));
    }

    @RequiresPermissions({"basedata/montdata:nestrundata:edit"})
    @Log(
            title = "机巢运行数据",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataMontNestRunData basedataMontNestrundata) {
        return this.toAjax(this.basedataMontNestRunDataService.updateBasedataMontNestRunData(basedataMontNestrundata));
    }

    @RequiresPermissions({"basedata/montdata:nestrundata:remove"})
    @Log(
            title = "机巢运行数据",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{mont_nestrundata_ids}"})
    public AjaxResult remove(@PathVariable("mont_nestrundata_ids") Long[] montNestRunDataIds) {
        return this.toAjax(this.basedataMontNestRunDataService.deleteBasedataMontNestRunDataByMontNestRunDataIds(montNestRunDataIds));
    }
}
