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

jianqian's avatar
jianqian committed
3
import com.alibaba.fastjson.JSONObject;
4 5
import com.github.pagehelper.PageInfo;
import com.zehong.common.utils.PageInfoUtil;
6
import com.zehong.system.domain.EquipmentForm;
耿迪迪's avatar
耿迪迪 committed
7
import com.zehong.system.domain.TDeviceInfo;
8
import com.zehong.system.domain.TDeviceInformation;
9
import com.zehong.system.domain.TPipe;
王晓倩's avatar
王晓倩 committed
10
import com.zehong.system.domain.vo.DeviceInfoVo;
耿迪迪's avatar
耿迪迪 committed
11
import com.zehong.system.mapper.TDeviceInfoMapper;
12
import com.zehong.system.mapper.TPipeMapper;
耿迪迪's avatar
耿迪迪 committed
13
import com.zehong.system.service.ITDeviceInfoService;
王晓倩's avatar
王晓倩 committed
14
import org.springframework.beans.BeanUtils;
15 16
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
耿迪迪's avatar
耿迪迪 committed
17

18
import java.util.*;
19 20 21

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

    /**
     * 查询设备信息
耿迪迪's avatar
耿迪迪 committed
36
     *
37 38 39 40
     * @param deviceId 设备信息ID
     * @return 设备信息
     */
    @Override
耿迪迪's avatar
耿迪迪 committed
41
    public DeviceInfoVo selectTDeviceInfoById(int deviceId)
42
    {
耿迪迪's avatar
耿迪迪 committed
43 44 45 46
        DeviceInfoVo deviceInfoVo = new DeviceInfoVo();
        TDeviceInfo tDeviceInfo = tDeviceInfoMapper.selectTDeviceInfoById(deviceId);
        BeanUtils.copyProperties(tDeviceInfo, deviceInfoVo);

47 48
        TPipe pipe = tPipeMapper.selectTPipeById(tDeviceInfo.getPipeId());
        deviceInfoVo.setPipeName(pipe.getPipeName());
耿迪迪's avatar
耿迪迪 committed
49 50

        return deviceInfoVo;
51 52 53 54
    }

    /**
     * 查询设备信息列表
耿迪迪's avatar
耿迪迪 committed
55
     *
56 57 58 59
     * @param tDeviceInfo 设备信息
     * @return 设备信息
     */
    @Override
王晓倩's avatar
王晓倩 committed
60
    public List<DeviceInfoVo> selectTDeviceInfoList(TDeviceInfo tDeviceInfo)
61
    {
王晓倩's avatar
王晓倩 committed
62 63 64 65 66 67
        List<DeviceInfoVo> list = new ArrayList<>();
        List<TDeviceInfo> deviceInfoList = tDeviceInfoMapper.selectTDeviceInfoList(tDeviceInfo);

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

            for(TDeviceInfo device : deviceInfoList){
王晓倩's avatar
王晓倩 committed
68
                DeviceInfoVo deviceInfoVo = new DeviceInfoVo();
王晓倩's avatar
王晓倩 committed
69 70 71 72 73 74 75 76 77 78
                BeanUtils.copyProperties(device, deviceInfoVo);

                TPipe pipe = tPipeMapper.selectTPipeById(device.getPipeId());
                deviceInfoVo.setPipeName(pipe.getPipeName());

                list.add(deviceInfoVo);
            }
        }

        return list;
79 80
    }

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    /**
     * 查询设备信息列表
     *
     * @param tDeviceInfo 设备信息
     * @return 设备信息
     */
    @Override
    public PageInfo<DeviceInfoVo> selectTDeviceInfoPage(TDeviceInfo tDeviceInfo)
    {
        List<TDeviceInfo> deviceInfoList = tDeviceInfoMapper.selectTDeviceInfoList(tDeviceInfo);
        PageInfo<DeviceInfoVo> pageVo = PageInfoUtil.pageInfo2PageInfoDTO(new PageInfo(deviceInfoList),DeviceInfoVo.class);
        if(pageVo.getList().size() != 0){
            for(DeviceInfoVo device : pageVo.getList()){

                TPipe pipe = tPipeMapper.selectTPipeById(device.getPipeId());
                device.setPipeName(pipe.getPipeName());

            }
        }

        return pageVo;
    }
