package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdApplyInfoList;
import com.ruoyi.system.manager.ApplyInfoListManager;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: ApplyInfoListController
 * Package: com.ruoyi.system.controller
 * Description:人员管理
 *
 * @Author wangxy
 * @Create 2025/8/13 9:31
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/applyList")
public class ApplyInfoListController extends BaseController {

    @Resource
    private ApplyInfoListManager applyInfoListManager;


    /**
     * 查询人员申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdApplyInfoList applyInfoList) {
        startPage();
        List<TdApplyInfoList> list = applyInfoListManager.selectTdApplyInfoListList(applyInfoList);
        return getDataTable(list);
    }


    /**
     * 获取OA 请假申请详细信息
     */
    @GetMapping(value = "/getInfo/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") String applyId)
    {
        return success(applyInfoListManager.selectTdApplyInfoListById(applyId));
    }

    /**
     * 新增人员申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "人员申请新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody TdApplyInfoList applyInfoList) {
        return toAjax(applyInfoListManager.insertTdApplyInfoList(applyInfoList));
    }

    /**
     * 修改人员申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "人员申请修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult edit(@RequestBody TdApplyInfoList applyInfoList) {
        return toAjax(applyInfoListManager.updateTdApplyInfoList(applyInfoList));
    }


    /**
     * 删除人员申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "删除人员申请", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{applyIds}")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult remove(@PathVariable String[] applyIds) {
        return toAjax(applyInfoListManager.deleteApplyInfoListByIds(applyIds));
    }

    /**
     * 提交审批
     */
    @PreAuthorize("@ss.hasPermi('system:apply:submit')")
    @Log(title = "人员申请提交", businessType = BusinessType.OTHER)
    @GetMapping(value = "/submit")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult submit(String id) {
        return toAjax(applyInfoListManager.submit(id));
    }


    /**
     * 办理(审核通过，退回）
     */
    @Log(title = "流程实例", businessType = BusinessType.OTHER)
    @PostMapping("/handle")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult handle(@RequestBody TdApplyInfoList applyInfoList, Long taskId, String skipType, String message) {
        return toAjax(applyInfoListManager.handle(applyInfoList, taskId, skipType, message));
    }


    /**
     * 终止流程，提前结束
     *
     * @param applyInfoList
     * @return
     */
    @PostMapping("/termination")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult termination(@RequestBody TdApplyInfoList applyInfoList) {
        return toAjax(applyInfoListManager.termination(applyInfoList));
    }


}
