package com.bofeng.service;

import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.bofeng.dao.QzTaskDao;
import com.bofeng.dao.QzTaskReplyDao;
import com.bofeng.entity.QzTaskReply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class QzTaskReplyService {

    @Autowired
    private QzTaskReplyDao qzTaskReplyDao;

    @Autowired
    private QzTaskDao qzTaskDao;

    public List<QzTaskReply> taskQuery(Long taskId) {
        return qzTaskReplyDao.taskQuery(taskId);

    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer insertQzTaskReply(QzTaskReply qzTaskReply) {

        qzTaskDao.updateStatusById(qzTaskReply.getTaskId(), 2);

        qzTaskReply.setReplyId(IdWorker.getId());

        return qzTaskReplyDao.insert(qzTaskReply);
    }

    public List<QzTaskReply> queryQzTaskReplyByTaskId(Long taskId) {
        return qzTaskReplyDao.queryQzTaskReplyByTaskId(taskId);
    }

}
