SignPatientLabelService.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.yihu.wlyy.service.app.label;
  2. import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
  3. import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelLog;
  4. import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
  5. import com.yihu.wlyy.repository.doctor.SignPatientLabelLogDao;
  6. import com.yihu.wlyy.service.BaseService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import java.util.ArrayList;
  11. import java.util.Date;
  12. import java.util.List;
  13. /**
  14. * 标签服务类
  15. * <p>
  16. * Created by lyr on 2016/10/9.
  17. */
  18. @Service
  19. @Transactional
  20. public class SignPatientLabelService extends BaseService {
  21. @Autowired
  22. SignPatientLabelDao labelDao;
  23. @Autowired
  24. SignPatientLabelLogDao labelLogDao;
  25. /**
  26. * 新增自定义标签
  27. *
  28. * @param lableName 标签名称
  29. * @param creator 创建人
  30. * @param teamCode 所属团队
  31. * @return
  32. */
  33. public SignPatientLabel addLabel(String lableName, String creator, long teamCode) {
  34. SignPatientLabel label = new SignPatientLabel();
  35. label.setLabelCode(getCode());
  36. label.setLabelName(lableName);
  37. label.setLabelType("4");
  38. label.setIsSystem(1);
  39. label.setCreator(creator);
  40. label.setTeamCode(teamCode);
  41. label.setStatus(1);
  42. label.setCzrq(new Date());
  43. return labelDao.save(label);
  44. }
  45. /**
  46. * 修改某个自定义标签
  47. *
  48. * @param labelCode 标签code
  49. * @param newName 新名称
  50. * @return
  51. */
  52. public int modifyLabel(String labelCode, String newName, String modifyBy) {
  53. SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1);
  54. if (label == null) {
  55. // 标签不存在
  56. return -1;
  57. }
  58. if (label.getIsSystem() == 1) {
  59. // 系统标签不能修改
  60. return -2;
  61. }
  62. SignPatientLabelLog log = new SignPatientLabelLog();
  63. log.setLabelCode(labelCode);
  64. log.setOldName(label.getLabelName());
  65. log.setNewName(newName);
  66. log.setModifyType(1);
  67. log.setModifyBy(modifyBy);
  68. log.setCzrq(new Date());
  69. label.setLabelName(newName);
  70. label.setCzrq(new Date());
  71. labelLogDao.save(log);
  72. return 1;
  73. }
  74. /**
  75. * 删除某个自定义标签
  76. *
  77. * @param labelCode 标签code
  78. * @return
  79. */
  80. public int deleteLabel(String labelCode, String modifyBy) {
  81. SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1);
  82. if (label == null) {
  83. // 标签不存在
  84. return -1;
  85. }
  86. if (label.getIsSystem() == 1) {
  87. // 系统标签不能删除
  88. return -2;
  89. }
  90. SignPatientLabelLog log = new SignPatientLabelLog();
  91. log.setLabelCode(labelCode);
  92. log.setModifyType(2);
  93. log.setModifyBy(modifyBy);
  94. log.setCzrq(new Date());
  95. label.setStatus(0);
  96. label.setCzrq(new Date());
  97. labelLogDao.save(log);
  98. return 1;
  99. }
  100. /**
  101. * 查询某个团队的标签
  102. *
  103. * @param teamCode 团队code
  104. * @return
  105. */
  106. public List<SignPatientLabel> getTeamAllLabels(long teamCode) {
  107. List<SignPatientLabel> labels = new ArrayList<>();
  108. // 非自定义系统标签
  109. List<SignPatientLabel> systemLabels = labelDao.findSystemLabels();
  110. if (systemLabels.size() > 0) {
  111. labels.addAll(systemLabels);
  112. }
  113. // 自定义标签
  114. List<SignPatientLabel> customLabels = labelDao.findCustomLabels(teamCode);
  115. if (customLabels.size() > 0) {
  116. labels.addAll(customLabels);
  117. }
  118. return labels;
  119. }
  120. /**
  121. * 查询某个团队的自定义标签
  122. *
  123. * @param teamCode 团队code
  124. * @return
  125. */
  126. public List<SignPatientLabel> getLabelsByTypeAndTeam(String labelType, long teamCode) {
  127. List<SignPatientLabel> labels = new ArrayList<>();
  128. if (labelType.equals("4")) {
  129. // 自定义标签
  130. labels = labelDao.findCustomLabels(teamCode);
  131. } else {
  132. labels = labelDao.findByLabelTypeAndStatus(labelType, 1);
  133. }
  134. return labels;
  135. }
  136. /**
  137. * 查询某个标签
  138. *
  139. * @param labelCode 标签code
  140. * @param labelType 标签类型
  141. * @return
  142. */
  143. public SignPatientLabel getLabelByCodeAndType(String labelCode, String labelType) {
  144. return labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode,labelType,1);
  145. }
  146. }