package com.srs.web.controller.teacher;

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

import com.srs.common.core.domain.entity.SysUser;
import com.srs.system.service.ISysUserService;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.teacher.domain.SysTeacherGuidance;
import com.srs.teacher.service.ISysTeacherGuidanceService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * guidanceController
 *
 * @author srs
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/teacher/guidance")
@Api(value = "guidance管理", tags = "guidance管理")
public class SysTeacherGuidanceController extends BaseController {
    @Autowired
    private ISysTeacherGuidanceService sysTeacherGuidanceService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询guidance列表
     */
@PreAuthorize("@ss.hasPermi('teacher:guidance:list')")
@GetMapping("/list")
@ApiOperation("查询guidance列表")
    public TableDataInfo list(SysTeacherGuidance sysTeacherGuidance)
    {
        startPage();
        List<SysTeacherGuidance> list = sysTeacherGuidanceService.selectSysTeacherGuidanceList(sysTeacherGuidance);
        return getDataTable(list);
    }

    /**
     * 导出guidance列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:guidance:export')")
    @Log(title = "guidance", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出guidance列表")
    public void export(HttpServletResponse response, SysTeacherGuidance sysTeacherGuidance)
    {
        List<SysTeacherGuidance> list = sysTeacherGuidanceService.selectSysTeacherGuidanceList(sysTeacherGuidance);
        //10.16 导出信息补充
        SysUser u = userService.selectUserByUserName(sysTeacherGuidance.getTeacherId().toString());
        for(int i=0;i<list.size();i++){
            list.get(i).setTeacherName(u.getUserName());
            list.get(i).setTeacherCollege(u.getDept().getDeptName());
        }
        ExcelUtil<SysTeacherGuidance> util = new ExcelUtil<SysTeacherGuidance>(SysTeacherGuidance.class);
        util.exportExcel(response, list, "guidance数据");
    }

    /**
     * 获取guidance详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:guidance:query')")
    @GetMapping(value = "/{guidanceId}")
    @ApiOperation("获取guidance详细信息")
    public AjaxResult getInfo(@PathVariable("guidanceId") Long guidanceId)
    {
        return success(sysTeacherGuidanceService.selectSysTeacherGuidanceByGuidanceId(guidanceId));
    }

    /**
     * 新增guidance
     */
    @PreAuthorize("@ss.hasPermi('teacher:guidance:add')")
    @Log(title = "guidance", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增guidance")
    public AjaxResult add(@RequestBody SysTeacherGuidance sysTeacherGuidance)
    {
        return toAjax(sysTeacherGuidanceService.insertSysTeacherGuidance(sysTeacherGuidance));
    }

    /**
     * 修改guidance
     */
    @PreAuthorize("@ss.hasPermi('teacher:guidance:edit')")
    @Log(title = "guidance", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改guidance")
    public AjaxResult edit(@RequestBody SysTeacherGuidance sysTeacherGuidance)
    {
        return toAjax(sysTeacherGuidanceService.updateSysTeacherGuidance(sysTeacherGuidance));
    }

    /**
     * 删除guidance
     */
    @PreAuthorize("@ss.hasPermi('teacher:guidance:remove')")
    @Log(title = "guidance", businessType = BusinessType.DELETE)
    @PostMapping("/{guidanceIds}")
    @ApiOperation("删除guidance")
    public AjaxResult remove(@PathVariable Long[] guidanceIds)
    {
        return toAjax(sysTeacherGuidanceService.deleteSysTeacherGuidanceByGuidanceIds(guidanceIds));
    }
}
