package com.ruoyi.web.controller.clock;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.clock.domain.bo.ActivityAgentBo;
import com.ruoyi.clock.domain.vo.ActivityAgentVo;
import com.ruoyi.clock.service.IActivityAgentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 活动与代理商关联Controller
 *
 * @author pengc
 * @date 2026-03-04
 */
@Validated
@Api(value = "活动与代理商关联控制器", tags = {"活动与代理商关联管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/clock/activityAgent")
public class ActivityAgentController extends BaseController {

    private final IActivityAgentService iActivityAgentService;

    /**
     * 分页查询活动与代理商关联列表
     */
    @ApiOperation("查询活动与代理商关联列表")
    @SaCheckPermission("clock:activityAgent:list")
    @GetMapping("/page")
    public TableDataInfo<ActivityAgentVo> page(@Validated(QueryGroup.class) ActivityAgentBo bo, PageQuery pageQuery) {
        return iActivityAgentService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询活动与代理商关联列表
     */
    @ApiOperation("查询活动与代理商关联列表")
    @GetMapping("/list")
    public R<List<ActivityAgentVo>> list(@Validated(QueryGroup.class) ActivityAgentBo bo) {
        return R.ok(iActivityAgentService.queryList(bo));
    }

    /**
     * 获取活动与代理商关联详细信息
     */
    @ApiOperation("获取活动与代理商关联详细信息")
    @SaCheckPermission("clock:activityAgent:query")
    @GetMapping("/info/{id}")
    public R<ActivityAgentVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iActivityAgentService.queryById(id));
    }

    /**
     * 新增活动与代理商关联
     */
    @ApiOperation("新增活动与代理商关联")
    @SaCheckPermission("clock:activityAgent:add")
    @Log(title = "活动与代理商关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ActivityAgentBo bo) {
        return toAjax(iActivityAgentService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改活动与代理商关联
     */
    @ApiOperation("修改活动与代理商关联")
    @SaCheckPermission("clock:activityAgent:edit")
    @Log(title = "活动与代理商关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ActivityAgentBo bo) {
        return toAjax(iActivityAgentService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除活动与代理商关联
     */
    @ApiOperation("删除活动与代理商关联")
    @SaCheckPermission("clock:activityAgent:remove")
    @Log(title = "活动与代理商关联", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iActivityAgentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 导出活动与代理商关联列表
     */
    @ApiOperation("导出活动与代理商关联列表")
    @SaCheckPermission("clock:activityAgent:export")
    @Log(title = "活动与代理商关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ActivityAgentBo bo, HttpServletResponse response) {
        List<ActivityAgentVo> list = iActivityAgentService.queryList(bo);
        ExcelUtil.exportExcel(list, "活动与代理商关联", ActivityAgentVo.class, response);
    }

}
