package com.zksy.controller.property;

import com.zksy.property.domain.AMaintenanceRecords;
import com.zksy.property.service.AMaintenanceRecordsService;
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;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 维护记录控制层
 * @date 2025/6/24 14:33:13
 */

@RestController
@RequestMapping("/amaintenanceRecords")
@Api(tags = "维护记录",description = "维护记录desc")
public class AMaintenanceRecordsController {
    @Autowired
    private AMaintenanceRecordsService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "维护记录查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String maintenanceDate,String maintenanceContent,String maintenanceType){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, maintenanceDate,maintenanceContent,maintenanceType));
    }
    @GetMapping("/getAMaintenanceRecordsList")
    @ApiOperation(value = "维护记录查询")
    public AjaxResult getAMaintenanceRecordsList(String maintenanceDate,String maintenanceContent,String maintenanceType){
        return AjaxResult.success(service.getAMaintenanceRecordsList(maintenanceDate,maintenanceContent,maintenanceType));
    }
    @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 AMaintenanceRecords entity) {
        return service.save(entity) ? AjaxResult.success(entity) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "维护记录修改")
    public AjaxResult update(@RequestBody AMaintenanceRecords 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.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }

    @GetMapping("/getByDeviceId")
    @ApiOperation(value = "根据设备Id查询维护记录")
    public AjaxResult getByDeviceId(String deviceId){
        return AjaxResult.success(service.getByDeviceId(deviceId));
    }

}
