package com.ruoyi.web.controller.clock;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.clock.domain.bo.ClockProductRecordBo;
import com.ruoyi.clock.domain.vo.ClockProductRecordVo;
import com.ruoyi.clock.service.IClockProductRecordService;
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/clockProductRecord")
public class ClockProductRecordController extends BaseController {

    private final IClockProductRecordService iClockProductRecordService;

    /**
     * 分页查询打卡记录关联产品信息列表
     */
    @ApiOperation("查询打卡记录关联产品信息列表")
    @SaCheckPermission("clock:clockProductRecord:list")
    @GetMapping("/page")
    public TableDataInfo<ClockProductRecordVo> page(@Validated(QueryGroup.class) ClockProductRecordBo bo, PageQuery pageQuery) {
        return iClockProductRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取打卡记录关联产品信息详细信息
     */
    @ApiOperation("获取打卡记录关联产品信息详细信息")
    @SaCheckPermission("clock:clockProductRecord:query")
    @GetMapping("/info/{recordDetailId}")
    public R<ClockProductRecordVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("recordDetailId") Long recordDetailId) {
        return R.ok(iClockProductRecordService.queryById(recordDetailId));
    }

    /**
     * 新增打卡记录关联产品信息
     */
    @ApiOperation("新增打卡记录关联产品信息")
    @SaCheckPermission("clock:clockProductRecord:add")
    @Log(title = "打卡记录关联产品信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ClockProductRecordBo bo) {
        return toAjax(iClockProductRecordService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改打卡记录关联产品信息
     */
    @ApiOperation("修改打卡记录关联产品信息")
    @SaCheckPermission("clock:clockProductRecord:edit")
    @Log(title = "打卡记录关联产品信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ClockProductRecordBo bo) {
        return toAjax(iClockProductRecordService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除打卡记录关联产品信息
     */
    @ApiOperation("删除打卡记录关联产品信息")
    @SaCheckPermission("clock:clockProductRecord:remove")
    @Log(title = "打卡记录关联产品信息", businessType = BusinessType.DELETE)
    @PostMapping("/del/{recordDetailIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] recordDetailIds) {
        return toAjax(iClockProductRecordService.deleteWithValidByIds(Arrays.asList(recordDetailIds), true) ? 1 : 0);
    }

    /**
     * 导出打卡记录关联产品信息列表
     */
    @ApiOperation("导出打卡记录关联产品信息列表")
    @SaCheckPermission("clock:clockProductRecord:export")
    @Log(title = "打卡记录关联产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ClockProductRecordBo bo, HttpServletResponse response) {
        List<ClockProductRecordVo> list = iClockProductRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "打卡记录关联产品信息", ClockProductRecordVo.class, response);
    }

}
