zhczyx 2 weeks ago
parent
commit
de3f6821ea
  1. 12
      data-center-business-service/src/main/java/com/techsor/datacenter/business/listener/PreloadDeviceCompanyMappingListener.java

12
data-center-business-service/src/main/java/com/techsor/datacenter/business/listener/PreloadDeviceCompanyMappingListener.java

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

Loading…
Cancel
Save