@Test public void testUpdateTransactionLogsAsReturned() throws Exception { }
@Override public CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams) { JSONObject jsonObject = new JSONObject(); Integer newCashierId = null; HashMap<String, List<TransactionParam>> collection = new HashMap<>(); for (TransactionParam t : transactionLogParams) { String invoiceCode = t.getInvoiceCode(); if (!collection.containsKey(invoiceCode)) { collection.put(invoiceCode, new ArrayList<>()); collection.get(invoiceCode).add(t); } else collection.get(invoiceCode).add(t); } for(String invoiceCode: collection.keySet()){ List<TransactionParam> returnedProjectList = collection.get(invoiceCode); List<Integer> returnedIdList = new ArrayList<>(); for(TransactionParam returnedProject: returnedProjectList){ Integer returnedCollectionId = returnedProject.getCollectionId(); newCashierId = returnedProject.getNewCashierId(); Integer returnedProjectId = returnedProject.getProjectId(); Byte returnedTransactionStatus = returnedProject.getStatus(); Byte returnedProjectStatus = returnedProject.getProjectStatus(); returnedIdList.addAll(transactionLogMapper.listIdByCollectionAndProjectId(invoiceCode, returnedCollectionId, returnedProjectId)); System.out.println(returnedIdList.get(0)); Byte itemCategory; if(returnedCollectionId.toString().startsWith("2")) itemCategory = 1; else if(returnedCollectionId.toString().startsWith("3")) itemCategory = 2; else if(returnedCollectionId.toString().startsWith("4")) itemCategory = 3; else if(returnedCollectionId.toString().startsWith("5")) itemCategory = 4; else return CommonResult.fail(E_712); if(itemCategory != 4){ if(!(returnedTransactionStatus == 2 && returnedProjectStatus == 2)) return CommonResult.fail(E_704); } else { if(returnedTransactionStatus == 2){ if(!((returnedProjectStatus == 2 && returnedProject.getReturnAmount() < returnedProject.getRemainAmount()) || (returnedProjectStatus == 5))) return CommonResult.fail(E_704); } } switch (itemCategory){ case (byte)1: inspectionMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)2: examinationMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)3: treatmentMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)4: Short returnedReturnAmount = returnedProject.getReturnAmount(); Short returnedRemainAmount = returnedProject.getRemainAmount(); if(returnedProjectStatus == 2){ recipeMapper.updateRemainAmount(returnedCollectionId, returnedProjectId, returnedReturnAmount); if(returnedReturnAmount.equals(returnedRemainAmount)) recipeMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); } break; } } transactionLogMapper.updateSelectiveAsReturned(invoiceCode); List<TransactionLog> transactionLogs = transactionLogMapper.listLogsByInvoiceCode(invoiceCode); String reverseInvoiceCode; synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); reverseInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ TransactionLog reverseTransactionLog = (TransactionLog) transactionLog.clone(); reverseTransactionLog.setId(null); reverseTransactionLog.setCashierId(newCashierId); reverseTransactionLog.setInvoiceCode(reverseInvoiceCode); reverseTransactionLog.setStatus((byte)4); reverseTransactionLog.setTotalMoney(transactionLog.getTotalMoney().negate()); CommonResult insertReverseResult = transactionService.insertTransactionLog(reverseTransactionLog); if (insertReverseResult.getCode() == 500) return insertReverseResult; } invoiceService.updateStatus((byte)3, reverseInvoiceCode); boolean isRecipeAllReturn = true; for(TransactionParam project: returnedProjectList){ if(project.getRemainAmount() > 0) isRecipeAllReturn = false; } String newInvoiceCode = null; if(transactionLogs.size() != returnedProjectList.size() || !isRecipeAllReturn) { synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); newInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ Integer collectionId = transactionLog.getCollectionId(); Integer projectId = transactionLog.getProjectId(); if ( !returnedIdList.contains(transactionLog.getId()) && !transactionLog.getType().equals("挂号费")){ TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setStatus((byte)2); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } else if(returnedIdList.contains(transactionLog.getId()) && transactionLog.getCollectionId().toString().startsWith("5")){ for(TransactionParam returnedProject: returnedProjectList){ if (returnedProject.getCollectionId().equals(collectionId) && returnedProject.getProjectId().equals(projectId)){ Short returnAmount = returnedProject.getReturnAmount(); Short remainAmount = returnedProject.getRemainAmount(); BigDecimal newTotalFee = null; if(returnedProject.getProjectStatus() == 5){ newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else if(returnedProject.getProjectStatus() == 2){ remainAmount = (short)(returnedProject.getRemainAmount() - returnAmount); if(remainAmount != 0) { newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else continue; } TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setAmount(remainAmount); newTransactionLog.setStatus((byte)2); newTransactionLog.setTotalMoney(newTotalFee); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } } } } invoiceService.updateStatus((byte)3, newInvoiceCode); } CommonResult insertExceptionResult = transactionService.insertTransactionExceptionLog( invoiceCode, newInvoiceCode, reverseInvoiceCode, newCashierId, "项目退费" ); if (insertExceptionResult.getCode() == 500) return insertExceptionResult; jsonObject.put("newInvoiceCode", newInvoiceCode); jsonObject.put("reverseInvoiceCode", reverseInvoiceCode); } return CommonResult.success(jsonObject); }
PaymentServiceImpl implements PaymentService { @Override public CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams) { JSONObject jsonObject = new JSONObject(); Integer newCashierId = null; HashMap<String, List<TransactionParam>> collection = new HashMap<>(); for (TransactionParam t : transactionLogParams) { String invoiceCode = t.getInvoiceCode(); if (!collection.containsKey(invoiceCode)) { collection.put(invoiceCode, new ArrayList<>()); collection.get(invoiceCode).add(t); } else collection.get(invoiceCode).add(t); } for(String invoiceCode: collection.keySet()){ List<TransactionParam> returnedProjectList = collection.get(invoiceCode); List<Integer> returnedIdList = new ArrayList<>(); for(TransactionParam returnedProject: returnedProjectList){ Integer returnedCollectionId = returnedProject.getCollectionId(); newCashierId = returnedProject.getNewCashierId(); Integer returnedProjectId = returnedProject.getProjectId(); Byte returnedTransactionStatus = returnedProject.getStatus(); Byte returnedProjectStatus = returnedProject.getProjectStatus(); returnedIdList.addAll(transactionLogMapper.listIdByCollectionAndProjectId(invoiceCode, returnedCollectionId, returnedProjectId)); System.out.println(returnedIdList.get(0)); Byte itemCategory; if(returnedCollectionId.toString().startsWith("2")) itemCategory = 1; else if(returnedCollectionId.toString().startsWith("3")) itemCategory = 2; else if(returnedCollectionId.toString().startsWith("4")) itemCategory = 3; else if(returnedCollectionId.toString().startsWith("5")) itemCategory = 4; else return CommonResult.fail(E_712); if(itemCategory != 4){ if(!(returnedTransactionStatus == 2 && returnedProjectStatus == 2)) return CommonResult.fail(E_704); } else { if(returnedTransactionStatus == 2){ if(!((returnedProjectStatus == 2 && returnedProject.getReturnAmount() < returnedProject.getRemainAmount()) || (returnedProjectStatus == 5))) return CommonResult.fail(E_704); } } switch (itemCategory){ case (byte)1: inspectionMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)2: examinationMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)3: treatmentMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)4: Short returnedReturnAmount = returnedProject.getReturnAmount(); Short returnedRemainAmount = returnedProject.getRemainAmount(); if(returnedProjectStatus == 2){ recipeMapper.updateRemainAmount(returnedCollectionId, returnedProjectId, returnedReturnAmount); if(returnedReturnAmount.equals(returnedRemainAmount)) recipeMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); } break; } } transactionLogMapper.updateSelectiveAsReturned(invoiceCode); List<TransactionLog> transactionLogs = transactionLogMapper.listLogsByInvoiceCode(invoiceCode); String reverseInvoiceCode; synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); reverseInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ TransactionLog reverseTransactionLog = (TransactionLog) transactionLog.clone(); reverseTransactionLog.setId(null); reverseTransactionLog.setCashierId(newCashierId); reverseTransactionLog.setInvoiceCode(reverseInvoiceCode); reverseTransactionLog.setStatus((byte)4); reverseTransactionLog.setTotalMoney(transactionLog.getTotalMoney().negate()); CommonResult insertReverseResult = transactionService.insertTransactionLog(reverseTransactionLog); if (insertReverseResult.getCode() == 500) return insertReverseResult; } invoiceService.updateStatus((byte)3, reverseInvoiceCode); boolean isRecipeAllReturn = true; for(TransactionParam project: returnedProjectList){ if(project.getRemainAmount() > 0) isRecipeAllReturn = false; } String newInvoiceCode = null; if(transactionLogs.size() != returnedProjectList.size() || !isRecipeAllReturn) { synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); newInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ Integer collectionId = transactionLog.getCollectionId(); Integer projectId = transactionLog.getProjectId(); if ( !returnedIdList.contains(transactionLog.getId()) && !transactionLog.getType().equals("挂号费")){ TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setStatus((byte)2); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } else if(returnedIdList.contains(transactionLog.getId()) && transactionLog.getCollectionId().toString().startsWith("5")){ for(TransactionParam returnedProject: returnedProjectList){ if (returnedProject.getCollectionId().equals(collectionId) && returnedProject.getProjectId().equals(projectId)){ Short returnAmount = returnedProject.getReturnAmount(); Short remainAmount = returnedProject.getRemainAmount(); BigDecimal newTotalFee = null; if(returnedProject.getProjectStatus() == 5){ newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else if(returnedProject.getProjectStatus() == 2){ remainAmount = (short)(returnedProject.getRemainAmount() - returnAmount); if(remainAmount != 0) { newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else continue; } TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setAmount(remainAmount); newTransactionLog.setStatus((byte)2); newTransactionLog.setTotalMoney(newTotalFee); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } } } } invoiceService.updateStatus((byte)3, newInvoiceCode); } CommonResult insertExceptionResult = transactionService.insertTransactionExceptionLog( invoiceCode, newInvoiceCode, reverseInvoiceCode, newCashierId, "项目退费" ); if (insertExceptionResult.getCode() == 500) return insertExceptionResult; jsonObject.put("newInvoiceCode", newInvoiceCode); jsonObject.put("reverseInvoiceCode", reverseInvoiceCode); } return CommonResult.success(jsonObject); } }
PaymentServiceImpl implements PaymentService { @Override public CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams) { JSONObject jsonObject = new JSONObject(); Integer newCashierId = null; HashMap<String, List<TransactionParam>> collection = new HashMap<>(); for (TransactionParam t : transactionLogParams) { String invoiceCode = t.getInvoiceCode(); if (!collection.containsKey(invoiceCode)) { collection.put(invoiceCode, new ArrayList<>()); collection.get(invoiceCode).add(t); } else collection.get(invoiceCode).add(t); } for(String invoiceCode: collection.keySet()){ List<TransactionParam> returnedProjectList = collection.get(invoiceCode); List<Integer> returnedIdList = new ArrayList<>(); for(TransactionParam returnedProject: returnedProjectList){ Integer returnedCollectionId = returnedProject.getCollectionId(); newCashierId = returnedProject.getNewCashierId(); Integer returnedProjectId = returnedProject.getProjectId(); Byte returnedTransactionStatus = returnedProject.getStatus(); Byte returnedProjectStatus = returnedProject.getProjectStatus(); returnedIdList.addAll(transactionLogMapper.listIdByCollectionAndProjectId(invoiceCode, returnedCollectionId, returnedProjectId)); System.out.println(returnedIdList.get(0)); Byte itemCategory; if(returnedCollectionId.toString().startsWith("2")) itemCategory = 1; else if(returnedCollectionId.toString().startsWith("3")) itemCategory = 2; else if(returnedCollectionId.toString().startsWith("4")) itemCategory = 3; else if(returnedCollectionId.toString().startsWith("5")) itemCategory = 4; else return CommonResult.fail(E_712); if(itemCategory != 4){ if(!(returnedTransactionStatus == 2 && returnedProjectStatus == 2)) return CommonResult.fail(E_704); } else { if(returnedTransactionStatus == 2){ if(!((returnedProjectStatus == 2 && returnedProject.getReturnAmount() < returnedProject.getRemainAmount()) || (returnedProjectStatus == 5))) return CommonResult.fail(E_704); } } switch (itemCategory){ case (byte)1: inspectionMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)2: examinationMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)3: treatmentMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)4: Short returnedReturnAmount = returnedProject.getReturnAmount(); Short returnedRemainAmount = returnedProject.getRemainAmount(); if(returnedProjectStatus == 2){ recipeMapper.updateRemainAmount(returnedCollectionId, returnedProjectId, returnedReturnAmount); if(returnedReturnAmount.equals(returnedRemainAmount)) recipeMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); } break; } } transactionLogMapper.updateSelectiveAsReturned(invoiceCode); List<TransactionLog> transactionLogs = transactionLogMapper.listLogsByInvoiceCode(invoiceCode); String reverseInvoiceCode; synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); reverseInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ TransactionLog reverseTransactionLog = (TransactionLog) transactionLog.clone(); reverseTransactionLog.setId(null); reverseTransactionLog.setCashierId(newCashierId); reverseTransactionLog.setInvoiceCode(reverseInvoiceCode); reverseTransactionLog.setStatus((byte)4); reverseTransactionLog.setTotalMoney(transactionLog.getTotalMoney().negate()); CommonResult insertReverseResult = transactionService.insertTransactionLog(reverseTransactionLog); if (insertReverseResult.getCode() == 500) return insertReverseResult; } invoiceService.updateStatus((byte)3, reverseInvoiceCode); boolean isRecipeAllReturn = true; for(TransactionParam project: returnedProjectList){ if(project.getRemainAmount() > 0) isRecipeAllReturn = false; } String newInvoiceCode = null; if(transactionLogs.size() != returnedProjectList.size() || !isRecipeAllReturn) { synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); newInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ Integer collectionId = transactionLog.getCollectionId(); Integer projectId = transactionLog.getProjectId(); if ( !returnedIdList.contains(transactionLog.getId()) && !transactionLog.getType().equals("挂号费")){ TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setStatus((byte)2); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } else if(returnedIdList.contains(transactionLog.getId()) && transactionLog.getCollectionId().toString().startsWith("5")){ for(TransactionParam returnedProject: returnedProjectList){ if (returnedProject.getCollectionId().equals(collectionId) && returnedProject.getProjectId().equals(projectId)){ Short returnAmount = returnedProject.getReturnAmount(); Short remainAmount = returnedProject.getRemainAmount(); BigDecimal newTotalFee = null; if(returnedProject.getProjectStatus() == 5){ newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else if(returnedProject.getProjectStatus() == 2){ remainAmount = (short)(returnedProject.getRemainAmount() - returnAmount); if(remainAmount != 0) { newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else continue; } TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setAmount(remainAmount); newTransactionLog.setStatus((byte)2); newTransactionLog.setTotalMoney(newTotalFee); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } } } } invoiceService.updateStatus((byte)3, newInvoiceCode); } CommonResult insertExceptionResult = transactionService.insertTransactionExceptionLog( invoiceCode, newInvoiceCode, reverseInvoiceCode, newCashierId, "项目退费" ); if (insertExceptionResult.getCode() == 500) return insertExceptionResult; jsonObject.put("newInvoiceCode", newInvoiceCode); jsonObject.put("reverseInvoiceCode", reverseInvoiceCode); } return CommonResult.success(jsonObject); }  }
PaymentServiceImpl implements PaymentService { @Override public CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams) { JSONObject jsonObject = new JSONObject(); Integer newCashierId = null; HashMap<String, List<TransactionParam>> collection = new HashMap<>(); for (TransactionParam t : transactionLogParams) { String invoiceCode = t.getInvoiceCode(); if (!collection.containsKey(invoiceCode)) { collection.put(invoiceCode, new ArrayList<>()); collection.get(invoiceCode).add(t); } else collection.get(invoiceCode).add(t); } for(String invoiceCode: collection.keySet()){ List<TransactionParam> returnedProjectList = collection.get(invoiceCode); List<Integer> returnedIdList = new ArrayList<>(); for(TransactionParam returnedProject: returnedProjectList){ Integer returnedCollectionId = returnedProject.getCollectionId(); newCashierId = returnedProject.getNewCashierId(); Integer returnedProjectId = returnedProject.getProjectId(); Byte returnedTransactionStatus = returnedProject.getStatus(); Byte returnedProjectStatus = returnedProject.getProjectStatus(); returnedIdList.addAll(transactionLogMapper.listIdByCollectionAndProjectId(invoiceCode, returnedCollectionId, returnedProjectId)); System.out.println(returnedIdList.get(0)); Byte itemCategory; if(returnedCollectionId.toString().startsWith("2")) itemCategory = 1; else if(returnedCollectionId.toString().startsWith("3")) itemCategory = 2; else if(returnedCollectionId.toString().startsWith("4")) itemCategory = 3; else if(returnedCollectionId.toString().startsWith("5")) itemCategory = 4; else return CommonResult.fail(E_712); if(itemCategory != 4){ if(!(returnedTransactionStatus == 2 && returnedProjectStatus == 2)) return CommonResult.fail(E_704); } else { if(returnedTransactionStatus == 2){ if(!((returnedProjectStatus == 2 && returnedProject.getReturnAmount() < returnedProject.getRemainAmount()) || (returnedProjectStatus == 5))) return CommonResult.fail(E_704); } } switch (itemCategory){ case (byte)1: inspectionMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)2: examinationMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)3: treatmentMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)4: Short returnedReturnAmount = returnedProject.getReturnAmount(); Short returnedRemainAmount = returnedProject.getRemainAmount(); if(returnedProjectStatus == 2){ recipeMapper.updateRemainAmount(returnedCollectionId, returnedProjectId, returnedReturnAmount); if(returnedReturnAmount.equals(returnedRemainAmount)) recipeMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); } break; } } transactionLogMapper.updateSelectiveAsReturned(invoiceCode); List<TransactionLog> transactionLogs = transactionLogMapper.listLogsByInvoiceCode(invoiceCode); String reverseInvoiceCode; synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); reverseInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ TransactionLog reverseTransactionLog = (TransactionLog) transactionLog.clone(); reverseTransactionLog.setId(null); reverseTransactionLog.setCashierId(newCashierId); reverseTransactionLog.setInvoiceCode(reverseInvoiceCode); reverseTransactionLog.setStatus((byte)4); reverseTransactionLog.setTotalMoney(transactionLog.getTotalMoney().negate()); CommonResult insertReverseResult = transactionService.insertTransactionLog(reverseTransactionLog); if (insertReverseResult.getCode() == 500) return insertReverseResult; } invoiceService.updateStatus((byte)3, reverseInvoiceCode); boolean isRecipeAllReturn = true; for(TransactionParam project: returnedProjectList){ if(project.getRemainAmount() > 0) isRecipeAllReturn = false; } String newInvoiceCode = null; if(transactionLogs.size() != returnedProjectList.size() || !isRecipeAllReturn) { synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); newInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ Integer collectionId = transactionLog.getCollectionId(); Integer projectId = transactionLog.getProjectId(); if ( !returnedIdList.contains(transactionLog.getId()) && !transactionLog.getType().equals("挂号费")){ TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setStatus((byte)2); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } else if(returnedIdList.contains(transactionLog.getId()) && transactionLog.getCollectionId().toString().startsWith("5")){ for(TransactionParam returnedProject: returnedProjectList){ if (returnedProject.getCollectionId().equals(collectionId) && returnedProject.getProjectId().equals(projectId)){ Short returnAmount = returnedProject.getReturnAmount(); Short remainAmount = returnedProject.getRemainAmount(); BigDecimal newTotalFee = null; if(returnedProject.getProjectStatus() == 5){ newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else if(returnedProject.getProjectStatus() == 2){ remainAmount = (short)(returnedProject.getRemainAmount() - returnAmount); if(remainAmount != 0) { newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else continue; } TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setAmount(remainAmount); newTransactionLog.setStatus((byte)2); newTransactionLog.setTotalMoney(newTotalFee); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } } } } invoiceService.updateStatus((byte)3, newInvoiceCode); } CommonResult insertExceptionResult = transactionService.insertTransactionExceptionLog( invoiceCode, newInvoiceCode, reverseInvoiceCode, newCashierId, "项目退费" ); if (insertExceptionResult.getCode() == 500) return insertExceptionResult; jsonObject.put("newInvoiceCode", newInvoiceCode); jsonObject.put("reverseInvoiceCode", reverseInvoiceCode); } return CommonResult.success(jsonObject); }  @Override CommonResult listTransactionLogsByRegistrationId(Integer registrationId); @Override CommonResult listTransactionLogsByInvoiceCode(String invoiceCode); @Override CommonResult listTransactionLogsByCollectionAndProjectId(Integer collectionId, Integer projectId); @Override @Transactional CommonResult updateTransactionLogsAsPaid(List<TransactionParam> transactionParams); @Override CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams); @Override CommonResult reprintTransactionLog(String invoiceCode, Integer newCashierId); @Override CommonResult listLogsByRegistrationIdAndDate(Integer registrationId, String beginDateStr, String endDateStr); }
PaymentServiceImpl implements PaymentService { @Override public CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams) { JSONObject jsonObject = new JSONObject(); Integer newCashierId = null; HashMap<String, List<TransactionParam>> collection = new HashMap<>(); for (TransactionParam t : transactionLogParams) { String invoiceCode = t.getInvoiceCode(); if (!collection.containsKey(invoiceCode)) { collection.put(invoiceCode, new ArrayList<>()); collection.get(invoiceCode).add(t); } else collection.get(invoiceCode).add(t); } for(String invoiceCode: collection.keySet()){ List<TransactionParam> returnedProjectList = collection.get(invoiceCode); List<Integer> returnedIdList = new ArrayList<>(); for(TransactionParam returnedProject: returnedProjectList){ Integer returnedCollectionId = returnedProject.getCollectionId(); newCashierId = returnedProject.getNewCashierId(); Integer returnedProjectId = returnedProject.getProjectId(); Byte returnedTransactionStatus = returnedProject.getStatus(); Byte returnedProjectStatus = returnedProject.getProjectStatus(); returnedIdList.addAll(transactionLogMapper.listIdByCollectionAndProjectId(invoiceCode, returnedCollectionId, returnedProjectId)); System.out.println(returnedIdList.get(0)); Byte itemCategory; if(returnedCollectionId.toString().startsWith("2")) itemCategory = 1; else if(returnedCollectionId.toString().startsWith("3")) itemCategory = 2; else if(returnedCollectionId.toString().startsWith("4")) itemCategory = 3; else if(returnedCollectionId.toString().startsWith("5")) itemCategory = 4; else return CommonResult.fail(E_712); if(itemCategory != 4){ if(!(returnedTransactionStatus == 2 && returnedProjectStatus == 2)) return CommonResult.fail(E_704); } else { if(returnedTransactionStatus == 2){ if(!((returnedProjectStatus == 2 && returnedProject.getReturnAmount() < returnedProject.getRemainAmount()) || (returnedProjectStatus == 5))) return CommonResult.fail(E_704); } } switch (itemCategory){ case (byte)1: inspectionMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)2: examinationMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)3: treatmentMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); break; case (byte)4: Short returnedReturnAmount = returnedProject.getReturnAmount(); Short returnedRemainAmount = returnedProject.getRemainAmount(); if(returnedProjectStatus == 2){ recipeMapper.updateRemainAmount(returnedCollectionId, returnedProjectId, returnedReturnAmount); if(returnedReturnAmount.equals(returnedRemainAmount)) recipeMapper.updateStatus(returnedCollectionId, returnedProjectId, (byte) 3); } break; } } transactionLogMapper.updateSelectiveAsReturned(invoiceCode); List<TransactionLog> transactionLogs = transactionLogMapper.listLogsByInvoiceCode(invoiceCode); String reverseInvoiceCode; synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); reverseInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ TransactionLog reverseTransactionLog = (TransactionLog) transactionLog.clone(); reverseTransactionLog.setId(null); reverseTransactionLog.setCashierId(newCashierId); reverseTransactionLog.setInvoiceCode(reverseInvoiceCode); reverseTransactionLog.setStatus((byte)4); reverseTransactionLog.setTotalMoney(transactionLog.getTotalMoney().negate()); CommonResult insertReverseResult = transactionService.insertTransactionLog(reverseTransactionLog); if (insertReverseResult.getCode() == 500) return insertReverseResult; } invoiceService.updateStatus((byte)3, reverseInvoiceCode); boolean isRecipeAllReturn = true; for(TransactionParam project: returnedProjectList){ if(project.getRemainAmount() > 0) isRecipeAllReturn = false; } String newInvoiceCode = null; if(transactionLogs.size() != returnedProjectList.size() || !isRecipeAllReturn) { synchronized (this) { CommonResult result = invoiceService.getNextInvoiceCode(); newInvoiceCode = (String) result.getData(); } for(TransactionLog transactionLog: transactionLogs){ Integer collectionId = transactionLog.getCollectionId(); Integer projectId = transactionLog.getProjectId(); if ( !returnedIdList.contains(transactionLog.getId()) && !transactionLog.getType().equals("挂号费")){ TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setStatus((byte)2); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } else if(returnedIdList.contains(transactionLog.getId()) && transactionLog.getCollectionId().toString().startsWith("5")){ for(TransactionParam returnedProject: returnedProjectList){ if (returnedProject.getCollectionId().equals(collectionId) && returnedProject.getProjectId().equals(projectId)){ Short returnAmount = returnedProject.getReturnAmount(); Short remainAmount = returnedProject.getRemainAmount(); BigDecimal newTotalFee = null; if(returnedProject.getProjectStatus() == 5){ newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else if(returnedProject.getProjectStatus() == 2){ remainAmount = (short)(returnedProject.getRemainAmount() - returnAmount); if(remainAmount != 0) { newTotalFee = new BigDecimal(remainAmount).multiply( medicineMapper.getUnitPriceById(projectId)); } else continue; } TransactionLog newTransactionLog = (TransactionLog) transactionLog.clone(); newTransactionLog.setId(null); newTransactionLog.setCashierId(newCashierId); newTransactionLog.setInvoiceCode(newInvoiceCode); newTransactionLog.setAmount(remainAmount); newTransactionLog.setStatus((byte)2); newTransactionLog.setTotalMoney(newTotalFee); CommonResult insertNewResult = transactionService.insertTransactionLog(newTransactionLog); if (insertNewResult.getCode() == 500) return insertNewResult; } } } } invoiceService.updateStatus((byte)3, newInvoiceCode); } CommonResult insertExceptionResult = transactionService.insertTransactionExceptionLog( invoiceCode, newInvoiceCode, reverseInvoiceCode, newCashierId, "项目退费" ); if (insertExceptionResult.getCode() == 500) return insertExceptionResult; jsonObject.put("newInvoiceCode", newInvoiceCode); jsonObject.put("reverseInvoiceCode", reverseInvoiceCode); } return CommonResult.success(jsonObject); }  @Override CommonResult listTransactionLogsByRegistrationId(Integer registrationId); @Override CommonResult listTransactionLogsByInvoiceCode(String invoiceCode); @Override CommonResult listTransactionLogsByCollectionAndProjectId(Integer collectionId, Integer projectId); @Override @Transactional CommonResult updateTransactionLogsAsPaid(List<TransactionParam> transactionParams); @Override CommonResult updateTransactionLogsAsReturned(List<TransactionParam> transactionLogParams); @Override CommonResult reprintTransactionLog(String invoiceCode, Integer newCashierId); @Override CommonResult listLogsByRegistrationIdAndDate(Integer registrationId, String beginDateStr, String endDateStr);  }