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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.xmgl.modules.basicdata.dto.EngineeringDeviceDto;
import com.zhgd.xmgl.modules.basicdata.entity.EnvironmentDev;
import com.zhgd.xmgl.modules.basicdata.mapper.EnvironmentDevMapper;
import com.zhgd.xmgl.modules.basicdata.service.IEngineeringService;
import com.zhgd.xmgl.modules.basicdata.service.IEnvironmentDevService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Description: 扬尘设备管理
 * @author： pds
 * @date：   2023-03-01
 * @version： V1.0
 */
@Service
public class EnvironmentDevServiceImpl extends ServiceImpl<EnvironmentDevMapper, EnvironmentDev> implements IEnvironmentDevService {

    @Autowired
    private IEngineeringService engineeringService;

    @Override
    public Page<EnvironmentDev> pageList(Page page, Wrapper<EnvironmentDev> wrapper) {
        return baseMapper.pageList(page, wrapper);
    }

    @Override
    public Page<EngineeringDeviceDto> pageListByGov(Map<String, Object> map) {
        Page<EngineeringDeviceDto> pageListByGov = engineeringService.pageListForGov(map);
        pageListByGov.getRecords().stream().forEach(e -> {
            e.setDeviceNum(baseMapper.selectCount(Wrappers.<EnvironmentDev>lambdaQuery().eq(EnvironmentDev::getEngineeringSn, e.getEngineeringSn())));
        });
        return pageListByGov;
    }
}
