DeviceService.java
2.15 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
57
58
59
60
61
62
63
64
65
66
67
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.com.glsx.stdinterface.dto.DeviceDto;
import cn.com.glsx.stdinterface.modules.converter.DeviceConverter;
import cn.com.glsx.stdinterface.modules.entity.Device;
import cn.com.glsx.stdinterface.modules.mapper.DeviceMapper;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* @BelongsProject: ne-shield-standard-interfaces
* @BelongsPackage: cn.com.glsx.stdinterface.modules.service
* @Author: dell_xw
* @CreateTime: 2022-04-19 13:26
* @Description: TODO
* @Version: 1.0
*/
@Slf4j
@Service
public class DeviceService {
@Autowired
private DeviceMapper deviceMapper;
public boolean updateDeviceActived(String sn, Integer actived) {
if (StringUtils.isBlank(sn) || actived == null) {
return false;
}
log.info("update device actived status sn:{},status:{}", sn, actived);
Device selectCondition = new Device();
selectCondition.setSn(sn);
Device device = deviceMapper.selectOne(selectCondition);
log.info("update device actived status device:{}", JSONUtil.toJsonStr(device));
if (device != null) {
device.setActivateStatus(Constants.DeviceActived.ACTIVED);
device.setActivateTime(new Date());
device.setUpdatedDate(new Date());
deviceMapper.updateByPrimaryKeySelective(device);
}
return true;
}
/**
* 根据设备号获取设备数据
*
* @param sn 设备号
* @return
*/
public DeviceDto getDeviceBySn(String sn) {
if (StringUtils.isEmpty(sn)) {
log.info("sn is null");
return null;
}
Device deviceBySn = deviceMapper.getDeviceBySn(sn);
DeviceDto deviceDto = DeviceConverter.INSTANCE.syncEntity2Dto(deviceBySn);
log.info("获取设备实体类数据:" + JSONUtil.toJsonStr(deviceDto));
return deviceDto;
}
}