package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.LpbBuilding;
import com.cool.bang.modules.business.service.ILpbBuildingService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 楼幢信息
 *
 * @author Sy
 * @version 1.0.0
 * 2024-10-22 09:27
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "building/v1")
public class LpbBuildingController extends BaseController {

    private ILpbBuildingService lpbBuildingService;

    @Autowired
    public LpbBuildingController(ILpbBuildingService lpbBuildingService) {
        this.lpbBuildingService = lpbBuildingService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','business:building:main')")
    public ResultTable main(PageDomain pageDomain, LpbBuilding param) {
        PageInfo<LpbBuilding> lpbBuildingPage = lpbBuildingService.page(pageDomain, param);
        return pageTable(lpbBuildingPage.getList(), lpbBuildingPage.getTotal());
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Long id) {
        return success(lpbBuildingService.queryById(id));
    }

    @PostMapping
    public Result add(LpbBuilding lpbBuilding) {
        lpbBuilding.insertConfigure();
        return decide(lpbBuildingService.save(lpbBuilding));
    }

    @PostMapping("edit")
    public Result edit(LpbBuilding lpbBuilding) {
        lpbBuildingService.updateHouse(lpbBuilding.getId(),lpbBuilding.getName());
        return decide(lpbBuildingService.update(lpbBuilding));
    }

    @DeleteMapping("{id}")
    public Result remove(@PathVariable Integer id) {
        return decide(lpbBuildingService.removeById(id));
    }

}
