|
@@ -1,27 +1,32 @@
|
|
|
package com.ruoyi.info.hospital.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ruoyi.base.area.service.ISysCnAreaService;
|
|
|
+import com.ruoyi.common.core.domain.PageQuery;
|
|
|
+import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
-import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
-import com.ruoyi.common.core.domain.PageQuery;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
+import com.ruoyi.info.hospital.domain.Hospital;
|
|
|
import com.ruoyi.info.hospital.domain.bo.HospitalBo;
|
|
|
+import com.ruoyi.info.hospital.domain.bo.HospitalRackUpdateBo;
|
|
|
import com.ruoyi.info.hospital.domain.vo.HospitalVo;
|
|
|
-import com.ruoyi.info.hospital.domain.Hospital;
|
|
|
import com.ruoyi.info.hospital.exception.HospitalExceptionEnum;
|
|
|
import com.ruoyi.info.hospital.mapper.HospitalMapper;
|
|
|
import com.ruoyi.info.hospital.service.IHospitalService;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
/**
|
|
|
* 医院信息Service业务层处理
|
|
@@ -35,6 +40,9 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
|
|
|
private final HospitalMapper baseMapper;
|
|
|
|
|
|
+ private final ISysCnAreaService sysCnAreaService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 查询医院信息分页
|
|
|
*
|
|
@@ -65,25 +73,15 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
LambdaQueryWrapper<Hospital> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getName()), Hospital::getName, bo.getName());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getResponsiblePerson()), Hospital::getResponsiblePerson, bo.getResponsiblePerson());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getContactMobile()), Hospital::getContactMobile, bo.getContactMobile());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getAddress()), Hospital::getAddress, bo.getAddress());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getBusinessStatus()), Hospital::getBusinessStatus, bo.getBusinessStatus());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getRackStatus()), Hospital::getRackStatus, bo.getRackStatus());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getLevel()), Hospital::getLevel, bo.getLevel());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getLabel()), Hospital::getLabel, bo.getLabel());
|
|
|
lqw.eq(bo.getProvinceId() != null, Hospital::getProvinceId, bo.getProvinceId());
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getProvinceName()), Hospital::getProvinceName, bo.getProvinceName());
|
|
|
lqw.eq(bo.getCityId() != null, Hospital::getCityId, bo.getCityId());
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getCityName()), Hospital::getCityName, bo.getCityName());
|
|
|
lqw.eq(bo.getAreaId() != null, Hospital::getAreaId, bo.getAreaId());
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getAreaName()), Hospital::getAreaName, bo.getAreaName());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getCoordinates()), Hospital::getCoordinates, bo.getCoordinates());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getServiceMobile()), Hospital::getServiceMobile, bo.getServiceMobile());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getIntroduction()), Hospital::getIntroduction, bo.getIntroduction());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getLogoUrl()), Hospital::getLogoUrl, bo.getLogoUrl());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getQrCodeUrl()), Hospital::getQrCodeUrl, bo.getQrCodeUrl());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getBusinessHours()), Hospital::getBusinessHours, bo.getBusinessHours());
|
|
|
- lqw.eq(bo.getSortOrder() != null, Hospital::getSortOrder, bo.getSortOrder());
|
|
|
+ lqw.ge(ObjectUtil.isNotNull(bo.getCreateTimeStart()), Hospital::getCreateTime, bo.getCreateTimeStart());
|
|
|
+ lqw.le(ObjectUtil.isNotNull(bo.getCreateTimeEnd()), Hospital::getCreateTime, bo.getCreateTimeEnd());
|
|
|
+ lqw.orderByDesc(Hospital::getSortOrder).orderByDesc(Hospital::getId);
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
@@ -108,7 +106,7 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
public Hospital loadById(Long id, Boolean tw){
|
|
|
Hospital info = this.baseMapper.selectById(id);
|
|
|
if(ObjectUtil.isEmpty(info) && tw){
|
|
|
- throw new ServiceException(HospitalExceptionEnum.Hospital_IS_NOT_EXISTS);
|
|
|
+ throw new ServiceException(HospitalExceptionEnum.HOSPITAL_IS_NOT_EXISTS);
|
|
|
}
|
|
|
return info;
|
|
|
}
|
|
@@ -123,9 +121,16 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
public Boolean insertByBo(HospitalBo bo) {
|
|
|
Hospital add = BeanUtil.toBean(bo, Hospital.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
+ // 生成省市区
|
|
|
+ add.setProvinceName(sysCnAreaService.getByCode(bo.getProvinceId()).getLabel());
|
|
|
+ add.setCityName(sysCnAreaService.getByCode(bo.getCityId()).getLabel());
|
|
|
+ add.setAreaName(sysCnAreaService.getByCode(bo.getAreaId()).getLabel());
|
|
|
+
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
+
|
|
|
+ // TODO 生成小程序二维码
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
@@ -139,6 +144,9 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
@Override
|
|
|
public Boolean updateByBo(HospitalBo bo) {
|
|
|
Hospital hospital = baseMapper.selectById(bo.getId());
|
|
|
+ if (ObjectUtil.isNull(hospital)) {
|
|
|
+ throw new ServiceException(HospitalExceptionEnum.HOSPITAL_IS_NOT_EXISTS);
|
|
|
+ }
|
|
|
Hospital update = BeanCopyUtils.copy(bo, hospital);
|
|
|
validEntityBeforeSave(update);
|
|
|
return baseMapper.updateById(update) > 0;
|
|
@@ -150,7 +158,24 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
* @param entity 实体类数据
|
|
|
*/
|
|
|
private void validEntityBeforeSave(Hospital entity){
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
+ // 医院名称不可重复
|
|
|
+ LambdaQueryWrapper<Hospital> lqw = new LambdaQueryWrapper<Hospital>()
|
|
|
+ .eq(Hospital::getName, entity.getName());
|
|
|
+ List<Hospital> hospitalList = baseMapper.selectList(lqw);
|
|
|
+ if (CollUtil.isNotEmpty(hospitalList)) {
|
|
|
+ if (entity.getId() == null) {
|
|
|
+ // 新增校验
|
|
|
+ throw new ServiceException(HospitalExceptionEnum.HOSPITAL_NAME_ALREADY_EXISTS);
|
|
|
+ } else {
|
|
|
+ // 编辑校验
|
|
|
+ if (hospitalList.stream().anyMatch(hospital -> !hospital.getId().equals(entity.getId()))) {
|
|
|
+ throw new ServiceException(HospitalExceptionEnum.HOSPITAL_NAME_ALREADY_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -167,4 +192,18 @@ public class HospitalServiceImpl implements IHospitalService {
|
|
|
return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateRackStatus(HospitalRackUpdateBo bo) {
|
|
|
+ Hospital hospital = baseMapper.selectById(bo.getId());
|
|
|
+ if (hospital == null) {
|
|
|
+ throw new ServiceException(HospitalExceptionEnum.HOSPITAL_IS_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hospital.getRackStatus().equals(bo.getRackStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ hospital.setRackStatus(bo.getRackStatus());
|
|
|
+ baseMapper.updateById(hospital);
|
|
|
+ }
|
|
|
+
|
|
|
}
|