package com.inspect.metadata.eqpbook.controller;

import com.inspect.metadata.eqpbook.domain.BasedataEqpBook;
import com.inspect.metadata.eqpbook.domain.BasedataUavResumeInfo;
import com.inspect.metadata.eqpbook.service.IBasedataEqpBookService;
import com.inspect.metadata.eqpbook.service.IBasedataUavResumeInfoService;
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.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;

@RestController
@RequestMapping({"/eqpbook/uavinfo"})
public class BasedataUavResumeInfoController extends BaseController {
    private final IBasedataUavResumeInfoService basedataUavResumeInfoService;
    private final IBasedataEqpBookService baseDataEqpBookService;

    public BasedataUavResumeInfoController(IBasedataUavResumeInfoService basedataUavResumeInfoService, IBasedataEqpBookService baseDataEqpBookService) {
        this.basedataUavResumeInfoService = basedataUavResumeInfoService;
        this.baseDataEqpBookService = baseDataEqpBookService;
    }

    @RequiresPermissions({"eqpbook:info:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataUavResumeInfo basedataUavResumeInfo) {
        this.startPage();
        List<BasedataUavResumeInfo> list = this.basedataUavResumeInfoService.selectBasedataUavResumeInfoList(basedataUavResumeInfo);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"eqpbook:info:export"})
    @Log(
            title = "基础数据-机器人无人机履历记录（设备台账副表）",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataUavResumeInfo basedataUavResumeInfo) {
        List<BasedataUavResumeInfo> list = this.basedataUavResumeInfoService.selectBasedataUavResumeInfoList(basedataUavResumeInfo);
        ExcelUtil<BasedataUavResumeInfo> util = new ExcelUtil<>(BasedataUavResumeInfo.class);
        util.exportExcel(response, list, "基础数据-机器人无人机履历记录（设备台账副表）数据");
    }

    @RequiresPermissions({"eqpbook:info:query"})
    @GetMapping({"/{recordId}"})
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return AjaxResult.success(this.basedataUavResumeInfoService.selectBasedataUavResumeInfoByRecordId(recordId));
    }

    @RequiresPermissions({"eqpbook:info:add"})
    @Log(
            title = "基础数据-机器人无人机履历记录（设备台账副表）",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataUavResumeInfo basedataUavResumeInfo) {
        return this.toAjax(this.basedataUavResumeInfoService.insertBasedataUavResumeInfo(basedataUavResumeInfo));
    }

    @RequiresPermissions({"eqpbook:info:edit"})
    @Log(
            title = "基础数据-机器人无人机履历记录（设备台账副表）",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataUavResumeInfo basedataUavResumeInfo) {
        return this.toAjax(this.basedataUavResumeInfoService.updateBasedataUavResumeInfo(basedataUavResumeInfo));
    }

    @RequiresPermissions({"eqpbook:info:remove"})
    @Log(
            title = "基础数据-机器人无人机履历记录（设备台账副表）",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{recordIds}"})
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return this.toAjax(this.basedataUavResumeInfoService.deleteBasedataUavResumeInfoByRecordIds(recordIds));
    }

    @RequiresPermissions({"eqpbook:info:query"})
    @Log(
            title = "查询机器人无人机履历记录的父类型",
            businessType = BizType.OTHER
    )
    @GetMapping({"/getUavList"})
    public AjaxResult getUavList() {
        List<BasedataEqpBook> list = this.baseDataEqpBookService.getUavList();
        return AjaxResult.success(list);
    }
}
