diff --git a/src/main/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImpl.java b/src/main/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImpl.java index dc6fdc3..a61ad11 100644 --- a/src/main/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImpl.java +++ b/src/main/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImpl.java @@ -50,10 +50,10 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe List source = request == null ? null : request.getItems(); if (source == null || source.size() < MIN_EXPENSE_ROWS || source.size() > MAX_EXPENSE_ROWS) { throw new ServiceException(HttpStatus.BAD_REQUEST, - "Please provide between " + MIN_EXPENSE_ROWS + " and " + MAX_EXPENSE_ROWS + " manufacturing cost items."); + "请填写 " + MIN_EXPENSE_ROWS + " 至 " + MAX_EXPENSE_ROWS + " 项制造费用。"); } if (bomTotals == null) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "Please save the Step 2 BOM calculation first."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "请先完成并保存第 2 步物料 BOM 成本核算。"); } BigDecimal smallManufacturingCost = BigDecimal.ZERO; @@ -64,13 +64,13 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe String expenseName = row == null ? "" : StringUtils.trimToEmpty(row.getExpenseName()); if (StringUtils.isBlank(expenseName)) { throw new ServiceException(HttpStatus.BAD_REQUEST, - "Please enter a manufacturing expense name at row " + (index + 1) + "."); + "请填写第 " + (index + 1) + " 行的制造费用名称。"); } if (row.getSmallBatchUnitCost() == null || row.getLargeBatchUnitCost() == null || row.getSmallBatchUnitCost().compareTo(BigDecimal.ZERO) < 0 || row.getLargeBatchUnitCost().compareTo(BigDecimal.ZERO) < 0) { throw new ServiceException(HttpStatus.BAD_REQUEST, - "Please enter non-negative costs for both batches at row " + (index + 1) + "."); + "请填写第 " + (index + 1) + " 行两种批量的非负制造费用。"); } HardwareCostStepThreeItem item = new HardwareCostStepThreeItem(); item.setExpenseName(expenseName); @@ -85,7 +85,7 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe largeManufacturingCost = scale(largeManufacturingCost); HardwareCostStepThreeValidationResult result = new HardwareCostStepThreeValidationResult(); result.setValid(true); - result.setMessage("Manufacturing and unit total costs have been calculated."); + result.setMessage("制造成本与单件总成本已核算完成。"); result.setItems(normalized); result.setSmallBatchManufacturingCost(smallManufacturingCost); result.setLargeBatchManufacturingCost(largeManufacturingCost); @@ -100,12 +100,12 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe TeachingClassStudent membership = teachingClassStudentMapper.selectActiveByStudentUserId(user.getUserId()); TrainingTask task = trainingTaskMapper.selectByTaskKey(TASK_KEY); if (membership == null || task == null) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "Current training task context was not found."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "未找到当前实训任务信息。"); } StudentTrainingAnswer answer = studentTrainingAnswerMapper.selectByStudentClassAndTask( user.getUserId(), membership.getTeachingClassId(), task.getId()); if (answer == null || StringUtils.isBlank(answer.getStep2Answer())) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "Please save the Step 2 BOM calculation first."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "请先完成并保存第 2 步物料 BOM 成本核算。"); } try { JsonNode saved = objectMapper.readTree(answer.getStep2Answer()); @@ -113,23 +113,23 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe } catch (ServiceException e) { throw e; } catch (Exception e) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "The saved Step 2 BOM calculation cannot be read."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "已保存的第 2 步物料 BOM 成本核算无法读取。"); } } private BigDecimal readMoney(JsonNode source, String field) { JsonNode value = source.path(field); if (value.isMissingNode() || value.isNull() || StringUtils.isBlank(value.asText())) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "The saved Step 2 BOM calculation is incomplete."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "已保存的第 2 步物料 BOM 成本核算不完整。"); } try { BigDecimal amount = new BigDecimal(value.asText()); if (amount.compareTo(BigDecimal.ZERO) < 0) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "The saved Step 2 BOM calculation is invalid."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "已保存的第 2 步物料 BOM 成本核算无效。"); } return scale(amount); } catch (NumberFormatException e) { - throw new ServiceException(HttpStatus.BAD_REQUEST, "The saved Step 2 BOM calculation is invalid."); + throw new ServiceException(HttpStatus.BAD_REQUEST, "已保存的第 2 步物料 BOM 成本核算无效。"); } } @@ -139,10 +139,10 @@ public class HardwareCostStepThreeServiceImpl implements HardwareCostStepThreeSe private void requireStudent(JwtUser user) { if (user == null || StringUtils.isBlank(user.getUserId())) { - throw new ServiceException(HttpStatus.UNAUTHORIZED, "Please log in first."); + throw new ServiceException(HttpStatus.UNAUTHORIZED, "请先登录后再操作。"); } if (user.getRoleId() != 4) { - throw new ServiceException(HttpStatus.FORBIDDEN, "Only students can validate training answers."); + throw new ServiceException(HttpStatus.FORBIDDEN, "仅学生可以校验实训答案。"); } } diff --git a/src/test/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImplTest.java b/src/test/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImplTest.java index 8d6b8ce..ea6d8a5 100644 --- a/src/test/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImplTest.java +++ b/src/test/java/com/sztzjy/linkCommerce/service/impl/HardwareCostStepThreeServiceImplTest.java @@ -60,6 +60,21 @@ class HardwareCostStepThreeServiceImplTest { new HardwareCostStepThreeServiceImpl.BomTotals(new BigDecimal("1"), new BigDecimal("1")))); } + @Test + void reportsChineseRowSpecificPromptWhenManufacturingExpenseNameIsBlank() { + ServiceException exception = assertThrows(ServiceException.class, () -> service.validateAgainstBomTotals( + request( + item("设备折旧费", "1", "1"), + item("生产运维费", "1", "1"), + item("人员薪酬", "1", "1"), + item("场地租赁费", "1", "1"), + item("包装费用", "1", "1"), + item("", "1", "1")), + new HardwareCostStepThreeServiceImpl.BomTotals(new BigDecimal("1"), new BigDecimal("1")))); + + assertEquals("请填写第 6 行的制造费用名称。", exception.getMessage()); + } + private HardwareCostStepThreeValidationRequest request(HardwareCostStepThreeItem... items) { HardwareCostStepThreeValidationRequest request = new HardwareCostStepThreeValidationRequest(); request.setItems(Arrays.asList(items));