Browse Source

设置集团编码设置

miaolijing 2 years ago
parent
commit
868b47bf03

+ 5 - 0
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -25,6 +25,7 @@ import com.persagy.framework.ems.data.core.enumeration.SpecialOperator;
 import com.persagy.framework.ems.data.mvc.dao.CoreDao;
 import com.persagy.framework.ems.data.pojo.hbase.IndicatorComputeLog;
 import com.persagy.framework.ems.data.pojo.hbase.MonitorIndicatorRecord;
+import com.persagy.framework.tenant.mybatis.datasource.db.holder.SaasContext;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
@@ -113,6 +114,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     public Future<String> computeIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
             if (!lockUtil.lock(projectDTO.getProjectId() + DiAgnoseConst.RedisConstants.ComputeProjectLockKey, String.valueOf(time))) {
                 // 获取不到锁,略过
                 return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
@@ -136,6 +138,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
         //        log.info(Thread.currentThread().getName() + "开始计算[{}]的设备运行诊断监测指标", projectDTO.getProjectId());
         //判断当前计算轮次是否大于缓存中最新计算轮次,如果是,则证明已经被计算过,则略过
+        SaasContext.setContextGroupCode(projectDTO.getGroupCode());
         if (checkProjectIsCalcd(projectDTO.getProjectId(), projectIndicatorCompute)) {
             return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "被占用");
         }
