Просмотр исходного кода

1:增加判断文本是否为json格式的判断方法。
2:代码调整

沈静伟 4 лет назад
Родитель
Сommit
f93b7c799e

+ 21 - 0
src/dsb/com/cnd3b/common/BaseClass.java

@@ -3,6 +3,9 @@
  */
 package com.cnd3b.common;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.data.db.SQLiteJDBC;
 import com.cnd3b.common.parameter.parameter;
 import com.cnd3b.utility.Sms;
@@ -227,4 +230,22 @@ public class BaseClass {
             sms.sendOutMsg(fphonenumber, msg);
         }
     }
+
+    public boolean isJSONObject(String jsonStr) {
+        try {
+            Object object = JSON.parse(jsonStr);
+            return object instanceof JSONObject;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    public boolean isJSONArray(String jsonStr) {
+        try {
+            Object object = JSON.parse(jsonStr);
+            return object instanceof JSONArray;
+        } catch (Exception e) {
+            return false;
+        }
+    }
 }

+ 4 - 1
src/dsb/com/cnd3b/restcontroller/customer/products/products.java

@@ -3,6 +3,7 @@ package com.cnd3b.restcontroller.customer.products;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.Controller;
+import com.cnd3b.common.D3BReturnObject_Err;
 import com.cnd3b.common.D3bException;
 import com.cnd3b.common.data.Row;
 import com.cnd3b.common.data.Rows;
@@ -104,7 +105,9 @@ public class products extends Controller {
         String fintroduction = content.getString("fintroduction", "tagents_product.fintroduction", "产品介绍");
         String fnotes = content.getString("fnotes", "tagents_product.fnotes", "备注");
         String ftag = content.getString("ftag", "tagents_product.ftag", "标签");
-
+        if(!isJSONArray(ftag)){
+            return new D3BReturnObject_Err().setErrMsg("ftag不是有效的JSONArray格式").toString();
+        }
         PaoSetRemote tagents_productSet = getP2ServerSystemPaoSet("tagents_product", "siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tagents_productid='" + tagents_productid + "'");
         PaoRemote tagents_product = null;
         if (tagents_productid <= 0 || tagents_productSet.isEmpty()) {

+ 1 - 1
src/dsb/com/cnd3b/restcontroller/customer/supplyanddemand/supplyanddemand.java

@@ -43,7 +43,7 @@ public class supplyanddemand extends Controller {
             if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
                 where.append(" and t1.ftype ='").append(whereObject.getString("ftype")).append("' ");
             }
-            if (whereObject.containsKey("fissupply")) {
+            if (whereObject.containsKey("fissupply") && !"".equals(whereObject.getString("fissupply"))) {
                 where.append(" and t1.fissupply =").append(whereObject.getBooleanValue("fissupply") ? 1 : 0);
             }
         }

+ 3 - 6
src/dsb/com/cnd3b/restcontroller/customer/tagents/tagents.java

@@ -65,12 +65,9 @@ public class tagents extends Controller {
             fchangemsgObject.checkStringLength("fdutyparagraph", "tagents.fdutyparagraph", "统一社会代码");//统一社会信用代码
             fchangemsgObject.checkStringLength("fbrand", "tagents.fbrand", "经营品牌");//统一社会信用代码
             fchangemsgObject.checkStringLength("fintroduction", "tagents.fintroduction", "公司介绍");//公司介绍
-            if (fchangemsgObject.containsKey("saleprodclass")) {
-                try {
-                    fchangemsgObject.getJSONArray("saleprodclass");
-                } catch (Exception e) {
-                    return new D3BReturnObject_Err().setErrMsg("saleprodclass不是有效的JSONArray格式").toString();
-                }
+
+            if (fchangemsgObject.containsKey("saleprodclass") && !isJSONArray(fchangemsgObject.getString("saleprodclass"))) {
+                return new D3BReturnObject_Err().setErrMsg("saleprodclass不是有效的JSONArray格式").toString();
             }
 
             dbConnect.runSqlUpdate("update tagents_msgchangeapp set fstatus='作废' where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and fstatus='申请'");

+ 5 - 25
src/dsb/com/cnd3b/restcontroller/enterprise/tagents/tagents.java

@@ -17,6 +17,7 @@ import p2.util.P2Exception;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 
 public class tagents extends Controller {
     public tagents(JSONObject content) {
@@ -159,12 +160,8 @@ public class tagents extends Controller {
             fchangemsgObject.checkStringLength("femail", "tagents.femail", "邮箱");//邮箱
             fchangemsgObject.checkStringLength("fdutyparagraph", "tagents.fdutyparagraph", "统一社会代码");//统一社会信用代码
             fchangemsgObject.checkStringLength("fbrand", "tagents.fbrand", "经营品牌");//统一社会信用代码
-            if (fchangemsgObject.containsKey("saleprodclass")) {
-                try {
-                    fchangemsgObject.getJSONArray("saleprodclass");
-                } catch (Exception e) {
-                    return new D3BReturnObject_Err().setErrMsg("saleprodclass不是有效的JSONArray格式").toString();
-                }
+            if (fchangemsgObject.containsKey("saleprodclass") && !isJSONArray(fchangemsgObject.getString("saleprodclass"))) {
+                return new D3BReturnObject_Err().setErrMsg("saleprodclass不是有效的JSONArray格式").toString();
             }
             if (tagentsid > 0) {
                 dbConnect.runSqlUpdate("update tagents_msgchangeapp set fstatus='作废' where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and fstatus='申请'");
@@ -223,27 +220,10 @@ public class tagents extends Controller {
             PaoRemote tagents = tagentsSet.getPao(0);
             JSONObject changemsgObject = JSONObject.parseObject(fchangemsg);
             Iterator it = changemsgObject.keySet().iterator();
+            List<String> fieldlist=Arrays.asList(getTableColumns("tagents"));
             while (it.hasNext()) {
                 String key = (String) it.next();
-                if ("saleprodclass".equalsIgnoreCase(key)) {
-                    try {
-                        changemsgObject.getJSONArray("saleprodclass");
-                    } catch (Exception e) {
-                        return new D3BReturnObject_Err().setErrMsg("saleprodclass不是有效的JSONArray格式").toString();
-                    }
-//                    //经营类目修改
-//                    JSONArray saleprodclassArray = changemsgObject.getJSONArray("saleprodclass");
-//                    PaoSetRemote tagents_prodclassSet = tagents.getPaoSet("$tagents_prodclass", "tagents_prodclass", "tagentsid=" + tagentsid);
-//                    tagents_prodclassSet.deleteAll();
-//                    for (Object saleprodclassObject : saleprodclassArray) {
-//                        String fprodclassname = (String) saleprodclassObject;
-//                        PaoRemote saleprodclassPao = tagents_prodclassSet.addAtEnd();
-//                        saleprodclassPao.setValue("tagentsid", tagentsid, 11L);
-//                        saleprodclassPao.setValue("siteid", siteid, 11L);
-//                        saleprodclassPao.setValue("fprodclassname", fprodclassname, 11L);
-//                    }
-                }
-                if (Arrays.asList(getTableColumns("tagents")).contains(key.toLowerCase())) {
+                if (fieldlist.contains(key.toLowerCase())) {
                     if (getTableColumnType("tagents", key.toLowerCase()).equals("datetime")) {
                         tagents.setValue(key, changemsgObject.getDate(key.toLowerCase()), 11L);
                     } else {

+ 1 - 1
src/dsb/com/cnd3b/restcontroller/system/system/SQL/附件信息调整.sql

@@ -1,3 +1,3 @@
 update tattachment
 set fdocument=$fdocument$,ownertable=$ownertable$ , ownerid=$ownerid$
-where siteid=$siteid$ and tattachmentid=$tattachmentid$
+where siteid=$siteid$ and (tattachmentid=$tattachmentid$ or fparentid=$tattachmentid$)