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.SysTeacherHonor;
import com.srs.teacher.service.ISysTeacherHonorService;
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;

/**
 * honorController
 *
 * @author srs
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/teacher/honor")
@Api(value = "honor管理", tags = "honor管理")
public class SysTeacherHonorController extends BaseController {
    @Autowired
    private ISysTeacherHonorService sysTeacherHonorService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询honor列表
     */
@PreAuthorize("@ss.hasPermi('teacher:honor:list')")
@GetMapping("/list")
@ApiOperation("查询honor列表")
    public TableDataInfo list(SysTeacherHonor sysTeacherHonor)
    {
        startPage();
        List<SysTeacherHonor> list = sysTeacherHonorService.selectSysTeacherHonorList(sysTeacherHonor);
        return getDataTable(list);
    }

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

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

    /**
     * 新增honor
     */
    @PreAuthorize("@ss.hasPermi('teacher:honor:add')")
    @Log(title = "honor", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增honor")
    public AjaxResult add(@RequestBody SysTeacherHonor sysTeacherHonor)
    {
        return toAjax(sysTeacherHonorService.insertSysTeacherHonor(sysTeacherHonor));
    }

    /**
     * 修改honor
     */
    @PreAuthorize("@ss.hasPermi('teacher:honor:edit')")
    @Log(title = "honor", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改honor")
    public AjaxResult edit(@RequestBody SysTeacherHonor sysTeacherHonor)
    {
        return toAjax(sysTeacherHonorService.updateSysTeacherHonor(sysTeacherHonor));
    }

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