|
|
|
@ -6,6 +6,7 @@ import com.techsor.datacenter.business.common.config.DataSourceContextHolder; |
|
|
|
import com.techsor.datacenter.business.dao.ex.DeviceInfoMapperExt; |
|
|
|
import com.techsor.datacenter.business.vo.device.DeviceVO; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.context.event.ApplicationStartedEvent; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
@ -52,6 +53,9 @@ public class PreloadDeviceCompanyMappingListener implements ApplicationListener< |
|
|
|
redisTemplate.opsForHash().put("deviceCompanyMapping", deviceVO.getDeviceId(), String.valueOf(companyId)); |
|
|
|
if(deviceVO.getCategoryId() != null && deviceVO.getCategoryId().equals(1011L)){ |
|
|
|
redisTemplate.opsForHash().put("f10:deviceCompanyMapping", getF10Prefix(deviceVO.getDeviceId()), String.valueOf(companyId)); |
|
|
|
} else if(deviceVO.getCategoryId() != null && deviceVO.getCategoryId().equals(1012L)){ |
|
|
|
String terminalId = getCsdjPrefix(deviceVO.getDeviceId()); |
|
|
|
redisTemplate.opsForHash().put("csdj:deviceCompanyMapping", terminalId, String.valueOf(companyId)); |
|
|
|
} |
|
|
|
}); |
|
|
|
DataSourceContextHolder.clearCurrentDataSourceKey(); |
|
|
|
@ -59,6 +63,14 @@ public class PreloadDeviceCompanyMappingListener implements ApplicationListener< |
|
|
|
log.info("PreloadDeviceCompanyMappingListener finished"); |
|
|
|
} |
|
|
|
|
|
|
|
private String getCsdjPrefix(String deviceId) { |
|
|
|
if (deviceId == null) { |
|
|
|
return ""; // 或抛异常
|
|
|
|
} |
|
|
|
String prefix = StringUtils.substringBefore(deviceId, "-"); |
|
|
|
return prefix + "-"; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getF10Prefix(String deviceId) { |
|
|
|
if (deviceId == null) { |
|
|
|
return null; |
|
|
|
|