package cn.autoform.web.controller.excel;
|
|
|
import java.util.List;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import cn.autoform.excel.Excel;
|
import cn.autoform.factory.product.ProductMethod.IOType;
|
import cn.autoform.fw.exception.RestResult;
|
import cn.autoform.fw.utility.RestResultGenerator;
|
import cn.autoform.util.thread.Keys;
|
import cn.autoform.util.thread.ThreadData;
|
import cn.autoform.util.tool.JSONTool;
|
|
@RestController
|
public class ExcelController {
|
|
@Autowired
|
private Excel excel = null;
|
|
/**
|
* 导出模板
|
* @param formID
|
* @param tenantID
|
* @param
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${request.excel01}", method = RequestMethod.GET)
|
public RestResult<String> expMod(String formID, String tenantID, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
excel.expMod(formID, tenantID, request, response);
|
return RestResultGenerator.genSuccessResult(null);
|
}
|
|
/**
|
* 导出数据
|
* @param formID
|
* @param tenantID
|
* @param
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${request.excel02}", method = RequestMethod.GET)
|
public RestResult<String> expExcel(String formID, String tenantID, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
return RestResultGenerator.genSuccessResult(excel.expExcel(formID, tenantID, ThreadData.get(Keys.IO_FLAG), request, response));
|
}
|
|
/**
|
* 导入数据
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${request.excel03}", method = RequestMethod.POST)
|
public RestResult<String> impExcel(@RequestParam(value = "filename", required = false) MultipartFile file ,HttpServletRequest request, HttpServletResponse response) throws Exception {
|
String formID = request.getParameter("formID");
|
String tenantID = request.getParameter("tenantID");
|
String userName = request.getParameter("userName");
|
IOType flag = IOType.services;
|
return RestResultGenerator.genSuccessResult(excel.impExcel(file, formID, tenantID, userName, flag, request, response));
|
}
|
|
/**
|
* 子表单导入
|
*/
|
@RequestMapping(value = "${request.excel04}", method = RequestMethod.POST)
|
public RestResult<List<List<String>>> impSonExcel(@RequestParam(value = "formFileData", required = false) MultipartFile file ,HttpServletRequest request, HttpServletResponse response) throws Exception {
|
IOType flag = IOType.cloud;
|
String formID = request.getParameter("formID");
|
String tenantID = request.getParameter("tenantID");
|
String userName = request.getParameter("userName");
|
String rowNum = request.getParameter("rowNum");
|
Integer num = 0;
|
if(rowNum!=null){
|
int a = rowNum.indexOf("_");
|
num = Integer.parseInt(rowNum.substring(a+1, rowNum.length()));
|
}
|
return RestResultGenerator.genSuccessResult(excel.imgSonExcel(num,formID, tenantID,userName,file,flag, request, response));
|
}
|
|
|
/**
|
*
|
* 导出子表单模板
|
*/
|
@RequestMapping(value = "/excel/expSonExcel", method = RequestMethod.GET)
|
public RestResult<String> expSonExcel(String data,String formID, String tenantID,String number, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
System.out.println("formID:"+formID+"tenantID"+tenantID+"number"+number);
|
excel.expSonExcel(data,formID, tenantID, number, request, response);
|
return RestResultGenerator.genSuccessResult(null);
|
}
|
|
}
|