package com.huigou.topsun.base.task.impl;

import com.huigou.context.Operator;
import com.huigou.context.ThreadLocalUtil;
import com.huigou.data.query.model.QueryDescriptor;
import com.huigou.topsun.base.task.BaseTask;
import com.huigou.uasp.bmp.common.application.BaseApplication;
import com.huigou.uasp.bmp.operator.OperatorApplication;
import com.huigou.uasp.bpm.engine.application.WorkflowApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xin.lu
 * @Description: TODO
 * @date 2025/3/2811:17
 */
@Service("baseTask")
public class BaseTaskImpl extends BaseApplication implements BaseTask {
    @Autowired
    private OperatorApplication operatorApplication;
    @Autowired
    private WorkflowApplication workflowService;

    @Override
    public String queryTaskByBizId(String bizId) {
        QueryDescriptor queryDescriptor = this.sqlExecutorDao.getQuery(QUERY_TASK_XML_FILE_PATH, "queryTaskByBizId");
        String sql = queryDescriptor.getSql();
        String taskId = this.sqlExecutorDao.queryToString(sql, bizId);
        return taskId;
    }

    @Override
    public void makeACopyFor(String bizId, String personMemberId, List<String> executorIds, String title) {
        String taskId = this.queryTaskByBizId(bizId);
        Operator operator = operatorApplication.createOperatorByPersonMemberId(personMemberId);
        ThreadLocalUtil.putOperator(operator);
        this.workflowService.makeACopyFor(taskId, executorIds,title);
    }

    @Override
    public List<String> queryHandlersByBizId(String bizId) {
        QueryDescriptor queryDescriptor = this.sqlExecutorDao.getQuery(QUERY_TASK_XML_FILE_PATH, "queryHandlersByBizId");
        String sql = queryDescriptor.getSql();
        return this.sqlExecutorDao.queryToList(sql, String.class, bizId);
    }
}
