package com.ssj.aijia.kmt.sys.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.alibaba.dubbo.config.annotation.Reference;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.security.annotation.IgnoreSecurity;
import com.ssj.framework.core.security.annotation.ModifySecurity;
import com.ssj.framework.core.security.manager.TokenManager;
import com.ssj.framework.core.util.ResponseConstant;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.service.kmt.constant.KnowledgeVersion;
import com.ssj.service.kmt.correctsys.dto.CheckTeacherDetailDto;
import com.ssj.service.kmt.correctsys.request.ApplyOperateReq;
import com.ssj.service.kmt.dto.KmtExerciseLibExportDto;
import com.ssj.service.kmt.dto.exercise.ExerciseBookAndLibExportDto;
import com.ssj.service.kmt.exercisesys.dto.*;
import com.ssj.service.kmt.exercisesys.enums.ExportExerciseBookStatusEnum;
import com.ssj.service.kmt.exercisesys.request.*;
import com.ssj.service.kmt.exercisesys.service.KmtExerciseSysService;
import com.ssj.service.kmt.request.KmtExerciseBookLibReq;
import com.ssj.sys.util.thirdparty.excel.CustomizeToExcel;
import com.ssj.sys.util.thirdparty.excel.ExcelColumn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;


/**
 * @author Mount Liu
 * @date 2020/3/18
 */
@RestController
@Api(value = "录题管理平台接口", tags = "录题管理平台接口")
@RequestMapping("/api/kmt/exerciseSys")
public class KmtExerciseSysController extends BaseController {

    @Autowired
    private TokenManager tokenManager;

    @Reference(version = "1.0", timeout = 60000)
    private KmtExerciseSysService kmtExerciseSysService;
    @Autowired
    private KnowledgeVersion knowledgeVersion;

