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.params.SerialNumberParams;
import com.qmth.distributed.print.business.entity.ExamDetail;
import com.qmth.distributed.print.business.entity.ExamStudent;
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.PushTypeEnum;
import com.qmth.teachcloud.common.enums.TaskTypeEnum;
import com.qmth.teachcloud.common.enums.UploadFileEnum;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.multipart.MultipartFile;

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

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

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

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

    /**
     * 保存html附件和该html转成pdf的附件
     *
     * @param fileName    文件名称
     * @param htmlContent html内容
     * @param userId      创建人
     * @return 附件对象
     */
    public BasicAttachment saveAttachmentHtmlAndPdf(String fileName, String htmlContent, Long userId) throws IOException;

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

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

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

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

    /**
     * 保存科目
     *
     * @param course
     * @param userId
     * @return
     */
    boolean saveCourse(BasicCourse course, Long userId);

    /**
     * 分页查询
     *
     * @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);

    /**
     * 更新任务状态
     */
    @Async
    public void updateStatus() throws IOException;

    /**
     * 重新生成pdf失败任务
     *
     * @throws IOException
     */
    public void resetCreatePdfTask() throws IOException;


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

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

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

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

    /**
     * 保存推送
     *
     * @param pushTypeEnum 推送类型
     * @return 结果
     */
    Map<String, Object> savePush(PushTypeEnum pushTypeEnum);

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

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

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

    /**
     * 保存考务数据
     *
     * @param schoolId
     * @param extendFields
     * @param classIds
     * @param examDetailCourseId
     * @param sysUser
     */
    public List<ExamStudent> createBatchStudent(Long schoolId, String extendFields, List<String> classIds, Long examDetailCourseId, SysUser sysUser);

    /**
     * 生成准考证号
     *
     * @param serialNumberParams
     * @return
     */
    public String createTempNumber(SerialNumberParams serialNumberParams);

    /**
     * 保存任务附件(导出)
     *
     * @param fos
     * @param oss
     * @return
     */
    public 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 paperType   试卷类型
     */
    public void updateGradeBatchStatus(Long schoolId, String paperNumber, String paperType);
}
