|
|
package com.controller;
|
|
|
|
|
|
// 导入文件操作相关类
|
|
|
import java.io.File;
|
|
|
// 导入用于高精度计算的类
|
|
|
import java.math.BigDecimal;
|
|
|
// 导入用于处理URL的类
|
|
|
import java.net.URL;
|
|
|
// 导入用于日期格式化的类
|
|
|
import java.text.SimpleDateFormat;
|
|
|
// 导入阿里巴巴的JSON对象类
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
// 导入常用的集合类
|
|
|
import java.util.*;
|
|
|
// 导入Spring的Bean属性复制工具类
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
// 导入Servlet请求相关类
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
// 导入Spring的上下文加载器类
|
|
|
import org.springframework.web.context.ContextLoader;
|
|
|
// 导入Servlet上下文类
|
|
|
import javax.servlet.ServletContext;
|
|
|
// 导入令牌服务类
|
|
|
import com.service.TokenService;
|
|
|
// 导入自定义工具类
|
|
|
import com.utils.*;
|
|
|
// 导入反射调用异常类
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
// 导入字典服务类
|
|
|
import com.service.DictionaryService;
|
|
|
// 导入Apache Commons提供的字符串工具类
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
// 导入自定义的忽略权限注解类
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
// 导入日志记录器接口
|
|
|
import org.slf4j.Logger;
|
|
|
// 导入日志记录器工厂类
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
// 导入Spring的自动注入注解
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
// 导入Spring的控制器注解
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
// 导入Spring的请求映射注解
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
// 导入MyBatis-Plus的实体包装器类
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
// 导入MyBatis-Plus的查询包装器接口
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
// 导入自定义的实体类
|
|
|
import com.entity.*;
|
|
|
// 导入自定义的视图类
|
|
|
import com.entity.view.*;
|
|
|
// 导入自定义的服务类
|
|
|
import com.service.*;
|
|
|
// 导入自定义的分页工具类
|
|
|
import com.utils.PageUtils;
|
|
|
// 导入自定义的响应结果类
|
|
|
import com.utils.R;
|
|
|
// 导入阿里巴巴的JSON工具类
|
|
|
import com.alibaba.fastjson.*;
|
|
|
|
|
|
/**
|
|
|
* 挂号
|
|
|
* 后端接口
|
|
|
* @author
|
|
|
* @email
|
|
|
*/
|
|
|
// 声明该类为RESTful控制器
|
|
|
@RestController
|
|
|
// 声明该类为控制器
|
|
|
@Controller
|
|
|
// 映射请求路径,所有以/guahao开头的请求都会由该控制器处理
|
|
|
@RequestMapping("/guahao")
|
|
|
public class GuahaoController {
|
|
|
// 日志记录器,用于记录当前控制器类的日志信息
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GuahaoController.class);
|
|
|
|
|
|
// 自动注入挂号服务类,用于处理挂号相关业务逻辑
|
|
|
@Autowired
|
|
|
private GuahaoService guahaoService;
|
|
|
|
|
|
// 自动注入令牌服务类
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
// 自动注入字典服务类
|
|
|
@Autowired
|
|
|
private DictionaryService dictionaryService;
|
|
|
|
|
|
// 级联表service,自动注入医生服务类
|
|
|
@Autowired
|
|
|
private YishengService yishengService;
|
|
|
// 级联表service,自动注入用户服务类
|
|
|
@Autowired
|
|
|
private YonghuService yonghuService;
|
|
|
|
|
|
/**
|
|
|
* 后端列表
|
|
|
*/
|
|
|
// 映射/page请求路径,支持GET请求
|
|
|
@RequestMapping("/page")
|
|
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request) {
|
|
|
// 记录方法调用日志,包含控制器类名和请求参数
|
|
|
logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params));
|
|
|
// 从请求会话中获取用户角色
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
// 此条件永远为false,注释掉的代码表示永远不会进入该分支
|
|
|
if (false)
|
|
|
return R.error(511, "永不会进入");
|
|
|
// 如果用户角色为"用户"
|
|
|
else if ("用户".equals(role))
|
|
|
// 在请求参数中添加用户id
|
|
|
params.put("yonghuId", request.getSession().getAttribute("userId"));
|
|
|
// 如果用户角色为"医生"
|
|
|
else if ("医生".equals(role))
|
|
|
// 在请求参数中添加医生id
|
|
|
params.put("yishengId", request.getSession().getAttribute("userId"));
|
|
|
// 如果请求参数中没有指定排序字段,则默认按id排序
|
|
|
if (params.get("orderBy") == null || params.get("orderBy") == "") {
|
|
|
params.put("orderBy", "id");
|
|
|
}
|
|
|
// 调用挂号服务的queryPage方法,根据请求参数进行分页查询
|
|
|
PageUtils page = guahaoService.queryPage(params);
|
|
|
|
|
|
// 将分页结果中的列表转换为挂号视图列表
|
|
|
List<GuahaoView> list = (List<GuahaoView>) page.getList();
|
|
|
// 遍历挂号视图列表
|
|
|
for (GuahaoView c : list) {
|
|
|
// 调用字典服务的dictionaryConvert方法,修改对应字典表字段
|
|
|
dictionaryService.dictionaryConvert(c, request);
|
|
|
}
|
|
|
// 返回成功响应,并将分页查询结果放入响应数据中
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后端详情
|
|
|
*/
|
|
|
// 映射/info/{id}请求路径,支持GET请求,{id}为路径变量
|
|
|
@RequestMapping("/info/{id}")
|
|
|
public R info(@PathVariable("id") Long id, HttpServletRequest request) {
|
|
|
// 记录方法调用日志,包含控制器类名和请求的id
|
|
|
logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
|
|
|
// 调用挂号服务的selectById方法,根据id查询挂号实体
|
|
|
GuahaoEntity guahao = guahaoService.selectById(id);
|
|
|
// 如果查询到挂号实体
|
|
|
if (guahao != null) {
|
|
|
// 创建挂号视图对象
|
|
|
GuahaoView view = new GuahaoView();
|
|
|
// 使用BeanUtils将挂号实体的属性复制到挂号视图中
|
|
|
BeanUtils.copyProperties(guahao, view);
|
|
|
|
|
|
// 级联查询医生信息
|
|
|
YishengEntity yisheng = yishengService.selectById(guahao.getYishengId());
|
|
|
// 如果查询到医生信息
|
|
|
if (yisheng != null) {
|
|
|
// 将医生信息的部分属性复制到挂号视图中,并排除指定字段
|
|
|
BeanUtils.copyProperties(yisheng, view, new String[]{"id", "createTime", "insertTime", "updateTime"});
|
|
|
// 设置挂号视图中的医生id
|
|
|
view.setYishengId(yisheng.getId());
|
|
|
}
|
|
|
// 级联查询用户信息
|
|
|
YonghuEntity yonghu = yonghuService.selectById(guahao.getYonghuId());
|
|
|
// 如果查询到用户信息
|
|
|
if (yonghu != null) {
|
|
|
// 将用户信息的部分属性复制到挂号视图中,并排除指定字段
|
|
|
BeanUtils.copyProperties(yonghu, view, new String[]{"id", "createTime", "insertTime", "updateTime"});
|
|
|
// 设置挂号视图中的用户id
|
|
|
view.setYonghuId(yonghu.getId());
|
|
|
}
|
|
|
// 调用字典服务的dictionaryConvert方法,修改对应字典表字段
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
// 返回成功响应,并将挂号视图对象放入响应数据中
|
|
|
return R.ok().put("data", view);
|
|
|
} else {
|
|
|
// 如果未查询到数据,返回错误响应,错误码为511
|
|
|
return R.error(511, "查不到数据");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后端保存
|
|
|
*/
|
|
|
// 映射/save请求路径,支持POST请求
|
|
|
@RequestMapping("/save")
|
|
|
public R save(@RequestBody GuahaoEntity guahao, HttpServletRequest request) {
|
|
|
// 记录方法调用日志,包含控制器类名和要保存的挂号实体信息
|
|
|
logger.debug("save方法:,,Controller:{},,guahao:{}", this.getClass().getName(), guahao.toString());
|
|
|
// 从请求会话中获取用户角色
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
// 此条件永远为false,注释掉的代码表示永远不会进入该分支
|
|
|
if (false)
|
|
|
return R.error(511, "永远不会进入");
|
|
|
// 如果用户角色为"医生"
|
|
|
else if ("医生".equals(role))
|
|
|
// 设置挂号实体的医生id为当前会话中的用户id
|
|
|
guahao.setYishengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
|
|
// 如果用户角色为"用户"
|
|
|
else if ("用户".equals(role))
|
|
|
// 设置挂号实体的用户id为当前会话中的用户id
|
|
|
guahao.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
|
|
|
|
|
// 创建查询包装器,用于构建查询条件
|
|
|
Wrapper<GuahaoEntity> queryWrapper = new EntityWrapper<GuahaoEntity>()
|
|
|
.eq("yisheng_id", guahao.getYishengId())
|
|
|
.eq("yonghu_id", guahao.getYonghuId())
|
|
|
.eq("guahao_uuin_number", guahao.getGuahaoUuinNumber())
|
|
|
.eq("guahao_time", new SimpleDateFormat("yyyy-MM-dd").format(guahao.getGuahaoTime()))
|
|
|
.eq("guahao_types", guahao.getGuahaoTypes())
|
|
|
.eq("guahao_status_types", guahao.getGuahaoStatusTypes())
|
|
|
.eq("guahao_yesno_types", guahao.getGuahaoYesnoTypes())
|
|
|
.eq("guahao_yesno_text", guahao.getGuahaoYesnoText());
|
|
|
|
|
|
// 记录生成的SQL查询语句
|
|
|
logger.info("sql语句:" + queryWrapper.getSqlSegment());
|
|
|
// 调用挂号服务的selectOne方法,根据查询条件查询是否存在相同数据
|
|
|
GuahaoEntity guahaoEntity = guahaoService.selectOne(queryWrapper);
|
|
|
// 如果未查询到相同数据
|
|
|
if (guahaoEntity == null) {
|
|
|
// 设置挂号审核类型为1
|
|
|
guahao.setGuahaoYesnoTypes(1);
|
|
|
// 设置挂号实体的创建时间为当前时间
|
|
|
guahao.setCreateTime(new Date());
|
|
|
// 调用挂号服务的insert方法,将挂号实体插入数据库
|
|
|
guahaoService.insert(guahao);
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
} else {
|
|
|
// 如果查询到相同数据,返回错误响应,错误码为511
|
|
|
return R.error(511, "表中有相同数据");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后端修改
|
|
|
*/
|
|
|
// 映射/update请求路径,支持POST请求
|
|
|
@RequestMapping("/update")
|
|
|
public R update(@RequestBody GuahaoEntity guahao, HttpServletRequest request) {
|
|
|
// 记录方法调用日志,包含控制器类名和要修改的挂号实体信息
|
|
|
logger.debug("update方法:,,Controller:{},,guahao:{}", this.getClass().getName(), guahao.toString());
|
|
|
// 从请求会话中获取用户角色
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
// 此条件注释掉,表示永远不会进入该分支
|
|
|
// if (false)
|
|
|
// return R.error(511, "永远不会进入");
|
|
|
// else if ("医生".equals(role))
|
|
|
// guahao.setYishengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
|
|
// else if ("用户".equals(role))
|
|
|
// guahao.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
|
|
|
// 创建查询包装器,用于构建查询条件,排除当前要修改的记录
|
|
|
Wrapper<GuahaoEntity> queryWrapper = new EntityWrapper<GuahaoEntity>()
|
|
|
.notIn("id", guahao.getId())
|
|
|
.andNew()
|
|
|
.eq("yisheng_id", guahao.getYishengId())
|
|
|
.eq("yonghu_id", guahao.getYonghuId())
|
|
|
.eq("guahao_uuin_number", guahao.getGuahaoUuinNumber())
|
|
|
.eq("guahao_time", guahao.getGuahaoTime())
|
|
|
.eq("guahao_types", guahao.getGuahaoTypes())
|
|
|
.eq("guahao_status_types", guahao.getGuahaoStatusTypes())
|
|
|
.eq("guahao_yesno_types", guahao.getGuahaoYesnoTypes())
|
|
|
.eq("guahao_yesno_text", guahao.getGuahaoYesnoText());
|
|
|
|
|
|
// 记录生成的SQL查询语句
|
|
|
logger.info("sql语句:" + queryWrapper.getSqlSegment());
|
|
|
// 调用挂号服务的selectOne方法,根据查询条件查询是否存在相同数据
|
|
|
GuahaoEntity guahaoEntity = guahaoService.selectOne(queryWrapper);
|
|
|
// 如果未查询到相同数据
|
|
|
if (guahaoEntity == null) {
|
|
|
// 调用挂号服务的updateById方法,根据id更新挂号实体
|
|
|
guahaoService.updateById(guahao);
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
} else {
|
|
|
// 如果查询到相同数据,返回错误响应,错误码为511
|
|
|
return R.error(511, "表中有相同数据");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
|
// 映射/delete请求路径,支持POST请求
|
|
|
@RequestMapping("/delete")
|
|
|
public R delete(@RequestBody Integer[] ids) {
|
|
|
// 记录方法调用日志,包含控制器类名和要删除的记录id数组
|
|
|
logger.debug("delete:,,Controller:{},,ids:{}", this.getClass().getName(), ids.toString());
|
|
|
// 调用挂号服务的deleteBatchIds方法,根据id数组批量删除记录
|
|
|
guahaoService.deleteBatchIds(Arrays.asList(ids));
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量上传
|
|
|
*/
|
|
|
// 映射/batchInsert请求路径,支持POST请求
|
|
|
@RequestMapping("/batchInsert")
|
|
|
public R save(String fileName) {
|
|
|
// 记录方法调用日志,包含控制器类名和文件名
|
|
|
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}", this.getClass().getName(), fileName);
|
|
|
try {
|
|
|
// 创建一个列表,用于存储要上传的挂号实体
|
|
|
List<GuahaoEntity> guahaoList = new ArrayList<>();
|
|
|
// 创建一个Map,用于存储要查询的字段
|
|
|
Map<String, List<String>> seachFields = new HashMap<>();
|
|
|
// 获取当前时间
|
|
|
Date date = new Date();
|
|
|
// 获取文件名中最后一个点的索引
|
|
|
int lastIndexOf = fileName.lastIndexOf(".");
|
|
|
// 如果文件名中没有点,返回错误响应,错误码为511
|
|
|
if (lastIndexOf == -1) {
|
|
|
return R.error(511, "该文件没有后缀");
|
|
|
} else {
|
|
|
// 获取文件后缀
|
|
|
String suffix = fileName.substring(lastIndexOf);
|
|
|
// 如果文件后缀不是.xls,返回错误响应,错误码为511
|
|
|
if (!".xls".equals(suffix)) {
|
|
|
return R.error(511, "只支持后缀为xls的excel文件");
|
|
|
} else {
|
|
|
// 获取文件的URL
|
|
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);
|
|
|
// 创建文件对象
|
|
|
File file = new File(resource.getFile());
|
|
|
// 如果文件不存在,返回错误响应,错误码为511
|
|
|
if (!file.exists()) {
|
|
|
return R.error(511, "找不到上传文件,请联系管理员");
|
|
|
} else {
|
|
|
// 使用PoiUtil工具类读取xls文件的数据
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());
|
|
|
// 删除第一行数据,因为第一行通常是表头
|
|
|
dataList.remove(0);
|
|
|
// 遍历数据列表
|
|
|
for (List<String> data : dataList) {
|
|
|
// 创建一个新的挂号实体
|
|
|
GuahaoEntity guahaoEntity = new GuahaoEntity();
|
|
|
// 以下代码注释掉,表示需要根据实际情况修改字段赋值
|
|
|
// guahaoEntity.setYishengId(Integer.valueOf(data.get(0))); //医生 要改的
|
|
|
// guahaoEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
|
|
|
// guahaoEntity.setGuahaoUuinNumber(Integer.valueOf(data.get(0))); //就诊识别码 要改的
|
|
|
// guahaoEntity.setGuahaoTime(new Date(data.get(0))); //挂号时间 要改的
|
|
|
// guahaoEntity.setGuahaoTypes(Integer.valueOf(data.get(0))); //时间类型 要改的
|
|
|
// guahaoEntity.setGuahaoStatusTypes(Integer.valueOf(data.get(0))); //挂号状态 要改的
|
|
|
// guahaoEntity.setGuahaoYesnoTypes(Integer.valueOf(data.get(0))); //挂号审核 要改的
|
|
|
// guahaoEntity.setGuahaoYesnoText(data.get(0)); //审核结果 要改的
|
|
|
// guahaoEntity.setCreateTime(date);//时间
|
|
|
// 将挂号实体添加到上传列表中
|
|
|
guahaoList.add(guahaoEntity);
|
|
|
|
|
|
// 把要查询是否重复的字段放入map中
|
|
|
}
|
|
|
|
|
|
//
|