Procházet zdrojové kódy

增加数据完整性验证接口

zyl před 1 měsícem
rodič
revize
17e6fdd657

+ 7 - 0
liutongyi-admin/src/main/java/com/citygis/web/dataEncrypt/controller/JiaMiController.java

@@ -47,4 +47,11 @@ public class JiaMiController {
         return jiaMiService.dataCompleteness(jiaMi.getTableName(), jiaMi.getIdColumn());
     }
 
+    @ApiOperation("验证数据完整性")
+    @Log(title = "验证数据完整性", businessType = BusinessType.OTHER)
+    @PostMapping(value = "/verifyDataCompleteness")
+    public AjaxResult verifyDataCompleteness(@RequestBody JiaMi jiaMi) {
+        return jiaMiService.verifyDataCompleteness(jiaMi.getTableName(), jiaMi.getIdColumn());
+    }
+
 }

+ 3 - 0
liutongyi-admin/src/main/java/com/citygis/web/dataEncrypt/mapper/JiaMiMapper.java

@@ -19,4 +19,7 @@ public interface JiaMiMapper {
     List<LinkedHashMap<String, Object>> getData(String tableName);
 
     int updateData(@Param("tableName") String tableName,@Param("idColumn") String idColumn,@Param("hmacText") String hmacText,@Param("id") String id);
+
+    List<LinkedHashMap<String, Object>> getVerifyData(String tableName);
+
 }

+ 2 - 0
liutongyi-admin/src/main/java/com/citygis/web/dataEncrypt/service/JiaMiService.java

@@ -14,4 +14,6 @@ public interface JiaMiService {
 
     AjaxResult dataCompleteness(String tableName, String idColumn);
 
+    AjaxResult verifyDataCompleteness(String tableName, String idColumn);
+
 }

+ 33 - 0
liutongyi-admin/src/main/java/com/citygis/web/dataEncrypt/service/impl/JiaMiServiceImpl.java

@@ -11,6 +11,7 @@ import com.citygis.web.dataEncrypt.service.JiaMiService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 
@@ -52,6 +53,8 @@ public class JiaMiServiceImpl implements JiaMiService {
 
         dateBySql.forEach(map -> {
             StringBuilder text = new StringBuilder();
+            map.remove("HAMC_CODE");
+            map.remove("IS_ENCRYPT");
             map.forEach((key, value) -> {
                 if (text.length() > 0) {
                     text.append(",");
@@ -71,4 +74,34 @@ public class JiaMiServiceImpl implements JiaMiService {
         return AjaxResult.success("hmac运算:" + dateBySql.size() + "条");
     }
 
+    @Override
+    public AjaxResult verifyDataCompleteness(String tableName, String idColumn) {
+        List<String> errorData = new ArrayList<>();
+
+        List<LinkedHashMap<String, Object>> dateBySql = jiaMiMapper.getVerifyData(tableName);
+        dateBySql.forEach(map -> {
+            StringBuilder text = new StringBuilder();
+            String hamcCode = map.get("HAMC_CODE").toString();
+            map.remove("HAMC_CODE");
+            map.remove("IS_ENCRYPT");
+            map.forEach((key, value) -> {
+                if (text.length() > 0) {
+                    text.append(",");
+                }
+                text.append(value);
+            });
+            String result = text.toString();
+            // 处理 result,如保存到集合或输出
+            try {
+                String hmacText = dataEncryptService.generateHmac(result);
+                if (!hmacText.equals(hamcCode)) {
+                    errorData.add(map.get(idColumn).toString());
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+        return AjaxResult.success("验证运算:" + dateBySql.size() + "条,错误数据:" + errorData.size() + "条,id为--->", errorData);
+    }
+
 }

+ 4 - 0
liutongyi-admin/src/main/resources/mapper/JiaMiMapper.xml

@@ -20,5 +20,9 @@
         update ${tableName} set HAMC_CODE = #{hmacText} where ${idColumn} = #{id}
     </update>
 
+    <select id="getVerifyData" parameterType="String" resultType="java.util.LinkedHashMap">
+        select * from ${tableName} where HAMC_CODE is not null
+    </select>
+
 </mapper>