@@ -323,6 +326,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     public Future<String> sendIndicatorData(ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
             if (!lockUtil.lock(projectDTO.getProjectId() + "_sendData", String.valueOf(time))) {
                 // 获取不到锁,略过
                 return new AsyncResult<>("【监测指标数据计算线程】:项目:" + projectDTO.getProjectId() + "被占用");
@@ -440,6 +444,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     }
 
     private void sendIndicatorDataToAlarmServer(ProjectDTO projectDTO) throws Exception {
+        SaasContext.setContextGroupCode(projectDTO.getGroupCode());
         //通过报警服务查询报警规则
         List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId());
         //        log.error("获取到的项目报警规则:" + projectDTO.getProjectId() + ";" + projectAlarmRules);

+ 1 - 1
src/main/java/com/persagy/apm/diagnose/maintenance/service/IProjectDataRecordService.java

@@ -15,6 +15,6 @@ public interface IProjectDataRecordService {
 
     Future<String> sendMaintenanceData(Date todayDate,ProjectDTO projectDTO, CountDownLatch latch) throws Exception;
 
-    Future<String> syncGoingDestroyEquip(String projectId, CountDownLatch latch) throws Exception;
+    Future<String> syncGoingDestroyEquip(ProjectDTO projectDTO, CountDownLatch latch) throws Exception;
 
 }

+ 14 - 7
src/main/java/com/persagy/apm/diagnose/maintenance/service/impl/ProjectDataRecordServiceImpl.java

@@ -107,6 +107,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
     public Future<String> computeMaintenanceData(Date todayDate, ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
             if (!lockUtil.lock(projectDTO.getProjectId() + "_computeMaintenance", String.valueOf(time))) {
                 // 获取不到锁,略过
                 return new AsyncResult<>("【监测维保数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
@@ -131,6 +132,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
     public Future<String> sendMaintenanceData(Date todayDate,ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
             if (!lockUtil.lock(projectDTO.getProjectId() + "_sendMaintenance", String.valueOf(time))) {
                 // 获取不到锁,略过
                 return new AsyncResult<>("【监测维保数据推送线程】:项目:" + projectDTO.getProjectId() + "被占用");
@@ -147,19 +149,20 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
 
     @Override
     @Async("asyncGoingDestroyEquipExecutor")
-    public Future<String> syncGoingDestroyEquip(String projectId, CountDownLatch latch) {
+    public Future<String> syncGoingDestroyEquip(ProjectDTO projectDTO, CountDownLatch latch) {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
-            if (!lockUtil.lock(projectId + "_syncEquip", String.valueOf(time))) {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
+            if (!lockUtil.lock(projectDTO.getProjectId() + "_syncEquip", String.valueOf(time))) {
                 // 获取不到锁,略过
-                return new AsyncResult<>("【监测同步即将报废设备线程】:项目:" + projectId + "被占用");
+                return new AsyncResult<>("【监测同步即将报废设备线程】:项目:" + projectDTO.getProjectId() + "被占用");
             }
             long start = System.currentTimeMillis();
-            syncProjectGoingDestroyEquip(projectId);
+            syncProjectGoingDestroyEquip(projectDTO);
             long end = System.currentTimeMillis();
-            return new AsyncResult<>("【监测同步即将报废设备线程】同步项目即将报废设备用时:" + projectId + ";" + (end - start));
+            return new AsyncResult<>("【监测同步即将报废设备线程】同步项目即将报废设备用时:" + projectDTO.getProjectId() + ";" + (end - start));
         } finally {
-            lockUtil.unlock(projectId + "_syncEquip", String.valueOf(time));
+            lockUtil.unlock(projectDTO.getProjectId() + "_syncEquip", String.valueOf(time));
             latch.countDown();
         }
     }
@@ -167,8 +170,10 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
     /**
      * 同步即将报废设备  更新更换设备报警信息
      */
-    private void syncProjectGoingDestroyEquip(String projectId) {
+    private void syncProjectGoingDestroyEquip(ProjectDTO projectDTO) {
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
+            String projectId = projectDTO.getProjectId();
             //获取该项目的更换设备类型的 报警集合
             Map<String, AlarmRecordItem> alarmRecordItemMap = getAlarmRecordItemMap(projectId);
             List<String> alarmEquipList = new ArrayList<>(alarmRecordItemMap.keySet());
@@ -269,6 +274,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
      * 推送维保数据
      */
     private void sendProjectMaintenanceData(Date todayDate,ProjectDTO projectDTO) throws Exception {
+        SaasContext.setContextGroupCode(projectDTO.getGroupCode());
         List<String> itemCodeList = new ArrayList<>();
         itemCodeList.add(EnumAlarmItem.CondAbnormal.getCode());
         itemCodeList.add(EnumAlarmItem.EvapAbnormal.getCode());
@@ -401,6 +407,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
      */
     private AsyncResult<String> computeProjectMaintenanceData(Date todayDate, ProjectDTO projectDTO) {
         try {
+            SaasContext.setContextGroupCode(projectDTO.getGroupCode());
             //通过报警服务查询报警规则
             List<String> itemCodeList = new ArrayList<>();
             itemCodeList.add(EnumAlarmItem.CondAbnormal.getCode());

+ 2 - 1
src/main/java/com/persagy/apm/diagnose/service/ComputeIndicatorDataService.java

@@ -6,6 +6,7 @@ import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordS
 import com.persagy.apm.diagnose.maintenance.model.dto.AlarmProjectDTO;
 import com.persagy.apm.diagnose.service.dto.ProjectDTO;
 import com.persagy.apm.diagnose.utils.CommonUtils;
+import com.persagy.framework.tenant.mybatis.datasource.db.holder.SaasContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -87,7 +88,7 @@ public class ComputeIndicatorDataService {
         }
 
         List<ProjectDTO> projectDTOList = alarmProjectDTOList.stream().map(
-                alarmProjectDTO -> ProjectDTO.builder().projectId(alarmProjectDTO.getProjectId()).build()
+                alarmProjectDTO -> ProjectDTO.builder().projectId(alarmProjectDTO.getProjectId()).groupCode(SaasContext.getContextGroupCode()).build()
         ).collect(Collectors.toList());
 //        //查询项目列表
 //        List<ProjectDTO> projectDTOList = saasWebServiceImpl.queryProjectDTOList(null);

+ 2 - 2
src/main/java/com/persagy/apm/diagnose/service/MaintenanceDataService.java

@@ -100,7 +100,7 @@ public class MaintenanceDataService {
         }
 
         List<ProjectDTO> projectDTOList = alarmProjectDTOList.stream().map(
-                alarmProjectDTO -> ProjectDTO.builder().projectId(alarmProjectDTO.getProjectId()).build()
+                alarmProjectDTO -> ProjectDTO.builder().projectId(alarmProjectDTO.getProjectId()).groupCode(SaasContext.getContextGroupCode()).build()
         ).collect(Collectors.toList());
 
 
@@ -115,7 +115,7 @@ public class MaintenanceDataService {
         List<Future<String>> futureList = new ArrayList<>();
         CountDownLatch latch = new CountDownLatch(projectDTOList.size());
         for (ProjectDTO projectDTO : projectDTOList) {
-            futureList.add(projectDataRecordService.syncGoingDestroyEquip(projectDTO.getProjectId(),latch));
+            futureList.add(projectDataRecordService.syncGoingDestroyEquip(projectDTO,latch));
         }
         //等待所有任务执行完
         latch.await();

+ 1 - 1
src/main/java/com/persagy/apm/diagnose/service/SaasWebServiceImpl.java

@@ -67,7 +67,7 @@ public class SaasWebServiceImpl {
 
         for (Object object : jsonArray) {
             JSONObject obj = (JSONObject) object;
-            ProjectDTO projectDTO = ProjectDTO.builder().projectId(obj.getString("projectId")).projectLocalId(obj.getString("projectLocalID")).build();
+            ProjectDTO projectDTO = ProjectDTO.builder().projectId(obj.getString("projectId")).projectLocalId(obj.getString("projectLocalID")).groupCode(SaasContext.getContextGroupCode()).build();
             result.add(projectDTO);
         }
         return result;