DeviceService.java 2.15 KB
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;
    }
}