package com.zksy.controller.property;

import com.zksy.property.domain.ADeviceInfo;
import com.zksy.property.service.ADeviceInfoService;
import com.zksy.utils.AjaxResult;
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.time.LocalDateTime;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 设备信息控制层
 * @date 2025/6/24 14:33:13
 */

@RestController
@RequestMapping("/adeviceInfo")
@Api(tags = "设备信息",description = "设备信息desc")
public class ADeviceInfoController {
    @Autowired
    private ADeviceInfoService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "设备信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String deviceName,String deviceType,String deviceNumber){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, deviceName,deviceType,deviceNumber));
    }
    @GetMapping("/getADeviceInfoList")
    @ApiOperation(value = "设备信息查询")
    public AjaxResult getADeviceInfoList(String deviceName,String deviceType,String deviceNumber){
        return AjaxResult.success(service.getADeviceInfoList(deviceName,deviceType,deviceNumber));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询设备信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "设备信息保存")
    public AjaxResult save(@RequestBody ADeviceInfo entity) {
        return service.save(entity) ? AjaxResult.success(entity) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "设备信息修改")
    public AjaxResult update(@RequestBody ADeviceInfo entity) {
        entity.setUpdateTime(LocalDateTime.now());
        return service.updateById(entity) ? AjaxResult.success(entity) : AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "设备信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchId(ids) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }

    @GetMapping("/getBySimplifiedHouseId")
    @ApiOperation(value = "根据房屋id查询设备信息")
    public AjaxResult getBySimplifiedHouseId(String simplifiedHouseId){
        return AjaxResult.success(service.getBySimplifiedHouseId(simplifiedHouseId));
    }

}
