package com.srs.web.controller.teacher;

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


import com.srs.common.utils.poi.ExcelExp;
import com.srs.common.utils.poi.ExcelUtilManySheet;
import com.srs.teacher.domain.*;
import com.srs.teacher.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;


/**
 * achievementcheckController
 *
 * @author srs
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/teacher/achievementcheck")
@Api(value = "achievementcheck管理", tags = "achievementcheck管理")
public class SysTeacherAchievementcheckController extends BaseController {
    @Autowired
    private ISysTeacherAchievementcheckService sysTeacherAchievementcheckService;

    @Autowired
    private ISysTeacherThesisService sysTeacherThesisService;

    @Autowired
    private ISysTeacherResearchService sysTeacherResearchService;

    @Autowired
    private ISysTeacherWorkexampleService sysTeacherWorkexampleService;

    @Autowired
    private ISysTeacherGuidanceService sysTeacherGuidanceService;
    @Autowired
    private ISysTeacherContestService sysTeacherContestService;
    @Autowired
    private ISysTeacherHonorService sysTeacherHonorService;

    @Value("${srs.url}")
    private String baseUrl;
    /**
     * 查询achievementcheck列表
     */
@PreAuthorize("@ss.hasPermi('teacher:achievementcheck:list')")
@GetMapping("/list")
@ApiOperation("查询achievementcheck列表")
    public TableDataInfo list(SysTeacherAchievementcheck sysTeacherAchievementcheck)
    {
        startPage();
        List<SysTeacherAchievementcheck> list = sysTeacherAchievementcheckService.selectSysTeacherAchievementcheckList(sysTeacherAchievementcheck);
        return getDataTable(list);
    }

    /**
     * 导出achievementcheck列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:achievementcheck:export')")
    @Log(title = "achievementcheck", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出achievementcheck列表")
    public void export(HttpServletResponse response, SysTeacherAchievementcheck sysTeacherAchievementcheck) throws IOException {

        List<SysTeacherAchievementcheck> list = sysTeacherAchievementcheckService.selectSysTeacherAchievementcheckList(sysTeacherAchievementcheck);
        //导出填报的成果绩效
        SysTeacherThesis thesisPar = new SysTeacherThesis();
        SysTeacherResearch researchPar = new SysTeacherResearch();
        SysTeacherWorkexample workexamplePar = new SysTeacherWorkexample();
        SysTeacherGuidance guidancePar = new SysTeacherGuidance();
        SysTeacherContest contestPar = new SysTeacherContest();
        SysTeacherHonor honorPar = new SysTeacherHonor();
        List<SysTeacherThesis> thesisList = new ArrayList<SysTeacherThesis>();
        List<SysTeacherResearch> researchList = new ArrayList<SysTeacherResearch>();
        List<SysTeacherWorkexample> workexampleList = new ArrayList<SysTeacherWorkexample>();
        List<SysTeacherGuidance> guidanceList = new ArrayList<SysTeacherGuidance>();
        List<SysTeacherContest>contestList = new ArrayList<SysTeacherContest>();
        List<SysTeacherHonor> honorList = new ArrayList<SysTeacherHonor>();
        for(int i =0;i<list.size();i++){
            long teacherId = list.get(i).getTeacherId();
            //论文成果
            thesisPar.setTeacherId(teacherId);
            List<SysTeacherThesis> list2 = sysTeacherThesisService.selectSysTeacherThesisList(thesisPar);
            if(list2.size()!=0){
                for(int n =0;n<list2.size();n++){
                    thesisList.add(list2.get(n));
                    thesisList.get(thesisList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    thesisList.get(thesisList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    thesisList.get(thesisList.size()-1).setSortId(thesisList.size());
                    thesisList.get(thesisList.size()-1).setEvidence(baseUrl.substring(0,baseUrl.length()-1) + thesisList.get(thesisList.size()-1).getEvidence());
                }

            }
            //课题研究
            researchPar.setTeacherId(teacherId);
            List<SysTeacherResearch> list3 = sysTeacherResearchService.selectSysTeacherResearchList(researchPar);
            if(list3.size()!=0){
                for(int n =0;n<list3.size();n++){
                    researchList.add(list3.get(n));
                    researchList.get(researchList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    researchList.get(researchList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    researchList.get(researchList.size()-1).setSortId(researchList.size());
                    researchList.get(researchList.size()-1).setEvidence(baseUrl.substring(0,baseUrl.length()-1) + researchList.get(researchList.size()-1).getEvidence());
                }
            }

            //工作案例
            workexamplePar.setTeacherId(teacherId);
            List<SysTeacherWorkexample> list4 = sysTeacherWorkexampleService.selectSysTeacherWorkexampleList(workexamplePar);
            if(list4.size()!=0){
                for(int n =0;n<list4.size();n++){
                    workexampleList.add(list4.get(n));
                    workexampleList.get(workexampleList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    workexampleList.get(workexampleList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    workexampleList.get(workexampleList.size()-1).setSortId(workexampleList.size());
                    workexampleList.get(workexampleList.size()-1).setEvidence(baseUrl.substring(0,baseUrl.length()-1) + workexampleList.get(workexampleList.size()-1).getEvidence());
                }
            }

            // 指导参赛
            guidancePar.setTeacherId(teacherId);
            List<SysTeacherGuidance> list5 = sysTeacherGuidanceService.selectSysTeacherGuidanceList(guidancePar);
            if(list5.size()!=0){
                for(int n =0;n<list5.size();n++){
                    guidanceList.add(list5.get(n));
                    guidanceList.get(guidanceList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    guidanceList.get(guidanceList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    guidanceList.get(guidanceList.size()-1).setSortId(guidanceList.size());
                    guidanceList.get(guidanceList.size()-1).setCertificate(baseUrl.substring(0,baseUrl.length()-1) + guidanceList.get(guidanceList.size()-1).getCertificate());
                }
            }

            //个人参赛
            contestPar.setTeacherId(teacherId);
            List<SysTeacherContest> list6 = sysTeacherContestService.selectSysTeacherContestList(contestPar);
            if(list6.size()!=0){
                for(int n =0;n<list6.size();n++){
                    contestList.add(list6.get(n));
                    contestList.get(contestList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    contestList.get(contestList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    contestList.get(contestList.size()-1).setSortId(contestList.size());
                    contestList.get(contestList.size()-1).setCertificate(baseUrl.substring(0,baseUrl.length()-1) + contestList.get(contestList.size()-1).getCertificate());
                }
            }
            //个人荣誉
            honorPar.setTeacherId(teacherId);
            List<SysTeacherHonor> list7 = sysTeacherHonorService.selectSysTeacherHonorList(honorPar);
            if(list7.size()!=0){
                for(int n =0;n<list7.size();n++){
                    honorList.add(list7.get(n));
                    honorList.get(honorList.size()-1).setTeacherName(list.get(i).getTeacherName());
                    honorList.get(honorList.size()-1).setTeacherCollege(list.get(i).getTeacherCollege());
                    honorList.get(honorList.size()-1).setSortId(honorList.size());
                    honorList.get(honorList.size()-1).setCertificate(baseUrl.substring(0,baseUrl.length()-1) + honorList.get(honorList.size()-1).getCertificate());
                }
            }
        }



//        ExcelUtil<SysTeacherAchievementcheck> util = new ExcelUtil<SysTeacherAchievementcheck>(SysTeacherAchievementcheck.class);
//        util.exportExcel(response, list, "achievementcheck数据");


        ExcelExp e1 = new ExcelExp("论文成果", thesisList, SysTeacherThesis.class);
        ExcelExp e2 = new ExcelExp("课题研究", researchList, SysTeacherResearch.class);
        ExcelExp e3 = new ExcelExp("工作案例", workexampleList, SysTeacherWorkexample.class);
        ExcelExp e4 = new ExcelExp("指导参赛", guidanceList, SysTeacherGuidance.class);
        ExcelExp e5 = new ExcelExp("个人参赛", contestList, SysTeacherContest.class);
        ExcelExp e6 = new ExcelExp("个人荣誉", honorList, SysTeacherHonor.class);
        List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
        mysheet.add(e1);
        mysheet.add(e2);
        mysheet.add(e3);
        mysheet.add(e4);
        mysheet.add(e5);
        mysheet.add(e6);
//        ExcelUtilManySheet<List<ExcelExp>> util2 = new ExcelUtilManySheet<List<ExcelExp>>(mysheet);
        ExcelUtilManySheet<List<SysTeacherThesis>> util2 = new ExcelUtilManySheet<List<SysTeacherThesis>>(mysheet);
        util2.exportExcelManySheet(response, mysheet);


    }

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

    /**
     * 新增achievementcheck
     */
    @PreAuthorize("@ss.hasPermi('teacher:achievementcheck:add')")
    @Log(title = "achievementcheck", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增achievementcheck")
    public AjaxResult add(@RequestBody SysTeacherAchievementcheck sysTeacherAchievementcheck)
    {
        return toAjax(sysTeacherAchievementcheckService.insertSysTeacherAchievementcheck(sysTeacherAchievementcheck));
    }

    /**
     * 修改achievementcheck
     */
    @PreAuthorize("@ss.hasPermi('teacher:achievementcheck:edit')")
    @Log(title = "achievementcheck", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改achievementcheck")
    public AjaxResult edit(@RequestBody SysTeacherAchievementcheck sysTeacherAchievementcheck)
    {
        return toAjax(sysTeacherAchievementcheckService.updateSysTeacherAchievementcheck(sysTeacherAchievementcheck));
    }

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

    /**
     * 删除achievementcheck
     */
    @PreAuthorize("@ss.hasPermi('teacher:achievementcheck:remove')")
    @Log(title = "achievementcheckByTeacherId", businessType = BusinessType.DELETE)
    @PostMapping("/{teacherId}")
    @ApiOperation("通过辅导员id删除achievementcheck")
    public AjaxResult removeByTeacherId(@PathVariable Long teacherId)
    {
        return toAjax(sysTeacherAchievementcheckService.deleteSysTeacherAchievementcheckByteacherId(teacherId));
    }
}
