package com.ruoyi.web.controller.appointment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PersonnelManagement;
import com.ruoyi.system.service.IPersonnelManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员管理Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/management")
public class PersonnelManagementController extends BaseController
{
    @Autowired
    private IPersonnelManagementService personnelManagementService;

/**
 * 查询人员管理列表
 */
@PreAuthorize("@ss.hasPermi('system:management:list')")
@GetMapping("/list")
    public TableDataInfo list(PersonnelManagement personnelManagement)
    {
        startPage();
        List<PersonnelManagement> list = personnelManagementService.selectPersonnelManagementList(personnelManagement);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonnelManagement personnelManagement)
    {
        List<PersonnelManagement> list = personnelManagementService.selectPersonnelManagementList(personnelManagement);
        ExcelUtil<PersonnelManagement> util = new ExcelUtil<PersonnelManagement>(PersonnelManagement.class);
        util.exportExcel(response, list, "人员管理数据");
    }

    /**
     * 获取人员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{personneId}")
    public AjaxResult getInfo(@PathVariable("personneId") Long personneId)
    {
        return success(personnelManagementService.selectPersonnelManagementByPersonneId(personneId));
    }

    /**
     * 新增人员管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonnelManagement personnelManagement)
    {
        return toAjax(personnelManagementService.insertPersonnelManagement(personnelManagement));
    }

    /**
     * 修改人员管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody PersonnelManagement personnelManagement)
    {
        return toAjax(personnelManagementService.updatePersonnelManagement(personnelManagement));
    }

    /**
     * 删除人员管理
     */
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{personneIds}")
    public AjaxResult remove(@PathVariable Long[] personneIds)
    {
        return toAjax(personnelManagementService.deletePersonnelManagementByPersonneIds(personneIds));
    }
}
