package com.backendsys.service.Ali;

import com.backendsys.aspect.HttpRequestAspect;
import com.backendsys.entity.Ali.AliDashscopeTaskDTO;
import com.backendsys.mapper.Ali.AliDashscopeTaskMapper;
import com.backendsys.utils.response.PageInfoResult;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AliDashscopeTaskServiceImpl implements AliDashscopeTaskService {

    @Autowired
    private HttpRequestAspect httpRequestAspect;

    @Autowired
    private AliDashscopeTaskMapper aliDashscopeTaskMapper;

    @Autowired
    private AliDashscopeService aliDashscopeService;

    @Override
    public Map<String, Object> getTaskList(Integer pageNum, Integer pageSize, AliDashscopeTaskDTO aliDashscopeTaskDTO) {
        // [查询] 自身 UserId (并加入)
        Long user_id = httpRequestAspect.getUserId();
        aliDashscopeTaskDTO.setUser_id(user_id);

        // 分页查询
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
            PageHelper.getLocalPage().setPageSizeZero(true);
        }
        // 分页输出 (自定义)
        List<Map<String, Object>> list = aliDashscopeTaskMapper.queryDashscopeTaskList(aliDashscopeTaskDTO);
        PageInfoResult pageInfoResult = new PageInfoResult(list);
        return pageInfoResult.toMap();
    }

    @Override
    public Map<String, Object> getTaskDetail(AliDashscopeTaskDTO aliDashscopeTaskDTO) {

        // [查询] 自身 UserId (并加入)
        Long user_id = httpRequestAspect.getUserId();
        aliDashscopeTaskDTO.setUser_id(user_id);

        Map<String, Object> resp = aliDashscopeService.getTaskById(aliDashscopeTaskDTO.getTask_id());

        return aliDashscopeTaskMapper.queryDashscopeTaskDetail(aliDashscopeTaskDTO);
    }
}
