|
@@ -3,10 +3,7 @@ package com.rongwei.bscommon.sys.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.aspose.cells.SaveFormat;
|
|
|
-import com.aspose.cells.Workbook;
|
|
|
-import com.aspose.cells.WorkbookDesigner;
|
|
|
+import com.aspose.cells.*;
|
|
|
import com.aspose.words.Document;
|
|
|
import com.aspose.words.MailMergeCleanupOptions;
|
|
|
import com.aspose.words.net.System.Data.DataRow;
|
|
@@ -16,13 +13,16 @@ import com.bsentity.domin.ComCustomerDo;
|
|
|
import com.bsentity.dto.ComExportMasterDto;
|
|
|
import com.bsentity.dto.ComProTempExcelDto;
|
|
|
import com.bsentity.dto.ComProductExportDto;
|
|
|
+import com.bsentity.dto.WFApproveDto;
|
|
|
import com.bsentity.vo.ComProTempWordVo;
|
|
|
import com.bsentity.vo.HashMapDataTableVo;
|
|
|
+import com.rongwei.bscommon.sys.dao.BusinessWfDao;
|
|
|
import com.rongwei.bscommon.sys.service.ComCustomerService;
|
|
|
import com.rongwei.bscommon.sys.service.ExportService;
|
|
|
import com.rongwei.bscommon.sys.utils.AsposeWordsUtils;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
-import lombok.Data;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -44,6 +44,44 @@ public class ExportServiceImpl implements ExportService {
|
|
|
|
|
|
@Autowired
|
|
|
private ComCustomerService comCustomerService;
|
|
|
+ @Autowired
|
|
|
+ private BusinessWfDao businessWfDao;
|
|
|
+
|
|
|
+ public static final List<String> TASK_CODE = new ArrayList<String>() {{
|
|
|
+ //开始
|
|
|
+ add("start___1687661176115");
|
|
|
+ //产品工程师
|
|
|
+ add("userTask___1687661259358");
|
|
|
+ //财务预估损失
|
|
|
+ add("userTask___1687661273552");
|
|
|
+ //产品经理/工艺经理审核
|
|
|
+ add("userTask___1687661310828");
|
|
|
+ //销售总监审核
|
|
|
+ add("userTask___1687661314113");
|
|
|
+ //财务总监审核
|
|
|
+ add("userTask___1687661318243");
|
|
|
+ //总经理审核
|
|
|
+ add("userTask___1687661337015");
|
|
|
+
|
|
|
+ }};
|
|
|
+
|
|
|
+ public static final String WF_CONCAT = "%s %s %s";
|
|
|
+
|
|
|
+ public static final Map<String, String> CHECK_BOX_CHECKED_MAP = new HashMap<String, String>() {{
|
|
|
+ put("是", "Check Box 13");
|
|
|
+ put("否", "Check Box 14");
|
|
|
+ // 上述为纠正措施
|
|
|
+ put("10", "Check Box 3"); //退回重新检验 Returned for Inspection
|
|
|
+ put("30", "Check Box 6"); //废料退回公司 Returns Valid
|
|
|
+ put("50", "Check Box 1"); //就地处理(报废)
|
|
|
+ put("90", "Check Box 7"); //顾客关系 Customer Relations
|
|
|
+ put("110", "Check Box 11"); //其它 Others
|
|
|
+ put("70", "Check Box 8"); //就地处理(打折)
|
|
|
+ put("20", "Check Box 4"); //承运商责任 Carrier/Vendor
|
|
|
+ put("40", "Check Box 5"); //市场部责任Sales/CSSR
|
|
|
+ put("80", "Check Box 9"); //就地处理(转其他客户)
|
|
|
+ put("100", "Check Box 10"); //信息仅供参考 Information Only
|
|
|
+ }};
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -110,31 +148,184 @@ public class ExportServiceImpl implements ExportService {
|
|
|
// 数据准备
|
|
|
ComProTempExcelDto comProTempExcelDto = getComProTempExcelVo(ids);
|
|
|
|
|
|
- Workbook wb = getWork(classPathResource , comProTempExcelDto );
|
|
|
+ Workbook wb = getWork(classPathResource, comProTempExcelDto);
|
|
|
|
|
|
wb.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
wb.dispose();
|
|
|
|
|
|
|
|
|
-
|
|
|
// 设置打印编号
|
|
|
- comCustomerService.updatePrintNoByIds(ids,"'"+comProTempExcelDto.getPrintNo()+"'");
|
|
|
+ comCustomerService.updatePrintNoByIds(ids, "'" + comProTempExcelDto.getPrintNo() + "'");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException("MAR单Excel导出异常");
|
|
|
+ }
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出客户申诉单
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void exportCustomerComplaintForm(String id, HttpServletResponse response) {
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ log.error("id为空");
|
|
|
+ throw new CustomException("id为空");
|
|
|
+ }
|
|
|
+ // 获取投诉主表信息
|
|
|
+ ComCustomerDo comCustomerDo = comCustomerService.getById(id);
|
|
|
+ if (comCustomerDo == null) {
|
|
|
+ log.error("无法获取到客诉单信息");
|
|
|
+ throw new CustomException("无法获取到客诉单信息");
|
|
|
+ }
|
|
|
+ // 客诉单明细信息
|
|
|
+ List<ComProductExportDto> comProductExportDtos = comCustomerService.getProductByIds(Arrays.asList(id));
|
|
|
+ // 获取流程节点信息
|
|
|
+ List<WFApproveDto> wfConsentSpYj = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(comCustomerDo.getProcessinstid())) {
|
|
|
+ wfConsentSpYj = businessWfDao.getWFConsentSpYj(comCustomerDo.getProcessinstid(), TASK_CODE);
|
|
|
+ }
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/customerComplaintForm.xlsx");
|
|
|
+ Workbook wb = new Workbook(classPathResource.getInputStream());
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner();
|
|
|
+ designer.setWorkbook(wb);
|
|
|
+ designer.setDataSource("COMNO", comCustomerDo.getComno());
|
|
|
+ designer.setDataSource("CUSTOMERNAME", comCustomerDo.getCustomername());
|
|
|
+ designer.setDataSource("COMDATE", comCustomerDo.getComdate());
|
|
|
+ designer.setDataSource("TAKEEFFECTDATE", comCustomerDo.getTakeeffectdate());
|
|
|
+ designer.setDataSource("COMMSG", comCustomerDo.getCommsg());
|
|
|
+ designer.setDataSource("CONFIRMCONTENT", comCustomerDo.getConfirmcontent());
|
|
|
+ designer.setDataSource("COMPUTECOSTRMB", comCustomerDo.getComputecostrmb());
|
|
|
+ designer.setDataSource("OTHERCOSTRMB", comCustomerDo.getOthercostrmb());
|
|
|
+ designer.setDataSource("TOTALCOSTRMB", comCustomerDo.getTotalcostrmb());
|
|
|
+ designer.setDataSource("COMPUTECOSTUSD", comCustomerDo.getComputecostusd());
|
|
|
+ designer.setDataSource("OTHERCOSTUSD", comCustomerDo.getOthercostusd());
|
|
|
+ designer.setDataSource("PRICETOTALUSD", comCustomerDo.getPricetotalusd());
|
|
|
+ /**************设置流程节点信息******************/
|
|
|
+ WFApproveDto wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(0))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("TJR", wfApproveDto.getApproveUser());
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(1))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SHR", wfApproveDto.getApproveUser());
|
|
|
+ //财务预估损失节点
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(2))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SSSPR", wfApproveDto.getApproveUser());
|
|
|
+ designer.setDataSource("SSSPSJ", wfApproveDto.getApproveDate());
|
|
|
+
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(3))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SP1", String.format(WF_CONCAT, wfApproveDto.getApproveComment(), wfApproveDto.getApproveUser(), wfApproveDto.getApproveDate()));
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(4))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SP2", String.format(WF_CONCAT, wfApproveDto.getApproveComment(), wfApproveDto.getApproveUser(), wfApproveDto.getApproveDate()));
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(5))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SP3", String.format(WF_CONCAT, wfApproveDto.getApproveComment(), wfApproveDto.getApproveUser(), wfApproveDto.getApproveDate()));
|
|
|
+ wfApproveDto = wfConsentSpYj.stream().filter(info -> info.getTaskCode().equals(TASK_CODE.get(6))).findFirst().orElse(new WFApproveDto());
|
|
|
+ designer.setDataSource("SP4", String.format(WF_CONCAT, wfApproveDto.getApproveComment(), wfApproveDto.getApproveUser(), wfApproveDto.getApproveDate()));
|
|
|
+
|
|
|
+ /**************设置流程节点信息结束****************/
|
|
|
+ // 子表数据
|
|
|
+ List<Map<String, Object>> listMap = new ArrayList<>();
|
|
|
+ Map<String, Object> dataMap;
|
|
|
+ for (ComProductExportDto comProductExportDto : comProductExportDtos) {
|
|
|
+ dataMap = new HashMap<>();
|
|
|
+ dataMap.put("NO", comProductExportDto.getNo());
|
|
|
+ dataMap.put("ORIORDERNO", comProductExportDto.getOriOrderNo());
|
|
|
+ dataMap.put("ALLOY", comProductExportDto.getAlloy());
|
|
|
+ dataMap.put("ISSTATUS", comProductExportDto.getIsStatus());
|
|
|
+ dataMap.put("SPECIFICATIONS", comProductExportDto.getSpecifications());
|
|
|
+ dataMap.put("VOLUMENO", comProductExportDto.getVolumeNo());
|
|
|
+ dataMap.put("COMWEIGHT", comProductExportDto.getComWeight());
|
|
|
+ dataMap.put("MRAWEIGHT", comProductExportDto.getMraWeight());
|
|
|
+ listMap.add(dataMap);
|
|
|
+ }
|
|
|
+ designer.setDataSource("LIST", new HashMapDataTableVo(listMap));
|
|
|
+ designer.setCalculateFormula(true);
|
|
|
+ designer.process();
|
|
|
+ AsposeWordsUtils.getExcelLicense();
|
|
|
+ Worksheet worksheet = wb.getWorksheets().get(0);
|
|
|
+ CheckBoxCollection checkBoxes = worksheet.getCheckBoxes();
|
|
|
+ // 获取单选框选中状态
|
|
|
+ List<String> checkBoxMap = getCheckBoxMap(comCustomerDo);
|
|
|
+ if (!checkBoxMap.isEmpty()) {
|
|
|
+ for (int i = 0; i < checkBoxes.getCount(); i++) {
|
|
|
+ checkBoxes.get(i).setValue(checkBoxMap.contains(checkBoxes.get(i).getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ response.setContentType("application/octet-stream;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=customerComplaintForm.pdf");
|
|
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+ PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
|
|
|
+ pdfSaveOptions.setOnePagePerSheet(true);
|
|
|
+ int[] autoDrawSheets = {3};
|
|
|
+ int[] showSheets = {0};
|
|
|
+ autoDraw(wb, autoDrawSheets);
|
|
|
+ //隐藏workbook中不需要的sheet页。
|
|
|
+ printSheetPage(wb, showSheets);
|
|
|
+ wb.save(response.getOutputStream(), pdfSaveOptions);
|
|
|
+ wb.dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error(e.getMessage());
|
|
|
throw new CustomException("MAR单Excel导出异常");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置单选框选中状态
|
|
|
+ *
|
|
|
+ * @param comCustomerDo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getCheckBoxMap(ComCustomerDo comCustomerDo) {
|
|
|
+ List<String> checkBoxName = new ArrayList<>();
|
|
|
+
|
|
|
+ checkBoxName.add(CHECK_BOX_CHECKED_MAP.get(comCustomerDo.getIseffective()));
|
|
|
+ if (comCustomerDo.getConresult() == null || comCustomerDo.getConresult().isEmpty()) {
|
|
|
+ return checkBoxName;
|
|
|
+ }
|
|
|
+ Arrays.asList(comCustomerDo.getConresult().split(",")).forEach(info -> {
|
|
|
+ checkBoxName.add(CHECK_BOX_CHECKED_MAP.get(info));
|
|
|
+ });
|
|
|
+ return checkBoxName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void autoDraw(Workbook wb, int[] page) {
|
|
|
+ if (null != page && page.length > 0) {
|
|
|
+ for (int i = 0; i < page.length; i++) {
|
|
|
+ wb.getWorksheets().get(i).getHorizontalPageBreaks().clear();
|
|
|
+ wb.getWorksheets().get(i).getVerticalPageBreaks().clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void printSheetPage(Workbook wb, int[] page) {
|
|
|
+ for (int i = 1; i < wb.getWorksheets().getCount(); i++) {
|
|
|
+ wb.getWorksheets().get(i).setVisible(false);
|
|
|
+ }
|
|
|
+ if (null == page || page.length == 0) {
|
|
|
+ wb.getWorksheets().get(0).setVisible(true);
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < page.length; i++) {
|
|
|
+ wb.getWorksheets().get(i).setVisible(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将数据塞入模板
|
|
|
- * @param classPathResource 模板
|
|
|
+ *
|
|
|
+ * @param classPathResource 模板
|
|
|
* @param comProTempExcelDto 业务数据
|
|
|
* @return 数据表
|
|
|
*/
|
|
|
- private Workbook getWork(ClassPathResource classPathResource, ComProTempExcelDto comProTempExcelDto) throws Exception{
|
|
|
+ private Workbook getWork(ClassPathResource classPathResource, ComProTempExcelDto comProTempExcelDto) throws Exception {
|
|
|
|
|
|
Workbook wb = new Workbook(classPathResource.getInputStream());
|
|
|
WorkbookDesigner designer = new WorkbookDesigner();
|
|
@@ -164,8 +355,8 @@ public class ExportServiceImpl implements ExportService {
|
|
|
dataMap.put("DEFECT",comProductExportDto.getDefect());
|
|
|
listMap.add(dataMap);
|
|
|
}
|
|
|
-
|
|
|
designer.setDataSource("LIST", new HashMapDataTableVo(listMap));
|
|
|
+ designer.setCalculateFormula(true);
|
|
|
designer.process();
|
|
|
return wb;
|
|
|
}
|