| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.constant.ConsumptionConstant; |
| | | import com.kidgrow.common.constant.PayConstants; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.mapper.ConsumptionRecordMapper; |
| | | import com.kidgrow.oprationcenter.model.ConsumptionRecord; |
| | | import com.kidgrow.oprationcenter.model.PayManager; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.model.SaasClientPay; |
| | | import com.kidgrow.oprationcenter.service.IConsumptionRecordService; |
| | | import com.kidgrow.oprationcenter.service.IPayManagerService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.oprationcenter.service.ISaasClientPayService; |
| | | import com.kidgrow.oprationcenter.vo.ConsumptionRequest; |
| | | import com.kidgrow.oprationcenter.vo.ConsumptionVo; |
| | | import com.kidgrow.oprationcenter.vo.ProductOrderJoinDetail; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private HttpServletRequest httpServletRequest; |
| | | private IPayManagerService payManagerService; |
| | | @Autowired |
| | | private ISaasClientPayService saasClientPayService; |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(ConsumptionRecordServiceImpl.class); |
| | | @Value("${spring.profiles.active}") |
| | | private String envName; |
| | | |
| | | /** |
| | | * 列表 |
| | | * |
| | |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //是否开通单次支付 |
| | | if (departmentIsPay(consumptionRequest)) { |
| | | //是否支付成功 |
| | | if (departmentPayStatus(consumptionRequest)) { |
| | | //预扣费成功 |
| | | reMsg = "单次支付模拟预扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_BEFORE_DEDUCTION; |
| | | } else { |
| | | reMsg = "单次支付未成功,不允许预扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | //1.先检查是否已经扣费 |
| | |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } |
| | | } else { |
| | | isSuccess = false; |
| | | reMsg = "传入参数有误!"; |
| | |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //是否开通单次支付 |
| | | if (departmentIsPay(consumptionRequest)) { |
| | | //是否支付成功 |
| | | if (departmentPayStatus(consumptionRequest)) { |
| | | //预扣费成功 |
| | | reMsg = "单次支付模拟扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | //消息队列通知 |
| | | MessageToBI(consumptionRequest); |
| | | } else { |
| | | reMsg = "单次支付未成功,不允许扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | Long hospitalId = consumptionRequest.getHospitalId(); |
| | |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } |
| | | } else { |
| | | isSuccess = false; |
| | | reMsg = "传入参数有误!"; |
| | |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //是否开通单次支付 |
| | | if (departmentIsPay(consumptionRequest)) { |
| | | //是否支付成功 |
| | | if (departmentPayStatus(consumptionRequest)) { |
| | | //预扣费成功 |
| | | reMsg = "单次支付模拟退还扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_RETURN_DEDUCTION; |
| | | } else { |
| | | reMsg = "单次支付未成功,不允许退扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | //1.先检查是否已经扣费 |
| | |
| | | Long tempProOrderDetailId=consumptionRecord.getProOrderDetailId(); |
| | | consumptionRecord.setProOrderDetailId(0L); |
| | | consumptionRecord.setUpdateTime(new Date()); |
| | | if (SaveConsumptionRecord(consumptionRecord)) |
| | | { |
| | | if (SaveConsumptionRecord(consumptionRecord)) { |
| | | //退预扣记录 |
| | | ConsumptionRecord consumptionRecordNew = new ConsumptionRecord(); |
| | | consumptionRecordNew.setBusinessCode(ConsumptionConstant.BUSINESS_CODE_RETURN_BEFORE_DEDUCTION); |
| | |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.RETURN_BEFORE_DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(tempProOrderDetailId); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getId()); |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) |
| | | { |
| | | consumptionRecordNew.setDiaId(consumptionRequest.getDiaId()); |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) { |
| | | isSuccess=true; |
| | | reMsg = "有预扣,写退还预扣成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_RETURN_BEFORE_DEDUCTION; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "写退还预扣失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } |
| | | else{ |
| | | } else { |
| | | reMsg = "更新预扣费记录失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "没有相关预扣记录!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | |
| | | //更新扣费记录 还回占用套餐 |
| | | consumptionRecord.setProOrderDetailId(0L); |
| | | consumptionRecord.setUpdateTime(new Date()); |
| | | if (SaveConsumptionRecord(consumptionRecord)) |
| | | { |
| | | if (SaveConsumptionRecord(consumptionRecord)) { |
| | | //退费成功 |
| | | //3.2 写退费记录 |
| | | ConsumptionRecord consumptionRecordNew = new ConsumptionRecord(); |
| | |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.RETURN_DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getId()); |
| | | consumptionRecordNew.setDiaId(consumptionRequest.getDiaId()); |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) { |
| | | //写退费记录成功 |
| | | isSuccess=true; |
| | | reMsg = "退还扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_RETURN_DEDUCTION; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "退还扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | //更新扣费失败 |
| | | reMsg = "更新扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | //退费失败 |
| | | reMsg = "退还扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "无相关套餐数据!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "无相关扣费数据!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | |
| | | |
| | | /** |
| | | * 发起人工读片-调用 |
| | | * |
| | | * @param consumptionRequest 请求的数据实体 |
| | | * @return |
| | | */ |
| | |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //是否开通单次支付 |
| | | if (departmentIsPay(consumptionRequest)) |
| | | { |
| | | //是否支付成功 |
| | | if (departmentPayStatus(consumptionRequest)) { |
| | | //预扣费成功 |
| | | reMsg = "单次支付模拟已经扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | //消息队列通知 |
| | | MessageToBI(consumptionRequest); |
| | | } else { |
| | | reMsg = "单次支付未成功,不允许业务进行!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } |
| | | else { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | //1.先检查是否已经扣费 |
| | |
| | | reMsg = "预扣费执行失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | return ResultReturn(consumptionRequest, bcode,ConsumptionConstant.BEFORE_DEDUCTION, reMsg, isSuccess); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | //发起了一个新的预扣,需要更新扣费业务数据列表 |
| | | consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | } |
| | |
| | | if (isSuccess) { |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | reMsg = "该业务扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_PARAMS_ERROR; |
| | | } |
| | |
| | | //已经扣费 |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } |
| | | } else { |
| | | reMsg = "传入参数有误!"; |
| | |
| | | |
| | | /** |
| | | * 扣费业务(扣费 更新预扣 写扣费记录) |
| | | * |
| | | * @param consumptionRequest 请求参数 |
| | | * @param consumptionRecordList 扣费业务数据 |
| | | * @return |
| | |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getId()); |
| | | consumptionRecordNew.setDiaId(consumptionRequest.getDiaId()); |
| | | consumptionRecordNew.setCreateTime(new Date()); |
| | | |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) { |
| | |
| | | |
| | | /** |
| | | * 预扣费业务 |
| | | * |
| | | * @param consumptionRequest 请求参数 |
| | | * @return |
| | | */ |
| | |
| | | consumptionRecord.setConsumptionCount(consumptionRequest.getConsumptionCount()); |
| | | consumptionRecord.setRecordType(ConsumptionConstant.BEFORE_DEDUCTION); |
| | | consumptionRecord.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecord.setDiaId(consumptionRequest.getDiaId()); |
| | | if (SaveConsumptionRecord(consumptionRecord)) { |
| | | return true; |
| | | } else { |
| | |
| | | String hosId = consumptionRequest.getHospitalId().toString(); |
| | | String depId = consumptionRequest.getDepartmentId().toString(); |
| | | String doctorId = consumptionRequest.getDoctorId().toString(); |
| | | String diaId = consumptionRequest.getDiaId().toString(); |
| | | if (StringUtils.isNotBlank(consumptionRequest.getBusinessId()) |
| | | && consumptionRequest.getConsumptionCount() > 0 |
| | | && StringUtils.isNotBlank(hosId) |
| | | && StringUtils.isNotBlank(depId) |
| | | && StringUtils.isNotBlank(doctorId)) { |
| | | && StringUtils.isNotBlank(doctorId) |
| | | && StringUtils.isNotBlank(diaId)) { |
| | | return true; |
| | | } else { |
| | | logger.info("扣费请求参数不完整!"); |
| | |
| | | |
| | | /** |
| | | * 检查余额够不够 |
| | | * |
| | | * @param consumptionCount 要扣的数量 |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取要使用的套餐实体 |
| | | * |
| | | * @param consumCount 要使用的数量 |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取一个业务关联的扣费记录 |
| | | * |
| | | * @param businessId 光片的名称/编号 |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 发消息到消息队列 |
| | | * |
| | | * @return |
| | | */ |
| | | //@RabbitListener(queues = "BoneAgeEvaluationData") |
| | | private void MessageToBI(ConsumptionRequest consumptionRequest) |
| | | { |
| | | private void MessageToBI(ConsumptionRequest consumptionRequest) { |
| | | //发消息到队列 |
| | | String context = "{\"hospitalId\":\"" + consumptionRequest.getHospitalId() + |
| | | "\",\"departmentId\":\"" + consumptionRequest.getDepartmentId() + |
| | |
| | | |
| | | log.error("骨龄评价扣费消息已发送:"+context); |
| | | } |
| | | |
| | | /** |
| | | * 查看当前科室是否开通了单次支付 |
| | | * |
| | | * @param consumptionRequest |
| | | * @return |
| | | */ |
| | | private Boolean departmentIsPay(ConsumptionRequest consumptionRequest) { |
| | | PayManager payManager = payManagerService.findByObject(consumptionRequest.getHospitalId(), consumptionRequest.getDepartmentId()); |
| | | if (payManager == null) { |
| | | return false; |
| | | } else { |
| | | return payManager.getId() > 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查看当前科室当前诊断id的支付状态是否成功 |
| | | * |
| | | * @param consumptionRequest |
| | | * @return |
| | | */ |
| | | private Boolean departmentPayStatus(ConsumptionRequest consumptionRequest) { |
| | | SaasClientPay saasClientPay = saasClientPayService.findModelByObject(consumptionRequest.getHospitalId(), consumptionRequest.getDepartmentId(), consumptionRequest.getDiaId()); |
| | | if (saasClientPay == null) { |
| | | return false; |
| | | } else { |
| | | if (saasClientPay.getPayStatus().equals(PayConstants.ORDER_PAY_SUCEESS)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |