AssistanceApplyService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package com.yihu.ehr.svrinspection.service;
  2. import com.yihu.ehr.query.BaseJpaService;
  3. import com.yihu.ehr.redis.schema.OrgKeySchema;
  4. import com.yihu.ehr.svrinspection.commons.exception.ManageException;
  5. import com.yihu.ehr.svrinspection.dao.AssistanceApplyDao;
  6. import com.yihu.ehr.svrinspection.model.AssistanceApplyModel;
  7. import com.yihu.ehr.util.datetime.DateUtil;
  8. import org.apache.commons.lang.StringUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.util.Date;
  13. /**
  14. * 检验申请 业务类
  15. *
  16. * @author HZY
  17. * @created 2018/11/14 9:21
  18. */
  19. @Transactional
  20. @Service
  21. public class AssistanceApplyService extends BaseJpaService<AssistanceApplyModel, AssistanceApplyDao> {
  22. @Autowired
  23. private AssistanceApplyDao assistanceApplyDao;
  24. @Autowired
  25. private OrgKeySchema orgKeySchema;
  26. public AssistanceApplyModel findById(int id) {
  27. return assistanceApplyDao.findOne(id);
  28. }
  29. public AssistanceApplyModel addApply(AssistanceApplyModel assistanceApplyModel) throws ManageException {
  30. assistanceApplyModel.setCreateTime(new Date());
  31. assistanceApplyModel.setSolutionStatus(-1);
  32. assistanceApplyModel.setIsRead(0);
  33. assistanceApplyModel = assistanceApplyDao.save(assistanceApplyModel);
  34. return assistanceApplyModel;
  35. }
  36. //申请
  37. public AssistanceApplyModel saveOrUpdateApply(AssistanceApplyModel assistanceApplyModel) throws ManageException {
  38. //申请机构名
  39. String applyOrgName = getOrgName(assistanceApplyModel.getApplyOrg());
  40. //处理机构名
  41. String solutionOrgName = getOrgName(assistanceApplyModel.getSolutionOrg());
  42. assistanceApplyModel.setCreateTime(new Date());
  43. //已申请
  44. assistanceApplyModel.setSolutionStatus(0);
  45. assistanceApplyModel.setIsRead(0);
  46. assistanceApplyModel.setApplyOrgName(applyOrgName);
  47. assistanceApplyModel.setSolutionOrgName(solutionOrgName);
  48. assistanceApplyModel = assistanceApplyDao.save(assistanceApplyModel);
  49. return assistanceApplyModel;
  50. }
  51. /**
  52. * 申请处理
  53. *
  54. * @param id 申请记录ID
  55. * @param replyUserId 处理人ID
  56. * @param replyContent 回复内容
  57. * @return
  58. * @throws ManageException
  59. */
  60. public AssistanceApplyModel solutionApply(int id, String replyUserId, String replyContent) throws ManageException {
  61. AssistanceApplyModel applyModel = findById(id);
  62. if (applyModel == null) {
  63. throw new ManageException("申请记录不存在!");
  64. }
  65. applyModel.setSolutionUserId(replyUserId);
  66. applyModel.setSolutionReply(replyContent);
  67. applyModel.setSolutionDate(new Date());
  68. applyModel.setSolutionStatus(1);
  69. assistanceApplyDao.save(applyModel);
  70. return applyModel;
  71. }
  72. /**
  73. * 根据申请状态-获取今日统计量
  74. *
  75. * @param status
  76. * @return
  77. */
  78. public long toDayCount(int status) {
  79. String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
  80. Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  81. Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  82. long todayCount = assistanceApplyDao.countAllBySolutionStatusAndCreateTimeBetween(status, start, end);
  83. return todayCount;
  84. }
  85. /* **************** 基层医疗机构 ********** */
  86. /**
  87. * 通过申请机构 获取检验处理总数
  88. *
  89. * @param applyOrg 申请机构编码
  90. * @param status 处理状态
  91. * @return
  92. */
  93. public long toDayIncreaseByApplyOrg(String applyOrg, int status) {
  94. long count = assistanceApplyDao.countAllByApplyOrgAndSolutionStatus(applyOrg, status);
  95. return count;
  96. }
  97. /**
  98. * 通过申请机构获取 今日已处理/未处理量
  99. *
  100. * @param solutionOrg 申请处理机构
  101. * @return
  102. */
  103. public long toDayCountByApplyOrg(String solutionOrg, int status) {
  104. String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
  105. Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  106. Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  107. long todayCount = assistanceApplyDao.countAllByApplyOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg, status, start, end);
  108. return todayCount;
  109. }
  110. /*************************** 医生端 ************************************/
  111. /**
  112. * 通过处理机构获取 今日新增申请量
  113. *
  114. * @param solutionOrg 申请处理机构
  115. * @return
  116. */
  117. public long toDayIncreaseBySolutionOrg(String solutionOrg) {
  118. String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
  119. Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  120. Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  121. long count = assistanceApplyDao.countAllBySolutionOrgAndCreateTimeBetween(solutionOrg, start, end);
  122. return count;
  123. }
  124. /**
  125. * 通过处理机构获取 今日已处理/未处理量
  126. *
  127. * @param solutionOrg 申请处理机构
  128. * @return
  129. */
  130. public long toDayCountBySolutionOrg(String solutionOrg, int status) {
  131. String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
  132. Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  133. Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
  134. long todayCount = assistanceApplyDao.countAllBySolutionOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg, status, start, end);
  135. return todayCount;
  136. }
  137. /**
  138. * 申请撤回
  139. *
  140. * @param id 申请记录id
  141. * @param status 申请记录状态
  142. * @return
  143. * @throws ManageException
  144. */
  145. public AssistanceApplyModel retractApply(int id, int status) throws ManageException {
  146. AssistanceApplyModel applyModel = findById(id);
  147. if (applyModel == null) {
  148. throw new ManageException("申请记录不存在!");
  149. }
  150. applyModel.setSolutionStatus(status);
  151. assistanceApplyDao.save(applyModel);
  152. return applyModel;
  153. }
  154. /**
  155. *获取机构名称redis
  156. * @return
  157. */
  158. public String getOrgName(String key) {
  159. if (StringUtils.isEmpty(key)) {
  160. return "";
  161. }else {
  162. return orgKeySchema.get(key);
  163. }
  164. }
  165. }