package org.jeecg.modules.stm.wb.config.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.stm.wb.config.entity.WbCheckItem;
import org.jeecg.modules.stm.wb.config.mapper.WbCheckItemMapper;
import org.jeecg.modules.stm.wb.config.service.IWbCheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.jeecg.modules.stm.base.domain.service.IStDomainService;

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

/**
 * @Description: 节点项
 * @Author: jeecg-boot
 * @Date:   2025-06-13
 * @Version: V1.0
 */
@Service
public class WbCheckItemServiceImpl extends ServiceImpl<WbCheckItemMapper, WbCheckItem> implements IWbCheckItemService {

    @Autowired
    private IStDomainService iStDomainService;

    @Override
    public List<WbCheckItem> queryWbCheckItems(Integer checkId){
        List<WbCheckItem> list = this.baseMapper.queryWbCheckItems(checkId);
        return list;
    }

    @Override
    public List<WbCheckItem> queryWbCheckMtrics(Integer checkId){
        List<WbCheckItem> list = this.baseMapper.queryWbCheckMtrics(checkId);
        List<String> listCode = new ArrayList<>();
        for(int i=0;i<list.size();i++){
            listCode.add(list.get(i).getDomainNo());
        }
        Map<String,String> codeNameMap = iStDomainService.getAllParentCode(listCode);
        if(codeNameMap!=null&&codeNameMap.size()>0) {
            for(int i=0;i<list.size();i++) {
                String strDomainCode = list.get(i).getDomainNo();
                if (strDomainCode != null) {
                    String strDomain = codeNameMap.get(strDomainCode);
                    if (strDomain != null && !strDomain.equals("null")) {
                        list.get(i).setDomainName(strDomain);
                    } else {
                        list.get(i).setDomainName("");
                    }
                }
            }
        }

        return list;
    }
}
