ServiceNumberService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package thyyxxk.webserver.service.dictionary;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.stereotype.Service;
  4. import thyyxxk.webserver.config.exception.ExceptionEnum;
  5. import thyyxxk.webserver.dao.his.dictionary.ServiceNumberDao;
  6. import thyyxxk.webserver.dao.his.dictionary.ZdHealthEducationDao;
  7. import thyyxxk.webserver.dao.his.dictionary.ZdHealthEducationTypeDao;
  8. import thyyxxk.webserver.entity.ResultVo;
  9. import thyyxxk.webserver.entity.dictionary.CodeName;
  10. import thyyxxk.webserver.entity.dictionary.ZdHealthEducation;
  11. import thyyxxk.webserver.entity.dictionary.ZdHealthEducationType;
  12. import thyyxxk.webserver.utils.ResultVoUtil;
  13. import thyyxxk.webserver.utils.StringUtil;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Optional;
  18. /**
  19. * @ClassName ServiceNumberService
  20. * @Author hsh
  21. * @Date 2024/3/22 8:54
  22. * @Version 1.0
  23. * @Description 服务号相关字典
  24. **/
  25. @Service
  26. @Slf4j
  27. public class ServiceNumberService {
  28. private final ServiceNumberDao dao;
  29. private final ZdHealthEducationDao healthEducationDao;
  30. private final ZdHealthEducationTypeDao zdHealthEducationTypeDao;
  31. public ServiceNumberService(ServiceNumberDao dao, ZdHealthEducationDao healthEducationDao,
  32. ZdHealthEducationTypeDao zdHealthEducationTypeDao) {
  33. this.dao = dao;
  34. this.healthEducationDao = healthEducationDao;
  35. this.zdHealthEducationTypeDao = zdHealthEducationTypeDao;
  36. }
  37. public ResultVo<Map<String, List<CodeName>>> selectServiceNumberDict(){
  38. Map<String, List<CodeName>> map = new HashMap<>();
  39. List<CodeName> list = dao.selectHealthEducationType();
  40. map.put("HEType", list);
  41. return ResultVoUtil.success(map);
  42. }
  43. public ResultVo<List<ZdHealthEducation>> selectHealthEducation(){
  44. return ResultVoUtil.success(healthEducationDao.selectHealthEducation());
  45. }
  46. public ResultVo<Map<String, Object>> saveHealthEducation(ZdHealthEducation zdHealthEducation){
  47. if(null == zdHealthEducation){
  48. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "健康教育字典信息不存在,请检查!");
  49. }
  50. Map<String, Object> resultMap = new HashMap<>();
  51. String code = zdHealthEducation.getCode();
  52. ZdHealthEducation healthEducation = healthEducationDao.selectHealthEducationByCode(code);
  53. // 设置健康教育类型名称
  54. List<CodeName> he = dao.selectHealthEducationType();
  55. Optional<CodeName> s = he.stream().filter(codeName -> codeName.getCode().equals(zdHealthEducation.getType())).findFirst();
  56. s.ifPresent(codeName -> zdHealthEducation.setTypeName(codeName.getName()));
  57. int num;
  58. try{
  59. if(null != healthEducation){
  60. num = healthEducationDao.updateHealthEducationByCode(zdHealthEducation);
  61. } else {
  62. String maxCode = healthEducationDao.selectMaxCodeOfHealthEducation();
  63. String newCode;
  64. if(maxCode.startsWith("0")){
  65. int number = Integer.parseInt(maxCode.replace("0", ""));
  66. if(number == 9){
  67. newCode = (number + 1) + "";
  68. } else {
  69. newCode = "0" + (number + 1);
  70. }
  71. } else {
  72. int number = Integer.parseInt(maxCode);
  73. newCode = (number + 1) + "";
  74. }
  75. zdHealthEducation.setCode(newCode);
  76. num = healthEducationDao.insert(zdHealthEducation);
  77. }
  78. if(num == 0){
  79. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育字典信息失败!");
  80. }
  81. resultMap.put("cg", "保存健康教育字典信息成功!");
  82. return ResultVoUtil.success(resultMap);
  83. } catch(Exception e){
  84. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育字典信息失败!");
  85. }
  86. }
  87. public ResultVo<Map<String, Object>> delHealthEducationByCode(String code) {
  88. if (StringUtil.isBlank(code)) {
  89. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有健康教育字典编码,请检查!");
  90. }
  91. Map<String, Object> resultMap = new HashMap<>();
  92. try{
  93. int num = healthEducationDao.deleteHealthEducationByCode(code);
  94. if(num == 0){
  95. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育字典失败!");
  96. }
  97. resultMap.put("cg", "删除健康教育字典成功!");
  98. return ResultVoUtil.success(resultMap);
  99. } catch(Exception e){
  100. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育字典失败!");
  101. }
  102. }
  103. public ResultVo<List<ZdHealthEducationType>> selectHeType(){
  104. return ResultVoUtil.success(zdHealthEducationTypeDao.selectHeType());
  105. }
  106. public ResultVo<Map<String, Object>> saveHeType(ZdHealthEducationType zdHealthEducationType){
  107. if(null == zdHealthEducationType || zdHealthEducationType.getCode() == null){
  108. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "健康教育类型信息不存在,请检查!");
  109. }
  110. Map<String, Object> resultMap = new HashMap<>();
  111. String code = zdHealthEducationType.getCode();
  112. ZdHealthEducationType type = zdHealthEducationTypeDao.selectHeTypeByCode(code);
  113. int num;
  114. try{
  115. if(null != type){
  116. num = zdHealthEducationTypeDao.updateHeTypeByCode(zdHealthEducationType);
  117. } else {
  118. num = zdHealthEducationTypeDao.insert(zdHealthEducationType);
  119. }
  120. if(num == 0){
  121. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育类型信息失败!");
  122. }
  123. resultMap.put("cg", "保存健康教育类型信息成功!");
  124. return ResultVoUtil.success(resultMap);
  125. } catch(Exception e){
  126. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育类型信息失败!");
  127. }
  128. }
  129. public ResultVo<Map<String, Object>> delHeTypeByCode(String code) {
  130. if (StringUtil.isBlank(code)) {
  131. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有健康教育类型编码,请检查!");
  132. }
  133. Map<String, Object> resultMap = new HashMap<>();
  134. try{
  135. int num = zdHealthEducationTypeDao.deleteHeTypeByCode(code);
  136. if(num == 0){
  137. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育类型失败!");
  138. }
  139. resultMap.put("cg", "删除健康教育类型成功!");
  140. return ResultVoUtil.success(resultMap);
  141. } catch(Exception e){
  142. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育类型失败!");
  143. }
  144. }
  145. }