package com.srs.web.controller.workstudy;

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

import com.srs.system.service.ISysRoleService;
import com.srs.web.controller.common.RoleBool;
import com.srs.workstudy.domain.QgzxStuPost;
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.workstudy.domain.QgzxMonthAssess;
import com.srs.workstudy.service.IQgzxMonthAssessService;
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;

/**
 * 勤工助学月度考核Controller
 *
 * @author srs
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/workstudy/assess")
@Api(value = "勤工助学月度考核管理", tags = "勤工助学月度考核管理")
public class QgzxMonthAssessController extends BaseController {
    @Autowired
    private IQgzxMonthAssessService qgzxMonthAssessService;

    @Autowired
    private ISysRoleService _roleService;

    @PostMapping("/manyAssess")
    @ApiOperation("老师月度考核")
    public AjaxResult manyAssess(@RequestBody List<QgzxMonthAssess> param) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return qgzxMonthAssessService.manyAssess(param);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    @PostMapping("/zdlsExport")
    @ApiOperation("指导老师导出勤工助学月度考核列表")
    public void zdlsExport(HttpServletResponse response, QgzxMonthAssess param) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            param.zdlsNo = getUsername();
            List<QgzxMonthAssess> list = qgzxMonthAssessService.listView(param);
            ExcelUtil<QgzxMonthAssess> util = new ExcelUtil<QgzxMonthAssess>(QgzxMonthAssess.class);
            util.exportExcel(response, list, "勤工助学月度考核数据");
        }
    }

    @PostMapping("/doAssess")
    @ApiOperation("老师月度考核")
    public AjaxResult doAssess(@RequestBody QgzxMonthAssess param) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return qgzxMonthAssessService.doAssess(param);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    @GetMapping("/listZdls")
    @ApiOperation("指导老师查询勤工助学月度考核列表")
    public TableDataInfo listZdls(QgzxMonthAssess param) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            param.zdlsNo = getUsername();
            startPage();
            List<QgzxMonthAssess> list = qgzxMonthAssessService.listView(param);
            return getDataTable(list);
        } else {
            return getDataTable(new ArrayList<>());
        }
    }


    /**
     * 查询勤工助学月度考核列表
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:list')")
    @GetMapping("/list")
    @ApiOperation("查询勤工助学月度考核列表")
    public TableDataInfo list(QgzxMonthAssess qgzxMonthAssess) {
        startPage();
        List<QgzxMonthAssess> list = qgzxMonthAssessService.selectQgzxMonthAssessList(qgzxMonthAssess);
        return getDataTable(list);
    }

    /**
     * 导出勤工助学月度考核列表
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:export')")
    @Log(title = "勤工助学月度考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出勤工助学月度考核列表")
    public void export(HttpServletResponse response, QgzxMonthAssess qgzxMonthAssess) {
        List<QgzxMonthAssess> list = qgzxMonthAssessService.selectQgzxMonthAssessList(qgzxMonthAssess);
        ExcelUtil<QgzxMonthAssess> util = new ExcelUtil<QgzxMonthAssess>(QgzxMonthAssess.class);
        util.exportExcel(response, list, "勤工助学月度考核数据");
    }

    /**
     * 获取勤工助学月度考核详细信息
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取勤工助学月度考核详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qgzxMonthAssessService.selectQgzxMonthAssessById(id));
    }

    /**
     * 新增勤工助学月度考核
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:add')")
    @Log(title = "勤工助学月度考核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增勤工助学月度考核")
    public AjaxResult add(@RequestBody QgzxMonthAssess qgzxMonthAssess) {
        return toAjax(qgzxMonthAssessService.insertQgzxMonthAssess(qgzxMonthAssess));
    }

    /**
     * 修改勤工助学月度考核
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:edit')")
    @Log(title = "勤工助学月度考核", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改勤工助学月度考核")
    public AjaxResult edit(@RequestBody QgzxMonthAssess qgzxMonthAssess) {
        return toAjax(qgzxMonthAssessService.updateQgzxMonthAssess(qgzxMonthAssess));
    }

    /**
     * 删除勤工助学月度考核
     */
    @PreAuthorize("@ss.hasPermi('workstudy:assess:remove')")
    @Log(title = "勤工助学月度考核", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除勤工助学月度考核")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qgzxMonthAssessService.deleteQgzxMonthAssessByIds(ids));
    }
}
