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.DemMicroStation;
import com.usky.fire.service.DemMicroStationService;
import com.usky.fire.service.vo.DemMicroStationExportVO;
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;
import java.util.Map;

/**
 * <p>
 * 微型消防站 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/demMicroStation")
public class DemMicroStationController {

    @Autowired
    private DemMicroStationService demMicroStationService;

    /**
     * 消防站点管理-列表
     *
     * @param squadron    所属中队
     * @param stationName 消防站名称
     * @param stationType 消防站类型（1：微消站;2：专职站，3：重点微消站）
     * @param id          主键ID
     * @param pageNum     当前页
     * @param pageSize    每页条数
     * @return
     */
    @GetMapping("microStationList")
    public ApiResult<CommonPage<Map<String, Object>>> microStationList(@RequestParam(value = "squadron", required = false) String squadron,
                                                                       @RequestParam(value = "stationName", required = false) String stationName,
                                                                       @RequestParam(value = "stationType", required = false) String stationType,
                                                                       @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                                                                       @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                       @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demMicroStationService.microStationList(squadron, stationName, stationType, id, pageNum, pageSize));
    }

    /**
     * 消防站点管理-列表-导出
     *
     * @param squadron    所属中队
     * @param stationName 消防站名称
     * @param stationType 消防站类型（1：微消站;2：专职站，3：重点微消站）
     * @param exportTitle 文件名
     * @throws IOException
     */
    @PostMapping("microStationListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "squadron", required = false) String squadron,
                       @RequestParam(value = "stationName", required = false) String stationName,
                       @RequestParam(value = "stationType", required = false) String stationType,
                       @RequestParam(value = "exportTitle") String exportTitle)throws IOException {
        List<DemMicroStationExportVO> list = demMicroStationService.microStationListExport(squadron, stationName, stationType);
        ExcelUtil<DemMicroStationExportVO> util = new ExcelUtil<DemMicroStationExportVO>(DemMicroStationExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 消防站点管理-修改
     *
     * @param demMicroStation
     */
    @Log(title = "消防站点管理-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateMicroStation")
    public ApiResult<Void> updateMicroStation(@RequestBody DemMicroStation demMicroStation) {
        demMicroStationService.updateMicroStation(demMicroStation);
        return ApiResult.success();
    }

    /**
     * 消防站点管理-删除
     *
     * @param id 主键ID
     */
    @Log(title = "消防站点管理-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delMicroStation")
    public ApiResult<Void> delMicroStation(@RequestParam(value = "id") Integer id) {
        demMicroStationService.delMicroStation(id);
        return ApiResult.success();
    }

    /**
     * 消防水源管理-天然水源维护-所属中队下拉框
     *
     * @param branchName 支队名称
     * @return
     */
    @GetMapping("microStationDroplistList")
    public ApiResult<List<Map<String, Object>>> microStationDroplistList(@RequestParam(value = "branchName", required = false, defaultValue = "闵行支队") String branchName) {
        return ApiResult.success(demMicroStationService.microStationDroplistList(branchName));
    }
}

