package org.dromara.ems.record.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.record.domain.EmsRecordDnbInstant;
import org.dromara.ems.record.service.IEmsRecordDnbInstantService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电实时数据Controller
 *
 * @author Yinq
 * @date 2024-05-11
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/record/recordDnbInstant")
public class EmsRecordDnbInstantController extends EmsBaseController {
    
    private final IEmsRecordDnbInstantService emsRecordDnbInstantService;

    /**
     * 查询电实时数据列表
     */
    @SaCheckPermission("ems/record:recordDnbInstant:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsRecordDnbInstant emsRecordDnbInstant) {
        startPage();
        List<EmsRecordDnbInstant> list = emsRecordDnbInstantService.selectEmsRecordDnbInstantList(emsRecordDnbInstant);
        return getDataTable(list);
    }

    /**
     * 查询电实时数据
     * @param emsRecordDnbInstant
     * @return
     */
    @GetMapping("/dnbInstantList")
    public R<?> dnbInstantList(EmsRecordDnbInstant emsRecordDnbInstant) {
        List<EmsRecordDnbInstant> list = emsRecordDnbInstantService.selectDnbInstantList(emsRecordDnbInstant);
        return success(list);
    }

    /**
     * 导出电实时数据列表
     */
    @SaCheckPermission("ems/record:recordDnbInstant:export")
    @Log(title = "电实时数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsRecordDnbInstant emsRecordDnbInstant) {
        List<EmsRecordDnbInstant> list = emsRecordDnbInstantService.selectEmsRecordDnbInstantList(emsRecordDnbInstant);
        ExcelUtil.exportExcel(list, "电实时数据数据", EmsRecordDnbInstant.class, response);
    }

    /**
     * 获取电实时数据详细信息
     */
    @SaCheckPermission("ems/record:recordDnbInstant:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId) {
        return success(emsRecordDnbInstantService.selectEmsRecordDnbInstantByObjId(objId));
    }

    /**
     * 新增电实时数据
     */
    @SaCheckPermission("ems/record:recordDnbInstant:add")
    @Log(title = "电实时数据", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsRecordDnbInstant emsRecordDnbInstant) {
        return toAjax(emsRecordDnbInstantService.insertEmsRecordDnbInstant(emsRecordDnbInstant));
    }

    /**
     * 修改电实时数据
     */
    @SaCheckPermission("ems/record:recordDnbInstant:edit")
    @Log(title = "电实时数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsRecordDnbInstant emsRecordDnbInstant) {
        return toAjax(emsRecordDnbInstantService.updateEmsRecordDnbInstant(emsRecordDnbInstant));
    }

    /**
     * 删除电实时数据
     */
    @SaCheckPermission("ems/record:recordDnbInstant:remove")
    @Log(title = "电实时数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds) {
        return toAjax(emsRecordDnbInstantService.deleteEmsRecordDnbInstantByObjIds(objIds));
    }
}
