CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ld.igds.three.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.CoreDeviceService;
import com.ld.igds.common.CoreThreeService;
import com.ld.igds.common.dto.DepotSerData;
import com.ld.igds.models.Device;
import com.ld.igds.models.ThreeConf;
import com.ld.igds.three.ThreeCodeEnum;
import com.ld.igds.three.ThreeConstant;
import com.ld.igds.three.data.Data3001;
import com.ld.igds.three.data.ThreeResponse;
import com.ld.igds.three.param.ThreeCommonParam;
import com.ld.igds.three.param.ThreeRequest;
import com.ld.igds.three.service.ThreeService;
import com.ld.igds.three.util.ThreeRespUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 3002-单个设备信息接口实现
 *
 * @author chen
 */
@Service
public class ThreeServiceImpl3002 implements ThreeService {
 
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private CoreThreeService coreThreeService;
    @Autowired
    private CoreDeviceService deviceService;
 
    @Override
    public String getInterfaceId() {
        return ThreeConstant.API_THREE_3002;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public ThreeResponse<Object> execute(ThreeRequest<JSONObject> req) {
        //转化请求参数
        ThreeCommonParam param = JSONObject.parseObject(req.getData().toString(), ThreeCommonParam.class);
 
        //判断uid
        if (StringUtils.isEmpty(param.getUid())) {
            return ThreeRespUtil.error(ThreeCodeEnum.CODE_1005, req);
        }
 
        //根据uid获取三维配置信息
        ThreeConf three = coreThreeService.getCacheThreeConfById(req.getCompanyId(), param.getUid());
        if (three == null) {
            return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "未查询到此uid的配置信息,请联系管理员!", req);
        }
 
        //根据仓库编码获取分机
        List<String> depotList = new ArrayList<>();
        depotList.add(three.getDepotId());
        List<DepotSerData> depotSerList = commonService.getCacheDepotSerByDepots(req.getCompanyId(), depotList);
 
        //存放分机获取的设备信息
        List<Device> deviceList = new ArrayList<>();
        //根据分机获取设备,存入deviceList
        for (DepotSerData depotSerData : depotSerList) {
            List<Device> tempList = deviceService.getCacheDeviceBySerId(
                    depotSerData.getCompanyId(), depotSerData.getSerId());
            deviceList.addAll(tempList);
        }
 
        //返回数据定义
        Data3001 data = new Data3001();
        if(deviceList.isEmpty()){
            return ThreeRespUtil.success(data, req);
        }
 
        //筛选返回数据
        for (Device device : deviceList) {
            if(device.getId().equals(three.getDeviceId())){
                data.setUid(three.getUid());
                data.setName(device.getName());
                data.setType(device.getTypeName());
                data.setStatus(device.getStatusName());
                break;
            }
        }
 
        return ThreeRespUtil.success(data, req);
    }
 
}