package com.usky.fire.controller.web;


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.BaseCompany;
import com.usky.fire.domain.DemReportInfo;
import com.usky.fire.service.DemReportInfoService;
import com.usky.fire.service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 报告信息表 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-03-02
 */
@RestController
@RequestMapping("/demReportInfo")
public class DemReportInfoController {
    @Autowired
    private DemReportInfoService demReportInfoService;

    /**
     * 消防报告-历史报告列表查询
     *
     * @param companyId  单位ID
     * @param sourceType  来源类型
     * @param pageNum      当前页
     * @param pageSize     每页条数
     * @return
     */
    @GetMapping("reportInfoList")
    public ApiResult<CommonPage<DemReportInfo>> reportInfoList(@RequestParam(value = "companyId", required = false) String companyId,
                                                               @RequestParam(value = "sourceType", required = false) String sourceType,
                                                               @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demReportInfoService.reportInfoList(companyId, sourceType, pageNum, pageSize));
    }

    /**
     * 生成报告单位信息-列表查询
     *
     * @param demReportInfoVo
     * @return
     */
    @PostMapping("reportInfoAdd")
    public ApiResult<List<DemReportInfoVo>> reportInfoAdd(@RequestBody DemReportInfoVo demReportInfoVo) {
        return ApiResult.success(demReportInfoService.reportInfoAdd(demReportInfoVo));
    }

    /**
     * 消防报告-推送
     *
     * @param demReportInfoIdVo
     * @return
     */
    @Log(title = "消防报告-推送", businessType = BusinessType.UPDATE)
    @PutMapping("propelsReport")
    public ApiResult<Void> propelsReport(@RequestBody DemReportInfoIdVo demReportInfoIdVo) {
        demReportInfoService.propelsReport(demReportInfoIdVo);
        return ApiResult.success();
    }

    /**
     * 消防报告-查询
     *
     * @param id   报告主键ID
     * @return
     */
    @GetMapping("reportById")
    public ApiResult<List<DemReportInfo>> reportById(@RequestParam(value = "id", required = false) Integer id) {
        return ApiResult.success(demReportInfoService.reportById(id));
    }

    /**
     * 报告读取状态更新
     *
     * @return
     */
    @Log(title = "报告读取状态更新", businessType = BusinessType.UPDATE)
    @PutMapping("/updateReadStatus")
    public ApiResult<Void> updateReadStatus(@RequestBody DemReportInfoVo vo) {
        demReportInfoService.updateReadStatus(vo.getId());
        return ApiResult.success();
    }
}

