| | |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //3.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount(),consumptionRequest.getHospitalId(),consumptionRequest.getDepartmentId())) { |
| | | Map<String,Object> vateMap=VateUserNowProduct(consumptionRequest.getConsumptionCount(),consumptionRequest.getHospitalId(),consumptionRequest.getDepartmentId()); |
| | | if (Boolean.parseBoolean(vateMap.get("vateRe").toString())) { |
| | | //4.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (beforeConsumption(consumptionRequest)) { |
| | | //预扣费成功 |
| | |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } else { |
| | | //余额不足 |
| | | //余额不足 或获取异常 |
| | | isSuccess = false; |
| | | reMsg = "余额不足或获取失败!"; |
| | | reMsg = vateMap.get("vateMsg").toString(); |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //2.1.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount(),hospitalId,consumptionRequest.getDepartmentId())) { |
| | | Map<String,Object> vateMap=VateUserNowProduct(consumptionRequest.getConsumptionCount(),hospitalId,consumptionRequest.getDepartmentId()); |
| | | if (Boolean.parseBoolean(vateMap.get("vateRe").toString())) { |
| | | //2.2.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (beforeConsumption(consumptionRequest)) { |
| | | //预扣费成功 |
| | |
| | | } else { |
| | | //余额不足 |
| | | isSuccess = false; |
| | | reMsg = "余额不足或获取失败!"; |
| | | reMsg = vateMap.get("vateMsg").toString(); |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | return ResultReturn(consumptionRequest, bcode,ConsumptionConstant.BEFORE_DEDUCTION, reMsg, isSuccess); |
| | | } |
| | |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //3.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount(),consumptionRequest.getHospitalId(),consumptionRequest.getDepartmentId())) { |
| | | Map<String,Object> vateMap=VateUserNowProduct(consumptionRequest.getConsumptionCount(),consumptionRequest.getHospitalId(),consumptionRequest.getDepartmentId()); |
| | | if (Boolean.parseBoolean(vateMap.get("vateRe").toString())) { |
| | | //4.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (!beforeConsumption(consumptionRequest)) { |
| | | //预扣费执行失败 |
| | |
| | | } |
| | | } else { |
| | | //余额不足 |
| | | reMsg = "余额不足或获取失败!"; |
| | | reMsg = vateMap.get("vateMsg").toString(); |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | return ResultReturn(consumptionRequest, bcode,ConsumptionConstant.BEFORE_DEDUCTION, reMsg, isSuccess); |
| | | } |
| | |
| | | * @param consumptionCount 要扣的数量 |
| | | * @return |
| | | */ |
| | | private Boolean VateUserNowProduct(int consumptionCount,Long hospitalId,Long departmentId) { |
| | | private Map<String,Object> VateUserNowProduct(int consumptionCount,Long hospitalId,Long departmentId) { |
| | | Map<String,Object> returnMap=new HashMap<>(); |
| | | ResultBody biUserPro = productOrderDetailService.biUserNowProduct(hospitalId, departmentId); |
| | | if (biUserPro.getCode() == 0) { |
| | | if (StringUtils.isNotBlank(biUserPro.getData().toString())) { |
| | | //余额 |
| | | int userAICount = Integer.parseInt(biUserPro.getData().toString()); |
| | | if (userAICount >= consumptionCount) { |
| | | return true; |
| | | returnMap.put("vateRe",true); |
| | | returnMap.put("vateMsg","余额足够!"); |
| | | } else { |
| | | returnMap.put("vateRe",false); |
| | | returnMap.put("vateMsg","余额不足!"); |
| | | logger.info("医院id:【{}】余额不足!", hospitalId); |
| | | } |
| | | } else { |
| | | returnMap.put("vateRe",false); |
| | | returnMap.put("vateMsg","余额获取异常,data为空!"); |
| | | logger.error("医院id:【{}】余额获取异常!", hospitalId); |
| | | } |
| | | } else { |
| | | }else { |
| | | returnMap.put("vateRe",false); |
| | | returnMap.put("vateMsg","余额获取异常,Code非0!"); |
| | | logger.info("医院id:【{}】余额获取异常,返回非0!", hospitalId); |
| | | } |
| | | return false; |
| | | return returnMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 发消息到消息队列 |
| | | * @return |
| | | */ |
| | | @RabbitListener(queues = "BoneAgeEvaluationData") |
| | | //@RabbitListener(queues = "BoneAgeEvaluationData") |
| | | private void MessageToBI(ConsumptionRequest consumptionRequest) |
| | | { |
| | | //发消息到队列 |
| | |
| | | "\",\"doctorId\":\"" + consumptionRequest.getDoctorId() + |
| | | "\",\"date\":\"" + DateUtils.formatDate(new Date(),"yyyy-MM-dd")+"\"}"; |
| | | rabbitTemplate.convertAndSend(ConsumptionConstant.EXCHANGE_DATA, ConsumptionConstant.ROUTINGKEY_DATA+envName, context); |
| | | |
| | | log.error("骨龄评价扣费消息已发送:"+context); |
| | | } |
| | | } |