当前位置:网站首页>公司封装方式导出excel过程
公司封装方式导出excel过程
2022-08-03 01:00:00 【一条小咸鱼i】
文章目录
1、IPrinterInfoServiceRemote层
@ApiOperation(value = "个人测试-导出打印机信息excel")
@PostMapping("/export")
ResponseData<PrinterInfoExportFileAResp> exportPrinterInfoExportFile(@RequestBody RequestData<PrinterInfoExportFileAReq> req);
2、PrinterInfoServiceRemoteImpl层
此处的list中如果存在null的字段则会报空指针异常
@Override
public ResponseData<PrinterInfoExportFileAResp> exportPrinterInfoExportFile(RequestData<PrinterInfoExportFileAReq> req) {
//1、查询要导出的数据list
List<PrinterInfoListAResp> list = null;
//2、根据是否传入ids 判断要导出的数据列表 传入ids为null时输出 所有的数据 否则 输出相应的数据
if(req.getRequest().getIds().size() > 0){
list = printerInfoService.getListByIds(req.getRequest().getIds());
}else{
Example example = new Example(PrinterInfo.class, true, false);
example.createCriteria().andEqualTo(PrinterInfo.FIELD_MARK, MarkEnum.NO_DELETE.getCode());
List<PrinterInfo> listByExample = printerInfoService.getListByExample(example, null);
list = BeanCopyUtils.beanCopy(PrinterInfoListAResp.class, listByExample);
}
PrinterInfoExportFileAResp resp = PrinterInfoExportFileAResp.builder().exportUrl(printerInfoService.exportPrinterInfoURL(list)).build();
return RestResultGenerator.genSuccessResult(resp);
}
3、PrinterInfoService层
//todo 导出打印机信息 测试完后待删除
public String exportPrinterInfoURL(List<PrinterInfoListAResp> list) {
List<PrinterInfoBean> data = BeanCopyUtils.beanCopy(PrinterInfoBean.class, list);
try {
XSSFWorkbook workbook = PoiUtils.exportExcel(data, PrinterInfoBean.class, "打印机信息", true, 10000);
String staticPath = ClassUtils.getDefaultClassLoader().getResource("tmp").getPath();
File file = new File(staticPath + File.separator + DateUtils.convert2Str() +"打印机信息导出文件"+".xlsx");
FileOutputStream outputStream = new FileOutputStream(file);
workbook.write(outputStream);
workbook.close();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(file.getPath());
String url = AliyunOssUtils.uploadFile(stringBuilder.toString(), file);
file.delete();
return String.format("https://%s", url);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//todo 批量查询 测试完后待删除
public List<PrinterInfoListAResp> getListByIds(List<Long> ids) {
return printerInfoDao.batchGetListByIds(ids);
}
4、PrinterInfoDao层
public List<PrinterInfoListAResp> batchGetListByIds(List<Long> ids) {
return printerInfoMapper.batchGetListByIds(ids);
}
5、IPrinterInfoMapper层
List<PrinterInfoListAResp> batchGetListByIds(@Param(value = "ids") List<Long> ids);
6、mapper.xml层
<select id="batchGetListByIds" resultType="com.PrinterInfoListAResp">
SELECT DISTINCT
b.id,
a.data_name AS dataName,
b.printer_name AS printerName,
b.remark,
b.printer_ip AS printerIp,
b.printer_port AS printerPort,
b.printer_state AS printerState,
b.create_time AS createTime,
b.creator_name AS creatorName,
b.last_modified_time AS lastModifiedTime,
b.editor_name AS editorName
FROM
printer_info b
LEFT JOIN printer_config c ON c.printer_info_id = b.id
LEFT JOIN sys_dict_data a ON a.data_value = c.data_value AND a.dict_code = "B0041"
WHERE
b.mark = 1
and
b.id in
<foreach open="(" close=")" collection="ids" item="item" separator=",">
#{item}
</foreach>
ORDER BY
b.create_time DESC
</select>
7、pojo层
@Data
@Builder
public class PrinterInfoExportFileAResp extends BaseAResp{
/** * 导出文件阿里云url */
@ApiModelProperty(value = "导出文件阿里云url")
private String exportUrl;
}
@Data
public class PrinterInfoExportFileAReq extends BaseAReq{
@ApiModelProperty(value = "打印机id集合")
private List<Long> ids;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PrinterInfoBean {
/** * id */
@ExcelHeader(value = "id")
private Long id;
/** * 字典值 记录类型 */
@ExcelHeader(value = "记录类型")
private String dataName;
/** * 打印机名称 */
@ExcelHeader(value = "打印机名称")
private String printerName;
/** * 打印机描述 */
@ExcelHeader(value = "打印机描述")
private String remark;
/** * 打印机IP */
@ExcelHeader(value = "打印机IP")
private String printerIp;
/** * 打印机端口 */
@ExcelHeader(value = "打印机端口")
private String printerPort;
/** * 是否有效 0-否,1-是 */
@ExcelHeader(value = "是否有效 0-否,1-是")
private Integer printerState;
/** * 创建时间 记录插入时间 */
@ExcelHeader(value = "创建时间")
private Date createTime;
/** * 创建人姓名 */
@ExcelHeader(value = "创建人姓名")
private String creatorName;
/** * 更新时间 记录最后更新时间 */
@ExcelHeader(value = "修改时间")
private Date lastModifiedTime;
/** * 编辑人姓名 */
@ExcelHeader(value = "修改人姓名")
private String editorName;
}
边栏推荐
猜你喜欢

7.31

什么情况下DigiCert证书会引起发生安全警报?

华为防火墙双机热备技术:HRP、VGMP、VRRP,三大技术值得一学!

20、商品微服务-web层实现

全栈---Proxy

国标GB28181协议EasyGBS平台项目现场通知消息过多导致系统卡顿该如何解决?

Wireshark data capture and analysis of the transport layer protocol (TCP protocol)

6-接口跨域处理

SAP ABAP OData 服务如何支持修改(Update)操作试读版

Violence recursion to dynamic programming 08 (pony go chess)
随机推荐
[NCTF2019]SQLi-1||SQL注入
Linear DP
20、商品微服务-web层实现
流程控制for和while循环语句
并发模型和I/O模型介绍
科捷智能冲刺科创板:年营收12.8亿 顺丰与日日顺是股东
Violent recursion to dynamic programming 06 (the sword refers to Offer II 095. Longest common subsequence)
SAP ABAP OData 服务如何支持修改(Update)操作试读版
npm运行项目dependencies were not found: core-js/modules/es6.array.fill
2022-08-02:小红拿到了一个大立方体,该大立方体由1*1*1的小方块拼成,初始每个小方块都是白色。 小红可以每次选择一个小方块染成红色, 每次小红可能选择同一个小方块重复染色, 每次染色以后,
Guidelines for the use of SVA in UVM
Brute force recursion to dynamic programming 07 (516. Longest palindrome subsequence)
从一文中了解SSRF的各种绕过姿势及攻击思路
聊聊 Nacos
文树勋率长沙市人大常委会主任会议成员莅临麒麟信安调研数字经济发展情况
【飞控开发高级教程1】疯壳·开源编队无人机-飞控整机代码走读、编译与烧写
暴力递归到动态规划 07(516. 最长回文子序列)
全栈---JSONP
封装和练习题目
”QSqlDatabasePrivate::removeDatabase: connection ‘test-connect‘ is still in use“数据库多次打开报错