package com.vctgo.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vctgo.common.mybatisplus.aop.TemporaryIgnoreTables;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.system.domain.SysPlatformTeachStaff;
import com.vctgo.system.service.ISysPlatformTeachStaffService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 教职工信息Controller
 *
 * @author caesar
 * @date 2024-03-26
 */
@Api(tags = "教职工信息")
@RestController
@RequestMapping("/plat/staff")
public class SysPlatformTeachStaffController extends BaseController {

    @Autowired
    private ISysPlatformTeachStaffService sysTeachStaffService;

    /**
     * 查询教职工信息分页列表
     */
    @TemporaryIgnoreTables(temporaryIgnoreTables = {"sys_user"})
    @ApiOperation(value = "查询教职工信息分页列表")
    @RequiresPermissions("system:staff:page")
    @GetMapping("/page")
    public AjaxResult page(SysPlatformTeachStaff sysPlatformTeachStaff) {
        IPage<SysPlatformTeachStaff> pageList = sysTeachStaffService.selectSysTeachStaffPage(sysPlatformTeachStaff);
        return AjaxResult.success(pageList);
    }

    /**
     * 导出教职工信息列表
     */
    @ApiOperation(value = "导出教职工信息列表")
    @RequiresPermissions("system:staff:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPlatformTeachStaff sysPlatformTeachStaff) {
        List<SysPlatformTeachStaff> list = sysTeachStaffService.selectSysTeachStaffList(sysPlatformTeachStaff);
        ExcelUtil<SysPlatformTeachStaff> util = new ExcelUtil<SysPlatformTeachStaff>(SysPlatformTeachStaff.class);
        util.exportExcel(response, list, "教职工信息数据");
    }

    /**
     * 获取教职工信息详细信息
     */
    @ApiOperation(value = "获取教职工信息详细信息")
    @RequiresPermissions("system:staff:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success((sysTeachStaffService.selectSysTeachStaffById(id)));
    }

    /**
     * 新增教职工信息
     */
    @Transactional
    @ApiOperation(value = "新增教职工信息")
    @RequiresPermissions("system:staff:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysPlatformTeachStaff sysPlatformTeachStaff) throws Exception {
        return sysTeachStaffService.insertSysTeachStaff(sysPlatformTeachStaff);
    }

    /**
     * 修改教职工信息
     */
    @Transactional
    @ApiOperation(value = "修改教职工信息")
    @RequiresPermissions("system:staff:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysPlatformTeachStaff sysPlatformTeachStaff) throws Exception {
        return sysTeachStaffService.updateSysTeachStaff(sysPlatformTeachStaff);
    }

    /**
     * 逻辑删除教职工信息
     */
    @Transactional
    @ApiOperation(value = "逻辑删除教职工信息")
    @RequiresPermissions("system:staff:abandon")
    @PutMapping("/abandon/{ids}")
    public AjaxResult abandon(@PathVariable Long[] ids, Long kindergartenId) {
        sysTeachStaffService.logicalDeleteSysTeachStaffByIds(ids, kindergartenId);
        return AjaxResult.success();
    }

    /**
     * 删除教职工信息
     */
    @ApiOperation(value = "删除教职工信息")
    @RequiresPermissions("system:staff:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        sysTeachStaffService.deleteSysTeachStaffByIds(ids);
        return AjaxResult.success();
    }
}
