|
@@ -4,6 +4,9 @@ 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.words.Document;
|
|
|
import com.aspose.words.MailMergeCleanupOptions;
|
|
|
import com.aspose.words.net.System.Data.DataRow;
|
|
@@ -11,12 +14,15 @@ import com.aspose.words.net.System.Data.DataTable;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.bsentity.domin.ComCustomerDo;
|
|
|
import com.bsentity.dto.ComExportMasterDto;
|
|
|
+import com.bsentity.dto.ComProTempExcelDto;
|
|
|
import com.bsentity.dto.ComProductExportDto;
|
|
|
import com.bsentity.vo.ComProTempWordVo;
|
|
|
+import com.bsentity.vo.HashMapDataTableVo;
|
|
|
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 org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -85,6 +91,173 @@ public class ExportServiceImpl implements ExportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * excel 导出
|
|
|
+ * @param ids
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void comProductListTempExcel(List<String> ids, HttpServletResponse response) {
|
|
|
+ AsposeWordsUtils.getExcelLicense();
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/comProductListTemp.xlsx");
|
|
|
+ try {
|
|
|
+
|
|
|
+ response.setContentType("application/octet-stream;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=comProductListTemp.xlsx");
|
|
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+
|
|
|
+ // 数据准备
|
|
|
+ ComProTempExcelDto comProTempExcelDto = getComProTempExcelVo(ids);
|
|
|
+
|
|
|
+ Workbook wb = getWork(classPathResource , comProTempExcelDto );
|
|
|
+
|
|
|
+ wb.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
+ wb.dispose();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 设置打印编号
|
|
|
+ comCustomerService.updatePrintNoByIds(ids,"'"+comProTempExcelDto.getPrintNo()+"'");
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException("MAR单Excel导出异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将数据塞入模板
|
|
|
+ * @param classPathResource 模板
|
|
|
+ * @param comProTempExcelDto 业务数据
|
|
|
+ * @return 数据表
|
|
|
+ */
|
|
|
+ private Workbook getWork(ClassPathResource classPathResource, ComProTempExcelDto comProTempExcelDto) throws Exception{
|
|
|
+
|
|
|
+ Workbook wb = new Workbook(classPathResource.getInputStream());
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner();
|
|
|
+ designer.setWorkbook(wb);
|
|
|
+ designer.setDataSource("PRINTNO", comProTempExcelDto.getPrintNo());
|
|
|
+ designer.setDataSource("CUSTOMERNAME", comProTempExcelDto.getCustomerName());
|
|
|
+ designer.setDataSource("COMNO", comProTempExcelDto.getComNo());
|
|
|
+ designer.setDataSource("CUSTOMERUSERNAME", comProTempExcelDto.getCustomerUserName());
|
|
|
+ designer.setDataSource("PRODUCTENGINEERNAME", comProTempExcelDto.getProductEngineerName());
|
|
|
+ designer.setDataSource("CUSTOMERPHONE", comProTempExcelDto.getCustomerPhone());
|
|
|
+ designer.setDataSource("CREATEUSERNAME", comProTempExcelDto.getCreatUserName());
|
|
|
+ designer.setDataSource("DATENOW", comProTempExcelDto.getDateNow());
|
|
|
+ designer.setDataSource("TOTALMARWEIGHT", comProTempExcelDto.getTotalMraWeight());
|
|
|
+
|
|
|
+ // 子表数据
|
|
|
+ List<Map<String, Object>> listMap = new ArrayList<>();
|
|
|
+ Map<String, Object> dataMap;
|
|
|
+ List<ComProductExportDto> comProductExportDtos = comProTempExcelDto.getComProductExportDtos();
|
|
|
+ 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("MRAWEIGHT",comProductExportDto.getMraWeight());
|
|
|
+ dataMap.put("DEFECT",comProductExportDto.getDefect());
|
|
|
+ listMap.add(dataMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ designer.setDataSource("LIST", new HashMapDataTableVo(listMap));
|
|
|
+ designer.process();
|
|
|
+ return wb;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据准备
|
|
|
+ * @param ids 主表ids集合
|
|
|
+ * @return 模板数据
|
|
|
+ */
|
|
|
+ private ComProTempExcelDto getComProTempExcelVo(List<String> ids) {
|
|
|
+ ComProTempExcelDto comProTempExcelDto = new ComProTempExcelDto();
|
|
|
+ if (ArrayUtil.isEmpty(ids)) {
|
|
|
+ return comProTempExcelDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询主表信息
|
|
|
+ ComExportMasterDto comExportMasterDto = comCustomerService.getCustomerByIds(ids);
|
|
|
+ if (ObjectUtil.isEmpty(comExportMasterDto)) {
|
|
|
+ return comProTempExcelDto;
|
|
|
+ }
|
|
|
+ // 数据转换
|
|
|
+ comDtos(comProTempExcelDto , comExportMasterDto);
|
|
|
+
|
|
|
+
|
|
|
+ /************************************ 子表信息 *****************************/
|
|
|
+
|
|
|
+ // 根据id 查询 客诉单信息
|
|
|
+ List<ComProductExportDto> comProductExportDtos = comCustomerService.getProductByIds(ids);
|
|
|
+ if (ArrayUtil.isEmpty(comProductExportDtos)) {
|
|
|
+ return comProTempExcelDto;
|
|
|
+ }
|
|
|
+ comProTempExcelDto.setComProductExportDtos(comProductExportDtos);
|
|
|
+
|
|
|
+
|
|
|
+ // 计算 MRA重量总和
|
|
|
+ BigDecimal totalMraWeight = comProductExportDtos.stream().map(ComProductExportDto::getMraWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ comProTempExcelDto.setTotalMraWeight(totalMraWeight);
|
|
|
+
|
|
|
+ return comProTempExcelDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据转换
|
|
|
+ * @param comProTempExcelDto 模板数据
|
|
|
+ * @param comExportMasterDto 主表数据
|
|
|
+ */
|
|
|
+ private void comDtos(ComProTempExcelDto comProTempExcelDto, ComExportMasterDto comExportMasterDto) {
|
|
|
+ String printNo = null;
|
|
|
+ // 最大 打印号
|
|
|
+ ComCustomerDo comCustomerDo = comCustomerService.getBaseMapper()
|
|
|
+ .selectOne(
|
|
|
+ new LambdaQueryWrapper<ComCustomerDo>()
|
|
|
+ .select(ComCustomerDo::getPrintNo)
|
|
|
+ .orderByDesc(ComCustomerDo::getPrintNo)
|
|
|
+ .last("LIMIT 1")
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ // 编号:规则(MRA+年份+序号)。例如,当年导出的第一个MRA就是MRA23001,导出的第二个就是MRA23002,按照年份以此递增
|
|
|
+ String year = String.valueOf(DateUtil.year(new Date())).substring(2);
|
|
|
+ if (ObjectUtil.isEmpty(comCustomerDo)) {
|
|
|
+ printNo = "MRA" + year + "001";
|
|
|
+ }else {
|
|
|
+ printNo = comCustomerDo.getPrintNo();
|
|
|
+ // 不为空
|
|
|
+ String number = printNo.substring(3);
|
|
|
+ Integer no = Integer.parseInt(number) + 1;
|
|
|
+ String y = String.valueOf(no).substring(0, 2);
|
|
|
+ // 跨年了。年份加一,从001开始计算
|
|
|
+ if (y.equals(year)) {
|
|
|
+ // 未跨年
|
|
|
+ printNo = "MRA" + no;
|
|
|
+ } else {
|
|
|
+ printNo = "MRA" + year + "001";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 赋值
|
|
|
+ comProTempExcelDto.setPrintNo(printNo);
|
|
|
+ comProTempExcelDto.setComNo(comExportMasterDto.getComNo());
|
|
|
+ comProTempExcelDto.setCustomerUserName(comExportMasterDto.getCustomerUserName());
|
|
|
+ comProTempExcelDto.setCustomerName(comExportMasterDto.getCustomerName());
|
|
|
+ comProTempExcelDto.setCustomerPhone(comExportMasterDto.getCustomerPhone());
|
|
|
+ comProTempExcelDto.setCreatUserName(comExportMasterDto.getCreateUserName());
|
|
|
+ comProTempExcelDto.setDateNow(DateUtil.formatDate(comExportMasterDto.getDateNow()));
|
|
|
+ comProTempExcelDto.setProductEngineerName(comExportMasterDto.getProductEngineerName());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 数据准备
|
|
|
*
|