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.BlockedMissCheckStatistics;
import com.sundot.airport.blocked.service.IBlockedMissCheckStatisticsService;
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/missReview")
public class BlockedMissCheckStatisticsController extends BaseController {
    @Autowired
    private IBlockedMissCheckStatisticsService blockedMissCheckStatisticsService;

    /**
     * 查询漏检统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        startPage();
        List<BlockedMissCheckStatistics> list = blockedMissCheckStatisticsService.selectBlockedMissCheckStatisticsList(blockedMissCheckStatistics);
        return getDataTable(list);
    }

    /**
     * 导出漏检统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:export')")
    @Log(title = "漏检统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlockedMissCheckStatistics blockedMissCheckStatistics) {
        List<BlockedMissCheckStatistics> list = blockedMissCheckStatisticsService.selectBlockedMissCheckStatisticsList(blockedMissCheckStatistics);
        ExcelUtil<BlockedMissCheckStatistics> util = new ExcelUtil<BlockedMissCheckStatistics>(BlockedMissCheckStatistics.class);
        util.exportExcel(response, list, "漏检统计数据");
    }

    /**
     * 导入漏检统计列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:import')")
    @Log(title = "漏检统计", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<BlockedMissCheckStatistics> util = new ExcelUtil<BlockedMissCheckStatistics>(BlockedMissCheckStatistics.class);
        List<BlockedMissCheckStatistics> list = util.importExcel(file.getInputStream());
        String message = blockedMissCheckStatisticsService.importData(list, updateSupport);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BlockedMissCheckStatistics> util = new ExcelUtil<BlockedMissCheckStatistics>(BlockedMissCheckStatistics.class);
        util.importTemplateExcel(response, "漏检统计数据");
    }

    /**
     * 获取漏检统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(blockedMissCheckStatisticsService.selectBlockedMissCheckStatisticsById(id));
    }

    /**
     * 检查数据是否重复
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:add')")
    @GetMapping("/checkDuplicate")
    public AjaxResult checkDuplicate(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        BlockedMissCheckStatistics duplicate = blockedMissCheckStatisticsService.checkDuplicate(blockedMissCheckStatistics);
        if (duplicate != null) {
            return AjaxResult.warn("数据已存在（被回查人：" + duplicate.getReviewedUserName() + "，回查日期：" + duplicate.getReviewDate() + "，漏检时间：" + duplicate.getMissCheckTime() + "），是否覆盖？", duplicate);
        }
        return success();
    }

    /**
     * 新增漏检统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:add')")
    @Log(title = "漏检统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlockedMissCheckStatistics blockedMissCheckStatistics) {
        blockedMissCheckStatistics.setCreateBy(getUsername());
        return toAjax(blockedMissCheckStatisticsService.insertBlockedMissCheckStatistics(blockedMissCheckStatistics));
    }

    /**
     * 新增或覆盖漏检统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:add')")
    @Log(title = "漏检统计", businessType = BusinessType.INSERT)
    @PostMapping("/addOrOverwrite")
    public AjaxResult addOrOverwrite(@RequestBody BlockedMissCheckStatistics blockedMissCheckStatistics) {
        blockedMissCheckStatistics.setCreateBy(getUsername());
        blockedMissCheckStatistics.setUpdateBy(getUsername());
        return toAjax(blockedMissCheckStatisticsService.insertOrUpdate(blockedMissCheckStatistics));
    }

    /**
     * 修改漏检统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:edit')")
    @Log(title = "漏检统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlockedMissCheckStatistics blockedMissCheckStatistics) {
        blockedMissCheckStatistics.setUpdateBy(getUsername());
        return toAjax(blockedMissCheckStatisticsService.updateBlockedMissCheckStatistics(blockedMissCheckStatistics));
    }

    /**
     * 删除漏检统计
     */
    @PreAuthorize("@ss.hasPermi('blocked:missReview:remove')")
    @Log(title = "漏检统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blockedMissCheckStatisticsService.deleteBlockedMissCheckStatisticsByIds(ids));
    }
}
