TDeviceInfoServiceImpl.java 6.82 KB
Newer Older
1 2
package com.zehong.system.service.impl;

3
import java.util.*;
4

5
import com.zehong.system.domain.TPipe;
6
import com.zehong.system.mapper.TPipeMapper;
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TDeviceInfoMapper;
import com.zehong.system.domain.TDeviceInfo;
import com.zehong.system.service.ITDeviceInfoService;

/**
 * 设备信息Service业务层处理
 * 
 * @author zehong
 * @date 2021-07-09
 */
@Service
public class TDeviceInfoServiceImpl implements ITDeviceInfoService 
{
    @Autowired
    private TDeviceInfoMapper tDeviceInfoMapper;
24 25
    @Autowired
    private TPipeMapper tPipeMapper;
26 27 28 29 30 31 32 33

    /**
     * 查询设备信息
     * 
     * @param deviceId 设备信息ID
     * @return 设备信息
     */
    @Override
34
    public TDeviceInfo selectTDeviceInfoById(int deviceId)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    {
        return tDeviceInfoMapper.selectTDeviceInfoById(deviceId);
    }

    /**
     * 查询设备信息列表
     * 
     * @param tDeviceInfo 设备信息
     * @return 设备信息
     */
    @Override
    public List<TDeviceInfo> selectTDeviceInfoList(TDeviceInfo tDeviceInfo)
    {
        return tDeviceInfoMapper.selectTDeviceInfoList(tDeviceInfo);
    }

51 52 53
    /**
     * 构建前端所需要下拉树结构
     *
54
     * @param param 参数集合
55 56 57
     * @return 下拉树结构列表
     */
    @Override
58
    public List<Map<Object, Object>> buildDeviceTreeSelect(Map<Object, List> param)
59 60
    {
        List<Map<Object, Object>> list = new ArrayList<>();
61 62
        List<Map<Object, Object>> deviceList = param.get("key1");
        List<Map<Object, Object>> pipeList = param.get("key2");
63

64 65 66 67 68 69 70 71
        if(deviceList.size() != 0) {
            for (Map<Object, Object> temp : deviceList) {
                Map<Object, Object> map = new HashMap<>();
                map.put("id", temp.get("deviceId"));
                map.put("label", temp.get("deviceName"));
                list.add(map);
            }
        }
72

73 74 75 76 77 78 79
        if(pipeList.size() != 0){
            for(Map<Object, Object> temp : pipeList){
                Map<Object, Object> map = new HashMap<>();
                map.put("id", temp.get("pipeId"));
                map.put("label", temp.get("pipeName"));
                list.add(map);
            }
80 81 82 83 84
        }

        return list;
    }

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    /**
     * 设备树
     *
     * @param
     * @return 树结构列表
     */
    @Override
    public List<Map<Object, Object>> buildDeviceTree() throws Exception
    {
        List<TPipe> pipeList = tPipeMapper.selectTPipeList(new TPipe());
        List<TDeviceInfo> deviceList = tDeviceInfoMapper.selectTDeviceInfoList(new TDeviceInfo());

        List<Map<Object, Object>> treeNodeList = new ArrayList<>();

        if(pipeList.size() != 0){
            List<Map<Object, Object>> childNodeList = new ArrayList<>();

            for(TPipe pipe : pipeList){
                Map<Object, Object> map = new HashMap<>();
                map.put("id", pipe.getPipeId());
                map.put("level", 2);
                map.put("name", pipe.getPipeName());
                childNodeList.add(map);
            }

            Map<Object, Object> treeNode = new HashMap<>();
            treeNode.put("id", 0);
            treeNode.put("level", 1);
            treeNode.put("name", "管道");
            treeNode.put("childList", childNodeList);

            treeNodeList.add(treeNode);
        }

        if(deviceList.size() != 0) {
            List<Map<Object, Object>> childNodeList1 = new ArrayList<>();
            List<Map<Object, Object>> childNodeList2 = new ArrayList<>();
            List<Map<Object, Object>> childNodeList3 = new ArrayList<>();
            List<Map<Object, Object>> childNodeList4 = new ArrayList<>();

            for (TDeviceInfo device : deviceList) {

                Map<Object, Object> childNode = new HashMap<>();
                childNode.put("id", device.getDeviceId());
                childNode.put("level", 2);
                childNode.put("name", device.getDeviceName());

                if("1".equals(device.getDeviceType())) {
                    childNodeList1.add(childNode);
                } else if ("2".equals(device.getDeviceType())) {
                    childNodeList2.add(childNode);
                } else if ("3".equals(device.getDeviceType())) {
                    childNodeList3.add(childNode);
                } else if ("4".equals(device.getDeviceType())){
                    childNodeList4.add(childNode);
                }
            }

            Map<Object, Object> treeNode1 = new HashMap<>();
            treeNode1.put("id", 1);
            treeNode1.put("level", 1);
            treeNode1.put("name", "调压阀");
            treeNode1.put("childList", childNodeList1);
            Map<Object, Object> treeNode2 = new HashMap<>();
            treeNode2.put("id", 2);
            treeNode2.put("level", 1);
            treeNode2.put("name", "阀门井");
            treeNode2.put("childList", childNodeList2);
            Map<Object, Object> treeNode3 = new HashMap<>();
            treeNode3.put("id", 3);
            treeNode3.put("level", 1);
            treeNode3.put("name", "流量计");
            treeNode3.put("childList", childNodeList3);
            Map<Object, Object> treeNode4 = new HashMap<>();
            treeNode4.put("id", 4);
            treeNode4.put("level", 1);
            treeNode4.put("name", "压力表");
            treeNode4.put("childList", childNodeList4);

            treeNodeList.add(treeNode1);
            treeNodeList.add(treeNode2);
            treeNodeList.add(treeNode3);
            treeNodeList.add(treeNode4);
        }

        return treeNodeList;
    }

173 174 175 176 177 178 179 180
    /**
     * 统计各设备类型的设备总数
     * @return
     */
    public List<Map<Object, Object>> countDeviceByType(){
        return tDeviceInfoMapper.countDeviceByType();
    };

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    /**
     * 新增设备信息
     * 
     * @param tDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int insertTDeviceInfo(TDeviceInfo tDeviceInfo)
    {
        return tDeviceInfoMapper.insertTDeviceInfo(tDeviceInfo);
    }

    /**
     * 修改设备信息
     * 
     * @param tDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int updateTDeviceInfo(TDeviceInfo tDeviceInfo)
    {
        return tDeviceInfoMapper.updateTDeviceInfo(tDeviceInfo);
    }

    /**
     * 批量删除设备信息
     * 
     * @param deviceIds 需要删除的设备信息ID
     * @return 结果
     */
    @Override
212
    public int deleteTDeviceInfoByIds(int[] deviceIds)
213 214 215 216 217 218 219 220 221 222 223
    {
        return tDeviceInfoMapper.deleteTDeviceInfoByIds(deviceIds);
    }

    /**
     * 删除设备信息信息
     * 
     * @param deviceId 设备信息ID
     * @return 结果
     */
    @Override
224
    public int deleteTDeviceInfoById(int deviceId)
225 226 227 228
    {
        return tDeviceInfoMapper.deleteTDeviceInfoById(deviceId);
    }
}