#include "TaskService.h"

#include "utils/ProMemory.h"

TaskService::TaskService()
{

}

QList<TaskDTO> TaskService::getDeptTaskListPage(TaskRequest request, Page &page)
{
    TaskDao taskDao;
    SystemDao systemDao;

    // 根据计量人员userId查询所在部门deptId
    QString deptId = systemDao.getStaffDeptIdByUserId(request.userId);
    request.deptId = deptId;
    request.userId = ""; // 查询部门任务时不需要userId

    QList<TaskDTO> deptTaskList = taskDao.getTaskListPage(request, page);

    // 获取字典值
    systemDao.getTaskMeasureStatusDict();

    // 为其他字典值填充名称
    for (TaskDTO &task : deptTaskList) {
        wrapperTaskDTO(task);
    }

    return deptTaskList;
}

QList<TaskDTO> TaskService::getUserTaskToBeDoneListPage(TaskRequest request, Page &page)
{
    TaskDao taskDao;
    SystemDao systemDao;

    QList<TaskDTO> taskList = taskDao.getTaskListPage(request, page);

    // 获取字典值
    systemDao.getTaskMeasureStatusDict();

    // 为其他字典值填充名称
    for (TaskDTO &task : taskList) {
        wrapperTaskDTO(task);
    }

    return taskList;
}

QStringList TaskService::getVerificationItemCatsBySelectedTask(QStringList taskIds)
{
    CheckDao checkDao;
    return checkDao.getSelectedTaskMeasureItemCategory(taskIds);
}


void TaskService::wrapperTaskDTO(TaskDTO &task)
{
    task.isUrgentName = task.isUrgent == "1" ? "是" : "否";
    task.measureStatusName = ProMemory::getInstance().getMeasureStatusDict().value(QString("measureStatus-%1").arg(task.measureStatus));
}
