package com.sundot.airport.web.controller.ledger;

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

import com.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.core.page.TableDataInfo;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.ledger.domain.LedgerUnsafeEvent;
import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
import com.sundot.airport.ledger.domain.vo.UnsafeItemVO;
import com.sundot.airport.ledger.domain.vo.UnsafePositionVO;
import com.sundot.airport.ledger.domain.vo.UnsafeTypeVO;
import com.sundot.airport.ledger.service.ILedgerUnsafeEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 不安全事件记录Controller
 */
@RestController
@RequestMapping("/ledger/unsafeEvent")
public class LedgerUnsafeEventController extends BaseController {

    @Autowired
    private ILedgerUnsafeEventService service;

    @PreAuthorize("@ss.hasPermi('ledger:unsafeEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(LedgerUnsafeEvent query) {
        startPage();
        List<LedgerUnsafeEvent> list = service.selectList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ledger:unsafeEvent:export')")
    @Log(title = "不安全事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LedgerUnsafeEvent query) {
        List<LedgerUnsafeEvent> list = service.selectList(query);
        ExcelUtil<LedgerUnsafeEvent> util = new ExcelUtil<>(LedgerUnsafeEvent.class);
        util.exportExcel(response, list, "不安全事件记录");
    }

    @PreAuthorize("@ss.hasPermi('ledger:unsafeEvent:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(service.getById(id));
    }

    /**
     * 功能描述：不安全事件物品分布
     *
     * @param countQueryReq 查询入参
     * @return AjaxResult
     * @method countSeizureStatsItem
     * @author PanHu Sun
     * @date 2026/5/20 16:24
     */
    @PostMapping("/countSeizureStatsItem")
    public AjaxResult countSeizureStatsItem(@RequestBody CountQueryReqVO countQueryReq) {
        List<UnsafeItemVO> unsafeItemList = service.countSeizureStatsItem(countQueryReq);
        return AjaxResult.success(unsafeItemList);
    }

    /**
     * 功能描述：不安全事件类型分布
     *
     * @param countQueryReq 查询入参
     * @return AjaxResult
     * @method countSeizureStatsItem
     * @author PanHu Sun
     * @date 2026/5/20 16:24
     */
    @PostMapping("/countSeizureStatsType")
    public AjaxResult countSeizureStatsType(@RequestBody CountQueryReqVO countQueryReq) {
        List<UnsafeTypeVO> unsafeTypeList = service.countSeizureStatsType(countQueryReq);
        return AjaxResult.success(unsafeTypeList);
    }

    /**
     * 功能描述：不安全事件岗位分布
     *
     * @param countQueryReq 查询入参
     * @return AjaxResult
     * @method countSeizureStatsItem
     * @author PanHu Sun
     * @date 2026/5/20 16:24
     */
    @PostMapping("/countSeizureStatsPost")
    public AjaxResult countSeizureStatsPost(@RequestBody CountQueryReqVO countQueryReq) {
        List<UnsafePositionVO> unsafePositionList = service.countSeizureStatsPost(countQueryReq);
        return AjaxResult.success(unsafePositionList);
    }
}
