package com.spider.quartz.controller;

import com.spider.common.annotation.Log;
import com.spider.common.core.controller.BaseController;
import com.spider.common.core.domain.AjaxResult;
import com.spider.common.core.page.TableDataInfo;
import com.spider.common.enums.BusinessType;
import com.spider.common.utils.StringUtils;
import com.spider.common.utils.poi.ExcelUtil;
import com.spider.quartz.domain.EuUnqualifiedGoods;
import com.spider.quartz.service.IEuUnqualifiedGoodsService;
import com.spider.quartz.task.EuropeTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 欧盟不合格商品展示Controller
 * 
 * @author ruoyi
 * @date 2025-11-26
 */
@Slf4j
@RestController
@RequestMapping("/bus/eu")
public class EuUnqualifiedGoodsController extends BaseController
{
    @Autowired
    private IEuUnqualifiedGoodsService euUnqualifiedGoodsService;
    @Autowired
    private EuropeTask europeTask;

    /**
     * 查询欧盟不合格商品展示列表
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:list')")
    @GetMapping("/list")
    public TableDataInfo list(EuUnqualifiedGoods euUnqualifiedGoods)
    {
        startPage();
        List<EuUnqualifiedGoods> list = euUnqualifiedGoodsService.selectEuUnqualifiedGoodsList(euUnqualifiedGoods);
        return getDataTable(list);
    }

    /**
     * 导出欧盟不合格商品展示列表
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:export')")
    @Log(title = "欧盟不合格商品展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EuUnqualifiedGoods euUnqualifiedGoods)
    {
        List<EuUnqualifiedGoods> list = euUnqualifiedGoodsService.selectEuUnqualifiedGoodsList(euUnqualifiedGoods);
        ExcelUtil<EuUnqualifiedGoods> util = new ExcelUtil<EuUnqualifiedGoods>(EuUnqualifiedGoods.class);
        util.exportExcel(response, list, "欧盟不合格商品展示数据");
    }

    /**
     * 获取欧盟不合格商品展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(euUnqualifiedGoodsService.selectEuUnqualifiedGoodsById(id));
    }

    /**
     * 新增欧盟不合格商品展示
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:add')")
    @Log(title = "欧盟不合格商品展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EuUnqualifiedGoods euUnqualifiedGoods)
    {
        return toAjax(euUnqualifiedGoodsService.insertEuUnqualifiedGoods(euUnqualifiedGoods));
    }

    /**
     * 修改欧盟不合格商品展示
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:edit')")
    @Log(title = "欧盟不合格商品展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EuUnqualifiedGoods euUnqualifiedGoods)
    {
        return toAjax(euUnqualifiedGoodsService.updateEuUnqualifiedGoods(euUnqualifiedGoods));
    }

    /**
     * 删除欧盟不合格商品展示
     */
    @PreAuthorize("@ss.hasPermi('bus:eu:remove')")
    @Log(title = "欧盟不合格商品展示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(euUnqualifiedGoodsService.deleteEuUnqualifiedGoodsByIds(ids));
    }

    @PostMapping("/manual")
    @PreAuthorize("@ss.hasPermi('bus:eu:manual')")
    public String manualCrawl() {
        new Thread(() -> {
            europeTask.startCrawl(true);
        }).start();
        return "手动爬取任务已启动";
    }

    @PostMapping("/scheduled")
    public String scheduledCrawl() {
        new Thread(() -> {
            europeTask.startCrawl(false);
        }).start();
        return "定时爬取任务已启动";
    }

}
