package com.fuyuanshen.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoRecordsVo;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoRecordsBo;
import com.fuyuanshen.app.service.IAppPersonnelInfoRecordsService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 人员信息登记记录
 *
 * @author CYT
 * @date 2025-08-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/personnelInfoRecords")
public class AppPersonnelInfoRecordsController extends BaseController {

    private final IAppPersonnelInfoRecordsService appPersonnelInfoRecordsService;

    /**
     * 查询人员信息登记记录列表
     */
    @SaCheckPermission("app:personnelInfoRecords:list")
    @GetMapping("/list")
    public TableDataInfo<AppPersonnelInfoRecordsVo> list(AppPersonnelInfoRecordsBo bo, PageQuery pageQuery) {
        return appPersonnelInfoRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出人员信息登记记录列表
     */
    @SaCheckPermission("app:personnelInfoRecords:export")
    @Log(title = "人员信息登记记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppPersonnelInfoRecordsBo bo, HttpServletResponse response) {
        List<AppPersonnelInfoRecordsVo> list = appPersonnelInfoRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员信息登记记录", AppPersonnelInfoRecordsVo.class, response);
    }

    /**
     * 获取人员信息登记记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:personnelInfoRecords:query")
    @GetMapping("/{id}")
    public R<AppPersonnelInfoRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(appPersonnelInfoRecordsService.queryById(id));
    }

    /**
     * 新增人员信息登记记录
     */
    @SaCheckPermission("app:personnelInfoRecords:add")
    @Log(title = "人员信息登记记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoRecordsBo bo) {
        return toAjax(appPersonnelInfoRecordsService.insertByBo(bo));
    }

    /**
     * 修改人员信息登记记录
     */
    @SaCheckPermission("app:personnelInfoRecords:edit")
    @Log(title = "人员信息登记记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppPersonnelInfoRecordsBo bo) {
        return toAjax(appPersonnelInfoRecordsService.updateByBo(bo));
    }

    /**
     * 删除人员信息登记记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:personnelInfoRecords:remove")
    @Log(title = "人员信息登记记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(appPersonnelInfoRecordsService.deleteWithValidByIds(List.of(ids), true));
    }
}
