CaoYaoYiZhuServer.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package thyyxxk.webserver.service.zhuyuanyisheng;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import thyyxxk.webserver.config.exception.ExceptionEnum;
  10. import thyyxxk.webserver.dao.his.zhuyuanyisheng.CaoYaoYiZhuDao;
  11. import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
  12. import thyyxxk.webserver.entity.ResultVo;
  13. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  14. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.CaoYaoChaXunTiaoJian;
  15. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
  16. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCyDetail;
  17. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzOrderPatternCy;
  18. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  19. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YiZhuMingChen;
  20. import thyyxxk.webserver.service.PublicServer;
  21. import thyyxxk.webserver.utils.*;
  22. import java.math.BigDecimal;
  23. import java.util.Date;
  24. import java.util.List;
  25. /**
  26. * <p>
  27. * 描述:
  28. * </p>
  29. *
  30. * @author xc
  31. * @date 2022-02-26 08:39
  32. */
  33. @Service
  34. @Slf4j
  35. public class CaoYaoYiZhuServer {
  36. private final CaoYaoYiZhuDao dao;
  37. private final PublicServer publicServer;
  38. private final YiZhuLuRuDao yiZhuLuRuDao;
  39. public CaoYaoYiZhuServer(CaoYaoYiZhuDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao) {
  40. this.dao = dao;
  41. this.publicServer = publicServer;
  42. this.yiZhuLuRuDao = yiZhuLuRuDao;
  43. }
  44. public ResultVo<IPage<YzActOrderCy>> huoQuCaoYaoShuJu(CaoYaoChaXunTiaoJian param) {
  45. IPage<YzActOrderCy> page = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0);
  46. QueryWrapper<?> qw = new QueryWrapper<>();
  47. qw.eq("inpatient_no", param.getPatNo());
  48. qw.eq("admiss_times", param.getTimes());
  49. qw.le("status_flag", "3");
  50. if (StringUtil.notBlank(param.getStartTime())) {
  51. qw.ge("input_date", param.getStartTime());
  52. qw.le("input_date", param.getEndTime());
  53. }
  54. dao.huoQuCaoYaoShuJu(page, qw);
  55. for (YzActOrderCy item : page.getRecords()) {
  56. item.setDaiJianFei(item.getQuantityDj().multiply(item.getOrderJeDj()));
  57. item.setJiaGe(item.getQuantity().multiply(item.getOrderJe()));
  58. item.setZongJia(item.getDaiJianFei().add(item.getJiaGe()));
  59. }
  60. return ResultVoUtil.success(page);
  61. }
  62. public ResultVo<List<YzActOrderCyDetail>> huoQuChaoYaoMingXi(BigDecimal orderNo) {
  63. return ResultVoUtil.success(dao.huoQuChaoYaoMingXi(orderNo));
  64. }
  65. public ResultVo<List<GetDropdownBox>> fuYongFangFa() {
  66. return ResultVoUtil.success(dao.fuYongFangFa());
  67. }
  68. public ResultVo<IPage<YiZhuMingChen>> huoQuCaoYao(String queryName, Integer groupNo, long currentPage, long pageSize, long total) {
  69. IPage<YiZhuMingChen> page = new Page<>(currentPage, pageSize, total == 0);
  70. String name = StringUtil.EnglishToCapital(queryName);
  71. QueryWrapper<?> qw = new QueryWrapper<>();
  72. qw.and(QueryWrapper -> QueryWrapper
  73. .like("py_code", name)
  74. .or()
  75. .like("name", name)
  76. .or()
  77. .like("d_code", name)
  78. .or()
  79. .like("code", name)
  80. )
  81. .eq("group_no", groupNo);
  82. dao.huoQuCaoYao(page, qw);
  83. return ResultVoUtil.success(page);
  84. }
  85. public ResultVo<IPage<YzOrderPatternCy>> huoQuMuBan(String queryName, String deptCode, long currentPage, long pageSize, long total) {
  86. IPage<YzOrderPatternCy> page = new Page<>(currentPage, pageSize, total == 0);
  87. String name = StringUtil.EnglishToCapital(queryName);
  88. QueryWrapper<?> qw = new QueryWrapper<>();
  89. qw.and(QueryWrapper -> QueryWrapper
  90. .like("py_code", name)
  91. .or()
  92. .like("d_code", name)
  93. .or()
  94. .like("pattern_name", name)
  95. );
  96. if (publicServer.noNeedRule(new int[]{1, 38})) {
  97. qw.eq("dept_code", deptCode);
  98. }
  99. qw.groupBy("pattern_name");
  100. dao.huoQuMuBan(page, qw);
  101. return ResultVoUtil.success(page);
  102. }
  103. public ResultVo<List<YzOrderPatternCy>> muBanXiangQing(String name, String deptCode) {
  104. return ResultVoUtil.success(dao.muBanXiangQing(name, deptCode));
  105. }
  106. public ResultVo<Boolean> chongFuMuBanMing(String name) {
  107. return ResultVoUtil.success(dao.chongFuMuBanMing(name) > 1);
  108. }
  109. public ResultVo<String> cunMuBan(YzOrderPatternCy param) {
  110. log.info("插入模板草药模板:{}", JSON.toJSONString(param));
  111. dao.chaRuMuBan(param.getList(), param.getPatternName(), TokenUtil.getTokenUserId(),
  112. PingYinUtils.pyShouZiMuDaXie(param.getPatternName()), PingYinUtils.getWBCode(param.getPatternName()),
  113. param.getDeptCode());
  114. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  115. }
  116. @Transactional(rollbackFor = Exception.class)
  117. public ResultVo<String> baoCunCaoYao(YzActOrderCy param) {
  118. log.info("上传的数据:{}", JSON.toJSONString(param));
  119. if (ListUtil.isBlank(param.getList())) {
  120. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要上传的数据。");
  121. }
  122. publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
  123. BigDecimal sum = new BigDecimal(0);
  124. param.setInputId(TokenUtil.getTokenUserId());
  125. for (YzActOrderCyDetail item : param.getList()) {
  126. sum = sum.add(item.getQuantity().multiply(item.getRetprice()));
  127. }
  128. param.setOrderJe(sum);
  129. param.setOrderJeDj(dao.huoQuDaiJianFei());
  130. param.setPageNo(Integer.valueOf(DateUtil.formatDatetime(new Date(), "yyMMdd") + publicServer.huoQuCaoYaoShenQingDanHao()));
  131. XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  132. param.setOrderNo(BigDecimal.valueOf(publicServer.getActOrderNo()));
  133. dao.chaRuCaoYaoYiZhu(param, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getSmallDept());
  134. dao.chaRuCaoYaoXiangQing(param.getList(), param.getOrderNo());
  135. dao.chaRuYiZhu(param, "草药医嘱:" + param.getOrderName() + param.getQuantity() + "剂", huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(), huanZheXinXi.getSmallDept(), publicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
  136. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  137. }
  138. public ResultVo<String> shanChuMuBan(String name, String deptCode) {
  139. YzOrderPatternCy mb = dao.caoYaoMuBanXiangQing(name);
  140. List<Integer> rolse = publicServer.getRoleCode().getData();
  141. boolean flag;
  142. if (publicServer.noNeedRule(rolse, new int[]{1, 38})) {
  143. flag = mb.getCreateId().equals(TokenUtil.getTokenUserId());
  144. if (!publicServer.noNeedRule(rolse, new int[]{11})) {
  145. flag = mb.getDeptCode().trim().equals(deptCode);
  146. }
  147. } else {
  148. flag = true;
  149. }
  150. if (flag) {
  151. dao.shanChuMuBan(name);
  152. return ResultVoUtil.success();
  153. } else {
  154. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限删除。");
  155. }
  156. }
  157. }