|
|
|
@ -2,6 +2,7 @@ package web.controller; |
|
|
|
|
|
|
|
|
|
import core.thrift.MyAsyncMethodCallback; |
|
|
|
|
import core.thrift.ThriftClientPool; |
|
|
|
|
import core.thrift.comment.QueryComment; |
|
|
|
|
import db.form.DBAction; |
|
|
|
|
import db.model.bilibili.DataModel; |
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
@ -33,11 +34,11 @@ import java.util.List; |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
@RequestMapping("/data") |
|
|
|
|
public class DataController extends TableController<DataModel, DataModelForm, DataService, OtherDataResult,DataTable<DataModel>> { |
|
|
|
|
public class DataController extends TableController<DataModel, DataModelForm, DataService, OtherDataResult, DataTable<DataModel>> { |
|
|
|
|
|
|
|
|
|
private final String regionJson = IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8")); |
|
|
|
|
|
|
|
|
|
private static final String key="regionJson"; |
|
|
|
|
private static final String key = "regionJson"; |
|
|
|
|
|
|
|
|
|
public DataController() throws IOException, InstantiationException, IllegalAccessException { |
|
|
|
|
super(); |
|
|
|
@ -54,10 +55,10 @@ public class DataController extends TableController<DataModel, DataModelForm, Da |
|
|
|
|
@RequestMapping(value = "count/{cid}") |
|
|
|
|
public Integer count(@PathVariable int cid) { |
|
|
|
|
try { |
|
|
|
|
MyAsyncMethodCallback<Integer> call= new MyAsyncMethodCallback<>(); |
|
|
|
|
ThriftClientPool.doExecute(client -> client.commentSum(cid,call)); |
|
|
|
|
MyAsyncMethodCallback<Integer> call = new MyAsyncMethodCallback<>(); |
|
|
|
|
ThriftClientPool.doExecute(client -> client.commentSum(cid, call),QueryComment.AsyncClient.class); |
|
|
|
|
return call.getResult(); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
@ -65,20 +66,20 @@ public class DataController extends TableController<DataModel, DataModelForm, Da |
|
|
|
|
|
|
|
|
|
@RequestMapping("download") |
|
|
|
|
public ResponseEntity export(DataModelForm form) throws Exception { |
|
|
|
|
if(StringUtils.isNotEmpty(form.getFileName())&&form.getCids()!=null&&!form.getCids().isEmpty()) { |
|
|
|
|
if (StringUtils.isNotEmpty(form.getFileName()) && form.getCids() != null && !form.getCids().isEmpty()) { |
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
|
|
|
|
headers.setContentDispositionFormData("attachment", form.getFileName()+".zip"); |
|
|
|
|
MyAsyncMethodCallback<String> call= new MyAsyncMethodCallback<>(); |
|
|
|
|
ThriftClientPool.doExecute(client -> client.download(form.getCids(),form.getFileName(),call)); |
|
|
|
|
String filePath=call.getResult(); |
|
|
|
|
if(filePath!=null) { |
|
|
|
|
headers.setContentDispositionFormData("attachment", form.getFileName() + ".zip"); |
|
|
|
|
MyAsyncMethodCallback<String> call = new MyAsyncMethodCallback<>(); |
|
|
|
|
ThriftClientPool.doExecute(client -> client.download(form.getCids(), form.getFileName(), call),QueryComment.AsyncClient.class); |
|
|
|
|
String filePath = call.getResult(); |
|
|
|
|
if (filePath != null) { |
|
|
|
|
return new ResponseEntity<>(FileUtils.readFileToByteArray(new File(filePath)), headers, HttpStatus.CREATED); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
return new ResponseEntity<>("弹幕下载失败", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
return new ResponseEntity("参数异常",HttpStatus.BAD_REQUEST); |
|
|
|
|
} else { |
|
|
|
|
return new ResponseEntity("参数异常", HttpStatus.BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -114,13 +115,13 @@ public class DataController extends TableController<DataModel, DataModelForm, Da |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected List<OtherDataResult> otherDatas(DataModelForm command) { |
|
|
|
|
return new ArrayList<OtherDataResult>(){{ |
|
|
|
|
return new ArrayList<OtherDataResult>() {{ |
|
|
|
|
add(new OtherDataResult()); |
|
|
|
|
}}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void setModel(Model model) { |
|
|
|
|
model.addAttribute(key,regionJson); |
|
|
|
|
model.addAttribute(key, regionJson); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|