package com.fs.store.controller;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.fs.store.cache.IFsStoreOrderCacheService;
import com.fs.store.domain.FsCouponSchedule;
import com.fs.store.domain.FsStoreOrder;
import com.fs.store.service.IFsCouponScheduleService;
import com.hc.openapi.tool.util.StringUtils;
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 com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 定时发放优惠券队列Controller
 *
 * @author fs
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/system/schedule")
public class FsCouponScheduleController extends BaseController
{
    @Autowired
    private IFsCouponScheduleService fsCouponScheduleService;

    @Autowired
    private IFsStoreOrderCacheService fsStoreOrderCacheService;

    /**
     * 查询定时发放优惠券队列列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCouponSchedule fsCouponSchedule)
    {

        startPage();
        List<FsCouponSchedule> list = fsCouponScheduleService.selectFsCouponScheduleList(fsCouponSchedule);

        return getDataTable(list);
    }

    /**
     * 导出定时发放优惠券队列列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:export')")
    @Log(title = "定时发放优惠券队列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsCouponSchedule fsCouponSchedule)
    {
        List<FsCouponSchedule> list = fsCouponScheduleService.selectFsCouponScheduleList(fsCouponSchedule);
        ExcelUtil<FsCouponSchedule> util = new ExcelUtil<FsCouponSchedule>(FsCouponSchedule.class);
        return util.exportExcel(list, "schedule");
    }

    /**
     * 获取定时发放优惠券队列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsCouponScheduleService.selectFsCouponScheduleById(id));
    }

    /**
     * 新增定时发放优惠券队列
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:add')")
    @Log(title = "定时发放优惠券队列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCouponSchedule fsCouponSchedule)
    {
        return toAjax(fsCouponScheduleService.insertFsCouponSchedule(fsCouponSchedule));
    }

    /**
     * 修改定时发放优惠券队列
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:edit')")
    @Log(title = "定时发放优惠券队列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCouponSchedule fsCouponSchedule)
    {
        return toAjax(fsCouponScheduleService.updateFsCouponSchedule(fsCouponSchedule));
    }

    /**
     * 删除定时发放优惠券队列
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:remove')")
    @Log(title = "定时发放优惠券队列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsCouponScheduleService.deleteFsCouponScheduleByIds(ids));
    }
}
