/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ifish.helper; import com.ifish.bean.LoginRecord; import com.ifish.bean.Tbl_Device; import com.ifish.bean.Tbl_Device_User; import com.ifish.bean.Tbl_Factory_List; import com.ifish.bean.Tbl_HardWare_Type; import com.ifish.mapper.Tbl_Device_Mapper; import com.ifish.mapper.Tbl_Hardware_Type_Mapper; import com.ifish.socket.model.send.DeviceLoginContextLength24; import com.ifish.util.IfishUtil; import com.ifish.util.RedisKey; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * * @author Administrator */ @Component public class DeviceHelper implements DeviceHelperI { /** * 所有tbl_Hardware_Type表的操作方法接口 */ @Autowired private Tbl_Hardware_Type_Mapper tbl_Hardware_Type_Mapper; @Autowired private RedisHelperI redisHelperI; @Autowired private Tbl_Device_Mapper tbl_Device_Mapper; @Override public Tbl_Device update(Tbl_Device device) { try { int i = tbl_Device_Mapper.updateTbl_Device(device); if (i > 0) { return device; } else { return null; } } catch (Exception e) { return null; } } @Override public Tbl_Device update(DeviceLoginContextLength24 model) { return null; } @Override public void updateWarnOnoff(String macAddress, String onOff) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public Tbl_Device getUniqueByProperty(String property, Object value) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List getByProperty(String property, Object value) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public Tbl_Device_User getUniqueByProperty(String macAddress) { Tbl_Device device = getDeviceByMacAddress(macAddress); Tbl_Device_User deviceUser = null; try { // String key = RedisKey.DeviceUser_Key + "m" + macAddress; // String redisString = redisHelperI.getRedis(key); // if (StringUtils.isNotBlank(redisString)) { // deviceUser = (Tbl_Device_User) IfishUtil.JsonToBean(redisString, Tbl_Device_User.class); // } else { // device = tbl_Device_Mapper.getDeviceUsersByUserIdAndDeviceId(device.get, deviceId); // if (device != null && device.getDeviceId() > 0) { // redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); // } // } } catch (Exception e) { } return deviceUser; } @Override public List getListByProperty(Integer deviceId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public LoginRecord save(LoginRecord loginRecord) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public Tbl_Factory_List getFactoryListById(String factoryCode) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public Tbl_HardWare_Type getHardwareTypeById(String typeCode) { Tbl_HardWare_Type hardwareType = null; try { String key = RedisKey.HardWareType_key + typeCode; String redisString = redisHelperI.getRedis(key); if (StringUtils.isNotBlank(redisString)) { hardwareType = (Tbl_HardWare_Type) IfishUtil.JsonToBean(redisString, Tbl_HardWare_Type.class); } else { hardwareType = tbl_Hardware_Type_Mapper.getHardwareTypeByTypeCode(typeCode); if (hardwareType != null && StringUtils.isNotBlank(hardwareType.getHardwareType())) { redisHelperI.setRedis(key, IfishUtil.ObjectToJson(hardwareType)); } } } catch (Exception e) { } return hardwareType; } public Tbl_Device getDeviceByMacAddress(String macAddress) { Tbl_Device device = null; try { String key = RedisKey.Device_key + macAddress; String redisString = redisHelperI.getRedis(key); if (StringUtils.isNotBlank(redisString)) { device = (Tbl_Device) IfishUtil.JsonToBean(redisString, Tbl_Device.class); } else { device = tbl_Device_Mapper.getDeviceByMacAddress(macAddress); if (device != null && device.getDeviceId() > 0) { redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); } } } catch (Exception e) { } return device; } }