package com.qmth.distributed.print.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itextpdf.text.DocumentException;
import com.qmth.distributed.print.business.bean.dto.PdfDto;
import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
import com.qmth.distributed.print.business.bean.excel.ExcelField;
import com.qmth.distributed.print.business.bean.params.ExamTaskStudentObjectParam;
import com.qmth.distributed.print.business.bean.result.ScoreResult;
import com.qmth.distributed.print.business.entity.BasicTemplate;
import com.qmth.distributed.print.business.entity.ExamDetail;
import com.qmth.distributed.print.business.entity.ExamStudent;
import com.qmth.distributed.print.business.entity.ExamTask;
import com.qmth.teachcloud.common.bean.vo.PrintPathVo;
import com.qmth.teachcloud.common.entity.BasicAttachment;
import com.qmth.teachcloud.common.entity.BasicCourse;
import com.qmth.teachcloud.common.entity.SysOrg;
import com.qmth.teachcloud.common.entity.SysUser;
import com.qmth.teachcloud.common.enums.ClassifyEnum;
import com.qmth.teachcloud.common.enums.PageSizeEnum;
import com.qmth.teachcloud.common.enums.TaskTypeEnum;
import com.qmth.teachcloud.common.enums.UploadFileEnum;
import com.qmth.teachcloud.mark.entity.MarkPaper;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Description: 公共服务service
 * @Author: wangliang
 * @Date: 2021/3/26
 */
public interface PrintCommonService {

    /**
     * 保存附件
     *
     * @param classifyEnum
     * @param examDetail
     * @param basicAttachment
     * @param pdfList
     * @param printCount
     * @param sequence
     * @return
     * @throws IOException
     */
    BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment,
                                      List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;

