| | |
| | | package com.ruoyi.inspect.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.aspose.words.License; |
| | | import com.aspose.words.SaveFormat; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | |
| | | import com.itextpdf.text.pdf.PdfContentByte; |
| | | import com.itextpdf.text.pdf.PdfReader; |
| | | import com.itextpdf.text.pdf.PdfStamper; |
| | | import com.ruoyi.basic.dto.IfsInventoryQuantitySupplierDto; |
| | | import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper; |
| | | import com.ruoyi.basic.pojo.IfsInventoryQuantity; |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.common.constant.MenuJumpPathConstants; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.domain.entity.InformationNotification; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.properties.WechatProperty; |
| | | import com.ruoyi.common.config.WechatProperty; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.api.IfsApiUtils; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.InsReportExport; |
| | | import com.ruoyi.inspect.dto.ReportPageDto; |
| | | import com.ruoyi.inspect.mapper.*; |
| | | import com.ruoyi.inspect.pojo.*; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | |
| | | private String wordUrl; |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | @Value("${file.licenseUrl}") |
| | | private String licenseUrl; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | @Resource |
| | |
| | | // todo: 仅看自己 |
| | | //获取当前人所属实验室id |
| | | String laboratory = null; |
| | | Integer createOrderUser = null; |
| | | |
| | | Integer createOrderUser = reportPageDto.getCreateOrderUser(); |
| | | String queryStatus = reportPageDto.getQueryStatus(); |
| | | reportPageDto.setQueryStatus(null); |
| | | reportPageDto.setCreateOrderUser(null); |
| | | |
| | | map.put("body", insReportMapper.pageInsReport(page, |
| | | QueryWrappers.queryWrappers(reportPageDto), |
| | |
| | | info.setSenderId(submitUserId); //发送人 |
| | | info.setConsigneeId(userId); //收件人 |
| | | info.setViewStatus(false); |
| | | info.setJumpPath("b1-report-preparation"); |
| | | info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); |
| | | informationNotificationService.addInformationNotification(info); |
| | | //系统生成报告地址 |
| | | String url = insReport.getUrl(); |
| | |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); |
| | | |
| | | String message = ""; |
| | | message += "报告编制审核退回通知"; |
| | | message += "耐丝系统报告编制审核退回通知"; |
| | | message += "\n审核人: " + checkUserName; |
| | | message += "\n委托编号: " + order.getEntrustCode(); |
| | | message += "\n样品名称: " + insSample.getModel(); |
| | |
| | | info.setSenderId(checkUserId); //发送人 |
| | | info.setConsigneeId(userId); //收件人 |
| | | info.setViewStatus(false); |
| | | info.setJumpPath("b1-report-preparation"); |
| | | info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); |
| | | informationNotificationService.addInformationNotification(info); |
| | | //系统生成报告地址 |
| | | String url = insReport.getUrl(); |
| | |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); |
| | | |
| | | String message = ""; |
| | | message += "报告编制批准通知"; |
| | | message += "耐丝系统报告编制批准通知"; |
| | | message += "\n检验人: " + userName; |
| | | message += "\n复核人: " + checkUserName; |
| | | message += "\n委托编号: " + order.getEntrustCode(); |
| | |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); |
| | | |
| | | String message = ""; |
| | | message += "报告编制批准退回通知"; |
| | | message += "耐丝系统报告编制批准退回通知"; |
| | | message += "\n批准人: " + ratifyUserName; |
| | | message += "\n委托编号: " + order.getEntrustCode(); |
| | | message += "\n样品名称: " + insSample.getModel(); |
| | |
| | | } |
| | | // 压缩临时文件夹 |
| | | zipFilePath = wordUrl + "/zip/output.zip"; |
| | | // 判断zip路径是否存在 |
| | | File zipDir = new File(wordUrl + "/zip"); |
| | | if(!zipDir.isDirectory()){ |
| | | zipDir.mkdirs(); |
| | | } |
| | | zipDirectory(tempFolderPath, zipFilePath); |
| | | |
| | | // 清理临时文件夹 |
| | |
| | | FileOutputStream os = null; |
| | | try { |
| | | //凭证 不然切换后有水印 |
| | | InputStream is = Files.newInputStream(new File(licenseUrl).toPath()); |
| | | InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); |
| | | License license = new License(); |
| | | license.setLicense(is); |
| | | if (!license.getIsLicensed()) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 报告报表导出 |
| | | * @param dto |
| | | * @param response |
| | | */ |
| | | @Override |
| | | public void reportAllExport(ReportPageDto dto, HttpServletResponse response) throws UnsupportedEncodingException { |
| | | |
| | | Integer createOrderUser = dto.getCreateOrderUser(); |
| | | String queryStatus = dto.getQueryStatus(); |
| | | dto.setQueryStatus(null); |
| | | dto.setCreateOrderUser(null); |
| | | |
| | | List<InsReportExport> insReportExports = insReportMapper.reportAllExport(QueryWrappers.queryWrappers(dto), |
| | | SecurityUtils.getUserId().intValue(), |
| | | queryStatus, |
| | | createOrderUser); |
| | | |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("报告报表导出", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | try { |
| | | //新建ExcelWriter |
| | | ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); |
| | | //获取sheet0对象 |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(0, "报告报表导出").head(InsReportExport.class).build(); |
| | | |
| | | //向sheet0写入数据 传入空list这样只导出表头 |
| | | excelWriter.write(insReportExports, mainSheet); |
| | | //关闭流 |
| | | excelWriter.finish(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 先修改采购订单批次号, 后进行移库操作 |
| | |
| | | FileOutputStream os = null; |
| | | try { |
| | | //凭证 不然切换后有水印 |
| | | InputStream is = Files.newInputStream(new File(licenseUrl).toPath()); |
| | | InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); |
| | | License license = new License(); |
| | | license.setLicense(is); |
| | | if (!license.getIsLicensed()) { |