jianqian's avatar
jianqian committed
103 104 105 106
    @Override
    public List<Map<String, Object>> devicefeed(Map<String, Object> param)
    {
        List<Integer> ids = new ArrayList<>();
jianqian's avatar
jianqian committed
107
        List<Integer> ids2 = new ArrayList<>();
jianqian's avatar
jianqian committed
108 109 110 111 112 113 114 115 116 117
        List<Map<Object, Object>> deviceList = (List<Map<Object, Object>>)param.get("key1");
        List<Map<Object, Object>> pipeList = (List<Map<Object, Object>>)param.get("key2");
        String orderId = (String) param.get("orderId");
        if(deviceList.size() != 0) {
            for (Map<Object, Object> temp : deviceList) {
                ids.add((Integer) temp.get("deviceId"));
            }
        }
        if(pipeList.size() != 0){
            for(Map<Object, Object> temp : pipeList){
jianqian's avatar
jianqian committed
118 119 120 121 122 123 124 125 126 127 128 129
                ids2.add((Integer) temp.get("pipeId"));
            }
        }
        List<Map<String,Object>> list = tDeviceInfoMapper.selectdevicefeed(orderId,ids,ids2);
        for(Map<String,Object> map:list){
            if((long)map.get("type")==1){
                //List<String[]> listgps =
                String str = (String) map.get("longitude");
                String[] strgps = str.split(",");
                map.put("longitude",strgps[0].substring(3, strgps[0].length() - 1));
                map.put("latitude",strgps[1].substring(1, strgps[1].length() - 2));
                //JSONObject jo =  JSONObject.parseObject(str);
jianqian's avatar
jianqian committed
130 131 132 133
            }
        }
        return list;
    }
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 173 174 175 176

    /**
     * 查询下级设备所有信息
     * @param relationDeviceId
     * @return
     */
    @Override
    public List<EquipmentForm> selectDevice(int relationDeviceId) {
        return tDeviceInfoMapper.selectDevice(relationDeviceId);
    }

    /**
     * 新增下级设备信息
     * @param equipmentList
     */
    @Override
    public void insertEquipmentList(List<EquipmentForm> equipmentList,int devId) {
        List<EquipmentForm> equipmentForms=new ArrayList<>();
        for (int i=0;i<equipmentList.size();i++){
            if (equipmentList.get(i).getRelationDeviceId()==null){
                equipmentList.get(i).setRelationDeviceId(devId);
                equipmentList.get(i).setCreateTime(new Date());
                equipmentForms.add(equipmentList.get(i));
            }
        }
        if (equipmentForms.size()!=0){
            tDeviceInfoMapper.insertTrelation(equipmentForms);
        }
    }

    /**
     * 删除下级设备信息
     * @param equipmentList
     */
    @Override
    public void deleteEquipmentList(List<EquipmentForm> equipmentList,int devid) {

        ArrayList<EquipmentForm> equipmentLists=new ArrayList<EquipmentForm>();
        for (int i=0;i<equipmentList.size();i++){
            if (equipmentList.get(i).getRelationId()!=null){
                equipmentLists.add(equipmentList.get(i));
            }
        }
177
            tDeviceInfoMapper.deleteEquipmentList(equipmentLists,devid);
178 179 180
    }


181 182 183
    /**
     * 构建前端所需要下拉树结构
     *
184
     * @param param 参数集合
185 186 187
     * @return 下拉树结构列表
     */
    @Override
188
    public List<Map<Object, Object>> buildDeviceTreeSelect(Map<Object, List> param)
189 190
    {
        List<Map<Object, Object>> list = new ArrayList<>();
191 192
        List<Map<Object, Object>> deviceList = param.get("key1");
        List<Map<Object, Object>> pipeList = param.get("key2");
193

194 195 196 197 198 199 200 201
        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);
            }
        }
202

203 204 205 206 207 208 209
        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);
            }
