package com.vctgo.system.controller;

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

import com.vctgo.common.core.domain.R;
import com.vctgo.system.api.domain.vo.SysTeachStaffVo;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
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.SysTeachStaff;
import com.vctgo.system.service.ISysTeachStaffService;
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-27
 */
@Api(tags = "幼儿园教职工信息")
@RestController
@RequestMapping("/staff")
public class SysTeachStaffController extends BaseController {
    @Autowired
    private ISysTeachStaffService sysTeachStaffService;

    /**
     * 查询幼儿园教职工信息分页列表
     */
    @RequiresPermissions("system:staff:page")
    @GetMapping("/page")
    public AjaxResult page(SysTeachStaff sysTeachStaff) {
        IPage<SysTeachStaff> pageList = sysTeachStaffService.selectSysTeachStaffPage(sysTeachStaff);
        return AjaxResult.success(pageList);
    }

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


    /**
     * 幼儿园教职工信息列表
     */
    @GetMapping("/list")
    public AjaxResult list(SysTeachStaff sysTeachStaff) {
        List<SysTeachStaff> list = sysTeachStaffService.selectSysTeachStaffList(sysTeachStaff);
        return AjaxResult.success(list);
    }

    /**
     * 查询幼儿园教职工信息
     *
     * @param userId 幼儿园教职工用户Id
     * @return 幼儿园教职工信息
     */
    @RequiresPermissions("system:staff:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId) {
        return success((sysTeachStaffService.selectSysTeachStaffById(userId)));
    }

    /**
     * 新增幼儿园教职工信息
     */
    @Transactional
    @RequiresPermissions("system:staff:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysTeachStaff sysTeachStaff) {
        return toAjax(sysTeachStaffService.insertSysTeachStaff(sysTeachStaff));
    }

    /**
     * 通过用户id检查离职状态
     */
    @Transactional
    @RequiresPermissions("system:staff:edit")
    @GetMapping("/check/{userId}")
    public AjaxResult checkSysTeachUserStatus(@PathVariable Long userId) {
        return sysTeachStaffService.checkSysTeachUserStatus(userId);
    }

    /**
     * 修改幼儿园教职工信息
     */
    @Transactional
    @RequiresPermissions("system:staff:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysTeachStaff sysTeachStaff) {
        return toAjax(sysTeachStaffService.updateSysTeachStaff(sysTeachStaff));
    }

    /**
     * 逻辑删除幼儿园教职工信息
     */
    @Transactional
    @RequiresPermissions("system:staff:abandon")
    @GetMapping("/abandon/{userId}")
    public AjaxResult abandon(@PathVariable Long userId) {
        return toAjax(sysTeachStaffService.logicalDeleteSysTeachStaffByIds(userId));
    }

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

    /**
     * 根据用户获取园所主键
     */
    @GetMapping("/getLocationId/{userId}")
    public AjaxResult getLocationId(@PathVariable("userId") Long userId) {
        return AjaxResult.success(sysTeachStaffService.getLocationId(userId));

    }

    /**
     * 回填教职工相关信息 并创建相应的租户数据
     * @param sysTeachStaffVo
     * @return
     */
    @GetMapping("/updateStaffByKinderId")
    public AjaxResult updateStaffByKinderId(@SpringQueryMap SysTeachStaffVo sysTeachStaffVo) {
        return AjaxResult.success(sysTeachStaffService.updateStaffByKinderId(sysTeachStaffVo));

    }
}
