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.DemFireStatistics;
import com.usky.fire.service.DemFireStatisticsService;
import com.usky.fire.service.vo.FirePlaceExportVO;
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.Map;
import java.util.List;

/**
 * <p>
 * 火灾事故说明总表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/firePlace")
public class FirePlaceController {

    @Autowired
    private DemFireStatisticsService demFireStatisticsService;

    /**
     * 起火场所信息-列表查询
     *
     * @param fireNumber 火灾序号
     * @param id         主键ID
     * @param pageNum    当前页
     * @param pageSize   每页条数
     * @return
     */
    @GetMapping("firePlaceList")
    public ApiResult<CommonPage<Map<String, Object>>> firePlaceList(@RequestParam(value = "fireNumber", required = false) String fireNumber,
                                                                    @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(demFireStatisticsService.firePlaceList(fireNumber, id, pageNum, pageSize));
    }

    /**
     * 起火场所信息-列表查询-导出
     *
     * @param fireNumber 火灾序号
     * @param exportTitle 文件名
     * @throws IOException
     */
    @PostMapping("firePlaceListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "fireNumber", required = false) String fireNumber,
                       @RequestParam(value = "exportTitle") String exportTitle)throws IOException {
        List<FirePlaceExportVO> list = demFireStatisticsService.firePlaceListExport(fireNumber);
        ExcelUtil<FirePlaceExportVO> util = new ExcelUtil<FirePlaceExportVO>(FirePlaceExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 起火场所信息-修改
     *
     * @param demFireStatistics
     * @return
     */
    @Log(title = "起火场所信息-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateFirePlace")
    public ApiResult<Void> updateFirePlace(@RequestBody DemFireStatistics demFireStatistics) {
        demFireStatisticsService.updateFirePlace(demFireStatistics);
        return ApiResult.success();
    }

}

