123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- package com.imed.costaccount.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.imed.costaccount.common.exception.CostException;
- import com.imed.costaccount.common.util.PageUtils;
- import com.imed.costaccount.constants.NumberConstant;
- import com.imed.costaccount.mapper.HospitalMapper;
- import com.imed.costaccount.model.Hospital;
- import com.imed.costaccount.model.dto.HospitalDto;
- import com.imed.costaccount.model.dto.HospitalSaveDto;
- import com.imed.costaccount.model.vo.CommonVO;
- import com.imed.costaccount.model.vo.HospitalAllVO;
- import com.imed.costaccount.model.vo.HospitalVO;
- import com.imed.costaccount.service.HospitalService;
- import com.imed.costaccount.utils.BeanUtil;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import java.util.Collections;
- import java.util.List;
- import java.util.Objects;
- /**
- * @author 11290
- */
- @Service("hosptailService")
- public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {
- /**
- * 分页查询所有的医院信息
- *
- * @param page
- * @param pageSize
- * @return
- */
- @Override
- public PageUtils queryList(Integer page, Integer pageSize, Integer hospId, String name) {
- Page<Hospital> hosptailPage = new Page<>(page, pageSize);
- Page<Hospital> pages = this.page(hosptailPage, new QueryWrapper<Hospital>().lambda()
- // .eq(!StringUtils.isEmpty(hospId), Hospital::getId, hospId)
- .like(!StringUtils.isEmpty(name), Hospital::getName, name));
- List<Hospital> records = pages.getRecords();
- List<HospitalVO> hospitalVOList = BeanUtil.convertList(records, HospitalVO.class);
- hospitalVOList.forEach(i -> {
- if (NumberConstant.ZERO.equals(i.getIsHospital())) {
- i.setParentId(null);
- i.setParentName(null);
- }
- String format = DateUtil.format(DateUtil.date(i.getCreateTime()), "yyyy-MM-dd HH:mm:ss");
- i.setCreateDateTime(format);
- });
- PageUtils pageUtils = new PageUtils(pages);
- pageUtils.setList(hospitalVOList);
- return pageUtils;
- }
- /**
- * 添加医院信息
- *
- * @param hospitalSaveDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveHosptail(HospitalSaveDto hospitalSaveDto) {
- String sign = hospitalSaveDto.getSign();
- // 检验此时保存的是医院还是院区
- checkParam(hospitalSaveDto, sign);
- Hospital hospital = BeanUtil.convertObj(hospitalSaveDto, Hospital.class);
- hospital.setCreateTime(System.currentTimeMillis());
- baseMapper.insert(hospital);
- }
- // 校验参数
- private void checkParam(HospitalSaveDto hospitalSaveDto, String sign) {
- Integer isHospital = hospitalSaveDto.getIsHospital();
- // 新增医院
- if (isHospital == 0) {
- if (StringUtils.isEmpty(sign)) {
- throw new CostException(500, "新增医院请选择医院标识");
- }
- Hospital bySign = this.getBySignHospital(sign);
- if (Objects.nonNull(bySign)) {
- throw new CostException(500, "当前医院标识已存在,请重新生成");
- }
- } else {
- Integer parentId = hospitalSaveDto.getParentId();
- // 校验参数
- if (parentId == 0) {
- throw new CostException(500, "新增院区请选择医院");
- }
- }
- }
- public Hospital getBySignHospital(String hospSign) {
- Hospital one = this.getOne(
- new LambdaQueryWrapper<Hospital>()
- .select(Hospital::getId, Hospital::getName)
- .eq(Hospital::getIsHospital, 0)
- .eq(Hospital::getSign, hospSign)
- .last("limit 1")
- );
- return one;
- }
- /**
- * 修改医院信息
- *
- * @param hospitalDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void updateByHosptail(HospitalDto hospitalDto) {
- Hospital hospital = baseMapper.selectOne(new QueryWrapper<Hospital>().lambda().
- eq(!StringUtils.isEmpty(hospitalDto.getId()), Hospital::getId, hospitalDto.getId()));
- if (Objects.isNull(hospital)) {
- throw new CostException("不存在相关医院信息");
- }
- baseMapper.deleteById(hospital.getId());
- Hospital hospitalRequest = BeanUtil.convertObj(hospitalDto, Hospital.class);
- hospitalRequest.setId(null);
- hospitalRequest.setCreateTime(System.currentTimeMillis());
- hospitalRequest.setSign(hospital.getSign());
- baseMapper.insert(hospitalRequest);
- }
- /**
- * 获取所有的医院信息
- *
- * @return
- */
- @Override
- public List<HospitalAllVO> getAll() {
- List<Hospital> hospitals = baseMapper.selectList(new QueryWrapper<Hospital>().lambda()
- .eq(Hospital::getIsHospital, NumberConstant.ONE));
- List<HospitalAllVO> hospitalAllVOList = BeanUtil.convertList(hospitals, HospitalAllVO.class);
- return hospitalAllVOList;
- }
- /**
- * 通过医院标识获取院区列表
- *
- * @param sign
- * @return
- */
- @Override
- public List<CommonVO> getHospArea(String sign) {
- Hospital one = this.getBySign(sign);
- // 获取下面所有院区
- List<Hospital> list = this.list(
- new LambdaQueryWrapper<Hospital>()
- .select(Hospital::getId)
- .eq(Hospital::getIsHospital, 1)
- .eq(Hospital::getParentId, one.getId())
- );
- // 如果不存在院区
- if (CollUtil.isEmpty(list)) {
- return Collections.emptyList();
- }
- return BeanUtil.convertList(list, CommonVO.class);
- }
- /**
- * 通过医院sign获取医院信息
- *
- * @param hospSign 医院唯一标识
- * @return
- */
- @Override
- public Hospital getBySign(String hospSign) {
- Hospital one = this.getOne(
- new LambdaQueryWrapper<Hospital>()
- .select(Hospital::getId, Hospital::getName)
- .eq(Hospital::getIsHospital, 0)
- .eq(Hospital::getSign, hospSign)
- .last("limit 1")
- );
- if (Objects.isNull(one)) {
- throw new CostException("当前医院不存在");
- }
- return one;
- }
- @Override
- public Hospital getByName(String str) {
- Hospital one = this.getOne(
- new LambdaQueryWrapper<Hospital>()
- // .select(Hospital::getId, Hospital::getName)
- .eq(Hospital::getName, str)
- .last("limit 1")
- );
- if (Objects.isNull(one)) {
- throw new CostException("当前医院名称为:" + str + "不存在");
- }
- return one;
- }
- // /**
- // * 校验是否是本院下人员,并且返回对应的院区id
- // *
- // * @param hospId
- // * @param str
- // * @return
- // */
- // @Override
- // public Integer getByNameAndCheck(Integer hospId, String str) {
- // // 得到这个hospId 相关的所有医院或院区id
- // Hospital byId = this.getById(hospId);
- // if (Objects.isNull(byId)) {
- // throw new CostException(500, "当前医院不存在");
- // }
- // Integer isHospital = byId.getIsHospital();
- // List<Integer>
- // // 是医院
- // if (isHospital == 0) {
- //
- // }
- // }
- }
|