Forráskód Böngészése

修复序列化框架序列化的问题

liukx 3 éve
szülő
commit
89aba793ec

+ 89 - 85
elab-db/src/test/java/com.db.service/main/BasicBaseDaoCase.java

@@ -13,10 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 基于拓展的测试用例
@@ -26,8 +23,7 @@ import java.util.Map;
  * @email liukx@elab-plus.com
  **/
 @RunWith(SpringJUnit4ClassRunner.class)  //使用junit4进行测试
-@ContextConfiguration
-        ({"classpath:applicationContext-datasource.xml",})
+@ContextConfiguration({"classpath:applicationContext-datasource.xml",})
 public class BasicBaseDaoCase {
 
     @Autowired
@@ -36,64 +32,63 @@ public class BasicBaseDaoCase {
     @Autowired
     private BasicBaseDao basicBaseDao;
 
-//    @Autowired
-//    private IHelloDao helloDao;
+    //    @Autowired
+    //    private IHelloDao helloDao;
 
-//    @Test
-//    public void executeQueryforListMap() {
-//        Map<String, String> map = new HashMap<>();
-//        map.put("status", "1");
-//        List<Map<String, Object>> maps = basicBaseDao.executeQueryForListMap("com.db.service.dao.ITestDao.selectByExample", map);
-//        System.out.println(maps.size());
-//    }
-//
-//    @Test
-//    public void executeQueryList() {
-//        TTest test = new TTest();
-//        test.setStatus("1");
-//        List<TTest> tTests = basicBaseDao.executeQueryList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
-//        System.out.println(tTests.size());
-//    }
-//
-//    @Test
-//    public void executeQueryBigDataList() {
-//        TTest test = new TTest();
-//        test.setStatus("1");
-//        List<TTest> tTests = basicBaseDao.executeQueryBigDataList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
-//        System.out.println(tTests.size());
-//    }
-//
-//
-//    @Test
-//    public void executeInsert() {
-//        TTest test = new TTest();
-//        test.setStatus("1");
-//        test.setUsername("某某某xx");
-//        int i = basicBaseDao.insert("test.insert", test);
-//        System.out.println(i);
-//    }
-//
-//    @Test
-//    public void executeUpdate() {
-//        TTest test = new TTest();
-//        test.setId(1);
-//        test.setStatus("1");
-//        test.setUsername("某某某xx");
-//        int i = basicBaseDao.executeUpdate("test.updateByPrimaryKey", test);
-//        System.out.println(i);
-//    }
+    //    @Test
+    //    public void executeQueryforListMap() {
+    //        Map<String, String> map = new HashMap<>();
+    //        map.put("status", "1");
+    //        List<Map<String, Object>> maps = basicBaseDao.executeQueryForListMap("com.db.service.dao.ITestDao.selectByExample", map);
+    //        System.out.println(maps.size());
+    //    }
+    //
+    //    @Test
+    //    public void executeQueryList() {
+    //        TTest test = new TTest();
+    //        test.setStatus("1");
+    //        List<TTest> tTests = basicBaseDao.executeQueryList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
+    //        System.out.println(tTests.size());
+    //    }
+    //
+    //    @Test
+    //    public void executeQueryBigDataList() {
+    //        TTest test = new TTest();
+    //        test.setStatus("1");
+    //        List<TTest> tTests = basicBaseDao.executeQueryBigDataList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
+    //        System.out.println(tTests.size());
+    //    }
+    //
+    //
+    //    @Test
+    //    public void executeInsert() {
+    //        TTest test = new TTest();
+    //        test.setStatus("1");
+    //        test.setUsername("某某某xx");
+    //        int i = basicBaseDao.insert("test.insert", test);
+    //        System.out.println(i);
+    //    }
+    //
+    //    @Test
+    //    public void executeUpdate() {
+    //        TTest test = new TTest();
+    //        test.setId(1);
+    //        test.setStatus("1");
+    //        test.setUsername("某某某xx");
+    //        int i = basicBaseDao.executeUpdate("test.updateByPrimaryKey", test);
+    //        System.out.println(i);
+    //    }
 
     @Test
     public void executeQueryList() throws Exception {
-//        String sql = configurableFactory.getSqlConfigurableFactory().getSql("test.selectByObjectToCount");
-        String sql = "select  count(1) from test.t_test where id =:id and love_name =:loveName  and  created " +
-                "=:created  and  sex =:sex  and  name =:name  and  id =:id  and  time =:time  and  username =:username  and  status =:status  and  test_id =:testId";
+        //        String sql = configurableFactory.getSqlConfigurableFactory().getSql("test.selectByObjectToCount");
+        String sql = "select  count(1) from test.t_test where id =:id and love_name =:loveName  and  created "
+            + "=:created  and  sex =:sex  and  name =:name  and  id =:id  and  time =:time  and  username =:username  and  status =:status  and  test_id =:testId";
         TTest test = new TTest();
         test.setStatus("1");
-        Long integer = basicBaseDao.executeQueryCount(sql,
-                test, null, Long.class);
-//        Long integer1 = basicBaseDao.getJdbcTemplate().queryForObject("select  count(1) from test.t_test where 1=1   and  status =?",
-//                new Object[]{1}, Long.class);
+        Long integer = basicBaseDao.executeQueryCount(sql, test, null, Long.class);
+        //        Long integer1 = basicBaseDao.getJdbcTemplate().queryForObject("select  count(1) from test.t_test where 1=1   and  status =?",
+        //                new Object[]{1}, Long.class);
         System.out.println(integer);
     }
 
@@ -109,12 +104,12 @@ public class BasicBaseDaoCase {
             test.setTime(new Date());
             test.setCreated(new Date());
             test.setName("batchTest_name_" + i);
-//            test.setLoveName("aaaaa");
+            //            test.setLoveName("aaaaa");
             list.add(test);
         }
-        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values " +
-                "(:username, :name, :sex, :status, :created, :time, :test_id, :love_name)";
-//        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
+        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values "
+            + "(:username, :name, :sex, :status, :created, :time, :test_id, :love_name)";
+        //        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
         basicBaseDao.batchOperation(SqlCommandType.INSERT, sql, list);
         System.out.println("=========");
     }
@@ -129,35 +124,44 @@ public class BasicBaseDaoCase {
             list.add(test);
         }
         String sql = "update t_test set time = :time where id = :id";
-//        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
+        //        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
         basicBaseDao.batchOperation(SqlCommandType.UPDATE, sql, list);
     }
 
     @Test
     public void testSql() throws Exception {
-        String json = "{\"houseId\":10151,\"writeType\":1,\"keyword1\":\"%%\",\"keyword2\n" +
-                "\":\"%%\"}";
+        String json = "{\"houseId\":10151,\"writeType\":1,\"keyword1\":\"%%\",\"keyword2\n" + "\":\"%%\"}";
         Map map = JSON.parseObject(json, Map.class);
-        String sql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n" +
-                "        a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n" +
-                "        d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n" +
-                "        b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n" +
-                "        left join organize_user_rlat b on b.user_id = a.id\n" +
-                "        left join organize d on d.id = b.organize_id\n" +
-                "        left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n" +
-                "        where d.status = 1 and f.status = 1 and b.house_id = :houseId and b.write_type = :writeType\n" +
-                "        and b.organize_id = :organizeId and (a.name like :keyword1 or a.mobile like :keyword2)\n" +
-                "        order by ifnull(b.updated,b.created) desc";
-        String okSql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n" +
-                "        a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n" +
-                "        d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n" +
-                "        b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n" +
-                "        left join organize_user_rlat b on b.user_id = a.id\n" +
-                "        left join organize d on d.id = b.organize_id\n" +
-                "        left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n" +
-                "        where d.status = 1 and f.status = 1 and b.house_id = ? and b.write_type = ?  and (a.name like ? )\n" +
-                "        order by ifnull(b.updated,b.created) desc";
-        JdbcParamsModel model = basicBaseDao.commonParseSql(sql, map);
+        String sql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n"
+            + "        a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n"
+            + "        d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n"
+            + "        b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n"
+            + "        left join organize_user_rlat b on b.user_id = a.id\n"
+            + "        left join organize d on d.id = b.organize_id\n"
+            + "        left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n"
+            + "        where d.status = 1 and f.status = 1 and b.house_id = :houseId and b.write_type = :writeType\n"
+            + "        and b.organize_id = :organizeId and (a.name like :keyword1 or a.mobile like :keyword2)\n"
+            + "        order by ifnull(b.updated,b.created) desc";
+        String okSql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n"
+            + "        a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n"
+            + "        d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n"
+            + "        b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n"
+            + "        left join organize_user_rlat b on b.user_id = a.id\n"
+            + "        left join organize d on d.id = b.organize_id\n"
+            + "        left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n"
+            + "        where d.status = 1 and f.status = 1 and b.house_id = ? and b.write_type = ?  and (a.name like ? )\n"
+            + "        order by ifnull(b.updated,b.created) desc";
+
+        String sql3 = "SELECT\n" + "        *\n" + "        FROM t_plate\n" + "        WHERE `status`=:status AND\n"
+            + "        MBRWITHIN (\n" + "        GeomFromText(:requestCentre),\n" + "        t_plate.geo_polygons)";
+
+        Map<String, Object> reqData = new HashMap<>();
+        List<String> fromText = new ArrayList<>();
+        fromText.add("A");
+        fromText.add("B");
+        reqData.put("requestCentre", fromText);
+        reqData.put("status",1);
+        JdbcParamsModel model = basicBaseDao.commonParseSql(sql3, reqData);
         Assert.assertTrue(model.getSql().equals(okSql));
     }
 }