210 211 212 213 214
        }

        return list;
    }

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    /**
     * 设备树
     *
     * @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());
235
                map.put("level", "2");
236 237 238 239 240
                map.put("name", pipe.getPipeName());
                childNodeList.add(map);
            }

            Map<Object, Object> treeNode = new HashMap<>();
241 242
            treeNode.put("id", "0");
            treeNode.put("level", "1");
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
            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<>();
274 275
            treeNode1.put("id", "1");
            treeNode1.put("level", "1");
276 277 278
            treeNode1.put("name", "调压阀");
            treeNode1.put("childList", childNodeList1);
            Map<Object, Object> treeNode2 = new HashMap<>();
279 280
            treeNode2.put("id", "2");
            treeNode2.put("level", "1");
281 282 283
            treeNode2.put("name", "阀门井");
            treeNode2.put("childList", childNodeList2);
            Map<Object, Object> treeNode3 = new HashMap<>();
284 285
            treeNode3.put("id", "3");
            treeNode3.put("level", "1");
286 287 288
            treeNode3.put("name", "流量计");
            treeNode3.put("childList", childNodeList3);
            Map<Object, Object> treeNode4 = new HashMap<>();
289 290
            treeNode4.put("id", "4");
            treeNode4.put("level", "1");
291 292 293 294 295 296 297 298 299 300 301 302
            treeNode4.put("name", "压力表");
            treeNode4.put("childList", childNodeList4);

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

        return treeNodeList;
    }

303 304 305 306 307 308 309 310
    /**
     * 统计各设备类型的设备总数
     * @return
     */
    public List<Map<Object, Object>> countDeviceByType(){
        return tDeviceInfoMapper.countDeviceByType();
    };

311 312
    /**
     * 新增设备信息
耿迪迪's avatar
耿迪迪 committed
313
     *
314 315 316 317 318 319
     * @param tDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int insertTDeviceInfo(TDeviceInfo tDeviceInfo)
    {
320
        int deviceId = tDeviceInfoMapper.insertTDeviceInfo(tDeviceInfo);
321 322 323 324 325 326 327 328
        if (tDeviceInfo.getEquipmentList().size()!=0){
            for (int i=0;i<tDeviceInfo.getEquipmentList().size();i++){
                tDeviceInfo.getEquipmentList().get(i).setCreateTime(new Date());
                tDeviceInfo.getEquipmentList().get(i).setRelationDeviceId(tDeviceInfo.getDeviceId());
            }
            /*添加下级设备*/
            tDeviceInfoMapper.insertTrelation(tDeviceInfo.getEquipmentList());
        }
329
        return deviceId;
330 331 332 333
    }

    /**
     * 修改设备信息
耿迪迪's avatar
耿迪迪 committed
334
     *
335 336 337 338 339 340 341 342 343 344 345
     * @param tDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int updateTDeviceInfo(TDeviceInfo tDeviceInfo)
    {
        return tDeviceInfoMapper.updateTDeviceInfo(tDeviceInfo);
    }

    /**
     * 批量删除设备信息
耿迪迪's avatar
耿迪迪 committed
346
     *
347 348 349 350
     * @param deviceIds 需要删除的设备信息ID
     * @return 结果
     */
    @Override
351
    public int deleteTDeviceInfoByIds(int[] deviceIds)
352 353 354 355 356 357
    {
        return tDeviceInfoMapper.deleteTDeviceInfoByIds(deviceIds);
    }

    /**
     * 删除设备信息信息
耿迪迪's avatar
耿迪迪 committed
358
     *
359 360 361 362
     * @param deviceId 设备信息ID
     * @return 结果
     */
    @Override
363
    public int deleteTDeviceInfoById(int deviceId)
364 365 366
    {
        return tDeviceInfoMapper.deleteTDeviceInfoById(deviceId);
    }
367 368 369 370 371 372 373 374 375 376

    /**
     * 根据设备id查询最新的设备信息数据
     * @param deviceId
     * @return
     */
    @Override
    public List<TDeviceInformation> getInformations(int deviceId) {
        return tDeviceInfoMapper.getInformation(deviceId);
    }
377
}