/*
 * Copyright (c) 2024 codvision.com All Rights Reserved.
 */

package com.codvision.basic.service.impl.inspection;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codvision.basic.entity.inspection.InspectionInventory;
import com.codvision.basic.entity.vo.inspection.InspectionInventoryVO;
import com.codvision.basic.mapper.inspection.InspectionChecklistMapper;
import com.codvision.basic.mapper.inspection.InspectionInventoryMapper;
import com.codvision.basic.service.inspection.InspectionInventoryService;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.webcore.util.QueryPageUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * @author codvision
 */
@Service
@RequiredArgsConstructor
public class InspectionInventoryServiceImpl extends ServiceImpl<InspectionInventoryMapper, InspectionInventory> implements InspectionInventoryService {

    private final InspectionChecklistMapper checklistMapper;

    @Override
    public IPage<InspectionInventoryVO> getPageResult(QueryPage<Map<String, Object>> queryPage) {
        return getBaseMapper().getPageResult(queryPage.getPage(), QueryPageUtil.queryMap(queryPage));
    }

    @Override
    public List<InspectionInventoryVO> getInspectionClassByTaskId(String keyword, Integer taskId) {
        Map<String, Object> paraMap = new HashMap<>(16);
        if (StringUtils.isNotBlank(keyword)) {
            paraMap.put("keyword", keyword);
        }
        if (null != taskId) {
            paraMap.put("taskId", taskId);
        }

        List<InspectionInventoryVO> list = getBaseMapper().getInspectionInventoryByTaskId(paraMap);
        for (InspectionInventoryVO inspectionClass : list) {
            inspectionClass.setInspectionChecklists(checklistMapper.getByInspectionId(inspectionClass.getId()));
        }

        return list;
    }
}
