houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
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
package com.iailab.module.feign;
 
import com.iailab.api.IFeignModelApi;
import com.iailab.module.device.service.DeviceAbnormalHistoryService;
import com.iailab.module.device.service.DeviceAccountService;
import com.iailab.module.device.service.DeviceHealthStateService;
import com.iailab.module.device.service.DeviceRunStateService;
import com.iailab.module.model.handler.ModelHandler;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author lirm
 * @Description
 * @createTime 2024年05月22日
 */
@RestController
public class FeignModelImpl implements IFeignModelApi {
 
    @Resource
    private DeviceRunStateService deviceRunStateService;
 
    @Resource
    private DeviceHealthStateService deviceHealthStateService;
 
    @Resource
    private DeviceAbnormalHistoryService deviceAbnormalHistoryService;
 
    @Resource
    private DeviceAccountService deviceAccountService;
 
    @Resource
    private ModelHandler modelHandler;
 
    @Override
    public void insertRunState(Map<String, Integer> tMap) {
        deviceRunStateService.insertRunState(tMap);
    }
 
    @Override
    public void insertHealthState(Map<String, Object> tMap) {
        deviceHealthStateService.insertHealthState(tMap);
        deviceAbnormalHistoryService.insertHistory(tMap);
    }
 
    @Override
    public void insertDeviceList(Map<String, String> tMap) {
        deviceAccountService.insertDeviceList(tMap);
    }
 
    @Override
    public Map<String, Object> runModel(Map<String, Object> params, List<double[][]> sampleDataList) {
        Map<String, Object> result = new HashMap<>();
        try {
            String modelCode = (String) params.get("modelCode");
            if (StringUtils.isBlank(modelCode)) {
                return result;
            }
            if (CollectionUtils.isEmpty(sampleDataList)) {
                return result;
            }
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            result = modelHandler.run(modelCode, sampleDataList);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
 
    @Override
    public List<String> getDeviceIdList() {
        return deviceAccountService.getDeviceIdList();
    }
}