| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent afe38fd commit 4c4ed82
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,10 +25,14 @@ | |||
| 25 | 25 | import com.alibaba.fastjson.JSONObject; | |
| 26 | 26 | ||
| 27 | 27 | import apijson.demo.server.model.BaseModel; | |
| 28 | + import apijson.demo.server.model.Comment; | ||
| 29 | + import zuo.biao.apijson.JSONResponse; | ||
| 28 | 30 | import zuo.biao.apijson.Log; | |
| 31 | + import zuo.biao.apijson.RequestMethod; | ||
| 29 | 32 | import zuo.biao.apijson.RequestRole; | |
| 30 | 33 | import zuo.biao.apijson.StringUtil; | |
| 31 | 34 | import zuo.biao.apijson.server.Function; | |
| 35 | + import zuo.biao.apijson.server.JSONRequest; | ||
| 32 | 36 | import zuo.biao.apijson.server.NotNull; | |
| 33 | 37 | ||
| 34 | 38 | ||
@@ -37,7 +41,7 @@ | |||
| 37 | 41 | */ | |
| 38 | 42 | public class DemoFunction extends Function implements FunctionList { | |
| 39 | 43 | private static final String TAG = "DemoFunction"; | |
| 40 | - | ||
| 44 | + | ||
| 41 | 45 | private final HttpSession session; | |
| 42 | 46 | public DemoFunction(HttpSession session) { | |
| 43 | 47 | this.session = session; | |
@@ -94,7 +98,7 @@ public Object invoke(JSONObject request, String function) throws Exception { | |||
| 94 | 98 | } | |
| 95 | 99 | ||
| 96 | 100 | ||
| 97 | - | ||
| 101 | + | ||
| 98 | 102 | /** | |
| 99 | 103 | * @param request | |
| 100 | 104 | * @return | |
@@ -115,8 +119,8 @@ public Object verifyIdList(@NotNull JSONObject request, @NotNull String idList) | |||
| 115 | 119 | } | |
| 116 | 120 | return null; | |
| 117 | 121 | } | |
| 118 | - | ||
| 119 | - | ||
| 122 | + | ||
| 123 | + | ||
| 120 | 124 | /** | |
| 121 | 125 | * @param request | |
| 122 | 126 | * @return | |
@@ -137,9 +141,75 @@ public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList | |||
| 137 | 141 | } | |
| 138 | 142 | return null; | |
| 139 | 143 | } | |
| 144 | + | ||
| 145 | + /**判断array是否为空 | ||
| 146 | + * @param request | ||
| 147 | + * @param array | ||
| 148 | + * @return | ||
| 149 | + */ | ||
| 150 | + public int deleteChildComment(@NotNull JSONObject rq, @NotNull String toId) throws Exception { | ||
| 151 | + long tid = rq.getLongValue(toId); | ||
| 152 | + if (tid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { | ||
| 153 | + return 0; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + //递归获取到全部子评论id | ||
| 157 | + | ||
| 158 | + JSONRequest request = new JSONRequest(); | ||
| 159 | + | ||
| 160 | + //Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| 161 | + JSONRequest comment = new JSONRequest(); | ||
| 162 | + comment.put("id{}", getChildCommentIdList(tid)); | ||
| 163 | + request.put("Comment", comment); | ||
| 164 | + | ||
| 165 | + //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| 166 | + | ||
| 167 | + JSONObject rp = new DemoParser(RequestMethod.DELETE).setNoVerify(true).parseResponse(request); | ||
| 168 | + | ||
| 169 | + JSONObject c = rp.getJSONObject("Comment"); | ||
| 170 | + return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + | ||
| 174 | + private JSONArray getChildCommentIdList(long tid) { | ||
| 175 | + | ||
| 176 | + JSONArray arr = new JSONArray(); | ||
| 177 | + | ||
| 178 | + JSONRequest request = new JSONRequest(); | ||
| 179 | + | ||
| 180 | + //Comment-id[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| 181 | + JSONRequest idItem = new JSONRequest(); | ||
| 182 | + | ||
| 183 | + //Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| 184 | + JSONRequest comment = new JSONRequest(); | ||
| 185 | + comment.put("toId", tid); | ||
| 186 | + comment.setColumn("id"); | ||
| 187 | + idItem.put("Comment", comment); | ||
| 188 | + //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| 189 | + | ||
| 190 | + request.putAll(idItem.toArray(0, 0, "Comment-id")); | ||
| 191 | + //Comment-id[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| 192 | + | ||
| 193 | + JSONObject rp = new DemoParser().setNoVerify(true).parseResponse(request); | ||
| 194 | + | ||
| 195 | + JSONArray a = rp.getJSONArray("Comment-id[]"); | ||
| 196 | + if (a != null) { | ||
| 197 | + arr.addAll(a); | ||
| 198 | + | ||
| 199 | + JSONArray a2; | ||
| 200 | + for (int i = 0; i < a.size(); i++) { | ||
| 201 | + | ||
| 202 | + a2 = getChildCommentIdList(a.getLongValue(i)); | ||
| 203 | + if (a2 != null) { | ||
| 204 | + arr.addAll(a2); | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + return arr; | ||
| 210 | + } | ||
| 140 | 211 | ||
| 141 | - | ||
| 142 | - | ||
| 212 | + | ||
| 143 | 213 | /**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()" | |
| 144 | 214 | * @param request | |
| 145 | 215 | * @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃 | |
@@ -149,7 +219,7 @@ public JSONArray getIdList(@NotNull JSONObject request) throws Exception { | |||
| 149 | 219 | return new JSONArray(new ArrayList<Object>(Arrays.asList(12, 15, 301, 82001, 82002, 38710))); | |
| 150 | 220 | } | |
| 151 | 221 | ||
| 152 | - | ||
| 222 | + | ||
| 153 | 223 | /**TODO 仅用来测试 "key-()":"verifyAccess()" | |
| 154 | 224 | * @param request | |
| 155 | 225 | * @return | |
@@ -163,10 +233,10 @@ public Object verifyAccess(@NotNull JSONObject request) throws Exception { | |||
| 163 | 233 | } | |
| 164 | 234 | return null; | |
| 165 | 235 | } | |
| 166 | - | ||
| 167 | - | ||
| 168 | - | ||
| 169 | - | ||
| 236 | + | ||
| 237 | + | ||
| 238 | + | ||
| 239 | + | ||
| 170 | 240 | ||
| 171 | 241 | public double plus(@NotNull JSONObject request, String i0, String i1) { | |
| 172 | 242 | return request.getDoubleValue(i0) + request.getDoubleValue(i1); | |
@@ -337,6 +407,6 @@ public double doubleValue(@NotNull JSONObject request, String value) { | |||
| 337 | 407 | //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 338 | 408 | ||
| 339 | 409 | ||
| 340 | - | ||
| 341 | - | ||
| 410 | + | ||
| 411 | + | ||
| 342 | 412 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments