| | |
| | | package com.ruoyi.inspect.service.impl; |
| | | |
| | | 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.ruoyi.basic.mapper.IfsInventoryQuantityMapper; |
| | | import com.ruoyi.basic.pojo.IfsInventoryQuantity; |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.constant.MenuJumpPathConstants; |
| | | 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 com.ruoyi.inspect.service.InsOrderService; |
| | | import com.ruoyi.inspect.service.InsReportService; |
| | | import com.ruoyi.inspect.mapper.InsUnqualifiedHandlerMapper; |
| | | import com.ruoyi.basic.vo.IfsInventoryQuantityVO; |
| | | import com.ruoyi.inspect.service.RawMaterialOrderService; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import com.ruoyi.system.service.InformationNotificationService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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; |
| | |
| | | * @createDate 2024-03-17 22:10:02 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> |
| | | implements InsReportService { |
| | | @Resource |
| | |
| | | private String wordUrl; |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | @Value("${file.licenseUrl}") |
| | | private String licenseUrl; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | @Resource |
| | |
| | | @Resource |
| | | private InsSampleUserMapper insSampleUserMapper; |
| | | |
| | | @Autowired |
| | | private RawMaterialOrderService rawMaterialOrderService; |
| | | |
| | | |
| | | @Override |
| | | public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) { |
| | |
| | | // 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); |
| | | |
| | | // 清理临时文件夹 |
| | | deleteDirectory(tempFolder); |
| | | |
| | | System.out.println("ZIP文件创建完成!"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | FileOutputStream os = null; |
| | | try { |
| | | //凭证 不然切换后有水印 |
| | | // InputStream is = this.getClass().getResourceAsStream("/lib/license.xml"); |
| | | // InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("license.xml"); |
| | | 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()) { |
| | | System.out.println("License验证不通过..."); |
| | | log.info("License验证不通过..."); |
| | | return null; |
| | | } |
| | | //生成一个空的PDF文件 |
| | |
| | | stamp.close(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void isRawMaterial(InsOrder insOrder) { |
| | | public void isRawMaterial(InsOrder insOrder,Boolean registerInsResults,Boolean hasExemption) { |
| | | IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() |
| | | .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); |
| | | if (Objects.isNull(one)) { |
| | |
| | | // 判断是否有不合格 |
| | | Long unqualifiedCount = getUnqualifiedCount(insOrder); |
| | | |
| | | if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1)) { |
| | | if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1) && registerInsResults) { |
| | | // 原材料移库 |
| | | toLocation = this.moveRawMaterial(one); |
| | | //如果是拆分的订单,则把拆分的所有批次都移库 |
| | | if(one.getIsSplitOrder()==1 && !hasExemption){ |
| | | //查询拆分订单详情 |
| | | List<IfsInventoryQuantityVO> ifsInventoryQuantityVOS = ifsInventoryQuantityMapper.selectSplitOrderList(one.getPartNo(), one.getLineNo(), one.getReleaseNo(), one.getReceiptNo(), one.getOrderNo()); |
| | | for (IfsInventoryQuantityVO vo : ifsInventoryQuantityVOS) { |
| | | //如果有委托单信息且合格,走登记后移库;如果没有,则走免检;不合格不做处理 |
| | | if(Objects.isNull(vo.getInsOrderId())){ |
| | | rawMaterialOrderService.rawOrderRelease(vo.getId(), vo.getPartDesc()); |
| | | }else if(Objects.equals(vo.getInsOrderId(),insOrder.getId())){ |
| | | toLocation = insOrderService.moveRawMaterial(one); |
| | | }else if(Objects.nonNull(vo.getInsResult()) && 1 == vo.getInsResult()){ |
| | | toLocation = insOrderService.moveRawMaterial(one); |
| | | } |
| | | } |
| | | }else{ |
| | | toLocation = insOrderService.moveRawMaterial(one); |
| | | } |
| | | } |
| | | |
| | | // 判断结束状态修改合格状态 |
| | |
| | | .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); |
| | | } |
| | | |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | // 企业微信通知 |
| | | String message = ""; |
| | | message += "检测结果提交通知"; |
| | | message += "\n批次号: " + one.getUpdateBatchNo(); |
| | | message += "\n零件号: " + one.getPartNo(); |
| | | message += "\n零件描述: " + one.getPartDesc(); |
| | | message += "\n供应商名称: " + one.getSupplierName(); |
| | | message += "\n抵达数量: " + one.getQtyArrived().stripTrailingZeros().toPlainString() + one.getBuyUnitMeas(); |
| | | // 发送企业inspectStatus信通知 |
| | | if (inspectStatus == 1) { |
| | | message += "\n检测结果: 合格"; |
| | | } else { |
| | | message += "\n检测结果: 不合格"; |
| | | } |
| | | WxCpUtils.informWebHook(wechatProperty.getExaminingUrl(), message); |
| | | }); |
| | | // threadPoolTaskExecutor.execute(() -> { |
| | | // // 企业微信通知 |
| | | // String message = ""; |
| | | // message += "检测结果提交通知"; |
| | | // message += "\n批次号: " + one.getUpdateBatchNo(); |
| | | // message += "\n零件号: " + one.getPartNo(); |
| | | // message += "\n零件描述: " + one.getPartDesc(); |
| | | // message += "\n供应商名称: " + one.getSupplierName(); |
| | | // message += "\n抵达数量: " + one.getQtyArrived().stripTrailingZeros().toPlainString() + one.getBuyUnitMeas(); |
| | | // // 发送企业inspectStatus信通知 |
| | | // if (inspectStatus == 1) { |
| | | // message += "\n检测结果: 合格"; |
| | | // } else { |
| | | // message += "\n检测结果: 不合格"; |
| | | // } |
| | | // WxCpUtils.informWebHook(wechatProperty.getExaminingUrl(), message); |
| | | // }); |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * ifs移库操作 |
| | | * @param one |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String moveRawMaterial(IfsInventoryQuantity one) { |
| | | String toLocation; |
| | | // 登记采购检验结果STD |
| | | if (one.getIsRegister().equals(0)) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("ORDER_NO", one.getOrderNo()); // 采购订单号 |
| | | map.put("LINE_NO", one.getLineNo()); // 行号 |
| | | map.put("RELEASE_NO", one.getReleaseNo()); // 下达号 |
| | | map.put("RECEIPT_NO", one.getReceiptNo()); // 接收号 |
| | | map.put("PURCH_QTY", one.getQtyToInspect()); // 要检验的采购数量 |
| | | resultList.add(map); |
| | | resultMap.put("RECORD_ID", UUID.randomUUID().toString()); |
| | | resultMap.put("SYSCODE", "LIMS"); |
| | | resultMap.put("SYSMODEL", "登记采购检验结果"); |
| | | resultMap.put("BATCH_INFO", resultList); |
| | | Result result = ifsApiUtils.getProcurementResults(JSONUtil.toJsonStr(resultMap)); |
| | | if (result.getCode() != 200) { |
| | | throw new ErrorException("IFS登记采购检验结果失败: " + result.getMessage()); |
| | | } |
| | | } |
| | | insOrderService.updateIfsInventoryQuantity(one.getId()); |
| | | /** |
| | | * TODO 后续需要调用IFS的接口 移入的库位号 toLocation |
| | | */ |
| | | // 检验后移库 |
| | | toLocation = "1301"; |
| | | Map<String, Object> moveResultMap = new HashMap<>(); |
| | | List<Map<String, Object>> moveResultList = new ArrayList<>(); |
| | | Map<String, Object> moveMap = new HashMap<>(); |
| | | moveMap.put("ORDER_NO", one.getOrderNo()); // 采购订单号 |
| | | moveMap.put("LINE_NO", one.getLineNo()); |
| | | moveMap.put("RELEASE_NO", one.getReleaseNo()); |
| | | moveMap.put("RECEIPT_NO", one.getReceiptNo()); |
| | | moveMap.put("PART_NO", one.getPartNo()); |
| | | moveMap.put("QTY", one.getQtyArrived()); |
| | | moveMap.put("LOCATION_NO", one.getLocationNo()); |
| | | moveMap.put("TO_LOCATION_NO", toLocation); |
| | | moveMap.put("LOT_BATCH_NO", one.getLotBatchNo()); |
| | | moveMap.put("SERIAL_NO", one.getSerialNo()); |
| | | moveMap.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo()); |
| | | moveMap.put("ENG_CHG_LEVEL", one.getEngChgLevel()); |
| | | moveMap.put("ACTIVITY_SEQ", one.getActivitySeq()); |
| | | moveResultList.add(moveMap); |
| | | moveResultMap.put("RECORD_ID", UUID.randomUUID().toString()); |
| | | moveResultMap.put("SYSCODE", "LIMS"); |
| | | moveResultMap.put("SYSMODEL", "检验后移库"); |
| | | moveResultMap.put("BATCH_INFO", moveResultList); |
| | | |
| | | Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap)); |
| | | // 如果有必须为零件指定批号报错需要重新提交移库信息去指定批号 |
| | | if (result1.getCode() != 200) { |
| | | String message = result1.getMessage(); |
| | | if (message.contains("必须为零件") && message.contains("指定批号")) { |
| | | updaeBatch(one, toLocation); |
| | | } else { |
| | | throw new ErrorException("IFS检验后移库失败: " + result1.getMessage()); |
| | | } |
| | | } |
| | | return toLocation; |
| | | } |
| | | |
| | | /** |
| | | * 退回到检验任务 |
| | | * @param id |
| | | * @return |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 先修改采购订单批次号, 后进行移库操作 |
| | | * @param one |
| | | * @param toLocation |
| | | * 报告报表导出 |
| | | * @param dto |
| | | * @param response |
| | | */ |
| | | private void updaeBatch(IfsInventoryQuantity one, String toLocation) { |
| | | if (one.getIsUpdateBatch().equals(0)) { |
| | | // 先修改批次号后进行移库 |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("ORDER_NO", one.getOrderNo()); // 采购订单号 |
| | | map.put("LINE_NO", one.getLineNo()); // 行号 |
| | | map.put("RELEASE_NO", one.getReleaseNo()); // 下达号 |
| | | map.put("RECEIPT_NO", one.getReceiptNo()); // 接收号 |
| | | map.put("PART_NO", one.getPartNo()); //零件号 |
| | | map.put("CONFIGURATION_ID", one.getConfigurationId()); // 配置标识 |
| | | map.put("LOCATION_NO", one.getLocationNo()); // 库位号 |
| | | map.put("LOT_BATCH_NO", one.getLotBatchNo());// 批次号 |
| | | map.put("NEW_LOT_BATCH_NO", one.getUpdateBatchNo()); // 目标批次号 |
| | | map.put("SERIAL_NO", one.getSerialNo()); // 序列号 |
| | | map.put("ENG_CHG_LEVEL", one.getEngChgLevel()); // 版本号 |
| | | map.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo()); // wdr号 |
| | | map.put("ACTIVITY_SEQ", one.getActivitySeq()); // 活动序号 |
| | | map.put("QTY_TO_CHANGE", one.getQtyArrived()); // 变更数量 |
| | | resultList.add(map); |
| | | resultMap.put("RECORD_ID", UUID.randomUUID().toString()); |
| | | resultMap.put("SYSCODE", "LIMS"); |
| | | resultMap.put("SYSMODEL", "修改采购订单批次号"); |
| | | resultMap.put("BATCH_INFO", resultList); |
| | | @Override |
| | | public void reportAllExport(ReportPageDto dto, HttpServletResponse response) throws UnsupportedEncodingException { |
| | | |
| | | Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap)); |
| | | Integer createOrderUser = dto.getCreateOrderUser(); |
| | | String queryStatus = dto.getQueryStatus(); |
| | | dto.setQueryStatus(null); |
| | | dto.setCreateOrderUser(null); |
| | | |
| | | if (result.getCode() != 200) { |
| | | throw new ErrorException("IFS修改批次号失败: " + result.getMessage()); |
| | | } |
| | | ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate() |
| | | .set(IfsInventoryQuantity::getIsUpdateBatch, 1) |
| | | .eq(IfsInventoryQuantity::getId, one.getId())); |
| | | 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("导出失败"); |
| | | } |
| | | |
| | | Map<String, Object> moveResultMap = new HashMap<>(); |
| | | List<Map<String, Object>> moveResultList = new ArrayList<>(); |
| | | Map<String, Object> moveMap = new HashMap<>(); |
| | | moveMap.put("ORDER_NO", one.getOrderNo()); // 采购订单号 |
| | | moveMap.put("LINE_NO", one.getLineNo()); |
| | | moveMap.put("RELEASE_NO", one.getReleaseNo()); |
| | | moveMap.put("RECEIPT_NO", one.getReceiptNo()); |
| | | moveMap.put("PART_NO", one.getPartNo()); |
| | | moveMap.put("QTY", one.getQtyArrived()); |
| | | moveMap.put("LOCATION_NO", one.getLocationNo()); |
| | | moveMap.put("TO_LOCATION_NO", toLocation); |
| | | moveMap.put("LOT_BATCH_NO", one.getUpdateBatchNo()); |
| | | moveMap.put("SERIAL_NO", one.getSerialNo()); |
| | | moveMap.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo()); |
| | | moveMap.put("ENG_CHG_LEVEL", one.getEngChgLevel()); |
| | | moveMap.put("ACTIVITY_SEQ", one.getActivitySeq()); |
| | | moveResultList.add(moveMap); |
| | | moveResultMap.put("RECORD_ID", UUID.randomUUID().toString()); |
| | | moveResultMap.put("SYSCODE", "LIMS"); |
| | | moveResultMap.put("SYSMODEL", "检验后移库"); |
| | | moveResultMap.put("BATCH_INFO", moveResultList); |
| | | |
| | | Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap)); |
| | | if (result1.getCode() != 200) { |
| | | throw new ErrorException("IFS检验后移库失败: " + result1.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | 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()) { |
| | | System.out.println("License验证不通过..."); |
| | | log.info("License验证不通过..."); |
| | | return null; |
| | | } |
| | | //生成一个空的PDF文件 |
| | |
| | | //要转换的word文件 |
| | | com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); |
| | | doc.save(os, SaveFormat.PDF); |
| | | String name = file.getName(); |
| | | return file.getName(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |