package com.sptg.gateway.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.FloorDto;
import com.sptg.estate.api.entity.Floor;
import com.sptg.estate.api.feigns.FloorFeign;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/grid/floor")
public class FloorController {

    private final FloorFeign floorFeign;

    @GetMapping(value = "/syncFloor/{residentialOldId}")
    public List<Floor> syncFloor(@PathVariable("residentialOldId")Long residentialOldId){
        Page<Floor> page = new Page<>();
        page.setCurrent(1);
        page.setSize(999999999);
        FloorDto floorDto = new FloorDto();
        floorDto.setResidentialId(residentialOldId);
        floorDto.setPage(page);
        ResultBean<Page<Floor>> pageResultBean = this.floorFeign.showFloorList(floorDto);
        if(pageResultBean !=null){
            if(pageResultBean.getData()!=null){
                return pageResultBean.getData().getRecords();
            }
        }
        return null;
    }

    /**
     * 功能描述:楼层列表查询
     * @param floorDto 楼层业务对象（含查询条件）
     * @param page 分页条件
     * @return ResultBean<Page<Floor>>
     *
     *
     */
    @GetMapping(value = "/showFloorList")
    public ResultBean<Page<Floor>> showFloorList(FloorDto floorDto, Page<Floor> page) {
        // 暂时拿全部的数据
//        residentialDto.setOrgPosition("0/1/");
        floorDto.setPage(page);
        return this.floorFeign.showFloorList(floorDto);
    }

    @GetMapping(value = "/findFloorById/{id}")
    public ResultBean<Floor> findFloorById(@PathVariable(value = "id") Long id){
        Floor floor = this.floorFeign.findFloorById(id);
        Assert.notNull(floor,"楼层不存在");
        return new ResultBean<>(ResultEnum.SUCCESS,floor);
    }

}
