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

import com.tuoheng.admin.entity.Accident;
import com.tuoheng.admin.mapper.AccidentMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.request.accident.QueryAccidentListRequest;
import com.tuoheng.admin.service.accident.build.BuildAccidentVoListService;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.accident.AccidentVo;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 查询事故卡片列表业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-03-03
 */
@Slf4j
@Service
public class QueryAccidentListService {


    @Autowired
    private UserMapper userMapper;

    @Autowired
    private AccidentMapper accidentMapper;

    @Autowired
    private BuildAccidentVoListService buildAccidentVoListService;

    public JsonResult getList(QueryAccidentListRequest request) {
//        log.info("进入查询应急事件列表业务");
        String tenantId = CurrentUserUtil.getTenantId();
        JsonResult result = this.check(tenantId, request);
        if (0 != result.getCode()) {
            log.info("进入查询事故卡片列表业务：校验失败：{}", result.getMsg());
            return result;
        }

        List<Integer> sourceList = new ArrayList<>();
        sourceList.add(1);
        sourceList.add(3);
        request.setSourceList(sourceList);
        request.setTenantId(tenantId);
        List<Accident> accidentList = accidentMapper.selectAccidentList(request);

        // 构造返回结果对象
        List<AccidentVo> accidentVoList = buildAccidentVoListService.build(accidentList);

        return JsonResult.success(accidentVoList);
    }

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

}
