|
@@ -2,13 +2,20 @@ package com.ruoyi.web.work.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
+import com.ruoyi.web.work.api.config.TokenServices;
|
|
|
|
+import com.ruoyi.web.work.api.util.AppUtil;
|
|
import com.ruoyi.web.work.domain.BindUser;
|
|
import com.ruoyi.web.work.domain.BindUser;
|
|
|
|
+import com.ruoyi.web.work.domain.Patient;
|
|
|
|
+import com.ruoyi.web.work.domain.User;
|
|
import com.ruoyi.web.work.domain.dto.BindDto;
|
|
import com.ruoyi.web.work.domain.dto.BindDto;
|
|
import com.ruoyi.web.work.mapper.BindUserMapper;
|
|
import com.ruoyi.web.work.mapper.BindUserMapper;
|
|
import com.ruoyi.web.work.service.IBindUserService;
|
|
import com.ruoyi.web.work.service.IBindUserService;
|
|
|
|
+import com.ruoyi.web.work.service.IUserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.rmi.ServerException;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -20,13 +27,77 @@ public class BindUserServiceImpl extends ServiceImpl<BindUserMapper, BindUser> i
|
|
@Autowired
|
|
@Autowired
|
|
private BindUserMapper bindUserMapper;
|
|
private BindUserMapper bindUserMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ IUserService userService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TokenServices tokenService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<BindUser> selectList(BindUser bindUser) {
|
|
public List<BindUser> selectList(BindUser bindUser) {
|
|
return bindUserMapper.selectList(bindUser);
|
|
return bindUserMapper.selectList(bindUser);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult bind(BindDto dto) throws ServerException {
|
|
|
|
+ Patient patient = bindUserMapper.selectPatient(new Patient().setPhone(dto.getPhone()));
|
|
|
|
+ if (patient == null) {
|
|
|
|
+ return AjaxResult.error("预留的就诊人手机号不存在");
|
|
|
|
+ }
|
|
|
|
+ BindUser bindUser = new BindUser();
|
|
|
|
+ bindUser.setPatientId(patient.getId());
|
|
|
|
+ bindUser.setUserId(AppUtil.getUser().getId());
|
|
|
|
+ bindUser.setPatientName(patient.getName());
|
|
|
|
+ if (bindUserMapper.selectBindUser(bindUser) != null) {
|
|
|
|
+ return AjaxResult.error("你已绑定过该就诊人");
|
|
|
|
+ }
|
|
|
|
+ //如果只有一个就诊人直接设置成当前就诊人
|
|
|
|
+ List<BindUser> bindUserList = bindUserMapper.selectList(new BindUser().setUserId(AppUtil.getUser().getId()));
|
|
|
|
+ if (bindUserList.size() == 0) {
|
|
|
|
+ bindUser.setState(1);
|
|
|
|
+ User user = AppUtil.getUser();
|
|
|
|
+ user.setPatientId(patient.getId());
|
|
|
|
+ user.setPatientName(patient.getName());
|
|
|
|
+ if (!userService.updateById(user)) {
|
|
|
|
+ throw new ServerException("绑定就诊人失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!save(bindUser)) {
|
|
|
|
+ throw new ServerException("绑定就诊人失败");
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult remove(Long id) throws ServerException {
|
|
|
|
+ BindUser bindUser = getById(id);
|
|
|
|
+ if (bindUser == null || !bindUser.getUserId().equals(AppUtil.getUser().getId())) {
|
|
|
|
+ return AjaxResult.error("数据不存在或非法操作");
|
|
|
|
+ }
|
|
|
|
+ if (!removeById(id)) {
|
|
|
|
+ throw new ServerException("删除就诊人失败");
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
- public AjaxResult bind(BindDto dto) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ public AjaxResult change(Long id) throws ServerException {
|
|
|
|
+ BindUser bindUser = getById(id);
|
|
|
|
+ if (bindUser == null || !bindUser.getUserId().equals(AppUtil.getUser().getId())) {
|
|
|
|
+ return AjaxResult.error("数据不存在或非法操作");
|
|
|
|
+ }
|
|
|
|
+ bindUserMapper.changeBindUser(bindUser);
|
|
|
|
+ bindUser.setState(1);
|
|
|
|
+ updateById(bindUser);
|
|
|
|
+ User user = AppUtil.getUser();
|
|
|
|
+ user.setPatientId(bindUser.getPatientId());
|
|
|
|
+ user.setPatientName(bindUser.getPatientName());
|
|
|
|
+ if (!userService.updateById(user)) {
|
|
|
|
+ throw new ServerException("切换就诊人失败");
|
|
|
|
+ }
|
|
|
|
+ tokenService.setLoginUser(userService.getById(AppUtil.getUser().getId()).setToken(AppUtil.getUser().getToken()));
|
|
|
|
+ return AjaxResult.success();
|
|
}
|
|
}
|
|
}
|
|
}
|