package com.cool.store.dao;

import com.cool.store.enums.WorkflowStatusEnum;
import com.cool.store.mapper.HyPartnerInterviewMapper;
import com.cool.store.mapper.HyPartnerLineInfoMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Repository
public class HyInterviewDAO {

    @Resource
    private HyPartnerInterviewMapper interviewMapper;

    @Resource
    private HyPartnerLineInfoMapper lineInfoMapper;

    /**
     * 更新面试状态必须使用该方法
     * 需要同步更新面试状态和线索表中的子流程状态
     */
    @Transactional
    public void updateInterviewWorkflowStatus(String interviewPlanId, WorkflowStatusEnum status) {
        //修改面试状态
        interviewMapper.updateInterviewStatus(interviewPlanId, status.getCode());
        //获取对应的lineId
        String lineId = interviewMapper.getLineId(interviewPlanId);
        //修改线索表子流程状态
        lineInfoMapper.updateWorkflowStatus(lineId, status.getCode());
    }

    /**
     * 根据线索id批量修改面试状态和线索表子流程状态
     * @param lineIds
     * @param status
     */
    @Transactional
    public void batchUpdateInterviewWorkflowStatus(List<Long> lineIds, Integer status){
        //修改面试状态
        interviewMapper.batchUpdateStatusByLineIds(lineIds, status);
        //修改线索表子流程状态
        lineInfoMapper.batchUpdateStatusByLineIds(lineIds, status);

    }

    public  int updateLineId(String newPartnerId,Long newLineId,Long oldLineId){
        if (newLineId==null || Objects.isNull(oldLineId)){
            return 0;
        }
        return interviewMapper.updateLineId(newPartnerId,newLineId, oldLineId);
    }

}
