QueRenYiZhuShouFeiServer.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package thyyxxk.webserver.service.zhuyuanyiji;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.GetDateFormat;
  10. import thyyxxk.webserver.dao.his.yibao.XiangMuLuRuDao;
  11. import thyyxxk.webserver.dao.his.zhuyuanyiji.QueRenYiZhuShouFeiDao;
  12. import thyyxxk.webserver.entity.ResultVo;
  13. import thyyxxk.webserver.entity.datamodify.FeiYongLeiXin;
  14. import thyyxxk.webserver.entity.datamodify.YzActOrder;
  15. import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
  16. import thyyxxk.webserver.utils.JiSuanFeiYong;
  17. import thyyxxk.webserver.utils.ResultVoUtil;
  18. import thyyxxk.webserver.utils.StringUtil;
  19. import thyyxxk.webserver.utils.TokenUtil;
  20. import java.math.BigDecimal;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * <p>
  25. * 描述: 确认医嘱收费
  26. * </p>
  27. *
  28. * @author xc
  29. * @date 2021-09-27 11:50
  30. */
  31. @Service
  32. @Slf4j
  33. public class QueRenYiZhuShouFeiServer {
  34. private final QueRenYiZhuShouFeiDao dao;
  35. private final XiangMuLuRuDao xiangMuLuRuDao;
  36. public QueRenYiZhuShouFeiServer(QueRenYiZhuShouFeiDao dao, XiangMuLuRuDao xiangMuLuRuDao) {
  37. this.dao = dao;
  38. this.xiangMuLuRuDao = xiangMuLuRuDao;
  39. }
  40. /**
  41. * @param yzActOrder 查询条件 住院号,住院次数,执行科室, 分页
  42. * @return 返回分页数据
  43. */
  44. public ResultVo<IPage<YzActOrder>> getXuQueFeiYiZhu(YzActOrder yzActOrder) {
  45. IPage<YzActOrder> page = new Page<>(yzActOrder.getCurrentPage(), yzActOrder.getPageSize());
  46. // yzActOrder.setInpatientNo(publicServer.getInpatientNo(yzActOrder.getInpatientNo()));
  47. if (StringUtil.isBlank(yzActOrder.getExecUnit())) {
  48. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "科室信息为空 [・_・?]");
  49. }
  50. log.info("查询需确费医嘱:数据:{}", JSON.toJSONString(yzActOrder));
  51. dao.getXuQueFeiYiZhu(page, yzActOrder.getInpatientNo(), yzActOrder.getAdmissTimes(), yzActOrder.getExecUnit());
  52. if (page.getRecords().isEmpty()) {
  53. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
  54. }
  55. return ResultVoUtil.success(page);
  56. }
  57. /**
  58. * 这里是查询 患者的具体医嘱确认信息
  59. *
  60. * @param inpatientNo 住院号
  61. * @param admissTimes 住院次数
  62. * @param execUnit 执行科室
  63. * @return 返回
  64. */
  65. public ResultVo<List<YzActOrder>> getXuQueFeiXiangXiXinXi(String inpatientNo, Integer admissTimes, String execUnit) {
  66. List<YzActOrder> list = dao.getXuQueFeiXiangXiXinXi(inpatientNo, admissTimes, execUnit);
  67. if (list.isEmpty()) {
  68. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "ヽ(゜Q。)ノ?");
  69. }
  70. return ResultVoUtil.success(list);
  71. }
  72. @Transactional(rollbackFor = Exception.class)
  73. public ResultVo<String> baoCunYiZhuQueFeiShuJu(YzActOrder param) {
  74. List<ZyDetailCharge> zyDetailCharges = new ArrayList<>();
  75. List<YzActOrder> shangChuanList = new ArrayList<>();
  76. BigDecimal sum = new BigDecimal(0);
  77. for (YzActOrder yzActOrder : param.getList()) {
  78. if (yzActOrder.getChargeStatus().equals("0")) {
  79. ZyDetailCharge zy = new ZyDetailCharge();
  80. zy.setChargeAmount(yzActOrder.getOrderCount());
  81. // 这里是价格传过来的价格是总价 所以我要先变成单价 才能计算不失误 这个除法是保留小数点后两位的
  82. zy.setChargeFee(yzActOrder.getChargeFee().divide(yzActOrder.getOrderCount(), 2, BigDecimal.ROUND_HALF_UP));
  83. zy.setBillItemCode(yzActOrder.getBillItemCode());
  84. zyDetailCharges.add(zy);
  85. sum = sum.add(zy.getChargeAmount().multiply(zy.getChargeFee()));
  86. shangChuanList.add(yzActOrder);
  87. } else if (yzActOrder.getChargeStatus().equals("1")) {
  88. shangChuanList.add(yzActOrder);
  89. }
  90. }
  91. if (shangChuanList.isEmpty()) {
  92. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有选择任何操作 !!!∑(゚Д゚ノ)ノ");
  93. } else {
  94. dao.baoCunYiZhuQueFei(param.getInpatientNo(), param.getAdmissTimes(), shangChuanList, TokenUtil.getTokenUserId());
  95. }
  96. if (!zyDetailCharges.isEmpty()) {
  97. FeiYongLeiXin fy = JiSuanFeiYong.jiSuan(zyDetailCharges, true);
  98. fy.setTotalCharge(sum);
  99. xiangMuLuRuDao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_ledger_file");
  100. xiangMuLuRuDao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_actpatient");
  101. }
  102. log.info("医嘱确费保存==》操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(param.getList(), GetDateFormat.DATE_TIME));
  103. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "操作成功 (๑*◡*๑)");
  104. }
  105. }