package org.jeecg.modules.itdmFirstPage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.jeecg.modules.itdmFirstPage.entity.ItdmTask;
import org.jeecg.modules.itdmFirstPage.mapper.ItdmTaskMapper;
import org.jeecg.modules.itdmFirstPage.service.IItdmTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 任务表
 * @Author: jeecg-boot
 * @Date:   2023-06-03
 * @Version: V1.0
 */
@Service
public class ItdmTaskServiceImpl extends ServiceImpl<ItdmTaskMapper, ItdmTask> implements IItdmTaskService {
    @Autowired
    @SuppressWarnings("all")
    private ItdmTaskMapper taskMapper;

    public boolean insertTaskAfterJudge(ItdmTask task) {
        if(task.getTaskUser()!=null){
            ItdmTask queryTask = new ItdmTask();
            queryTask.setTaskRole(task.getTaskRole());
            queryTask.setTaskUser(task.getTaskUser());
            queryTask.setTaskContent(task.getTaskContent());
            queryTask.setWeituoId(task.getTaskContent());
            QueryWrapper<ItdmTask> taskQueryWrapper = new QueryWrapper<>(task);
            List<ItdmTask> list = taskMapper.selectList(taskQueryWrapper);
            if(list.isEmpty()){
                task.setTaskStatus(0);
                return SqlHelper.retBool(this.getBaseMapper().insert(task));
            }else return false;
        }else return true;
    }
}
