HospitalServiceImpl.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.imed.costaccount.common.exception.CostException;
  8. import com.imed.costaccount.common.util.PageUtils;
  9. import com.imed.costaccount.constants.NumberConstant;
  10. import com.imed.costaccount.mapper.HospitalMapper;
  11. import com.imed.costaccount.model.Hospital;
  12. import com.imed.costaccount.model.dto.HospitalDto;
  13. import com.imed.costaccount.model.dto.HospitalSaveDto;
  14. import com.imed.costaccount.model.vo.CommonVO;
  15. import com.imed.costaccount.model.vo.HospitalAllVO;
  16. import com.imed.costaccount.model.vo.HospitalVO;
  17. import com.imed.costaccount.service.HospitalService;
  18. import com.imed.costaccount.utils.BeanUtil;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Propagation;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.util.StringUtils;
  23. import java.util.Collections;
  24. import java.util.List;
  25. import java.util.Objects;
  26. /**
  27. * @author 11290
  28. */
  29. @Service("hosptailService")
  30. public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {
  31. /**
  32. * 分页查询所有的医院信息
  33. *
  34. * @param page
  35. * @param pageSize
  36. * @return
  37. */
  38. @Override
  39. public PageUtils queryList(Integer page, Integer pageSize, Integer hospId, String name) {
  40. Page<Hospital> hosptailPage = new Page<>(page, pageSize);
  41. Page<Hospital> pages = this.page(hosptailPage, new QueryWrapper<Hospital>().lambda()
  42. // .eq(!StringUtils.isEmpty(hospId), Hospital::getId, hospId)
  43. .like(!StringUtils.isEmpty(name), Hospital::getName, name));
  44. List<Hospital> records = pages.getRecords();
  45. List<HospitalVO> hospitalVOList = BeanUtil.convertList(records, HospitalVO.class);
  46. hospitalVOList.forEach(i->{
  47. if (NumberConstant.ZERO.equals(i.getIsHospital())){
  48. i.setParentId(null);
  49. i.setParentName(null);
  50. }
  51. });
  52. PageUtils pageUtils = new PageUtils(pages);
  53. pageUtils.setList(hospitalVOList);
  54. return pageUtils;
  55. }
  56. /**
  57. * 添加医院信息
  58. *
  59. * @param hospitalSaveDto
  60. */
  61. @Override
  62. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  63. public void saveHosptail(HospitalSaveDto hospitalSaveDto) {
  64. String sign = hospitalSaveDto.getSign();
  65. checkParam(hospitalSaveDto, sign);
  66. Hospital hospital = BeanUtil.convertObj(hospitalSaveDto, Hospital.class);
  67. hospital.setCreateTime(System.currentTimeMillis());
  68. baseMapper.insert(hospital);
  69. }
  70. // 校验参数
  71. private void checkParam(HospitalSaveDto hospitalSaveDto, String sign) {
  72. Integer isHospital = hospitalSaveDto.getIsHospital();
  73. // 新增医院
  74. if (isHospital == 0) {
  75. if (StringUtils.isEmpty(sign)) {
  76. throw new CostException(500, "新增医院请选择医院标识");
  77. }
  78. Hospital bySign = this.getBySign(sign);
  79. if (Objects.nonNull(bySign)) {
  80. throw new CostException(500, "当前医院标识已存在,请重新生成");
  81. }
  82. } else {
  83. Integer parentId = hospitalSaveDto.getParentId();
  84. // 校验参数
  85. if (parentId == 0) {
  86. throw new CostException(500, "新增院区请选择医院");
  87. }
  88. }
  89. }
  90. /**
  91. * 修改医院信息
  92. *
  93. * @param hospitalDto
  94. */
  95. @Override
  96. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  97. public void updateByHosptail(HospitalDto hospitalDto) {
  98. Hospital hospital = baseMapper.selectOne(new QueryWrapper<Hospital>().lambda().
  99. eq(!StringUtils.isEmpty(hospitalDto.getId()), Hospital::getId, hospitalDto.getId()));
  100. if (Objects.isNull(hospital)) {
  101. throw new CostException("不存在相关医院信息");
  102. }
  103. baseMapper.deleteById(hospital.getId());
  104. Hospital hospitalRequest = BeanUtil.convertObj(hospitalDto, Hospital.class);
  105. hospitalRequest.setId(null);
  106. hospitalRequest.setCreateTime(System.currentTimeMillis());
  107. hospitalRequest.setSign(hospital.getSign());
  108. baseMapper.insert(hospitalRequest);
  109. }
  110. /**
  111. * 获取所有的医院信息
  112. *
  113. * @return
  114. */
  115. @Override
  116. public List<HospitalAllVO> getAll() {
  117. List<Hospital> hospitals = baseMapper.selectList(new QueryWrapper<Hospital>().lambda()
  118. .eq(Hospital::getIsHospital,NumberConstant.ONE));
  119. List<HospitalAllVO> hospitalAllVOList = BeanUtil.convertList(hospitals, HospitalAllVO.class);
  120. return hospitalAllVOList;
  121. }
  122. /**
  123. * 通过医院标识获取院区列表
  124. *
  125. * @param sign
  126. * @return
  127. */
  128. @Override
  129. public List<CommonVO> getHospArea(String sign) {
  130. Hospital one = this.getBySign(sign);
  131. // 获取下面所有院区
  132. List<Hospital> list = this.list(
  133. new LambdaQueryWrapper<Hospital>()
  134. .select(Hospital::getId)
  135. .eq(Hospital::getIsHospital, 1)
  136. .eq(Hospital::getParentId, one.getId())
  137. );
  138. // 如果不存在院区
  139. if (CollUtil.isEmpty(list)) {
  140. return Collections.emptyList();
  141. }
  142. return BeanUtil.convertList(list, CommonVO.class);
  143. }
  144. /**
  145. * 通过医院sign获取医院信息
  146. *
  147. * @param hospSign 医院唯一标识
  148. * @return
  149. */
  150. @Override
  151. public Hospital getBySign(String hospSign) {
  152. Hospital one = this.getOne(
  153. new LambdaQueryWrapper<Hospital>()
  154. .select(Hospital::getId, Hospital::getName)
  155. .eq(Hospital::getIsHospital, 1)
  156. .eq(Hospital::getSign, hospSign)
  157. .last("limit 1")
  158. );
  159. if (Objects.isNull(one)) {
  160. throw new CostException("当前医院不存在");
  161. }
  162. return one;
  163. }
  164. }