Day232&233
[](()1.2 科室前端
[](()1.2.1 添加路由
在 src/router/index.js 文件添加排班隐藏路由
{
path: 'hosp/schedule/:hoscode',
name: '排班',
component: ()=> import('@/views/hosp/schedule.vue'),
meta:{title: '排班',icon:'table',nocache:'true'},
hidden: true
}
[](()1.2.2 添加按钮
在医院列表页面,添加排班按钮
<router-link :to="'/hospSet/hosp/schedule/'+scope.row.hoscode">
<el-button type="info" size="mini">查看排班</el-button>
</router-link>
[](()1.2.3 封装 api 请求
//获取医院科室,根据医院编号
getDeptByHoscode(hoscode){
return request({
url: /admin/hosp/department/getDeptList/${hoscode}
,
method: 'get'
})
}
[](()1.2.4 部门展示
修改/views/hosp/schedule.vue 组件
<template>
<div class="app-container">
<div style="margin-bottom: 10px;font-size: 10px;">选择:</div>
<el-container style="height: 100%">
<el-aside width="200px" style="border: 1px silver solid">
<el-tree
:data="data"
:props="defaultProps"
:default-expand-all="true"
@node-click="handleNodeClick">
</el-tree>
</el-aside>
<el-main style="padding: 0 0 0 20px;">
<el-row style="width: 100%">
</el-row>
<el-row style="margin-top: 20px;">
</el-row>
</el-main>
</el-container>
</div>
</template>
<script>
import hospAPI from '@/api/hosp'
export default {
data(){
return{
hoscode:null,
data:[],
defaultProps:{
children:'children',
label:'depname'
},
}
},
created(){
this.hoscode = this.$route.params.hoscode
this.getDeptByHoscode()
},
methods:{
getDeptByHoscode(){
hospAPI.getDeptByHoscode(this.hoscode).then(resp=>{
this.data = resp.data
console.log(this.data)
})
},
}
}
</script>
<style scoped>
.el-tree-node.is-current > .el-tree-node__content {
background-color: #409EFF !important;
color: white;
}
.el-checkbox__input.is-checked+.el-checkbox__label {
color: black;
}
</style>
说明:底部 style 标签是为了控制树形展示数据选中效果的
[](()2、排班日期分页列表
[](()2.1 api 接口
[](h 《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 ttps://achang.blog.csdn.net/article/details/115284546)2.1.1 添加 service 接口与实现
在 ScheduleService 类添加接口
//根据【医院编号】 【科室编号】,【分页查询】排版规则数据
Map<String, Object> getScheduleRulePage(long page, long limit, String hoscode, String depcode);
在 ScheduleServiceImpl 类实现接口
package com.achang.yygh.hosp.service.impl;
import com.achang.exception.YyghException;
import com.achang.utils.DateUtil;
import com.achang.yygh.hosp.repository.ScheduleRepository;
import com.achang.yygh.hosp.service.HospitalService;
import com.achang.yygh.hosp.service.HospitalSetService;
import com.achang.yygh.hosp.service.ScheduleService;
import com.achang.yygh.model.hosp.Department;
import com.achang.yygh.model.hosp.Schedule;
import com.achang.yygh.vo.hosp.BookingScheduleRuleVo;
import com.achang.yygh.vo.hosp.ScheduleQueryVo;
import com.alibaba.fastjson.JSONObject;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private HospitalService hospitalService;
//根据【医院编号】 【科室编号】,【分页查询】排版规则数据
@Override
public Map<String, Object> getScheduleRulePage(long page, long limit, String hoscode, String depcode) {
//根据医院编号、科室编号 查询对应数据
//封装查询条件
Criteria criteria = Criteria.where("hoscode").is(hoscode)
.and("depcode").is(depcode);
//根据工作日 workDate 期进行分组
Aggregation agg = Aggregation.newAggregation(
Aggregation.match(criteria),//条件匹配
Aggregation.group("workDate")//分组字段
.first("workDate").as("workDate")//设置分组后的别名
.count().as("docCount")//统计号源数量并设置名字
.sum("reservedNumber").as("reservedNumber")//求和 reservedNumber 字段
.sum("availableNumber").as("availableNumber"),//求和 availableNumber 字段
Aggregation.sort(Sort.Direction.DESC,"workDate"),//指定是升序还是降序,指定哪个字段排序
//分页
Aggregation.skip((page-1)*limit),//(当前页-1)*每页记录数
Aggregation.limit(limit)//每页显示数
);
//得到分组查询后的总记录数
Aggregation totalAgg = Aggregation.newAggregation(
Aggregation.match(criteria),//条件查询
Aggregation.group("workDate")//分组)
);
AggregationResults<BookingScheduleRuleVo> totalAggResults = mongoTemplate.aggregate(totalAgg, Schedule.class, BookingScheduleRuleVo.class);
//获取总记录数
int total = totalAggResults.getMappedResults().size();
//调用方法最终执行
//参数 1:上面封装的条件
//参数 2:之前的实体类
//参数 3:最后封装的尸体类
AggregationResults<BookingScheduleRuleVo> results = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
//获取到最终的集合
List<BookingScheduleRuleVo> ruleVoList = results.getMappedResults();
//把日期对应的星期获取出来
for (BookingScheduleRuleVo bookingScheduleRuleVo:ruleVoList){
Date workDate = bookingScheduleRuleVo.getWorkDate();
//获取到星期几
String week = DateUtil.getDayOfWeek(new DateTime(workDate));
bookingScheduleRuleVo.setDayOfWeek(week);
}
//设置最终数据进行返回
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("list",ruleVoList);
resultMap.put("total",total);
//根据医院编号,获取医院名称
String hospName = hospitalService.getHospName(hoscode);
//其他基础数据
HashMap<String, String> baseMap = new HashMap<>();
baseMap.put("hospName",hospName);
resultMap.put("baseMap",baseMap);
return resultMap;
}
/**
根据日期获取周几数据
@param dateTime
@return
*/
private String getDayOfWeek(DateTime dateTime) {
String dayOfWeek = "";
switch (dateTime.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
dayOfWeek = "周日";
break;
case DateTimeConstants.MONDAY:
dayOfWeek = "周一";
break;
case DateTimeConstants.TUESDAY:
dayOfWeek = "周二";
break;
case DateTimeConstants.WEDNESDAY:
dayOfWeek = "周三";
break;
case DateTimeConstants.THURSDAY:
dayOfWeek = "周四";
break;
case DateTimeConstants.FRIDAY:
dayOfWeek = "周五";
break;
case DateTimeConstants.SATURDAY:
dayOfWeek = "周六";
default:
break;
}
return dayOfWeek;
}
}
[](()2.1.2 添加根据医院编号获取医院名称接口
在 HospitalService 类添加接口
//根据医院编号,获取医院名称
String getHospName(String hoscode);
在 HospitalServiceImpl 类实现接口
//根据医院编号,获取医院名称
@Override
public String getHospName(String hoscode) {
Hospital hospital = hospitalRepository.getHospitalByHoscode(hoscode);
if (hospital!=null){
return hospital.getHosname();
}
return null;
}
[](()2.1.3 添加 controller 接口
添加 com.atguigu.yygh.hosp.controller.ScheduleController 类
import com.achang.result.Result;
import com.achang.yygh.hosp.service.ScheduleService;
import com.achang.yygh.model.hosp.Schedule;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("/admin/hosp/Schedule")
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
//根据【医院编号】 【科室编号】,【分页查询】排版规则数据
@GetMapping("/getScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
public Result getScheduleRule(@PathVariable long page,
@PathVariable long limit,
@PathVariable String hoscode,
@PathVariable String depcode){
Map<String,Object> map = scheduleService.getScheduleRulePage(page,limit,hoscode,depcode);
return Result.ok(map);
}
}
测试
[](()2.2 排班日期前端
[](()1.2.1 封装 api 请求
创建/api/hosp/schedule.js
import request from '@/utils/request'
export default {
//根据【医院编号】 【科室编号】,【分页查询】排版规则数据
getScheduleRule(page,limit,hoscode,depcode) {
return request({
url: /admin/hosp/Schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}
,
method: 'get'
})
}
}
[](()1.2.2 页面展示
修改/views/hosp/schedule.vue 组件
<template>
<div class="app-container">
<div style="margin-bottom: 10px;font-size: 10px;">选择:{{ baseMap.hospName }} / {{ depname }} / {{ workDate }}</div>
<el-container style="height: 100%">
<el-aside width="200px" style="border: 1px silver solid">
<el-tree
:data="data"
:props="defaultProps"
:default-expand-all="true"
@node-click="handleNodeClick">
</el-tree>
</el-aside>
<el-main style="padding: 0 0 0 20px;">
<el-row style="width: 100%">
<el-tag v-for="(item,index) in bookingScheduleList" :key="item.id" @click="selectDate(item.workDate, index)"
:type="index == activeIndex ? '' : 'info'"
style="height: 60px;margin-right: 5px;margin-right:15px;cursor:pointer;">
{{ item.workDate }} {{ item.dayOfWeek }}<br/>
{{ item.availableNumber }} / {{ item.reservedNumber }}
</el-tag>
<el-pagination
:current-page="page"
:total="total"
:page-size="limit"
class="pagination"
layout="prev, pager, next"
@current-change="getPage">
</el-pagination>
</el-row>
<el-row style="margin-top: 20px;">
</el-row>
</el-main>
</el-container>
</div>
</template>
<script>
import hospAPI from '@/api/hosp'
import scheduleAPI from '@/api/schedule'
export default {
data() {
return {
bookingScheduleList: [],
hoscode: null,
data: [],
defaultProps: {
children: 'children',
label: 'depname'
},
activeIndex: 0,
depcode: null,
depname: null,
workDate: null,
baseMap: {},
page: 1, // 当前页
limit: 7, // 每页个数
total: 0 // 总页码
}
},
created() {
this.hoscode = this.$route.params.hoscode
this.workDate = this.getCurDate()
this.getDeptByHoscode()
},
methods: {
getDeptByHoscode() {
hospAPI.getDeptByHoscode(this.hoscode).then(resp => {
this.data = resp.data
console.log(this.data)
//默认选中第一个
if (this.data.length > 0) {
this.depcode = this.data[0].children[0].depcode
this.depname = this.data[0].children[0].depname
//刷新页面
this.getPage()
}
})
},
//得到当前日期
getCurDate() {
var datetime = new Date()
var year = datetime.getFullYear()
var month = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1
var date = datetime.getDate() < 10 ? '0' + datetime.getDate() : datetime.getDate()
return year + '-' + month + '-' + date
},
//根据【医院编号】 【科室编号】,【分页查询】排版规则数据
getScheduleRule() {
scheduleAPI.getScheduleRule(this.page, this.limit, this.hoscode, this.depcode).then(resp => {
console.log(resp.data)
this.bookingScheduleList = resp.data.list
this.total = resp.data.total
this.scheduleList = resp.data.scheduleList
this.baseMap = resp.data.baseMap
// 分页后 workDate=null,默认选中第一个
if (this.workDate == null) {
this.workDate = this.bookingScheduleList[0].workDate
}
})
},
//分页查询
getPage(page = 1) {
this.page = page
this.workDate = null
this.activeIndex = 0
this.getScheduleRule()
},
handleNodeClick(data) {
// 科室大类直接返回
if (data.children != null) return
this.depcode = data.depcode
this.depname = data.depname
this.getPage(1)
},
selectDate(workDate, index) {
this.workDate = workDate
this.activeIndex = index
},
}
}
</script>
<style scoped>
.el-tree-node.is-current > .el-tree-node__content {
background-color: #409EFF !important;
color: white;
}
.el-checkbox__input.is-checked + .el-checkbox__label {
color: black;
}
</style>
效果显示
[](()3、根据排班日期获取排班详情列表
[](()3.1 api 接口
[](()3.1.1 添加 repository 接口
在 ScheduleRepository 类添加接口
//根据医院编号、科室编号、工作日期,查询排版详细信息
List<Schedule> findScheduleByHoscodeAndDepcodeAndWorkDate(String hoscode, String depcode, Date toDate);
[](()3.1.2 添加 service 接口与实现
在 ScheduleService 类添加接口
//根据医院编号、科室编号、工作日期,查询排版详细信息
List<Schedule> getScheduleDetail(String hoscode, String depcode, String workDate);
在 ScheduleServiceImpl 类实现接口
//根据医院编号、科室编号、工作日期,查询排版详细信息
@Override
public List<Schedule> getScheduleDetail(String hoscode, String depcode, String workDate) {
//根据参数,查询 mongodb
List<Schedule> scheduleList = scheduleRepository.findScheduleByHoscodeAndDepcodeAndWorkDate(hoscode,depcode,new DateTime(workDate).toDate());
//遍历 list 集合,设置每个元素对应的属性
//使用 stream 流遍历
scheduleList.stream().forEach(item->{
this.packageSchedule(item);
});
return scheduleList;
}
//封装其他值:医院名称,科室名称,日期对应的星期
private void packageSchedule(Schedule item) {
Map<String, Object> map = item.getParam();
//获取医院名称
String hospName = hospitalService.getHospName(item.getHoscode());
//根据医院编号、科室编号,获取科室名称
String deptName = departmentService.getDeptName(item.getHoscode(),item.getDepcode());
//获取日期对应的星期
String week = DateUtil.getDayOfWeek(new DateTime(item.getWorkDate()));
map.put("hospName",hospName);
map.put("deptName",deptName);
map.put("week",week);
}
[](()3.1.3 添加根据部门编码获取部门名称
1,在 DepartmentService 类添加接口
//根据医院编号、科室编号,获取科室名称
String getDeptName(String hoscode, String depcode);
2,在 DepartmentService 类添加接口实现
//根据医院编号、科室编号,获取科室名称
@Override
public String getDeptName(String hoscode, String depcode) {
Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode,depcode);
if (department!=null){
return department.getDepname();
}
return null;
}
[](()3.1.4 添加 controller
//根据医院编号、科室编号、工作日期,查询排版详细信息
@GetMapping("/getScheduleDetail/{hoscode}/{depcode}/{workDate}")
public Result getScheduleDetail(@PathVariable String hoscode,
@PathVariable String depcode,
@PathVariable String workDate){
List<Schedule> list = scheduleService.getScheduleDetail(hoscode,depcode,workDate);
return Result.ok(list);
}
[](()3.2 排班日期前端
[](()3.2.1 封装 api 请求
在/api/hosp/schedule.js 文件添加方法
//根据医院编号、科室编号、工作日期,查询排版详细信息
getScheduleDetail(hoscode,depcode,workDate) {
return request({
url: /admin/hosp/Schedule/getScheduleDetail/${hoscode}/${depcode}/${workDate}
,
method: 'get'
})
},
[](()1.2.2 页面展示
修改/views/hosp/schedule.vue 组件
<template>
<div class="app-container">
<div style="margin-bottom: 10px;font-size: 10px;">选择:{{ baseMap.hospName }} / {{ depname }} / {{ workDate }}</div>
<el-container style="height: 100%">
<el-aside width="200px" style="border: 1px silver solid">
<el-tree
:data="data"
:props="defaultProps"
:default-expand-all="true"
@node-click="handleNodeClick">
</el-tree>
</el-aside>
<el-main style="padding: 0 0 0 20px;">
<el-row style="width: 100%">
<el-tag v-for="(item,index) in bookingScheduleList" :key="item.id" @click="selectDate(item.workDate, index)"
:type="index == activeIndex ? '' : 'info'"
style="height: 60px;margin-right: 5px;margin-right:15px;cursor:pointer;">
{{ item.workDate }} {{ item.dayOfWeek }}<br/>
{{ item.availableNumber }} / {{ item.reservedNumber }}
</el-tag>
<el-pagination
:current-page="page"
:total="total"
:page-size="limit"
class="pagination"
layout="prev, pager, next"
@current-change="getPage">
</el-pagination>
</el-row>
<el-row style="margin-top: 20px;">
<el-table
v-loading="listLoading"
:data="scheduleList"
border
fit
highlight-current-row>
<el-table-column
label="序号"
width="60"
align="center">
<template slot-scope="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column label="职称" width="150">
<template slot-scope="scope">
{{ scope.row.title }} | {{ scope.row.docname }}
评论