package com.inspect.metadata.eqpbook.controller;

import com.inspect.metadata.eqpbook.domain.BasedataEqpBookNvr;
import com.inspect.metadata.eqpbook.service.IBasedataEqpBookNvrService;
import com.inspect.metadata.statis.domain.BasedataStatisNvr;
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.base.redis.service.RedisService;
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({"/nvr"})
public class BasedataEqpBookNvrController extends BaseController {
    private final IBasedataEqpBookNvrService basedataEqpBookNvrService;
    final
    RedisService redisService;

    public BasedataEqpBookNvrController(IBasedataEqpBookNvrService basedataEqpBookNvrService, RedisService redisService) {
        this.basedataEqpBookNvrService = basedataEqpBookNvrService;
        this.redisService = redisService;
    }

    @RequiresPermissions({"basedata:nvr:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataEqpBookNvr basedataEqpbookNvr) {
        this.startPage();
        List<BasedataEqpBookNvr> list = this.basedataEqpBookNvrService.selectBasedataEqpbookNvrList(basedataEqpbookNvr);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata:nvr:export"})
    @Log(
            title = "硬盘录像机工况",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataEqpBookNvr basedataEqpbookNvr) {
        List<BasedataEqpBookNvr> list = this.basedataEqpBookNvrService.selectBasedataEqpbookNvrList(basedataEqpbookNvr);
        ExcelUtil<BasedataEqpBookNvr> util = new ExcelUtil<>(BasedataEqpBookNvr.class);
        util.exportExcel(response, list, "硬盘录像机工况数据");
    }

    @RequiresPermissions({"basedata:nvr:query"})
    @GetMapping({"/{nvrId}"})
    public AjaxResult getInfo(@PathVariable("nvrId") Long nvrId) {
        return AjaxResult.success(this.basedataEqpBookNvrService.selectBasedataEqpBookNvrByNvrId(nvrId));
    }

    @RequiresPermissions({"basedata:nvr:add"})
    @Log(
            title = "硬盘录像机工况",
            businessType = BizType.INSERT
    )
    @PostMapping({"/add"})
    public AjaxResult add(@RequestBody BasedataEqpBookNvr basedataEqpbookNvr) {
        return this.toAjax(this.basedataEqpBookNvrService.insertBasedataEqpBookNvr(basedataEqpbookNvr));
    }

    @RequiresPermissions({"basedata:nvr:edit"})
    @Log(
            title = "硬盘录像机工况",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/update"})
    public AjaxResult edit(@RequestBody BasedataEqpBookNvr basedataEqpbookNvr) {
        return this.toAjax(this.basedataEqpBookNvrService.updateBasedataEqpBookNvr(basedataEqpbookNvr));
    }

    @RequiresPermissions({"basedata:nvr:remove"})
    @Log(
            title = "硬盘录像机工况",
            businessType = BizType.DELETE
    )
    @PostMapping({"/{nvrIds}"})
    public AjaxResult remove(@PathVariable Long[] nvrIds) {
        return this.toAjax(this.basedataEqpBookNvrService.deleteBasedataEqpBookNvrByNvrIds(nvrIds));
    }

    @RequiresPermissions({"basedata:nvr:list"})
    @PostMapping({"/selectNewInfo"})
    public AjaxResult selectNewInfo() {
        List<BasedataStatisNvr> basedataStatisNvr = this.basedataEqpBookNvrService.selectNewInfo();
        return AjaxResult.success(basedataStatisNvr);
    }
}
