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

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

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
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.enums.BusinessType;
import com.sundot.airport.blocked.domain.BlockedLuggageStatisticsDaily;
import com.sundot.airport.blocked.service.IBlockedLuggageStatisticsDailyService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 每日行李过检查堵统计Controller
 *
 * @author wangxx
 * @date 2026-04-13
 */
@RestController
@RequestMapping("/blocked/daily")
public class BlockedLuggageStatisticsDailyController extends BaseController {
    @Autowired
    private IBlockedLuggageStatisticsDailyService blockedLuggageStatisticsDailyService;

    /**
     * 查询每日行李过检查堵统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        startPage();
        List<BlockedLuggageStatisticsDaily> list = blockedLuggageStatisticsDailyService.selectBlockedLuggageStatisticsDailyList(blockedLuggageStatisticsDaily);
        return getDataTable(list);
    }

    /**
     * 导出每日行李过检查堵统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:export')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        List<BlockedLuggageStatisticsDaily> list = blockedLuggageStatisticsDailyService.selectBlockedLuggageStatisticsDailyList(blockedLuggageStatisticsDaily);
        ExcelUtil<BlockedLuggageStatisticsDaily> util = new ExcelUtil<BlockedLuggageStatisticsDaily>(BlockedLuggageStatisticsDaily.class);
        util.exportExcel(response, list, "每日行李过检查堵统计数据");
    }

    /**
     * 导入每日行李过检查堵统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:import')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, @RequestParam(defaultValue = "false") boolean updateSupport) throws Exception {
        ExcelUtil<BlockedLuggageStatisticsDaily> util = new ExcelUtil<BlockedLuggageStatisticsDaily>(BlockedLuggageStatisticsDaily.class);
        List<BlockedLuggageStatisticsDaily> list = util.importExcel(file.getInputStream());
        String message = blockedLuggageStatisticsDailyService.importData(list, updateSupport);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BlockedLuggageStatisticsDaily> util = new ExcelUtil<BlockedLuggageStatisticsDaily>(BlockedLuggageStatisticsDaily.class);
        util.importTemplateExcel(response, "每日行李过检查堵统计数据");
    }

    /**
     * 获取每日行李过检查堵统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(blockedLuggageStatisticsDailyService.selectBlockedLuggageStatisticsDailyById(id));
    }

    /**
     * 检查数据是否重复
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:add')")
    @GetMapping("/checkDuplicate")
    public AjaxResult checkDuplicate(BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        BlockedLuggageStatisticsDaily duplicate = blockedLuggageStatisticsDailyService.checkDuplicate(blockedLuggageStatisticsDaily);
        if (duplicate != null) {
            return AjaxResult.warn("数据已存在，是否覆盖？", duplicate);
        }
        return success();
    }

    /**
     * 新增每日行李过检查堵统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:add')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        blockedLuggageStatisticsDaily.setCreateBy(getUsername());
        return toAjax(blockedLuggageStatisticsDailyService.insertBlockedLuggageStatisticsDaily(blockedLuggageStatisticsDaily));
    }

    /**
     * 新增或覆盖每日行李过检查堵统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:add')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.INSERT)
    @PostMapping("/addOrOverwrite")
    public AjaxResult addOrOverwrite(@RequestBody BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        blockedLuggageStatisticsDaily.setCreateBy(getUsername());
        blockedLuggageStatisticsDaily.setUpdateBy(getUsername());
        return toAjax(blockedLuggageStatisticsDailyService.insertOrUpdate(blockedLuggageStatisticsDaily));
    }

    /**
     * 修改每日行李过检查堵统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:edit')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlockedLuggageStatisticsDaily blockedLuggageStatisticsDaily) {
        blockedLuggageStatisticsDaily.setUpdateBy(getUsername());
        return toAjax(blockedLuggageStatisticsDailyService.updateBlockedLuggageStatisticsDaily(blockedLuggageStatisticsDaily));
    }

    /**
     * 删除每日行李过检查堵统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:daily:remove')")
    @Log(title = "每日行李过检查堵统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blockedLuggageStatisticsDailyService.deleteBlockedLuggageStatisticsDailyByIds(ids));
    }
}
