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.EmsBaseWorkUnit;
import org.dromara.ems.base.domain.TreeSelects;
import org.dromara.ems.base.service.IEmsBaseWorkUnitService;
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-09
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseWorkUnit")
public class EmsBaseWorkUnitController extends EmsBaseController
{
    
    private final IEmsBaseWorkUnitService emsBaseWorkUnitService;

    /**
     * 查询统计单元信息列表
     */
    @SaCheckPermission("ems/base:baseWorkUnit:list")
    @GetMapping("/list")
    public R<?> list(EmsBaseWorkUnit emsBaseWorkUnit)
    {
        List<EmsBaseWorkUnit> list = emsBaseWorkUnitService.selectEmsBaseWorkUnitList(emsBaseWorkUnit);
        return success(list);
    }

    /**
     * 查询计量设备信息下拉树结构
     */
    @PostMapping("/workUnitTree")
    public R<?> getMonitorInfoTree(EmsBaseWorkUnit baseWorkUnit) {
        List<TreeSelects> list = emsBaseWorkUnitService.selectBaseWorkUnitTreeList(baseWorkUnit);
        return success(list);
    }

    /**
     * 导出统计单元信息列表
     */
    @SaCheckPermission("ems/base:baseWorkUnit:export")
    @Log(title = "统计单元信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseWorkUnit emsBaseWorkUnit)
    {
        List<EmsBaseWorkUnit> list = emsBaseWorkUnitService.selectEmsBaseWorkUnitList(emsBaseWorkUnit);
        ExcelUtil.exportExcel(list, "统计单元信息数据", EmsBaseWorkUnit.class, response);
    }

    /**
     * 获取统计单元信息详细信息
     */
    @SaCheckPermission("ems/base:baseWorkUnit:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsBaseWorkUnitService.selectEmsBaseWorkUnitByObjId(objId));
    }

    /**
     * 新增统计单元信息
     */
    @SaCheckPermission("ems/base:baseWorkUnit:add")
    @Log(title = "统计单元信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseWorkUnit emsBaseWorkUnit)
    {
        return toAjax(emsBaseWorkUnitService.insertEmsBaseWorkUnit(emsBaseWorkUnit));
    }

    /**
     * 修改统计单元信息
     */
    @SaCheckPermission("ems/base:baseWorkUnit:edit")
    @Log(title = "统计单元信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseWorkUnit emsBaseWorkUnit)
    {
        return toAjax(emsBaseWorkUnitService.updateEmsBaseWorkUnit(emsBaseWorkUnit));
    }

    /**
     * 删除统计单元信息
     */
    @SaCheckPermission("ems/base:baseWorkUnit:remove")
    @Log(title = "统计单元信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsBaseWorkUnitService.deleteEmsBaseWorkUnitByObjIds(objIds));
    }
}
