package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.CphStuEvaTask;
import com.srs.comprehensive.domain.Dto.CphEvaStuPub;
import com.srs.comprehensive.service.ICphStuEvaTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
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.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.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 综合评价评定小组任务Controller
 * 
 * @author srs
 * @date 2023-08-19
 */
@RestController
@RequestMapping("/system/task")
public class CphStuEvaTaskController extends BaseController
{
    @Autowired
    private ICphStuEvaTaskService cphStuEvaTaskService;

    /***
     * 辅导员发布任务
     * @author zhy
     * @date 2023-08-19 16:56:27
     * @return
     **/
    @PostMapping("/pubTask")
    public AjaxResult pubTask(CphEvaStuPub param){
        return AjaxResult.success(cphStuEvaTaskService.pubTask(param));
    }

    @GetMapping(value = "/listownstubyclass/{id}")
    public AjaxResult listOwnStuByClass(@PathVariable("id")Long id){
        return AjaxResult.success(cphStuEvaTaskService.listOwnStuByClass(id));
    }

    @GetMapping("/listStuYear")
    public AjaxResult listStuYear(){
        return AjaxResult.success(cphStuEvaTaskService.listStuYear());
    }

    /***
     * 列出自己的班级
     * @author zhy
     * @date 2023-08-19 15:21:40
     * @return
     **/
    @GetMapping("/listownclass")
    public AjaxResult listOwnClass(){
        String tno = getUsername();
        return AjaxResult.success(cphStuEvaTaskService.listOwnClass(tno));
    }


    /**
     * 查询自己的综合评价评定小组任务列表
     */
    @GetMapping("/listown")
    public TableDataInfo listOwn()
    {
        startPage();
        CphStuEvaTask param = new CphStuEvaTask();
        String t_no = getUsername();
        param.setTaskTNo(t_no);
        List<CphStuEvaTask> list = cphStuEvaTaskService.selectCphStuEvaTaskList(param);
        return getDataTable(list);
    }

    /**
     * 查询综合评价评定小组任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CphStuEvaTask cphStuEvaTask)
    {
        startPage();
        List<CphStuEvaTask> list = cphStuEvaTaskService.selectCphStuEvaTaskList(cphStuEvaTask);
        return getDataTable(list);
    }

    /**
     * 导出综合评价评定小组任务列表
     */
    @Log(title = "综合评价评定小组任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CphStuEvaTask cphStuEvaTask)
    {
        List<CphStuEvaTask> list = cphStuEvaTaskService.selectCphStuEvaTaskList(cphStuEvaTask);
        ExcelUtil<CphStuEvaTask> util = new ExcelUtil<CphStuEvaTask>(CphStuEvaTask.class);
        util.exportExcel(response, list, "综合评价评定小组任务数据");
    }

    /**
     * 获取综合评价评定小组任务详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphStuEvaTaskService.selectCphStuEvaTaskById(id));
    }

    /**
     * 新增综合评价评定小组任务
     */
    @Log(title = "综合评价评定小组任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CphStuEvaTask cphStuEvaTask)
    {
        return toAjax(cphStuEvaTaskService.insertCphStuEvaTask(cphStuEvaTask));
    }

    /**
     * 修改综合评价评定小组任务
     */
    @Log(title = "综合评价评定小组任务", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CphStuEvaTask cphStuEvaTask)
    {
        return toAjax(cphStuEvaTaskService.updateCphStuEvaTask(cphStuEvaTask));
    }

    /**
     * 删除综合评价评定小组任务
     */
    @Log(title = "综合评价评定小组任务", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphStuEvaTaskService.deleteCphStuEvaTaskByIds(ids));
    }
}
