package com.jeeplus.human.enrollment.enrollmentRegistration.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jeeplus.common.excel.EasyExcelUtils;
import com.jeeplus.common.excel.ExcelOptions;
import com.jeeplus.common.excel.annotation.ExportMode;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.human.depart.handover.domain.Handover;
import com.jeeplus.human.depart.handover.service.HandoverService;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.*;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.*;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.ExportDTO;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.UserTemplate;
import com.jeeplus.human.enrollment.enrollmentRegistration.utils.DingTalkSyncUtil;
import com.jeeplus.human.enrollment.enrollmentRegistration.utils.EasyPoiUtil;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import freemarker.template.Configuration;
import freemarker.template.Template;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 王强
 * @version 1.0
 */
@Slf4j
@RestController
@Api("教育经历")
@RequestMapping(value = "/eduInfo")
public class EnrollmentEduInfoController {

    @Resource
    private EnrollmentEduInfoService eduInfoService;


    /**
     * 保存教育经历
     * @return
     */
    @ApiLog(value = "保存教育经历", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody EnrollmentEduInfo eduInfo) throws Exception {
        eduInfoService.saveOrUpdateEduInfo(eduInfo);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 删除教育经历
     * @return
     */
    @ApiLog(value = "删除教育经历", type = LogTypeEnum.SAVE)
    @PostMapping("delete")
    public ResponseEntity<String> delete(@Valid @RequestBody EnrollmentEduInfo eduInfo) throws Exception {
        eduInfoService.removeById(eduInfo.getId());
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 教育经历列表
     * @return
     */
    @ApiLog(value = "教育经历列表", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentEduInfo>> findList(EnrollmentEduInfo eduInfo) throws Exception {
        List<EnrollmentEduInfo> list = eduInfoService.findByUserId(eduInfo.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询教育经历信息
     * @return
     */
    @ApiLog(value = "根据id查询教育经历信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentEduInfo> findById(EnrollmentEduInfo eduInfo) throws Exception {
        EnrollmentEduInfo res = eduInfoService.findById(eduInfo.getId());
        return ResponseEntity.ok (res);
    }


    /**
     * 教育经历用户端列表
     * @return
     */
    @ApiLog(value = "教育经历用户端列表", type = LogTypeEnum.SAVE)
    @GetMapping("findAuditList")
    public ResponseEntity<List<EnrollmentEduInfo>> findAuditList(EnrollmentEduInfo eduInfo) throws Exception {
        List<EnrollmentEduInfo> list = eduInfoService.findByUserId(eduInfo.getUserId(),"1");
        return ResponseEntity.ok (list);
    }
}
