Bladeren bron

优化代码

java110 5 jaren geleden
bovenliggende
commit
20a4e8acb6

+ 16 - 0
java110-db/src/main/resources/mapper/center/CenterServiceDAOImplMapper.xml

@@ -259,6 +259,22 @@
         ]]>
     </select>
 
+    <select id="getDatabusAll" resultType="com.java110.dto.businessDatabus.BusinessDatabusDto">
+        <![CDATA[
+            SELECT
+                t.databus_id databusId,
+                t.databus_name databusName,
+                t.business_type_cd businessTypeCd,
+                t.bean_name beanName,
+                t.seq
+            FROM
+                c_business_databus t
+            WHERE
+                t.status_cd = '0'
+            AND t.state = '1001'
+        ]]>
+    </select>
+
     <select id="judgeAllBusinessCompleted" parameterType="map" resultType="map">
         SELECT co.* FROM c_orders co WHERE co.`o_id` = #{oId} and not exists (
         SELECT 1 FROM c_business cb WHERE cb.`o_id` = co.`o_id`

+ 73 - 0
java110-utils/src/main/java/com/java110/utils/cache/DatabusCache.java

@@ -0,0 +1,73 @@
+package com.java110.utils.cache;
+
+import com.java110.dto.businessDatabus.BusinessDatabusDto;
+import com.java110.utils.util.SerializeUtil;
+import redis.clients.jedis.Jedis;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 映射缓存工具类
+ * Created by wuxw on 2018/4/14.
+ */
+public class DatabusCache extends BaseCache {
+
+    //后缀 用来刷缓存时删除 所有以这个为后缀的数据
+    public final static String DEFAULT_DATABUS = "JAVA110_DATABUS";
+
+
+    /**
+     * 获取  databus
+     *
+     * @return
+     */
+    public static List<BusinessDatabusDto> getDatabuss() {
+        Jedis redis = null;
+        try {
+            redis = getJedis();
+            return SerializeUtil.unserializeList(redis.get((DEFAULT_DATABUS).getBytes()), BusinessDatabusDto.class);
+        } finally {
+            if (redis != null) {
+                redis.close();
+            }
+        }
+    }
+
+    /**
+     * 获取  databus
+     *
+     * @return
+     */
+    public static List<BusinessDatabusDto> getDatabuss(String businessType) {
+        List<BusinessDatabusDto> businessDatabusDtos = getDatabuss();
+
+        List<BusinessDatabusDto> tmpBusinessDatabusDtos = new ArrayList<>();
+
+        for (BusinessDatabusDto businessDatabusDto : businessDatabusDtos) {
+            if (businessType.equals(businessDatabusDto.getBusinessTypeCd())) {
+                tmpBusinessDatabusDtos.add(businessDatabusDto);
+            }
+        }
+        return tmpBusinessDatabusDtos;
+    }
+
+    /**
+     * 保存list 数据
+     *
+     * @param businessDatabusDtos
+     */
+    public static void setValue(List<BusinessDatabusDto> businessDatabusDtos) {
+        Jedis redis = null;
+        try {
+            redis = getJedis();
+            redis.set((DEFAULT_DATABUS).getBytes(), SerializeUtil.serializeList(businessDatabusDtos));
+        } finally {
+            if (redis != null) {
+                redis.close();
+            }
+        }
+    }
+
+
+}

+ 37 - 0
service-job/src/main/java/com/java110/job/adapt/IDatabusAdapt.java

@@ -0,0 +1,37 @@
+/**
+ * Copyright 2017-2020 吴学文 and java110 team.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt;
+
+import com.java110.entity.order.Business;
+
+import java.util.List;
+
+/**
+ * databus 适配器
+ * <p>
+ * add by wuxw 2020-12-07
+ */
+public interface IDatabusAdapt {
+
+    /**
+     * 业务处理
+     *
+     * @param business   当前处理业务
+     * @param businesses 所有业务信息
+     */
+    public void execute(Business business, List<Business> businesses);
+
+}

