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.AppPersonnelInfoVo;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.service.IAppPersonnelInfoService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 人员信息登记
 *
 * @author Lion Li
 * @date 2025-07-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/personnelInfo")
public class AppPersonnelInfoController extends BaseController {

    private final IAppPersonnelInfoService appPersonnelInfoService;

    /**
     * 查询人员信息登记列表
     */
    @SaCheckPermission("app:personnelInfo:list")
    @GetMapping("/list")
    public TableDataInfo<AppPersonnelInfoVo> list(AppPersonnelInfoBo bo, PageQuery pageQuery) {
        return appPersonnelInfoService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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