package com.ics.admin.controller;

import com.ics.admin.domain.Building;
import com.ics.admin.domain.Park;
import com.ics.admin.service.IBuildingService;
import com.ics.admin.service.IParkService;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wf.jwtp.annotation.RequiresPermissions;

import java.util.List;

/**
 * 楼宇管理 提供者
 *
 * @author zzm
 * @date 2021-03-24
 */
@RestController
@RequestMapping("admin/building")
public class BuildingController extends BaseController {

    @Autowired
    private IBuildingService buildingService;

    @Autowired
    private IParkService  parkService;



    /**
     * 查询楼宇管理
     */
    @RequiresPermissions("admin:building:view")
    @GetMapping("get/{id}")
    public Building get(@PathVariable("id") Long id) {
        return buildingService.selectBuildingById(id);
    }

    /**
     * 查询楼宇管理列表
     */
    @RequiresPermissions("admin:building:list")
    @GetMapping("list")
    public R list(Building building) {
        startPage();
        building.setDeleteFlag(0);
        List<Building> buildings = buildingService.selectBuildingList(building);
        return result(buildings);
    }


    /**
     * 新增保存楼宇管理
     */
    @RequiresPermissions("admin:building:add")
    @PostMapping("save")
    public R addSave(@RequestBody Building building) {
//        Park park = parkService.getById(1L);
        return toAjax(buildingService.insertBuilding(building));
    }

    /**
     * 修改保存楼宇管理
     */
    @RequiresPermissions("admin:building:edit")
    @PostMapping("update")
    public R editSave(@RequestBody Building building) {
        return toAjax(buildingService.updateBuilding(building));
    }

    /**
     * 删除楼宇管理
     */
    @RequiresPermissions("admin:building:remove")
    @PostMapping("remove")
    public R remove(String ids) {
        return toAjax(buildingService.deleteBuildingByIds(ids));
    }

}