增加 首页导出

master
wangh 1 year ago
parent e57d2166e6
commit 09e5577cf4

File diff suppressed because one or more lines are too long

@ -17,6 +17,12 @@
<dependencies> <dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
<!-- Spring框架基本的核心工具 --> <!-- Spring框架基本的核心工具 -->
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>

@ -4,6 +4,7 @@ import com.haiwei.common.annotation.Excel;
import com.haiwei.common.annotation.Excel.ColumnType; import com.haiwei.common.annotation.Excel.ColumnType;
import com.haiwei.common.annotation.Excel.Type; import com.haiwei.common.annotation.Excel.Type;
import com.haiwei.common.annotation.Excels; import com.haiwei.common.annotation.Excels;
import com.haiwei.common.config.Global;
import com.haiwei.common.core.domain.AjaxResult; import com.haiwei.common.core.domain.AjaxResult;
import com.haiwei.common.core.text.Convert; import com.haiwei.common.core.text.Convert;
import com.haiwei.common.exception.UtilException; import com.haiwei.common.exception.UtilException;
@ -172,6 +173,14 @@ public class ExcelUtil_2<T> {
this.init(list, sheetName, title, Type.EXPORT); this.init(list, sheetName, title, Type.EXPORT);
return exportExcel(); return exportExcel();
} }
public static String getAbsoluteFilew(String filename) {
String downloadPath = Global.getDownloadPath() + filename;
File desc = new File(downloadPath);
if (!desc.getParentFile().exists()) {
desc.getParentFile().mkdirs();
}
return downloadPath;
}
/** /**
* listexcel * listexcel

@ -1,6 +1,20 @@
package com.haiwei.manage.controller; package com.haiwei.manage.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.haiwei.common.exception.BusinessException;
import com.haiwei.common.utils.poi.ExcelUtil_2;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -21,14 +35,13 @@ import com.haiwei.common.core.page.TableDataInfo;
/** /**
* Controller * Controller
* *
* @author wangh * @author wangh
* @date 2023-10-30 * @date 2023-10-30
*/ */
@Controller @Controller
@RequestMapping("/manage/record_report") @RequestMapping("/manage/record_report")
public class RecordTestReportController extends BaseController public class RecordTestReportController extends BaseController {
{
private String prefix = "manage/record_report"; private String prefix = "manage/record_report";
@Autowired @Autowired
@ -36,23 +49,22 @@ public class RecordTestReportController extends BaseController
@RequiresPermissions("manage:record_report:view") @RequiresPermissions("manage:record_report:view")
@GetMapping() @GetMapping()
public String record_report() public String record_report() {
{
return prefix + "/record_report"; return prefix + "/record_report";
} }
@GetMapping("/selectData") @GetMapping("/selectData")
public String record_piont_data() public String record_piont_data() {
{
return "manage/record_piont_data/record_piont_data"; return "manage/record_piont_data/record_piont_data";
} }
/** /**
* *
*/ */
@RequiresPermissions("manage:record_report:list") @RequiresPermissions("manage:record_report:list")
@PostMapping("/list") @PostMapping("/list")
@ResponseBody @ResponseBody
public TableDataInfo list(RecordTestReport recordTestReport) public TableDataInfo list(RecordTestReport recordTestReport) {
{
startPage(); startPage();
List<RecordTestReport> list = recordTestReportService.selectRecordTestReportList(recordTestReport); List<RecordTestReport> list = recordTestReportService.selectRecordTestReportList(recordTestReport);
return getDataTable(list); return getDataTable(list);
@ -63,21 +75,58 @@ public class RecordTestReportController extends BaseController
*/ */
@RequiresPermissions("manage:record_report:export") @RequiresPermissions("manage:record_report:export")
@Log(title = "实验报告", businessType = BusinessType.EXPORT) @Log(title = "实验报告", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export/{id}")
@ResponseBody @ResponseBody
public AjaxResult export(RecordTestReport recordTestReport) public AjaxResult export(@PathVariable("id") Long id) {
{ RecordTestReport recordTestReport = recordTestReportService.selectRecordTestReportById(id);
List<RecordTestReport> list = recordTestReportService.selectRecordTestReportList(recordTestReport); String targetFile = null;
ExcelUtil<RecordTestReport> util = new ExcelUtil<RecordTestReport>(RecordTestReport.class); WriteSheet sheet = null;
return util.exportExcel(list, "record_report"); ExcelWriter workBook = null;
OutputStream out = null;
try {
File file = new File("D:/moban/实验报告.xlsx");
//目标文件
targetFile = "实验报告.xlsx";
out = new FileOutputStream(ExcelUtil_2.getAbsoluteFilew(targetFile));
workBook = EasyExcel.write(out).withTemplate(file).build();
//创建工作表
sheet = EasyExcel.writerSheet().build();
//写入数据
HashMap<String, Object> map = new HashMap<>();
map.put("testData", recordTestReport.getTestData());
map.put("sampleName", recordTestReport.getSampleName());
map.put("entrustedUnit", recordTestReport.getEntrustedUnit());
map.put("testParam", recordTestReport.getTestParam());
map.put("inStatus", recordTestReport.getInStatus());
map.put("temperature", recordTestReport.getTemperature());
map.put("viscosity", recordTestReport.getViscosity());
map.put("weight", recordTestReport.getWeight());
map.put("testResults", recordTestReport.getTestResults());
workBook.fill(map, sheet);//单组
workBook.fill(recordTestReport.getRecordTestParamList(), sheet);//多组
workBook.finish();
out.flush();
} catch (Exception e) {
//log.error("导出Excel异常{}", e.getMessage());
throw new BusinessException("导出Excel失败请联系网站管理员");
} finally {
if (null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return AjaxResult.success(targetFile);
} }
/** /**
* *
*/ */
@GetMapping("/add") @GetMapping("/add")
public String add() public String add() {
{
return prefix + "/add"; return prefix + "/add";
} }
@ -88,8 +137,7 @@ public class RecordTestReportController extends BaseController
@Log(title = "实验报告", businessType = BusinessType.INSERT) @Log(title = "实验报告", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
@ResponseBody @ResponseBody
public AjaxResult addSave(RecordTestReport recordTestReport) public AjaxResult addSave(RecordTestReport recordTestReport) {
{
return toAjax(recordTestReportService.insertRecordTestReport(recordTestReport)); return toAjax(recordTestReportService.insertRecordTestReport(recordTestReport));
} }
@ -97,8 +145,7 @@ public class RecordTestReportController extends BaseController
* *
*/ */
@GetMapping("/edit/{objid}") @GetMapping("/edit/{objid}")
public String edit(@PathVariable("objid") Long objid, ModelMap mmap) public String edit(@PathVariable("objid") Long objid, ModelMap mmap) {
{
RecordTestReport recordTestReport = recordTestReportService.selectRecordTestReportById(objid); RecordTestReport recordTestReport = recordTestReportService.selectRecordTestReportById(objid);
mmap.put("recordTestReport", recordTestReport); mmap.put("recordTestReport", recordTestReport);
return prefix + "/edit"; return prefix + "/edit";
@ -111,8 +158,7 @@ public class RecordTestReportController extends BaseController
@Log(title = "实验报告", businessType = BusinessType.UPDATE) @Log(title = "实验报告", businessType = BusinessType.UPDATE)
@PostMapping("/edit") @PostMapping("/edit")
@ResponseBody @ResponseBody
public AjaxResult editSave(RecordTestReport recordTestReport) public AjaxResult editSave(RecordTestReport recordTestReport) {
{
return toAjax(recordTestReportService.updateRecordTestReport(recordTestReport)); return toAjax(recordTestReportService.updateRecordTestReport(recordTestReport));
} }
@ -121,10 +167,9 @@ public class RecordTestReportController extends BaseController
*/ */
@RequiresPermissions("manage:record_report:remove") @RequiresPermissions("manage:record_report:remove")
@Log(title = "实验报告", businessType = BusinessType.DELETE) @Log(title = "实验报告", businessType = BusinessType.DELETE)
@PostMapping( "/remove") @PostMapping("/remove")
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids) {
{
return toAjax(recordTestReportService.deleteRecordTestReportByIds(ids)); return toAjax(recordTestReportService.deleteRecordTestReportByIds(ids));
} }
} }

@ -23,7 +23,7 @@ public class RecordTestParam extends BaseEntity
private Long reportId; private Long reportId;
/** 采样时间 */ /** 采样时间 */
@Excel(name = "采样时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "采样时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date recordTime; private Date recordTime;
/** 进料预热温度 */ /** 进料预热温度 */

@ -60,8 +60,8 @@
url: prefix + "/list", url: prefix + "/list",
showSearch: false, showSearch: false,
showRefresh: false, showRefresh: false,
showToggle: false, // showToggle: false,
showColumns: false, // showColumns: false,
createUrl: prefix + "/add", createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}", updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove", removeUrl: prefix + "/remove",
@ -115,23 +115,26 @@
} }
}*/] }*/]
}; };
$.table.init(options); table= $.table.init(options);
}; };
var table;
/* 添加用户-选择用户-提交 */ /* 添加用户-选择用户-提交 */
function submitHandler(index, layero) { function submitHandler(index, layero) {
var rows = $.table.selectFirstColumns(); var rows = table.selectFirstColumns();
if (rows.length == 0) { if (rows.length == 0) {
$.modal.alertWarning("请至少选择一条记录"); $.modal.alertWarning("请至少选择一条记录");
return; return;
} }
$.modal.close(); $.modal.close();
// 父页面的方法
parent.selectUsers();
// 父页面的变量
parent.$('#userids').html(rows.join());
} }
<!-- laydate示例 --> <!-- laydate示例 -->
layui.use('laydate', function () { layui.use('laydate', function () {
var laydate = layui.laydate; var laydate = layui.laydate;

@ -230,7 +230,7 @@
}); });
function addColumn() { function addColumn() {
$.modal.open('选择数据', prefix + "/selectData", '900', '620', callback); $.modal.open('选择数据', prefix + "/selectData", '900', '620');
// //
// var count = $("#" + table.options.id).bootstrapTable('getData').length; // var count = $("#" + table.options.id).bootstrapTable('getData').length;
// sub.editColumn(); // sub.editColumn();
@ -256,7 +256,10 @@
} }
function callback(index, layero) { function callback(index, layero) {
console.log("进入了回调函数提交方法"+layero.toString()); console.log("进入了回调函数提交方法"+layero.toString());
// $.modal.close();
}
function selectUsers() {
alert("进入了回调函数提交方法")
} }
</script> </script>
</body> </body>

@ -35,7 +35,7 @@
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="manage:record_report:remove"> <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="manage:record_report:remove">
<i class="fa fa-remove"></i> 删除 <i class="fa fa-remove"></i> 删除
</a> </a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="manage:record_report:export"> <a class="btn btn-warning single disabled" onclick="exportExcel()" shiro:hasPermission="manage:record_report:export">
<i class="fa fa-download"></i> 导出 <i class="fa fa-download"></i> 导出
</a> </a>
</div> </div>
@ -123,6 +123,19 @@
}; };
$.table.init(options); $.table.init(options);
}); });
function exportExcel() {
var row =$.table.selectFirstColumns()
$.modal.loading("正在导出数据,请稍后...");
$.post(prefix + "/export/"+row, function(result) {
if (result.code == 0) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
});
}
</script> </script>
</body> </body>
</html> </html>
Loading…
Cancel
Save