From cb3ec598dc18e66b70a2cc9f7181c8be5bcf6e57 Mon Sep 17 00:00:00 2001 From: zhuo <2089219845@qq.com> Date: 星期二, 01 四月 2025 08:50:16 +0800 Subject: [PATCH] 检验项预警非文字检验项都要预警 --- inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java | 1186 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 711 insertions(+), 475 deletions(-) diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java index 1f39ef1..b8bb4a0 100644 --- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java +++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java @@ -30,27 +30,28 @@ import com.ruoyi.basic.pojo.IfsInventoryQuantity; import com.ruoyi.basic.pojo.StandardTemplate; import com.ruoyi.basic.service.StandardTemplateService; +import com.ruoyi.common.constant.DictDataConstants; import com.ruoyi.common.constant.InsOrderTypeConstants; +import com.ruoyi.common.constant.MenuJumpPathConstants; import com.ruoyi.common.core.domain.entity.Custom; import com.ruoyi.common.core.domain.entity.InformationNotification; -import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.domain.entity.User; -import com.ruoyi.common.utils.DateImageUtil; -import com.ruoyi.common.utils.QueryWrappers; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.WxCpUtils; +import com.ruoyi.common.utils.*; import com.ruoyi.framework.exception.ErrorException; import com.ruoyi.inspect.dto.*; import com.ruoyi.inspect.mapper.*; import com.ruoyi.inspect.pojo.*; import com.ruoyi.inspect.service.*; +import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo; import com.ruoyi.inspect.vo.InsOrderPlanVO; import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper; import com.ruoyi.performance.mapper.PerformanceShiftMapper; import com.ruoyi.performance.mapper.ShiftTimeMapper; import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours; +import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHoursTemporary; import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursService; +import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursTemporaryService; import com.ruoyi.system.mapper.CustomMapper; import com.ruoyi.system.mapper.UserMapper; import com.ruoyi.system.service.ISysDictTypeService; @@ -58,6 +59,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.poi.xwpf.usermodel.*; import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; import org.springframework.mock.web.MockMultipartFile; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; @@ -70,13 +72,13 @@ import java.math.RoundingMode; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -103,14 +105,9 @@ private InsOrderStateMapper insOrderStateMapper; @Resource private InsProductMapper insProductMapper; - @Resource - private ShiftTimeMapper shiftTimeMapper; - @Resource - private PerformanceShiftMapper performanceShiftMapper; + @Value("${wordUrl}") private String wordUrl; - @Value("${twoCode}") - private String twoCode; @Resource private InsReportMapper insReportMapper; @Resource @@ -118,11 +115,9 @@ @Resource private InsProductUserMapper insProductUserMapper; @Resource - private InsUnPassService insUnPassService; + private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService; @Resource private AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper; - @Resource - private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService; @Resource private InformationNotificationService informationNotificationService; @Resource @@ -131,7 +126,6 @@ private CustomMapper customMapper; @Value("${file.path}") private String imgUrl; - @Resource private InsOrderFileMapper insOrderFileMapper; @Resource @@ -150,8 +144,7 @@ private InsOrderFactoryVerifyMapper insOrderFactoryVerifyMapper; @Resource private InsOrderFactoryVerifyItemService insOrderFactoryVerifyItemService; - @Value("${file.licenseUrl}") - private String licenseUrl; + @Resource private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper; @Resource @@ -162,6 +155,12 @@ private InsOrderDeviceRecordService insOrderDeviceRecordService; @Resource private ISysDictTypeService iSysDictTypeService; + @Resource + private InsOrderRatesService insOrderRatesService; + @Resource + private InsProductDeviationWarningService insProductDeviationWarningService; + @Resource + private InsProductDeviationWarningDetailService insProductDeviationWarningDetailService; @Override @@ -236,17 +235,19 @@ // 鏌ヨ鍘傚瀵嗗害 String supplierDensity = ""; - SampleProductDto sampleProductDto = list.get(0); + if (CollectionUtils.isNotEmpty(list)) { + SampleProductDto sampleProductDto = list.get(0); - // 鍒ゆ柇鏈夋病鏈夌粦瀹氬瀷鍙� - String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(), - order.getProduction(), - sampleProductDto.getModel()); - if (StringUtils.isNotBlank(modelValue)) { - supplierDensity = modelValue; - } else { - supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(), - order.getProduction()); + // 鍒ゆ柇鏈夋病鏈夌粦瀹氬瀷鍙� + String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(), + order.getProduction(), + sampleProductDto.getModel()); + if (StringUtils.isNotBlank(modelValue)) { + supplierDensity = modelValue; + } else { + supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(), + order.getProduction()); + } } map.put("supplierDensity", supplierDensity); return map; @@ -508,6 +509,7 @@ InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); this.addAuxiliary(userId, finalInsProduct, insOrder); }); + } }); String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null); @@ -524,55 +526,60 @@ // 娣诲姞璁惧璁板綍 threadPoolTaskExecutor.execute(() -> { - InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId()); - User user = userMapper.selectById(userId); - // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍 - List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId()); - Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet()); + // 娣诲姞璁惧浣跨敤璁板綍 + addDeviceRecord(insSample, userId); + }); + } - // 鑾峰彇璁㈠崟璁惧缂栧彿 - List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId()); - Set<String> deviceCodeSet = new HashSet<>(); - for (InsProductResult result : resultList) { - // 娣诲姞璁惧缂栧彿 - List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class); - for (JSONObject jsonObject : jsonObjects) { - if (!"".equals(jsonObject.get("v") + "")) { - List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�"); - deviceCodeSet.addAll(v); - } + private synchronized void addDeviceRecord(InsSample insSample, Integer userId) { + InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId()); + User user = userMapper.selectById(userId); + // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍 + List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId()); + Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet()); + + // 鑾峰彇璁㈠崟璁惧缂栧彿 + List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId()); + Set<String> deviceCodeSet = new HashSet<>(); + for (InsProductResult result : resultList) { + // 娣诲姞璁惧缂栧彿 + List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class); + for (JSONObject jsonObject : jsonObjects) { + if (!"".equals(jsonObject.get("v") + "")) { + List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�"); + deviceCodeSet.addAll(v); } } - // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍 - Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset); - // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id - if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) { - List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers); - List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> { - InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord(); - insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId()); - insOrderDeviceRecord.setDeviceId(deviceId); - insOrderDeviceRecord.setSampleCode(order.getEntrustCode()); - insOrderDeviceRecord.setUseBefore(1); - insOrderDeviceRecord.setUseAfter(1); - insOrderDeviceRecord.setUsePerson(user.getName()); - insOrderDeviceRecord.setUsePersonId(user.getId()); - return insOrderDeviceRecord; - }).collect(Collectors.toList()); + } + // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍 + Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset); + // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id + if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) { + List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers); + List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> { + InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord(); + insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId()); + insOrderDeviceRecord.setDeviceId(deviceId); + insOrderDeviceRecord.setSampleCode(order.getEntrustCode()); + insOrderDeviceRecord.setUseBefore(1); + insOrderDeviceRecord.setUseAfter(1); + insOrderDeviceRecord.setUsePerson(user.getName()); + insOrderDeviceRecord.setUsePersonId(user.getId()); + return insOrderDeviceRecord; + }).collect(Collectors.toList()); - insOrderDeviceRecordService.saveBatch(collect); + insOrderDeviceRecordService.saveBatch(collect); - } + } - // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢� - Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet); - if (CollectionUtils.isNotEmpty(repoprNumbers)) { - List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers); - insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery() - .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds) - .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId())); - } - }); + // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢� + Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet); + if (CollectionUtils.isNotEmpty(repoprNumbers)) { + List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers); + insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery() + .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds) + .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId())); + } } private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) { @@ -592,8 +599,27 @@ return insSampleUserMapper.insert(insSampleUser); } + /** + * 鏌ヨ妯℃澘鍐呭 + * @param order + * @param insProducts + */ private void getTemplateThing(InsOrder order, List<InsProduct> insProducts) { Set<Integer> set = new HashSet<>(); + // 妫�楠岄」鍒嗙被+妫�楠岄」+妫�楠屽瓙椤圭殑鎷兼帴 +// List<String> itemNameList = insProducts.stream().map(insProduct -> { +// String itemName = ""; +// if (StringUtils.isNotBlank(insProduct.getInspectionItemClass())) { +// itemName += insProduct.getInspectionItemClass().trim(); +// } +// if (StringUtils.isNotBlank(insProduct.getInspectionItem())) { +// itemName += insProduct.getInspectionItem().trim(); +// } +// if (StringUtils.isNotBlank(insProduct.getInspectionItemSubclass())) { +// itemName += insProduct.getInspectionItemSubclass().trim(); +// } +// return itemName; +// }).collect(Collectors.toList()); // 鏌ヨ璁㈠崟鐘舵�佸垽鏂槸鍚︽槸鏌ュ巻鍙叉ā鏉� if (order.getIsFirstSubmit() != null && order.getIsFirstSubmit().equals(1)) { InsOrderState insOrderState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery() @@ -613,8 +639,9 @@ .eq(InsOrderStandardTemplate::getInsOrderId, order.getId())); thing = one.getThing(); if (StrUtil.isNotEmpty(thing)) { - JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); - JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); + thing = GZipUtil.uncompress(thing); + JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0); + JSONObject config = sheet.getJSONObject("config"); List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); Map<String, Object> style = new HashMap<>(); style.put("rowlen", config.get("rowlen")); @@ -634,33 +661,111 @@ } String thing = null; if (product.getTemplateId() != null && set.add(product.getTemplateId())) { - long begin = System.currentTimeMillis(); thing = standardTemplateService.getStandTempThingById(product.getTemplateId()); - long end = System.currentTimeMillis(); - System.out.println("=========鏃堕棿====" + (end - begin)); } if (StrUtil.isNotEmpty(thing)) { - JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); - JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); + JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0); + JSONObject config = sheet.getJSONObject("config"); List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); Map<String, Object> style = new HashMap<>(); style.put("rowlen", config.get("rowlen")); style.put("columnlen", config.get("columnlen")); product.setTemplate(cellData); product.setStyle(style); - long begin = System.currentTimeMillis(); product.setTemplateName(standardTemplateService.getStandTempNameById(product.getTemplateId())); - long end = System.currentTimeMillis(); - System.out.println("=========鏃堕棿22222====" + (end - begin)); } } + } + + /** + * todo: 鍘熷璁板綍妯℃澘娓呴櫎娌℃湁浣跨敤鐨勬楠岄」(鏆傛椂鏈塨ug鏃犳硶浣跨敤) + * @param sheet + * @param itemNameList + */ + private static void eliminateItem(JSONObject sheet, List<String> itemNameList) { + // 鑾峰彇鍒� 妫�楠岄」鍒嗙被+妫�楠岄」+妫�楠屽瓙椤圭殑鎷兼帴,濡傛灉妯℃澘閲岀殑淇℃伅璺熸帴鍙h繑鍥炵殑妫�楠岄」淇℃伅鑳藉鍖归厤鍒欏睍绀哄嚭鏉� + + // 寰幆琛屾暟鍒ゆ柇鏄惁 + JSONArray dataListJSONArray = sheet.getJSONArray("data"); + + // 娣诲姞鍧愭爣map + Map<String, String> coordinatesMap = new HashMap<>(); + + // 闇�瑕佺Щ闄ょ殑绱㈠紩 + List<Integer> deleteIndex = new ArrayList<>(); + // 寰幆鍒� + for (int r = 0; r < dataListJSONArray.size(); r++) { + JSONArray dataList = dataListJSONArray.getJSONArray(r); + // 寰幆琛� + String itemName = ""; + // 鍒ゆ柇鏄惁鏄剧ず + boolean isShow = false; + + for (int c = 0; c < dataList.size(); c++) { + // 鏌ヨ鎵规敞 + JSONObject jsonObject = dataList.getJSONObject(c); + try { + if (jsonObject.getJSONObject("ps").getString("value").equals("妫�楠岄」鍒嗙被")) { + String value = jsonObject.getString("v").trim(); + itemName += value; + // 娣诲姞鍧愭爣 + String coordinates = coordinatesJoint(r, c); + coordinatesMap.put(coordinates, value); + isShow = true; + } else if (jsonObject.getJSONObject("ps").getString("value").equals("妫�楠岄」")) { + String value = jsonObject.getString("v").trim(); + itemName += value; + // 娣诲姞鍧愭爣 + String coordinates = coordinatesJoint(r, c); + coordinatesMap.put(coordinates, value); + isShow = true; + } else if (jsonObject.getJSONObject("ps").getString("value").equals("妫�楠屽瓙椤�")) { + String value = jsonObject.getString("v").trim(); + itemName += value; + // 娣诲姞鍧愭爣 + String coordinates = coordinatesJoint(r, c); + coordinatesMap.put(coordinates, value); + isShow = true; + } + } catch (Exception e) { + // 鍒ゆ柇鏄惁鏈塵c鍚堝苟鍗曞厓鏍� + if (jsonObject != null && jsonObject.getJSONObject("mc") != null) { + // 鏌ヨ鍧愭爣杩涜娣诲姞 + String value = coordinatesMap.get(coordinatesJoint(jsonObject.getJSONObject("mc").getInteger("r"), jsonObject.getJSONObject("mc").getInteger("c"))); + if (StringUtils.isNotBlank(value) && !itemName.contains(value)) { + itemName += value; + } + } + } + } + // 鍒ゆ柇璇ヨ鍗曟槸鍚︽湁鏀规楠岄」, 娌℃湁鍓旈櫎 + if (isShow) { + if (!itemNameList.contains(itemName)) { + dataListJSONArray.remove(r); + r--; + } + } + } + } + + + /** + * 鍧愭爣鎷兼帴 + * @param r 妯潗鏍� + * @param c 绾靛潗鏍� + * @return + */ + private static String coordinatesJoint(int r, int c) { + String coordinates = ""; + coordinates = "r:" + r + ",c:" + c; + return coordinates; } @Override @Transactional(rollbackFor = Exception.class) public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode) { InsOrder order = insOrderMapper.selectById(orderId); - // 鍒ゆ柇鏄惁鏈夐噸澶嶇紪鍙�, 鏈夐噸澶嶇紪鍙峰仛鎻愰啋 + // 1. 鍒ゆ柇鏄惁鏈夐噸澶嶇紪鍙�, 鏈夐噸澶嶇紪鍙峰仛鎻愰啋 Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery() .ne(InsOrder::getState, -1) .ne(InsOrder::getIfsInventoryId, order.getIfsInventoryId()) @@ -669,7 +774,7 @@ throw new ErrorException("褰撳墠缂栧彿鏈夐噸澶�, 璇峰厛鍘讳慨鏀归噸澶嶇紪鍙�"); } - // 鍒ゆ柇璇ヨ鍗曟槸鍚︽槸绗竴娆$敓浜� + // 2. 鍒ゆ柇璇ヨ鍗曟槸鍚︽槸绗竴娆$敓浜�(鍚庣画鎶ュ憡鐢熸垚鍙彇绗竴娆℃彁浜ゆ椂闂�) if (!(order.getIsFirstSubmit() != null && order.getIsFirstSubmit().equals(1))) { insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() .eq(InsOrder::getId, orderId) @@ -677,11 +782,12 @@ .set(InsOrder::getFirstSubmitDate, LocalDateTime.now())); } + // 3. 鍒ゆ柇鏄惁鏈夋湭妫�椤� List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery() .eq(InsSample::getInsOrderId, orderId).select(InsSample::getId)); - List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList()); + List<Integer> InsSampleIds = insSamples.stream().map(InsSample::getId).collect(Collectors.toList()); List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() - .in(InsProduct::getInsSampleId, ids) + .in(InsProduct::getInsSampleId, InsSampleIds) .eq(InsProduct::getSonLaboratory, laboratory) .eq(InsProduct::getState, 1) .and(wrapper -> wrapper @@ -689,37 +795,37 @@ .or() .eq(InsProduct::getInsResult, 2) ) - .isNull(InsProduct::getInsFiberId) - .isNull(InsProduct::getInsFibersId) .ne(InsProduct::getIsBinding, 1)); - insProducts.addAll(insProductMapper.selectFiberInsProduct(ids, laboratory)); + insProducts.addAll(insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory)); if (insProducts.size() > 0) { String str = ""; int count = 0; for (InsProduct product : insProducts) { count++; - str += "<br/>" + count + "锛�" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>"; - + str += (count != 0 ? "\n" : "") + count + "锛�" + + product.getInspectionItemClass() + " " + + product.getInspectionItem() + " " + + product.getInspectionItemSubclass(); } if (ObjectUtils.isNotEmpty(str)) { - throw new ErrorException("<strong>瀛樺湪寰呮楠岀殑椤圭洰锛�</strong><br/>" + str); + throw new ErrorException("瀛樺湪寰呮楠岀殑椤圭洰锛�" + str); } } + + // 4.淇敼妫�娴嬬粨鏋� insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId) .eq(InsOrderState::getLaboratory, laboratory) .set(InsOrderState::getInsTime, LocalDateTime.now()) .set(InsOrderState::getInsState, 3) .set(InsOrderState::getVerifyUser, verifyUser)); - // 鍙戦�佹秷鎭� + + // 5.鍙戦�佹秷鎭�氱煡缁欏鏍镐汉 // 鏌ヨ褰撳墠浜轰俊鎭� Integer userId = SecurityUtils.getUserId().intValue(); String userName = insProductMapper.selectUserById(userId).get("name"); - // 鏌ヨ鍙戦�佷汉淇℃伅 String sendUserAccount = insProductMapper.selectUserById(verifyUser).get("account"); - - InformationNotification info = new InformationNotification(); info.setCreateUser(userName); info.setMessageType("2"); @@ -728,18 +834,19 @@ info.setSenderId(userId); info.setConsigneeId(verifyUser); info.setViewStatus(false); - info.setJumpPath("b1-inspect-orderPlan-review"); + info.setJumpPath(MenuJumpPathConstants.INSPECTION_REVIEW); informationNotificationService.addInformationNotification(info); - //澶嶆牳浜�--妫�楠屽崟鐩稿叧璐熻矗浜� + // 6.澶嶆牳浜�--鏂板妫�楠屽崟鐩稿叧璐熻矗浜� InsSampleUser insSampleUser = new InsSampleUser(); insSampleUser.setUserId(verifyUser); insSampleUser.setInsSampleId(orderId); insSampleUser.setState(1); insSampleUser.setSonLaboratory(laboratory); insSampleUserMapper.insert(insSampleUser); - /*鏍¢獙涓�涓媟esult琛�*/ - CompletableFuture.supplyAsync(() -> { + + // 7.鏍¢獙涓�涓媟esult琛�(閬垮厤鍑虹幇澶氫釜妫�楠岄」缁撴灉) + threadPoolTaskExecutor.execute(() -> { List<Integer> ips = insProducts.stream().map(InsProduct::getId).distinct().collect(Collectors.toList()); for (Integer ip : ips) { List<InsProductResult> insProductResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() @@ -750,29 +857,242 @@ } } } - return null; }); - // todo: 鍒犻櫎鏁伴噰閲囬泦娆℃暟 -// String key = "frequency" + ":" + entrustCode + ":*"; -// RedisUtil.delsLike(key); - // 鎻愪氦鐢熸垚鎶ュ憡 + // 8.鎻愪氦鐢熸垚鎶ュ憡 this.generateReport(orderId); - // 娣诲姞涓存椂pdf鐢熸垚鍦板潃 + // 9.娣诲姞涓存椂pdf鐢熸垚鍦板潃 InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery() .eq(InsReport::getInsOrderId, orderId)); String tempUrlPdf = this.wordToPdfTemp(report.getUrl().replace("/word", wordUrl)); report.setTempUrlPdf("/word/" + tempUrlPdf); insReportMapper.updateById(report); - // 鏌ヨ璁㈠崟 + // 10.鍘熷璁板綍妯℃澘澶嶅埗(娣诲姞澶囦唤, 閬垮厤淇敼鍘熷妯℃澘褰卞搷鍒板凡缁忓畬鎴愮殑鍗曞瓙) + this.templateCopy(orderId, InsSampleIds); + + // 11.鎴愬搧鎶芥牱娣诲姞鍚堟牸鐘舵�� + // 鍒ゆ柇鏄惁鏈夋娊鏍蜂俊鎭� + if (order.getQuarterItemId() != null) { + // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 + this.addProductSpotCheck(insSamples, order); + } + + // 12.娣诲姞宸ユ椂 +// // 鍒犻櫎鍘熸湰璁㈠崟宸ユ椂 +// auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery() +// .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId)); +// // 鏌ヨ宸ユ椂鏆傚瓨 +// List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery() +// .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId)); +// List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> { +// AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours(); +// BeanUtil.copyProperties(hoursTemporary, workingHours); +// workingHours.setId(null); +// return workingHours; +// }).collect(Collectors.toList()); +// auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours); + + // 13.娣诲姞璁㈠崟璐圭敤缁熻淇℃伅 + List<InsProduct> productList = insProductMapper.selectProductByOrderId(orderId); + // 鍒犻櫎鍘熸湰璐圭敤淇℃伅 + insOrderRatesService.remove(Wrappers.<InsOrderRates>lambdaQuery() + .eq(InsOrderRates::getInsOrderId, orderId)); + List<InsOrderRates> orderRatesList = productList.stream().map(insProduct -> { + InsOrderRates insOrderRates = new InsOrderRates(); + insOrderRates.setInsOrderId(orderId); + insOrderRates.setInsSampleId(insProduct.getInsSampleId()); + insOrderRates.setInsProductId(insProduct.getId()); + insOrderRates.setSampleCode(insProduct.getSampleCode()); + insOrderRates.setEntrustCode(order.getEntrustCode()); + insOrderRates.setInspectionItemClass(insProduct.getInspectionItemClass()); + insOrderRates.setInspectionItem(insProduct.getInspectionItem()); + insOrderRates.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); + insOrderRates.setCableTag(insProduct.getCableTag()); + insOrderRates.setRates(insProduct.getRates()); + insOrderRates.setManHourGroup(insProduct.getManHourGroup()); + return insOrderRates; + }).collect(Collectors.toList()); + insOrderRatesService.saveBatch(orderRatesList); + + + // 14.鍙戦�佷紒涓氬井淇¢�氱煡 + // 鏌ヨ鍘熸潗鏂� + IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); + // 鏌ヨ鏍峰搧淇℃伅 InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery() .eq(InsSample::getInsOrderId, orderId) .last("limit 1")); - // 鏌ヨ鍘熸潗鏂� - IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); + threadPoolTaskExecutor.execute(() -> { + String message = ""; + message += "妫�楠屼换鍔″鏍搁�氱煡"; + message += "\n鎻愪氦浜�: " + userName; + message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); + message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); + if (ifsInventoryQuantity != null) { + message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); + } + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 + try { + WxCpUtils.inform(sendUserAccount, message, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + // 15.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴 + if (ifsInventoryQuantity != null) { + // 鐧昏妫�楠岀粨鏋� + // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱 + // todo: ifs绉诲簱 + insReportService.isRawMaterial(order); + + // 16 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10% + // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭� + threadPoolTaskExecutor.execute(() -> { + // 娣诲姞鍒嗘瀽鏁版嵁 + addAnalysis(productList, ifsInventoryQuantity, order, userName); + }); + + + } else { + // 淇敼鎴愬搧鐘舵�� + // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 + Long unqualifiedCount = insReportService.getUnqualifiedCount(order); + if (unqualifiedCount.equals(0L)) { + insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() + .eq(InsOrder::getId, order.getId()) + .set(InsOrder::getInsResult, 1)); + } else { + insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() + .eq(InsOrder::getId, order.getId()) + .set(InsOrder::getInsResult, 0)); + } + } + + return 1; + } + + /** + * *****娣诲姞鍒嗘瀽鏁版嵁****** + * @param productList + * @param ifsInventoryQuantity + * @param order + */ + private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String userName) { + for (InsProduct insProduct : productList) { + // 鍒ゆ柇鏄惁鏄暟鍊肩被鍨� + if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) { + List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); + + if (insProductAnalysisDtoList.size() < 5) { + continue; + } + + // 鍒ゆ柇褰撳墠妫�娴嬮」鏄惁鍋忓樊瓒呰繃10% + List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductDeviationWarningDetail::getTestValue) + .collect(Collectors.toList()); + + double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue()); + // 鍒ゆ柇鍋忓樊鏄惁澶т簬10 + if (deviation > 10) { + // 鍒ゆ柇涔嬪墠鏄惁娣诲姞杩�, 娣诲姞杩囦笉闇�瑕佹坊鍔� + long count = insProductDeviationWarningService.count(Wrappers.<InsProductDeviationWarning>lambdaQuery() + .eq(InsProductDeviationWarning::getInsProductId, insProduct.getId())); + if (count == 0L) { + // 鍙戦�侀�氱煡, 骞朵笖娣诲姞鏁版嵁 + // 娣诲姞涓昏〃淇℃伅 + InsProductDeviationWarning deviationWarning = new InsProductDeviationWarning(); + deviationWarning.setInsOrderId(order.getId()); + deviationWarning.setInsSampleId(insProduct.getInsSampleId()); + deviationWarning.setInsProductId(insProduct.getId()); + deviationWarning.setEntrustCode(order.getEntrustCode()); + deviationWarning.setSampleCode(insProduct.getSampleCode()); + deviationWarning.setSupplierName(ifsInventoryQuantity.getSupplierName()); + deviationWarning.setDeviationValue(Double.toString(deviation)); + deviationWarning.setDetectionTime(insProduct.getUpdateTime()); + insProductDeviationWarningService.save(deviationWarning); + + // 娣诲姞璇︽儏鏁版嵁 + InsProductDeviationWarningDetail deviationWarningDetail = new InsProductDeviationWarningDetail(); + deviationWarningDetail.setInsOrderId(order.getId()); + deviationWarningDetail.setInsSampleId(insProduct.getInsSampleId()); + deviationWarningDetail.setInsProductId(insProduct.getId()); + deviationWarningDetail.setEntrustCode(order.getEntrustCode()); + deviationWarningDetail.setSampleCode(insProduct.getSampleCode()); + deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName()); + deviationWarningDetail.setTestValue(insProduct.getLastValue()); + deviationWarningDetail.setDetectionTime(insProduct.getCreateTime()); + deviationWarningDetail.setIsIssue(1); + + insProductAnalysisDtoList.add(deviationWarningDetail); + + // 娣诲姞id + for (InsProductDeviationWarningDetail warningDetail : insProductAnalysisDtoList) { + warningDetail.setDeviationWarningId(deviationWarning.getDeviationWarningId()); + } + + insProductDeviationWarningDetailService.saveBatch(insProductAnalysisDtoList); + + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 妫�楠岄」棰勮棰勮閫氱煡 + try { + String message = ""; + message += "妫�楠岄」棰勮棰勮閫氱煡"; + message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); + message += "\n鏍峰搧鍚嶇О: " + order.getSample(); + message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); + message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); + message += "\n渚涘簲鍟嗗悕绉�: " + ifsInventoryQuantity.getSupplierName(); + message += "\n妫�楠岄」: " + insProduct.getInspectionItem() + insProduct.getInspectionItemSubclass(); + message += "\n鍋忓樊瓒呰繃浜� 10%"; + // 鍙戦�佺粰鎻愪氦浜� + WxCpUtils.inform(userName, message, null); + + // todo: 鍙戦�佺粰妫�娴嬩腑蹇冧富浠�(鍥哄畾姝�) + WxCpUtils.inform("ZT-004704", message, null); + } catch (Exception e) { + e.printStackTrace(); + log.error("鍋忓樊棰勮浼佷笟寰俊閫氱煡鎶ラ敊"); + } + } + } + } + } + } + + /** + * *****璁$畻鍋忓樊**** + * @param data + * @param targetStr + * @return + */ + public static double isDeviationOverTenPercent(List<String> data, String targetStr) { + if (data.isEmpty()) { + return 0; + } + List<Double> doubleData = data.stream() + .map(Double::parseDouble) + .collect(Collectors.toList()); + double sum = doubleData.stream().mapToDouble(Double::doubleValue).sum(); + double average = sum / doubleData.size(); + + double target = Double.parseDouble(targetStr); + double deviationPercent = Math.abs(target - average) / average * 100; + + // 淇濈暀涓や綅灏忔暟 + DecimalFormat df = new DecimalFormat("#.00"); + String formatted = df.format(deviationPercent); + return Double.parseDouble(formatted); + } + + /** + * ******鍘熷璁板綍妯℃澘澶嶅埗***** + * @param orderId + * @param ids + */ + private void templateCopy(Integer orderId, List<Integer> ids) { // 鍒犻櫎鍘熸湰妯℃澘 insOrderStandardTemplateService.remove(Wrappers.<InsOrderStandardTemplate>lambdaQuery() .eq(InsOrderStandardTemplate::getInsOrderId, orderId)); @@ -796,138 +1116,6 @@ insOrderStandardTemplateService.save(insOrderStandardTemplate); } } - } - - - // todo: 鎴愬搧鎶芥牱娣诲姞鍚堟牸鐘舵�� - // 鍒ゆ柇鏄惁鏈夋娊鏍蜂俊鎭� - if (order.getQuarterItemId() != null) { - // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 - Long unqualifiedCount = 0L; - 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> productList = 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 : productList) { - 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; - } - } - } - spotCheckQuarterItemMapper.update(null, Wrappers.<SpotCheckQuarterItem>lambdaUpdate() - .eq(SpotCheckQuarterItem::getQuarterItemId, order.getQuarterItemId()) - .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "鍚堟牸" : "涓嶅悎鏍�")); - - } - - // 鍙戦�佷紒涓氬井淇¢�氱煡 - threadPoolTaskExecutor.execute(() -> { - String message = ""; - message += "妫�楠屼换鍔″鏍搁�氱煡"; - message += "\n鎻愪氦浜�: " + userName; - message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); - message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); - message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); - if (ifsInventoryQuantity != null) { - message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); - } - //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 - try { - WxCpUtils.inform(sendUserAccount, message, null); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - - // ifs绉诲簱 - if (ifsInventoryQuantity != null) { - // 鐧昏妫�楠岀粨鏋� - // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱 - // todo: ifs绉诲簱 - insReportService.isRawMaterial(order); - } else { - // 淇敼鎴愬搧鐘舵�� - // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 - Long unqualifiedCount = insReportService.getUnqualifiedCount(order); - if (unqualifiedCount.equals(0L)) { - insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() - .eq(InsOrder::getId, order.getId()) - .set(InsOrder::getInsResult, 1)); - } else { - insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate() - .eq(InsOrder::getId, order.getId()) - .set(InsOrder::getInsResult, 0)); - } - } - - return 1; - } - - public int pxToCm(int px) { - return px / 9; - } - - // 鑾峰彇涓や釜localDateTime鐨勬瘡涓�澶� - public static List<LocalDateTime> getLocalDateTimesBetween(LocalDateTime start, LocalDateTime end) { - List<LocalDateTime> localDateTimes = new ArrayList<>(); - LocalDate currentDate = start.toLocalDate(); - LocalDateTime currentLocalDateTime = start; - while (!currentDate.isAfter(end.toLocalDate())) { - localDateTimes.add(currentLocalDateTime); - currentLocalDateTime = currentLocalDateTime.plusDays(1); - currentDate = currentDate.plusDays(1); - } - return localDateTimes; - } - - public static String getWeek(String dayStr) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - Date date = sdf.parse(dayStr); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); - int day = calendar.get(Calendar.DAY_OF_MONTH); - return getWeekDay(dayOfWeek); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static String getWeekDay(int dayOfWeek) { - switch (dayOfWeek) { - case Calendar.MONDAY: - return "鍛ㄤ竴"; - case Calendar.TUESDAY: - return "鍛ㄤ簩"; - case Calendar.WEDNESDAY: - return "鍛ㄤ笁"; - case Calendar.THURSDAY: - return "鍛ㄥ洓"; - case Calendar.FRIDAY: - return "鍛ㄤ簲"; - case Calendar.SATURDAY: - return "鍛ㄥ叚"; - case Calendar.SUNDAY: - return "鍛ㄦ棩"; - default: - return "鏈煡"; } } @@ -1066,7 +1254,6 @@ * @param orderId */ private void generateReport(Integer orderId) { - List<InsUnPass> insUnPasses = new ArrayList<>(); /*鏍峰搧涓嬬殑椤圭洰鍙鏈変竴涓」鐩笉鍚堟牸鍒欐楠岀粨鏋滀负0,鍚﹀垯涓�1*/ //杩欓噷鐨刬nsSamples鏄鍗曚笅鐨勬墍鏈夋牱鍝佸寘鎷�("/") List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); @@ -1082,25 +1269,7 @@ insSample.setInsResult(1); } insSampleMapper.updateById(insSample); - /*澶嶆牳閫氳繃鍚庯紝灏嗕笉鍚堟牸鐨勯」鐩俊鎭坊鍔犲埌ins_un_pass琛ㄤ腑*/ - for (InsProduct insProduct : insProducts) { - if (insProduct.getInsResult() == 0) { - InsUnPass insUnPass = new InsUnPass(); - insUnPass.setId(null); - insUnPass.setModel(insSample.getModel()); - insUnPass.setSample(insSample.getSample()); - insUnPass.setInspectionItem(insProduct.getInspectionItem()); - insUnPass.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); - insUnPass.setLastValue(insProduct.getLastValue()); - insUnPass.setEntrustCode(insOrderMapper.selectById(orderId).getEntrustCode()); - List<Integer> userIds = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery().eq(InsProductUser::getInsProductId, insProduct.getId())).stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList()); - String name = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(",")); - insUnPass.setName(name); - insUnPasses.add(insUnPass); - } - } } - insUnPassService.saveBatch(insUnPasses); InsOrder insOrder = insOrderMapper.selectById(orderId); // 鎶芥鍙樻垚濮旀墭妫�楠� if (insOrder.getOrderType().equals(InsOrderTypeConstants.SPOT_CHECK)) { @@ -1527,9 +1696,9 @@ standardMethod2.append("銆�").append(s); } standardMethod2.replace(0, 1, ""); - // todo: 妫�娴嬬被鍨� -// List<SysDictData> sysDictData = iSysDictTypeService.selectDictDataByName(""); - String orderType = null; + + // 鏍峰搧绫诲瀷 + String orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE, insOrder.getOrderType()); List<RowRenderData> rows = new ArrayList<>(); List<TextRenderData> text = new ArrayList<>(); @@ -1870,10 +2039,6 @@ ConfigureBuilder builder = Configure.builder(); builder.useSpringEL(true); - // 鑾峰彇褰撳墠鏃堕棿 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String formattedDate = currentDate.format(formatter); InputStream inputStream = this.getClass().getResourceAsStream("/static/small-report-template.docx"); XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( @@ -1892,6 +2057,8 @@ put("seal1", null); }}); try { + // 淇敼鎹㈣鍜屽悎骞堕棶棰� + updaeMerge(template.getXWPFDocument(), true); String name = insReport.getCode().replace("/", "") + "-J.docx"; template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); insReport.setUrl("/word/" + name); @@ -1906,8 +2073,6 @@ } catch (IOException e) { throw new RuntimeException(e); } - // 淇敼鎹㈣鍜屽悎骞堕棶棰� - updaeMerge(insReport, null, true); } /** @@ -2275,10 +2440,19 @@ tables.forEach(table -> { table.put("tableSize", tables.size() + 1); }); + // 璁惧淇℃伅 List<Map<String, String>> deviceList = null; - if (deviceSet.size() != 0) { + if (CollectionUtils.isNotEmpty(deviceSet)) { deviceList = insOrderMapper.selectDeviceList(deviceSet); } + if (CollectionUtils.isNotEmpty(deviceList)) { + int count = 1; + for (Map<String, String> stringMap : deviceList) { + stringMap.put("index", String.valueOf(count)); + count++; + } + } + Map<String, String> codeStr = new HashMap<>(); codeStr.put("鎶ュ憡缂栧彿", insReport.getCode()); codeStr.put("鏍峰搧鍚嶇О", insOrder.getSample()); @@ -2286,19 +2460,23 @@ codeStr.put("鍙戞斁鏃ユ湡", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); String modelStr = CollUtil.join(models, "\n"); - String finalModelStr = modelStr; - // todo: 鏌ヨ瀛楀吀 + // 妫�娴嬬被鍨� String orderType = null; - String formType = null; + orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE, insOrder.getOrderType()); + // 鍒ゆ柇绗竴涓瓧鍏告槸鍚︿负绌� + if (StringUtils.isBlank(orderType)) { + orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE1, insOrder.getOrderType()); + } + + // 鏉ユ牱鏂瑰紡 + String formType = iSysDictTypeService.selectLabelByDict(DictDataConstants.FORM_TYPE, insOrder.getFormType()); // 鏍峰搧鐘舵�� - String sampleStatus = null; + String sampleStatus = iSysDictTypeService.selectLabelByDict(DictDataConstants.SAMPLE_STATUS_LIST, insOrder.getSampleStatus()); + ; - ConfigureBuilder builder = Configure.builder(); - builder.useSpringEL(true); - List<Map<String, String>> finalDeviceList = deviceList; - Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, orderId).last("limit 1")).getUserId(); + // 鍏徃淇℃伅 Custom custom = customMapper.selectById(insOrder.getCompanyId()); // 鏌ヨ鍒ゆ柇鏄惁鏈変笉鍒ゅ畾椤圭洰,鍜屽叏閮芥槸鍒ゅ畾椤� @@ -2388,11 +2566,19 @@ environment = (ObjectUtils.isNotEmpty(insOrder.getTemperature()) ? insOrder.getTemperature() + "鈩� " : "") + (ObjectUtils.isNotEmpty(insOrder.getHumidity()) ? insOrder.getHumidity() + "%" : ""); String finalEnvironment = environment; LocalDateTime finalSendTime = sendTime; - String finalResultCh = resultCh; String finalResultEn = resultEn; + String finalOrderType = orderType; + List<Map<String, String>> finalDeviceList = deviceList; + String finalModelStr = modelStr; + InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); - XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( + Configure configure = Configure.builder() + .bind("deviceList", new HackLoopTableRenderPolicy()) + .useSpringEL(true) + .build(); + + XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( new HashMap<String, Object>() {{ put("order", insOrder); put("report", insReport); @@ -2415,7 +2601,7 @@ put("images", images); put("examineUrl", null); put("ratifyUrl", null); - put("orderType", orderType); + put("orderType", finalOrderType); put("getTime", finalSendTime.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"))); put("getTimeEn", monthNames[finalSendTime.getMonthValue() - 1] + " " + finalSendTime.format(DateTimeFormatter.ofPattern("dd, yyyy"))); put("seal1", null); @@ -2427,6 +2613,8 @@ put("sampleStatus", sampleStatus); }}); try { + // 淇敼鎹㈣鍜屽悎骞堕棶棰� + updaeMerge(template.getXWPFDocument(), false); String name = insReport.getCode().replace("/", "") + ".docx"; template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); insReport.setUrl("/word/" + name); @@ -2439,8 +2627,6 @@ } catch (IOException e) { throw new RuntimeException(e); } - // 淇敼鎹㈣鍜屽悎骞堕棶棰� - updaeMerge(insReport, deviceList, false); } /** @@ -2511,188 +2697,165 @@ /** * 鍚堝苟鍗曞厓鏍� - * @param insReport - * @param deviceList */ - private void updaeMerge(InsReport insReport, List<Map<String, String>> deviceList, boolean isSmall) { + private void updaeMerge(XWPFDocument document, boolean isSmall) { // 澶勭悊鍚堝苟鍗曞厓鏍肩殑闂 - String path = wordUrl + insReport.getUrl().replaceFirst("/word", ""); - try { - // 鑾峰彇鏂囨。涓殑鎵�鏈夎〃鏍� - FileInputStream stream = new FileInputStream(path); - XWPFDocument document = new XWPFDocument(stream); - List<XWPFTable> xwpfTables = document.getTables(); - // 閬嶅巻琛ㄦ牸锛屼絾璺宠繃绗竴涓〃鏍硷紙濡傛灉deviceList涓簄ull锛屽垯棰濆璺宠繃绗簩涓級 - for (int i = 1; i < xwpfTables.size() - (deviceList == null ? 1 : 2); i++) { - // 鍒涘缓涓�涓狧ashSet鏉ュ瓨鍌ㄥ敮涓�鐨勫瓧绗︿覆锛堣繖閲屽熀浜�"鈭�"鍒嗗壊鍚庣殑绗簩閮ㄥ垎锛� - Set<String> set1 = new HashSet<>(); - // 鍒涘缓涓�涓狧ashMap鏉ュ瓨鍌ㄦ瘡涓敮涓�瀛楃涓插強鍏跺搴旂殑鍗曞厓鏍间綅缃俊鎭� - Map<String, Map<String, Integer>> maps = new HashMap<>(); - // 閬嶅巻褰撳墠琛ㄦ牸鐨勬墍鏈夎 - for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) { - // 閬嶅巻褰撳墠琛岀殑鎵�鏈夊崟鍏冩牸 - for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) { - // 妫�鏌ュ崟鍏冩牸鏂囨湰涓槸鍚﹀寘鍚�"鈭�" - if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("鈭�") > -1) { - String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�"); - // 濡傛灉鍒嗗壊鍚庣殑绗簩閮ㄥ垎鏄柊鐨勶紙鍗充箣鍓嶆湭鍑虹幇杩囷級锛屽垯娣诲姞鍒皊et1骞跺垱寤轰綅缃俊鎭痬ap - if (set1.add(split[1])) { - Map<String, Integer> map = new HashMap<>(); - // 瀛樺偍璧峰琛屻�佽捣濮嬪垪銆佺粨鏉熻锛堝綋鍓嶈锛夈�佺粨鏉熷垪锛堝綋鍓嶅垪锛� - map.put("sr", j); - map.put("sc", k); - map.put("er", j + 0); - map.put("ec", k + 0); - maps.put(split[1], map); - } else { - // 濡傛灉宸插瓨鍦紝鍒欐洿鏂扮粨鏉熻鎴栫粨鏉熷垪 - Map<String, Integer> map1 = maps.get(split[1]); - if (j == map1.get("sr")) { - map1.put("ec", map1.get("ec") + 1); - } else if (k == map1.get("sc")) { - map1.put("er", map1.get("er") + 1); - } + // 鑾峰彇鏂囨。涓殑鎵�鏈夎〃鏍� + List<XWPFTable> xwpfTables = document.getTables(); + // 閬嶅巻琛ㄦ牸 + for (int i = 1; i < xwpfTables.size(); i++) { + // 鍒涘缓涓�涓狧ashSet鏉ュ瓨鍌ㄥ敮涓�鐨勫瓧绗︿覆锛堣繖閲屽熀浜�"鈭�"鍒嗗壊鍚庣殑绗簩閮ㄥ垎锛� + Set<String> set1 = new HashSet<>(); + // 鍒涘缓涓�涓狧ashMap鏉ュ瓨鍌ㄦ瘡涓敮涓�瀛楃涓插強鍏跺搴旂殑鍗曞厓鏍间綅缃俊鎭� + Map<String, Map<String, Integer>> maps = new HashMap<>(); + // 閬嶅巻褰撳墠琛ㄦ牸鐨勬墍鏈夎 + for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) { + // 閬嶅巻褰撳墠琛岀殑鎵�鏈夊崟鍏冩牸 + for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) { + // 妫�鏌ュ崟鍏冩牸鏂囨湰涓槸鍚﹀寘鍚�"鈭�" + if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("鈭�") > -1) { + String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�"); + // 濡傛灉鍒嗗壊鍚庣殑绗簩閮ㄥ垎鏄柊鐨勶紙鍗充箣鍓嶆湭鍑虹幇杩囷級锛屽垯娣诲姞鍒皊et1骞跺垱寤轰綅缃俊鎭痬ap + if (set1.add(split[1])) { + Map<String, Integer> map = new HashMap<>(); + // 瀛樺偍璧峰琛屻�佽捣濮嬪垪銆佺粨鏉熻锛堝綋鍓嶈锛夈�佺粨鏉熷垪锛堝綋鍓嶅垪锛� + map.put("sr", j); + map.put("sc", k); + map.put("er", j + 0); + map.put("ec", k + 0); + maps.put(split[1], map); + } else { + // 濡傛灉宸插瓨鍦紝鍒欐洿鏂扮粨鏉熻鎴栫粨鏉熷垪 + Map<String, Integer> map1 = maps.get(split[1]); + if (j == map1.get("sr")) { + map1.put("ec", map1.get("ec") + 1); + } else if (k == map1.get("sc")) { + map1.put("er", map1.get("er") + 1); } - // 鍒ゆ柇灏忛珮鎶ュ憡杩樻槸澶ф姤鍛� - if (isSmall) { - // 鑾峰彇鍗曞厓鏍� - XWPFTableCell cell = xwpfTables.get(i).getRows().get(j).getTableCells().get(k); - XWPFParagraph paragraph = cell.getParagraphArray(0); - String originalText = paragraph.getText(); - String newText = originalText.split("鈭�")[0]; - List<XWPFRun> runs = paragraph.getRuns(); - for (XWPFRun run : runs) { - run.setText("", 0); // 娓呯┖ run 涓殑鏂囨湰 - } - if (!runs.isEmpty()) { - XWPFRun run = runs.get(0); - run.setText(newText); - - // 澶嶅埗鏍峰紡 - run.setFontFamily(paragraph.getRuns().get(0).getFontFamily()); - run.setFontSize(paragraph.getRuns().get(0).getFontSize()); - run.setBold(paragraph.getRuns().get(0).isBold()); - run.setItalic(paragraph.getRuns().get(0).isItalic()); - run.setUnderline(paragraph.getRuns().get(0).getUnderline()); - run.setColor(paragraph.getRuns().get(0).getColor()); - } - - cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); - paragraph.setAlignment(ParagraphAlignment.CENTER); - } else { - // 绉婚櫎鍖呭惈"鈭�"鐨勬钀斤紝骞堕噸鏂拌缃崟鍏冩牸鏂囨湰鍜屾牱寮� - String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�")[0]; - xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); - xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str); - xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); - xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER); + } + // 鍒ゆ柇灏忛珮鎶ュ憡杩樻槸澶ф姤鍛� + if (isSmall) { + // 鑾峰彇鍗曞厓鏍� + XWPFTableCell cell = xwpfTables.get(i).getRows().get(j).getTableCells().get(k); + XWPFParagraph paragraph = cell.getParagraphArray(0); + String originalText = paragraph.getText(); + String newText = originalText.split("鈭�")[0]; + List<XWPFRun> runs = paragraph.getRuns(); + for (XWPFRun run : runs) { + run.setText("", 0); // 娓呯┖ run 涓殑鏂囨湰 } + if (!runs.isEmpty()) { + XWPFRun run = runs.get(0); + run.setText(newText); + + // 澶嶅埗鏍峰紡 + run.setFontFamily(paragraph.getRuns().get(0).getFontFamily()); + run.setFontSize(paragraph.getRuns().get(0).getFontSize()); + run.setBold(paragraph.getRuns().get(0).isBold()); + run.setItalic(paragraph.getRuns().get(0).isItalic()); + run.setUnderline(paragraph.getRuns().get(0).getUnderline()); + run.setColor(paragraph.getRuns().get(0).getColor()); + } + + cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); + paragraph.setAlignment(ParagraphAlignment.CENTER); + } else { + // 绉婚櫎鍖呭惈"鈭�"鐨勬钀斤紝骞堕噸鏂拌缃崟鍏冩牸鏂囨湰鍜屾牱寮� + String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�")[0]; + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER); } } } + } - // 鍗曞厓鏍兼帓搴�, 閬垮厤鏍煎紡閿欎贡 - List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet()); - entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc")); + // 鍗曞厓鏍兼帓搴�, 閬垮厤鏍煎紡閿欎贡 + List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet()); + entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc")); - // 鎸夌収椤哄簭娣诲姞杩涢泦鍚� - List<String> list = new ArrayList<>(); - for (Map.Entry<String, Map<String, Integer>> entry : entries) { - list.add(entry.getKey()); - } + // 鎸夌収椤哄簭娣诲姞杩涢泦鍚� + List<String> list = new ArrayList<>(); + for (Map.Entry<String, Map<String, Integer>> entry : entries) { + list.add(entry.getKey()); + } - for (int a = list.size() - 1; a >= 0; a--) { - Map<String, Integer> v = maps.get(list.get(a)); - for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { - if (v.get("ec") > v.get("sc")) { - try { - TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); - } catch (Exception e) { - } - } - } - if (v.get("er") > v.get("sr")) { + for (int a = list.size() - 1; a >= 0; a--) { + Map<String, Integer> v = maps.get(list.get(a)); + for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { + if (v.get("ec") > v.get("sc")) { try { - TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); + TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); } catch (Exception e) { } } } + if (v.get("er") > v.get("sr")) { + try { + TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); + } catch (Exception e) { + } + } } - FileOutputStream fileOutputStream = new FileOutputStream(path); - document.write(fileOutputStream); - fileOutputStream.close(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); } + //澶勭悊涓嫳鏂囨崲琛岀殑闂 - try { - FileInputStream stream1 = new FileInputStream(path); - XWPFDocument document1 = new XWPFDocument(stream1); - List<XWPFTable> xwpfTables1 = document1.getTables(); - for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) { - for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) { - for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) { - if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) { - if (isSmall) { - // 鑾峰彇鍘熸湁娈佃惤鐨勭涓�涓� XWPFRun - String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); - XWPFParagraph oldParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getParagraphs().get(0); - XWPFRun oldRun = oldParagraph.getRuns().get(0); - // 淇濆瓨鍘熸湁鏍峰紡 - String fontFamily = oldRun.getFontFamily(); - int fontSize = oldRun.getFontSize(); - boolean isBold = oldRun.isBold(); - boolean isItalic = oldRun.isItalic(); - boolean isUnderline = oldRun.getUnderline() != UnderlinePatterns.NONE; - // 鍒犻櫎鍘熸湁娈佃惤 - xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); - // 娣诲姞鏂版钀� - XWPFParagraph newParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); - XWPFRun newRun = newParagraph.createRun(); - // 搴旂敤淇濆瓨鐨勬牱寮� - newRun.setFontFamily(fontFamily); - newRun.setFontSize(fontSize); - newRun.setBold(isBold); - newRun.setItalic(isItalic); - if (isUnderline) { - newRun.setUnderline(UnderlinePatterns.SINGLE); - } - // 璁剧疆鏂版枃鏈� - String[] split = text.split("@"); - newRun.setText(split[0]); - if (split.length > 1) { - newRun.addBreak(); - newRun.setText(split[1]); - } - // 璁剧疆娈佃惤瀵归綈鏂瑰紡 - newParagraph.setAlignment(ParagraphAlignment.CENTER); - } else { - String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); - String[] split = text.split("@"); - xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); - XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); - XWPFRun run = xwpfParagraph.createRun(); - run.setText(split[0]); - if (ObjectUtils.isNotNull(split[1])) { - run.addBreak(); - run.setText(split[1]); - } - xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); + + List<XWPFTable> xwpfTables1 = document.getTables(); + for (int i = 1; i < xwpfTables1.size(); i++) { + for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) { + for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) { + if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) { + if (isSmall) { + // 鑾峰彇鍘熸湁娈佃惤鐨勭涓�涓� XWPFRun + String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); + XWPFParagraph oldParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getParagraphs().get(0); + XWPFRun oldRun = oldParagraph.getRuns().get(0); + // 淇濆瓨鍘熸湁鏍峰紡 + String fontFamily = oldRun.getFontFamily(); + int fontSize = oldRun.getFontSize(); + boolean isBold = oldRun.isBold(); + boolean isItalic = oldRun.isItalic(); + boolean isUnderline = oldRun.getUnderline() != UnderlinePatterns.NONE; + // 鍒犻櫎鍘熸湁娈佃惤 + xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); + // 娣诲姞鏂版钀� + XWPFParagraph newParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); + XWPFRun newRun = newParagraph.createRun(); + // 搴旂敤淇濆瓨鐨勬牱寮� + newRun.setFontFamily(fontFamily); + newRun.setFontSize(fontSize); + newRun.setBold(isBold); + newRun.setItalic(isItalic); + if (isUnderline) { + newRun.setUnderline(UnderlinePatterns.SINGLE); } + // 璁剧疆鏂版枃鏈� + String[] split = text.split("@"); + newRun.setText(split[0]); + if (split.length > 1) { + newRun.addBreak(); + newRun.setText(split[1]); + } + // 璁剧疆娈佃惤瀵归綈鏂瑰紡 + newParagraph.setAlignment(ParagraphAlignment.CENTER); + } else { + String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); + String[] split = text.split("@"); + xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); + XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); + XWPFRun run = xwpfParagraph.createRun(); + run.setText(split[0]); + if (ObjectUtils.isNotNull(split[1])) { + run.addBreak(); + run.setText(split[1]); + } + xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); } } } } - FileOutputStream fileOutputStream1 = new FileOutputStream(path); - document1.write(fileOutputStream1); - fileOutputStream1.close(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); } } @@ -4015,7 +4178,7 @@ } /** - * 淇濆瓨鍏冩闃块噷杩涜揣楠岃瘉鍘熷璁板綍 + * *****淇濆瓨鍏冩闃块噷杩涜揣楠岃瘉鍘熷璁板綍***** * @param insOrderId 璁㈠崟Id * @param examineUserId 澶嶆牳浜篒d * @param writeUserId 妫�楠屽憳Id @@ -4165,7 +4328,7 @@ /** - * 鏍煎紡鍖栬繘鍘傞獙璇佸唴瀹� + * ***鏍煎紡鍖栬繘鍘傞獙璇佸唴瀹�**** * @param basicType * @return */ @@ -4194,7 +4357,7 @@ } /** - * word杞崲pdf + * ***word杞崲pdf*** * @param path * @return */ @@ -4211,11 +4374,10 @@ 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楠岃瘉涓嶉�氳繃..."); return null; } //鐢熸垚涓�涓┖鐨凱DF鏂囦欢 @@ -4243,6 +4405,43 @@ } /** + * *****淇敼鎴愬搧鎶芥牱鐘舵��****** + * @param insSamples + * @param order + */ + private void addProductSpotCheck(List<InsSample> insSamples, InsOrder order) { + Long unqualifiedCount = 0L; + 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> productList = 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 : productList) { + 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; + } + } + } + spotCheckQuarterItemMapper.update(null, Wrappers.<SpotCheckQuarterItem>lambdaUpdate() + .eq(SpotCheckQuarterItem::getQuarterItemId, order.getQuarterItemId()) + .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "鍚堟牸" : "涓嶅悎鏍�")); + } + + /** * 娣诲姞宸ユ椂 * @param userId * @param insProduct @@ -4253,43 +4452,80 @@ return; } - //棣栧厛鍒ゆ柇褰撳墠浜虹殑褰撳墠鏃堕棿鏄惁鏄帓鐝椂闂村唴,濡傛灉涓嶆槸灏辨槸鍔犵彮 - LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT); - //鏍¢獙濡傛灉杩欎釜浜鸿繖涓娴嬮」鐩凡缁忔坊鍔犺繃浜� List<AuxiliaryOutputWorkingHours> count2s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery() .eq(AuxiliaryOutputWorkingHours::getCheck, userId) .eq(AuxiliaryOutputWorkingHours::getInsProductId, insProduct.getId())); if (CollectionUtils.isNotEmpty(count2s)) { - auxiliaryOutputWorkingHoursMapper.deleteBatchIds(count2s.stream().map(auxiliaryOutputWorkingHours -> auxiliaryOutputWorkingHours.getId()).collect(Collectors.toList())); - } - if (ObjectUtils.isNotEmpty(insProduct.getManHour()) && StringUtils.isNotBlank(insProduct.getLastValue())) { - AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours(); - auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被 - auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤� - auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤� - auxiliaryOutputWorkingHours.setSample(insSampleMapper.selectById(insProduct.getInsSampleId()).getSampleCode());//鏍峰搧缂栧彿 - auxiliaryOutputWorkingHours.setOrderId(insOrder.getId());//璁㈠崟id - auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//闈炲姞鐝鎵樺崟鍙� - auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃� - auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲� - auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂 - auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍 - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡 - LocalDateTime localDateTime = LocalDateTime.now(); - DateTime parse = DateUtil.parse(localDateTime.format(formatter)); - auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡 - auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ - auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉 - auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环 - auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id - auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id + for (AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours : count2s) { + auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉 + } + auxiliaryOutputWorkingHoursService.updateBatchById(count2s); + } else { + if (ObjectUtils.isNotEmpty(insProduct.getManHour()) && StringUtils.isNotBlank(insProduct.getLastValue())) { + AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours(); + auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被 + auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤� + auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤� + auxiliaryOutputWorkingHours.setSample(insSampleMapper.selectById(insProduct.getInsSampleId()).getSampleCode());//鏍峰搧缂栧彿 + auxiliaryOutputWorkingHours.setOrderId(insOrder.getId());//璁㈠崟id + auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//闈炲姞鐝鎵樺崟鍙� + auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃� + auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲� + auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂 + auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡 + LocalDateTime localDateTime = LocalDateTime.now(); + DateTime parse = DateUtil.parse(localDateTime.format(formatter)); + auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡 + auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ + auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉 + auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环 + auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id + auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id - auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours); + auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours); + } } } + + public static String getWeek(String dayStr) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date date = sdf.parse(dayStr); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + int day = calendar.get(Calendar.DAY_OF_MONTH); + return getWeekDay(dayOfWeek); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String getWeekDay(int dayOfWeek) { + switch (dayOfWeek) { + case Calendar.MONDAY: + return "鍛ㄤ竴"; + case Calendar.TUESDAY: + return "鍛ㄤ簩"; + case Calendar.WEDNESDAY: + return "鍛ㄤ笁"; + case Calendar.THURSDAY: + return "鍛ㄥ洓"; + case Calendar.FRIDAY: + return "鍛ㄤ簲"; + case Calendar.SATURDAY: + return "鍛ㄥ叚"; + case Calendar.SUNDAY: + return "鍛ㄦ棩"; + default: + return "鏈煡"; + } + } } -- Gitblit v1.9.3