| | |
| | | package com.kidgrow.oprationcenter.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.constant.ConsumptionConstant; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.mapper.ConsumptionRecordMapper; |
| | | import com.kidgrow.oprationcenter.model.ConsumptionRecord; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.service.IConsumptionRecordService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.oprationcenter.vo.ConsumptionRequest; |
| | | import com.kidgrow.oprationcenter.vo.ConsumptionVo; |
| | | import com.kidgrow.oprationcenter.vo.ProductOrderJoinDetail; |
| | | import com.kidgrow.oprationcenter.vo.UserProductDetail; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @version 1.0 |
| | | * @Description: <br> |
| | | * @Project: 运营中心<br> |
| | | * @CreateDate: Created in 2020-06-23 15:07:14 <br> |
| | | * @Author: <a href="411269194@kidgrow.com">houruijun</a> |
| | | * @version 1.0 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class ConsumptionRecordServiceImpl extends SuperServiceImpl<ConsumptionRecordMapper, ConsumptionRecord> implements IConsumptionRecordService { |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private HttpServletRequest httpServletRequest; |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(ConsumptionRecordServiceImpl.class); |
| | | |
| | | |
| | | /** |
| | | * 列表 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageResult<ConsumptionRecord> findList(Map<String, Object> params){ |
| | | public PageResult<ConsumptionRecord> findList(Map<String, Object> params) { |
| | | Page<ConsumptionRecord> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); |
| | | List<ConsumptionRecord> list = baseMapper.findList(page, params); |
| | | List<ConsumptionRecord> list = baseMapper.findList(page, params); |
| | | return PageResult.<ConsumptionRecord>builder().data(list).code(0).count(page.getTotal()).build(); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<ConsumptionRecord> findAllList(Map<String, Object> params){ |
| | | public List<ConsumptionRecord> findAllList(Map<String, Object> params) { |
| | | return baseMapper.findList(params); |
| | | } |
| | | |
| | | /** |
| | | * 根据ConsumptionRecord对象当做查询条件进行查询 |
| | | * @param consumptionRecord |
| | | * @return ConsumptionRecord |
| | | */ |
| | | * 根据ConsumptionRecord对象当做查询条件进行查询 |
| | | * |
| | | * @param consumptionRecord |
| | | * @return ConsumptionRecord |
| | | */ |
| | | @Override |
| | | public ConsumptionRecord findByObject(ConsumptionRecord consumptionRecord){ |
| | | public ConsumptionRecord findByObject(ConsumptionRecord consumptionRecord) { |
| | | return baseMapper.findByObject(consumptionRecord); |
| | | } |
| | | |
| | | /** |
| | | * 要让AI读片-调用 |
| | | * |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @param consumptionRequest 请求的数据实体 |
| | | * @return |
| | | */ |
| | | public boolean deductionDepartmentProduct(Long hospitalId,Long departmentId) |
| | | { |
| | | UserProductDetail userProductDetail=productOrderDetailService.getUserProductDetail(hospitalId,departmentId); |
| | | //合并集合 |
| | | userProductDetail.getProductOrderJoinDetailListShare().addAll(userProductDetail.getProductOrderJoinDetailsListDep()); |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailList=userProductDetail.getProductOrderJoinDetailListShare(); |
| | | //Collections.sort(productOrderJoinDetailList); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody consumptionAIStart(ConsumptionRequest consumptionRequest) { |
| | | //默认的业务返回码 |
| | | int bcode = -1; |
| | | //业务执行结果 |
| | | boolean isSuccess = false; |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | //1.先检查是否已经扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.DEDUCTION)) { |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //3.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount())) { |
| | | //4.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (beforeConsumption(consumptionRequest)) { |
| | | //预扣费成功 |
| | | isSuccess = true; |
| | | reMsg = "预扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_BEFORE_DEDUCTION; |
| | | } else { |
| | | //预扣费执行失败 |
| | | reMsg = "预扣费执行失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } else { |
| | | //余额不足 |
| | | reMsg = "余额不足或获取失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | | //已经预扣费 |
| | | reMsg = "该业务已经预扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_BEFORE_DEDUCTION; |
| | | } |
| | | } else { |
| | | //已经扣费 |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } else { |
| | | reMsg = "传入参数有误!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_PARAMS_ERROR; |
| | | } |
| | | return ResultReturn(consumptionRequest, bcode, reMsg, isSuccess); |
| | | } |
| | | |
| | | /** |
| | | * AI返回结果-调用 |
| | | * |
| | | * @param consumptionRequest 请求的数据实体 |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody consumptionAIReturn(ConsumptionRequest consumptionRequest) { |
| | | //默认的业务返回码 |
| | | int bcode = -1; |
| | | //业务执行结果 |
| | | boolean isSuccess = false; |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | //1.先检查是否已经扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.DEDUCTION)) { |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //2.1.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount())) { |
| | | //2.2.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (beforeConsumption(consumptionRequest)) { |
| | | //预扣费成功 |
| | | logger.info("医院id:【{}】AI返回结果应该不走预扣,目前确已经预扣!", hospitalId); |
| | | } else { |
| | | //预扣费执行失败 |
| | | reMsg = "预扣费执行失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } else { |
| | | //余额不足 |
| | | reMsg = "余额不足或获取失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } |
| | | if (consumptionBusiess(consumptionRequest, consumptionRecordList)) { |
| | | isSuccess = true; |
| | | reMsg = "该业务扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } else { |
| | | reMsg = "该业务扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } else { |
| | | //已经扣费 |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } else { |
| | | reMsg = "传入参数有误!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_PARAMS_ERROR; |
| | | } |
| | | return ResultReturn(consumptionRequest, bcode, reMsg, isSuccess); |
| | | } |
| | | |
| | | /** |
| | | * AI拒读/失败通知-调用 |
| | | * |
| | | * @param consumptionRequest 请求的数据实体 |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody consumptionAIFail(ConsumptionRequest consumptionRequest) { |
| | | //默认的业务返回码 |
| | | int bcode = -1; |
| | | //业务执行结果 |
| | | boolean isSuccess = false; |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | //1.先检查是否已经扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.DEDUCTION)) { |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //2.1.有预扣费 |
| | | ConsumptionRecord consumptionRecord = consumptionRecordList.stream().filter(f -> f.getRecordType() == ConsumptionConstant.BEFORE_DEDUCTION).collect(Collectors.toList()).get(0); |
| | | //把占用的套餐id还回去 |
| | | Long tempProOrderDetailId=consumptionRecord.getProOrderDetailId(); |
| | | consumptionRecord.setProOrderDetailId(0L); |
| | | consumptionRecord.setUpdateTime(new Date()); |
| | | if (SaveConsumptionRecord(consumptionRecord)) |
| | | { |
| | | //退预扣记录 |
| | | ConsumptionRecord consumptionRecordNew = new ConsumptionRecord(); |
| | | consumptionRecordNew.setBusinessCode(ConsumptionConstant.RETURN_BEFORE_DEDUCTION); |
| | | consumptionRecordNew.setBusinessId(consumptionRequest.getBusinessId()); |
| | | consumptionRecordNew.setConsumptionCount(consumptionRequest.getConsumptionCount()); |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(tempProOrderDetailId); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getLastRecordId()); |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) |
| | | { |
| | | reMsg = "有预扣,写退还预扣成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_RETURN_BEFORE_DEDUCTION; |
| | | } |
| | | else |
| | | { |
| | | reMsg = "写退还预扣失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } |
| | | else{ |
| | | reMsg = "更新预扣费记录失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | reMsg = "没有相关预扣记录!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } else { |
| | | //3.有扣费记录 |
| | | //3.1 退还账户 |
| | | //获取预扣的时候占住的套餐id |
| | | ConsumptionRecord consumptionRecord = consumptionRecordList.stream().filter(f -> f.getRecordType() == ConsumptionConstant.DEDUCTION).collect(Collectors.toList()).get(0); |
| | | if (consumptionRecord != null) { |
| | | ProductOrderDetail productOrderDetail = productOrderDetailService.getById(consumptionRecord.getProOrderDetailId()); |
| | | if (productOrderDetail != null) { |
| | | //退还金额 |
| | | productOrderDetail.setAilightCount(productOrderDetail.getAilightCount()+consumptionRecord.getConsumptionCount()); |
| | | productOrderDetail.setUpdateTime(new Date()); |
| | | //退费 |
| | | boolean consumptionRe = productOrderDetailService.saveOrUpdate(productOrderDetail); |
| | | if (consumptionRe) { |
| | | //退费成功 |
| | | //3.2 写退费记录 |
| | | ConsumptionRecord consumptionRecordNew = new ConsumptionRecord(); |
| | | consumptionRecordNew.setBusinessCode(ConsumptionConstant.BUSINESS_CODE_RETURN_DEDUCTION); |
| | | consumptionRecordNew.setBusinessId(consumptionRecord.getBusinessId()); |
| | | consumptionRecordNew.setConsumptionCount(consumptionRecord.getConsumptionCount()); |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.RETURN_DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getLastRecordId()); |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) { |
| | | //写退费记录成功 |
| | | isSuccess=true; |
| | | reMsg = "退还扣费成功!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_RETURN_DEDUCTION; |
| | | } |
| | | else |
| | | { |
| | | reMsg = "退还扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //退费失败 |
| | | reMsg = "退还扣费失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | reMsg = "无相关套餐数据!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | reMsg = "无相关扣费数据!"; |
| | | bcode = ConsumptionConstant.BUSINESS_RUN_FAIL; |
| | | } |
| | | } |
| | | } else { |
| | | reMsg = "传入参数有误!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_PARAMS_ERROR; |
| | | } |
| | | return ResultReturn(consumptionRequest, bcode, reMsg, isSuccess); |
| | | } |
| | | |
| | | /** |
| | | * 发起人工读片-调用 |
| | | * @param consumptionRequest 请求的数据实体 |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ResultBody consumptionArtificial(ConsumptionRequest consumptionRequest) { |
| | | //默认的业务返回码 |
| | | int bcode = -1; |
| | | //业务执行结果 |
| | | boolean isSuccess = false; |
| | | //业务执行结果信息 |
| | | String reMsg = ""; |
| | | if (VateParams(consumptionRequest)) { |
| | | //先获取这个业务关联的扣费记录 |
| | | List<ConsumptionRecord> consumptionRecordList = GetBusinessConsumptionList(consumptionRequest.getBusinessId()); |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | //1.先检查是否已经扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.DEDUCTION)) { |
| | | //2.没有扣费,检查是否已经预扣费 |
| | | if (!isBeforeDeduction(consumptionRecordList, ConsumptionConstant.BEFORE_DEDUCTION)) { |
| | | //3.没有预扣,查询余额 |
| | | if (VateUserNowProduct(consumptionRequest.getConsumptionCount())) { |
| | | //4.余额充足 获取要扣的套餐 写预扣费记录 |
| | | if (!beforeConsumption(consumptionRequest)) { |
| | | //预扣费执行失败 |
| | | reMsg = "预扣费执行失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_ERROR; |
| | | } |
| | | } else { |
| | | //余额不足 |
| | | reMsg = "余额不足或获取失败!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_FAIL; |
| | | } |
| | | } |
| | | //扣费业务 |
| | | isSuccess= consumptionBusiess(consumptionRequest,consumptionRecordList); |
| | | } else { |
| | | //已经扣费 |
| | | reMsg = "该业务已经扣费!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION; |
| | | } |
| | | } else { |
| | | reMsg = "传入参数有误!"; |
| | | bcode = ConsumptionConstant.BUSINESS_CODE_PARAMS_ERROR; |
| | | } |
| | | return ResultReturn(consumptionRequest, bcode, reMsg, isSuccess); |
| | | } |
| | | |
| | | /** |
| | | * 扣费业务(扣费 更新预扣 写扣费记录) |
| | | * @param consumptionRequest 请求参数 |
| | | * @param consumptionRecordList 扣费业务数据 |
| | | * @return |
| | | */ |
| | | private boolean consumptionBusiess(ConsumptionRequest consumptionRequest, List<ConsumptionRecord> consumptionRecordList) { |
| | | //3.已经预扣费 则扣费 写扣费记录 更新预扣状态 |
| | | ConsumptionRecord consumptionRecord = consumptionRecordList.stream().filter(f -> f.getRecordType() == ConsumptionConstant.BEFORE_DEDUCTION).collect(Collectors.toList()).get(0); |
| | | Long detailId = consumptionRecord.getProOrderDetailId(); |
| | | //获取预扣的时候占住的套餐id |
| | | ProductOrderDetail productOrderDetail = productOrderDetailService.getById(detailId); |
| | | if (productOrderDetail.getAilightCount() >= consumptionRequest.getConsumptionCount()) { |
| | | //扣掉 |
| | | productOrderDetail.setAilightCount(productOrderDetail.getAilightCount() - consumptionRequest.getConsumptionCount()); |
| | | } else { |
| | | //要是被别人已经用了,就要重新找套餐 |
| | | productOrderDetail = deductionDepartmentProduct(consumptionRequest.getConsumptionCount()); |
| | | if (productOrderDetail == null) { |
| | | logger.info("业务编号:【{}】无可用套餐!", consumptionRequest.getBusinessId()); |
| | | return false; |
| | | } else { |
| | | //新套餐扣费 |
| | | productOrderDetail = productOrderDetailService.getById(detailId); |
| | | productOrderDetail.setAilightCount(productOrderDetail.getAilightCount() - consumptionRequest.getConsumptionCount()); |
| | | } |
| | | } |
| | | //3.1扣费! |
| | | boolean consumptionRe = productOrderDetailService.saveOrUpdate(productOrderDetail); |
| | | if (consumptionRe) { |
| | | //3.2扣费成功,写扣费记录 |
| | | ConsumptionRecord consumptionRecordNew = new ConsumptionRecord(); |
| | | consumptionRecordNew.setBusinessCode(ConsumptionConstant.BUSINESS_CODE_IS_DEDUCTION); |
| | | consumptionRecordNew.setBusinessId(consumptionRequest.getBusinessId()); |
| | | consumptionRecordNew.setConsumptionCount(consumptionRequest.getConsumptionCount()); |
| | | consumptionRecordNew.setRecordType(ConsumptionConstant.DEDUCTION); |
| | | consumptionRecordNew.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecordNew.setLastRecordId(consumptionRecord.getLastRecordId()); |
| | | |
| | | if (SaveConsumptionRecord(consumptionRecordNew)) { |
| | | //3.3 扣费成功 如果套餐id变化,则更新预扣费的套餐id |
| | | if (consumptionRecordNew.getProOrderDetailId() != consumptionRecord.getProOrderDetailId()) { |
| | | consumptionRecord.setProOrderDetailId(productOrderDetail.getId()); |
| | | consumptionRecord.setUpdateTime(new Date()); |
| | | if (!SaveConsumptionRecord(consumptionRecord)) { |
| | | logger.info("业务编号:【{}】更新预扣费的套餐id!", consumptionRequest.getBusinessId()); |
| | | } |
| | | } |
| | | //消息队列通知 |
| | | MessageToBI(); |
| | | //已经扣费 |
| | | logger.info("业务编号:【{}】该业务已经扣费!", consumptionRequest.getBusinessId()); |
| | | return true; |
| | | } else { |
| | | logger.info("业务编号:【{}】预扣费执行失败!", consumptionRequest.getBusinessId()); |
| | | } |
| | | } else { |
| | | logger.info("业务编号:【{}】扣除套餐失败!", consumptionRequest.getBusinessId()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 写/更新记录数据 |
| | | * @param consumptionRecord |
| | | * 返回结果包装 |
| | | * |
| | | * @param consumptionRequest 请求参数 |
| | | * @param bcode 返回码 |
| | | * @param reMsg 返回信息 |
| | | * @param isSuccess 业务执行是否成功 |
| | | * @return |
| | | */ |
| | | public ConsumptionRecord SaveConsumptionRecord(ConsumptionRecord consumptionRecord) |
| | | { |
| | | if (consumptionRecord != null) { |
| | | this.saveOrUpdate(consumptionRecord); |
| | | return consumptionRecord; |
| | | private ResultBody ResultReturn(ConsumptionRequest consumptionRequest, int bcode, String reMsg, boolean isSuccess) { |
| | | //返回的数据实体 |
| | | ConsumptionVo consumptionVo = new ConsumptionVo(); |
| | | consumptionVo.setConsumptionCount(consumptionRequest.getConsumptionCount()); |
| | | consumptionVo.setBusinessId(consumptionRequest.getBusinessId()); |
| | | consumptionVo.setBcode(bcode); |
| | | consumptionVo.setRecordType(ConsumptionConstant.BEFORE_DEDUCTION); |
| | | if (isSuccess) { |
| | | return ResultBody.ok().data(consumptionVo).msg(reMsg); |
| | | } else { |
| | | return ResultBody.failed(reMsg).data(consumptionVo); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 预扣费业务 |
| | | * @param consumptionRequest 请求参数 |
| | | * @return |
| | | */ |
| | | private Boolean beforeConsumption(ConsumptionRequest consumptionRequest) { |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | ProductOrderDetail productOrderDetail = deductionDepartmentProduct(consumptionRequest.getConsumptionCount()); |
| | | if (productOrderDetail != null) { |
| | | ConsumptionRecord consumptionRecord = new ConsumptionRecord(); |
| | | consumptionRecord.setBusinessCode(ConsumptionConstant.BUSINESS_CODE_IS_BEFORE_DEDUCTION); |
| | | consumptionRecord.setBusinessId(consumptionRequest.getBusinessId()); |
| | | consumptionRecord.setConsumptionCount(consumptionRequest.getConsumptionCount()); |
| | | consumptionRecord.setRecordType(ConsumptionConstant.BEFORE_DEDUCTION); |
| | | consumptionRecord.setProOrderDetailId(productOrderDetail.getId()); |
| | | if (SaveConsumptionRecord(consumptionRecord)) { |
| | | return true; |
| | | } else { |
| | | logger.info("医院id:【{}】预扣费执行失败!", hospitalId); |
| | | } |
| | | } else { |
| | | logger.info("医院id:【{}】套餐获取失败!", hospitalId); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 参数验证 |
| | | */ |
| | | private Boolean VateParams(ConsumptionRequest consumptionRequest) { |
| | | if (consumptionRequest != null) { |
| | | //从请求头获取医院和科室id |
| | | String hosId = httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER); |
| | | String depId = httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER); |
| | | if (StringUtils.isNotBlank(consumptionRequest.getBusinessId()) |
| | | && consumptionRequest.getConsumptionCount() > 0 |
| | | && StringUtils.isNotBlank(hosId) |
| | | && StringUtils.isNotBlank(depId)) { |
| | | return true; |
| | | } else { |
| | | logger.info("扣费请求参数不完整!"); |
| | | } |
| | | } else { |
| | | logger.info("扣费请求参数为空!"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 检查余额够不够 |
| | | * @param consumptionCount 要扣的数量 |
| | | * @return |
| | | */ |
| | | private Boolean VateUserNowProduct(int consumptionCount) { |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | 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; |
| | | } else { |
| | | logger.info("医院id:【{}】余额不足!", hospitalId); |
| | | } |
| | | } else { |
| | | logger.error("医院id:【{}】余额获取异常!", hospitalId); |
| | | } |
| | | } else { |
| | | logger.info("医院id:【{}】余额获取异常,返回非0!", hospitalId); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 获取要使用的套餐实体 |
| | | * @param consumCount 要使用的数量 |
| | | * @return |
| | | */ |
| | | private ProductOrderDetail deductionDepartmentProduct(int consumCount) { |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | UserProductDetail userProductDetail = productOrderDetailService.getUserProductDetail(hospitalId, departmentId); |
| | | //合并集合 |
| | | userProductDetail.getProductOrderJoinDetailListShare().addAll(userProductDetail.getProductOrderJoinDetailsListDep()); |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailList = userProductDetail.getProductOrderJoinDetailListShare(); |
| | | if (productOrderJoinDetailList.size() > 0) { |
| | | //合并后按id排序并筛除已用完的套餐 |
| | | List<ProductOrderJoinDetail> productOrderJoinDetailsNewList = productOrderJoinDetailList.stream().filter(f -> f.getAilightCount() >= consumCount).sorted(Comparator.comparing(ProductOrderJoinDetail::getId)).collect(Collectors.toList()); |
| | | //要使用的套餐信息 |
| | | ProductOrderDetail productOrderDetail = productOrderDetailService.getById(productOrderJoinDetailsNewList.get(0).getId()); |
| | | return productOrderDetail; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 检查该业务是否存在该业务类型 |
| | | * @param consumptionRecordList 该业务下的扣费列表 |
| | | * @param recordType 记录类型编码 参考ConsumptionConstant里面 |
| | | * 写/更新记录数据 |
| | | * |
| | | * @param consumptionRecord |
| | | * @return |
| | | */ |
| | | public boolean isBeforeDeduction(List<ConsumptionRecord> consumptionRecordList,int recordType) |
| | | { |
| | | private Boolean SaveConsumptionRecord(ConsumptionRecord consumptionRecord) { |
| | | if (consumptionRecord != null) { |
| | | return this.saveOrUpdate(consumptionRecord); |
| | | } else { |
| | | logger.info("扣费数据写入参数为空!"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 检查该业务是否存在该业务类型 |
| | | * |
| | | * @param consumptionRecordList 该业务下的扣费列表 |
| | | * @param recordType 记录类型编码 参考ConsumptionConstant里面 |
| | | * @return |
| | | */ |
| | | private boolean isBeforeDeduction(List<ConsumptionRecord> consumptionRecordList, int recordType) { |
| | | if (consumptionRecordList != null) { |
| | | if (consumptionRecordList.size()>0) { |
| | | if (consumptionRecordList.size() > 0) { |
| | | //过滤预扣费的记录 |
| | | return consumptionRecordList.stream().filter(f->f.getRecordType()==recordType).collect(Collectors.toList()).size()==1; |
| | | return consumptionRecordList.stream().filter(f -> f.getRecordType() == recordType).collect(Collectors.toList()).size() == 1; |
| | | } |
| | | } |
| | | return false; |
| | |
| | | |
| | | /** |
| | | * 获取一个业务关联的扣费记录 |
| | | * |
| | | * @param businessId 光片的名称/编号 |
| | | * @return |
| | | */ |
| | | public List<ConsumptionRecord> GetBusinessConsumptionList(String businessId) |
| | | { |
| | | private List<ConsumptionRecord> GetBusinessConsumptionList(String businessId) { |
| | | if (StringUtils.isNotBlank(businessId)) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("businessId", businessId); |
| | | List<ConsumptionRecord> consumptionRecordList=this.findAllList(params); |
| | | List<ConsumptionRecord> consumptionRecordList = this.findAllList(params); |
| | | return consumptionRecordList; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取一个扣费记录 |
| | | * |
| | | * @param recordId 扣费记录id |
| | | * @return |
| | | */ |
| | | public ConsumptionRecord GetBusinessConsumptionList(Long recordId) |
| | | { |
| | | if (recordId>0) { |
| | | private ConsumptionRecord GetBusinessConsumptionList(Long recordId) { |
| | | if (recordId > 0) { |
| | | return baseMapper.selectById(recordId); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 发消息到消息队列 |
| | | * @return |
| | | */ |
| | | @RabbitListener(queues = "BoneAgeEvaluationData") |
| | | private void MessageToBI() |
| | | { |
| | | Long hospitalId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER)); |
| | | Long departmentId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER)); |
| | | Long doctorId = Long.valueOf(httpServletRequest.getHeader(SecurityConstants.DOCTOR_ID_HEADER)); |
| | | //发消息到队列 |
| | | String context = "{\"hospitalId\":\"" + hospitalId + |
| | | "\",\"departmentId\":\"" + departmentId + |
| | | "\",\"doctorId\":\"" + doctorId + |
| | | "\",\"date\":\"" + DateUtils.formatDate(new Date(),"yyyy-MM-dd")+"\"}"; |
| | | rabbitTemplate.convertAndSend(ConsumptionConstant.EXCHANGE_DATA, ConsumptionConstant.ROUTINGKEY_DATA, context); |
| | | } |
| | | } |