DeviceService.java 1.54 KB
package cn.com.glsx.stdinterface.modules.service;

import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.com.glsx.stdinterface.modules.entity.Device;
import cn.com.glsx.stdinterface.modules.mapper.DeviceMapper;
import com.alibaba.fastjson.JSONObject;
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:{}", JSONObject.toJSONString(device));
        if (device!=null) {
            device.setActivateStatus((byte) Constants.DeviceActived.ACTIVED);
            device.setActivateTime(new Date());
            device.setUpdatedDate(new Date());
            deviceMapper.updateByPrimaryKeySelective(device);
        }
        return true;
    }
}