| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | 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 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.atomic.AtomicBoolean; |
| | |
| | | @Resource |
| | | private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService; |
| | | @Resource |
| | | private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService; |
| | | private AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper; |
| | | @Resource |
| | | private InformationNotificationService informationNotificationService; |
| | | @Resource |
| | |
| | | private ISysDictTypeService iSysDictTypeService; |
| | | @Resource |
| | | private InsOrderRatesService insOrderRatesService; |
| | | @Resource |
| | | private InsProductDeviationWarningService insProductDeviationWarningService; |
| | | @Resource |
| | | private InsProductDeviationWarningDetailService insProductDeviationWarningDetailService; |
| | | |
| | | |
| | | @Override |
| | | public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { |
| | |
| | | List<InsProduct> insProducts = new ArrayList<>(); |
| | | switch (dto.getType()) { |
| | | case 0: |
| | | insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), null); |
| | | //样品 |
| | | break; |
| | | case 4: |
| | | //电缆配置 |
| | | insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), null); |
| | | //委托 |
| | | insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag()); |
| | | break; |
| | | case 5: |
| | | //原材料下单 |
| | | insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), null); |
| | | insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag()); |
| | | break; |
| | | } |
| | | if (BeanUtil.isEmpty(insProducts)) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveInsContext(Map<String, Object> insContext, Integer currentTable, Integer currentSampleId, Integer orderId, String sonLaboratory) { |
| | | public void saveInsContext(SaveInsContextDto saveInsContextDto) { |
| | | Map<String, Object> insContext = JSON.parseObject(saveInsContextDto.getParam(), Map.class); |
| | | Integer userId = SecurityUtils.getUserId().intValue(); |
| | | InsSample insSample = insSampleMapper.selectById(currentSampleId); |
| | | InsSample insSample = insSampleMapper.selectById(saveInsContextDto.getSampleId()); |
| | | insContext.forEach((k, v) -> { |
| | | JSONObject jo = JSON.parseObject(JSON.toJSONString(v)); |
| | | InsProduct insProduct = new InsProduct(); |
| | | insProduct.setId(Integer.parseInt(k)); |
| | | InsProduct product = insProductMapper.selectById(insProduct.getId()); |
| | | if (currentTable.equals(product.getTemplateId()) && currentSampleId.equals(product.getInsSampleId())) { |
| | | if (saveInsContextDto.getCurrentTable().equals(product.getTemplateId()) && saveInsContextDto.getSampleId().equals(product.getInsSampleId())) { |
| | | List<InsProductResult> oldResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() |
| | | .eq(InsProductResult::getInsProductId, insProduct.getId())); |
| | | InsProductResult newResult = new InsProductResult(); |
| | |
| | | } |
| | | } |
| | | |
| | | // 添加工时 |
| | | // 判断是否只是参与计算值, 参与计算值实际没有填写 |
| | | InsProduct finalInsProduct = insProductMapper.selectById(product.getId()); |
| | | InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); |
| | | if (StringUtils.isNotBlank(newResult.getInsValue()) && !newResult.getInsValue().equals("[]")) { |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | this.addAuxiliary(userId, finalInsProduct, insOrder); |
| | | }); |
| | | } else { |
| | | // 判断是否是没有检验值的内容 |
| | | if (saveInsContextDto.getIsNoTestValue() != null && saveInsContextDto.getIsNoTestValue() == 1) { |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | this.addAuxiliary(userId, finalInsProduct, insOrder); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | }); |
| | | String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null); |
| | | if (sampleIdStr != null) { |
| | | int count = insProductMapper.selectInsProductCountByOrderId(orderId); |
| | | int count = insProductMapper.selectInsProductCountByOrderId(saveInsContextDto.getOrderId()); |
| | | if (count == 0) { |
| | | insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate() |
| | | .eq(InsOrderState::getInsOrderId, orderId) |
| | | .eq(InsOrderState::getLaboratory, sonLaboratory) |
| | | .eq(InsOrderState::getInsOrderId, saveInsContextDto.getOrderId()) |
| | | .eq(InsOrderState::getLaboratory, saveInsContextDto.getSonLaboratory()) |
| | | .set(InsOrderState::getInsState, 2)); |
| | | } |
| | | } |
| | |
| | | |
| | | // 添加设备记录 |
| | | 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) { |
| | |
| | | */ |
| | | 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() |
| | |
| | | } |
| | | |
| | | /** |
| | | * todo: 清除没有使用的检验项 |
| | | * todo: 原始记录模板清除没有使用的检验项(暂时有bug无法使用) |
| | | * @param sheet |
| | | * @param itemNameList |
| | | */ |
| | |
| | | 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.添加订单费用统计信息 |
| | | // 12.添加订单费用统计信息 |
| | | List<InsProduct> productList = insProductMapper.selectProductByOrderId(orderId); |
| | | // 删除原本费用信息 |
| | | insOrderRatesService.remove(Wrappers.<InsOrderRates>lambdaQuery() |
| | |
| | | insOrderRatesService.saveBatch(orderRatesList); |
| | | |
| | | |
| | | // 14.发送企业微信通知 |
| | | // 13.发送企业微信通知 |
| | | // 查询原材料 |
| | | IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId()); |
| | | // 查询样品信息 |
| | |
| | | } |
| | | }); |
| | | |
| | | // 15.ifs移库(原材料需要进行移库操作) --> 最后执行,因为失败无法回滚 |
| | | // 14.ifs移库(原材料需要进行移库操作) --> 最后执行,因为失败无法回滚 |
| | | if (ifsInventoryQuantity != null) { |
| | | // 登记检验结果 |
| | | // 判断是否有不合格, 有不合格不能移库 |
| | | // todo: ifs移库 |
| | | insReportService.isRawMaterial(order); |
| | | |
| | | // 15 判断当前样品是否为原材料, 原材料需要进行数据分析, 判断之前10条数据同一个供应商, 同一个检验项的偏差是否超过10% |
| | | // 查询ifs信息获取获取前10个供应商一样的, 检验项一样信息 |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | // 添加分析数据 |
| | | addAnalysis(productList, ifsInventoryQuantity, order, sendUserAccount); |
| | | }); |
| | | |
| | | |
| | | } else { |
| | | // 修改成品状态 |
| | | // 判断是否有不合格 |
| | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * *****添加分析数据****** |
| | | * @param productList |
| | | * @param ifsInventoryQuantity |
| | | * @param order |
| | | */ |
| | | private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String sendUserAccount) { |
| | | for (InsProduct insProduct : productList) { |
| | | // 判断是否是数值类型 |
| | | if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) { |
| | | List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); |
| | | |
| | | if (insProductAnalysisDtoList.size() < 10) { |
| | | 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(sendUserAccount, 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() |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取不合格数据 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<InsProduct> getInsProductUnqualified(InsOrderPlanProductDto dto) { |
| | | List<InsProduct> insProducts = new ArrayList<>(); |
| | | switch (dto.getType()) { |
| | | case 0: |
| | | //样品 |
| | | insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), "1"); |
| | | break; |
| | | case 4: |
| | | //电缆配置 |
| | | insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), "1"); |
| | | break; |
| | | case 5: |
| | | //原材料下单 |
| | | insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), "1"); |
| | | break; |
| | | } |
| | | return insProducts; |
| | | } |
| | | |
| | | /** |
| | | * 新增不合格复测内容 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addDisqualificationRetest(List<Integer> ids) { |
| | | public boolean addDisqualificationRetest(List<InsProduct> insProductsList) { |
| | | List<Integer> ids = insProductsList.stream().map(InsProduct::getId).collect(Collectors.toList()); |
| | | |
| | | // 判断之前是否添加过 |
| | | Long count = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery() |
| | | .in(InsUnqualifiedRetestProduct::getInsProductId, ids)); |
| | |
| | | |
| | | // 查询不合格内容 |
| | | List<InsUnqualifiedRetestProduct> list = insUnqualifiedRetestProductMapper.selectRetestProduct(ids); |
| | | // 循环判断是否是绑定值, 绑定值修改检验要求 |
| | | for (InsUnqualifiedRetestProduct insUnqualifiedRetestProduct : list) { |
| | | for (InsProduct insProduct : insProductsList) { |
| | | if (insProduct.getIsBinding().equals(1)) { |
| | | insUnqualifiedRetestProduct.setIsBinding(1); |
| | | insUnqualifiedRetestProduct.setAsk(null); |
| | | insUnqualifiedRetestProduct.setTell(null); |
| | | insUnqualifiedRetestProduct.setPrice(null); |
| | | insUnqualifiedRetestProduct.setManHour(null); |
| | | insUnqualifiedRetestProduct.setSection(null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 新增不合格内容 |
| | | insUnqualifiedRetestProductService.saveBatch(list); |
| | | list.forEach(insUnqualifiedRetestProduct -> { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<InsProduct> getInsProductUnqualifiedRetest(Integer id, Integer type, String laboratory, String cableTag, String rawMaterialTag, String retestTag) { |
| | | public List<InsProduct> getInsProductUnqualifiedRetest(InsOrderPlanProductDto dto) { |
| | | |
| | | List<InsProduct> insProducts = new ArrayList<>(); |
| | | switch (type) { |
| | | switch (dto.getType()) { |
| | | case 0: |
| | | //样品 |
| | | insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest1(id, laboratory, retestTag); |
| | | break; |
| | | case 4: |
| | | //电缆配置 |
| | | insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest5(id, laboratory, cableTag, retestTag); |
| | | //委托 |
| | | insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), dto.getRetestTag()); |
| | | break; |
| | | case 5: |
| | | //原材料下单 |
| | | insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest6(id, laboratory, rawMaterialTag, retestTag); |
| | | insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), dto.getRetestTag()); |
| | | break; |
| | | } |
| | | if (BeanUtil.isEmpty(insProducts)) { |
| | | return null; |
| | | } |
| | | InsOrder order = insOrderMapper.selectFirstSubmit(id); |
| | | InsOrder order = insOrderMapper.selectFirstSubmit(dto.getId()); |
| | | getTemplateThing(order, Collections.unmodifiableList(insProducts)); |
| | | return insProducts; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保存不合格复测检验内容 |
| | | * @param currentTable |
| | | * @param orderId |
| | | * @param sonLaboratory |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveUnqualifiedContext(Map<String, Object> insContext, Integer currentTable, Integer currentSampleId, Integer orderId, String sonLaboratory) { |
| | |
| | | BeanUtil.copyProperties(oldResults.get(0), newResult); |
| | | } |
| | | newResult.setRetestProductId(Integer.parseInt(k)); |
| | | |
| | | /*校验一下result表*/ |
| | | if (oldResults.size() > 1) { |
| | | for (int i = 1; i < oldResults.size(); i++) { |
| | | insUnqualifiedRetestResultMapper.deleteById(oldResults.get(i)); |
| | | } |
| | | } |
| | | |
| | | //检验值 |
| | | if (jo.get("insValue") != null) { |
| | | JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(jo.get("insValue"))); |
| | |
| | | for (Object o : jsonArray2) { |
| | | JSONObject comValue = JSON.parseObject(JSON.toJSONString(o)); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("r", JSON.toJSONString(comValue.get("r"))); |
| | | map.put("c", JSON.toJSONString(comValue.get("c"))); |
| | | map.put("v", JSON.parseObject(JSON.toJSONString(comValue.get("v"))).get("v")); |
| | | cv.add(map); |
| | | } |
| | |
| | | insProductUserMapper.insert(new InsProductUser(null, userId, LocalDateTime.now(), insProduct.getId())); |
| | | |
| | | |
| | | InsSample insSample = insSampleMapper.selectById(insProductMapper.selectById(insProduct.getId()).getInsSampleId()); |
| | | insSample.setInsState(1); |
| | | Long l = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, insSample.getId())); |
| | | Long l1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, insSample.getId()) |
| | | .and(wrapper -> wrapper |
| | | .isNotNull(InsProduct::getInsResult) |
| | | .or() |
| | | .ne(InsProduct::getInsResult, 2) |
| | | )); |
| | | if (Objects.equals(l, l1)) { |
| | | insSample.setInsState(2); |
| | | } |
| | | insSampleMapper.updateById(insSample); |
| | | /*校验一下result表*/ |
| | | List<InsUnqualifiedRetestResult> insProductResults = insUnqualifiedRetestResultMapper.selectList(Wrappers.<InsUnqualifiedRetestResult>lambdaQuery() |
| | | .eq(InsUnqualifiedRetestResult::getRetestProductId, insProduct.getId())); |
| | | .eq(InsUnqualifiedRetestResult::getRetestProductId, product.getId())); |
| | | if (insProductResults.size() > 1) { |
| | | for (int i = 1; i < insProductResults.size(); i++) { |
| | | insUnqualifiedRetestResultMapper.deleteById(insProductResults.get(i)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | }); |
| | | String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null); |
| | | if (sampleIdStr != null) { |
| | | int count = insProductMapper.selectInsProductCountByOrderId(orderId); |
| | | if (count == 0) { |
| | | insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate() |
| | | .eq(InsOrderState::getInsOrderId, orderId) |
| | | .eq(InsOrderState::getLaboratory, sonLaboratory) |
| | | .set(InsOrderState::getInsState, 2)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | 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( |
| | |
| | | insReportMapper.delete(Wrappers.<InsReport>lambdaQuery() |
| | | .eq(InsReport::getInsOrderId, insOrder.getId())); |
| | | insReportMapper.insert(insReport); |
| | | |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | * @param |
| | | */ |
| | | private void addBitReport(Integer orderId, InsOrder insOrder) { |
| | | Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId()); |
| | | //samples是不包括带有"/"的样品 |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | InsReport insReport = new InsReport(); |
| | |
| | | boolean isOneSample = samples.size() == 1 ? true : false; |
| | | /*基础报告(根据绘制的原始记录模版形成)*/ |
| | | samples.forEach(a -> { |
| | | Map<Integer, String> map2 = new HashMap<>(); |
| | | models.add(a.getModel()); |
| | | String standardMethodCode = baseMapper.getStandardMethodCode(a.getStandardMethodListId()); |
| | | if (StrUtil.isNotBlank(a.getSpecialStandardMethod())) { |
| | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | Configure configure = Configure.builder() |
| | | .bind("deviceList", new HackLoopTableRenderPolicy()) |
| | | .useSpringEL(true) |
| | | .build(); |
| | | |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | |
| | | insReportMapper.delete(Wrappers.<InsReport>lambdaQuery() |
| | | .eq(InsReport::getInsOrderId, insOrder.getId())); |
| | | insReportMapper.insert(insReport); |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | |
| | | // 保存到附件里面 |
| | | uploadFile(insOrderId, multipartFile); |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "合格" : "不合格")); |
| | | } |
| | | |
| | | /** |
| | | * 添加工时 |
| | | * @param userId |
| | | * @param insProduct |
| | | * @param insOrder |
| | | */ |
| | | private synchronized void addAuxiliary(Integer userId, InsProduct insProduct, InsOrder insOrder) { |
| | | if (insProduct.getIsBinding().equals(1)) { |
| | | return; |
| | | } |
| | | |
| | | //校验如果这个人这个检测项目已经添加过了 |
| | | List<AuxiliaryOutputWorkingHours> count2s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery() |
| | | .eq(AuxiliaryOutputWorkingHours::getCheck, userId) |
| | | .eq(AuxiliaryOutputWorkingHours::getInsProductId, insProduct.getId())); |
| | | if (CollectionUtils.isNotEmpty(count2s)) { |
| | | 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); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | 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 "未知"; |
| | | } |
| | | } |
| | | } |