package cn.iocoder.yudao.module.property.controller.admin;

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.property.entity.PropertyKeep;
import cn.iocoder.yudao.module.property.service.PropertyKeepService;
import cn.iocoder.yudao.module.property.vo.PropertyKeepReqVO;
import cn.iocoder.yudao.module.property.vo.PropertyKeepRespVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 资产维修/保养记录 控制层
 *
 * @author 小李
 * @date 11:23 2024/8/16
 **/
@Tag(name = "管理后台 - 资产维修/保养记录")
@RestController
@RequestMapping("/company/property-keep")
@Validated
public class PropertyKeepController {

    @Resource
    private PropertyKeepService propertyKeepService;

    /**
     * 创建资产维修/保养记录
     *
     * @param keepRespVO 资产维修/保养记录对象
     * @author 小李
     * @date 11:26 2024/8/16
     **/
    @PostMapping("/create")
    @Operation(summary = "创建资产维修/保养记录")
    @PreAuthorize("@ss.hasPermission('company:property-keep:create')")
    public CommonResult createPropertyKeep(@RequestBody PropertyKeepRespVO keepRespVO) {
        propertyKeepService.createPropertyKeep(keepRespVO);
        return CommonResult.ok();
    }

    /**
     * 资产维修/保养记录 分页
     * @author 小李
     * @date 15:42 2024/8/16
     * @param pageReqVO 查询对象
     * @param pageNo 页码
     * @param pageSize 条数
    **/
    @GetMapping("/page")
    @Operation(summary = "获得资产维修/保养记录分页")
    @PreAuthorize("@ss.hasPermission('company:property-keep:query')")
    public CommonResult<IPage<?>> getPropertyKeepPage(PropertyKeepReqVO pageReqVO,
                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<PropertyKeep> page = new Page<>(pageNo, pageSize);
        return success(propertyKeepService.getPropertyKeepPage(pageReqVO, page));
    }
}