package com.qmth.sop.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qmth.sop.business.bean.params.*;
import com.qmth.sop.business.bean.result.FlowResult;
import com.qmth.sop.business.bean.result.FlowTaskResult;
import com.qmth.sop.business.bean.result.SopInfoResult;
import com.qmth.sop.business.entity.*;
import com.qmth.sop.common.enums.FlowApprovePassEnum;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * sop表 服务类
 * </p>
 *
 * @author wangliang
 * @since 2023-08-01
 */
public interface TBSopInfoService extends IService<TBSopInfo> {

    /**
     * 查询动态sop表名是否存在
     *
     * @param db
     * @param tableName
     * @return
     */
    int selectSopDynamicExist(String db, String tableName);

    /**
     * 保存动态sop信息
     *
     * @param tfCustomFlow
     * @param code
     * @param flowId
     * @param flowTaskResult
     * @return
     */
    Boolean saveDynamicSop(TFCustomFlow tfCustomFlow, String code, Long flowId, FlowTaskResult flowTaskResult);

    /**
     * 查询动态sop数据
     *
     * @param tableName
     * @param flowDeploymentId
     * @param flowId
     * @return
     */
    int selectDynamicSop(String tableName, String flowDeploymentId, Long flowId);

    /**
     * sop发布信息
     *
     * @param sopPublishParam
     * @return
     */
    Boolean sopPublish(SopPublishParam sopPublishParam) throws InterruptedException;

    /**
     * sop申请信息
     *
     * @param sopApplyParam
     * @return
     */
    Boolean sopApply(SopApplyParam sopApplyParam) throws InterruptedException;

    /**
     * sop填报信息
     *
     * @param flowApproveParam
     * @return
     */
    Boolean sopApprove(FlowApproveParam flowApproveParam) throws InterruptedException;

    /**
     * sop管理列表
     *
     * @param sopInfoListParam
     * @return
     */
    IPage<Map> list(SopInfoListParam sopInfoListParam);

    /**
     * sop申请或发布
     *
     * @param sopNo
     * @param crmNo
     * @param flowDeploymentId
     * @param approve
     * @param formProperties
     * @return
     * @throws InterruptedException
     */
    public Boolean sopApplyOrPublish(String sopNo, String crmNo, String flowDeploymentId, FlowApprovePassEnum approve,
            String formProperties) throws InterruptedException;

    /**
     * 根据crmNo查询在途的sop信息
     *
     * @param crmNo
     * @return
     */
    List<String> findFlowPassageByCrmNo(String crmNo, Long requestUserId);

    /**
     * 根据serviceId和userId查询所有sop信息
     *
     * @param serviceId
     * @return
     */
    List<SopInfoResult> findFlowByServiceId(Long serviceId, Long userId);

    /**
     * sop自动审批
     *
     * @param tfCustomFlow
     * @param tfCustomFlowEntity
     * @param tfFlowApprove
     * @param tbSopInfoDetail
     * @param crmNo
     */
    public void sopSystemApprove(TFCustomFlow tfCustomFlow, TFCustomFlowEntity tfCustomFlowEntity,
            TFFlowApprove tfFlowApprove, TBSopInfoDetail tbSopInfoDetail, String crmNo) throws InterruptedException;

    /**
     * 保存提醒/延时任务
     *
     * @param map
     */
    public void saveJobRemind(Map<String, Object> map) throws InterruptedException;

    /**
     * 更新sop计划进场开始时间和结束时间
     *
     * @param flowTaskResult
     * @param sopId
     * @param flowId
     * @param userId
     * @throws InterruptedException
     */
    public void saveSopPlanDate(FlowTaskResult flowTaskResult, Long sopId, Long flowId, Long userId)
            throws InterruptedException;

    /**
     * sop保存设备信息
     *
     * @param map
     * @param setup
     * @throws InterruptedException
     */
    public void sopDeviceInOutSave(Map<String, Object> map, Integer setup) throws InterruptedException;

    /**
     * sop编辑
     *
     * @param id
     * @return
     */
    public FlowResult sopEdit(Long id) throws InterruptedException;

    /**
     * sop保存
     *
     * @param sopSaveParam
     * @return
     */
    public Boolean sopSave(SopSaveParam sopSaveParam) throws InterruptedException;

    List<SysUser> userList(Long id);

    /**
     * 根据服务单元查找在途的区域协调人、实施工程师、助理工程师
     *
     * @param serviceId
     * @return
     */
    List<Map<String, Object>> findSopPassage(Long serviceId);

    /**
     * 获取表单内容
     *
     * @param tfCustomFlowEntity
     * @param setup
     * @return
     */
    public FlowTaskResult getFormProperties(TFCustomFlowEntity tfCustomFlowEntity, Integer setup);
}
