package com.hw.ems.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.hw.common.core.domain.Ztree;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseBuildInfo;
import com.hw.ems.base.service.IBaseBuildInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 建筑信息管理Controller
 *
 * @author YinQ
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/buildInfo")
public class BaseBuildInfoController extends BaseController {
    @Autowired
    private IBaseBuildInfoService baseBuildInfoService;

    /**
     * 查询建筑信息管理列表
     */
    @RequiresPermissions("base:buildInfo:list")
    @GetMapping("/list")
    public AjaxResult list(BaseBuildInfo baseBuildInfo) {
        List<BaseBuildInfo> list = baseBuildInfoService.selectBaseBuildInfoList(baseBuildInfo);
        return success(list);
    }


    /**
     * 导出建筑信息管理列表
     */
    @RequiresPermissions("base:buildInfo:export")
    @Log(title = "建筑信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseBuildInfo baseBuildInfo) {
        List<BaseBuildInfo> list = baseBuildInfoService.selectBaseBuildInfoList(baseBuildInfo);
        ExcelUtil<BaseBuildInfo> util = new ExcelUtil<BaseBuildInfo>(BaseBuildInfo.class);
        util.exportExcel(response, list, "建筑信息管理数据");
    }

    /**
     * 获取建筑信息管理详细信息
     */
    @RequiresPermissions("base:buildInfo:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseBuildInfoService.selectBaseBuildInfoByObjid(objid));
    }

    /**
     * 新增建筑信息管理
     */
    @RequiresPermissions("base:buildInfo:add")
    @Log(title = "建筑信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBuildInfo baseBuildInfo) {
        return toAjax(baseBuildInfoService.insertBaseBuildInfo(baseBuildInfo));
    }

    /**
     * 修改建筑信息管理
     */
    @RequiresPermissions("base:buildInfo:edit")
    @Log(title = "建筑信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBuildInfo baseBuildInfo) {
        return toAjax(baseBuildInfoService.updateBaseBuildInfo(baseBuildInfo));
    }

    /**
     * 删除建筑信息管理
     */
    @RequiresPermissions("base:buildInfo:remove")
    @Log(title = "建筑信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseBuildInfoService.deleteBaseBuildInfoByObjids(objids));
    }

    /**
     * 加载建筑信息管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData() {
        List<Ztree> ztrees = baseBuildInfoService.selectBaseBuildInfoTree();
        return ztrees;
    }

}
