DismissService.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package thyyxxk.webserver.service.yibao;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import thyyxxk.webserver.config.exception.BizException;
  7. import thyyxxk.webserver.config.exception.ExceptionEnum;
  8. import thyyxxk.webserver.dao_his.yibao.DismissDao;
  9. import thyyxxk.webserver.pojo.ResultVo;
  10. import thyyxxk.webserver.pojo.dictionary.PureCodeName;
  11. import thyyxxk.webserver.pojo.yibao.dismiss.ActOrderDetail;
  12. import thyyxxk.webserver.pojo.yibao.dismiss.ActOrderGroup;
  13. import thyyxxk.webserver.pojo.yibao.dismiss.ReceiptFeePojo;
  14. import thyyxxk.webserver.pojo.yibao.dismiss.YbSettleFeePojo;
  15. import thyyxxk.webserver.pojo.yibao.patient.OverviewPojo;
  16. import thyyxxk.webserver.pojo.yibao.patient.PatientPojo;
  17. import thyyxxk.webserver.utils.*;
  18. import java.math.BigDecimal;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import static thyyxxk.webserver.utils.YibaoHttpUtil.equalizeUpload;
  24. import static thyyxxk.webserver.utils.YibaoHttpUtil.httpPost;
  25. @Slf4j
  26. @Service
  27. public class DismissService {
  28. private final DismissDao dao;
  29. @Autowired
  30. public DismissService(DismissDao dao) {
  31. this.dao = dao;
  32. }
  33. public ResultVo<List<ActOrderGroup>> getActOrders(String inpatientNo, Integer admissTimes) {
  34. final Integer ledgerSn = dao.getLedgerSn(inpatientNo, admissTimes);
  35. if (ledgerSn < 1) {
  36. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "获取帐页数失败。");
  37. }
  38. dao.acceptFeeStepOne(inpatientNo, admissTimes);
  39. if(dao.acceptFeeStepTwo(inpatientNo, admissTimes) < 0) {
  40. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "接收费用失败。");
  41. }
  42. if (dao.getOrderList(inpatientNo, admissTimes) < 0) {
  43. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询医嘱失败。");
  44. }
  45. List<ActOrderDetail> allOrders = dao.getActOrderDetail();
  46. if (allOrders == null) {
  47. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询医嘱失败。");
  48. }
  49. return analyzeActOrders(allOrders);
  50. }
  51. private ResultVo<List<ActOrderGroup>> analyzeActOrders(List<ActOrderDetail> allOrders) {
  52. HashMap<String, ActOrderGroup> temp = new HashMap<>();
  53. for (ActOrderDetail item : allOrders) {
  54. String actOrderNo = item.getActOrderNo();
  55. String fee = item.getChargeFee();
  56. if (!temp.containsKey(actOrderNo)) {
  57. ActOrderGroup aModel = new ActOrderGroup(actOrderNo, fee, item.getChargeStatus(), item.getCxFlag());
  58. if (aModel.getList() == null) {
  59. aModel.setList(new ArrayList<>());
  60. }
  61. aModel.getList().add(item);
  62. temp.put(actOrderNo, aModel);
  63. } else {
  64. temp.get(actOrderNo).setFee(DecimalUtil.add(fee, temp.get(actOrderNo).getFee()));
  65. temp.get(actOrderNo).getList().add(item);
  66. }
  67. }
  68. List<ActOrderGroup> list = new ArrayList<>();
  69. for (HashMap.Entry<String, ActOrderGroup> modelEntry : temp.entrySet()) {
  70. list.add(modelEntry.getValue());
  71. }
  72. return ResultVoUtil.success(list);
  73. }
  74. public ResultVo<List<PureCodeName>> calculateForDismiss(PatientPojo param) {
  75. final String inpatientNo = param.getInpatientNo();
  76. final Integer admissTimes = param.getAdmissTimes();
  77. if (param.getDismissFlag() == 1) {
  78. int disActOrderCount = dao.countDisActOrders(inpatientNo, admissTimes);
  79. if (disActOrderCount < 1) {
  80. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  81. exception.setMessage("此患者没有出院医嘱,请检查。");
  82. throw new BizException(exception);
  83. }
  84. if (disActOrderCount > 1) {
  85. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  86. exception.setMessage("此患者的出院医嘱不止一条,请检查。");
  87. throw new BizException(exception);
  88. }
  89. }
  90. if (null == param.getAdmissDate()) {
  91. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  92. exception.setMessage("没有找到入院时间,请重新获取病人信息。");
  93. throw new BizException(exception);
  94. }
  95. Date actOrderDisDate = getDismissDate(param.getDismissFlag(), inpatientNo, admissTimes, param.getZjdzDatetime());
  96. final int ledgerSn = dao.getLedgerSn(inpatientNo, admissTimes);
  97. if (dao.hasUnsettledStepOne(inpatientNo, admissTimes, ledgerSn) < 0) {
  98. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  99. exception.setMessage("获取记账信息失败。");
  100. throw new BizException(exception);
  101. }
  102. if (dao.hasUnsettledStepTwo(inpatientNo, admissTimes) > 0) {
  103. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  104. exception.setMessage("此患者有未结算的记账金额,请联系收费窗口。");
  105. throw new BizException(exception);
  106. }
  107. if (dao.hasNotAccounted(inpatientNo, admissTimes) > 0) {
  108. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  109. exception.setMessage("此患者有未上账金额。");
  110. throw new BizException(exception);
  111. }
  112. if (dao.hasUnreceivedDrugList(inpatientNo, admissTimes) > 0) {
  113. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  114. exception.setMessage("此患者有未接收的药单。");
  115. throw new BizException(exception);
  116. }
  117. if (dao.hasUnreceivedFees(inpatientNo, admissTimes, actOrderDisDate) > 0) {
  118. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  119. exception.setMessage("此患者有未接收的费用。");
  120. throw new BizException(exception);
  121. }
  122. if (dao.hasUnSubmitDrugList(inpatientNo, admissTimes) > 0) {
  123. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  124. exception.setMessage("此患者有未提交的药单。");
  125. throw new BizException(exception);
  126. }
  127. if (dao.hasUntreatedDrugWithdrawalOrder(inpatientNo, admissTimes) > 0) {
  128. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  129. exception.setMessage("此患者有未处理的药品退药单。");
  130. throw new BizException(exception);
  131. }
  132. if (dao.hasUnconfirmedMedicalTech(inpatientNo, admissTimes, actOrderDisDate) > 0) {
  133. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  134. exception.setMessage("此患者有未确认的医技。");
  135. throw new BizException(exception);
  136. }
  137. List<PureCodeName> feeNegativeList = dao.feeOrderNegative(inpatientNo, admissTimes);
  138. if (feeNegativeList.size() > 0) {
  139. return ResultVoUtil.fail(ExceptionEnum.EXIST_NEGATIVE_FEES, "此患者费用清单存在负数。",
  140. feeNegativeList);
  141. }
  142. dao.deleteTemporaryTable(inpatientNo, admissTimes);
  143. final Integer transFlag = param.getDismissFlag() == 1 ? 0 : 2;
  144. if (dao.calculateCost(inpatientNo, admissTimes, ledgerSn, param.getStaffId(), param.getAdmissDate(),
  145. actOrderDisDate, param.getAdmissWard(), param.getAdmissDept(), transFlag) == null) {
  146. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  147. exception.setMessage("费用计算失败。执行zy_cngl_fyjs过程出错。");
  148. throw new BizException(exception);
  149. }
  150. if (dao.hasSettled(inpatientNo, admissTimes, ledgerSn) != 0) {
  151. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  152. exception.setMessage("此患者已存在结算信息。");
  153. throw new BizException(exception);
  154. }
  155. if (dao.hasUncheckedFee(inpatientNo, admissTimes, ledgerSn) > 0) {
  156. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  157. exception.setMessage("此患者有未结账的费用。");
  158. throw new BizException(exception);
  159. }
  160. if (dao.getFeeOffset(inpatientNo, admissTimes, ledgerSn) > 0) {
  161. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  162. exception.setMessage("此患者明细费用与账页费用不一致。");
  163. throw new BizException(exception);
  164. }
  165. String responce = param.getResponceType();
  166. Date lastZjdzDatetime = null;
  167. if (!responce.equals("01")) {
  168. String hisTotalCharge;
  169. if (param.getDismissFlag() == 2) {
  170. lastZjdzDatetime = ledgerSn == 1 ? param.getAdmissDate() :
  171. dao.getLastZjdzDatetime(inpatientNo, admissTimes, ledgerSn - 1);
  172. hisTotalCharge = dao.getTotalChargeForZjdz(inpatientNo, admissTimes, ledgerSn, lastZjdzDatetime, actOrderDisDate);
  173. } else {
  174. hisTotalCharge = dao.getTotalChargeForCyjs(inpatientNo, admissTimes, ledgerSn);
  175. }
  176. ResultVo<Object> resultVo = YibaoHttpUtil.httpPost("preCalculateCost", param, responce);
  177. if (resultVo.getCode() != 200 && resultVo.getCode() != 2002) {
  178. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  179. exception.setMessage(resultVo.getMessage());
  180. throw new BizException(exception);
  181. } else {
  182. HashMap<String, String> obj = FilterUtil.cast(resultVo.getData());
  183. String ybTotalCharge = obj.get("totalCost");
  184. if (DecimalUtil.compare(hisTotalCharge, ybTotalCharge) != 0) {
  185. if (param.getDismissFlag() == 1) {
  186. int count = dao.hasFeeNotUpload(inpatientNo, admissTimes, ledgerSn);
  187. String message = "此患者明细费用与医保中心费用不一致。";
  188. if (count > 0) {
  189. message += "(有未上传的费用【" + count + "】条)";
  190. }
  191. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  192. exception.setMessage(message);
  193. throw new BizException(exception);
  194. } else {
  195. int count = dao.hasFeeNotUploadWithZjdz(param.getInpatientNo(), param.getAdmissTimes(),
  196. lastZjdzDatetime, param.getZjdzDatetime());
  197. if (responce.equals("02")) {
  198. String message = "此患者明细费用与医保中心费用不一致。";
  199. if (count > 0) {
  200. message += "(有未上传的费用【" + count + "】条)";
  201. }
  202. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  203. exception.setMessage(message);
  204. throw new BizException(exception);
  205. }
  206. if (count == 0) {
  207. httpPost("cancelUploadFee", param, param.getResponceType());
  208. }
  209. dao.updateTransFlagForZjdz(inpatientNo, admissTimes, ledgerSn, 1, param.getZjdzDatetime());
  210. OverviewPojo overview = makeOverview(param);
  211. if (responce.equals("04")) {
  212. resultVo = httpPost("uploadFee", overview, responce);
  213. } else {
  214. if (responce.equals("03") || responce.equals("09")) {
  215. resultVo = equalizeUpload("cssyb", "single", null, overview, responce);
  216. } else {
  217. resultVo = equalizeUpload("hnsyb", "single", null, overview, responce);
  218. }
  219. }
  220. dao.updateTransFlagForZjdz(inpatientNo, admissTimes, ledgerSn, 0, param.getZjdzDatetime());
  221. if (resultVo.getCode() != 200 && resultVo.getCode() != 2002) {
  222. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  223. exception.setMessage(resultVo.getMessage());
  224. throw new BizException(exception);
  225. } else {
  226. obj = FilterUtil.cast(resultVo.getData());
  227. ybTotalCharge = obj.get("totalCost");
  228. if (DecimalUtil.compare(hisTotalCharge, ybTotalCharge) != 0) {
  229. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  230. exception.setMessage("此患者明细费用与医保中心费用不一致。");
  231. throw new BizException(exception);
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. return ResultVoUtil.success();
  239. }
  240. private OverviewPojo makeOverview(PatientPojo param) {
  241. OverviewPojo overview = new OverviewPojo();
  242. overview.setStaffId(param.getStaffId());
  243. overview.setInpatientNo(param.getInpatientNo());
  244. overview.setAdmissTimes(param.getAdmissTimes());
  245. overview.setName(param.getName());
  246. overview.setSex(param.getSex());
  247. overview.setBedNo(param.getBedNo());
  248. overview.setResponceType(param.getResponceType());
  249. overview.setSid(param.getSid());
  250. return overview;
  251. }
  252. @Transactional(rollbackFor = Exception.class)
  253. public ResultVo<String> doDismiss(YbSettleFeePojo settleFee) throws BizException {
  254. updateHicNo(settleFee.getInpatientNo());
  255. settleFee.setLedgerSn(dao.getLedgerSn(settleFee.getInpatientNo(), settleFee.getAdmissTimes()));
  256. if (!settleFee.getResponceType().trim().equals("01")) { // 自费病人不进行医保结算
  257. int write;
  258. dao.deleteZyLedgerFileYb(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), settleFee.getLedgerSn());
  259. String cashPay = settleFee.getXjzf();
  260. String fundPay = settleFee.getTczf();
  261. // 如果医院支付为正,则 现金支付 = 现金支付 + 医院支付
  262. if (!settleFee.getHospitalPay().startsWith("-")) {
  263. cashPay = DecimalUtil.add(cashPay, settleFee.getHospitalPay());
  264. }
  265. if (settleFee.getYzsCzdd() == null || settleFee.getYzsCzdd().trim().equals("") ||
  266. settleFee.getYzsCzdd().trim().equals("null")) {
  267. write = dao.writeYbSettleTableStepTwoShort(settleFee.getInpatientNo(), settleFee.getAdmissTimes(),
  268. settleFee.getLedgerSn(), settleFee.getTotalCost(), fundPay, settleFee.getGrzhzf(), settleFee.getDbzf(),
  269. cashPay, settleFee.getFullSelfPay(), settleFee.getPartSelfPay(), settleFee.getHospitalPay());
  270. } else {
  271. write = dao.writeYbSettleTableStepTwoLong(settleFee.getInpatientNo(), settleFee.getAdmissTimes(),
  272. settleFee.getLedgerSn(), settleFee.getTotalCost(), fundPay, settleFee.getGrzhzf(), settleFee.getDbzf(),
  273. cashPay, settleFee.getYzsXjzf(), settleFee.getYzsThbz(), settleFee.getYzsMzjz(),
  274. settleFee.getYzsYyjm(), settleFee.getYzsCzdd(), settleFee.getYzsFplx(), settleFee.getYzsMzlx(),
  275. settleFee.getFullSelfPay(), settleFee.getPartSelfPay(), settleFee.getHospitalPay());
  276. }
  277. if (write < 1) {
  278. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  279. exception.setMessage("写医保结算表失败。");
  280. throw new BizException(exception);
  281. }
  282. }
  283. if (writeReceiptTable(settleFee) < 1) {
  284. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  285. exception.setMessage("写发票表失败。");
  286. throw new BizException(exception);
  287. }
  288. int code = settleFee.getFlag() == 1 ? setHisStatusOut(settleFee) : hisMiddleSettle(settleFee);
  289. if (updateCostStatusToSettled(settleFee) < 1) {
  290. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  291. exception.setMessage("更新费用状态失败。");
  292. throw new BizException(exception);
  293. }
  294. if (code < 1) {
  295. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  296. exception.setMessage("更新操作日志失败。" + code);
  297. throw new BizException(exception);
  298. }
  299. return ResultVoUtil.success();
  300. }
  301. private int writeReceiptTable(YbSettleFeePojo indata) {
  302. if (dao.beforeWriteReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(),
  303. indata.getLedgerSn()) < 1) return -1;
  304. final int infantFlag = dao.selectInfantFlag(indata.getInpatientNo(), indata.getAdmissTimes(),
  305. indata.getLedgerSn()); // =0 无婴儿,>0 有婴儿
  306. final Date dismissDate = getDismissDate(indata.getFlag(), indata.getInpatientNo(), indata.getAdmissTimes(),
  307. indata.getZjdzDatetime());
  308. final Integer transFlag = indata.getFlag() == 1 ? 0 : 2;
  309. final Date admissDate = dao.selectAdmissDate(indata.getInpatientNo(), indata.getAdmissTimes());
  310. final List<ReceiptFeePojo> fees = dao.calculateCost(indata.getInpatientNo(), indata.getAdmissTimes(),
  311. indata.getLedgerSn(), indata.getStaffId(), admissDate, dismissDate, indata.getWardCode(),
  312. indata.getDeptCode(), transFlag);
  313. if (fees == null || fees.isEmpty()) return -1;
  314. String totalCharge = getTotalCharge(fees, false);
  315. if (dao.writeReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(), 1,
  316. admissDate, dismissDate, indata.getWardCode(), indata.getDeptCode(), dismissDate, "01",
  317. indata.getStaffId(), totalCharge, fees.get(0).getChargePercent(), fees.get(1).getChargePercent(),
  318. fees.get(2).getChargePercent(), fees.get(3).getChargePercent(), fees.get(4).getChargePercent(),
  319. fees.get(5).getChargePercent(), fees.get(6).getChargePercent(), fees.get(7).getChargePercent(),
  320. fees.get(8).getChargePercent(), fees.get(9).getChargePercent(), fees.get(10).getChargePercent(),
  321. fees.get(11).getChargePercent(), fees.get(12).getChargePercent(), fees.get(13).getChargePercent(),
  322. fees.get(14).getChargePercent(), fees.get(15).getChargePercent(), fees.get(16).getChargePercent(),
  323. fees.get(17).getChargePercent(), fees.get(18).getChargePercent(), fees.get(19).getChargePercent(),
  324. fees.get(20).getChargePercent(), fees.get(21).getChargePercent(), fees.get(22).getChargePercent(),
  325. fees.get(23).getChargePercent(), fees.get(24).getChargePercent(), fees.get(25).getChargePercent(),
  326. fees.get(26).getChargePercent(), fees.get(27).getChargePercent()) < 1)
  327. return -1;
  328. if (infantFlag > 0) {
  329. totalCharge = getTotalCharge(fees, true);
  330. return dao.writeReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(), 4,
  331. admissDate, dismissDate, indata.getWardCode(), indata.getDeptCode(), dismissDate, "04",
  332. indata.getStaffId(), totalCharge, fees.get(0).getChargeInfant(), fees.get(1).getChargeInfant(),
  333. fees.get(2).getChargeInfant(), fees.get(3).getChargeInfant(), fees.get(4).getChargeInfant(),
  334. fees.get(5).getChargeInfant(), fees.get(6).getChargeInfant(), fees.get(7).getChargeInfant(),
  335. fees.get(8).getChargeInfant(), fees.get(9).getChargeInfant(), fees.get(10).getChargeInfant(),
  336. fees.get(11).getChargeInfant(), fees.get(12).getChargeInfant(), fees.get(13).getChargeInfant(),
  337. fees.get(14).getChargeInfant(), fees.get(15).getChargeInfant(), fees.get(16).getChargeInfant(),
  338. fees.get(17).getChargeInfant(), fees.get(18).getChargeInfant(), fees.get(19).getChargeInfant(),
  339. fees.get(20).getChargeInfant(), fees.get(21).getChargeInfant(), fees.get(22).getChargeInfant(),
  340. fees.get(23).getChargeInfant(), fees.get(24).getChargeInfant(), fees.get(25).getChargeInfant(),
  341. fees.get(26).getChargeInfant(), fees.get(27).getChargeInfant());
  342. }
  343. return 1;
  344. }
  345. private String getTotalCharge(List<ReceiptFeePojo> fees, boolean infant) {
  346. String totalCharge = "0.00";
  347. for (ReceiptFeePojo item : fees) {
  348. totalCharge = mathAdd(totalCharge, infant ? item.getChargeInfant() : item.getChargePercent());
  349. }
  350. return totalCharge;
  351. }
  352. private Date getDismissDate(Integer flag, String inpatientNo, Integer admissTimes, Date zjdzDate) {
  353. return flag == 1 ? dao.selectActOrderDisDate(inpatientNo, admissTimes) : zjdzDate;
  354. }
  355. private int updateCostStatusToSettled(YbSettleFeePojo indata) {
  356. Date date = indata.getFlag() == 1 ? new Date() : indata.getZjdzDatetime();
  357. final int code;
  358. if (indata.getResponceType().equals("01")) {
  359. code = dao.updateZifeiCostStatus(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(),
  360. indata.getWardCode(), indata.getDeptCode(), indata.getStaffId(), date);
  361. } else {
  362. final int hasInfant = dao.hasInfant(indata.getInpatientNo(), indata.getAdmissTimes());
  363. code = hasInfant == 0 ?
  364. dao.updateCostStatusWithoutInfant(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(),
  365. indata.getWardCode(), indata.getDeptCode(), indata.getStaffId(), date, indata.getResponceType()) :
  366. dao.updateCostStatusWithInfant(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(),
  367. indata.getWardCode(), indata.getDeptCode(), indata.getStaffId(), date, indata.getResponceType());
  368. }
  369. if (code < 1) return -1;
  370. return dao.updateZyDetailCharge(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn());
  371. }
  372. private int setHisStatusOut(YbSettleFeePojo indata) {
  373. final Date disDate = dao.selectActOrderDisDate(indata.getInpatientNo(), indata.getAdmissTimes());
  374. if (dao.updateZyActpatient(indata.getInpatientNo(), indata.getAdmissTimes(),
  375. disDate, indata.getStaffId()) < 1) return -1;
  376. dao.deleteZyInactpatient(indata.getInpatientNo(), indata.getAdmissTimes());
  377. if (dao.insertZyInactpatient(indata.getInpatientNo(), indata.getAdmissTimes()) < 1) return -2;
  378. final String inpatientNo1 = indata.getInpatientNo() + "$1";
  379. final String inpatientNo6 = indata.getInpatientNo() + "$6";
  380. dao.updateZyActpatientAgain(inpatientNo1, inpatientNo6, indata.getAdmissTimes(), disDate);
  381. dao.insertZyInactpatientAgain(inpatientNo1, inpatientNo6, indata.getAdmissTimes());
  382. if (dao.updateZyAdt(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getWardCode(), indata.getDeptCode(),
  383. indata.getBedNo(), disDate) < 1) return -3;
  384. if (dao.updateZyBedMi(indata.getInpatientNo(), indata.getAdmissTimes()) < 1) return -4;
  385. if (dao.deleteZyActpatient(indata.getInpatientNo()) < 1) return -5;
  386. dao.deleteZyActpatientAgain(inpatientNo1, inpatientNo6, indata.getAdmissTimes());
  387. return insertNewZyWorkLog(indata);
  388. }
  389. private int insertNewZyWorkLog(YbSettleFeePojo indata) {
  390. final String userName = dao.getOperateName(indata.getStaffId());
  391. return dao.insertNewZyWorkLog(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(),
  392. indata.getWardCode(), indata.getDeptCode(), indata.getStaffId(), userName);
  393. }
  394. private int hisMiddleSettle(YbSettleFeePojo indata) {
  395. indata.setLedgerSn(dao.getLedgerSn(indata.getInpatientNo(), indata.getAdmissTimes()));
  396. int newLedgerSn = indata.getLedgerSn() + 1;
  397. dao.updateTimesBilledByIncreaseOne(indata.getInpatientNo(), indata.getAdmissTimes());
  398. dao.insertNewLedgerFile(indata.getInpatientNo(), indata.getAdmissTimes(), newLedgerSn);
  399. dao.updateFeesLedgerSn(indata.getInpatientNo(), indata.getAdmissTimes(), newLedgerSn,
  400. indata.getLedgerSn(), indata.getZjdzDatetime());
  401. dao.updateZyLedgerFileTotalCharge(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn());
  402. dao.updateZyLedgerFileTotalCharge(indata.getInpatientNo(), indata.getAdmissTimes(), newLedgerSn);
  403. dao.retractYbsf1(indata.getInpatientNo(), indata.getAdmissTimes());
  404. dao.retractYbsf2(indata.getInpatientNo(), indata.getAdmissTimes());
  405. return insertNewZyWorkLog(indata);
  406. }
  407. private String mathAdd(String a, String b) {
  408. BigDecimal d1 = new BigDecimal(a);
  409. BigDecimal d2 = new BigDecimal(b);
  410. return d1.add(d2).toString();
  411. }
  412. private void updateHicNo(String zyh) {
  413. String hicNoNew = dao.getHicNoNew(zyh);
  414. if (null != hicNoNew) {
  415. if (hicNoNew.length() > 16) {
  416. hicNoNew = hicNoNew.substring(0, 16);
  417. }
  418. dao.updateCpy(zyh, hicNoNew);
  419. if (hicNoNew.length() > 10) {
  420. hicNoNew = hicNoNew.substring(0, 10);
  421. }
  422. dao.updateHic(zyh, hicNoNew);
  423. }
  424. }
  425. }