opt:页面新增导出功能案例
This commit is contained in:
@@ -4,7 +4,9 @@ package org.nl.wms.basedata_manage.controller;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.common.base.TableDataInfo;
|
import org.nl.common.base.TableDataInfo;
|
||||||
@@ -15,7 +17,7 @@ import org.nl.common.utils.IdUtil;
|
|||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.language.LangBehavior;
|
import org.nl.language.LangBehavior;
|
||||||
import org.nl.wms.basedata_manage.service.IMdPbStoragevehicleinfoService;
|
import org.nl.wms.basedata_manage.service.IMdPbStoragevehicleinfoService;
|
||||||
import org.nl.wms.basedata_manage.service.dao.MdPbStoragevehicleinfo;
|
import org.nl.wms.system_manage.service.columnInfo.ColumnInfoService;
|
||||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||||
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateDtlService;
|
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateDtlService;
|
||||||
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
|
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
|
||||||
@@ -29,12 +31,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,6 +61,9 @@ public class GroupController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final IMdPbStoragevehicleinfoService iMdPbStoragevehicleinfoService;
|
private final IMdPbStoragevehicleinfoService iMdPbStoragevehicleinfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ColumnInfoService columnInfoService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Log("分页查询")
|
@Log("分页查询")
|
||||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
|
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
|
||||||
@@ -124,4 +128,32 @@ public class GroupController {
|
|||||||
public ResponseEntity<Object> getdtl(@PathVariable String id) {
|
public ResponseEntity<Object> getdtl(@PathVariable String id) {
|
||||||
return new ResponseEntity<>(iMdPbGroupplateService.getdtl(id), HttpStatus.OK);
|
return new ResponseEntity<>(iMdPbGroupplateService.getdtl(id), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/exportFile")
|
||||||
|
public void exportFile(@RequestBody Map whereJson, HttpServletResponse response) {
|
||||||
|
PageQuery page = new PageQuery();
|
||||||
|
page.setPage(0);
|
||||||
|
page.setSize(99999);
|
||||||
|
IPage<JSONObject> groupPlateIPage = iMdPbGroupplateService.queryAll(whereJson, page);
|
||||||
|
List<JSONObject> groupPlateList = groupPlateIPage.getRecords();
|
||||||
|
|
||||||
|
List<Map> maps = groupPlateList.stream().map(groupPlate -> {
|
||||||
|
try {
|
||||||
|
return groupPlate.toJavaObject(new TypeReference<Map<String, Object>>() {});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new HashMap();
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
try {
|
||||||
|
columnInfoService.exportFile("md_pb_groupplate", maps, response,
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("EXCEL 导出异常,异常原因=【{}】",e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,13 @@ export function getdtl(id) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function exportFile(query) {
|
||||||
|
return request({
|
||||||
|
url: 'api/group/exportFile',
|
||||||
|
method: 'post',
|
||||||
|
data: query,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default { add, edit, del, getdtl }
|
export default { add, edit, del, getdtl }
|
||||||
|
|||||||
@@ -59,7 +59,17 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||||
<crudOperation :permission="permission" />
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||||
|
<crudOperation :permission="permission">
|
||||||
|
<el-button
|
||||||
|
slot="right"
|
||||||
|
class="filter-item"
|
||||||
|
type="primary"
|
||||||
|
size="mini"
|
||||||
|
@click="exportExcel"
|
||||||
|
>导出excel
|
||||||
|
</el-button>
|
||||||
|
</crudOperation>
|
||||||
<!--新增表格-->
|
<!--新增表格-->
|
||||||
<el-dialog
|
<el-dialog
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
@@ -237,7 +247,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import crudGroup from '@/views/wms/basedata/group/group'
|
import crudGroup, { exportFile } from '@/views/wms/basedata/group/group'
|
||||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
import udOperation from '@crud/UD.operation'
|
import udOperation from '@crud/UD.operation'
|
||||||
@@ -298,6 +308,34 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 导出Excel功能
|
||||||
|
exportExcel() {
|
||||||
|
// 构建文件名称:仓位管理导出yyyymmdd.xlsx
|
||||||
|
const now = new Date()
|
||||||
|
const year = now.getFullYear()
|
||||||
|
const month = String(now.getMonth() + 1).padStart(2, '0')
|
||||||
|
const day = String(now.getDate()).padStart(2, '0')
|
||||||
|
const fileName = `组盘管理导出${year}${month}${day}.xlsx`
|
||||||
|
|
||||||
|
// 使用导入的exportFile方法调用后端接口
|
||||||
|
exportFile(this.query).then(res => {
|
||||||
|
// 创建Blob对象
|
||||||
|
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
||||||
|
// 创建下载链接
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = URL.createObjectURL(blob)
|
||||||
|
link.download = fileName
|
||||||
|
// 触发下载
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
// 清理
|
||||||
|
document.body.removeChild(link)
|
||||||
|
URL.revokeObjectURL(link.href)
|
||||||
|
this.crud.notify('导出成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
}).catch(() => {
|
||||||
|
this.crud.notify('导出失败', CRUD.NOTIFICATION_TYPE.ERROR)
|
||||||
|
})
|
||||||
|
},
|
||||||
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
||||||
[CRUD.HOOK.beforeRefresh]() {
|
[CRUD.HOOK.beforeRefresh]() {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user