package com.zehong.system.service.impl;

import java.util.List;

import com.zehong.common.core.domain.entity.SysDictData;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TPipeMapper;
import com.zehong.system.domain.TPipe;
import com.zehong.system.service.ITPipeService;

/**
 * 管道信息Service业务层处理
 * 
 * @author zehong
 * @date 2021-07-08
 */
@Service
public class TPipeServiceImpl implements ITPipeService 
{
    @Autowired
    private TPipeMapper tPipeMapper;
    @Autowired
    private ISysDictTypeService iSysDictTypeService;

    /**
     * 查询管道信息
     * 
     * @param pipeId 管道信息ID
     * @return 管道信息
     */
    @Override
    public TPipe selectTPipeById(int pipeId)
    {
        TPipe tPipe = tPipeMapper.selectTPipeById(pipeId);
        if (StringUtils.isNotEmpty(tPipe.getPipeType())) {
            List<SysDictData> sysDictDataList = iSysDictTypeService.selectDictDataByType("t_pipe_type");
            for (SysDictData sysDictData : sysDictDataList) {
                if (tPipe.getPipeType().equals(sysDictData.getDictValue())) {
                    tPipe.setPipeType(sysDictData.getDictLabel());
                }
            }
        }
        if (StringUtils.isNotEmpty(tPipe.getPipePressure())) {
            List<SysDictData> sysDictDataList = iSysDictTypeService.selectDictDataByType("t_pipe_pressure");
            for (SysDictData sysDictData : sysDictDataList) {
                if (tPipe.getPipePressure().equals(sysDictData.getDictValue())) {
                    tPipe.setPipePressure(sysDictData.getDictLabel());
                }
            }
        }
        return tPipe;
    }

    /**
     * 查询管道信息列表
     * 
     * @param tPipe 管道信息
     * @return 管道信息
     */
    @Override
    public List<TPipe> selectTPipeList(TPipe tPipe)
    {
        List<TPipe> tPipeList = tPipeMapper.selectTPipeList(tPipe);

        if(tPipeList.size() != 0){

            for(TPipe pipe : tPipeList){

                if (StringUtils.isNotEmpty(pipe.getPipeType())) {
                    List<SysDictData> sysDictDataList = iSysDictTypeService.selectDictDataByType("t_pipe_type");
                    for (SysDictData sysDictData : sysDictDataList) {
                        if (pipe.getPipeType().equals(sysDictData.getDictValue())) {
                            pipe.setPipeType(sysDictData.getDictLabel());
                        }
                    }
                }
                if (StringUtils.isNotEmpty(pipe.getPipePressure())) {
                    List<SysDictData> sysDictDataList = iSysDictTypeService.selectDictDataByType("t_pipe_pressure");
                    for (SysDictData sysDictData : sysDictDataList) {
                        if (pipe.getPipePressure().equals(sysDictData.getDictValue())) {
                            pipe.setPipePressure(sysDictData.getDictLabel());
                        }
                    }
                }

            }
        }

        return tPipeList;
    }

    /**
     * 统计管道总长度
     * @return
     */
    @Override
    public double countPipeLength() {
        return tPipeMapper.countPipeLength();
    };

    /**
     * 新增管道信息
     * 
     * @param tPipe 管道信息
     * @return 结果
     */
    @Override
    public int insertTPipe(TPipe tPipe)
    {
        return tPipeMapper.insertTPipe(tPipe);
    }

    /**
     * 修改管道信息
     * 
     * @param tPipe 管道信息
     * @return 结果
     */
    @Override
    public int updateTPipe(TPipe tPipe)
    {
        return tPipeMapper.updateTPipe(tPipe);
    }

    /**
     * 批量删除管道信息
     * 
     * @param pipeIds 需要删除的管道信息ID
     * @return 结果
     */
    @Override
    public int deleteTPipeByIds(int[] pipeIds)
    {
        return tPipeMapper.deleteTPipeByIds(pipeIds);
    }

    /**
     * 删除管道信息信息
     * 
     * @param pipeId 管道信息ID
     * @return 结果
     */
    @Override
    public int deleteTPipeById(int pipeId)
    {
        return tPipeMapper.deleteTPipeById(pipeId);
    }
}