+ 1 - 1
elab-redis/src/main/java/com/elab/redis/config/CacheAutoConfiguration.java

@@ -54,7 +54,7 @@ public class CacheAutoConfiguration {
         template.setKeySerializer(new StringRedisSerializer());
         template.setValueSerializer(new CompatibilityJsonRedisSerializer());
         template.setHashKeySerializer(new StringRedisSerializer());
-        template.setHashValueSerializer(new CompatibilityJsonRedisSerializer());
+        template.setHashValueSerializer(new StringRedisSerializer());
         return template;
     }
 

+ 12 - 7
elab-redis/src/main/java/com/elab/redis/serializers/CompatibilityJsonRedisSerializer.java

@@ -7,7 +7,7 @@ import org.springframework.data.redis.serializer.SerializationException;
 
 /**
  * @Module redis序列化
- * @Description 通用的序列化类,兼容fastjson、jackson两个版本
+ * @Description 通用的序列化类, 兼容fastjson、jackson两个版本
  * @Author liukaixiong
  * @Date 2021/1/18 15:33
  */
@@ -17,13 +17,18 @@ public class CompatibilityJsonRedisSerializer extends GenericFastJsonRedisSerial
 
     @Override
     public Object deserialize(byte[] bytes) throws SerializationException {
-        Object deserialize = super.deserialize(bytes);
-        if (deserialize != null && deserialize instanceof JSONObject) {
-            String clazz = ((JSONObject) deserialize).getString("@class");
-            if (clazz != null) {
-                return redisSerializer.deserialize(bytes);
+        try {
+            Object deserialize = super.deserialize(bytes);
+            if (deserialize instanceof JSONObject) {
+                String clazz = ((JSONObject)deserialize).getString("@class");
+                if (clazz != null) {
+                    return redisSerializer.deserialize(bytes);
+                }
             }
+            return deserialize;
+        } catch (Exception e) {
+            // 出现未考虑场景,直接按照字符串处理
         }
-        return deserialize;
+        return new String(bytes);
     }
 }

+ 1 - 1
elab-redis/src/test/resources/application.yml

@@ -1,6 +1,6 @@
 spring:
   redis:
-    database: 6
+    database: 12
     host: r-uf6e60u5cmlj0sx563pd.redis.rds.aliyuncs.com
     password: xcGm4kTks6
     port: 6379

+ 2 - 2
pom.xml

@@ -35,7 +35,7 @@
         <springboot.version>2.0.5.RELEASE</springboot.version>
         <mysql.connector.version>5.1.38</mysql.connector.version>
         <druid.version>1.1.6</druid.version>
-        <fastjson.version>1.2.60</fastjson.version>
+        <fastjson.version>1.2.83</fastjson.version>
         <swagger_version>2.8.0</swagger_version>
     </properties>
 
@@ -335,7 +335,7 @@
             <dependency>
                 <groupId>com.jay.monitor.data</groupId>
                 <artifactId>jay-monitor-data-client</artifactId>
-                <version>1.1-SNAPSHOT</version>
+                <version>1.2-SNAPSHOT</version>
             </dependency>
         </dependencies>
     </dependencyManagement>