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

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 importExcel(MultipartFile file) throws Exception;
void downLoad();
}

46
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;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.nacos.client.config.NacosConfigService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
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.safeproduct.feign.IDangerSourceClient;
import org.apache.commons.lang.StringUtils;
import org.jfree.chart.util.ExportUtils;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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.List;
import java.util.Set;
@ -92,37 +94,15 @@ public class OperAccessLibraryServiceImpl extends BaseServiceImpl<OperAccessLibr
return R.data(pages);
}
/**
*
* .
*/
@Override
public R importExcel(MultipartFile file) throws Exception {
ImportParams params = new ImportParams();
params.setHeadRows(2);
List<OperAccessLibraryUpload> data = ExcelImportUtil.importExcel(file.getInputStream(), OperAccessLibraryUpload.class, params);
public void downLoad() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();
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;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
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.WorkTaskPreviewVO;
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.PdfUtils;
import com.hnac.hzims.ticket.utils.WordUtils;
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.mp.base.BaseServiceImpl;
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 javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
/**
@ -57,8 +65,8 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
private final IUserClient userClient;
@Value("${hzims.ticket.workTask.saveWrokTask.xlsx}")
private String saveWrokTaskXlsxPath;
@Value("${hzims.ticket.workTask.saveWrokTask.work}")
private String saveWrokTaskWorkPath;
@Value("${hzims.ticket.workTask.saveWrokTask.pdf}")
private String saveWrokTaskPdfPath;
@ -185,7 +193,7 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
//准备数据
WorkTaskPreviewVO preview = this.workTaskExport(id);
if(ObjectUtil.isEmpty(preview)){
throw new ServiceException("查询应急抢修单失败");
throw new ServiceException("查询工作任务单失败");
}
Map<String,Object> params = new HashMap<>();
try {
@ -194,27 +202,15 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
}catch (Exception e) {
log.error("转换对象失败!");
}
TemplateExportParams templateExportParams = new TemplateExportParams("template/excel/work_task_template.xlsx", true);
Workbook workbook = null;
try {
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();
}
// 保存wrok至本地服务器
String fileName = preview.getCode() + "_工作任务单";
String path = WordUtils.uploadWord("/template/work/",saveWrokTaskWorkPath,params,"work_task_template",fileName);
//将docx文件转换为pdf并保存
String pdfFileName = preview.getCode() + "_工作任务单" + PdfUtils.PDF_SUFFIX;
String xlsxFileName = preview.getCode() + "_工作任务单" + PdfUtils.XLSX_SUFFIX;
PdfUtils.convertPdf(saveWrokTaskPdfPath, xlsxFileName, saveWrokTaskPdfPath, pdfFileName);
String savePath = saveWrokTaskPdfPath + pdfFileName;
String savePdfPath = saveWrokTaskPdfPath + preview.getCode() + "_工作任务单" + PdfUtils.PDF_SUFFIX;
AsposeUtil.wordToPdf(path,savePdfPath);
// 设置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