package com.tuoheng.admin.service.mission.query;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.ThMission;
import com.tuoheng.admin.entity.request.emergency.QueryMissionListRequest;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.ThMissionMapper;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.system.entity.User;
import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 查询任务列表业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-02-13
 */
@Slf4j
@Service
public class QueryMissionListService {

    @Autowired
    private ThMissionMapper thMissionMapper;

    public JsonResult getList(QueryMissionListRequest request) {
//        log.info("进入查询任务列表业务");
        User user = ShiroUtils.getUserInfo();
        Integer tenantId = user.getTenantId();
        request.setTenantId(tenantId);

        JsonResult result = this.check(tenantId, request);
        if (0 != result.getCode()) {
            log.info("进入查询任务列表业务：校验失败：{}", result.getMsg());
            return result;
        }
        List<ThMission> missionList = thMissionMapper.selectList(new LambdaQueryWrapper<ThMission>()
                .eq(ThMission::getMark, MarkEnum.VALID.getCode())
                .eq(ThMission::getTenantId, tenantId)
                .in(CollectionUtil.isNotEmpty(request.getStatusList()), ThMission::getStatus, request.getStatusList()));

        if (CollectionUtil.isEmpty(missionList)) {
            log.info("任务列表数据为空");
        }
        return JsonResult.success(missionList);
    }

    /**
     * 检查参数
     *
     * @param tenantId
     * @param request
     * @return
     */
    private JsonResult check(Integer tenantId, QueryMissionListRequest request) {
        return JsonResult.success();
    }

}
