DoctorServiceImpl.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package com.caimei.service.impl;
  2. import com.caimei.mapper.DoctorMapper;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.po.CmBrandDoctorPo;
  5. import com.caimei.model.vo.*;
  6. import com.caimei.service.DoctorService;
  7. import com.github.pagehelper.PageHelper;
  8. import com.github.pagehelper.PageInfo;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.beans.BeanUtils;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.util.*;
  16. /**
  17. * Description
  18. *
  19. * @author : Aslee
  20. * @date : 2022/1/7
  21. */
  22. @Slf4j
  23. @Service
  24. public class DoctorServiceImpl implements DoctorService {
  25. @Resource
  26. private DoctorMapper doctorMapper;
  27. @Value("${spring.profiles.active}")
  28. private String active;
  29. @Value("${caimei.imageDomain}")
  30. private String imageDomain;
  31. @Override
  32. public ResponseJson<PageInfo<DoctorListVo>> getDoctorList(Integer listType, Integer authUserId, String doctorName, Integer status, Integer auditStatus, Integer pageNum, Integer pageSize) {
  33. if (null == authUserId) {
  34. return ResponseJson.error("参数异常,请输入供应商用户id", null);
  35. }
  36. listType = null == listType ? 1 : listType;
  37. PageHelper.startPage(pageNum, pageSize);
  38. List<DoctorListVo> doctorList = doctorMapper.getDoctorList(listType, authUserId, doctorName, status, auditStatus);
  39. PageInfo<DoctorListVo> pageData = new PageInfo<>(doctorList);
  40. return ResponseJson.success(pageData);
  41. }
  42. @Override
  43. public ResponseJson updateDoctorStatus(Integer doctorId, Integer status) {
  44. if (null == doctorId) {
  45. return ResponseJson.error("请输入医师id");
  46. }
  47. if (null == status) {
  48. return ResponseJson.error("请输入要更新的状态值");
  49. }
  50. doctorMapper.updateDoctorStatus(doctorId, status);
  51. if (0 == status) {
  52. return ResponseJson.success("下线医师成功");
  53. } else {
  54. return ResponseJson.success("上线医师成功");
  55. }
  56. }
  57. @Override
  58. public ResponseJson deleteDoctor(Integer doctorId) {
  59. if (null == doctorId) {
  60. return ResponseJson.error("参数异常,请输入医师id");
  61. }
  62. // 删除医师
  63. doctorMapper.deleteDoctorByDoctorId(doctorId);
  64. // 删除轮播图
  65. doctorMapper.deleteBanner(doctorId);
  66. // 删除仪器
  67. doctorMapper.deleteEquipment(doctorId);
  68. return ResponseJson.success("删除医师成功");
  69. }
  70. @Override
  71. public ResponseJson<DoctorFormVo> getDoctorFormData(Integer doctorId) {
  72. if (null == doctorId) {
  73. return ResponseJson.error("参数异常,医师id不能为空", null);
  74. }
  75. CmBrandDoctorPo doctor = doctorMapper.getDoctorById(doctorId);
  76. DoctorFormVo doctorFormVo = new DoctorFormVo();
  77. doctorFormVo.setDoctorId(doctor.getId());
  78. doctorFormVo.setDoctorName(doctor.getName());
  79. BeanUtils.copyProperties(doctor, doctorFormVo);
  80. // 轮播图
  81. List<String> bannerList = doctorMapper.getBannerList(doctorId);
  82. doctorFormVo.setBannerList(bannerList);
  83. // 仪器
  84. List<DoctorEquipmentVo> equipmentList = doctorMapper.getEquipmentList(doctorId);
  85. doctorFormVo.setEquipmentList(equipmentList);
  86. return ResponseJson.success(doctorFormVo);
  87. }
  88. @Override
  89. public ResponseJson saveDoctor(CmBrandDoctorPo doctor, List<String> bannerList, List<Map<String,String>> equipmentList) {
  90. Integer doctorId = doctor.getId();
  91. Integer authUserId = doctor.getAuthUserId();
  92. String certificateNo = doctor.getCertificateNo();
  93. if (null == authUserId) {
  94. return ResponseJson.error("参数异常,请输入供应商用户id");
  95. }
  96. if (StringUtils.isBlank(doctor.getName())) {
  97. return ResponseJson.error("参数异常,请输入医师名称");
  98. }
  99. if (StringUtils.isBlank(certificateNo)) {
  100. return ResponseJson.error("参数异常,请输入从业资格证编号");
  101. }
  102. Integer doctorIdByCertificateNo = doctorMapper.getDoctorIdByCertificateNo(certificateNo, authUserId);
  103. if (null != doctorIdByCertificateNo && !doctorIdByCertificateNo.equals(doctorId)) {
  104. return ResponseJson.error("参数异常,该从业资格证编号已存在,请重新输入", null);
  105. }
  106. if (StringUtils.isBlank(doctor.getClubName())) {
  107. return ResponseJson.error("参数异常,请输入所属机构");
  108. }
  109. if (StringUtils.isBlank(doctor.getImage())) {
  110. return ResponseJson.error("参数异常,请上传医师照片");
  111. }
  112. if (null == doctor.getCreateBy()) {
  113. return ResponseJson.error("参数异常,请输入创建人id");
  114. }
  115. if (null == bannerList || bannerList.size() <= 0) {
  116. return ResponseJson.error("参数异常,请上传轮播图");
  117. }
  118. if (null == equipmentList || equipmentList.size() <= 0) {
  119. return ResponseJson.error("参数异常,请上传设备列表");
  120. }
  121. // 保存医师信息,上线状态默认为“待上线”,审核状态为“待审核”
  122. doctor.setStatus(2);
  123. doctor.setAuditStatus(2);
  124. /*
  125. 保存医师
  126. */
  127. if (null == doctorId) {
  128. doctorMapper.insertDoctor(doctor);
  129. } else {
  130. doctorMapper.updateDoctorByDoctorId(doctor);
  131. // 删除原有的轮播图
  132. doctorMapper.deleteBanner(doctor.getId());
  133. // 删除原有的设备
  134. doctorMapper.deleteEquipment(doctor.getId());
  135. }
  136. // 保存轮播图
  137. bannerList.forEach(banner-> doctorMapper.insertBanner(doctor.getId(), banner));
  138. // 保存设备
  139. equipmentList.forEach(equipment-> {
  140. doctorMapper.insertEquipment(doctor.getId(), equipment.get("equipmentName"), equipment.get("brand"), equipment.get("image"));
  141. });
  142. return ResponseJson.success("保存医师成功", doctor);
  143. }
  144. @Override
  145. public ResponseJson auditDoctor(Integer doctorId, Integer auditStatus, String invalidReason, Integer auditBy) {
  146. if (doctorId == null) {
  147. return ResponseJson.error("请输入医师id");
  148. }
  149. if (auditStatus == null) {
  150. return ResponseJson.error("请输入审核结果");
  151. }
  152. if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) {
  153. return ResponseJson.error("请输入审核不通过的原因");
  154. }
  155. if (auditBy == null) {
  156. return ResponseJson.error("请输入审核人用户id");
  157. }
  158. Date auditTime = new Date();
  159. // 医师状态更新
  160. Integer status = null;
  161. if (auditStatus == 0) {
  162. // 审核不通过,下线医师
  163. status = 0;
  164. } else {
  165. // 审核通过,上线医师
  166. status = 1;
  167. }
  168. doctorMapper.updateDoctorAuditStatus(doctorId, status, auditStatus, invalidReason, auditBy, auditTime);
  169. return ResponseJson.success("审核医师成功");
  170. }
  171. @Override
  172. public ResponseJson<PageInfo<WxDoctorListVo>> getWxDoctorList(String appId, String doctorName, Integer pageNum, Integer pageSize) {
  173. if (null == appId) {
  174. return ResponseJson.error("参数异常,请输入供应商appId", null);
  175. }
  176. PageHelper.startPage(pageNum, pageSize);
  177. List<WxDoctorListVo> productList = doctorMapper.getWxDoctorList(appId, doctorName);
  178. PageInfo<WxDoctorListVo> pageData = new PageInfo<>(productList);
  179. return ResponseJson.success(pageData);
  180. }
  181. @Override
  182. public ResponseJson<DoctorFormVo> getAuthDoctorDetails(Integer doctorId) {
  183. if (null == doctorId) {
  184. return ResponseJson.error("参数异常,医师id不能为空", null);
  185. }
  186. DoctorFormVo doctor = doctorMapper.getDoctorDetailsById(doctorId);
  187. // 轮播图
  188. List<String> bannerList = doctorMapper.getBannerList(doctorId);
  189. doctor.setBannerList(bannerList);
  190. // 仪器
  191. List<DoctorEquipmentVo> equipmentList = doctorMapper.getEquipmentList(doctorId);
  192. doctor.setEquipmentList(equipmentList);
  193. return ResponseJson.success(doctor);
  194. }
  195. }