HospitalServiceImpl.java 8.0 KB

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