FeiYongJieShouChongSuan.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package thyyxxk.webserver.scheduled;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.aspectj.lang.annotation.Pointcut;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.scheduling.annotation.Scheduled;
  6. import org.springframework.stereotype.Component;
  7. import thyyxxk.webserver.dao.his.scheduled.JieShouFeiYongDao;
  8. import thyyxxk.webserver.entity.inpatient.patient.Patient;
  9. import thyyxxk.webserver.service.PublicServer;
  10. import thyyxxk.webserver.service.inpatient.PatientService;
  11. import javax.annotation.PostConstruct;
  12. import javax.validation.constraints.Positive;
  13. import java.util.List;
  14. /**
  15. * <p>
  16. * 描述: 费用接受重算
  17. * </p>
  18. *
  19. * @author xc
  20. * @date 2021-12-21 16:37
  21. */
  22. @Slf4j
  23. @Component
  24. public class FeiYongJieShouChongSuan {
  25. private final JieShouFeiYongDao dao;
  26. private final PatientService patientService;
  27. private final PublicServer publicServer;
  28. @Value("${execute-scheduled}")
  29. private Boolean executeScheduled;
  30. public FeiYongJieShouChongSuan(JieShouFeiYongDao dao, PatientService patientService, PublicServer publicServer) {
  31. this.dao = dao;
  32. this.patientService = patientService;
  33. this.publicServer = publicServer;
  34. }
  35. /**
  36. * 费用接受重算
  37. */
  38. @Scheduled(cron = "0 30 23 * * ?")
  39. public void jieShouFeiYong() {
  40. // 每天 23 点 执行
  41. if (executeScheduled) {
  42. List<Patient> xuYaoJieShouDeFeiYong = dao.xuYaoJieShouFeiYong();
  43. for (Patient item : xuYaoJieShouDeFeiYong) {
  44. try {
  45. if (item.getLedgerSn() == null) {
  46. item.setLedgerSn(publicServer.getLedgerSn(item.getInpatientNo(), item.getAdmissTimes()));
  47. }
  48. patientService.receiveAndRecalculateCost(item);
  49. log.info("费用接受成功==>住院号:{},住院次数:{},账页号:{} ", item.getInpatientNo(), item.getAdmissTimes(), item.getLedgerSn());
  50. } catch (Exception e) {
  51. log.info("费用接受失败==>住院号:{},住院次数:{},账页号:{},错误信息:{}", item.getInpatientNo(), item.getAdmissTimes(), item.getLedgerSn(), getExceptionAllinformation(e));
  52. e.printStackTrace();
  53. }
  54. }
  55. }
  56. }
  57. public static String getExceptionAllinformation(Exception ex) {
  58. StringBuilder sOut = new StringBuilder();
  59. StackTraceElement[] trace = ex.getStackTrace();
  60. for (StackTraceElement s : trace) {
  61. sOut.append("\tat ").append(s).append("\r\n");
  62. }
  63. return sOut.toString();
  64. }
  65. @Scheduled(cron = "59 59 23 * * ?")
  66. public void chongZhiYaoDanHao() {
  67. if (executeScheduled) {
  68. dao.chongZhiYaoDanHao();
  69. }
  70. }
  71. }