|
@@ -6,6 +6,8 @@ import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -19,6 +21,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.swing.filechooser.FileSystemView;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Service: tb_enterprise -- 商家
|
|
@@ -93,11 +97,15 @@ public class TbEnterpriseService extends ServiceImpl<TbEnterpriseMapper, TbEnter
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
- public String outportExcel(String keyword) throws IOException {
|
|
|
+ public String outportExcel(String keyword,String filepath) throws IOException {
|
|
|
System.out.println("\n开始执行文件导出....\n");
|
|
|
- //路径
|
|
|
- String localPath = "C:\\Users\\Administrator\\Desktop\\generate\\";
|
|
|
- String filepath = localPath + "商家数据表_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ".xlsx";
|
|
|
+ //导出的文件的路径
|
|
|
+ if(filepath == null){
|
|
|
+ // 获取当前用户的桌面路径
|
|
|
+ FileSystemView fileSystemView = FileSystemView.getFileSystemView();
|
|
|
+ filepath = fileSystemView.getHomeDirectory().getPath();
|
|
|
+ }
|
|
|
+ filepath = filepath + "\\商家数据表_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ".xlsx";
|
|
|
//根据需求查询数据
|
|
|
List<TbEnterprise> selectedList = tbEnterpriseMapper.selectList(new LambdaQueryWrapper<TbEnterprise>().eq(StringUtils.isNoneBlank(keyword), TbEnterprise::getName, keyword));
|
|
|
if(selectedList.size() == 0)return "没有可导出的数据。";
|
|
@@ -137,6 +145,8 @@ public class TbEnterpriseService extends ServiceImpl<TbEnterpriseMapper, TbEnter
|
|
|
row.createCell(27).setCellValue("更新人名称");
|
|
|
row.createCell(28).setCellValue("删除状态");
|
|
|
|
|
|
+ //定义计数器
|
|
|
+ int count = 0;
|
|
|
//遍历集合
|
|
|
for (int i = 0; i < selectedList.size(); i++) {
|
|
|
HSSFRow sheetRow = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
@@ -169,6 +179,7 @@ public class TbEnterpriseService extends ServiceImpl<TbEnterpriseMapper, TbEnter
|
|
|
sheetRow.createCell(26).setCellValue((selectedList.get(i).getUpdateBy() + "").equals("null")? "": selectedList.get(i).getUpdateBy() + "");
|
|
|
sheetRow.createCell(27).setCellValue((selectedList.get(i).getUpdateName() + "").equals("null")? "": selectedList.get(i).getUpdateName() + "");
|
|
|
sheetRow.createCell(28).setCellValue((selectedList.get(i).getDeleteStatus() + "").equals("null")? "": selectedList.get(i).getDeleteStatus() + "");
|
|
|
+ count += 1;
|
|
|
}
|
|
|
//建立输出流,输出文件
|
|
|
FileOutputStream fos = new FileOutputStream(filepath);
|
|
@@ -178,9 +189,10 @@ public class TbEnterpriseService extends ServiceImpl<TbEnterpriseMapper, TbEnter
|
|
|
//关闭输出流
|
|
|
fos.close();
|
|
|
workbook.close();
|
|
|
- System.out.println("\n数据导出完成!");
|
|
|
- return "数据导出完成!";
|
|
|
+ System.out.println("\n数据导出完成!共导出 " + count + " 条数据。");
|
|
|
+ return "数据导出完成!共导出 " + count + " 条数据。";
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|