package com.usky.fire.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.domain.BaseBuild;
import com.usky.fire.domain.BaseStreetTown;
import com.usky.fire.service.BaseBuildService;
import com.usky.fire.service.vo.BaseBuildAddVO;
import com.usky.fire.service.vo.BaseBuildExportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
 * <p>
 * 建筑信息 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-11-22
 */
@RestController
@RequestMapping("/baseBuild")
public class BaseBuildController {


    @Autowired
    private BaseBuildService baseBuildService;

    /**
     * 建筑信息-列表查询
     *
     * @param buildNum  建筑编号
     * @param buildName 建筑名称
     * @param companyId 单位ID
     * @param pageNum   当前页
     * @param pageSize  每页条数
     * @return
     */
    @GetMapping("baseBuildList")
    public ApiResult<CommonPage<Object>> baseBuildList(@RequestParam(value = "buildNum", required = false) String buildNum,
                                                       @RequestParam(value = "buildName", required = false) String buildName,
                                                       @RequestParam(value = "companyId", required = false) String companyId,
                                                       @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(baseBuildService.baseBuildList(buildNum, buildName, companyId, pageNum, pageSize));
    }

    /**
     * 建筑信息-列表查询-导出
     *
     * @param buildNum  建筑编号
     * @param buildName 建筑名称
     * @param exportTitle 文件名
     * @throws IOException
     */
    @PostMapping("baseBuildListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "buildNum", required = false) String buildNum,
                       @RequestParam(value = "buildName", required = false) String buildName,
                       @RequestParam(value = "exportTitle") String exportTitle)throws IOException{
        List<BaseBuildExportVO> list = baseBuildService.baseBuildListExport(buildNum, buildName);
        ExcelUtil<BaseBuildExportVO> util = new ExcelUtil<BaseBuildExportVO>(BaseBuildExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 建筑信息-修改
     *
     * @param baseBuild
     * @return
     */
    @Log(title = "建筑信息-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateBaseBuild")
    public ApiResult<Void> updateBaseBuild(@RequestBody BaseBuild baseBuild) {
        baseBuildService.updateBaseBuild(baseBuild);
        return ApiResult.success();
    }

    /**
     * 建筑信息-删除
     *
     * @param id 主键ID
     * @return
     */
    @Log(title = "建筑信息-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delBaseBuild")
    public ApiResult<Void> delBaseBuild(@RequestParam(value = "id") Integer id) {
        baseBuildService.delBaseBuild(id);
        return ApiResult.success();
    }

    /**
     * 建筑信息-列表查询
     *
     * @param companyId  建筑编号
     * @param buildName 建筑名称
     * @return
     */
    @GetMapping("baseBuildByIdList")
    public ApiResult<List<BaseBuildAddVO>> baseBuildByIdList(@RequestParam(value = "companyId", required = false) String companyId,
                                                             @RequestParam(value = "buildName", required = false) String buildName) {
        return ApiResult.success(baseBuildService.baseBuildByIdList(companyId, buildName));
    }
}

