package com.zksy.infrared.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.common.core.domain.Result;
import com.zksy.common.utils.SearchUtil;
import com.zksy.infrared.domain.CompanyElectric;
import com.zksy.infrared.service.CompanyElectricService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project dh-server-micro
 * @description 公司关联红外电表控制层
 * @date 2025/9/15 16:56:35
 */
@RestController
@RequestMapping("/companyElectric")
@Api(tags = "公司关联红外电表",description = "公司关联红外电表desc")
public class CompanyElectricController {

    @Autowired
    private CompanyElectricService service;

    @GetMapping("/findByPage")
    @ApiOperation(value = "分页查询")
    public Result findByPage(long pageNum, long pageSize, String conditionJson) throws Exception {
        Page<CompanyElectric> page = service.page(new Page<>(pageNum, pageSize), SearchUtil.parseWhereSql(conditionJson));
        return Result.ok(page);
    }
    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有")
    public Result getAll(String conditionJson) throws Exception {
        return Result.ok(service.list(SearchUtil.parseWhereSql(conditionJson)));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据id查询")
    public Result getById(@PathVariable String id) throws Exception {
        return Result.ok(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public Result save(@RequestBody CompanyElectric entity) throws Exception {
        return Result.ok(service.save(entity));
    }
    @PostMapping("/update")
    @ApiOperation(value = "更新")
    public Result update(@RequestBody CompanyElectric entity) throws Exception {
        return Result.ok(service.updateById(entity));
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除")
    public Result deleteBatch(@RequestBody String[] ids) throws Exception {
        return Result.ok(service.removeByIds(Arrays.asList(ids)));
    }
}
