后端--排班管理
作者:互联网
后端--排班管理
一、排班管理需求分析
1、页面效果
排班分成三部分显示:
1、科室信息(大科室与小科室树形展示)
2、排班日期,分页显示,根据上传排班数据聚合统计产生
3、排班日期对应的就诊医生信息
2、接口分析
1,科室数据使用Element-ui el-tree组件渲染展示,需要将医院上传的科室数据封装成两层父子级数据;
2,聚合所有排班数据,按日期分页展示,并统计号源数据展示;
3,根据排班日期获取排班详情数据
3、实现分析
虽然是一个页面展示所有内容,但是页面相对复杂,我们分步骤实现
1,先实现左侧科室树形展示;
2,其次排班日期分页展示
3,最后根据排班日期获取排班详情数据
二、排班管理实现
1、科室列表
1.1、科室列表树形图展示后端接口
1.1.1、引入实体类模型
@Data
@ApiModel(description = "Department")
public class DepartmentVo {
@ApiModelProperty(value = "科室编号")
private String depcode;
@ApiModelProperty(value = "科室名称")
private String depname;
@ApiModelProperty(value = "下级节点")
private List<DepartmentVo> children;
}
1.1.2、控制层代码编写
@Api(tags = "科室信息管理")
@RestController
@RequestMapping("/admin/hosp/department")
@CrossOrigin
public class DepartmentController {
@Autowired
private DepartmentService departmentService;
@ApiOperation("查询医院所有科室列表")
@GetMapping("getDepartList/{hoscode}")
public Result getDeptList(@PathVariable String hoscode){
List<DepartmentVo> list = departmentService.getDeptList(hoscode);
return Result.ok(list);
}
}
1.1.3、业务层接口代码编写
//查询医院所有科室列表
List<DepartmentVo> getDeptList(String hoscode);
1.1.4、业务层实现类代码编写
//根据医院编号,查询医院所有科室信息,并对信息按照JSON格式进行封装
@Override
public List<DepartmentVo> getDeptList(String hoscode) {
//创建list集合,用于封装最终数据
List<DepartmentVo> result = new ArrayList<>();
//1、根据前端传递的医院编号,查询所有科室信息。
//创建一个Department对象,用于封装查询条件
Department departmentQuery = new Department();
departmentQuery.setHoscode(hoscode);
//封装查询条件
Example example = Example.of(departmentQuery);
//查询mongoDB数据库中存放的所有科室信息
List<Department> departmentList = departmentRepository.findAll(example);
//2、根据大科室编号 bigcode 分组,获取每个大科室里面下级子科室
Map<String, List<Department>> departmentMap =
departmentList.stream().collect(Collectors.groupingBy(Department::getBigcode));
//遍历Map集合departmentMap
for(Map.Entry<String, List<Department>> entry : departmentMap.entrySet()){
//获取大的科室编号
String bigcode = entry.getKey();
//获取大科室标号对应的所有数据
List<Department> departmentList1 = entry.getValue();
//封装大科室
DepartmentVo departmentVo1 = new DepartmentVo();
departmentVo1.setDepcode(bigcode);
departmentVo1.setDepname(departmentList1.get(0).getBigname());
//封装小科室
List<DepartmentVo> children = new ArrayList<>();
for(Department department: departmentList1) {
DepartmentVo departmentVo2 = new DepartmentVo();
departmentVo2.setDepcode(department.getDepcode());
departmentVo2.setDepname(department.getDepname());
//封装到list集合
children.add(departmentVo2);
}
//将小科室信息放到大科室中
departmentVo1.setChildren(children);
//将封装的信息放到最终返回的list集合中
result.add(departmentVo1);
}
return result;
}
1.1.5、业务层实现类代码讲解
1.1.6、swagger测试
1.2、科室列表树形图展示前端展示
1.2.1、添加隐藏路由
{
path: 'hospital/schedule/:hoscode',
name: '排班',
component: () => import('@/views/hospital/schedule'),
meta: { title: '排班', icon: 'table' },
hidden:true
}
1.2.2、在医院列表页添加医院排班的按钮
<router-link :to="'/hospSet/hospital/show/'+scope.row.hoscode">
<el-button type="primary" size="mini">排班</el-button>
</router-link>
1.2.3、在js文件中编写调用后端接口的方法
//查看医院科室
getScheduleByHoscode(hoscode){
return request({
url:`/admin/hosp/department/getDepartList/${hoscode}`,
method:'get'
})
}
1.2.4、修改/views/hospital/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>
js代码:
<script>
import hospital from '@/api/hospital'
export default{
data(){
return {
data:[],
defaultProps: {//表示children这些数据要做一个树形结构显示
children: 'children',
label: 'depname'
},
hoscode:null//医院编号
}
},
created(){
//获取医院编号
this.hoscode = this.$route.params.hoscode
//调用方法初始化数据
this.fetchData()
},
methods:{
fetchData(){
hospital.getScheduleByHoscode(this.hoscode)
.then(response=>{
this.data = response.data
})
}
}
}
</script>
css样式
// 页面css样式
<style>
.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>
2、科室排班
2.1、后端接口
2.1.1、控制层代码
@RestController
@RequestMapping("/admin/hosp/schedule")
@CrossOrigin
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
//根据 医院编号 和 科室编号,查询排班规则信息
@ApiOperation("查询排班规则信息")
@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.getScheduleRule(page,limit,hoscode,depcode);
return Result.ok(map);
}
}
2.1.2、业务层接口代码
//根据 医院编号 和 科室编号,查询排班规则信息
Map<String, Object> getScheduleRule(Long page, Long limit, String hoscode, String depcode);
2.1.3、业务层实现类代码
//根据 医院编号 和 科室编号,查询排班规则信息
@Override
public Map<String, Object> getScheduleRule(Long page, Long limit, String hoscode, String depcode) {
//1、根据医院编号 和 科室 编号查询
Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode);
//2、根据工作日期workDate进行分组
Aggregation agg = Aggregation.newAggregation(
Aggregation.match(criteria),//匹配条件
Aggregation.group("workDate")//分组字段
.first("workDate").as("workDate")
//3、统计号源数量
.count().as("docCount")
.sum("reservedNumber").as("reservedNumber")
.sum("availableNumber").as("availableNumber"),
//排序
Aggregation.sort(Sort.Direction.DESC,"workDate"),
//4、实现分页
Aggregation.skip((page-1)*limit),
Aggregation.limit(limit)
);
//调用方法,最终执行
AggregationResults<BookingScheduleRuleVo> aggResults =
mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
List<BookingScheduleRuleVo> bookingScheduleRuleVoList = aggResults.getMappedResults();
//分组查询记录总数
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();
//获取对应日期是星期几
for(BookingScheduleRuleVo bookingScheduleRuleVo:bookingScheduleRuleVoList){
Date workDate = bookingScheduleRuleVo.getWorkDate();
String dayOfWeek = this.getDayOfWeek(new DateTime(workDate));
bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
}
//设置最终数据,进行返回
Map<String, Object> result = new HashMap<>();
result.put("bookingScheduleRuleList",bookingScheduleRuleVoList);
result.put("total",total);
//获取医院名称
String hosName = hospitalService.getHospName(hoscode);
//其他基础数据
Map<String, String> baseMap = new HashMap<>();
baseMap.put("hosname",hosName);
result.put("baseMap",baseMap);
return result;
}
/**
* 根据日期获取周几数据
* @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.2、前端页面
2.2.1、js代码
//查询预约规则
getScheduleRule(page,limit,hoscode,depcode){
return request({
url:`/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`,
method:'get'
})
}
2.2.1、页面组件
<template>
<div class="app-container">
<!-- <div style="margin-bottom: 10px;font-size: 10px;">
选择:{{ baseMap.hosname }} / {{ 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 hospital from '@/api/hospital'
export default{
data(){
return {
data:[],
defaultProps: {//表示children这些数据要做一个树形结构显示
children: 'children',
label: 'depname'
},
hoscode:null,//医院编号
activeIndex: 0,
depcode: null,
depname: null,
workDate: null,
bookingScheduleList: [],
baseMap: {},
page: 1, // 当前页
limit: 7, // 每页个数
total: 0 // 总页码
}
},
created(){
//获取医院编号
this.hoscode = this.$route.params.hoscode
//调用方法初始化数据
this.fetchData()
this.workDate = this.getCurDate()
},
methods:{
fetchData(){
hospital.getScheduleByHoscode(this.hoscode)
.then(response=>{
this.data = response.data
// 默认选中第一个
if (this.data.length > 0) {
this.depcode = this.data[0].children[0].depcode
this.depname = this.data[0].children[0].depname
this.getPage()
}
})
},
getPage(page = 1) {
this.page = page
this.workDate = null
this.activeIndex = 0
this.getScheduleRule()
},
getScheduleRule() {
hospital.getScheduleRule(this.page, this.limit, this.hoscode, this.depcode).then(response => {
this.bookingScheduleList = response.data.bookingScheduleRuleList
this.total = response.data.total
this.scheduleList = response.data.scheduleList
this.baseMap = response.data.baseMap
// 分页后workDate=null,默认选中第一个
if (this.workDate == null) {
this.workDate = this.bookingScheduleList[0].workDate
}
})
},
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
},
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
}
}
}
</script>
// 页面css样式
<style>
.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>
标签:hoscode,workDate,String,后端,--,科室,排班,data 来源: https://blog.csdn.net/qq_46112274/article/details/117551213