package com.caimei.service.impl; import com.caimei.mapper.DoctorMapper; import com.caimei.model.ResponseJson; import com.caimei.model.po.CmBrandDoctorPo; import com.caimei.model.vo.*; import com.caimei.service.DoctorService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; /** * Description * * @author : Aslee * @date : 2022/1/7 */ @Slf4j @Service public class DoctorServiceImpl implements DoctorService { @Resource private DoctorMapper doctorMapper; @Value("${spring.profiles.active}") private String active; @Value("${caimei.imageDomain}") private String imageDomain; @Override public ResponseJson> getDoctorList(Integer listType, Integer authUserId, String doctorName, Integer status, Integer auditStatus, Integer pageNum, Integer pageSize) { if (null == authUserId) { return ResponseJson.error("参数异常,请输入供应商用户id", null); } listType = null == listType ? 1 : listType; PageHelper.startPage(pageNum, pageSize); List doctorList = doctorMapper.getDoctorList(listType, authUserId, doctorName, status, auditStatus); PageInfo pageData = new PageInfo<>(doctorList); return ResponseJson.success(pageData); } @Override public ResponseJson updateDoctorStatus(Integer doctorId, Integer status) { if (null == doctorId) { return ResponseJson.error("请输入医师id"); } if (null == status) { return ResponseJson.error("请输入要更新的状态值"); } doctorMapper.updateDoctorStatus(doctorId, status); if (0 == status) { return ResponseJson.success("下线医师成功"); } else { return ResponseJson.success("上线医师成功"); } } @Override public ResponseJson deleteDoctor(Integer doctorId) { if (null == doctorId) { return ResponseJson.error("参数异常,请输入医师id"); } // 删除医师 doctorMapper.deleteDoctorByDoctorId(doctorId); // 删除轮播图 doctorMapper.deleteBanner(doctorId); // 删除仪器 doctorMapper.deleteEquipment(doctorId); return ResponseJson.success("删除医师成功"); } @Override public ResponseJson getDoctorFormData(Integer doctorId) { if (null == doctorId) { return ResponseJson.error("参数异常,医师id不能为空", null); } CmBrandDoctorPo doctor = doctorMapper.getDoctorById(doctorId); DoctorFormVo doctorFormVo = new DoctorFormVo(); doctorFormVo.setDoctorId(doctor.getId()); doctorFormVo.setDoctorName(doctor.getName()); BeanUtils.copyProperties(doctor, doctorFormVo); // 轮播图 List bannerList = doctorMapper.getBannerList(doctorId); doctorFormVo.setBannerList(bannerList); // 仪器 List equipmentList = doctorMapper.getEquipmentList(doctorId); doctorFormVo.setEquipmentList(equipmentList); return ResponseJson.success(doctorFormVo); } @Override public ResponseJson saveDoctor(CmBrandDoctorPo doctor, List bannerList, List> equipmentList) { Integer doctorId = doctor.getId(); Integer authUserId = doctor.getAuthUserId(); String certificateNo = doctor.getCertificateNo(); if (null == authUserId) { return ResponseJson.error("参数异常,请输入供应商用户id"); } if (StringUtils.isBlank(doctor.getName())) { return ResponseJson.error("参数异常,请输入医师名称"); } if (StringUtils.isBlank(certificateNo)) { return ResponseJson.error("参数异常,请输入从业资格证编号"); } Integer doctorIdByCertificateNo = doctorMapper.getDoctorIdByCertificateNo(certificateNo, authUserId); if (null != doctorIdByCertificateNo && !doctorIdByCertificateNo.equals(doctorId)) { return ResponseJson.error("参数异常,该从业资格证编号已存在,请重新输入", null); } if (StringUtils.isBlank(doctor.getClubName())) { return ResponseJson.error("参数异常,请输入所属机构"); } if (StringUtils.isBlank(doctor.getImage())) { return ResponseJson.error("参数异常,请上传医师照片"); } if (null == doctor.getCreateBy()) { return ResponseJson.error("参数异常,请输入创建人id"); } if (null == bannerList || bannerList.size() <= 0) { return ResponseJson.error("参数异常,请上传轮播图"); } if (null == equipmentList || equipmentList.size() <= 0) { return ResponseJson.error("参数异常,请上传设备列表"); } // 保存医师信息,上线状态默认为“待上线”,审核状态为“待审核” doctor.setStatus(2); doctor.setAuditStatus(2); /* 保存医师 */ if (null == doctorId) { doctorMapper.insertDoctor(doctor); } else { doctorMapper.updateDoctorByDoctorId(doctor); // 删除原有的轮播图 doctorMapper.deleteBanner(doctor.getId()); // 删除原有的设备 doctorMapper.deleteEquipment(doctor.getId()); } // 保存轮播图 bannerList.forEach(banner-> doctorMapper.insertBanner(doctor.getId(), banner)); // 保存设备 equipmentList.forEach(equipment-> { doctorMapper.insertEquipment(doctor.getId(), equipment.get("equipmentName"), equipment.get("brand"), equipment.get("image")); }); return ResponseJson.success("保存医师成功", doctor); } @Override public ResponseJson auditDoctor(Integer doctorId, Integer auditStatus, String invalidReason, Integer auditBy) { if (doctorId == null) { return ResponseJson.error("请输入医师id"); } if (auditStatus == null) { return ResponseJson.error("请输入审核结果"); } if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) { return ResponseJson.error("请输入审核不通过的原因"); } if (auditBy == null) { return ResponseJson.error("请输入审核人用户id"); } Date auditTime = new Date(); // 医师状态更新 Integer status = null; if (auditStatus == 0) { // 审核不通过,下线医师 status = 0; } else { // 审核通过,上线医师 status = 1; } doctorMapper.updateDoctorAuditStatus(doctorId, status, auditStatus, invalidReason, auditBy, auditTime); return ResponseJson.success("审核医师成功"); } @Override public ResponseJson> getWxDoctorList(String appId, String doctorName, Integer pageNum, Integer pageSize) { if (null == appId) { return ResponseJson.error("参数异常,请输入供应商appId", null); } PageHelper.startPage(pageNum, pageSize); List productList = doctorMapper.getWxDoctorList(appId, doctorName); PageInfo pageData = new PageInfo<>(productList); return ResponseJson.success(pageData); } @Override public ResponseJson getAuthDoctorDetails(Integer doctorId) { if (null == doctorId) { return ResponseJson.error("参数异常,医师id不能为空", null); } DoctorFormVo doctor = doctorMapper.getDoctorDetailsById(doctorId); // 轮播图 List bannerList = doctorMapper.getBannerList(doctorId); doctor.setBannerList(bannerList); // 仪器 List equipmentList = doctorMapper.getEquipmentList(doctorId); doctor.setEquipmentList(equipmentList); return ResponseJson.success(doctor); } }