package com.ruoyi.web.controller.ems;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ems.domain.EmsObjModel;
import com.ruoyi.ems.service.IEmsObjModelService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 能源对象属性Controller
 *
 * @author ruoyi
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/ems/object/model")
@Api(value = "EmsObjModelController", description = "能源对象模型管理")
public class EmsObjModelController extends BaseController {
    @Autowired
    private IEmsObjModelService objModelService;

    /**
     * 查询能源对象属性列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EmsObjModel objModel) {
        startPage();
        List<EmsObjModel> list = objModelService.selectObjModelList(objModel);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(EmsObjModel objModel) {
        List<EmsObjModel> list = objModelService.selectObjModelList(objModel);
        return success(list);
    }

    /**
     * 获取能源对象属性详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(objModelService.selectObjModelById(id));
    }

    /**
     * 获取能源对象属性详细信息
     */
    @GetMapping(value = "/getByModelCode")
    public AjaxResult getInfo(@RequestParam(name = "modelCode") String modelCode) {
        return success(objModelService.selectByModelCode(modelCode));
    }

    /**
     * 新增能源对象属性
     */
    @Log(title = "能源对象属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsObjModel objModel) {
        return toAjax(objModelService.insertObjModel(objModel));
    }

    /**
     * 修改能源对象属性
     */
    @Log(title = "能源对象属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsObjModel objModel) {
        return toAjax(objModelService.updateObjModel(objModel));
    }

    /**
     * 删除能源对象属性
     */
    @Log(title = "能源对象属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(objModelService.deleteObjModelByIds(ids));
    }
}
