package com.cool.store.dao;

import com.cool.store.entity.LineFollowLogDO;
import com.cool.store.entity.LineInfoDO;
import com.cool.store.mapper.LineFollowLogMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

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

/**
 * @author zhangchenbiao
 * @FileName: LineFollowLogDAO
 * @Description:跟进日志
 * @date 2024-03-27 14:33
 */
@Slf4j
@Repository
public class LineFollowLogDAO {

    @Resource
    private LineFollowLogMapper lineFollowLogMapper;

    public Page<LineFollowLogDO> getFollowLogPage(Long lineId, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return lineFollowLogMapper.getFollowLogPage(lineId);
    }

    /**
     * 新增跟进线索
     * @param lineInfo
     * @param operateUserId
     * @param operateUsername
     * @param message
     * @return
     */
    public Long addFollowLog(LineInfoDO lineInfo, String operateUserId, String operateUsername, String message){
        if(Objects.isNull(lineInfo)){
            return null;
        }
        LineFollowLogDO followLog = new LineFollowLogDO(lineInfo.getPartnerId(), lineInfo.getId(), operateUserId, operateUsername, lineInfo.getWorkflowStage(), lineInfo.getWorkflowSubStage(), lineInfo.getWorkflowSubStageStatus(), message);
        lineFollowLogMapper.insertSelective(followLog);
        return followLog.getId();
    }

}
