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.LedgerSeizureStats;
import com.sundot.airport.ledger.domain.vo.*;
import com.sundot.airport.ledger.service.ILedgerSeizureStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 查获违规品统计Controller
 */
@RestController
@RequestMapping("/ledger/seizureStats")
public class LedgerSeizureStatsController extends BaseController {

    @Autowired
    private ILedgerSeizureStatsService service;

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

    @PreAuthorize("@ss.hasPermi('ledger:seizureStats:export')")
    @Log(title = "查获违规品统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LedgerSeizureStats query) {
        List<LedgerSeizureStats> list = service.selectList(query);
        ExcelUtil<LedgerSeizureStats> util = new ExcelUtil<>(LedgerSeizureStats.class);
        util.exportExcel(response, list, "查获违规品统计");
    }

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

    /**
     * 功能描述：近30天查获数量（总表）
     *
     * @param countQueryReq 查询参数
     * @return AjaxResult
     * @method countSeizureTotalQuantity
     * @author PanHu Sun
     * @date 2026/5/20 10:32
     */
    @PostMapping("/countSeizureTotalQuantity")
    public AjaxResult countSeizureTotalQuantity(@RequestBody CountQueryReqVO countQueryReq) {
        List<CountSeizureTotalQuantityResVO> seizureQuantityList = service.countSeizureTotalQuantity(countQueryReq);
        return AjaxResult.success(seizureQuantityList);
    }

    /**
     * 功能描述：近30天查获数量（员工/小组/班组/部门）
     *
     * @param countQueryReq 查询参数
     * @return AjaxResult
     * @method countSeizureSingleQuantity
     * @author PanHu Sun
     * @date 2026/5/20 10:32
     */
    @PostMapping("/countSeizureSingleQuantity")
    public AjaxResult countSeizureSingleQuantity(@RequestBody CountQueryReqVO countQueryReq) {
        List<CountSeizureSingleQuantityDateResVO> seizureQuantityList = service.countSeizureSingleQuantity(countQueryReq);
        return AjaxResult.success(seizureQuantityList);
    }

    /**
     * 功能描述：查获信息展示
     *
     * @param countQueryReq 查询参数
     * @return AjaxResult
     * @method countSeizureInfoItem
     * @author PanHu Sun
     * @date 2026/5/20 13:32
     */
    @PostMapping("/countSeizureInfoItem")
    public AjaxResult countSeizureInfoItem(@RequestBody CountQueryReqVO countQueryReq) {
        SeizeTotalAndItemVO seizeTotalAndItemVO = service.getTimeRangeStats(countQueryReq);
        return AjaxResult.success(seizeTotalAndItemVO);
    }

    /**
     * 功能描述：查获物品分布
     *
     * @param countQueryReq 查询参数
     * @return AjaxResult
     * @method countSeizeSubjectItemQuantity
     * @author PanHu Sun
     * @date 2026/5/20 13:32
     */
    @PostMapping("/countSeizeSubjectItemQuantity")
    public AjaxResult countSeizeSubjectItemQuantity(@RequestBody CountQueryReqVO countQueryReq) {
        List<SeizeCategoryQuantityVO> seizeCategoryQuantityList = service.countSeizeSubjectItemQuantity(countQueryReq);
        return AjaxResult.success(seizeCategoryQuantityList);
    }

    /**
     * 功能描述：查获工作区域分布
     *
     * @param countQueryReq 查询参数
     * @return AjaxResult
     * @method countSeizureInfoItem
     * @author PanHu Sun
     * @date 2026/5/20 13:32
     */
    @PostMapping("/countSeizeAreaQuantity")
    public AjaxResult countSeizeAreaQuantity(@RequestBody CountQueryReqVO countQueryReq) {
        List<SeizureAreaVO> seizureAreaList = service.countSeizeAreaQuantity(countQueryReq);
        return AjaxResult.success(seizureAreaList);
    }
}
