From ec1f20c31d64ddbc5242c3942902bc5233a8a140 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期五, 18 四月 2025 10:40:34 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev_ztzb' into dev_ztzb --- inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java | 2377 ++++++++++++++++++++++++++++++----------------------------- 1 files changed, 1,214 insertions(+), 1,163 deletions(-) diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java index 45ef235..9c08968 100644 --- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java +++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java @@ -1,1163 +1,1214 @@ -//package com.ruoyi.inspect.service.impl; -// -//import cn.hutool.core.util.StrUtil; -//import cn.hutool.json.JSONUtil; -//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -//import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -//import com.baomidou.mybatisplus.core.toolkit.StringUtils; -//import com.baomidou.mybatisplus.core.toolkit.Wrappers; -//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -//import com.deepoove.poi.XWPFTemplate; -//import com.deepoove.poi.data.Pictures; -//import com.ruoyi.common.properties.WechatProperty; -//import com.ruoyi.common.utils.QueryWrappers; -//import com.ruoyi.inspect.dto.ReportPageDto; -//import com.ruoyi.inspect.mapper.InsOrderStateMapper; -//import com.ruoyi.inspect.mapper.InsProductMapper; -//import com.ruoyi.inspect.mapper.InsReportMapper; -//import com.ruoyi.inspect.mapper.InsUnqualifiedRetestProductMapper; -//import com.ruoyi.inspect.pojo.InsReport; -//import com.ruoyi.inspect.service.InsOrderService; -//import com.ruoyi.inspect.service.InsReportService; -//import com.ruoyi.system.mapper.UserMapper; -//import org.apache.poi.xwpf.usermodel.*; -//import org.springframework.beans.factory.annotation.Value; -//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -//import org.springframework.stereotype.Service; -//import org.springframework.transaction.annotation.Transactional; -//import org.springframework.web.multipart.MultipartFile; -// -//import javax.annotation.Resource; -//import javax.imageio.ImageIO; -//import java.awt.image.BufferedImage; -//import java.io.*; -//import java.nio.file.Files; -//import java.nio.file.Path; -//import java.nio.file.Paths; -//import java.nio.file.StandardCopyOption; -//import java.time.LocalDateTime; -//import java.time.format.DateTimeFormatter; -//import java.util.*; -//import java.util.stream.Collectors; -//import java.util.zip.ZipEntry; -//import java.util.zip.ZipFile; -//import java.util.zip.ZipOutputStream; -// -///** -// * @author Administrator -// * @description 閽堝琛ㄣ�恑ns_report(妫�楠屾姤鍛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇 -// * @createDate 2024-03-17 22:10:02 -// */ -//@Service -//public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> -// implements InsReportService { -// -// @Resource -// private GetLook getLook; -// @Resource -// private UserMapper userMapper; -// @Resource -// private InsReportMapper insReportMapper; -// @Resource -// private InsOrderStateMapper insOrderStateMapper; -// @Resource -// private InsProductMapper insProductMapper; -// @Resource -// private InformationNotificationService informationNotificationService; -// @Value("${wordUrl}") -// private String wordUrl; -// @Value("${file.path}") -// private String imgUrl; -// @Value("${file.licenseUrl}") -// private String licenseUrl; -// @Resource -// private InsOrderMapper insOrderMapper; -// @Resource -// private IfsInventoryQuantityMapper ifsInventoryQuantityMapper; -// @Resource -// private InsUnqualifiedHandlerMapper insUnqualifiedHandlerMapper; -// @Resource -// private InsSampleMapper insSampleMapper; -// @Resource -// private ThreadPoolTaskExecutor threadPoolTaskExecutor; -// @Resource -// private InsOrderService insOrderService; -// @Resource -// private WechatProperty wechatProperty; -// @Resource -// private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper; -// @Resource -// private IfsApiUtils ifsApiUtils; -// @Resource -// private InsSampleUserMapper insSampleUserMapper; -// -// -// @Override -// public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) { -// Map<String, Object> map = new HashMap<>(); -// map.put("head", PrintChina.printChina(ReportPageDto.class)); -// Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsReport"); -// User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉 -// //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id -// String departLimsId = user.getDepartLimsId(); -// String laboratory = null; -//// if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { -//// String[] split = departLimsId.split(","); -//// //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙) -//// String departLims = insOrderMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); -//// if (departLims.contains("瀹為獙瀹�")) { -//// laboratory = departLims; -//// } -//// } -// -// Integer createOrderUser = null; -// if (map1.get("look") == 1) { -// //涓汉 -// createOrderUser = map1.get("userId"); -// } -// String queryStatus = reportPageDto.getQueryStatus(); -// reportPageDto.setQueryStatus(null); -// -// map.put("body", insReportMapper.pageInsReport(page, -// QueryWrappers.queryWrappers(reportPageDto), -// laboratory, -// map1.get("userId"), -// queryStatus, -// createOrderUser)); -// return map; -// } -// -// @Override -// public int inReport(String url, Integer id) { -// InsReport insReport = new InsReport(); -// insReport.setId(id); -// insReport.setUrlS(url); -// // 杩樺師pdf -// String tempUrlPdf = wordToPdfTemp(insReport.getUrlS().replace("/word", wordUrl)); -// insReport.setTempUrlPdf("/word/" + tempUrlPdf); -// return insReportMapper.updateById(insReport); -// } -// -// @Override -// public int upReportUrl(Integer id) { -// InsReport report = insReportMapper.selectById(id); -// // 杩樺師pdf -// String tempUrlPdf = wordToPdfTemp(report.getUrl().replace("/word", wordUrl)); -// -// return insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() -// .eq(InsReport::getId, id) -// .set(InsReport::getUrlS, null) -// .set(InsReport::getTempUrlPdf, "/word/" + tempUrlPdf)); -// } -// -// //鎻愪氦 -// @Override -// @Transactional(rollbackFor = Exception.class) -// public int writeReport(Integer id, Integer userId, Integer submitUserId) { -// submitUserId = submitUserId == null ? getLook.selectPowerByMethodAndUserId(null).get("userId") : submitUserId; -// InsReport insReport = insReportMapper.selectById(id); -// insReport.setId(id); -// insReport.setState(1); -// insReport.setWriteUserId(submitUserId);//鎻愪氦浜� -// if (userId == null) { -// throw new ErrorException("缂哄皯瀹℃牳浜�"); -// } -// insReport.setExamineUserId(userId);//瀹℃牳浜� -// insReport.setWriteTime(LocalDateTime.now());//鎻愪氦鏃堕棿 -// //鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃 -// String signatureUrl; -// try { -// signatureUrl = userMapper.selectById(insReport.getWriteUserId()).getSignatureUrl(); -// } catch (Exception e) { -// throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�"); -// } -// if (ObjectUtils.isEmpty(signatureUrl) || signatureUrl.equals("")) { -// throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�"); -// } -// -// Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); -// InsOrder order = insOrderMapper.selectById(insOrderId); -// boolean isRawMater = order.getTypeSource() != null && order.getTypeSource().equals(1); -// -// //鍙戦�佹秷鎭� -// InformationNotification info = new InformationNotification(); -// info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); -// info.setMessageType("3"); -// info.setTheme("瀹℃牳閫氱煡"); -// info.setContent("鎮ㄦ湁涓�鏉℃姤鍛婄紪鍒跺緟瀹℃牳娑堟伅, 缂栧彿:" + insReport.getCode()); -// info.setSenderId(submitUserId); //鍙戦�佷汉 -// info.setConsigneeId(userId); //鏀朵欢浜� -// info.setViewStatus(false); -// info.setJumpPath("b1-report-preparation"); -// informationNotificationService.addInformationNotification(info); -// //绯荤粺鐢熸垚鎶ュ憡鍦板潃 -// String url = insReport.getUrl(); -// //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 -// String urlS = insReport.getUrlS(); -// -// // 鍒ゆ柇鏄惁鏄師鏉愭枡 闇�瑕佹浛鎹�****鎴愪緵搴斿晢 -// IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() -// .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId())); -// if (one != null) { -// if (isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) { -// changeText(new HashMap<String, String>() {{ -// put("**********", one.getSupplierName()); -// }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); -// } -// } -// -// wordInsertUrl(new HashMap<String, Object>() {{ -// put("writeUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); -// put("writeDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); -// put("insUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); -// }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); -// -// // 淇敼涓存椂pdf -// String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); -// insReport.setTempUrlPdf("/word/" + tempUrlPdf); -// -// insReportMapper.updateById(insReport); -// -// // 娓呯┖瀹℃牳鏃堕棿, 瀹℃牳鐘舵�� -// insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() -// .eq(InsReport::getId, insReport.getId()) -// .set(InsReport::getRatifyTime, null) -// .set(InsReport::getIsRatify, null) -// .set(InsReport::getExamineTime, null) -// .set(InsReport::getIsExamine, null)); -// -// return 1; -// } -// -// //瀹℃牳 -// @Override -// @Transactional(rollbackFor = Exception.class) -// public int examineReport(Integer id, Integer isExamine, String examineTell, Integer userId) { -// InsReport insReport = insReportMapper.selectById(id); -// insReport.setIsExamine(isExamine); -// if (ObjectUtils.isNotEmpty(examineTell)) { -// insReport.setExamineTell(examineTell); -// } -// -// // 妫�楠屼汉 -// String userName = insProductMapper.selectUserById(insReport.getWriteUserId()).get("name"); -// String userAccount = insProductMapper.selectUserById(insReport.getWriteUserId()).get("account"); -// -// // 瀹℃牳浜� -// Integer checkUserId = getLook.selectPowerByMethodAndUserId(null).get("userId"); -// String checkUserName = insProductMapper.selectUserById(checkUserId).get("name"); -// -// insReport.setExamineTime(LocalDateTime.now());//瀹℃牳鏃堕棿 -// if (isExamine == 0) { -// // 鍙戦�佷紒涓氬井淇¢�氱煡(瀹℃牳閫�鍥�) -// threadPoolTaskExecutor.execute(() -> { -// // 鏌ヨ璁㈠崟 -// InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); -// InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() -// .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) -// .last("limit 1")); -// // 鏌ヨ鍘熸潗鏂� -// IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); -// -// String message = ""; -// message += "鎶ュ憡缂栧埗瀹℃牳閫�鍥為�氱煡"; -// message += "\n瀹℃牳浜�: " + checkUserName; -// message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); -// message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); -// message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); -// if (ifsInventoryQuantity != null) { -// message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); -// } -// message += "\n閫�鍥炲師鍥�: " + examineTell; -// //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 -// try { -// WxCpUtils.inform(userAccount, message, null); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// }); -// -// //濡傛灉瀹℃牳涓嶉�氳繃 -// insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦 -// return insReportMapper.updateById(insReport); -// } else { -// if (userId == null) { -// throw new ErrorException("缂哄皯鎵瑰噯浜�"); -// } -// } -// insReport.setRatifyUserId(userId);//鎵瑰噯浜� -// //鑾峰彇瀹℃牳浜虹殑绛惧悕鍦板潃 -// String signatureUrl; -// try { -// signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl(); -// } catch (Exception e) { -// throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�"); -// } -// if (StringUtils.isBlank(signatureUrl)) { -// throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�"); -// } -// -// // 鎵瑰噯浜� -// String sendUserAccount = insProductMapper.selectUserById(userId).get("account"); -// -// //鍙戦�佹秷鎭� -// //褰撳墠鐢ㄦ埛 -// Integer currentUser = getLook.selectPowerByMethodAndUserId(null).get("userId"); -// InformationNotification info = new InformationNotification(); -// info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); -// info.setMessageType("3"); -// info.setTheme("鎵瑰噯閫氱煡"); -// info.setContent("鎮ㄦ湁涓�鏉℃姤鍛婄紪鍒跺緟鎵瑰噯娑堟伅, 缂栧彿:" + insReport.getCode()); -// info.setSenderId(currentUser); //鍙戦�佷汉 -// info.setConsigneeId(userId); //鏀朵欢浜� -// info.setViewStatus(false); -// info.setJumpPath("b1-report-preparation"); -// informationNotificationService.addInformationNotification(info); -// //绯荤粺鐢熸垚鎶ュ憡鍦板潃 -// String url = insReport.getUrl(); -// //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 -// String urlS = insReport.getUrlS(); -// wordInsertUrl(new HashMap<String, Object>() {{ -// put("examineUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); -// put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); -// }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); -// -// // 淇敼涓存椂pdf -// String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); -// insReport.setTempUrlPdf("/word/" + tempUrlPdf); -// -// // 鍙戦�佷紒涓氬井淇¢�氱煡(閫氱煡鎵瑰噯浜哄鎵�) -// threadPoolTaskExecutor.execute(() -> { -// // 鏌ヨ璁㈠崟 -// InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); -// InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() -// .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) -// .last("limit 1")); -// // 鏌ヨ鍘熸潗鏂� -// IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); -// -// String message = ""; -// message += "鎶ュ憡缂栧埗鎵瑰噯閫氱煡"; -// message += "\n妫�楠屼汉: " + userName; -// message += "\n澶嶆牳浜�: " + checkUserName; -// message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); -// message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); -// message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); -// if (ifsInventoryQuantity != null) { -// message += "\n鐢熶骇鍘傚: " + ifsInventoryQuantity.getSupplierName(); -// message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); -// } -// //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 -// try { -// WxCpUtils.inform(sendUserAccount, message, null); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// }); -// insReportMapper.updateById(insReport); -// -// // 娓呯┖鎵瑰噯澶囨敞, 鎵瑰噯鏃堕棿, 鎵瑰噯鐘舵�� -// insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() -// .eq(InsReport::getId, insReport.getId()) -// .set(InsReport::getExamineTell, null) -// .set(InsReport::getRatifyTime, null) -// .set(InsReport::getIsRatify, null)); -// return 1; -// } -// -// //鎵瑰噯 -// @Override -// @Transactional(rollbackFor = Exception.class) -// public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) { -// InsReport insReport = insReportMapper.selectById(id); -// insReport.setIsRatify(isRatify); -// if (ObjectUtils.isNotEmpty(ratifyTell)) { -// insReport.setRatifyTell(ratifyTell); -// } -// insReport.setRatifyTime(LocalDateTime.now());//鎵瑰噯鏃堕棿 -// if (isRatify == 0) { -// -// // 鎵瑰噯浜� -// Integer ratifyUserId = getLook.selectPowerByMethodAndUserId(null).get("userId"); -// String ratifyUserName = insProductMapper.selectUserById(ratifyUserId).get("name"); -// -// // 鍙戦�佷汉(瀹℃牳浜�)(妫�楠屼汉) -// // 妫�楠屼汉 -// String userAccount = insProductMapper.selectUserById(insReport.getWriteUserId()).get("account"); -// // 瀹℃牳浜� -// String checkUserAccount = insProductMapper.selectUserById(insReport.getExamineUserId()).get("account"); -// -// -// // 鍙戦�佷紒涓氬井淇¢�氱煡(鎵瑰噯閫�鍥�) -// threadPoolTaskExecutor.execute(() -> { -// // 鏌ヨ璁㈠崟 -// InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); -// InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() -// .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) -// .last("limit 1")); -// // 鏌ヨ鍘熸潗鏂� -// IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); -// -// String message = ""; -// message += "鎶ュ憡缂栧埗鎵瑰噯閫�鍥為�氱煡"; -// message += "\n鎵瑰噯浜�: " + ratifyUserName; -// message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); -// message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); -// message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); -// if (ifsInventoryQuantity != null) { -// message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); -// } -// message += "\n閫�鍥炲師鍥�: " + ratifyTell; -// //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 -// try { -// // 瀹℃壒浜� -// WxCpUtils.inform(checkUserAccount, message, null); -// -// // 妫�楠屼汉 -// WxCpUtils.inform(userAccount, message, null); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// }); -// -// //濡傛灉鎵瑰噯涓嶉�氳繃 鐩存帴閫�鍥炲埌鎻愪氦浜洪偅杈瑰幓 -// insReport.setState(0); -// insReport.setIsExamine(0); -// return insReportMapper.updateById(insReport); -// } -// //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃 -// String signatureUrl; -// try { -// signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl(); -// } catch (Exception e) { -// throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�"); -// } -// if (StringUtils.isBlank(signatureUrl)) { -// throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�"); -// } -// Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); -// InsOrder order = insOrderMapper.selectById(insOrderId); -// boolean isRawMater = order.getTypeSource() != null && order.getTypeSource().equals(1); -// -// //鑾峰彇鍦烘墍鐨勬姤鍛婁笓鐢ㄧ珷 -// String sealUrl; -// String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); -// try { -// String type = ""; -// if (isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) { -// type = "杩涘巶鎶ュ憡"; -// } else { -// type = "濮旀墭鎶ュ憡"; -// } -// sealUrl = insReportMapper.getLaboratoryByName(laboratory, type); -// } catch (Exception e) { -// throw new ErrorException(laboratory + "鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); -// } -// if (StringUtils.isBlank(sealUrl)) { -// throw new ErrorException(laboratory + "鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); -// } -// //绯荤粺鐢熸垚鎶ュ憡鍦板潃 -// String url = insReport.getUrl(); -// //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 -// String urlS = insReport.getUrlS(); -// String finalUrl = (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl); -// -// wordInsertUrl(new HashMap<String, Object>() {{ -// put("ratifyUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); -// put("ratifyDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); -// put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); -// put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); -// }}, finalUrl); -// -// // 淇敼涓存椂pdf -// insReport.setTempUrlPdf((StrUtil.isBlank(urlS) ? url : urlS).replace(".docx", ".pdf")); -// -// InsOrder insOrder = new InsOrder(); -// insOrder.setId(insOrderId); -// insOrder.setState(4); -// insOrderMapper.updateById(insOrder); -// -// wordToPdf(finalUrl, sealUrl, isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)); -// -// // 鍒ゆ柇鏄惁涓哄師鏉愭枡 -// if (isRawMater) { -// // 淇敼ifs搴撳瓨鐘舵�� -// ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() -// .set(IfsInventoryQuantity::getState, 2) -// .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId())); -// } -// insReport.setRatifyTell(""); -// -// // 鍙戦�佹枃浠跺埌濮旀墭浜� -// if (StringUtils.isNotBlank(order.getPrepareCode())) { -// threadPoolTaskExecutor.execute(() -> { -// String message = ""; -// message += "濮旀墭缂栧彿: " + order.getEntrustCode(); -// message += "濮旀墭鏍峰搧: " + order.getSampleView(); -// message += "宸叉娴嬬粨鏉�, 璇锋帴鏀�"; -// try { -// WxCpUtils.inform(order.getPrepareCode(), message, new File(finalUrl.replace(".docx", ".pdf"))); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// }); -// } -// -// return insReportMapper.updateById(insReport); -// } -// -// @Override -// public int wordInsertUrl(Map<String, Object> map, String url) { -// XWPFTemplate template = XWPFTemplate.compile(url).render(map); -// try { -// template.writeAndClose(Files.newOutputStream(Paths.get(url))); -// } catch (IOException e) { -// throw new RuntimeException(e); -// } -// return 1; -// } -// -// -// //鎶ュ憡鎵归噺涓嬭浇 -// @Override -// @Transactional(rollbackFor = Exception.class) -// public String downAll(String ids) { -// List<Long> list = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); -// List<InsReport> insReports = insReportMapper.selectBatchIds(list); -// String zipFilePath = null; -// // 涓存椂鏂囦欢澶硅矾寰� -// try { -// String tempFolderPath = wordUrl + "/tempFolder"; -// File tempFolder = new File(tempFolderPath); -// if (tempFolder.exists()) { -// deleteDirectory(tempFolder); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶� -// } -// tempFolder.mkdirs(); // 鍒涘缓鏂扮殑涓存椂鏂囦欢澶� -// for (InsReport insReport : insReports) { -// File sourceFile = new File((ObjectUtils.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl()).replace("/word", wordUrl)); -// File destinationFile = new File(tempFolder, sourceFile.getName()); -// Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); -// } -// // 鍘嬬缉涓存椂鏂囦欢澶� -// zipFilePath = wordUrl + "/zip/output.zip"; -// zipDirectory(tempFolderPath, zipFilePath); -// -// // 娓呯悊涓存椂鏂囦欢澶� -// deleteDirectory(tempFolder); -// -// System.out.println("ZIP鏂囦欢鍒涘缓瀹屾垚锛�"); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// return "/word/zip/output.zip"; -// } -// -// //鎵归噺涓婁紶 -// @Override -// @Transactional(rollbackFor = Exception.class) -// public int upAll(MultipartFile file) throws IOException { -// File tempFile = null; -// File unzipDir = null; -// try { -// tempFile = File.createTempFile(wordUrl, ".zip"); -// file.transferTo(tempFile); -// -// unzipDir = new File("uploaded_files"); -// if (!unzipDir.exists()) { -// unzipDir.mkdir(); -// } -// unzip(tempFile, unzipDir); -// // 澶勭悊瑙e帇鍚庣殑鏂囦欢 -// File[] files = unzipDir.listFiles(); -// if (files != null) { -// for (File f : files) { -// // 鏍规嵁鏂囦欢鍚嶆煡璇d -// String name = f.getName(); -// InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", "").replace("JCZX", "JCZX/"))); -// if (ObjectUtils.isEmpty(insReport)) { -// throw new ErrorException("娌℃湁鎵惧埌 " + f.getName() + " 杩欎釜鏂囦欢瀵瑰簲鐨勬姤鍛婃暟鎹�"); -// } -// String urlString; -// String pathName; -// try { -// String path = wordUrl; -// File realpath = new File(path); -// if (!realpath.exists()) { -// realpath.mkdirs(); -// } -// pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + f.getName(); -// urlString = realpath + "/" + pathName; -// // 澶嶅埗鏂囦欢鍒版寚瀹氳矾寰� -// Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING); -// inReport("/word/" + pathName, insReport.getId()); -// } catch (IOException e) { -// throw new ErrorException("鏂囦欢涓婁紶澶辫触"); -// } -// } -// } -// } catch (IOException e) { -// throw new ErrorException("鏂囦欢澶勭悊澶辫触"); -// } finally { -// if (tempFile != null && tempFile.exists()) { -// tempFile.delete(); -// } -// // 閫掑綊鍒犻櫎瑙e帇鐩綍鍙婂叾涓殑鏂囦欢 -// if (unzipDir.exists()) { -// deleteDirectory(unzipDir); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶� -// } -// } -// return 0; -// } -// -// -// //瑙e帇鏂囦欢澶� -// private void unzip(File zipFile, File destDir) throws IOException { -// try (ZipFile zip = new ZipFile(zipFile)) { -// Enumeration<? extends ZipEntry> entries = zip.entries(); -// while (entries.hasMoreElements()) { -// ZipEntry entry = entries.nextElement(); -// File file = new File(destDir, entry.getName()); -// if (entry.isDirectory()) { -// file.mkdirs(); -// } else { -// file.getParentFile().mkdirs(); -// try (InputStream in = zip.getInputStream(entry); -// OutputStream out = new FileOutputStream(file)) { -// byte[] buffer = new byte[1024]; -// int len; -// while ((len = in.read(buffer)) > 0) { -// out.write(buffer, 0, len); -// } -// } -// } -// } -// } -// } -// -// // 鍘嬬缉鏂囦欢澶� -// public static void zipDirectory(String sourceDirPath, String zipFilePath) throws IOException { -// try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath))) { -// Path sourceDir = Paths.get(sourceDirPath); -// Files.walk(sourceDir) -// .filter(path -> !Files.isDirectory(path)) -// .forEach(path -> { -// ZipEntry zipEntry = new ZipEntry(sourceDir.relativize(path).toString()); -// try { -// zipOut.putNextEntry(zipEntry); -// Files.copy(path, zipOut); -// zipOut.closeEntry(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// }); -// } -// } -// -// // 鍒犻櫎鏂囦欢澶瑰強鍏跺唴瀹� -// public static void deleteDirectory(File directory) throws IOException { -// if (directory.isDirectory()) { -// File[] files = directory.listFiles(); -// if (files != null) { -// for (File file : files) { -// deleteDirectory(file); -// } -// } -// } -// Files.delete(directory.toPath()); -// } -// -// @Override -// public void wordToPdf(String path, String sealUrl, boolean isRawMater) { -// try { -// wordToPdf(path, path.replace(".docx", ".pdf"), sealUrl, isRawMater); -// } catch (Exception e) { -// throw new ErrorException("杞崲澶辫触"); -// } -// } -// -// -// public String wordToPdf(String wordPath, String pdfPath, String sealUrl, boolean isRawMater) { -// 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()); -// License license = new License(); -// license.setLicense(is); -// if (!license.getIsLicensed()) { -// System.out.println("License楠岃瘉涓嶉�氳繃..."); -// return null; -// } -// //鐢熸垚涓�涓┖鐨凱DF鏂囦欢 -// File file; -// //鍒ゆ柇鏄惁鏄繘鍘傛姤鍛� -// if (!isRawMater) { -// file = new File(pdfPath.replace(".pdf", "-1.pdf")); -// } else { -// file = new File(pdfPath.replace(".pdf", ".pdf")); -// } -// os = new FileOutputStream(file); -// //瑕佽浆鎹㈢殑word鏂囦欢 -// com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); -// doc.save(os, SaveFormat.PDF); -// -// //娣诲姞楠戠紳绔� -// if (!isRawMater) { -// stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl); -// } -// -// -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// if (os != null) { -// try { -// os.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// } -// return null; -// } -// -// /** -// * 鍒囧壊鍥剧墖 -// * -// * @param Path 鍥剧墖璺緞 -// * @param n 鍒囧壊浠芥暟 -// */ -// public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException { -// com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n]; -// BufferedImage img = ImageIO.read(new File(Path)); -// -// int h = img.getHeight(); -// int w = img.getWidth(); -// -// int sw = w / n; -// for (int i = 0; i < n; i++) { -// BufferedImage subImg; -// if (i == n - 1) {//鏈�鍚庡墿浣欓儴鍒� -// subImg = img.getSubimage(i * sw, 0, w - i * sw, h); -// } else {//鍓峮-1鍧楀潎鍖�鍒� -// subImg = img.getSubimage(i * sw, 0, sw, h); -// } -// ByteArrayOutputStream out = new ByteArrayOutputStream(); -// ImageIO.write(subImg, Path.substring(Path.lastIndexOf('.') + 1), out); -// nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray()); -// -// } -// return nImage; -// } -// -// /** -// * 鐩栭獞缂濈珷 -// * -// * @param infilePath 鍘烶DF璺緞 -// * @param outFilePath 杈撳嚭PDF璺緞 -// */ -// public static void stamperCheckMarkPDF(String infilePath, String outFilePath, String picPath) throws IOException, DocumentException { -// PdfReader reader = new PdfReader(infilePath);//閫夋嫨闇�瑕佸嵃绔犵殑pdf -// PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//鍔犲畬鍗扮珷鍚庣殑pdf -// -// -// com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//鑾峰緱绗竴椤� -// float height = pageSize.getHeight(); -// float width = pageSize.getWidth(); -// -// int nums = reader.getNumberOfPages(); -// com.itextpdf.text.Image[] nImage = slicingImages(picPath, nums);//鐢熸垚楠戠紳绔犲垏鍓插浘鐗� -// -// for (int n = 1; n <= nums; n++) { -// PdfContentByte over = stamp.getOverContent(n);//璁剧疆鍦ㄧ鍑犻〉鎵撳嵃鍗扮珷 -// com.itextpdf.text.Image img = nImage[n - 1];//閫夋嫨鍥剧墖 -// float newHeight = 100f; -// float newWidth = img.getWidth() / (img.getHeight() / 100); -// img.scaleAbsolute(newWidth, newHeight);//鎺у埗鍥剧墖澶у皬 -// img.setAbsolutePosition(width - newWidth, height / 2 - newHeight / 2);//鎺у埗鍥剧墖浣嶇疆 -// over.addImage(img); -// } -// stamp.close(); -// } -// -// @Transactional(rollbackFor = Exception.class) -// public void isRawMaterial(InsOrder insOrder) { -// IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() -// .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); -// if (Objects.isNull(one)) { -// throw new ErrorException("鎵句笉鍒板師鏉愭枡淇℃伅"); -// } -// // 鍒ゆ柇鏄惁鏈変笉鍚堟牸淇℃伅 -// Long count = insUnqualifiedHandlerMapper.selectCount(Wrappers.<InsUnqualifiedHandler>lambdaQuery() -// .eq(InsUnqualifiedHandler::getInventoryQuantityId, one.getId())); -// String toLocation = null; -// -// // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 -// Long unqualifiedCount = getUnqualifiedCount(insOrder); -// -// if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1)) { -// // 鍘熸潗鏂欑Щ搴� -// toLocation = this.moveRawMaterial(one); -// } -// -// // 鍒ゆ柇缁撴潫鐘舵�佷慨鏀瑰悎鏍肩姸鎬� -// int inspectStatus = (count == 0 && unqualifiedCount == 0) ? 1 : 2; -// insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() -// .eq(InsOrder::getId, insOrder.getId()) -// .set(InsOrder::getInsResult, inspectStatus)); -// -// if (one.getIsFinish().equals(0)) { -// ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate() -// .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId()) -// .set(IfsInventoryQuantity::getInspectStatus, inspectStatus)); -// -// // 淇敼ifs搴撳瓨鐘舵�� -// if (StringUtils.isBlank(toLocation)) { -// ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() -// .set(IfsInventoryQuantity::getIsFinish, 1) -// .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); -// } else { -// ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() -// .set(IfsInventoryQuantity::getIsFinish, 1) -// .set(IfsInventoryQuantity::getToLocation, toLocation) -// .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(); -// // 鍙戦�佷紒涓歩nspectStatus淇¢�氱煡 -// if (inspectStatus == 1) { -// message += "\n妫�娴嬬粨鏋�: 鍚堟牸"; -// } else { -// message += "\n妫�娴嬬粨鏋�: 涓嶅悎鏍�"; -// } -// WxCpUtils.informWebHook(wechatProperty.getExaminingUrl(), message); -// }); -// -// } -// -// -// } -// -// /** -// * 鍒ゆ柇鏄惁鏈変笉鍚堟牸 -// * @param insOrder -// * @return -// */ -// @Override -// public Long getUnqualifiedCount(InsOrder insOrder) { -// Long unqualifiedCount = 0L; -// List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery() -// .eq(InsSample::getInsOrderId, insOrder.getId())); -// if (CollectionUtils.isNotEmpty(insSamples)) { -// unqualifiedCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() -// .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList())) -// .eq(InsProduct::getInsResult, 0)); -// -// // 鍒ゆ柇濡傛灉鏈変笉鍚堟牸鐨勬楠岄」, 鍒ゆ柇鏈夋病鏈夋楠岄」澶嶆祴, 澶嶆牳鍚堟牸涔熺畻鍚堟牸閫氳繃 -// if (!unqualifiedCount.equals(0L)) { -// List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() -// .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList())) -// .eq(InsProduct::getInsResult, 0)); -// -// boolean flag = true; -// for (InsProduct insProduct : insProducts) { -// Long unqualifiedProductCount = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery() -// .eq(InsUnqualifiedRetestProduct::getInsProductId, insProduct.getId()) -// .ne(InsUnqualifiedRetestProduct::getInsResult, 0)); -// if (unqualifiedProductCount != 2) { -// flag = false; -// } -// } -// if (flag) { -// unqualifiedCount = 0L; -// } -// } -// } -// return unqualifiedCount; -// } -// -// /** -// * ifs绉诲簱鎿嶄綔 -// * @param one -// * @return -// */ -// @Override -// public String moveRawMaterial(IfsInventoryQuantity one) { -// String toLocation; -// // 鐧昏閲囪喘妫�楠岀粨鏋淪TD -// 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 鍚庣画闇�瑕佽皟鐢↖FS鐨勬帴鍙� 绉诲叆鐨勫簱浣嶅彿 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 -// */ -// @Override -// @Transactional(rollbackFor = Exception.class) -// public boolean sendBackTask(Integer id) { -// InsReport report = insReportMapper.selectById(id); -// // 鏍规嵁璁㈠崟鏌ヨ璇曢獙瀹� -// String laboratory = insOrderMapper.selectLaboratoryByOrderId(report.getInsOrderId()); -// -// // 淇敼璁㈠崟鐘舵�� -// insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate() -// .eq(InsOrderState::getInsOrderId, report.getInsOrderId()) -// .eq(InsOrderState::getLaboratory, laboratory) -// .set(InsOrderState::getInsState, 4)); -// -// Integer insSampleId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery() -// .eq(InsSampleUser::getInsSampleId, report.getInsOrderId()) -// .orderByDesc(InsSampleUser::getId) -// .last("limit 1")).getId(); -// insSampleUserMapper.deleteById(insSampleId); -// -// // 淇敼鎶ュ憡琛屼负鏈樉绀� -// insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() -// .eq(InsReport::getId, id) -// .set(InsReport::getIsPass, 0)); -// -// return false; -// } -// -// -// /** -// * 鍏堜慨鏀归噰璐鍗曟壒娆″彿, 鍚庤繘琛岀Щ搴撴搷浣� -// * @param one -// * @param toLocation -// */ -// 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); -// -// Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap)); -// -// 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())); -// } -// -// 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()); -// } -// -// } -// -// /** -// * 鏇挎崲娈佃惤鏂囨湰 -// * @param filePath docx瑙f瀽瀵硅薄 -// * @param textMap 闇�瑕佹浛鎹㈢殑淇℃伅闆嗗悎 -// */ -// public static void changeText(Map<String, String> textMap, String filePath) { -// try { -// FileInputStream stream = new FileInputStream(filePath); -// XWPFDocument document = new XWPFDocument(stream); -// List<XWPFTable> tables = document.getTables(); -// for (XWPFTable table : tables) { -// for (XWPFTableRow row : table.getRows()) { -// for (XWPFTableCell cell : row.getTableCells()) { -// -// textMap.forEach((s, s2) -> { -// if (cell.getText().equals(s)) { -// XWPFParagraph paragraph = cell.getParagraphs().get(0); -// XWPFRun oldRun = paragraph.getRuns().get(0); -// // 淇濆瓨鍘熸牱寮� -// String fontFamily = oldRun.getFontFamily(); -// int fontSize = oldRun.getFontSize(); -// String color = oldRun.getColor(); -// ParagraphAlignment alignment = paragraph.getAlignment(); -// // 鏇挎崲鍐呭 -// paragraph.removeRun(0); // 绉婚櫎鍘熸湁鐨� run -// XWPFRun newRun = paragraph.createRun(); -// newRun.setText(s2); -// // 搴旂敤鍘熸牱寮� -// newRun.setFontFamily(fontFamily); -// newRun.setFontSize(fontSize); -// newRun.setColor(color); -// paragraph.setAlignment(alignment); -// } -// }); -// } -// } -// } -// FileOutputStream fileOutputStream = new FileOutputStream(filePath); -// document.write(fileOutputStream); -// fileOutputStream.close(); -// -// } catch (Exception e) { -// e.printStackTrace(); -// throw new ErrorException(e.getMessage()); -// } -// } -// -// /** -// * word杞崲pdf -// * @param path -// * @return -// */ -// private String wordToPdfTemp(String path) { -// try { -// return wordToPdf(path, path.replace(".docx", "-涓存椂.pdf")); -// } catch (Exception e) { -// throw new ErrorException("杞崲澶辫触"); -// } -// } -// -// private String wordToPdf(String wordPath, String pdfPath) { -// FileOutputStream os = null; -// try { -// //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃 -// InputStream is = Files.newInputStream(new File(licenseUrl).toPath()); -// License license = new License(); -// license.setLicense(is); -// if (!license.getIsLicensed()) { -// System.out.println("License楠岃瘉涓嶉�氳繃..."); -// return null; -// } -// //鐢熸垚涓�涓┖鐨凱DF鏂囦欢 -// File file; -// //鍒ゆ柇鏄惁鏄繘鍘傛姤鍛� -// file = new File(pdfPath); -// os = new FileOutputStream(file); -// //瑕佽浆鎹㈢殑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(); -// } finally { -// if (os != null) { -// try { -// os.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// } -// return null; -// } -//} -// -// -// -// -// -// +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.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.data.Pictures; +import com.itextpdf.text.BadElementException; +import com.itextpdf.text.DocumentException; +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.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.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.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 org.springframework.web.multipart.MultipartFile; + +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; +import java.nio.file.StandardCopyOption; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +/** + * @author Administrator + * @description 閽堝琛ㄣ�恑ns_report(妫�楠屾姤鍛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇 + * @createDate 2024-03-17 22:10:02 + */ +@Service +@Slf4j +public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport> + implements InsReportService { + @Resource + private UserMapper userMapper; + @Resource + private InsReportMapper insReportMapper; + @Resource + private InsOrderStateMapper insOrderStateMapper; + @Resource + private InsProductMapper insProductMapper; + @Resource + private InformationNotificationService informationNotificationService; + @Value("${wordUrl}") + private String wordUrl; + @Value("${file.path}") + private String imgUrl; + + @Resource + private InsOrderMapper insOrderMapper; + @Resource + private IfsInventoryQuantityMapper ifsInventoryQuantityMapper; + @Resource + private InsUnqualifiedHandlerMapper insUnqualifiedHandlerMapper; + @Resource + private InsSampleMapper insSampleMapper; + @Resource + private ThreadPoolTaskExecutor threadPoolTaskExecutor; + @Resource + private InsOrderService insOrderService; + @Resource + private WechatProperty wechatProperty; + @Resource + private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper; + @Resource + private IfsApiUtils ifsApiUtils; + @Resource + private InsSampleUserMapper insSampleUserMapper; + + + @Override + public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) { + Map<String, Object> map = new HashMap<>(); + // todo: 浠呯湅鑷繁 + //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id + String laboratory = null; + + Integer createOrderUser = reportPageDto.getCreateOrderUser(); + String queryStatus = reportPageDto.getQueryStatus(); + reportPageDto.setQueryStatus(null); + reportPageDto.setCreateOrderUser(null); + + map.put("body", insReportMapper.pageInsReport(page, + QueryWrappers.queryWrappers(reportPageDto), + laboratory, + SecurityUtils.getUserId().intValue(), + queryStatus, + createOrderUser)); + return map; + } + + @Override + public int inReport(String url, Integer id) { + InsReport insReport = new InsReport(); + insReport.setId(id); + insReport.setUrlS(url); + // 杩樺師pdf + String tempUrlPdf = wordToPdfTemp(insReport.getUrlS().replace("/word", wordUrl)); + insReport.setTempUrlPdf("/word/" + tempUrlPdf); + return insReportMapper.updateById(insReport); + } + + @Override + public int upReportUrl(Integer id) { + InsReport report = insReportMapper.selectById(id); + // 杩樺師pdf + String tempUrlPdf = wordToPdfTemp(report.getUrl().replace("/word", wordUrl)); + + return insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() + .eq(InsReport::getId, id) + .set(InsReport::getUrlS, null) + .set(InsReport::getTempUrlPdf, "/word/" + tempUrlPdf)); + } + + //鎻愪氦 + @Override + @Transactional(rollbackFor = Exception.class) + public int writeReport(Integer id, Integer userId, Integer submitUserId) { + submitUserId = submitUserId == null ? SecurityUtils.getUserId().intValue() : submitUserId; + InsReport insReport = insReportMapper.selectById(id); + insReport.setId(id); + insReport.setState(1); + insReport.setWriteUserId(submitUserId);//鎻愪氦浜� + if (userId == null) { + throw new ErrorException("缂哄皯瀹℃牳浜�"); + } + insReport.setExamineUserId(userId);//瀹℃牳浜� + insReport.setWriteTime(LocalDateTime.now());//鎻愪氦鏃堕棿 + //鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃 + String signatureUrl; + try { + signatureUrl = userMapper.selectById(insReport.getWriteUserId()).getSignatureUrl(); + } catch (Exception e) { + throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�"); + } + if (ObjectUtils.isEmpty(signatureUrl) || signatureUrl.equals("")) { + throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�"); + } + + Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); + InsOrder order = insOrderMapper.selectById(insOrderId); + boolean isRawMater = order.getTypeSource() != null && order.getTypeSource().equals(1); + + //鍙戦�佹秷鎭� + InformationNotification info = new InformationNotification(); + info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); + info.setMessageType("3"); + info.setTheme("瀹℃牳閫氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃姤鍛婄紪鍒跺緟瀹℃牳娑堟伅, 缂栧彿:" + insReport.getCode()); + info.setSenderId(submitUserId); //鍙戦�佷汉 + info.setConsigneeId(userId); //鏀朵欢浜� + info.setViewStatus(false); + info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); + informationNotificationService.addInformationNotification(info); + //绯荤粺鐢熸垚鎶ュ憡鍦板潃 + String url = insReport.getUrl(); + //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 + String urlS = insReport.getUrlS(); + + // 鍒ゆ柇鏄惁鏄師鏉愭枡 闇�瑕佹浛鎹�****鎴愪緵搴斿晢 + IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() + .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId())); + if (one != null) { + if (isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) { + changeText(new HashMap<String, String>() {{ + put("**********", one.getSupplierName()); + }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); + } + } + + wordInsertUrl(new HashMap<String, Object>() {{ + put("writeUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); + put("writeDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); + put("insUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); + }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); + + // 淇敼涓存椂pdf + String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); + insReport.setTempUrlPdf("/word/" + tempUrlPdf); + + insReportMapper.updateById(insReport); + + // 娓呯┖瀹℃牳鏃堕棿, 瀹℃牳鐘舵�� + insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() + .eq(InsReport::getId, insReport.getId()) + .set(InsReport::getRatifyTime, null) + .set(InsReport::getIsRatify, null) + .set(InsReport::getExamineTime, null) + .set(InsReport::getIsExamine, null)); + + return 1; + } + + //瀹℃牳 + @Override + @Transactional(rollbackFor = Exception.class) + public int examineReport(Integer id, Integer isExamine, String examineTell, Integer userId) { + InsReport insReport = insReportMapper.selectById(id); + insReport.setIsExamine(isExamine); + if (ObjectUtils.isNotEmpty(examineTell)) { + insReport.setExamineTell(examineTell); + } + + // 妫�楠屼汉 + String userName = insProductMapper.selectUserById(insReport.getWriteUserId()).get("name"); + String userAccount = insProductMapper.selectUserById(insReport.getWriteUserId()).get("account"); + + // 瀹℃牳浜� + Integer checkUserId = SecurityUtils.getUserId().intValue(); + String checkUserName = insProductMapper.selectUserById(checkUserId).get("name"); + + insReport.setExamineTime(LocalDateTime.now());//瀹℃牳鏃堕棿 + if (isExamine == 0) { + // 鍙戦�佷紒涓氬井淇¢�氱煡(瀹℃牳閫�鍥�) + threadPoolTaskExecutor.execute(() -> { + // 鏌ヨ璁㈠崟 + InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); + InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() + .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) + .last("limit 1")); + // 鏌ヨ鍘熸潗鏂� + IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); + + String message = ""; + message += "鎶ュ憡缂栧埗瀹℃牳閫�鍥為�氱煡"; + message += "\n瀹℃牳浜�: " + checkUserName; + message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); + message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); + if (ifsInventoryQuantity != null) { + message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); + } + message += "\n閫�鍥炲師鍥�: " + examineTell; + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 + try { + WxCpUtils.inform(userAccount, message, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + + //濡傛灉瀹℃牳涓嶉�氳繃 + insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦 + return insReportMapper.updateById(insReport); + } else { + if (userId == null) { + throw new ErrorException("缂哄皯鎵瑰噯浜�"); + } + } + insReport.setRatifyUserId(userId);//鎵瑰噯浜� + //鑾峰彇瀹℃牳浜虹殑绛惧悕鍦板潃 + String signatureUrl; + try { + signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl(); + } catch (Exception e) { + throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�"); + } + if (StringUtils.isBlank(signatureUrl)) { + throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�"); + } + + // 鎵瑰噯浜� + String sendUserAccount = insProductMapper.selectUserById(userId).get("account"); + + //鍙戦�佹秷鎭� + InformationNotification info = new InformationNotification(); + info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); + info.setMessageType("3"); + info.setTheme("鎵瑰噯閫氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃姤鍛婄紪鍒跺緟鎵瑰噯娑堟伅, 缂栧彿:" + insReport.getCode()); + info.setSenderId(checkUserId); //鍙戦�佷汉 + info.setConsigneeId(userId); //鏀朵欢浜� + info.setViewStatus(false); + info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); + informationNotificationService.addInformationNotification(info); + //绯荤粺鐢熸垚鎶ュ憡鍦板潃 + String url = insReport.getUrl(); + //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 + String urlS = insReport.getUrlS(); + wordInsertUrl(new HashMap<String, Object>() {{ + put("examineUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); + put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); + }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); + + // 淇敼涓存椂pdf + String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl)); + insReport.setTempUrlPdf("/word/" + tempUrlPdf); + + // 鍙戦�佷紒涓氬井淇¢�氱煡(閫氱煡鎵瑰噯浜哄鎵�) + threadPoolTaskExecutor.execute(() -> { + // 鏌ヨ璁㈠崟 + InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); + InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() + .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) + .last("limit 1")); + // 鏌ヨ鍘熸潗鏂� + IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); + + String message = ""; + message += "鎶ュ憡缂栧埗鎵瑰噯閫氱煡"; + message += "\n妫�楠屼汉: " + userName; + message += "\n澶嶆牳浜�: " + checkUserName; + message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); + message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); + if (ifsInventoryQuantity != null) { + message += "\n鐢熶骇鍘傚: " + ifsInventoryQuantity.getSupplierName(); + message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); + } + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 + try { + WxCpUtils.inform(sendUserAccount, message, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + insReportMapper.updateById(insReport); + + // 娓呯┖鎵瑰噯澶囨敞, 鎵瑰噯鏃堕棿, 鎵瑰噯鐘舵�� + insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() + .eq(InsReport::getId, insReport.getId()) + .set(InsReport::getExamineTell, null) + .set(InsReport::getRatifyTime, null) + .set(InsReport::getIsRatify, null)); + return 1; + } + + //鎵瑰噯 + @Override + @Transactional(rollbackFor = Exception.class) + public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) { + InsReport insReport = insReportMapper.selectById(id); + insReport.setIsRatify(isRatify); + if (ObjectUtils.isNotEmpty(ratifyTell)) { + insReport.setRatifyTell(ratifyTell); + } + insReport.setRatifyTime(LocalDateTime.now());//鎵瑰噯鏃堕棿 + if (isRatify == 0) { + + // 鎵瑰噯浜� + Integer ratifyUserId = SecurityUtils.getUserId().intValue(); + String ratifyUserName = insProductMapper.selectUserById(ratifyUserId).get("name"); + + // 鍙戦�佷汉(瀹℃牳浜�)(妫�楠屼汉) + // 妫�楠屼汉 + String userAccount = insProductMapper.selectUserById(insReport.getWriteUserId()).get("account"); + // 瀹℃牳浜� + String checkUserAccount = insProductMapper.selectUserById(insReport.getExamineUserId()).get("account"); + + + // 鍙戦�佷紒涓氬井淇¢�氱煡(鎵瑰噯閫�鍥�) + threadPoolTaskExecutor.execute(() -> { + // 鏌ヨ璁㈠崟 + InsOrder order = insOrderMapper.selectById(insReport.getInsOrderId()); + InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() + .eq(InsSample::getInsOrderId, insReport.getInsOrderId()) + .last("limit 1")); + // 鏌ヨ鍘熸潗鏂� + IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); + + String message = ""; + message += "鎶ュ憡缂栧埗鎵瑰噯閫�鍥為�氱煡"; + message += "\n鎵瑰噯浜�: " + ratifyUserName; + message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); + message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); + if (ifsInventoryQuantity != null) { + message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); + } + message += "\n閫�鍥炲師鍥�: " + ratifyTell; + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 + try { + // 瀹℃壒浜� + WxCpUtils.inform(checkUserAccount, message, null); + + // 妫�楠屼汉 + WxCpUtils.inform(userAccount, message, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + + //濡傛灉鎵瑰噯涓嶉�氳繃 鐩存帴閫�鍥炲埌鎻愪氦浜洪偅杈瑰幓 + insReport.setState(0); + insReport.setIsExamine(0); + return insReportMapper.updateById(insReport); + } + //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃 + String signatureUrl; + try { + signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl(); + } catch (Exception e) { + throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�"); + } + if (StringUtils.isBlank(signatureUrl)) { + throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�"); + } + Integer insOrderId = insReportMapper.selectById(id).getInsOrderId(); + InsOrder order = insOrderMapper.selectById(insOrderId); + boolean isRawMater = order.getTypeSource() != null && order.getTypeSource().equals(1); + + //鑾峰彇鍦烘墍鐨勬姤鍛婁笓鐢ㄧ珷 + String sealUrl; + String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); + try { + String type = ""; + if (isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) { + type = "杩涘巶鎶ュ憡"; + } else { + type = "濮旀墭鎶ュ憡"; + } + sealUrl = insReportMapper.getLaboratoryByName(laboratory, type); + } catch (Exception e) { + throw new ErrorException(laboratory + "鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); + } + if (StringUtils.isBlank(sealUrl)) { + throw new ErrorException(laboratory + "鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); + } + //绯荤粺鐢熸垚鎶ュ憡鍦板潃 + String url = insReport.getUrl(); + //鎵嬪姩涓婁紶鎶ュ憡鍦板潃 + String urlS = insReport.getUrlS(); + String finalUrl = (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl); + + wordInsertUrl(new HashMap<String, Object>() {{ + put("ratifyUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create()); + put("ratifyDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); + put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); + put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); + }}, finalUrl); + + // 淇敼涓存椂pdf + insReport.setTempUrlPdf((StrUtil.isBlank(urlS) ? url : urlS).replace(".docx", ".pdf")); + + InsOrder insOrder = new InsOrder(); + insOrder.setId(insOrderId); + insOrder.setState(4); + insOrderMapper.updateById(insOrder); + + wordToPdf(finalUrl, sealUrl, isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)); + + // 鍒ゆ柇鏄惁涓哄師鏉愭枡 + if (isRawMater) { + // 淇敼ifs搴撳瓨鐘舵�� + ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() + .set(IfsInventoryQuantity::getState, 2) + .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId())); + } + insReport.setRatifyTell(""); + + // 鍙戦�佹枃浠跺埌濮旀墭浜� + if (StringUtils.isNotBlank(order.getPrepareCode())) { + threadPoolTaskExecutor.execute(() -> { + String message = ""; + message += "濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "濮旀墭鏍峰搧: " + order.getSampleView(); + message += "宸叉娴嬬粨鏉�, 璇锋帴鏀�"; + try { + WxCpUtils.inform(order.getPrepareCode(), message, new File(finalUrl.replace(".docx", ".pdf"))); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + return insReportMapper.updateById(insReport); + } + + @Override + public int wordInsertUrl(Map<String, Object> map, String url) { + XWPFTemplate template = XWPFTemplate.compile(url).render(map); + try { + template.writeAndClose(Files.newOutputStream(Paths.get(url))); + } catch (IOException e) { + throw new RuntimeException(e); + } + return 1; + } + + + //鎶ュ憡鎵归噺涓嬭浇 + @Override + @Transactional(rollbackFor = Exception.class) + public String downAll(String ids) { + List<Long> list = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); + List<InsReport> insReports = insReportMapper.selectBatchIds(list); + String zipFilePath = null; + // 涓存椂鏂囦欢澶硅矾寰� + try { + String tempFolderPath = wordUrl + "/tempFolder"; + File tempFolder = new File(tempFolderPath); + if (tempFolder.exists()) { + deleteDirectory(tempFolder); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶� + } + tempFolder.mkdirs(); // 鍒涘缓鏂扮殑涓存椂鏂囦欢澶� + for (InsReport insReport : insReports) { + File sourceFile = new File((ObjectUtils.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl()).replace("/word", wordUrl)); + File destinationFile = new File(tempFolder, sourceFile.getName()); + Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + // 鍘嬬缉涓存椂鏂囦欢澶� + zipFilePath = wordUrl + "/zip/output.zip"; + // 鍒ゆ柇zip璺緞鏄惁瀛樺湪 + File zipDir = new File(wordUrl + "/zip"); + if(!zipDir.isDirectory()){ + zipDir.mkdirs(); + } + zipDirectory(tempFolderPath, zipFilePath); + + // 娓呯悊涓存椂鏂囦欢澶� + deleteDirectory(tempFolder); + + } catch (IOException e) { + e.printStackTrace(); + } + return "/word/zip/output.zip"; + } + + //鎵归噺涓婁紶 + @Override + @Transactional(rollbackFor = Exception.class) + public int upAll(MultipartFile file) throws IOException { + File tempFile = null; + File unzipDir = null; + try { + tempFile = File.createTempFile(wordUrl, ".zip"); + file.transferTo(tempFile); + + unzipDir = new File("uploaded_files"); + if (!unzipDir.exists()) { + unzipDir.mkdir(); + } + unzip(tempFile, unzipDir); + // 澶勭悊瑙e帇鍚庣殑鏂囦欢 + File[] files = unzipDir.listFiles(); + if (files != null) { + for (File f : files) { + // 鏍规嵁鏂囦欢鍚嶆煡璇d + String name = f.getName(); + InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", "").replace("JCZX", "JCZX/"))); + if (ObjectUtils.isEmpty(insReport)) { + throw new ErrorException("娌℃湁鎵惧埌 " + f.getName() + " 杩欎釜鏂囦欢瀵瑰簲鐨勬姤鍛婃暟鎹�"); + } + String urlString; + String pathName; + try { + String path = wordUrl; + File realpath = new File(path); + if (!realpath.exists()) { + realpath.mkdirs(); + } + pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + f.getName(); + urlString = realpath + "/" + pathName; + // 澶嶅埗鏂囦欢鍒版寚瀹氳矾寰� + Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING); + inReport("/word/" + pathName, insReport.getId()); + } catch (IOException e) { + throw new ErrorException("鏂囦欢涓婁紶澶辫触"); + } + } + } + } catch (IOException e) { + throw new ErrorException("鏂囦欢澶勭悊澶辫触"); + } finally { + if (tempFile != null && tempFile.exists()) { + tempFile.delete(); + } + // 閫掑綊鍒犻櫎瑙e帇鐩綍鍙婂叾涓殑鏂囦欢 + if (unzipDir.exists()) { + deleteDirectory(unzipDir); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶� + } + } + return 0; + } + + + //瑙e帇鏂囦欢澶� + private void unzip(File zipFile, File destDir) throws IOException { + try (ZipFile zip = new ZipFile(zipFile)) { + Enumeration<? extends ZipEntry> entries = zip.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + File file = new File(destDir, entry.getName()); + if (entry.isDirectory()) { + file.mkdirs(); + } else { + file.getParentFile().mkdirs(); + try (InputStream in = zip.getInputStream(entry); + OutputStream out = new FileOutputStream(file)) { + byte[] buffer = new byte[1024]; + int len; + while ((len = in.read(buffer)) > 0) { + out.write(buffer, 0, len); + } + } + } + } + } + } + + // 鍘嬬缉鏂囦欢澶� + public static void zipDirectory(String sourceDirPath, String zipFilePath) throws IOException { + try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath))) { + Path sourceDir = Paths.get(sourceDirPath); + Files.walk(sourceDir) + .filter(path -> !Files.isDirectory(path)) + .forEach(path -> { + ZipEntry zipEntry = new ZipEntry(sourceDir.relativize(path).toString()); + try { + zipOut.putNextEntry(zipEntry); + Files.copy(path, zipOut); + zipOut.closeEntry(); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + } + + // 鍒犻櫎鏂囦欢澶瑰強鍏跺唴瀹� + public static void deleteDirectory(File directory) throws IOException { + if (directory.isDirectory()) { + File[] files = directory.listFiles(); + if (files != null) { + for (File file : files) { + deleteDirectory(file); + } + } + } + Files.delete(directory.toPath()); + } + + @Override + public void wordToPdf(String path, String sealUrl, boolean isRawMater) { + try { + wordToPdf(path, path.replace(".docx", ".pdf"), sealUrl, isRawMater); + } catch (Exception e) { + throw new ErrorException("杞崲澶辫触"); + } + } + + + public String wordToPdf(String wordPath, String pdfPath, String sealUrl, boolean isRawMater) { + FileOutputStream os = null; + try { + //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃 + InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); + License license = new License(); + license.setLicense(is); + if (!license.getIsLicensed()) { + log.info("License楠岃瘉涓嶉�氳繃..."); + return null; + } + //鐢熸垚涓�涓┖鐨凱DF鏂囦欢 + File file; + //鍒ゆ柇鏄惁鏄繘鍘傛姤鍛� + if (!isRawMater) { + file = new File(pdfPath.replace(".pdf", "-1.pdf")); + } else { + file = new File(pdfPath.replace(".pdf", ".pdf")); + } + os = new FileOutputStream(file); + //瑕佽浆鎹㈢殑word鏂囦欢 + com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); + doc.save(os, SaveFormat.PDF); + + //娣诲姞楠戠紳绔� + if (!isRawMater) { + stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl); + } + + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + + /** + * 鍒囧壊鍥剧墖 + * + * @param Path 鍥剧墖璺緞 + * @param n 鍒囧壊浠芥暟 + */ + public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException { + com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n]; + BufferedImage img = ImageIO.read(new File(Path)); + + int h = img.getHeight(); + int w = img.getWidth(); + + int sw = w / n; + for (int i = 0; i < n; i++) { + BufferedImage subImg; + if (i == n - 1) {//鏈�鍚庡墿浣欓儴鍒� + subImg = img.getSubimage(i * sw, 0, w - i * sw, h); + } else {//鍓峮-1鍧楀潎鍖�鍒� + subImg = img.getSubimage(i * sw, 0, sw, h); + } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageIO.write(subImg, Path.substring(Path.lastIndexOf('.') + 1), out); + nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray()); + + } + return nImage; + } + + /** + * 鐩栭獞缂濈珷 + * + * @param infilePath 鍘烶DF璺緞 + * @param outFilePath 杈撳嚭PDF璺緞 + */ + public static void stamperCheckMarkPDF(String infilePath, String outFilePath, String picPath) throws IOException, DocumentException { + PdfReader reader = new PdfReader(infilePath);//閫夋嫨闇�瑕佸嵃绔犵殑pdf + PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//鍔犲畬鍗扮珷鍚庣殑pdf + + + com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//鑾峰緱绗竴椤� + float height = pageSize.getHeight(); + float width = pageSize.getWidth(); + + int nums = reader.getNumberOfPages(); + com.itextpdf.text.Image[] nImage = slicingImages(picPath, nums);//鐢熸垚楠戠紳绔犲垏鍓插浘鐗� + + for (int n = 1; n <= nums; n++) { + PdfContentByte over = stamp.getOverContent(n);//璁剧疆鍦ㄧ鍑犻〉鎵撳嵃鍗扮珷 + com.itextpdf.text.Image img = nImage[n - 1];//閫夋嫨鍥剧墖 + float newHeight = 100f; + float newWidth = img.getWidth() / (img.getHeight() / 100); + img.scaleAbsolute(newWidth, newHeight);//鎺у埗鍥剧墖澶у皬 + img.setAbsolutePosition(width - newWidth, height / 2 - newHeight / 2);//鎺у埗鍥剧墖浣嶇疆 + over.addImage(img); + } + stamp.close(); + } + + @Transactional(rollbackFor = Exception.class) + public void isRawMaterial(InsOrder insOrder) { + IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() + .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); + if (Objects.isNull(one)) { + throw new ErrorException("鎵句笉鍒板師鏉愭枡淇℃伅"); + } + // 鍒ゆ柇鏄惁鏈変笉鍚堟牸淇℃伅 + Long count = insUnqualifiedHandlerMapper.selectCount(Wrappers.<InsUnqualifiedHandler>lambdaQuery() + .eq(InsUnqualifiedHandler::getInventoryQuantityId, one.getId())); + String toLocation = null; + + // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 + Long unqualifiedCount = getUnqualifiedCount(insOrder); + + if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1)) { + // 鍘熸潗鏂欑Щ搴� + toLocation = this.moveRawMaterial(one); + } + + // 鍒ゆ柇缁撴潫鐘舵�佷慨鏀瑰悎鏍肩姸鎬� + int inspectStatus = (count == 0 && unqualifiedCount == 0) ? 1 : 2; + insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() + .eq(InsOrder::getId, insOrder.getId()) + .set(InsOrder::getInsResult, inspectStatus)); + + if (one.getIsFinish().equals(0)) { + ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate() + .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId()) + .set(IfsInventoryQuantity::getInspectStatus, inspectStatus)); + + // 淇敼ifs搴撳瓨鐘舵�� + if (StringUtils.isBlank(toLocation)) { + ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() + .set(IfsInventoryQuantity::getIsFinish, 1) + .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())); + } else { + ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>() + .set(IfsInventoryQuantity::getIsFinish, 1) + .set(IfsInventoryQuantity::getToLocation, toLocation) + .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(); + // 鍙戦�佷紒涓歩nspectStatus淇¢�氱煡 + if (inspectStatus == 1) { + message += "\n妫�娴嬬粨鏋�: 鍚堟牸"; + } else { + message += "\n妫�娴嬬粨鏋�: 涓嶅悎鏍�"; + } + WxCpUtils.informWebHook(wechatProperty.getExaminingUrl(), message); + }); + + } + + + } + + /** + * 鍒ゆ柇鏄惁鏈変笉鍚堟牸 + * @param insOrder + * @return + */ + @Override + public Long getUnqualifiedCount(InsOrder insOrder) { + Long unqualifiedCount = 0L; + List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery() + .eq(InsSample::getInsOrderId, insOrder.getId())); + if (CollectionUtils.isNotEmpty(insSamples)) { + unqualifiedCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList())) + .eq(InsProduct::getInsResult, 0)); + + // 鍒ゆ柇濡傛灉鏈変笉鍚堟牸鐨勬楠岄」, 鍒ゆ柇鏈夋病鏈夋楠岄」澶嶆祴, 澶嶆牳鍚堟牸涔熺畻鍚堟牸閫氳繃 + if (!unqualifiedCount.equals(0L)) { + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList())) + .eq(InsProduct::getInsResult, 0)); + + boolean flag = true; + for (InsProduct insProduct : insProducts) { + Long unqualifiedProductCount = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery() + .eq(InsUnqualifiedRetestProduct::getInsProductId, insProduct.getId()) + .ne(InsUnqualifiedRetestProduct::getInsResult, 0)); + if (unqualifiedProductCount != 2) { + flag = false; + } + } + if (flag) { + unqualifiedCount = 0L; + } + } + } + return unqualifiedCount; + } + + /** + * ifs绉诲簱鎿嶄綔 + * @param one + * @return + */ + @Override + public String moveRawMaterial(IfsInventoryQuantity one) { + String toLocation; + // 鐧昏閲囪喘妫�楠岀粨鏋淪TD + 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 鍚庣画闇�瑕佽皟鐢↖FS鐨勬帴鍙� 绉诲叆鐨勫簱浣嶅彿 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 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean sendBackTask(Integer id) { + InsReport report = insReportMapper.selectById(id); + // 鏍规嵁璁㈠崟鏌ヨ璇曢獙瀹� + String laboratory = insOrderMapper.selectLaboratoryByOrderId(report.getInsOrderId()); + + // 淇敼璁㈠崟鐘舵�� + insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate() + .eq(InsOrderState::getInsOrderId, report.getInsOrderId()) + .eq(InsOrderState::getLaboratory, laboratory) + .set(InsOrderState::getInsState, 4)); + + Integer insSampleId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery() + .eq(InsSampleUser::getInsSampleId, report.getInsOrderId()) + .orderByDesc(InsSampleUser::getId) + .last("limit 1")).getId(); + insSampleUserMapper.deleteById(insSampleId); + + // 淇敼鎶ュ憡琛屼负鏈樉绀� + insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate() + .eq(InsReport::getId, id) + .set(InsReport::getIsPass, 0)); + + return false; + } + + /** + * 鎶ュ憡鎶ヨ〃瀵煎嚭 + * @param dto + * @param response + */ + @Override + public void reportAllExport(ReportPageDto dto, HttpServletResponse response) throws UnsupportedEncodingException { + //鏌ヨ瀵煎嚭鐨勮垂鐢ㄧ粺璁℃暟鎹� + + //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id + + 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鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 + 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(); + + //鍚憇heet0鍐欏叆鏁版嵁 浼犲叆绌簂ist杩欐牱鍙鍑鸿〃澶� + excelWriter.write(insReportExports, mainSheet); + //鍏抽棴娴� + excelWriter.finish(); + } catch (IOException e) { + throw new RuntimeException("瀵煎嚭澶辫触"); + } + + + } + + + /** + * 鍏堜慨鏀归噰璐鍗曟壒娆″彿, 鍚庤繘琛岀Щ搴撴搷浣� + * @param one + * @param toLocation + */ + 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); + + Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap)); + + 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())); + } + + 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()); + } + + } + + /** + * 鏇挎崲娈佃惤鏂囨湰 + * @param filePath docx瑙f瀽瀵硅薄 + * @param textMap 闇�瑕佹浛鎹㈢殑淇℃伅闆嗗悎 + */ + public static void changeText(Map<String, String> textMap, String filePath) { + try { + FileInputStream stream = new FileInputStream(filePath); + XWPFDocument document = new XWPFDocument(stream); + List<XWPFTable> tables = document.getTables(); + for (XWPFTable table : tables) { + for (XWPFTableRow row : table.getRows()) { + for (XWPFTableCell cell : row.getTableCells()) { + + textMap.forEach((s, s2) -> { + if (cell.getText().equals(s)) { + XWPFParagraph paragraph = cell.getParagraphs().get(0); + XWPFRun oldRun = paragraph.getRuns().get(0); + // 淇濆瓨鍘熸牱寮� + String fontFamily = oldRun.getFontFamily(); + int fontSize = oldRun.getFontSize(); + String color = oldRun.getColor(); + ParagraphAlignment alignment = paragraph.getAlignment(); + // 鏇挎崲鍐呭 + paragraph.removeRun(0); // 绉婚櫎鍘熸湁鐨� run + XWPFRun newRun = paragraph.createRun(); + newRun.setText(s2); + // 搴旂敤鍘熸牱寮� + newRun.setFontFamily(fontFamily); + newRun.setFontSize(fontSize); + newRun.setColor(color); + paragraph.setAlignment(alignment); + } + }); + } + } + } + FileOutputStream fileOutputStream = new FileOutputStream(filePath); + document.write(fileOutputStream); + fileOutputStream.close(); + + } catch (Exception e) { + e.printStackTrace(); + throw new ErrorException(e.getMessage()); + } + } + + /** + * word杞崲pdf + * @param path + * @return + */ + private String wordToPdfTemp(String path) { + try { + return wordToPdf(path, path.replace(".docx", "-涓存椂.pdf")); + } catch (Exception e) { + throw new ErrorException("杞崲澶辫触"); + } + } + + private String wordToPdf(String wordPath, String pdfPath) { + FileOutputStream os = null; + try { + //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃 + InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); + License license = new License(); + license.setLicense(is); + if (!license.getIsLicensed()) { + log.info("License楠岃瘉涓嶉�氳繃..."); + return null; + } + //鐢熸垚涓�涓┖鐨凱DF鏂囦欢 + File file; + //鍒ゆ柇鏄惁鏄繘鍘傛姤鍛� + file = new File(pdfPath); + os = new FileOutputStream(file); + //瑕佽浆鎹㈢殑word鏂囦欢 + com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); + doc.save(os, SaveFormat.PDF); + return file.getName(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } +} + + + + + + -- Gitblit v1.9.3