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