    @RequestMapping(value = "/getVerificationCode", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "获取手机验证码", httpMethod = "POST", notes = "获取手机验证码")
    public ResponseEntity getVerificationCode(@RequestParam(name = "accessToken") String accessToken, @RequestBody GetVerificationCodeReq req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.getVerificationCode(req.getPhone(), req.getType(), userId);
        } catch (Exception e) {
            logger.error("获取手机验证码异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/verifyCode", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "注册验证验证码", httpMethod = "POST", notes = "注册验证验证码")
    public ResponseEntity verifyCode(@RequestBody VerifyCodeReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.verifyCode(req.getPhone(), req.getVcode());
        } catch (Exception e) {
            logger.error("注册验证验证码异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/accountLogin", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "账号密码登录", httpMethod = "POST", notes = "账号密码登录")
    public ResponseEntity accountLogin(@RequestBody AccountLoginReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.accountLogin(req.getLoginName(), req.getPassword());
        } catch (Exception e) {
            logger.error("账号密码登录异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/setPassword", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "注册设置密码", httpMethod = "POST", notes = "注册设置密码")
    public ResponseEntity setPassword(@RequestBody SetPasswordReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.setPassword(req);
        } catch (Exception e) {
            logger.error("注册设置密码异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
    @ApiOperation(value = "重置密码", httpMethod = "POST", notes = "重置密码")
    public ResponseEntity resetPassword(@RequestParam(name = "accessToken") String accessToken, @RequestBody ResetPasswordReq req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.resetPassword(req, userId);
        } catch (Exception e) {
            logger.error("重置密码异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/forgetPassword", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "忘记密码", httpMethod = "POST", notes = "忘记密码")
    public ResponseEntity forgetPassword(@RequestBody ForgetPasswordReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.forgetPassword(req);
        } catch (Exception e) {
            logger.error("忘记密码异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/updateBindPhone", method = RequestMethod.POST)
    @ApiOperation(value = "换绑手机号", httpMethod = "POST", notes = "换绑手机号")
    public ResponseEntity updateBindPhone(@RequestParam(name = "accessToken") String accessToken, @RequestBody ForgetPasswordReq req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.updateBindPhone(req, userId);
        } catch (Exception e) {
            logger.error("换绑手机号异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/bindWxUnionId2PhoneUser", method = RequestMethod.POST)
    @ApiOperation(value = "扫码绑定微信账户", httpMethod = "POST", notes = "扫码绑定微信账户")
    public ResponseEntity bindWxUnionId2PhoneUser(@RequestParam(name = "accessToken") String accessToken, @RequestBody @Valid ScanWxRequest req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.bindWxUnionId2PhoneUser(req.getCode(), userId);
        } catch (Exception e) {
            logger.error("扫码绑定微信账户", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }


    @RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
    @ApiOperation(value = "提交资料", httpMethod = "POST", notes = "提交资料")
    public ResponseEntity saveInfo(@RequestParam(name = "accessToken") String accessToken, @RequestBody SaveInfoExesysReq req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.saveInfo(userId, req);
        } catch (Exception e) {
            logger.error("提交资料异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/getMyInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取用户信息", httpMethod = "POST", notes = "获取用户信息")
    public ResponseEntity getMyInfo(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.getMyInfo(userId);
        } catch (Exception e) {
            logger.error("获取用户信息异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findRegisTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "注册资料详情列表", httpMethod = "POST", notes = "注册资料详情列表")
    public ResponseEntity queryAllRegisterTeacher(@RequestParam(name = "accessToken") String accessToken, @Valid @RequestBody ExercisePageReq req) {

        ResponseEntity responseEntity;
        try {
            Pageable pageable = initPage(req.getPageNo(), req.getPageSize(), Sort.Direction.ASC, "createTime");
            responseEntity = kmtExerciseSysService.queryAllRegisterTeacher(req, pageable);
        } catch (Exception e) {
            logger.error("获取注册资料详情列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/applyOperate", method = RequestMethod.POST)
    @ApiOperation(value = "申请审批操作", httpMethod = "POST", notes = "申请审批操作")
    public ResponseEntity applyExerciseTeacherOperate(@RequestParam(name = "accessToken") String accessToken, @RequestBody ApplyOperateReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.applyExerciseTeacherOperate(req);
        } catch (Exception e) {
            logger.error("申请审批操作异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "练习册老师列表", httpMethod = "POST", notes = "练习册老师列表")
    public ResponseEntity findExerciseTeacherList(@RequestParam(name = "accessToken") String accessToken,
                                                  @RequestBody ExerciseTeacherListReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findExerciseTeacherList(req);
        } catch (Exception e) {
            logger.error("req={}", req);
            logger.error("查询练习册老师列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseTeacherDetails", method = RequestMethod.POST)
    @ApiOperation(value = "练习册老师详情", httpMethod = "POST", notes = "练习册老师详情")
    public ResponseEntity findExerciseTeacherDetails(@RequestParam(name = "accessToken") String accessToken,
                                                     @RequestBody ExerciseTeacherDetailReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findExerciseTeacherDetails(req);
        } catch (Exception e) {
            logger.error("查询练习册老师详情异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseTeacherReviseQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "查询练习册打回的题目", httpMethod = "POST", notes = "查询练习册打回的题目")
    public ResponseEntity findExerciseTeacherReviseQuestions(@RequestParam(name = "accessToken") String accessToken,
                                                             @RequestBody @Valid ExerciseTeacherReviseQuestionReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findExerciseTeacherReviseQuestions(req);
        } catch (Exception e) {
            logger.error("req={}", req);
            logger.error("查询练习册打回的题目异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findKmtTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "kmt老师列表", httpMethod = "POST", notes = "kmt老师列表")
    public ResponseEntity findKmtTeacherList(@RequestParam(name = "accessToken") String accessToken,
                                             @RequestBody FindKmtTeacherListReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findKmtTeacherList(req);
        } catch (Exception e) {
            logger.error("kmt老师列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findKmtTeacherDetails", method = RequestMethod.POST)
    @ApiOperation(value = "kmt老师详情", httpMethod = "POST", notes = "kmt老师详情")
    public ResponseEntity findKmtTeacherDetails(@RequestParam(name = "accessToken") String accessToken,
                                                @RequestBody FindKmtTeacherDetailReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findKmtTeacherDetails(req);
        } catch (Exception e) {
            logger.error("kmt老师详情异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findTeacherStatusDetail", method = RequestMethod.POST)
    @ApiOperation(value = "老师信息状态详情", httpMethod = "POST", notes = "kmt老师详情")
    public ResponseEntity findTeacherStatusDetail(@RequestParam(name = "accessToken") String accessToken,
                                                  @Valid @RequestBody TeacherInfoStatusDetailReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findTeacherStatusDetail(req);
        } catch (Exception e) {
            logger.error("teacherId={}", req.getTeacherId());
            logger.error("查询老师信息状态详情异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/changeTeacherWorkingStatus", method = RequestMethod.POST)
    @ApiOperation(value = "老师转正/冻结/解冻/注销", httpMethod = "POST", notes = "老师转正/冻结/解冻/注销")
    public ResponseEntity changeTeacherWorkingStatus(@RequestParam(name = "accessToken") String accessToken,
                                                     @RequestBody ChangeTeacherWorkingStatusReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.changeTeacherWorkingStatus(req);
        } catch (Exception e) {
            logger.error("老师转正/冻结/解冻/注销异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }


    @RequestMapping(value = "/findKmtTeacherReviseQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "查询kmt打回的题目", httpMethod = "POST", notes = "查询kmt打回的题目")
    public ResponseEntity findKmtTeacherReviseQuestions(@RequestParam(name = "accessToken") String accessToken,
                                                        @RequestBody FindTeacherReviseQuestionsReq req) {
        ResponseEntity responseEntity = new ResponseEntity();
        ;
        try {
            responseEntity = kmtExerciseSysService.findKmtTeacherReviseQuestions(req);
        } catch (Exception e) {
            logger.error("查询kmt打回的题目异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findTeacherInfoList", method = RequestMethod.POST)
    @ApiOperation(value = "查看老师资料表", httpMethod = "POST", notes = "查看老师资料表")
    public ResponseEntity findTeacherInfoList(@RequestParam(name = "accessToken") String accessToken, @Valid @RequestBody MonthPageReq req) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            Pageable pageable = initPage(req.getPageNo(), req.getPageSize());
            responseEntity = kmtExerciseSysService.findTeacherInfoList(req, pageable);
        } catch (Exception e) {
            logger.error("kmt老师列表异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }


    @RequestMapping(value = "/findLastInsertMonth", method = RequestMethod.POST)
    @ApiOperation(value = "查询最近增加老师月份", httpMethod = "POST", notes = "查询最近增加老师月份")
    public ResponseEntity findLastInsertMonth(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtExerciseSysService.findLastInsertMonth();
        } catch (Exception e) {
            logger.error("查询最近增加老师月份异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/exerciseBookCount", method = RequestMethod.POST)
    @ApiOperation(value = "练习册统计", httpMethod = "POST", notes = "查询最近增加老师月份")
    public ResponseEntity exerciseBookCount(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtExerciseSysService.findExerciseBookCount();
        } catch (Exception e) {
            logger.error("查询练习册统计异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/exerciseBookCountSubjectDetail", method = RequestMethod.POST)
    @ApiOperation(value = "单科练习册列表", httpMethod = "POST", notes = "查询最近增加老师月份")
    public ResponseEntity exerciseBookCountSubjectDetail(@RequestParam(name = "accessToken") String accessToken,
                                                         @RequestBody @Valid ExerciseBookCountSubjectDetailReq req) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtExerciseSysService.findExerciseBookCountSubjectDetail(req);
        } catch (Exception e) {
            logger.error("查询单科练习册列表异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @IgnoreSecurity
    @RequestMapping(value = "/findOrgRecordRateList", method = RequestMethod.POST)
    @ApiOperation(value = "查询机构识别率", httpMethod = "POST", notes = "查询机构识别率")
    public ResponseEntity findOrgRecordRateList(@RequestParam(name = "accessToken") String accessToken, @RequestBody KmtExerciseBookLibReq req) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtExerciseSysService.findOrgRecordRateList(req);
        } catch (Exception e) {
            logger.error("查询机构识别率异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ApiOperation(value = "from表单上传，可上传多个")
    @IgnoreSecurity
    @RequestMapping(value = "/uploadForm", method = RequestMethod.POST)
    public ResponseEntity uploadForm(@RequestParam(name = "accessToken") String accessToken,
                                     @RequestParam(name = "type") int type,
                                     @RequestParam(name = "files") List<MultipartFile> files) throws Exception {
        ResponseEntity responseEntity = new ResponseEntity();
        if (files != null && files.size() > 0) {
            //文件信息入库
            responseEntity = kmtExerciseSysService.uploadForm(tokenManager.getUserId(accessToken), type, files);
        } else {
            responseEntity.failure(ResponseConstant.CODE_000, "上传图片失败");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseList", method = RequestMethod.POST)
    @ApiOperation(value = "查看练习册列表", httpMethod = "POST", notes = "查看练习册列表")
    public ResponseEntity findExerciseList(@RequestParam(name = "accessToken") String accessToken, @RequestBody ExerciseListReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findExerciseList(req);
        } catch (Exception e) {
            logger.error("查看练习册列表", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/addOrEditExerciseBook", method = RequestMethod.POST)
    @ApiOperation(value = "新加或编辑练习册", httpMethod = "POST", notes = "新加或编辑练习册")
    public ResponseEntity addOrEditExerciseBook(@RequestParam(name = "accessToken") String accessToken, @RequestBody AddOrEditExerciseReq req) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSysService.addOrEditExerciseBook(req, userId);
        } catch (Exception e) {
            logger.error("新加或编辑练习册", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseDetail", method = RequestMethod.POST)
    @ApiOperation(value = "查看练习册详情", httpMethod = "POST", notes = "查看练习册详情")
    public ResponseEntity findExerciseDetail(@RequestParam(name = "accessToken") String accessToken, @RequestBody ExerciseDetailReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findExerciseDetail(req);
        } catch (Exception e) {
            logger.error("查看练习册详情", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findLibList", method = RequestMethod.POST)
    @ApiOperation(value = "查看机构列表", httpMethod = "POST", notes = "查看机构列表")
    public ResponseEntity findLibList(@RequestParam(name = "accessToken") String accessToken, @RequestBody FindLibReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findLibList(req);
        } catch (Exception e) {
            logger.error("查看机构列表", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findPressList", method = RequestMethod.POST)
    @ApiOperation(value = "查看出版社列表", httpMethod = "POST", notes = "查看出版社列表")
    public ResponseEntity findPressList(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findPressList();
        } catch (Exception e) {
            logger.error("查看出版社列表", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExercise")
    @ApiOperation(value = "练习册导出", httpMethod = "GET", notes = "练习册导出")
    public void exportTeacherInfo(@RequestParam(name = "accessToken") String accessToken,
                                  @RequestParam(name = "pageNo", required = false) Integer pageNo,
                                  @RequestParam(name = "pageSize", required = false) Integer pageSize,
                                  HttpServletResponse response) throws Exception {
        if (accessToken == null || !tokenManager.checkToken(accessToken)) {
            throw new Exception("accessToken无效");
        }
        ServletOutputStream os;
        try {
            String name = DateUtil.format_yyyyMMdd(new Date());
            os = response.getOutputStream(); //获得输出流
            response.reset();   //清空输出流
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = new String(name.getBytes("gb2312"), "UTF-8") + ".xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName); //设定输出文件头
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");
            List<Exercise1Dto> list = null;
            ExerciseListReq req = new ExerciseListReq();
            req.setPageNo(pageNo);
            req.setPageSize(pageSize);
            ResponseEntity responseEntity = kmtExerciseSysService.findExerciseList(req);
            if ("999".equals(responseEntity.getCode())) {
                Map<String, Object> data = (Map<String, Object>) responseEntity.getData();
                list = (List<Exercise1Dto>) data.get("list");
            }
            List<Map<String, Object>> mapList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(list)) {
                list.forEach(e -> {
                    Map<String, Object> hashMap = new HashMap<>(16);
                    hashMap.put("url1", e.getUrl1());
                    hashMap.put("url2", e.getUrl2());
                    hashMap.put("bookName", e.getBookName());
                    hashMap.put("press", e.getPress());
                    hashMap.put("subject", e.getSubject());
                    hashMap.put("grade", e.getGrade());
                    hashMap.put("versionName", e.getVersionName());
                    hashMap.put("semester", e.getSemester() == 1 ? "上册" : "下册");
                    int bookType=e.getBookType();
                    if(0==bookType){
                        hashMap.put("bookType","整本");
                    }else if(1==bookType){
                        hashMap.put("bookType","上半");
                    }else if(2==bookType){
                        hashMap.put("bookType","下半");
                    }else if(3==bookType){
                        hashMap.put("bookType","不同");
                    }
                    hashMap.put("printYear", e.getPrintYear());
                    hashMap.put("useYear", e.getBookYear()+"");
                    hashMap.put("status", e.getStatus());
                    hashMap.put("orgNums", e.getOrgNums());
                    hashMap.put("progress", e.getProgress());
                    hashMap.put("priority", e.getPriority());
                    hashMap.put("identifiedNums", e.getIdentifiedNums());
                    hashMap.put("assignedBatch", e.getAssignedBatch());
                    mapList.add(hashMap);
                });
            }

            List<ExcelColumn> myColumns3 = new ArrayList<>();
            myColumns3.add(new ExcelColumn("练习册完整封面页", "url1", 20));
            myColumns3.add(new ExcelColumn("含印刷版次页", "url2", 20));
            myColumns3.add(new ExcelColumn("练习册名称", "bookName", 20));
            myColumns3.add(new ExcelColumn("出版社", "press", 20));
            myColumns3.add(new ExcelColumn("科目", "subject", 20));
            myColumns3.add(new ExcelColumn("年级", "grade", 20));
            myColumns3.add(new ExcelColumn("版本", "versionName", 20));
            myColumns3.add(new ExcelColumn("上下册", "semester", 20));
            myColumns3.add(new ExcelColumn("类型", "bookType", 20));
            myColumns3.add(new ExcelColumn("印刷年份", "printYear", 20));
            myColumns3.add(new ExcelColumn("使用年份", "useYear", 20));
            myColumns3.add(new ExcelColumn("状态", "status", 20));
            myColumns3.add(new ExcelColumn("关联机构数", "orgNums", 20));
            myColumns3.add(new ExcelColumn("对接进度", "progress", 20));
            myColumns3.add(new ExcelColumn("优先级", "priority", 20));
            myColumns3.add(new ExcelColumn("被识别次数", "identifiedNums", 20));
            myColumns3.add(new ExcelColumn("归属批次", "assignedBatch", 20));
            try {
                CustomizeToExcel.downFile(myColumns3, mapList, os);
            } catch (Exception e) {
                logger.error("异常", e);
            }
        } catch (Exception e) {
            logger.error("练习册信息导出失败", e);
        }

    }


    @ResponseBody
    @RequestMapping(value = "/OrgRecograteListExport")
    @ApiOperation(value = "识别率导出", httpMethod = "GET", notes = "识别率导出")
    public void exportTeacherInfo(@RequestParam(name = "accessToken") String accessToken,
                                  @RequestParam(name = "subject") String subject,
                                  HttpServletResponse response) throws Exception {
        if (accessToken == null || !tokenManager.checkToken(accessToken)) {
            throw new Exception("accessToken无效");
        }
        ServletOutputStream os = null;
        try {
            String name = DateUtil.format_yyyyMMdd(new Date());
            os = response.getOutputStream(); //获得输出流
            response.reset();   //清空输出流
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = new String(name.getBytes("gb2312"), "UTF-8") + ".xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName); //设定输出文件头
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");
            List<ExerciseBookAndLibExportDto> list0 = kmtExerciseSysService.findAllExportExerciseLib(subject);
            List<Map<String, Object>> list2 = this.getMapForBean(list0);
            List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
            //构造对象等同于@Excel
            ExcelExportEntity excelentity01 = new ExcelExportEntity("合作机构", "libName");
            excelentity01.setNeedMerge(true);
            ExcelExportEntity excelentity02 = new ExcelExportEntity("地区", "address");
            excelentity02.setNeedMerge(true);
            ExcelExportEntity excelentity03 = new ExcelExportEntity("签约数", "signService");
            excelentity03.setNeedMerge(true);
            entity.add(excelentity01);
            entity.add(excelentity02);
            entity.add(excelentity03);
            ExcelExportEntity excelentity5 = new ExcelExportEntity(null, "bookLibList");
            List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
            temp.add(new ExcelExportEntity("版本", "version"));
            temp.add(new ExcelExportEntity("练习册名单", "exerciseName"));
            temp.add(new ExcelExportEntity("教册", "semester"));
            temp.add(new ExcelExportEntity("优先级", "priority"));
            temp.add(new ExcelExportEntity("一年级", "gradeOne"));
            temp.add(new ExcelExportEntity("二年级", "gradeTwo"));
            temp.add(new ExcelExportEntity("三年级", "gradeThree"));
            temp.add(new ExcelExportEntity("四年级", "gradeFour"));
            temp.add(new ExcelExportEntity("五年级", "gradeFive"));
            temp.add(new ExcelExportEntity("六年级", "gradeSix"));
            excelentity5.setList(temp);
            entity.add(excelentity5);
            List<Map<String, Object>> list1 = new ArrayList<>();
            ExcelExportEntity excelentity04 = new ExcelExportEntity("总数", "totalCount");
            excelentity04.setNeedMerge(true);
            ExcelExportEntity excelentity05 = new ExcelExportEntity("可识别", "recogeCount");
            excelentity05.setNeedMerge(true);
            ExcelExportEntity excelentity06 = new ExcelExportEntity("无法识别", "unrecogeCount");
            excelentity06.setNeedMerge(true);
            ExcelExportEntity excelentity07 = new ExcelExportEntity("未购买", "unPurchaseCount");
            excelentity07.setNeedMerge(true);
            ExcelExportEntity excelentity08 = new ExcelExportEntity("识别率", "chineseRecogeRate");
            excelentity08.setNeedMerge(true);
            entity.add(excelentity04);
            entity.add(excelentity05);
            entity.add(excelentity06);
            entity.add(excelentity07);
            entity.add(excelentity08);
            //构造List等同于@ExcelCollection
            //把我们构造好的bean对象放到params就可以了
            Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(name, name, ExcelType.XSSF), entity,
                    list2);
            workbook.write(os);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.flush();
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }

    private List<Map<String, Object>> getMapForBean(List<ExerciseBookAndLibExportDto> list) {
        List<Map<String, Object>> list2 = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(it -> {
                Map<String, Object> map = new HashMap<>();
                map.put("libName", it.getLibName());
                map.put("address", it.getLibArea());
                map.put("signService", it.getSignService());
                map.put("totalCount", it.getTotalCount());
                map.put("recogeCount", it.getRecogeCount());
                map.put("unrecogeCount", it.getUnrecogeCount());
                map.put("unPurchaseCount", it.getUnPurchaseCount());
                map.put("chineseRecogeRate", it.getChineseRecogeRate());
                List<Map<String, Object>> list3 = new ArrayList<>();
                for (KmtExerciseLibExportDto kmt : it.getLibExportDtoList()) {
                    Map<String, Object> dmap = new HashMap<>();
                    dmap.put("version", kmt.getVersion());
                    dmap.put("exerciseName", kmt.getExerciseName());
                    dmap.put("semester", kmt.getSemester());
                    dmap.put("priority", Optional.ofNullable(kmt.getPriority()).orElse(""));
                    dmap.put("gradeOne", Optional.ofNullable(kmt.getGradeOne()).orElse(""));
                    dmap.put("gradeTwo", Optional.ofNullable(kmt.getGradeTwo()).orElse(""));
                    dmap.put("gradeThree", Optional.ofNullable(kmt.getGradeThree()).orElse(""));
                    dmap.put("gradeFour", Optional.ofNullable(kmt.getGradeFour()).orElse(""));
                    dmap.put("gradeFive", Optional.ofNullable(kmt.getGradeFive()).orElse(""));
                    dmap.put("gradeSix", Optional.ofNullable(kmt.getGradeSix()).orElse(""));
                    list3.add(dmap);
                }
                map.put("bookLibList", list3);
                list2.add(map);

            });
        }
        return list2;
    }

/*    @IgnoreSecurity
    @RequestMapping(value = "/getPriority", method = RequestMethod.POST)
    @ApiOperation(value = "计算优先级", httpMethod = "POST", notes = "计算优先级")
    public ResponseEntity getPriority(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            kmtExerciseSysService.getPriority();
            responseEntity.success("更新计算优先级成功");
        } catch (Exception e) {
            logger.error("更新计算优先级成功异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "更新失败");
        }
        return responseEntity;
    }*/

    @RequestMapping(value = "/findEnterTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "题库录入老师列表", httpMethod = "POST", notes = "kmt老师列表")
    public ResponseEntity findEnterTeacherList(@RequestParam(name = "accessToken") String accessToken,
                                               @RequestBody FindKmtTeacherListReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findEnterTeacherList(req);
        } catch (Exception e) {
            logger.error("题库录入老师列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findEnterTeacherDetails", method = RequestMethod.POST)
    @ApiOperation(value = "题库录入老师详情", httpMethod = "POST", notes = "kmt老师详情")
    public ResponseEntity findEnterTeacherDetails(@RequestParam(name = "accessToken") String accessToken,
                                                  @RequestBody FindKmtTeacherDetailReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findEnterTeacherDetails(req);
        } catch (Exception e) {
            logger.error("题库录入老师详情异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findCheckTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "查找可分配老师列表", httpMethod = "POST", notes = "查找可分配老师列表")
    public ResponseEntity findCheckTeacherList(@RequestParam(name = "accessToken") String accessToken,
                                               @RequestBody FindCheckTeacherListReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findCheckTeacherList(req);
        } catch (Exception e) {
            logger.error("查找可分配老师列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ModifySecurity
    @RequestMapping(value = "/allotCheckTeacher", method = RequestMethod.POST)
    @ApiOperation(value = "分配校对老师", httpMethod = "POST", notes = "分配校对老师")
    public ResponseEntity allotCheckTeacher(@RequestParam(name = "accessToken") String accessToken,
                                            @RequestBody @Valid AllotCheckTeacherReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.allotCheckTeacher(req);
        } catch (Exception e) {
            logger.error("分配校对老师异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findUncheckedExerciseBookList", method = RequestMethod.POST)
    @ApiOperation(value = "查找未校对练习册列表", httpMethod = "POST", notes = "查找未校对练习册列表")
    public ResponseEntity findUncheckedExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                        @RequestBody CheckExerciseBookReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findUncheckedExerciseBookList(req);
        } catch (Exception e) {
            logger.error("查找未校对练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findCheckExerciseBookList", method = RequestMethod.POST)
    @ApiOperation(value = "查找校对中练习册列表", httpMethod = "POST", notes = "查找校对中练习册列表")
    public ResponseEntity findCheckExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                    @RequestBody CheckExerciseBookReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findCheckExerciseBookList(req);
        } catch (Exception e) {
            logger.error("查找校对中练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findCheckedExerciseBookList", method = RequestMethod.POST)
    @ApiOperation(value = "查找已校对练习册列表", httpMethod = "POST", notes = "查找已校对练习册列表")
    public ResponseEntity findCheckExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                    @RequestBody CheckedExerciseBookReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findCheckedExerciseBookList(req);
        } catch (Exception e) {
            logger.error("查找已校对练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/answerProofreadExerciseBookList", method = RequestMethod.POST)
    @ApiOperation(value = "答案报错练习册列表", httpMethod = "POST", notes = "答案报错练习册列表")
    public ResponseEntity findAnswerProofreadExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                              @RequestBody @Valid AnswerProofreadExerciseBookListReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findAnswerProofreadExerciseBookList(req);
        } catch (Exception e) {
            logger.error("req={}", req);
            logger.error("查询答案报错练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/answerProofreadQuestionList", method = RequestMethod.POST)
    @ApiOperation(value = "答案报错题目列表", httpMethod = "POST", notes = "答案报错题目列表")
    public ResponseEntity findAnswerProofreadQuestionList(@RequestParam(name = "accessToken") String accessToken,
                                                          @RequestBody @Valid AnswerProofreadQuestionListReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findAnswerProofreadQuestionList(req);
        } catch (Exception e) {
            logger.error("req={}", req);
            logger.error("查询答案报错题目列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ResponseBody
    @RequestMapping(value = "/exportCheckExerciseBookList")
    @ApiOperation(value = "导出已校对和校对中列表", httpMethod = "GET", notes = "导出已校对和校对中列表")
    public void exportTeacherInfo(@RequestParam(name = "accessToken") String accessToken,
                                  @RequestParam(name = "pageNo", required = false) Integer pageNo,
                                  @RequestParam(name = "pageSize", required = false) Integer pageSize,
                                  @RequestParam(name = "type") int type,
                                  @RequestParam(name = "teacherName", required = false) String teacherName,
                                  @RequestParam(name = "beginTime", required = false) String beginTime,
                                  @RequestParam(name = "endTime", required = false) String endTime,
                                  HttpServletResponse response) throws Exception {
        if (accessToken == null || !tokenManager.checkToken(accessToken)) {
            throw new Exception("accessToken无效");
        }
        if (type == 1) {
            this.exportCheckingExercise(response, pageNo, pageSize, teacherName);
        } else {
            this.exportCheckedExercise(response, pageNo, pageSize, teacherName, beginTime,endTime);
        }
    }

    /**
     * 导出校验中的数据
     * @param response
     * @param pageNo
     * @param pageSize
     * @param teacherName
     */
    private void exportCheckingExercise(HttpServletResponse response, int pageNo, int pageSize, String teacherName) {
        CheckExerciseBookReq req = new CheckExerciseBookReq();
        req.setPageNo(pageNo);
        req.setPageSize(pageSize);
        req.setType(1);
        req.setTeacherName(teacherName);
        ServletOutputStream os = null;
        try {
            String name = "校对中列表导出";
            os = response.getOutputStream(); //获得输出流
            response.reset();   //清空输出流
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = new String(name.getBytes("gb2312"), "UTF-8") + ".xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName); //设定输出文件头
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");
            List<Exercise4Dto> list0 = kmtExerciseSysService.exportCheckExerciseBookList(req);
            List<Map<String, Object>> list2 = this.getBookListMap(list0);
            List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
            //构造对象等同于@Excel
            ExcelExportEntity excelentity = new ExcelExportEntity("老师", "teacherName");
            excelentity.setNeedMerge(true);
            entity.add(excelentity);
            ExcelExportEntity excelentity1 = new ExcelExportEntity(null, "bookList");
            List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
            temp.add(new ExcelExportEntity("名称", "bookName"));
            temp.add(new ExcelExportEntity("科目", "subject"));
            temp.add(new ExcelExportEntity("年级", "grade"));
            temp.add(new ExcelExportEntity("版本", "versionName"));
            temp.add(new ExcelExportEntity("上下册", "semester"));
            temp.add(new ExcelExportEntity("上下半本", "bookType"));
            excelentity1.setList(temp);
            entity.add(excelentity1);
            List<Map<String, Object>> list1 = new ArrayList<>();
            //构造List等同于@ExcelCollection
            //把我们构造好的bean对象放到params就可以了
            Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(name, name, ExcelType.XSSF), entity,
                    list2);
            workbook.write(os);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.flush();
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 导出已校验的数据
     *
     * @param response
     * @param pageNo
     * @param pageSize
     * @param teacherName
     */
    private void exportCheckedExercise(HttpServletResponse response, Integer pageNo, Integer pageSize, String teacherName, String beginTime,String endTime) {
        ServletOutputStream os = null;
        try {
            String name = DateUtil.format_yyyyMMdd(new Date());
            os = response.getOutputStream(); //获得输出流
            response.reset();   //清空输出流
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = new String(name.getBytes("gb2312"), "UTF-8") + ".xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName); //设定输出文件头
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");
            List<Exercise5Dto> list = null;
            CheckedExerciseBookReq req = new CheckedExerciseBookReq();
            req.setPageNo(pageNo);
            req.setPageSize(pageSize);
            req.setTeacherName(teacherName);
            req.setBeginTime(beginTime);
            req.setEndTime(endTime);
            ResponseEntity responseEntity = kmtExerciseSysService.findCheckedExerciseBookList(req);
            if ("999".equals(responseEntity.getCode())) {
                Map<String, Object> data = (Map<String, Object>) responseEntity.getData();
                list = (List<Exercise5Dto>) data.get("list");
            }
            List<Map<String, Object>> mapList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(list)) {
                list.forEach(e -> {
                    Map<String, Object> hashMap = new HashMap<>(16);
                    hashMap.put("bookName", e.getBookName());
                    hashMap.put("subject", e.getSubject());
                    hashMap.put("grade", e.getGrade());
                    hashMap.put("versionName", e.getVersionName());
                    hashMap.put("semester", e.getSemester() == 1 ? "上册" : "下册");
                    String bookType = "";
                    int type = e.getBookType();
                    if (0 == type) {
                        bookType = "整本";
                    } else if (1 == type) {
                        bookType = "上半";
                    } else {
                        bookType = "下半";
                    }
                    hashMap.put("bookType", bookType);
                    hashMap.put("useYear", e.getUseYear());
                    hashMap.put("checkTime", e.getCheckedTime());
                    hashMap.put("teacherName", e.getTeacherName());
                    mapList.add(hashMap);
                });
            }

            List<ExcelColumn> myColumns3 = new ArrayList<>();
            myColumns3.add(new ExcelColumn("名称", "bookName", 20));
            myColumns3.add(new ExcelColumn("科目", "subject", 20));
            myColumns3.add(new ExcelColumn("年级", "grade", 20));
            myColumns3.add(new ExcelColumn("版本", "versionName", 20));
            myColumns3.add(new ExcelColumn("上下册", "semester", 20));
            myColumns3.add(new ExcelColumn("上下半本", "bookType", 20));
            myColumns3.add(new ExcelColumn("使用年份", "useYear", 20));
            myColumns3.add(new ExcelColumn("完成时间", "checkTime", 20));
            myColumns3.add(new ExcelColumn("校对老师", "teacherName", 20));
            try {
                CustomizeToExcel.downFile(myColumns3, mapList, os);
            } catch (Exception e) {
                logger.error("异常", e);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.flush();
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private List<Map<String, Object>> getBookListMap(List<Exercise4Dto> list) {
        List<Map<String, Object>> list1 = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(a -> {
             Map<String,Object> linkMap=new LinkedHashMap<>();
             linkMap.put("teacherName",a.getTeacherName());
             List<Map<String,Object>> list2=new ArrayList<>();
             for(Exercise3Dto exercise3Dto:a.getExercise3DtoList()){
                 Map<String,Object> linkMap1=new LinkedHashMap<>();
                 linkMap1.put("bookName",exercise3Dto.getBookName());
                 linkMap1.put("subject",exercise3Dto.getSubject());
                 linkMap1.put("grade",exercise3Dto.getGrade());
                 linkMap1.put("versionName",exercise3Dto.getVersionName());
                 linkMap1.put("semester",exercise3Dto.getSemester()==1? "上册":"下册");
                 String bookType="";
                 int type=exercise3Dto.getBookType();
                 if(0==type){
                     bookType="整本";
                 }else if(1==type){
                     bookType="上半";
                 }else {
                     bookType="下半";
                 }
                 linkMap1.put("bookType",bookType);
                 list2.add(linkMap1);

             }
             linkMap.put("bookList",list2);
             list1.add(linkMap);
            });

        }

        return list1 ;
    }


    @RequestMapping(value = "/findRoleHistoryList", method = RequestMethod.POST)
    @ApiOperation(value = "角色更改历史记录", httpMethod = "POST", notes = "角色更改历史记录")
    public ResponseEntity findRoleHistoryList(@RequestParam(name = "accessToken") String accessToken,
                                              @RequestBody @Valid TeacherInfoStatusDetailReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findRoleHistoryList(req.getTeacherId());
        } catch (Exception e) {
            logger.error("角色更改历史记录异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @IgnoreSecurity
    @RequestMapping(value = "/updateExerciseAnwerStatus", method = RequestMethod.POST)
    @ApiOperation(value = "更新练习册状态", httpMethod = "POST", notes = "更新练习册状态")
    public ResponseEntity updateExerciseAnwerStatus(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            kmtExerciseSysService.updateExerciseAnwerStatus();
            responseEntity.success("更新练习册状态成功");
        } catch (Exception e) {
            logger.error("更新练习册状态异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "更新练习册状态");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findCheckTeacherDetails", method = RequestMethod.POST)
    @ApiOperation(value = "答案校对老师详情",httpMethod = "POST",notes = "答案校对老师详情")
    public ResponseEntity findCheckTeacherDetails(@RequestParam(name = "accessToken") String accessToken,@RequestBody CheckTeacherDetailsRequest req){
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findCheckTeacherDetailsList(req);
        } catch (Exception e) {
            logger.error("角色更改历史记录异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ResponseBody
    @RequestMapping(value = "/exportCheckTeacherDetails")
    @ApiOperation(value = "导出答案校对详情", httpMethod = "GET", notes = "导出答案校对详情")
    public void exportCheckTeacherDetails(@RequestParam(name = "accessToken") String accessToken,
                                  @RequestParam(name = "pageNo", required = true) Integer pageNo,
                                  @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                  @RequestParam(name = "teacherId",required = true) String teacherId,
                                  HttpServletResponse response) throws Exception {
        if (accessToken == null || !tokenManager.checkToken(accessToken)) {
            throw new Exception("accessToken无效");
        }
        ServletOutputStream os;
        try {
            String name = DateUtil.format_yyyyMMdd(new Date());
            os = response.getOutputStream(); //获得输出流
            response.reset();   //清空输出流
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = new String(name.getBytes("gb2312"), "UTF-8") + ".xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName); //设定输出文件头
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");
            CheckTeacherDetailsRequest req = new CheckTeacherDetailsRequest();
            req.setPageNo(pageNo);
            req.setPageSize(pageSize);
            req.setTeacherId(teacherId);
            req.setMaxCreateTime(DateUtil.format_yyyyMMddHHmmss(new Date()));
            List<CheckTeacherDetailDto> list=kmtExerciseSysService.findCheckTeacherList(req);
            List<Map<String, Object>> mapList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(list)) {
                list.forEach(e -> {
                    Map<String, Object> hashMap = new HashMap<>(16);
                    hashMap.put("exerciseBookName",e.getBookName());
                    hashMap.put("grade",e.getGrade());
                    hashMap.put("semester",e.getSemester()==1?"上册":"下册");
                    hashMap.put("halfBook",e.getHalfBook());
                    hashMap.put("subject",e.getCourseName());
                    hashMap.put("version",e.getVersionName());
                    hashMap.put("status",e.getBookStatus());
                    hashMap.put("checkTime",e.getCheckTime());
                    mapList.add(hashMap);
                });
            }

            List<ExcelColumn> myColumns3 = new ArrayList<>();
            myColumns3.add(new ExcelColumn("练习册", "exerciseBookName", 20));
            myColumns3.add(new ExcelColumn("年级", "grade", 20));
            myColumns3.add(new ExcelColumn("上下册", "semester", 20));
            myColumns3.add(new ExcelColumn("上下半本", "halfBook", 20));
            myColumns3.add(new ExcelColumn("科目", "subject", 20));
            myColumns3.add(new ExcelColumn("版本", "version", 20));
            myColumns3.add(new ExcelColumn("状态", "status", 20));
            myColumns3.add(new ExcelColumn("完成校对时间", "checkTime", 20));

            try {
                CustomizeToExcel.downFile(myColumns3, mapList, os);
            } catch (Exception e) {
                logger.error("异常", e);
            }
        } catch (Exception e) {
            logger.error("答案校对详情导出失败", e);
        }

    }

    @RequestMapping(value = "/distributionCount", method = RequestMethod.POST)
    @ApiOperation(value = "练习册分配统计", httpMethod = "POST", notes = "练习册分配统计")
    public ResponseEntity findDistributionCount(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findDistributionCount();
        } catch (Exception e) {
            logger.error("查询练习册分配统计异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/distributionExerciseBookFilterOption", method = RequestMethod.POST)
    @ApiOperation(value = "查询练习册分配筛选项", httpMethod = "POST", notes = "查询练习册分配筛选项")
    public ResponseEntity findDistributionExerciseBookFilterOption(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findDistributionExerciseBookFilterOption();
        } catch (Exception e) {
            logger.error("查询练习册分配筛选项异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findDistributionExerciseBookList", method = RequestMethod.POST)
    @ApiOperation(value = "待分配/已分配练习册列表", httpMethod = "POST", notes = "待分配/已分配练习册列表")
    public ResponseEntity findDistributionExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                           @RequestBody @Valid DistributionExerciseBookListReq req) {

        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findDistributionExerciseBookList(req);
        } catch (Exception e) {
            logger.error("req={}", req);
            logger.error("查询待分配/已分配练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findAllotExerciseTeacherList", method = RequestMethod.POST)
    @ApiOperation(value = "查找可分配练习册老师列表", httpMethod = "POST", notes = "查找可分配练习册老师列表")
    public ResponseEntity findAllotExerciseTeacherList(@RequestParam(name = "accessToken") String accessToken,
                                              @RequestBody FindCheckTeacherListReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.findTeacherListByType(req);
        } catch (Exception e) {
            logger.error("查找可分配练习册老师列表", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ModifySecurity
    @RequestMapping(value = "/allotExerciseDealTeacher", method = RequestMethod.POST)
    @ApiOperation(value = "分配加工人/加审人/解析人/解审人老师", httpMethod = "POST", notes = "分配加工人/加审人/解析人/解审人老师")
    public ResponseEntity allotExerciseDealTeacher(@RequestParam(name = "accessToken") String accessToken,
                                            @RequestBody @Valid AllotExerciseTeacherRequest req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.allotExerciseDealTeacher(req);
        } catch (Exception e) {
            logger.error("分配加工人/加审人/解析人/解审人老师", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ModifySecurity
    @RequestMapping(value = "/exerciseTeacherSalary", method = RequestMethod.POST)
    @ApiOperation(value = "加工人/加审人/解析人/解审人结薪", httpMethod = "POST", notes = "加工人/加审人/解析人/解审人结薪")
    public ResponseEntity exerciseTeacherSalary(@RequestParam(name = "accessToken") String accessToken,
                                                   @RequestBody @Valid ExerciseTeacherSalaryReq req) {
        ResponseEntity responseEntity;
        try {
            responseEntity = kmtExerciseSysService.exerciseTeacherSalary(req);
        } catch (Exception e) {
            logger.error("加工人/加审人/解析人/解审人结薪", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ResponseBody
    @RequestMapping(value = "/exportDistributionExerciseBookList", method = RequestMethod.GET)
    @ApiOperation(value = "导出已分配练习册列表", httpMethod = "GET", notes = "待分配/已分配练习册列表")
    public void exportDistributionExerciseBookList(@RequestParam(name = "accessToken") String accessToken,
                                                   HttpServletResponse response,
                                                   @RequestParam(name = "startTime", required = false) String startTime,
                                                   @RequestParam(name = "endTime", required = false) String endTime) {

        ResponseEntity responseEntity;
        ServletOutputStream os = null;
        try {
            // 参数校验
            if (StringUtils.isNotBlank(startTime) && !startTime.matches(".{0}|\\d{4}-\\d{2}-\\d{2}")) {
                logger.error("异常：导出已分配练习册列表时开始时间格式不正确startTime=[{}]", startTime);
            }
            if (StringUtils.isNotBlank(endTime) && !endTime.matches(".{0}|\\d{4}-\\d{2}-\\d{2}")) {
                logger.error("异常：导出已分配练习册列表时开始时间格式不正确endTime=[{}]", endTime);
            }

            String name = "已分配练习册列表导出";
            response.reset();
            response.setHeader("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent," +
                    "X-Requested-With,x_requested_with,If-Modified-Since,Cache-Control,Content-Type,Authorization");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            response.addHeader("Access-Control-Allow-Origin", "*");
            String fileName = "已分配练习册.xlsx";
            response.setHeader("Content-disposition", "attachment; filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("utf-8");

            // 查询导出数据
            ExportDistributionExerciseBookListReq req = new ExportDistributionExerciseBookListReq();
            req.setStartTime(startTime);
            req.setEndTime(endTime);
            List<ExportDistributionExerciseBookDTO> distributionExerciseBookList =
                    kmtExerciseSysService.findExportDistributionExerciseBookList(req);
            List<Map<String, Object>> dataMapList = this.getExportDistributionExerciseBookMapList(distributionExerciseBookList);

            //构造对象等同于@Excel
            List<ExcelExportEntity> entityList = new ArrayList<>();
            ExcelExportEntity subjectEntity = new ExcelExportEntity("科目", "subject");
            entityList.add(subjectEntity);
            ExcelExportEntity gradeEntity = new ExcelExportEntity("年级", "grade");
            entityList.add(gradeEntity);
            ExcelExportEntity versionEntity = new ExcelExportEntity("版本", "versionName");
            entityList.add(versionEntity);
            ExcelExportEntity semesterEntity = new ExcelExportEntity("上下册", "semester");
            entityList.add(semesterEntity);
            ExcelExportEntity exerciseBookNameEntity = new ExcelExportEntity("练习册名称", "bookName");
            exerciseBookNameEntity.setWidth(12);
            entityList.add(exerciseBookNameEntity);
            ExcelExportEntity halfBookEntity = new ExcelExportEntity("上下半本/整本", "halfBook");
            halfBookEntity.setWidth(15);
            entityList.add(halfBookEntity);
            ExcelExportEntity unitCourseNumEntity = new ExcelExportEntity("单元/课时数", "unitCourseNum");
            unitCourseNumEntity.setWidth(15);
            entityList.add(unitCourseNumEntity);
            ExcelExportEntity handlerNameEntity = new ExcelExportEntity("加工人", "handlerName");
            entityList.add(handlerNameEntity);
            ExcelExportEntity handlerSubmitTimeEntity = new ExcelExportEntity("加工人提交审核时间", "handlerSubmitTime");
            handlerSubmitTimeEntity.setWidth(20);
            entityList.add(handlerSubmitTimeEntity);
            ExcelExportEntity handlerSalaryGivenEntity = new ExcelExportEntity("加工人是否结薪", "handlerSalaryGiven");
            handlerSalaryGivenEntity.setWidth(15);
            entityList.add(handlerSalaryGivenEntity);
            ExcelExportEntity handlerSalaryGivenTimeEntity = new ExcelExportEntity("加工人结薪时间", "handlerSalaryGivenTime");
            handlerSalaryGivenTimeEntity.setWidth(15);
            ExcelExportEntity handleAccuracyEntity = new ExcelExportEntity("加工正确率", "handleAccuracy");
            handleAccuracyEntity.setWidth(12);
            entityList.add(handleAccuracyEntity);
            entityList.add(handlerSalaryGivenTimeEntity);
            ExcelExportEntity handleAuditUserNameEntity = new ExcelExportEntity("加审人", "handleAuditUserName");
            entityList.add(handleAuditUserNameEntity);
            ExcelExportEntity handleAuditUserSubmitTimeEntity = new ExcelExportEntity("加审人提交审核时间", "handleAuditUserSubmitTime");
            handleAuditUserSubmitTimeEntity.setWidth(20);
            entityList.add(handleAuditUserSubmitTimeEntity);
            ExcelExportEntity handleAuditUserSalaryGivenEntity = new ExcelExportEntity("加审人是否结薪", "handleAuditUserSalaryGiven");
            handleAuditUserSalaryGivenEntity.setWidth(15);
            entityList.add(handleAuditUserSalaryGivenEntity);
            ExcelExportEntity handleAuditUserSalaryGivenTimeEntity = new ExcelExportEntity("加审人结薪时间", "handleAuditUserSalaryGivenTime");
            handleAuditUserSalaryGivenTimeEntity.setWidth(15);
            entityList.add(handleAuditUserSalaryGivenTimeEntity);
            ExcelExportEntity handleAuditAccuracyEntity = new ExcelExportEntity("审核发布正确率", "handleAuditAccuracy");
            handleAuditAccuracyEntity.setWidth(15);
            entityList.add(handleAuditAccuracyEntity);
            ExcelExportEntity analyserNameEntity = new ExcelExportEntity("解析人", "analyserName");
            entityList.add(analyserNameEntity);
            ExcelExportEntity analyserSubmitTimeEntity = new ExcelExportEntity("解析人提交审核时间", "analyserSubmitTime");
            analyserSubmitTimeEntity.setWidth(20);
            entityList.add(analyserSubmitTimeEntity);
            ExcelExportEntity analyserSalaryGivenEntity = new ExcelExportEntity("解析人是否结薪", "analyserSalaryGiven");
            analyserSalaryGivenEntity.setWidth(15);
            entityList.add(analyserSalaryGivenEntity);
            ExcelExportEntity analyserSalaryGivenTimeEntity = new ExcelExportEntity("解析人结薪时间", "analyserSalaryGivenTime");
            analyserSalaryGivenTimeEntity.setWidth(15);
            entityList.add(analyserSalaryGivenTimeEntity);
            ExcelExportEntity analysisAccuracyEntity = new ExcelExportEntity("解析加工正确率", "analysisAccuracy");
            analysisAccuracyEntity.setWidth(15);
            entityList.add(analysisAccuracyEntity);
            ExcelExportEntity analysisAuditUserNameEntity = new ExcelExportEntity("解审人", "analysisAuditUserName");
            entityList.add(analysisAuditUserNameEntity);
            ExcelExportEntity analysisAuditUserSubmitTimeEntity = new ExcelExportEntity("解审人提交审核时间", "analysisAuditUserSubmitTime");
            analysisAuditUserSubmitTimeEntity.setWidth(20);
            entityList.add(analysisAuditUserSubmitTimeEntity);
            ExcelExportEntity analysisAuditUserSalaryGivenEntity = new ExcelExportEntity("解审人是否结薪", "analysisAuditUserSalaryGiven");
            analysisAuditUserSalaryGivenEntity.setWidth(15);
            entityList.add(analysisAuditUserSalaryGivenEntity);
            ExcelExportEntity analysisAuditUserSalaryGivenTimeEntity = new ExcelExportEntity("解审人结薪时间", "analysisAuditUserSalaryGivenTime");
            analysisAuditUserSalaryGivenTimeEntity.setWidth(15);
            entityList.add(analysisAuditUserSalaryGivenTimeEntity);
            ExcelExportEntity bookStatusEntity = new ExcelExportEntity("练习册状态", "bookStatus");
            entityList.add(bookStatusEntity);
            ExcelExportEntity assignedBatchEntity = new ExcelExportEntity("归属批次", "assignedBatch");
            entityList.add(assignedBatchEntity);

            // 生成excel工作表
            Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(name, name, ExcelType.XSSF), entityList,
                    dataMapList);

            // 写入输出流
            os = response.getOutputStream();
            workbook.write(os);
        } catch (Exception e) {
            logger.error("startTime=[{}], endTime=[{}]", startTime, endTime);
            logger.error("导出已分配练习册列表异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        } finally {
            if (os != null) {
                try {
                    os.flush();
                    os.close();
                } catch (IOException e) {
                    logger.error("输出流关闭异常", e);
                }
            }
        }
    }

    private List<Map<String, Object>> getExportDistributionExerciseBookMapList(List<ExportDistributionExerciseBookDTO> exportDistributionExerciseBookDTOList) {
        List<Map<String, Object>> dataMapList = new ArrayList<>(exportDistributionExerciseBookDTOList.size());
        Map<String, Object> dataMap;
        for (ExportDistributionExerciseBookDTO exportDistributionExerciseBookDTO : exportDistributionExerciseBookDTOList) {
            dataMap = new HashMap<>(64);
            dataMapList.add(dataMap);

            dataMap.put("subject", exportDistributionExerciseBookDTO.getSubject());
            dataMap.put("grade", exportDistributionExerciseBookDTO.getGrade());
            dataMap.put("versionName", knowledgeVersion.getVersionNameBySubjectAndVersionNum(exportDistributionExerciseBookDTO.getSubject(), exportDistributionExerciseBookDTO.getVersion()));
            dataMap.put("semester", exportDistributionExerciseBookDTO.getSemester() == 1 ? "上册" : "下册");
            dataMap.put("bookName", exportDistributionExerciseBookDTO.getBookName());
            dataMap.put("halfBook", exportDistributionExerciseBookDTO.getHalfBook());
            dataMap.put("unitCourseNum", exportDistributionExerciseBookDTO.getUnitCount() + "/" + exportDistributionExerciseBookDTO.getCourseCount());
            dataMap.put("handlerName", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandlerName()).orElse(""));
            dataMap.put("handlerSubmitTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandlerLastSubmitTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("handlerSalaryGiven", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandlerSalaryGiven()).orElse(0) == 1 ? "是" : "否");
            dataMap.put("handlerSalaryGivenTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandlerSalaryGivenTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("handleAuditUserName", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandleAuditUserName()).orElse(""));
            dataMap.put("handleAuditUserSubmitTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandleAuditUserLastSubmitTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("handleAuditUserSalaryGiven", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandleAuditUserSalaryGiven()).orElse(0) == 1 ? "是" : "否");
            dataMap.put("handleAuditUserSalaryGivenTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandleAuditUserSalaryGivenTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("analyserName", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalyserName()).orElse(""));
            dataMap.put("analyserSubmitTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalyserLastSubmitTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("analyserSalaryGiven", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalyserSalaryGiven()).orElse(0) == 1 ? "是" : "否");
            dataMap.put("analyserSalaryGivenTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalyserSalaryGivenTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("analysisAuditUserName", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalysisAuditUserName()).orElse(""));
            dataMap.put("analysisAuditUserSubmitTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalysisAuditUserLastSubmitTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("analysisAuditUserSalaryGiven", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalysisAuditUserSalaryGiven()).orElse(0) == 1 ? "是" : "否");
            dataMap.put("analysisAuditUserSalaryGivenTime", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalysisAuditUserSalaryGivenTime()).map(DateUtil::format_yyyyMMddHHmmss).orElse(null));
            dataMap.put("handleAccuracy", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandlerAccuracy()).map(it -> BigDecimal.valueOf(it * 0.01).setScale(2, BigDecimal.ROUND_DOWN).toPlainString() + "%").orElse(""));
            dataMap.put("handleAuditAccuracy", Optional.ofNullable(exportDistributionExerciseBookDTO.getHandleAuditUserAccuracy()).map(it -> BigDecimal.valueOf(it * 0.01).setScale(2, BigDecimal.ROUND_DOWN).toPlainString() + "%").orElse(""));
            dataMap.put("analysisAccuracy", Optional.ofNullable(exportDistributionExerciseBookDTO.getAnalyserAccuracy()).map(it -> BigDecimal.valueOf(it * 0.01).setScale(2, BigDecimal.ROUND_DOWN).toPlainString() + "%").orElse(""));
            dataMap.put("bookStatus", ExportExerciseBookStatusEnum.getDescriptionByCode(exportDistributionExerciseBookDTO.getBookStatus()));
            dataMap.put("assignedBatch", exportDistributionExerciseBookDTO.getAssignedBatch());
        }
        return dataMapList;
    }
    @IgnoreSecurity
    @RequestMapping(value = "/getOrgRate", method = RequestMethod.POST)
    @ApiOperation(value = "更新机构识别统计", httpMethod = "POST", notes = "更新机构识别统计")
    public ResponseEntity getOrgRate(@RequestParam(name="subject") String subject,@RequestParam(name="accessToken")String accessToken){
        ResponseEntity responseEntity = new ResponseEntity();
        try {
           responseEntity=kmtExerciseSysService.CountOrgRate(subject);
           return responseEntity.success("更新机构识别统计成功");
        } catch (Exception e) {
            logger.error("更新机构识别统计异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "更新失败");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/updateOrgRateCount", method = RequestMethod.POST)
    @IgnoreSecurity
    @ApiOperation(value = "更新机构识别率相关计算", httpMethod = "POST", notes = "更新机构识别率相关计算")
    public void updateOrgRateCount(@RequestParam(name="accessToken")String accessToken) {
        try {
             kmtExerciseSysService.updateOrgRateCount();
        } catch (Exception e) {
            logger.error("更新机构识别率相关计算异常", e);

        }

    }
}

