HospitalServiceImpl.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 current
  36. * @param pageSize
  37. * @return
  38. */
  39. @Override
  40. public PageUtils queryList(Integer current, Integer pageSize, Integer hospId, String name) {
  41. Page<Hospital> hosptailPage = new Page<>(current, 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. if (NumberConstant.ONE.equals(hospitalDto.getIsHospital())){
  118. // 此时修改的是院区 需要传递parent_Id 和 parent__name
  119. if (hospitalDto.getParentId()<=0 || StringUtils.isEmpty(hospitalDto.getParentName())){
  120. throw new CostException(500,"修改院区的时候需要传递医院的Id和医院名称");
  121. }
  122. }
  123. baseMapper.deleteById(hospital.getId());
  124. Hospital hospitalRequest = BeanUtil.convertObj(hospitalDto, Hospital.class);
  125. hospitalRequest.setId(null);
  126. hospitalRequest.setCreateTime(System.currentTimeMillis());
  127. hospitalRequest.setSign(hospital.getSign());
  128. baseMapper.insert(hospitalRequest);
  129. }
  130. /**
  131. * 获取所有的医院信息
  132. *
  133. * @return
  134. */
  135. @Override
  136. public List<HospitalAllVO> getAll() {
  137. List<Hospital> hospitals = baseMapper.selectList(new QueryWrapper<Hospital>().lambda()
  138. .eq(Hospital::getIsHospital, NumberConstant.ONE));
  139. List<HospitalAllVO> hospitalAllVOList = BeanUtil.convertList(hospitals, HospitalAllVO.class);
  140. return hospitalAllVOList;
  141. }
  142. /**
  143. * 通过医院标识获取院区列表
  144. *
  145. * @param sign
  146. * @return
  147. */
  148. @Override
  149. public List<CommonVO> getHospArea(String sign) {
  150. Hospital one = this.getBySign(sign);
  151. // 获取下面所有院区
  152. List<Hospital> list = this.list(
  153. new LambdaQueryWrapper<Hospital>()
  154. .select(Hospital::getId)
  155. .eq(Hospital::getIsHospital, 1)
  156. .eq(Hospital::getParentId, one.getId())
  157. );
  158. // 如果不存在院区
  159. if (CollUtil.isEmpty(list)) {
  160. return Collections.emptyList();
  161. }
  162. return BeanUtil.convertList(list, CommonVO.class);
  163. }
  164. /**
  165. * 通过医院sign获取医院信息
  166. *
  167. * @param hospSign 医院唯一标识
  168. * @return
  169. */
  170. @Override
  171. public Hospital getBySign(String hospSign) {
  172. Hospital one = this.getOne(
  173. new LambdaQueryWrapper<Hospital>()
  174. .select(Hospital::getId, Hospital::getName)
  175. .eq(Hospital::getIsHospital, 0)
  176. .eq(Hospital::getSign, hospSign)
  177. .last("limit 1")
  178. );
  179. if (Objects.isNull(one)) {
  180. throw new CostException("当前医院不存在");
  181. }
  182. return one;
  183. }
  184. @Override
  185. public Hospital getByName(String str) {
  186. Hospital one = this.getOne(
  187. new LambdaQueryWrapper<Hospital>()
  188. // .select(Hospital::getId, Hospital::getName)
  189. .eq(Hospital::getName, str)
  190. .last("limit 1")
  191. );
  192. if (Objects.isNull(one)) {
  193. throw new CostException("当前医院名称为:" + str + "不存在");
  194. }
  195. return one;
  196. }
  197. // /**
  198. // * 校验是否是本院下人员,并且返回对应的院区id
  199. // *
  200. // * @param hospId
  201. // * @param str
  202. // * @return
  203. // */
  204. // @Override
  205. // public Integer getByNameAndCheck(Integer hospId, String str) {
  206. // // 得到这个hospId 相关的所有医院或院区id
  207. // Hospital byId = this.getById(hospId);
  208. // if (Objects.isNull(byId)) {
  209. // throw new CostException(500, "当前医院不存在");
  210. // }
  211. // Integer isHospital = byId.getIsHospital();
  212. // List<Integer>
  213. // // 是医院
  214. // if (isHospital == 0) {
  215. //
  216. // }
  217. // }
  218. }