package com.fgkj.controller;
|
|
import com.fgkj.dto.DLG_Progress;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.services.ResDataUploadService;
|
import com.fgkj.util.*;
|
import com.google.gson.Gson;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpSession;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.util.Date;
|
|
import javax.annotation.Resource;
|
|
@RequestMapping("resDataUpload")
|
@RestController
|
@Api(tags = "resDataUpload接口")
|
public class ResDataUploadController{
|
|
/*private String tableRowData;
|
private int battgroupid;
|
private File[] file;
|
// 提交过来的file的名字
|
private String[] fileFileName;*/
|
|
@Resource
|
private ResDataUploadService service;
|
|
@PostMapping("uploadResFile")
|
@ApiOperation(notes = "",value="上传文件")
|
public boolean uploadResfile(@RequestParam String tableRowData,int battgroupid,File[] file,String[] fileFileName){
|
boolean res=false;
|
|
User_inf user=(User_inf)ActionUtil.getUser();
|
if(user!=null){
|
HttpSession session = ActionUtil.getSession();
|
Gson gson = new Gson();
|
createFile(file,fileFileName);
|
String[][] tableRowDatas = gson
|
.fromJson(tableRowData, String[][].class);
|
//System.out.println(file.length + "---" + tableRowDatas.length);
|
//uinf.setuId(1001);
|
|
/*ResDataUploadService rdus=new ResDataUploadService(user, battgroupid, tableRowDatas, file, session);
|
rdus.start();*/
|
service.uploadResFile(user, battgroupid, tableRowDatas, file, session);
|
res=true;
|
}
|
return res;
|
}
|
|
// 停止上传
|
@PutMapping("stopResUpload")
|
@ApiOperation(notes = "",value="停止上传")
|
public DLG_Progress stopResUpload() {
|
HttpSession session = ActionUtil.getSession();
|
DLG_Progress progress = (DLG_Progress) session.getAttribute("Resprogress");
|
if (progress != null) {
|
progress.setJudge(false);
|
}
|
return progress;
|
}
|
|
// 查询进度
|
@GetMapping("resProgress")
|
@ApiOperation(notes = "",value="查询进度")
|
public ServiceModel selectResprogress() {
|
ServiceModel model = new ServiceModel();
|
|
HttpSession session = ActionUtil.getSession();
|
DLG_Progress progress = (DLG_Progress) session.getAttribute("Resprogress");
|
// for(int i=0;i<progress.getTableData().length;i++){
|
// for(int j=0;j<progress.getTableData()[i].length;j++){
|
// System.out.print(progress.getTableData()[i][j]+"\t");
|
// }
|
// System.out.println();
|
// }
|
// System.out.println(progress+"**********");
|
if (progress != null) {
|
model.setCode(1);
|
model.setData(progress);
|
}
|
return model;
|
}
|
|
public void createFile(File[] file,String[] fileFileName){
|
String root = ActionUtil.getApplication().getRealPath(""); // 上传路径
|
//System.out.println(root);
|
for(int i=0;i<file.length;i++){
|
long times=new Date().getTime();
|
String savepath=root+"/"+times+fileFileName[i];
|
File f=new File(savepath);
|
FileInputStream fis=null;
|
FileOutputStream fos=null;
|
try {
|
if (!f.exists()) {
|
/** 创建此文件对象路径 */
|
f.createNewFile();
|
}
|
/** 创建输入流 */
|
fis = new FileInputStream(file[i]);
|
/** 输出流 更据文件的路径+文件名称创建文件对象 */
|
fos = new FileOutputStream(savepath);
|
/** 读取字节 */
|
byte b[] = new byte[1024];
|
int n = 0;
|
/** 读取操作 */
|
while ((n = fis.read(b)) != -1) {
|
/** 写操作 */
|
fos.write(b, 0, n);
|
}
|
fos.flush();
|
file[i]=f;
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally{
|
/** 关闭操作 */
|
try {
|
if (fis != null) {
|
fis.close();
|
}
|
if (fos != null) {
|
fos.close();
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
}
|