PublicServer.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. package thyyxxk.webserver.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import lombok.AllArgsConstructor;
  6. import lombok.Data;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.apache.commons.collections4.ListUtils;
  9. import org.apache.ibatis.session.ExecutorType;
  10. import org.apache.ibatis.session.SqlSession;
  11. import org.apache.ibatis.session.SqlSessionFactory;
  12. import org.jetbrains.annotations.NotNull;
  13. import org.springframework.scheduling.annotation.Async;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Isolation;
  16. import org.springframework.transaction.annotation.Propagation;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import thyyxxk.webserver.config.exception.BizException;
  19. import thyyxxk.webserver.config.exception.ExceptionEnum;
  20. import thyyxxk.webserver.constants.Capacity;
  21. import thyyxxk.webserver.constants.Message;
  22. import thyyxxk.webserver.constants.RestrictedDrugLevels;
  23. import thyyxxk.webserver.constants.Ysjb;
  24. import thyyxxk.webserver.dao.his.PublicDao;
  25. import thyyxxk.webserver.dao.his.inpatient.TransferInOfExpensesDao;
  26. import thyyxxk.webserver.dao.his.settings.SettingsDao;
  27. import thyyxxk.webserver.entity.ResultVo;
  28. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  29. import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
  30. import thyyxxk.webserver.entity.dictionary.CodeName;
  31. import thyyxxk.webserver.entity.inpatient.ZyActpatient;
  32. import thyyxxk.webserver.entity.login.UserInfo;
  33. import thyyxxk.webserver.entity.login.UserInfoSelect;
  34. import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyPatientInfo;
  35. import thyyxxk.webserver.entity.publicapi.ItemDrug;
  36. import thyyxxk.webserver.entity.publicapi.ZkList;
  37. import thyyxxk.webserver.entity.settings.notification.SendMessageParam;
  38. import thyyxxk.webserver.entity.socketmessage.ApiMessageBody;
  39. import thyyxxk.webserver.entity.socketmessage.SendUserList;
  40. import thyyxxk.webserver.entity.socketmessage.SocketMessage;
  41. import thyyxxk.webserver.entity.zhuyuanyisheng.PatientAllergenInfo;
  42. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  43. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YaoPinXiangMu;
  44. import thyyxxk.webserver.service.externalhttp.WebSocketService;
  45. import thyyxxk.webserver.service.hutoolcache.ExtraCache;
  46. import thyyxxk.webserver.service.hutoolcache.UserCache;
  47. import thyyxxk.webserver.utils.*;
  48. import java.lang.reflect.InvocationTargetException;
  49. import java.math.BigDecimal;
  50. import java.util.*;
  51. import java.util.stream.Collectors;
  52. /**
  53. * <p>
  54. * 描述: 公共接口
  55. * </p>
  56. *
  57. * @author xc
  58. * @date 2021-09-17 10:54
  59. */
  60. @Service
  61. @Slf4j
  62. public class PublicServer {
  63. private final PublicDao dao;
  64. private final TransferInOfExpensesDao transferInOfExpensesDao;
  65. private final SettingsDao settingsDao;
  66. private final WebSocketService socketService;
  67. private final SqlSessionFactory sqlSessionFactory;
  68. private final ExtraCache extraCache;
  69. private final UserCache userCache;
  70. public PublicServer(PublicDao dao, TransferInOfExpensesDao transferInOfExpensesDao, WebSocketService socketService, SettingsDao settingsDao, SqlSessionFactory sqlSessionFactory, ExtraCache extraCache, UserCache userCache) {
  71. this.dao = dao;
  72. this.transferInOfExpensesDao = transferInOfExpensesDao;
  73. this.settingsDao = settingsDao;
  74. this.extraCache = extraCache;
  75. this.socketService = socketService;
  76. this.sqlSessionFactory = sqlSessionFactory;
  77. this.userCache = userCache;
  78. }
  79. /**
  80. * 手术日期格式
  81. *
  82. * @param opStartDate 手术开始时间
  83. * @param opEndDate 手术结束时间
  84. * @param anstStartDate 麻醉开始时间
  85. * @param anstEndDate 麻醉结束时间
  86. */
  87. public static void surgeryTimeLimit(String opName, Date opStartDate, Date opEndDate, Date anstStartDate, Date anstEndDate) {
  88. if (anstStartDate != null) {
  89. if (DateUtil.shiJianDaXiao(opStartDate, anstStartDate, "<")) {
  90. throw new BizException(ExceptionEnum.LOGICAL_ERROR, opName + ":麻醉开始时间要大于手术开始时间.");
  91. }
  92. long opDate = opEndDate.getTime() - opStartDate.getTime();
  93. long anstDate = anstEndDate.getTime() - anstStartDate.getTime();
  94. if (opDate >= anstDate) {
  95. throw new BizException(ExceptionEnum.LOGICAL_ERROR, opName + ":手术麻醉时间一定要比手术时间长.");
  96. }
  97. }
  98. }
  99. /**
  100. * 获取用户的角色信息
  101. *
  102. * @return 返回角色
  103. */
  104. public ResultVo<List<Integer>> getRoleCode() {
  105. return ResultVoUtil.success(userCache.getUserInfoByToken().getRoles());
  106. }
  107. /**
  108. * @param jueSeBianMa 不需要限制的角色id
  109. * @return Boolean
  110. */
  111. public Boolean noNeedRule(int... jueSeBianMa) {
  112. return getaBoolean(jueSeBianMa, getRoleCode().getData());
  113. }
  114. /**
  115. * @param jueSeBianMa 不需要限制的角色id
  116. * @return Boolean
  117. */
  118. public Boolean noNeedRule(List<Integer> role, int... jueSeBianMa) {
  119. return getaBoolean(jueSeBianMa, role);
  120. }
  121. /**
  122. * @param jueSeBianMa 不需要限制的角色id
  123. * @return Boolean 如果有就返回true
  124. */
  125. public Boolean needRule(int... jueSeBianMa) {
  126. return !getaBoolean(jueSeBianMa, getRoleCode().getData());
  127. }
  128. /**
  129. * @param jueSeBianMa 不需要限制的角色id
  130. * @return Boolean
  131. */
  132. public Boolean needRule(List<Integer> role, int... jueSeBianMa) {
  133. return !getaBoolean(jueSeBianMa, role);
  134. }
  135. public Boolean getaBoolean(int[] jueSeBianMa, List<Integer> roleCode) {
  136. if (roleCode.contains(1)) {
  137. return false;
  138. }
  139. if (ListUtil.isBlank(roleCode)) {
  140. return true;
  141. }
  142. for (Integer i : jueSeBianMa) {
  143. if (roleCode.contains(i)) {
  144. return false;
  145. }
  146. }
  147. return true;
  148. }
  149. /**
  150. * 获取新的医嘱号
  151. *
  152. * @return 返回医嘱号
  153. */
  154. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  155. public BigDecimal getActOrderNo() {
  156. BigDecimal oldId = dao.getActOrderNo();
  157. BigDecimal newId = oldId.add(BigDecimal.ONE);
  158. int num = dao.updateActOrderNo(newId, oldId);
  159. // 插入生成医嘱的日志
  160. orderRecord(newId, TokenUtil.getInstance().getTokenUserId());
  161. if (num == 0) {
  162. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成医嘱号错误,请重试!");
  163. }
  164. return newId;
  165. }
  166. /**
  167. * 获取新的医嘱编码号
  168. *
  169. * @return 返回医嘱号
  170. */
  171. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  172. public String getOrderNo() {
  173. BigDecimal oldId = dao.getOrderCode();
  174. BigDecimal newId = oldId.add(BigDecimal.ONE);
  175. int num = dao.updateOrderNo(newId, oldId);
  176. // 插入生成医嘱的日志
  177. if (num == 0) {
  178. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成医嘱号错误,请重试!");
  179. }
  180. return formatNumberWithLeadingZeros(newId, 5);
  181. }
  182. /**
  183. * 将数字格式化为指定长度的字符串,不足位数在前面补0.
  184. *
  185. * @param number 需要格式化的数字
  186. * @param length 格式化后的字符串长度
  187. * @return 格式化后的字符串
  188. * @throws IllegalArgumentException 如果 length 小于等于 0
  189. */
  190. public static String formatNumberWithLeadingZeros(Object number, int length) {
  191. if (length <= 0) {
  192. throw new IllegalArgumentException("Length must be greater than 0.");
  193. }
  194. String numberString;
  195. if (number instanceof BigDecimal) {
  196. numberString = ((BigDecimal) number).toPlainString(); // 使用 toPlainString() 防止科学计数法
  197. } else if (number instanceof Integer) {
  198. numberString = String.valueOf(number);
  199. } else {
  200. throw new IllegalArgumentException("Unsupported number type. Must be BigDecimal or Integer.");
  201. }
  202. if (numberString.length() >= length) {
  203. // 如果数字本身长度大于等于指定长度,则直接返回数字字符串,不进行补0
  204. return numberString;
  205. }
  206. StringBuilder sb = new StringBuilder();
  207. int zerosToAdd = length - numberString.length();
  208. for (int i = 0; i < zerosToAdd; i++) {
  209. sb.append("0");
  210. }
  211. sb.append(numberString);
  212. return sb.toString();
  213. }
  214. /**
  215. * 获取模板的编码
  216. *
  217. * @return 返回编码信息
  218. */
  219. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  220. public String getPatternCode() {
  221. Integer oldId = dao.getPatternCode();
  222. Integer newId = oldId + 1;
  223. int num = dao.updatePatternCode(newId, oldId);
  224. if (num == 0) {
  225. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成模板编码错误,请重试!");
  226. }
  227. return newId.toString();
  228. }
  229. /**
  230. * 获取医嘱模板下面的 子级 排序号
  231. *
  232. * @return 返回序号
  233. */
  234. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  235. public BigDecimal getPatternOrderCode() {
  236. BigDecimal oldId = dao.getPatternOrderCode();
  237. BigDecimal newId = oldId.add(BigDecimal.ONE);
  238. int num = dao.updatePatternOrderCode(newId, oldId);
  239. if (num == 0) {
  240. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成子医嘱模板编码错误,请重试!");
  241. }
  242. return newId;
  243. }
  244. /**
  245. * @return 返回说明模板的编码
  246. */
  247. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  248. public Integer getYjTemplateNo() {
  249. Integer oldId = dao.tempNo();
  250. Integer newId = oldId + 1;
  251. int num = dao.updateTempNo(newId, oldId);
  252. if (num == 0) {
  253. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成说明模板的编码错误,请重试!");
  254. }
  255. return newId;
  256. }
  257. /**
  258. * @return 返回申请号
  259. */
  260. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  261. public Integer getReqPageNo() {
  262. Integer oldId = dao.getReqNo();
  263. Integer newId = oldId + 1;
  264. int num = dao.updateReqNo(newId, oldId);
  265. if (num == 0) {
  266. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  267. }
  268. return newId;
  269. }
  270. /**
  271. * 获取药品单号
  272. *
  273. * @return 药品单号
  274. */
  275. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  276. public Integer getTheDrugListNo() {
  277. Integer oldId = dao.caoYaoDanHao();
  278. Integer newId = oldId + 1;
  279. int num = dao.genXingCaoYaoDanHao(newId, oldId);
  280. if (num == 0) {
  281. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  282. }
  283. return Integer.valueOf(DateUtil.formatDatetime(new Date(), "yyMMdd") + newId);
  284. }
  285. /**
  286. * 获取传染病序号
  287. *
  288. * @return 序号
  289. */
  290. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  291. public Integer getCrbNo() {
  292. Integer oldId = dao.oldCrbNo();
  293. Integer newId = oldId + 1;
  294. int num = dao.updateCrbNo(newId, oldId);
  295. if (num == 0) {
  296. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  297. }
  298. return newId;
  299. }
  300. /**
  301. * @param inpatientNo 住院号
  302. * @return 返回婴儿标志
  303. */
  304. public static int getInfantFlag(String inpatientNo) {
  305. if (StringUtil.isBlank(inpatientNo)) {
  306. return 0;
  307. }
  308. if (inpatientNo.contains("$")) {
  309. return 1;
  310. }
  311. return 0;
  312. }
  313. /**
  314. * 返回
  315. *
  316. * @param inpatientNo 住院号
  317. * @return 返回新住院号
  318. */
  319. public static String getInpatientNo(String inpatientNo) {
  320. if (StringUtil.isBlank(inpatientNo)) {
  321. return "";
  322. }
  323. if (inpatientNo.contains("$")) {
  324. inpatientNo = inpatientNo.split("\\$")[0];
  325. }
  326. return inpatientNo;
  327. }
  328. /**
  329. * 获取最大流水号
  330. *
  331. * @param inpatientNo 住院号
  332. * @param admissTimes 住院次数
  333. * @return 返回 流水
  334. */
  335. public Integer getMaxDetailSn(String inpatientNo, Integer admissTimes) {
  336. return transferInOfExpensesDao.getMaxDetailSn(inpatientNo, admissTimes);
  337. }
  338. /**
  339. * 获取科室的子科室和本科
  340. *
  341. * @param deptCode 科室代码
  342. * @return 返回科室
  343. */
  344. public List<String> getKeShiLieBiaoList(String deptCode) {
  345. if (noNeedRule()) {
  346. List<String> list = dao.getKeShiLieBiao(deptCode);
  347. list.add(deptCode);
  348. return list;
  349. }
  350. return new ArrayList<>();
  351. }
  352. public Set<String> getChildDeptByUserCode() {
  353. return getChildDeptByUserCode(true);
  354. }
  355. public Set<String> getChildDeptByUserCode(String userCode) {
  356. return getChildDeptByUserCode(true, userCode);
  357. }
  358. public Set<String> getChildDeptByUserCode(boolean needPartTimeDept, String userCode) {
  359. UserInfo userInfo = userCache.get(userCode);
  360. return getDept(needPartTimeDept, userInfo);
  361. }
  362. /**
  363. * 获取医生的子科室 和 兼职科室 以及兼职下面的子科室
  364. *
  365. * @return 返回科室
  366. */
  367. public Set<String> getChildDeptByUserCode(boolean needPartTimeDept) {
  368. UserInfo userInfo = userCache.getUserInfoByToken();
  369. return getDept(needPartTimeDept, userInfo);
  370. }
  371. @NotNull
  372. public Set<String> getDept(boolean needPartTimeDept, UserInfo userInfo) {
  373. Set<String> list = new HashSet<>();
  374. if (needPartTimeDept && ListUtil.notBlank(userInfo.getPartTimeDept())) {
  375. list.addAll(userInfo.getPartTimeDept());
  376. }
  377. list.add(userInfo.getDeptCode());
  378. QueryWrapper<?> qw = new QueryWrapper<>();
  379. qw.in("parent_code", list);
  380. List<String> temp = dao.selectChildDeptByCodeList(qw);
  381. if (ListUtil.notBlank(temp)) {
  382. list.addAll(temp);
  383. }
  384. return list;
  385. }
  386. /**
  387. * 获取科室 列表 下面的子科室
  388. *
  389. * @param deptCodeList 科室列表
  390. * @return 返回科室
  391. */
  392. public List<String> getKeShiLieBiaoList(List<String> deptCodeList) {
  393. if (ListUtil.isBlank(deptCodeList)) {
  394. return new ArrayList<>();
  395. }
  396. return dao.getKeShiLieBiaoList(deptCodeList);
  397. }
  398. /**
  399. * 获取人员信息
  400. *
  401. * @param code 人员代码
  402. * @return 返回人员
  403. */
  404. public ResultVo<List<GetDropdownBox>> getRenYuan(String code, String deptCode) {
  405. return ResultVoUtil.success(dao.getRenYuan(StringUtil.isContainChinese(code), deptCode));
  406. }
  407. /**
  408. * 获取员工信息
  409. *
  410. * @param code 编码
  411. * @return 返回
  412. */
  413. public UserInfo huoQuYuanGongXinXi(String code) {
  414. if (StringUtil.isBlank(code)) {
  415. return new UserInfo();
  416. }
  417. return dao.huoQuYuanGongBianMa(code);
  418. }
  419. public ResultVo<List<UserInfoSelect>> getPersonnelAll() {
  420. return ResultVoUtil.success(dao.getPersonnelAll());
  421. }
  422. /**
  423. * 搜索项目信息
  424. *
  425. * @param pyCode 拼音码
  426. * @return 返回项目信息
  427. */
  428. public ResultVo<List<GetDropdownBox>> getChargeCode(String pyCode) {
  429. log.info("获取编码:{}", pyCode);
  430. return ResultVoUtil.success(dao.getChargeCode(StringUtil.isContainChinese(pyCode)));
  431. }
  432. /**
  433. * 获取科室信息
  434. *
  435. * @return 返回科室
  436. */
  437. public ResultVo<List<GetDropdownBox>> getDept() {
  438. return ResultVoUtil.success(dao.getDept());
  439. }
  440. public ResultVo<List<GetDropdownBox>> queryDept(String code) {
  441. return ResultVoUtil.success(dao.queryDept(StringUtil.isContainChinese(code)));
  442. }
  443. /**
  444. * 获取这个人的账页号
  445. *
  446. * @param inpatientNo 住院号
  447. * @param admissTimes 住院次数
  448. * @return 返回有用的账页号
  449. */
  450. public Integer getLedgerSn(String inpatientNo, Integer admissTimes) {
  451. if (StringUtil.isBlank(inpatientNo) || admissTimes == null) {
  452. return 0;
  453. }
  454. inpatientNo = getInpatientNo(inpatientNo);
  455. return dao.getLedgerSn(inpatientNo, admissTimes);
  456. }
  457. /**
  458. * 更新患者的退费对应的正流水号
  459. *
  460. * @param inpatientNo 住院号
  461. * @param admissTimes 住院次数
  462. * @param ledger 账页号
  463. */
  464. public void genXingYuanLiuShuiBiaoZhi(String inpatientNo, Integer admissTimes, Integer ledger) {
  465. dao.chongZhiZhenLiuShui(inpatientNo, admissTimes, ledger);
  466. // 这里是重置 正流水号
  467. List<Integer> huoQuTuiFeiYuanLiuShui = dao.huoQuTuiFeiYuanLiuShui(inpatientNo, admissTimes, ledger);
  468. if (ListUtil.notBlank(huoQuTuiFeiYuanLiuShui)) {
  469. List<List<Integer>> fenGeFuLiuShui = ListUtils.partition(huoQuTuiFeiYuanLiuShui, 50);
  470. for (List<Integer> integers : fenGeFuLiuShui) {
  471. dao.genXingFuShuDuiYingZhenLiuShui(inpatientNo, admissTimes, ledger, integers);
  472. }
  473. }
  474. // 这里是判断正数的是否没有了,如果正数的没有了 那么负数的就要更新为空
  475. List<Integer> xuYaoQingKongDeFuLiuShui = new ArrayList<>();
  476. List<Integer> zhenShuLiuShuiMap = dao.zhenShuLiuShui(inpatientNo, admissTimes, ledger);
  477. List<Integer> fuShuLiuShui = dao.fuShuLiuShui(inpatientNo, admissTimes, ledger);
  478. for (Integer integer : fuShuLiuShui) {
  479. if (!zhenShuLiuShuiMap.contains(integer) && !xuYaoQingKongDeFuLiuShui.contains(integer)) {
  480. xuYaoQingKongDeFuLiuShui.add(integer);
  481. }
  482. }
  483. if (ListUtil.notBlank(xuYaoQingKongDeFuLiuShui)) {
  484. List<List<Integer>> list = ListUtils.partition(xuYaoQingKongDeFuLiuShui, 50);
  485. for (List<Integer> integers : list) {
  486. dao.chongZhiFuShuYuanLiuShui(inpatientNo, admissTimes, ledger, integers);
  487. }
  488. }
  489. // 这里判断是否重复退费,退多了
  490. Map<Integer, ZyDetailCharge> chongFuYuanLiuShuiMap = dao.chongFuTuiFeiLiuShui(inpatientNo, admissTimes, ledger).stream().collect(Collectors.toMap(ZyDetailCharge::getOriDetailSn, a -> a, (k1, k2) -> k1));
  491. if (!chongFuYuanLiuShuiMap.isEmpty()) {
  492. List<ZyDetailCharge> chongFuTuiFeiZhenShu = dao.getZhenShuLiuShui(inpatientNo, admissTimes, ledger, chongFuYuanLiuShuiMap.keySet());
  493. List<Integer> xuYaoChongZhiLiuShui = new ArrayList<>();
  494. if (ListUtil.notBlank(chongFuTuiFeiZhenShu)) {
  495. for (ZyDetailCharge zyDetailCharge : chongFuTuiFeiZhenShu) {
  496. ZyDetailCharge zy = chongFuYuanLiuShuiMap.get(zyDetailCharge.getDetailSn());
  497. if (BigUtils.bigXiaoYu(zyDetailCharge.getChargeFee(), zy.getChargeFee().negate())) {
  498. xuYaoChongZhiLiuShui.add(zyDetailCharge.getDetailSn());
  499. }
  500. }
  501. }
  502. // 这里更新
  503. if (ListUtil.notBlank(xuYaoChongZhiLiuShui)) {
  504. dao.chongFuTuiFeiChongZhi(inpatientNo, admissTimes, ledger, xuYaoChongZhiLiuShui);
  505. }
  506. }
  507. // 这个是判断 trans_flag_yb = 2 费用相加 不为 0 的 就重置一下
  508. if (!BigUtils.dengYu(dao.zhenFuXingDiFeiYong(inpatientNo, admissTimes, ledger), 0)) {
  509. dao.chongXingZhengFuXiangDi(inpatientNo, admissTimes, ledger);
  510. }
  511. }
  512. public List<String> huoQuBingFangDeKeShi(String deptCode) {
  513. if (getRoleCode().getData().contains(1) || getRoleCode().getData().contains(8) || StringUtil.isBlank(deptCode)) {
  514. return new ArrayList<>();
  515. }
  516. List<String> keShiDaiMa = dao.bingFangSuoSuKeShi(deptCode);
  517. if (ListUtil.isBlank(keShiDaiMa)) {
  518. keShiDaiMa.add(deptCode);
  519. }
  520. return keShiDaiMa;
  521. }
  522. /**
  523. * 这里的住院号是没有 处理过得
  524. *
  525. * @param inpatientNo 住院号
  526. * @return 返回病人基本信息
  527. */
  528. public ZyActpatient huoQuHuanZheXinXi(String inpatientNo) {
  529. if (StringUtil.isBlank(inpatientNo)) {
  530. throw new BizException(ExceptionEnum.NULL_POINTER, "住院号为空。");
  531. }
  532. ZyActpatient zyActpatient = dao.getHuanZheJiBenXinXi(inpatientNo);
  533. if (zyActpatient == null) {
  534. throw new BizException(ExceptionEnum.NULL_POINTER, "没有查询到患者的基本信息。");
  535. }
  536. zyActpatient.setInfantFlag(getInfantFlag(zyActpatient.getInpatientNo()));
  537. zyActpatient.setInpatientNo(getInpatientNo(zyActpatient.getInpatientNo()));
  538. return zyActpatient;
  539. }
  540. /**
  541. * 获取麻醉方式
  542. *
  543. * @return 返回数据
  544. */
  545. public ResultVo<List<GetDropdownBox>> maZuiFangShi() {
  546. return ResultVoUtil.success(dao.maZuiFangShi());
  547. }
  548. public Integer huoQuJianYanJianChaXuHao() {
  549. dao.jianYanJianChaSuo();
  550. Integer xuHao = dao.jianYanJianChaXuHao() + 1;
  551. dao.genXingJianYanJianChaXuHao(xuHao);
  552. return xuHao;
  553. }
  554. public Integer huoQuShouShuHao() {
  555. dao.suoZhuShouShu();
  556. Integer index = dao.shouShuXuHao() + 1;
  557. dao.genXingShouShuXuHao(index);
  558. return index;
  559. }
  560. public void huanZheJieSuan(String patNo, Integer times) {
  561. if (StringUtil.isBlank(patNo) || times == null) {
  562. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "住院号不能为空。");
  563. }
  564. patNo = getInpatientNo(patNo);
  565. Integer settleType = dao.jieSuanXinXi(patNo, times);
  566. if (settleType == null) {
  567. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者结算信息。");
  568. }
  569. if (settleType == 1) {
  570. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "患者已经结算无法进行操作了。");
  571. }
  572. }
  573. /**
  574. * 药品限制
  575. *
  576. * @param listCode 药品的编码以及规格 做成code
  577. * @return 返回提示
  578. */
  579. public String yaoPinXianZhi(List<String> listCode, boolean delFlag) {
  580. StringBuilder sb = new StringBuilder();
  581. QueryWrapper<?> qw = new QueryWrapper<>();
  582. qw.in("rtrim(code) + rtrim(serial)", listCode);
  583. Map<String, YaoPinXiangMu> map = dao.huoQuYaoPinPiPeiXinXi(qw).stream().collect(Collectors.toMap(YaoPinXiangMu::getZdCode, a -> a, (k1, k2) -> k1));
  584. return yaoPingXiangMuXianZhi(map, sb, "药品", delFlag);
  585. }
  586. public String xiangMuXianZhi(List<String> listCode, boolean delFlag) {
  587. Map<String, YaoPinXiangMu> map = dao.huoQuXiangMuXinXi(listCode).stream().collect(Collectors.toMap(YaoPinXiangMu::getZdCode, a -> a, (k1, k2) -> k1));
  588. StringBuilder sb = new StringBuilder();
  589. return yaoPingXiangMuXianZhi(map, sb, "项目", delFlag);
  590. }
  591. @NotNull
  592. public String yaoPingXiangMuXianZhi(Map<String, YaoPinXiangMu> map, StringBuilder sb, String name, boolean delFlag) {
  593. for (YaoPinXiangMu item : map.values()) {
  594. if (delFlag && item.getDelFlag() == 1) {
  595. sb.append(cuoWuXinXi(item.getZdCode(), "00".equals(item.getSerial().trim()) ? "医嘱名:" + item.getName() + " 项目名:" + item.getZdName() : "" + item.getName(), name + "已被停用"));
  596. }
  597. if (StringUtil.isBlank(item.getNationalCode()) && !delFlag) {
  598. sb.append(cuoWuXinXi(item.getZdCode(), "00".equals(item.getSerial().trim()) ? "医嘱名:" + item.getName() + " 项目名:" + item.getZdName() : "" + item.getName(), name + "没有匹配医保编码"));
  599. }
  600. }
  601. return sb.toString();
  602. }
  603. public String cuoWuXinXi(String code, String name, String xinXi) {
  604. return "编码:<span style='color:teal'>【" + code + "】</span><br>" + "名称:<span style='color:#a5673f'>【" + name + "】 </span><br>" + "<span style='color:red'>" + xinXi + "</span><br>";
  605. }
  606. public void sendDoctorNotification(XinZhenYiZhu huanZheXinXi, String content, String title, String sender, List<String> userCodeList) {
  607. sendDoctorNotification(huanZheXinXi, Collections.singletonList(content), title, sender, userCodeList);
  608. }
  609. public void faSongXiaoXi(XinZhenYiZhu huanZheXinXi, String content, String title, String userCode) {
  610. List<String> huShiBianMa = dao.huoQuHuanZheBingFangDeHuShi(huanZheXinXi.getDeptCode());
  611. sendDoctorNotification(huanZheXinXi, Collections.singletonList(content), title, userCode, huShiBianMa);
  612. }
  613. /**
  614. * @param huanZheXinXi 患者信息
  615. * @param content 内容
  616. * @param title 标题
  617. * @param userCode 发送人id
  618. */
  619. public void faSongXiaoXi(XinZhenYiZhu huanZheXinXi, List<String> content, String title, String userCode) {
  620. List<String> huShiBianMa = dao.huoQuHuanZheBingFangDeHuShi(huanZheXinXi.getDeptCode());
  621. sendDoctorNotification(huanZheXinXi, content, title, userCode, huShiBianMa);
  622. }
  623. /**
  624. * @param huanZheXinXi 患者信息
  625. * @param content 内容
  626. * @param title 标题
  627. * @param sender 发送人 TokenUtil.getInstance().getTokenUserId() 不能使用这个因为用的 异步的方法 会导致 tokenUtil.getTokenUserId() 为 99999
  628. * @param userCodeList 接收方
  629. */
  630. @Async
  631. public void sendDoctorNotification(XinZhenYiZhu huanZheXinXi, List<String> content, String title, String sender, List<String> userCodeList) {
  632. int count = content.size();
  633. // 发送通知类
  634. List<SocketMessage> socketMessage1 = new ArrayList<>();
  635. List<SocketMessage> socketMessage2 = new ArrayList<>();
  636. for (String s : content) {
  637. SocketMessage faSongNeiRong = new SocketMessage();
  638. faSongNeiRong.setSender(sender);
  639. faSongNeiRong.setContent(s);
  640. // 雪花算法
  641. faSongNeiRong.setId(SnowFlakeId.instance().nextId());
  642. faSongNeiRong.setPatId(huanZheXinXi.getInpatientNo() + "_" + huanZheXinXi.getAdmissTimes());
  643. faSongNeiRong.setTitle(title);
  644. socketMessage1.add(faSongNeiRong);
  645. for (String huShi : userCodeList) {
  646. SocketMessage jieShouFang = new SocketMessage();
  647. jieShouFang.setMsgId(faSongNeiRong.getId());
  648. jieShouFang.setSender(faSongNeiRong.getSender());
  649. jieShouFang.setReceiver(huShi);
  650. socketMessage2.add(jieShouFang);
  651. }
  652. }
  653. List<List<SocketMessage>> fenGeFaSongFang = ListUtils.partition(socketMessage1, 20);
  654. List<List<SocketMessage>> fenGeJieShouFang = ListUtils.partition(socketMessage2, 20);
  655. SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  656. PublicDao mapper = sqlSession.getMapper(PublicDao.class);
  657. for (List<SocketMessage> item : fenGeFaSongFang) {
  658. mapper.chaRuTongZhiXinXi(item);
  659. }
  660. for (List<SocketMessage> item : fenGeJieShouFang) {
  661. mapper.chaRuJieShouShuJu(item);
  662. }
  663. try {
  664. sqlSession.commit();
  665. } finally {
  666. sqlSession.close();
  667. }
  668. JSONObject json = new JSONObject();
  669. UserInfo userInfo = userCache.get(sender);
  670. json.put("avatar", userInfo.getAvatar());
  671. json.put("deptName", userInfo.getDeptName());
  672. json.put("name", userInfo.getName());
  673. json.put("msg", "患者:【" + huanZheXinXi.getName() + "】" + "新增数据:" + count + "条");
  674. json.put("title", title);
  675. json.put("count", count);
  676. String msgContent = SocketMsg.socketVo(Message.AVATAR_NOTIFICATION, json);
  677. socketService.sendUserListMessage(new SendUserList(userCodeList, msgContent));
  678. }
  679. public ResultVo<String> makePyCode(String tableName, String idColumn, String nameColumn, String pyColumn) {
  680. List<CodeName> list = dao.originalList(tableName, idColumn, nameColumn, pyColumn);
  681. if (null == list || list.isEmpty()) {
  682. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有需要更改的数据。");
  683. }
  684. for (CodeName item : list) {
  685. String pycode = PingYinUtils.pyShouZiMuDaXie(item.getName());
  686. dao.updatePycode(tableName, idColumn, item.getCode(), pyColumn, pycode);
  687. log.info("修复:{},{},{}", item.getCode(), item.getName(), pycode);
  688. }
  689. return ResultVoUtil.success("修复拼音码成功,共修复 " + list.size() + " 条。");
  690. }
  691. public ResultVo<List<GetDropdownBox>> getAllergens(String name) {
  692. return ResultVoUtil.success(dao.getAllergens(StringUtil.isContainChinese(name)));
  693. }
  694. public ResultVo<List<PatientAllergenInfo>> getPatientAllergens(String patNo) {
  695. return ResultVoUtil.success(dao.getPatientAllergens(patNo));
  696. }
  697. public ResultVo<Boolean> whetherThePatientHasAllergens(String PatNo) {
  698. return ResultVoUtil.success(dao.whetherThePatientHasAllergens(PatNo) > 0);
  699. }
  700. public ResultVo<Integer> newPatientAllergens(String patNo, String allergenCode, int allergenType) {
  701. if (StringUtil.isBlank(patNo)) {
  702. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有患者住院号");
  703. }
  704. PatientAllergenInfo info = new PatientAllergenInfo();
  705. info.setAllergenCode(allergenCode);
  706. info.setPatNo(patNo);
  707. info.setType(allergenType);
  708. dao.newPatientAllergens(info);
  709. return ResultVoUtil.success(info.getId());
  710. }
  711. public ResultVo<String> removePatientAllergens(Integer id) {
  712. dao.removePatientAllergens(id);
  713. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
  714. }
  715. /**
  716. * @param name 名称
  717. * @return 获取药品信息
  718. */
  719. public ResultVo<List<GetDropdownBox>> getDrugInfo(String name) {
  720. return ResultVoUtil.success(dao.getDrugInfo(StringUtil.isContainChinese(name)));
  721. }
  722. public ResultVo<List<GetDropdownBox>> getBldCat(String name) {
  723. return ResultVoUtil.success(dao.getBldCat(StringUtil.isContainChinese(name)));
  724. }
  725. /**
  726. * 获取转科列表
  727. *
  728. * @return
  729. */
  730. public ResultVo<List<ZkList>> getTheTransferList() {
  731. List<ZkList> list = dao.getTheTransferList();
  732. for (ZkList zkList : list) {
  733. zkList.setValue(JSON.toJSONString(zkList));
  734. }
  735. return ResultVoUtil.success(list);
  736. }
  737. @Data
  738. @AllArgsConstructor
  739. public static class IntCodeName {
  740. private Integer code;
  741. private String name;
  742. }
  743. public ResultVo<Map<String, Object>> getPeopleToFillInInformation() throws InvocationTargetException, IllegalAccessException {
  744. Map<String, Object> map = new HashMap<>(Capacity.EIGHT);
  745. map.put("restrictedDrugLevels", EnumToJson.toJson(RestrictedDrugLevels.values()));
  746. map.put("ysjbData", EnumToJson.toJson(Ysjb.values()));
  747. map.put("deptData", getDept().getData());
  748. map.put("empPosition", dao.getEmpPosition());
  749. map.put("empInmark", dao.getEmpInmark());
  750. map.put("zdIfcadre", dao.getZdIfcadre());
  751. map.put("zdEmpTitle", dao.getZdEmpTitle());
  752. map.put("mzyZdChargeType", dao.getMzyZdChargeType());
  753. List<IntCodeName> list = new ArrayList<IntCodeName>() {{
  754. add(new IntCodeName(1, "非限制"));
  755. add(new IntCodeName(2, "限制"));
  756. }};
  757. map.put("doctorYpZl", list);
  758. return ResultVoUtil.success(map);
  759. }
  760. public ResultVo<Boolean> idVerification(String idCard) {
  761. return ResultVoUtil.success(IdCardUtil.isValidatedIdCard(idCard));
  762. }
  763. public Integer getPersonnelCode() {
  764. dao.lockThePersonnelCodeTable();
  765. Integer code = dao.getPersonnelCode();
  766. dao.updateStaffCodeTable(code);
  767. return code;
  768. }
  769. public ResultVo<String> sendMessage(SendMessageParam param) {
  770. settingsDao.insertNewMessage(SnowFlakeId.instance().nextId(), param.getMessage());
  771. JSONObject obj = new JSONObject();
  772. obj.put("message", param.getMessage());
  773. if (null != param.getRefreshDelay()) {
  774. int delay = param.getRefreshDelay() * 1000;
  775. obj.put("refreshDelay", delay);
  776. }
  777. String msgContent = SocketMsg.socketVo(Message.SYSTEM_NOTIFICATION, obj);
  778. ApiMessageBody messageBody = new ApiMessageBody(msgContent);
  779. socketService.sendMessageToAll(messageBody);
  780. log.info("发送全体消息 => 操作员:{},消息体:{}", TokenUtil.getInstance().getTokenUserId(), obj);
  781. return ResultVoUtil.success();
  782. }
  783. public void sendSystemAnnouncement() {
  784. Map<String, String> map = extraCache.getMessage();
  785. JSONObject obj = new JSONObject();
  786. obj.put("data", map);
  787. String msgContent = SocketMsg.socketVo(Message.SYSTEM_ANNOUNCEMENT, obj);
  788. ApiMessageBody messageBody = new ApiMessageBody(msgContent);
  789. socketService.sendMessageToAll(messageBody);
  790. }
  791. /**
  792. * @description: 查询有住院的科室
  793. * @author: lihong
  794. * @date: 2022/12/26 16:58
  795. * @return: thyyxxk.webserver.entity.ResultVo<java.util.List < thyyxxk.webserver.entity.datamodify.GetDropdownBox>>
  796. **/
  797. public ResultVo<List<GetDropdownBox>> getZhuYuanDept() {
  798. return ResultVoUtil.success(dao.getZhuYuanDept());
  799. }
  800. @Async
  801. public void orderRecord(BigDecimal orderCode, String userCode) {
  802. if (orderCode == null) {
  803. return;
  804. }
  805. if (dao.selectRecordByOrderNo(orderCode) > 0) {
  806. return;
  807. }
  808. dao.insertOrderNoRecord(orderCode, userCode);
  809. }
  810. public ResultVo<UserInfo> getUserInfoByCode(String code) {
  811. return ResultVoUtil.success(userCache.get(code));
  812. }
  813. public ZyPatientInfo getPatInfo(String patNo, Integer times) {
  814. ZyPatientInfo p = dao.queryPatientInfo(patNo, times, "zy_actpatient");
  815. if (p == null) {
  816. p = dao.queryPatientInfo(patNo, times, "zy_inactpatient");
  817. }
  818. return p;
  819. }
  820. public ResultVo<JSONObject> getUserConfigByCode(String code) {
  821. String config = dao.getUserConfigByCode(code);
  822. return ResultVoUtil.success(StringUtil.isBlank(config) ? new JSONObject() : JSONObject.parseObject(config));
  823. }
  824. public ResultVo<String> setUserConfigByCode(JSONObject config) {
  825. dao.setUserConfigByCode(TokenUtil.getInstance().getTokenUserId(), JSON.toJSONString(config));
  826. return ResultVoUtil.success();
  827. }
  828. public ResultVo<String> refreshUserInfo(String code) {
  829. userCache.refreshCache(code);
  830. return ResultVoUtil.success();
  831. }
  832. public ResultVo<List<ItemDrug>> getItemDrug(String code) {
  833. return ResultVoUtil.success(dao.getItemDrug(StringUtil.isContainChinese(code)));
  834. }
  835. public Set<String> getUserDeptList(String code) {
  836. Set<String> deptList;
  837. UserInfo userInfo = userCache.get(code);
  838. if (userInfo.getDeptCode().startsWith("8")) {
  839. deptList = dao.chaXunZhiZXinKeShi(userInfo.getDeptCode());
  840. deptList.add(userInfo.getDeptCode());
  841. } else {
  842. deptList = getDept(true, userInfo);
  843. }
  844. return deptList;
  845. }
  846. public Set<String> getUserDeptList() {
  847. return getUserDeptList(TokenUtil.getInstance().getTokenUserId());
  848. }
  849. public static <T> String listToSqlIn(Collection<T> collection) {
  850. if (collection == null || collection.isEmpty()) {
  851. return "('')";
  852. }
  853. Set<T> uniqueSet = new HashSet<>(collection);
  854. StringBuilder sb = new StringBuilder("(");
  855. for (T item : uniqueSet) {
  856. if (item instanceof String) {
  857. sb.append("'").append(item).append("',");
  858. } else {
  859. sb.append(item).append(",");
  860. }
  861. }
  862. sb.deleteCharAt(sb.length() - 1);
  863. sb.append(")");
  864. return sb.toString();
  865. }
  866. }