czt
2024-07-13 b030109e665301e7edd6ad0fe5c832ee10fe39b4
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
package com.ld.igds.protocol.iot.height.analysis;
 
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.grain.dto.GrainData;
import com.ld.igds.models.Building;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DeviceIot;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.protocol.iot.height.analysis.message.DeviceAttr;
import com.ld.igds.protocol.iot.height.analysis.message.DeviceAttrInfo;
import com.ld.igds.util.RedisUtil;
import com.ld.igds.view.service.BuildingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * 协议解析入口
 *
 * @author vince
 */
@Slf4j
@Component(AnalysisHeightService.BEAN_ID)
public class AnalysisHeightService {
 
    public static final String BEAN_ID = "iot.analysisHeightService";
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private CoreCommonService coreCommonService;
    @Autowired
    private BuildingService buildingService;
 
    /**
     * @param deviceAttr
     * @param ser
     */
    public void analysis(DeviceAttr deviceAttr , DeviceSer ser ,DeviceIot deviceIot)  {
        try{
            List<DeviceAttrInfo> deviceAttrInfos = deviceAttr.getTerminalAttrInfoList();
            String height =(deviceAttrInfos.get(2).getValue());
            GrainData data = new GrainData();
            data.setOilHeight(height);
            data.setReceiveDate(new Date());
            data.setDepotId(deviceIot.getDepotId());
            data.setCompanyId(ser.getCompanyId());
//            //计算储量
//            Depot depot = coreCommonService.getCacheDepot(ser.getCompanyId(), deviceIot.getDepotId());
//
//            if(null != depot){
//                Building building;
//                //容重
//                Double bulkWeight = depot.getBulkWeight();
//                if (null != depot.getBuildingId()) {
//                    building = buildingService.getCacheBuilding(depot.getCompanyId(),depot.getDeptId(), depot.getBuildingId());
//                    if (null != building) {
//                        if (null != building.getHeight()) {
//                            height = building.getHeight() + "";
//                        }
//                        if (null != building.getLength()) {
//                            diameter = building.getLength();
//                        }
//                        if (null != building.getDeVolume()) {
//                            deVolume = building.getDeVolume();
//                        }
//                    }
//                }
//
//                grainData.setDepotData(depot);
//                grainData.setDepotHeight(height);
//                if (null != bulkWeight && StringUtils.isNotEmpty(grainData.getOilHeight())) {
//                    Double oilHeight = Double.valueOf(grainData.getOilHeight());
//                    //计算体积
//                    volume = 3.14 * Math.pow(diameter / 2, 2) * oilHeight  - deVolume;
//                    storage = volume * bulkWeight;
//                }
//
//                grainData.setStorage(storage);
//            }
            redisUtil.set(RedisConst.buildKey(ser.getCompanyId(),RedisConst.KEY_DEPOT_HEIGHT,deviceIot.getDepotId()),data);
            log.info("高度解析完成:" + data.toString());
        }catch (Exception e){
           log.error(e.getMessage(),e);
        }
    }
}