2525import com .alibaba .fastjson .JSONObject ;
2626
2727import apijson .demo .server .model .BaseModel ;
28+ import apijson .demo .server .model .Comment ;
29+ import zuo .biao .apijson .JSONResponse ;
2830import zuo .biao .apijson .Log ;
31+ import zuo .biao .apijson .RequestMethod ;
2932import zuo .biao .apijson .RequestRole ;
3033import zuo .biao .apijson .StringUtil ;
3134import zuo .biao .apijson .server .Function ;
35+ import zuo .biao .apijson .server .JSONRequest ;
3236import zuo .biao .apijson .server .NotNull ;
3337
3438
3741 */
3842public class DemoFunction extends Function implements FunctionList {
3943 private static final String TAG = "DemoFunction" ;
40-
44+
4145 private final HttpSession session ;
4246 public DemoFunction (HttpSession session ) {
4347 this .session = session ;
@@ -94,7 +98,7 @@ public Object invoke(JSONObject request, String function) throws Exception {
9498 }
9599
96100
97-
101+
98102 /**
99103 * @param request
100104 * @return
@@ -115,8 +119,8 @@ public Object verifyIdList(@NotNull JSONObject request, @NotNull String idList)
115119 }
116120 return null ;
117121 }
118-
119-
122+
123+
120124 /**
121125 * @param request
122126 * @return
@@ -137,9 +141,75 @@ public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList
137141 }
138142 return null ;
139143 }
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+ }
140211
141-
142-
212+
143213 /**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()"
144214 * @param request
145215 * @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃
@@ -149,7 +219,7 @@ public JSONArray getIdList(@NotNull JSONObject request) throws Exception {
149219 return new JSONArray (new ArrayList <Object >(Arrays .asList (12 , 15 , 301 , 82001 , 82002 , 38710 )));
150220 }
151221
152-
222+
153223 /**TODO 仅用来测试 "key-()":"verifyAccess()"
154224 * @param request
155225 * @return
@@ -163,10 +233,10 @@ public Object verifyAccess(@NotNull JSONObject request) throws Exception {
163233 }
164234 return null ;
165235 }
166-
167-
168-
169-
236+
237+
238+
239+
170240
171241 public double plus (@ NotNull JSONObject request , String i0 , String i1 ) {
172242 return request .getDoubleValue (i0 ) + request .getDoubleValue (i1 );
@@ -337,6 +407,6 @@ public double doubleValue(@NotNull JSONObject request, String value) {
337407 //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
338408
339409
340-
341-
410+
411+
342412}
0 commit comments