package com.bofeng.service;

import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.bofeng.dao.QzTaskDao;
import com.bofeng.entity.QzTask;
import lombok.var;
import org.joda.time.DateTime;
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 QzTaskService {

    @Autowired
    private QzTaskDao qzTaskDao;

    public List<QzTask> selectAll () {
        return qzTaskDao.selectAll();
    }

    public List<QzTask> queryByHouseNumber (String houseNumber, Integer status) {
        return qzTaskDao.queryByHouseNumber(houseNumber, status);
    }

    public QzTask queryByTaskId (Long taskId) {
        return qzTaskDao.queryByTaskId(taskId);
    }

  //求助的新增
  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  public int addHelp(String taskTitle,String taskTarget,String remark) {
    var qzTak=new QzTask();
    qzTak.setTaskId(IdWorker.getId());
    qzTak.setTaskTitle(taskTitle);
    qzTak.setRemark(remark);
    qzTak.setTaskTarget(taskTarget);
    qzTak.setTaskStatus(1);

    /*long userId = Long.parseLong(JwtHelper.getUserId());
    qzTak.setUserId(userId);
    qzTak.setUserCreate(userId);*/
    qzTak.setTimeCreate(new DateTime());
   /* qzTak.setUserUpdate(userId);*/
    qzTak.setTimeUpdate(new DateTime());
    return qzTaskDao.insert(qzTak);
  }



  public List<QzTask> queryQzTask(){
    return qzTaskDao.queryQzTask();
  }
}
