package com.zhgd.xmgl.modules.basicdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.xmgl.modules.basicdata.entity.AiMonitorQuestion;
import com.zhgd.xmgl.modules.basicdata.entity.SystemDictData;
import com.zhgd.xmgl.modules.basicdata.mapper.AiMonitorQuestionMapper;
import com.zhgd.xmgl.modules.basicdata.service.IAiMonitorQuestionService;
import com.zhgd.xmgl.modules.basicdata.service.ISystemDictDataService;
import com.zhgd.xmgl.util.ParamEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: AI预警整改记录
 * @author： pengj
 * @date：   2023-03-04
 * @version： V1.0
 */
@Service
public class AiMonitorQuestionServiceImpl extends ServiceImpl<AiMonitorQuestionMapper, AiMonitorQuestion> implements IAiMonitorQuestionService {

    @Autowired
    private ISystemDictDataService systemDictDataService;

    @Override
    public Integer getCountByStateForEng(String engineeringSn, Integer state) {
        return baseMapper.getCountByStateForEng(engineeringSn, state);
    }

    @Override
    public Integer getCountByStateForPro(String engineeringSn, Integer state) {
        return baseMapper.getCountByStateForPro(engineeringSn, state);
    }

    @Override
    public Page<AiMonitorQuestion> getPageList(Page page, Wrapper<AiMonitorQuestion> wrapper) {
        List<SystemDictData> dictDataList = systemDictDataService.getByType(ParamEnum.SysDictType.AI_ALARM_TYPE.getValue());
        Page<AiMonitorQuestion> pageList = baseMapper.getPageList(page, wrapper);
        pageList.getRecords().stream().forEach(a -> {
            List<SystemDictData> dictData = dictDataList.stream().filter(d -> d.getDictLabel().equals(a.getType().toString()))
                    .collect(Collectors.toList());
            if (dictData.size() > 0) {
                a.setTypeName(dictData.get(0).getDictValue());
            }
        });
        return pageList;
    }
}
