package com.yuchen.saas.park.service.controller.elevator;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.elevator.ElevatorFloorGroupDTO;
import com.yuchen.saas.park.api.request.ElevatorFloorGroupRequest;
import com.yuchen.saas.park.api.vo.elevator.ElevatorFloorGroupVO;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorPermissionFloorGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 梯控楼层分组 前端控制器
 * </p>
 *
 * @author baichaojie
 * @since 2024-07-08
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(value = "楼层分组控制器接口", tags = "楼层分组控制器接口")
@RequestMapping("/saasParkElevatorPermissionFloorGroup")
public class SaasParkElevatorPermissionFloorGroupController {

    private final ISaasParkElevatorPermissionFloorGroupService baseService;


    /**
     * 分页 人员分组
     */
    @GetMapping("/pageByParam")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "分页 人员分组", notes = "分页 人员分组")
    public R<IPage<ElevatorFloorGroupVO>> pageByParam(@Valid ElevatorFloorGroupRequest req, Query query) {
        R<IPage<ElevatorFloorGroupVO>> pages = baseService.list(req, query);
        return pages;
    }



    /**
     * 人员分组 新增或修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "人员分组 新增或修改", notes = "人员分组 新增或修改")
    public R saveOrUpdate(@Valid @RequestBody ElevatorFloorGroupDTO elevatorFloorGroupDTO) {
        if (Func.isEmpty(elevatorFloorGroupDTO)) {
            return R.error("人员分组不能为空");
        }
        return R.data(baseService.saveOrUpdateByParam(elevatorFloorGroupDTO));
    }

    /**
     * 根据主表id删除人员分组
     *
     * @param elevatorFloorGroupRequest
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "人员分组 删除", notes = "人员分组 删除")
    public R removeId(@RequestBody ElevatorFloorGroupRequest elevatorFloorGroupRequest) {
        return R.data(baseService.removeById(elevatorFloorGroupRequest.getId()));
    }





}
