Browse Source

#work导出

zhongwei
yang_shj 10 months ago
parent
commit
c6e2b67d74
  1. 23
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/OperAccessLibraryController.java
  2. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessLibraryService.java
  3. 48
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/OperAccessLibraryServiceImpl.java
  4. BIN
      hzims-service/operational/src/main/resources/template/excel/access_import_template.xls
  5. 40
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java
  6. BIN
      hzims-service/ticket/src/main/resources/template/excel/work_task_template.xlsx
  7. BIN
      hzims-service/ticket/src/main/resources/template/work/work_task_template.docx

23
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/OperAccessLibraryController.java

@ -41,7 +41,7 @@ public class OperAccessLibraryController extends BladeController {
* 删除 * 删除
*/ */
@PostMapping("/remove") @PostMapping("/remove")
@ApiOperationSupport(order = 10) @ApiOperationSupport(order = 1)
@ApiOperation(value = "逻辑删除") @ApiOperation(value = "逻辑删除")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
return R.status(service.deleteLogic(Func.toLongList(ids))); return R.status(service.deleteLogic(Func.toLongList(ids)));
@ -51,7 +51,7 @@ public class OperAccessLibraryController extends BladeController {
* 新增 * 新增
*/ */
@PostMapping("/save") @PostMapping("/save")
@ApiOperationSupport(order = 20) @ApiOperationSupport(order = 2)
@ApiOperation(value = "新增") @ApiOperation(value = "新增")
public R save(@Valid @RequestBody OperAccessLibraryDTO req) { public R save(@Valid @RequestBody OperAccessLibraryDTO req) {
return service.doSave(req); return service.doSave(req);
@ -61,7 +61,7 @@ public class OperAccessLibraryController extends BladeController {
* 修改 * 修改
*/ */
@PostMapping("/update") @PostMapping("/update")
@ApiOperationSupport(order = 30) @ApiOperationSupport(order = 3)
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
public R update(@Valid @RequestBody OperAccessLibraryDTO req) { public R update(@Valid @RequestBody OperAccessLibraryDTO req) {
return service.doUpdateById(req); return service.doUpdateById(req);
@ -72,7 +72,7 @@ public class OperAccessLibraryController extends BladeController {
*/ */
@ApiLog @ApiLog
@GetMapping("/detail") @GetMapping("/detail")
@ApiOperationSupport(order = 40) @ApiOperationSupport(order = 4)
@ApiOperation(value = "详情") @ApiOperation(value = "详情")
public R<OperAccessLibraryVO> detail(@RequestParam Long id) { public R<OperAccessLibraryVO> detail(@RequestParam Long id) {
return service.detail(id); return service.detail(id);
@ -83,7 +83,7 @@ public class OperAccessLibraryController extends BladeController {
*/ */
@ApiLog @ApiLog
@GetMapping("/list") @GetMapping("/list")
@ApiOperationSupport(order = 50) @ApiOperationSupport(order = 5)
@ApiOperation(value = "分页 查询参数:emCode,gradeCode") @ApiOperation(value = "分页 查询参数:emCode,gradeCode")
@OperationAnnotation(moduleName = "检修管理",title = "检修库",operatorType = OperatorType.MOBILE,businessType = @OperationAnnotation(moduleName = "检修管理",title = "检修库",operatorType = OperatorType.MOBILE,businessType =
BusinessType.GENCODE, BusinessType.GENCODE,
@ -92,13 +92,10 @@ public class OperAccessLibraryController extends BladeController {
return service.list(req, query); return service.list(req, query);
} }
/** @ApiOperation(value = "导入模板下载")
* 导入数据 @ApiOperationSupport(order = 6)
*/ @PostMapping(value = "/template_download")
@ApiOperation(value = "导入Excel") public void downLoad() {
@ApiOperationSupport(order = 70) service.downLoad();
@PostMapping(value = "/importExcel")
public R importExcel(MultipartFile file) throws Exception {
return service.importExcel(file);
} }
} }

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessLibraryService.java

@ -26,5 +26,5 @@ public interface IOperAccessLibraryService extends BaseService<OperAccessLibrary
R<IPage<OperAccessLibraryVO>> list(OperAccessLibraryListDTO req, Query query); R<IPage<OperAccessLibraryVO>> list(OperAccessLibraryListDTO req, Query query);
R importExcel(MultipartFile file) throws Exception; void downLoad();
} }

48
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/OperAccessLibraryServiceImpl.java

@ -1,7 +1,6 @@
package com.hnac.hzims.operational.access.service.impl; package com.hnac.hzims.operational.access.service.impl;
import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.nacos.client.config.NacosConfigService; import com.alibaba.nacos.client.config.NacosConfigService;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -20,17 +19,20 @@ import com.hnac.hzims.operational.access.vo.OperAccessLibraryVO;
import com.hnac.hzims.operational.access.wrapper.OperAccessLibraryWrapper; import com.hnac.hzims.operational.access.wrapper.OperAccessLibraryWrapper;
import com.hnac.hzims.safeproduct.feign.IDangerSourceClient; import com.hnac.hzims.safeproduct.feign.IDangerSourceClient;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jfree.chart.util.ExportUtils;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -92,38 +94,16 @@ public class OperAccessLibraryServiceImpl extends BaseServiceImpl<OperAccessLibr
return R.data(pages); return R.data(pages);
} }
/**
*
* .
*/
@Override @Override
public R importExcel(MultipartFile file) throws Exception { public void downLoad() {
ImportParams params = new ImportParams(); ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
params.setHeadRows(2); HttpServletResponse response = servletRequestAttributes.getResponse();
List<OperAccessLibraryUpload> data = ExcelImportUtil.importExcel(file.getInputStream(), OperAccessLibraryUpload.class, params);
for (OperAccessLibraryUpload libraryExcel : data) {
try {
//数据校验
R<String> r = this.validExcel(libraryExcel);
if (r != null && r.getCode() != 500) {
return r;
}
//数据库操作 }
OperAccessLibraryDTO libraryDTO = BeanUtil.copy(libraryExcel, OperAccessLibraryDTO.class);
this.doSave(libraryDTO);
if (CollectionUtil.isNotEmpty(libraryExcel.getDetails())) {
List<OperAccessLibraryDetailEntity> libraryDetailEntities = libraryExcel.getDetails().stream().map(o -> {
OperAccessLibraryDetailEntity detailEntity = BeanUtil.copy(o, OperAccessLibraryDetailEntity.class);
detailEntity.setPid(libraryDTO.getId());
return detailEntity;
}).collect(Collectors.toList());
libraryDetailService.saveBatch(libraryDetailEntities);
}
} catch (Exception ex) {
throw new RuntimeException(String.format("第%s行导入数据异常!", counter), ex);
}
}
return R.success("OK");
}
/** /**
* 调整检修库明细 * 调整检修库明细

BIN
hzims-service/operational/src/main/resources/template/excel/access_import_template.xls

Binary file not shown.

40
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java

@ -1,6 +1,7 @@
package com.hnac.hzims.ticket.repair.service.impl; package com.hnac.hzims.ticket.repair.service.impl;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -12,13 +13,16 @@ import com.hnac.hzims.ticket.repair.service.IWorkTaskService;
import com.hnac.hzims.ticket.repair.vo.WorkTaskContentVO; import com.hnac.hzims.ticket.repair.vo.WorkTaskContentVO;
import com.hnac.hzims.ticket.repair.vo.WorkTaskPreviewVO; import com.hnac.hzims.ticket.repair.vo.WorkTaskPreviewVO;
import com.hnac.hzims.ticket.repair.vo.WorkTaskVO; import com.hnac.hzims.ticket.repair.vo.WorkTaskVO;
import com.hnac.hzims.ticket.utils.AsposeUtil;
import com.hnac.hzims.ticket.utils.ExcelUtil; import com.hnac.hzims.ticket.utils.ExcelUtil;
import com.hnac.hzims.ticket.utils.PdfUtils; import com.hnac.hzims.ticket.utils.PdfUtils;
import com.hnac.hzims.ticket.utils.WordUtils;
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService; import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
@ -39,6 +43,10 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*; import java.util.*;
/** /**
@ -57,8 +65,8 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
private final IUserClient userClient; private final IUserClient userClient;
@Value("${hzims.ticket.workTask.saveWrokTask.xlsx}") @Value("${hzims.ticket.workTask.saveWrokTask.work}")
private String saveWrokTaskXlsxPath; private String saveWrokTaskWorkPath;
@Value("${hzims.ticket.workTask.saveWrokTask.pdf}") @Value("${hzims.ticket.workTask.saveWrokTask.pdf}")
private String saveWrokTaskPdfPath; private String saveWrokTaskPdfPath;
@ -185,7 +193,7 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
//准备数据 //准备数据
WorkTaskPreviewVO preview = this.workTaskExport(id); WorkTaskPreviewVO preview = this.workTaskExport(id);
if(ObjectUtil.isEmpty(preview)){ if(ObjectUtil.isEmpty(preview)){
throw new ServiceException("查询应急抢修单失败"); throw new ServiceException("查询工作任务单失败");
} }
Map<String,Object> params = new HashMap<>(); Map<String,Object> params = new HashMap<>();
try { try {
@ -194,27 +202,15 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
}catch (Exception e) { }catch (Exception e) {
log.error("转换对象失败!"); log.error("转换对象失败!");
} }
TemplateExportParams templateExportParams = new TemplateExportParams("template/excel/work_task_template.xlsx", true); // 保存wrok至本地服务器
Workbook workbook = null; String fileName = preview.getCode() + "_工作任务单";
try { String path = WordUtils.uploadWord("/template/work/",saveWrokTaskWorkPath,params,"work_task_template",fileName);
workbook = ExcelUtil.getWorkbook(templateExportParams,params);
} catch (Exception e) {
e.printStackTrace();
}
//上传xlsx至服务器
String fileName = preview.getCode() + "_工作任务单" + PdfUtils.XLSX_SUFFIX;
try {
ExcelUtil.upload(workbook,saveWrokTaskXlsxPath,fileName);
} catch (Exception e) {
e.printStackTrace();
}
//将docx文件转换为pdf并保存 //将docx文件转换为pdf并保存
String pdfFileName = preview.getCode() + "_工作任务单" + PdfUtils.PDF_SUFFIX; String savePdfPath = saveWrokTaskPdfPath + preview.getCode() + "_工作任务单" + PdfUtils.PDF_SUFFIX;
String xlsxFileName = preview.getCode() + "_工作任务单" + PdfUtils.XLSX_SUFFIX; AsposeUtil.wordToPdf(path,savePdfPath);
PdfUtils.convertPdf(saveWrokTaskPdfPath, xlsxFileName, saveWrokTaskPdfPath, pdfFileName);
String savePath = saveWrokTaskPdfPath + pdfFileName;
// 设置response参数,可以打开下载页面 // 设置response参数,可以打开下载页面
PdfUtils.readPdf(response,savePath); PdfUtils.readPdf(response,savePdfPath);
} }
/** /**

BIN
hzims-service/ticket/src/main/resources/template/excel/work_task_template.xlsx

Binary file not shown.

BIN
hzims-service/ticket/src/main/resources/template/work/work_task_template.docx

Binary file not shown.
Loading…
Cancel
Save