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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.BlockedLuggagePieceDaily;
import com.sundot.airport.blocked.service.IBlockedLuggagePieceDailyService;
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/pieceDaily")
public class BlockedLuggagePieceDailyController extends BaseController {
    @Autowired
    private IBlockedLuggagePieceDailyService blockedLuggagePieceDailyService;

    /**
     * 查询每日各时段查堵行李列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlockedLuggagePieceDaily blockedLuggagePieceDaily) {
        startPage();
        List<BlockedLuggagePieceDaily> list = blockedLuggagePieceDailyService.selectBlockedLuggagePieceDailyList(blockedLuggagePieceDaily);
        return getDataTable(list);
    }

    /**
     * 导出每日各时段查堵行李列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:export')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlockedLuggagePieceDaily blockedLuggagePieceDaily) {
        List<BlockedLuggagePieceDaily> list = blockedLuggagePieceDailyService.selectBlockedLuggagePieceDailyList(blockedLuggagePieceDaily);
        ExcelUtil<BlockedLuggagePieceDaily> util = new ExcelUtil<BlockedLuggagePieceDaily>(BlockedLuggagePieceDaily.class);
        util.exportExcel(response, list, "每日各时段查堵行李数据");
    }

    /**
     * 导入每日各时段查堵行李列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:import')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<BlockedLuggagePieceDaily> util = new ExcelUtil<BlockedLuggagePieceDaily>(BlockedLuggagePieceDaily.class);
        List<BlockedLuggagePieceDaily> list = util.importExcel(file.getInputStream());
        String message = blockedLuggagePieceDailyService.importData(list, updateSupport);
        return success(message);
    }

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

    /**
     * 获取每日各时段查堵行李详细信息
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(blockedLuggagePieceDailyService.selectBlockedLuggagePieceDailyById(id));
    }

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

    /**
     * 新增每日各时段查堵行李
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:add')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlockedLuggagePieceDaily blockedLuggagePieceDaily) {
        blockedLuggagePieceDaily.setCreateBy(getUsername());
        return toAjax(blockedLuggagePieceDailyService.insertBlockedLuggagePieceDaily(blockedLuggagePieceDaily));
    }

    /**
     * 新增或覆盖每日各时段查堵行李
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:add')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.INSERT)
    @PostMapping("/addOrOverwrite")
    public AjaxResult addOrOverwrite(@RequestBody BlockedLuggagePieceDaily blockedLuggagePieceDaily) {
        blockedLuggagePieceDaily.setCreateBy(getUsername());
        blockedLuggagePieceDaily.setUpdateBy(getUsername());
        return toAjax(blockedLuggagePieceDailyService.insertOrUpdate(blockedLuggagePieceDaily));
    }

    /**
     * 修改每日各时段查堵行李
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:edit')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlockedLuggagePieceDaily blockedLuggagePieceDaily) {
        blockedLuggagePieceDaily.setUpdateBy(getUsername());
        return toAjax(blockedLuggagePieceDailyService.updateBlockedLuggagePieceDaily(blockedLuggagePieceDaily));
    }

    /**
     * 删除每日各时段查堵行李
     */
    @PreAuthorize("@ss.hasPermi('blocked:pieceDaily:remove')")
    @Log(title = "每日各时段查堵行李", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blockedLuggagePieceDailyService.deleteBlockedLuggagePieceDailyByIds(ids));
    }
}
