3333
3434import apijson .demo .DemoParser ;
3535
36- import javax .imageio .ImageIO ;
37-
3836import static com .google .common .io .Files .getFileExtension ;
3937
4038/**文件相关的控制器,包括上传、下载、浏览等
@@ -134,7 +132,8 @@ public JSONObject upload(@RequestParam("file") MultipartFile file) {
134132 res .put ("path" , "/download/" + name );
135133 res .put ("size" , file .getBytes ().length );
136134 return new DemoParser ().extendSuccessResult (res );
137- } catch (Exception e ) {
135+ }
136+ catch (Exception e ) {
138137 e .printStackTrace ();
139138 return new DemoParser ().newErrorResult (e );
140139 }
@@ -204,9 +203,12 @@ private MediaType determineContentType(String fileName) {
204203 @ GetMapping ("/download/cv/report/{id}" )
205204 @ ResponseBody
206205 public ResponseEntity <Object > downloadCVReport (@ PathVariable (name = "id" ) String idStr , HttpSession session ) throws FileNotFoundException , IOException {
207- long reportId = Long .parseLong (idStr );
208- boolean isLast = reportId <= 0 ;
209- String name = "CVAuto_report_" + (isLast ? "last" : reportId ) + ".xlsx" ;
206+ long repOrDocId = Long .parseLong (idStr );
207+ if (repOrDocId <= 0 ) {
208+ throw new IllegalArgumentException ("id 必须为 > 0 的 reportId 或 documentId 有效整数!" );
209+ }
210+
211+ String name = "CVAuto_report_" + repOrDocId + ".xlsx" ;
210212 String path = fileUploadRootDir + name ;
211213 File file = new File (path );
212214 long size = file .exists () ? file .length () : 0 ;
@@ -219,22 +221,20 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
219221
220222 { // TestRecord <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
221223 JSONObject testRecord = new JSONObject ();
222- if (isLast ) {
223- testRecord .put ("@order" , "reportId-" );
224- } else {
225- testRecord .put ("reportId" , reportId );
226- }
224+ testRecord .put ("reportId" , repOrDocId );
225+ testRecord .put ("documentId" , repOrDocId );
226+ testRecord .put ("@combine" , "reportId,documentId" );
227227 testRecord .put ("@column" , "reportId,documentId,randomId,sameIds" );
228+ testRecord .put ("@order" , "reportId-" );
228229
229230 request .put ("TestRecord" , testRecord );
230231 } // TestRecord >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
231232
232233 { // [] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
233234 JSONObject item = new JSONObject ();
234- item .put ("count" , 3 );
235- // item.put("count", 0 );
235+ item .put ("count" , 0 );
236+ // item.put("count", 3 );
236237 item .put ("join" , "&/TestRecord" );
237- //item.put("join", "@/TestRecord");
238238
239239 { // Random <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
240240 JSONObject random = new JSONObject ();
@@ -250,19 +250,12 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
250250
251251 { // TestRecord <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
252252 JSONObject testRecord = new JSONObject ();
253- testRecord .put ("@column" , "id,total,correct,wrong,compare,response" );
253+ testRecord .put ("@column" , "id,total,correct,wrong,wrongs, compare,response" );
254254 testRecord .put ("randomId@" , "/Random/id" );
255255 testRecord .put ("documentId@" , "TestRecord/documentId" );
256+ testRecord .put ("reportId@" , "TestRecord/reportId" );
256257
257258 //testRecord.put("idx{}@", "TestRecord/sameIds");
258- if (isLast ) {
259- testRecord .put ("reportId@" , "TestRecord/reportId" );
260- //testRecord.put("@combine", "idx | reportId@");
261- } else {
262- testRecord .put ("reportId" , reportId );
263- //testRecord.put("@combine", "idx | reportId");
264- }
265- //testRecord.put("@key", "idx:(id)");
266259 //testRecord.put("@combine", "idx | reportId");
267260
268261 testRecord .put ("total>=" , 0 );
@@ -281,20 +274,17 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
281274
282275 { // TestRecord <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
283276 JSONObject testRecord = new JSONObject ();
284- testRecord .put ("@column" , "id,randomId,total,correct,wrong,compare,response" );
277+ testRecord .put ("@column" , "id,randomId,total,correct,wrong,wrongs, compare,response" );
285278 testRecord .put ("id{}@" , "TestRecord/sameIds" );
286279 testRecord .put ("documentId@" , "TestRecord/documentId" );
287- if (isLast ) {
288- testRecord .put ("reportId@" , "TestRecord/reportId" );
289- } else {
290- testRecord .put ("reportId" , reportId );
291- }
280+ // testRecord.put("reportId@", "TestRecord/reportId");
292281 testRecord .put ("total>=" , 0 );
293282 testRecord .put ("correct>=" , 0 );
294283 testRecord .put ("wrong>=" , 0 );
295284 testRecord .put ("@order" , "date-" );
296285
297286 item .put ("TestRecord" , testRecord );
287+ item .put ("count" , 0 );
298288 } // TestRecord >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
299289
300290 request .put ("TestRecord[]" , item );
@@ -307,16 +297,13 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
307297 throw new IOException (JSONResponse .getMsg (response ));
308298 }
309299
310- // JSONObject lastTr = response.getJSONObject("TestRecord");
311- // long documentId = lastTr == null ? 0 : lastTr.getLongValue("documentId");
312- // long randomId = lastTr == null ? 0 : lastTr.getLongValue("randomId");
313- if (isLast ) {
314- JSONObject lastTr = response .getJSONObject ("TestRecord" );
315- reportId = lastTr == null ? 0 : lastTr .getLongValue ("reportId" );
316- if (reportId > 0 ) {
317- name = "CVAuto_report_" + reportId + ".xlsx" ;
318- path = fileUploadRootDir + name ;
319- }
300+ JSONObject lastTr = response .getJSONObject ("TestRecord" );
301+ long reportId = lastTr == null ? 0 : lastTr .getLongValue ("reportId" );
302+ // long documentId = lastTr == null ? 0 : lastTr.getLongValue("documentId");
303+ // long randomId = lastTr == null ? 0 : lastTr.getLongValue("randomId");
304+ if (reportId != repOrDocId ) {
305+ name = "CVAuto_report_" + (reportId > 0 ? reportId : repOrDocId + "_last" ) + ".xlsx" ;
306+ path = fileUploadRootDir + name ;
320307 }
321308
322309 JSONArray array = response .getJSONArray ("[]" );
@@ -373,14 +360,15 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
373360 JSONObject renderReq = new JSONObject ();
374361 renderReq .put ("img" , img );
375362 renderReq .put ("data" , resObj );
363+ renderReq .put ("wrongs" , testRecord .getJSONArray ("wrongs" ));
376364 String body = renderReq .toJSONString ();
377365 HttpHeaders headers = new HttpHeaders ();
378366 String renderStr = demoController .sendRequest (session , HttpMethod .POST , "http://localhost:3003/cv/render" , body , headers );
379367 renderStr = StringUtil .trim (renderStr );
380368 if (renderStr .length () > 100 ) {
381369 File renderFile = new File (fileUploadRootDir + nfn );
382370 try (FileOutputStream fos = new FileOutputStream (renderFile )) {
383- int commaInd = renderStr .startsWith ("data:image/" ) ? - 1 : renderStr .indexOf ("base64," );
371+ int commaInd = renderStr .startsWith ("data:image/" ) ? renderStr .indexOf ("base64," ) : - 1 ;
384372 String base64 = commaInd < 0 ? renderStr : renderStr .substring (commaInd + "base64," .length ());
385373 byte [] bytes = Base64 .getDecoder ().decode (base64 );
386374 fos .write (bytes );
0 commit comments