    void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount,
                               List<File> fileTempList, BasicTemplate basicTemplate);

    void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, Integer printCount, BasicTemplate basicTemplate);

    /**
     * 保存html附件
     *
     * @param fileName
     * @param htmlContent
     * @param userId
     * @param localFileList
     * @param fileTempList
     * @return
     * @throws IOException
     */
    BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList,
                                       List<File> fileTempList) throws IOException;

    BasicAttachment saveAttachmentPdfFromHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList, List<File> fileTempList) throws IOException;

    BasicAttachment saveAttachmentPdfFromHtml(String fileName, File file, Long userId, List<PdfDto> localFileList, List<File> fileTempList, PageSizeEnum pageSizeEnum) throws IOException;
    /**
     * 保存html附件和该html转成pdf的附件
     *
     * @param fileName    文件名称
     * @param htmlContent html内容
     * @param userId      创建人
     * @return 附件对象
     */
    BasicAttachment saveAttachmentHtmlAndPdf(String fileName, String htmlContent, Long userId) throws IOException;

    /**
     * 保存附件公用
     *
     * @param file
     * @param md5
     * @param type
     * @param objId
     * @return
     */
    BasicAttachment saveAttachmentCommon(MultipartFile file, String md5, UploadFileEnum type, Long objId);

    /**
     * 保存附件
     *
     * @param file
     * @param md5
     * @param type
     * @return
     */
    BasicAttachment saveAttachment(MultipartFile file, String md5, UploadFileEnum type);

    /**
     * 科目删除
     *
     * @param id
     * @return
     */
    boolean remove(Long id);

    /**
     * 分页查询
     *
     * @param code
     * @param name
     * @param pageNumber
     * @param pageSize
     * @return
     */
    IPage<BasicCourse> list(String code, String name, Integer pageNumber, Integer pageSize);

    /**
     * 科目查询
     *
     * @param param
     * @param printPlanIdList
     * @param teachingRoomId
     * @return
     */
    List<BasicCourse> list(String param, List<Long> printPlanIdList, Long teachingRoomId);

    /**
     * 机构禁用
     *
     * @param org
     * @return
     */
    boolean enable(SysOrg org);

    /**
     * 机构删除
     *
     * @param id
     * @return
     */
    boolean sysOrgRemove(Long id);

    /**
     * 保存任务
     *
     * @param file
     * @param taskTypeEnum
     * @return
     */
    Map<String, Object> saveTask(MultipartFile file, TaskTypeEnum taskTypeEnum);

    /**
     * 保存任务
     *
     * @param file
     * @param taskTypeEnum
     * @return
     */
    Map<String, Object> saveTask(MultipartFile file, Long examId, TaskTypeEnum taskTypeEnum);

    /**
     * 保存任务
     *
     * @param printPlanId
     * @param file
     * @param taskTypeEnum
     * @return
     */
    Map<String, Object> saveTask(Long printPlanId, MultipartFile file, TaskTypeEnum taskTypeEnum);

    /**
     * 保存任务(导出)
     *
     * @param taskTypeEnum
     * @return
     */
    Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum);

    /**
     * 保存任务
     *
     * @param taskTypeEnum
     * @return
     */
    Map<String, Object> saveTask(Long printPlanId, TaskTypeEnum taskTypeEnum);

    /**
     * 校验课程关联考场是否提交打印
     *
     * @param schoolId
     * @param printPlanId
     * @param examId
     * @param courseCode
     * @param paperNumber
     * @return
     */
    Boolean checkExamDetailStatus(Long schoolId, Long printPlanId, Long examId, String courseCode, String paperNumber);

    /**
     * 生成唯一的试卷编号
     *
     * @param schoolId
     * @return
     */
    String createPaperNumber(Long schoolId, Long examId);

    /**
     * 校验是否可以提交
     *
     * @param schoolId
     * @param courseCode
     * @param paperNumber
     * @param user
     * @throws IOException
     */
    void checkExamDataAndCreatePdfTask(Long schoolId, Long examId, String courseCode, String paperNumber, SysUser user) throws IOException;

    void checkDataMakeup(Long schoolId, ExamDetail examDetail, String courseCode, String paperNumber, SysUser user);

    /**
     * 根据学生集合创建考生考务数据
     *
     * @param examTask                       命题任务
     * @param extendFields                   扩展字段
     * @param examTaskStudentObjectParamList 学生参数集合
     * @param examDetailCourseId             考察表id
     * @param sysUser                        请求用户
     * @return 结果
     */
    List<ExamStudent> createBatchStudentByStudentList(Long examId, ExamTask examTask,
                                                      String extendFields, List<ExamTaskStudentObjectParam> examTaskStudentObjectParamList, Long examDetailCourseId, SysUser sysUser);

    /**
     * 保存任务附件(导出)
     *
     * @param fos
     * @param oss
     * @return
     */
    String saveTaskAttachment(ByteArrayOutputStream fos, boolean oss) throws IOException;

    /**
     * 生成任务序号
     *
     * @param schoolId   学校ID
     * @param courseCode 课程代码
     * @return
     */
    String createCourseSequence(Long schoolId, String courseCode);

    /**
     * 提交初始化数据后更新批次状态
     *
     * @param schoolId    学校ID
     * @param paperNumber 试卷编号
     * @param examId      考试id
     * @param paperType   试卷类型
     */
    public void updateGradeBatchStatus(Long schoolId, Long examId, String paperNumber, String paperType);

    void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> variablePdfList,
                                  Integer printCount, List<File> fileTempList);

    void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, Integer printCount);

    String parseAttachmentPath(String attachmentPath, PrintPathVo printPathVo);

    /**
     * 成绩管理导入excel校验
     *
     * @param file
     * @param examId
     * @param courseCode
     * @param paperNumber
     * @return
     */
    public MarkPaper scoreImportExcelVaild(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException;

    /**
     * 获取阅卷数据
     *
     * @param examId
     * @param courseCode
     * @param paperNumber
     * @return
     */
    public MarkPaper getMarkPaper(Long examId, String courseCode, String paperNumber);

    /**
     * 成绩管理动态生成excel
     *
     * @param describe
     * @param sheetName
     * @param fileName
     * @param excelFieldList
     * @throws IOException
     */
    public void scoreDownLoadExaminationTemplate(String describe, String sheetName, String fileName, List<ExcelField> excelFieldList) throws IOException;

    /**
     * 成绩管理列表
     *
     * @param iPage
     * @param examId
     * @param courseCode
     * @return
     */
    public IPage<ScoreResult> scoreList(IPage<Map> iPage, Long examId, String courseCode);

    /**
     * 获取成绩管理需要的锁
     *
     * @param examId
     * @param courseCode
     * @param paperNumber
     * @param teachCourseId
     */
    public void getLock(Long examId, String courseCode, String paperNumber, Long teachCourseId);
}
