LansiAppLogController.java
2.12 KB
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
package com.ruoyi.controller.dss;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.domain.dss2.log.EquipmengLogDTO;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@RestController
@Slf4j
@RequestMapping("/dss")
@Api(tags = "【蓝斯二期】蓝斯设备日志")
public class LansiAppLogController extends BaseController {
private final static Map<String, Logger> LOGGER_MAP = new HashMap<>();
public LansiAppLogController(IEquipmentService equipmentService) {
List<Equipment> equipmentList = equipmentService.list();
int size = CollectionUtils.size(equipmentList);
for (int i = 0; i < size; i++) {
String name = StringUtils.join("lansi:", equipmentList.get(i).getDeviceId());
LOGGER_MAP.put(equipmentList.get(i).getDeviceId(), LoggerFactory.getLogger(name));
}
}
@ApiOperation(value = "设备日志")
@PostMapping("/equipment/log")
public ResponseResult<Boolean> createLog(@RequestBody EquipmengLogDTO equipmengLogDTO) {
Logger logger = LOGGER_MAP.get(equipmengLogDTO.getDevice());
if (Objects.isNull(logger)) {
String name = StringUtils.join("lansi:", equipmengLogDTO.getDevice());
logger = LoggerFactory.getLogger(name);
LOGGER_MAP.put(equipmengLogDTO.getDevice(), logger);
}
logger.info("[{}]", equipmengLogDTO);
return ResponseResult.success(Boolean.TRUE);
}
}