package com.xinyilu.web.controller.teacherInfo;

import com.xinyilu.common.annotation.Log;
import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.common.custominterface.Insert;
import com.xinyilu.common.custominterface.Update;
import com.xinyilu.common.enums.BusinessType;
import com.xinyilu.system.domain.classinfo.ClassInfo;
import com.xinyilu.system.domain.dto.TeacherInfoDTO;
import com.xinyilu.system.domain.teacherInfo.TeacherInfo;
import com.xinyilu.system.service.teacherInfo.ITeacherInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师信息管理Controller
 *
 * @author jihan
 * @date 2022-08-05
 */
@RestController
@RequestMapping("/system/teacherInfo")
public class TeacherInfoController extends BaseController {
    @Autowired
    private ITeacherInfoService teacherInfoService;

    /**
     * 查询教师信息管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:teacherInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeacherInfoDTO teacherInfo) {
        return teacherInfoService.selectTeacherInfoList(teacherInfo);
    }

    /**
     * 获取教师信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacherInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(teacherInfoService.selectTeacherInfoById(id));
    }

    /**
     * 新增教师信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:teacherInfo:add')")
    @Log(title = "教师信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody TeacherInfoDTO teacherInfo) {
        return teacherInfoService.insertTeacherInfo(teacherInfo, getUsername());
    }

    /**
     * 修改教师信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:teacherInfo:edit')")
    @Log(title = "教师信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody TeacherInfoDTO teacherInfo) {
        return teacherInfoService.updateTeacherInfo(teacherInfo, getUsername());
    }

    /**
     * 删除教师信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:teacherInfo:remove')")
    @Log(title = "教师信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return teacherInfoService.updateTeacherInfoByIds(ids);
    }

    /**
     * 删除教师信息管理
     */
    @Log(title = "教师信息管理", businessType = BusinessType.DELETE)
    @GetMapping("/getClassInfo")
    public AjaxResult getClassInfo(Long id) {
        List<ClassInfo> classInfoList = teacherInfoService.getClassInfoList(id);
        return AjaxResult.success(classInfoList);
    }
}