+ 33 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/MachineTransactionIotAdapt.java

@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcIot;
+
+import com.java110.entity.order.Business;
+import com.java110.job.adapt.IDatabusAdapt;
+
+import java.util.List;
+
+/**
+ * HC iot 设备同步适配器
+ *
+ * @desc add by 吴学文 18:58
+ */
+public class MachineTransactionIotAdapt implements IDatabusAdapt {
+    @Override
+    public void execute(Business business, List<Business> businesses) {
+
+    }
+}

+ 7 - 0
service-order/src/main/java/com/java110/order/dao/ICenterServiceDAO.java

@@ -1,6 +1,7 @@
 package com.java110.order.dao;
 
 import com.java110.dto.basePrivilege.BasePrivilegeDto;
+import com.java110.dto.businessDatabus.BusinessDatabusDto;
 import com.java110.utils.exception.DAOException;
 import com.java110.entity.mapping.Mapping;
 
@@ -210,6 +211,12 @@ public interface ICenterServiceDAO {
      * @return
      */
     public List<BasePrivilegeDto> getPrivilegeAll();
+    /**
+     * 查询映射表
+     *
+     * @return
+     */
+    public List<BusinessDatabusDto> getDatabusAll();
 
     /**
      * 查询业主 添加 修改 删除订单

+ 6 - 0
service-order/src/main/java/com/java110/order/dao/impl/CenterServiceDAOImpl.java

@@ -3,6 +3,7 @@ package com.java110.order.dao.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.base.dao.BaseServiceDao;
 import com.java110.dto.basePrivilege.BasePrivilegeDto;
+import com.java110.dto.businessDatabus.BusinessDatabusDto;
 import com.java110.entity.mapping.Mapping;
 import com.java110.order.dao.ICenterServiceDAO;
 import com.java110.utils.constant.ResponseConstant;
@@ -356,6 +357,11 @@ public class CenterServiceDAOImpl extends BaseServiceDao implements ICenterServi
         return sqlSessionTemplate.selectList("centerServiceDAOImpl.getPrivilegeAll");
     }
 
+    @Override
+    public List<BusinessDatabusDto> getDatabusAll() {
+        return sqlSessionTemplate.selectList("centerServiceDAOImpl.getDatabusAll");
+    }
+
     /**
      * 查询业主订单
      *

+ 13 - 2
service-order/src/main/java/com/java110/order/smo/impl/CenterServiceCacheSMOImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.java110.core.factory.DataTransactionFactory;
 import com.java110.db.dao.IQueryServiceDAO;
 import com.java110.dto.basePrivilege.BasePrivilegeDto;
+import com.java110.dto.businessDatabus.BusinessDatabusDto;
 import com.java110.entity.center.AppRoute;
 import com.java110.entity.mapping.Mapping;
 import com.java110.entity.order.ServiceBusiness;
@@ -97,11 +98,13 @@ public class CenterServiceCacheSMOImpl implements ICenterServiceCacheSMO {
 
         //3.0 分装 ServiceSql
         doFlushServiceSql();
-
+        //5.0 刷新全新
         doFlushServiceBusiness();
 
-        //5.0 刷新全新
+
         doFlushPrivilege();
+
+        doFlushDatabus();
     }
 
 
@@ -289,6 +292,14 @@ public class CenterServiceCacheSMOImpl implements ICenterServiceCacheSMO {
         PrivilegeCache.setValue(basePrivilegeDtos);
     }
 
+    private void doFlushDatabus() {
+        logger.debug("开始刷新 Mapping数据到redis数据库中");
+        List<BusinessDatabusDto> businessDatabusDtos = centerServiceDAOImpl.getDatabusAll();
+        //删除原始数据
+        DatabusCache.removeData(DatabusCache.DEFAULT_DATABUS);
+        DatabusCache.setValue(businessDatabusDtos);
+    }
+
     /**
      * 刷新AppRoute数据
      */