package org.dromara.ems.base.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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.base.domain.EmsBaseMonitorInfo;
import org.dromara.ems.base.domain.TreeSelects;
import org.dromara.ems.base.service.IEmsBaseMonitorInfoService;
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-08
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseMonitorInfo")
public class EmsBaseMonitorInfoController extends EmsBaseController
{
    
    private final IEmsBaseMonitorInfoService emsBaseMonitorInfoService;

    /**
     * 查询计量设备信息列表
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:list")
    @GetMapping("/list")
    public R<?> list(EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        List<EmsBaseMonitorInfo> list = emsBaseMonitorInfoService.selectEmsBaseMonitorInfoList(emsBaseMonitorInfo);
        return success(list);
    }

    /**
     * 查询计量设备信息下拉树结构
     * */
    @PostMapping("/monitorInfoTree")
    public R<?> getMonitorInfoTree(@RequestBody  EmsBaseMonitorInfo baseMonitorInfo) {
        List<TreeSelects> list = emsBaseMonitorInfoService.selectBaseMonitorInfoTreeList(baseMonitorInfo);
        return success(list);
    }

    /**
     * 导出计量设备信息列表
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:export")
    @Log(title = "计量设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        List<EmsBaseMonitorInfo> list = emsBaseMonitorInfoService.selectEmsBaseMonitorInfoList(emsBaseMonitorInfo);
        ExcelUtil.exportExcel(list, "计量设备信息数据", EmsBaseMonitorInfo.class, response);
    }

    /**
     * 获取计量设备信息详细信息
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsBaseMonitorInfoService.selectEmsBaseMonitorInfoByObjId(objId));
    }

    /**
     * 新增计量设备信息
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:add")
    @Log(title = "计量设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        return toAjax(emsBaseMonitorInfoService.insertEmsBaseMonitorInfo(emsBaseMonitorInfo));
    }

    /**
     * 修改计量设备信息
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:edit")
    @Log(title = "计量设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseMonitorInfo emsBaseMonitorInfo)
    {
        return toAjax(emsBaseMonitorInfoService.updateEmsBaseMonitorInfo(emsBaseMonitorInfo));
    }

    /**
     * 删除计量设备信息
     */
    @SaCheckPermission("ems/base:baseMonitorInfo:remove")
    @Log(title = "计量设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsBaseMonitorInfoService.deleteEmsBaseMonitorInfoByObjIds(objIds));
    }
}
