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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatParkRoomInfo;
import com.yuchen.saas.park.api.vo.park.PmgbatParkRoomVo;
import com.yuchen.saas.park.service.service.PmgBatParkRoomInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘碧清
 * @date 2021/04/26 11:05
 */
@RestController
@AllArgsConstructor
@RequestMapping("/pmgBatParkRoomInfo")
@Api(value = "房间信息对象", tags = "房间信息接口")
public class PmgBatParkRoomInfoController {
    @Autowired
    private PmgBatParkRoomInfoService pmgBatParkRoomInfoService;

    /**
     * 新增或者修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "批量插入 房间信息", notes = "批量插入 房间信息")
    public R submit(@Valid @RequestBody List<PmgbatParkRoomVo> pmgBatParkRoomVos) {
        return pmgBatParkRoomInfoService.submit(pmgBatParkRoomVos);
    }


    /**
     * 删除 房间信息
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除 房间信息", notes = "删除 房间信息")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(pmgBatParkRoomInfoService.deleteLogic(Func.toLongList(ids)));
    }


    @GetMapping("/getByFloorId")
    @ApiOperation(value = "通过楼层获取房间", notes = "通过楼层获取房间")
    public R<List<PmgBatParkRoomInfo>> getByParkId(@RequestParam Long floorId) {
        List<PmgBatParkRoomInfo> list = pmgBatParkRoomInfoService.list(Wrappers.<PmgBatParkRoomInfo>lambdaQuery().
                eq(PmgBatParkRoomInfo::getFloorId, floorId).orderByDesc(PmgBatParkRoomInfo::getCreateTime));
        return R.data(list);
    }
}
