Browse Source

新增获取单个查询的值、获取List的HashMap集方法

shudong 1 year ago
parent
commit
81631b4fb3

+ 38 - 6
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/common/dbhelper/DbHelper.java

@@ -315,12 +315,12 @@ public class DbHelper {
 //                }
 //                sb.append(")}");
 
-                if(!procurdeName.contains("map.")){
-                    procurdeName=procurdeName.replace("#{","#{map.");
+                if (!procurdeName.contains("map.")) {
+                    procurdeName = procurdeName.replace("#{", "#{map.");
                 }
-                if(procurdeName.contains("CURSOR")
-                        &&!procurdeName.contains("resultMap")){
-                    procurdeName=procurdeName.replace("CURSOR","CURSOR,resultMap=mapCus");
+                if (procurdeName.contains("CURSOR")
+                        && !procurdeName.contains("resultMap")) {
+                    procurdeName = procurdeName.replace("CURSOR", "CURSOR,resultMap=mapCus");
                 }
                 commonMapper.procedureCmd(procurdeName, objectHashMap);
                 return objectHashMap;
@@ -348,7 +348,7 @@ public class DbHelper {
      * @param list          参数对象
      * @return Map对象
      */
-    public Map excuteProcedure(String procedureName, List<ProcParamModel> list) {
+    public Map executeProcedure(String procedureName, List<ProcParamModel> list) {
         try {
             Map<String, Object> objectHashMap = new HashMap<>();
             StringBuilder sbProc = new StringBuilder();
@@ -380,4 +380,36 @@ public class DbHelper {
             throw new RuntimeException(e);
         }
     }
+
+    /**
+     * 获取单个查询的值
+     *
+     * @param sql 查询语句
+     * @return 返回第一条记录的第一列的第一个字段值,不存在或异常时返回空字符或null
+     */
+    public String getValue(String sql) {
+        String strResult = "";
+        try {
+            List<HashMap<String, Object>> newPage = commonMapper.query(sql);
+            strResult = (String) newPage.get(0).entrySet().iterator().next().getValue();
+        } catch (Exception e) {
+            strResult = null;
+        }
+        return strResult;
+    }
+
+    /**
+     * 获取List的HashMap集
+     *
+     * @param sql 查询语句
+     * @return
+     */
+    public List<HashMap<String, Object>> getList(String sql) {
+        try {
+            List<HashMap<String, Object>> hashMapList = commonMapper.query(sql);
+            return hashMapList;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 }