/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.watermeter.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.watermeter.entity.File;
import com.tofly.watermeter.entity.Watermeter;
import com.tofly.watermeter.mapper.WatermeterMapper;
import com.tofly.watermeter.service.FileService;
import com.tofly.watermeter.service.WatermeterService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

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

/**
 * 水表信息采集数据表：TF_YWPN _WATERMETER_W
 *
 * @author admin
 * @date Wed Mar 10 00:00:00 CST 2021
 */
@Service("watermeterService")
@AllArgsConstructor
public class WatermeterServiceImpl extends ServiceImpl<WatermeterMapper, Watermeter> implements WatermeterService {

    private final WatermeterMapper watermeterMapper;
    private final FileService fileService;

    @Override
    public List<Map<String, Object>> getWaterInfo(String sid) {
        List<Map<String, Object>> waterInfo = watermeterMapper.getWaterInfo(sid);
        if (waterInfo != null && !waterInfo.isEmpty()) {
            for (Map<String, Object> map : waterInfo) {
                Object fileIds = map.get("fileIds");
                List<String> fileList = null;
                if (!StringUtils.isEmpty(fileIds)) {
                    fileList = fileService.list(Wrappers.<File>lambdaQuery()
                            .select(File::getFilePath)
                            .in(File::getId, Arrays.asList(fileIds.toString().split(","))))
                            .stream().map(File::getFilePath)
                            .collect(Collectors.toList());
                }
                map.put("filePath", fileList);
            }
        }
        return waterInfo;
    }
}
