需求分析
1、页面效果
排班管理这是我们想要实现的页面,从mongodb中获取数据显示到页面上
排班分成三部分显示:
1、科室信息(大科室与小科室树形展示)
2、排班日期,分页显示,根据上传排班数据聚合统计产生
3、排班日期对应的就诊医生信息
2、接口分析
1,科室数据使用Element-ui el-tree组件渲染展示,需要将医院上传的科室数据封装成两层父子级数据;
2,聚合所有排班数据,按日期分页展示,并统计号源数据展示;
3,根据排班日期获取排班详情数据
3、实现分析
虽然是一个页面展示所有内容,但是页面相对复杂,我们分步骤实现
1,先实现左侧科室树形展示;
2,其次排班日期分页展示
3,最后根据排班日期获取排班详情数据
排班管理实现
1.科室列表
根据hoscode查询数据库
Controller
@RestController
@RequestMapping("/admin/hosp/department")
//@CrossOrigin
public class DepartmentController {
@Autowired
private DepartmentService departmentService;
//根据医院的编号查询所有科室列表
@ApiOperation(value = "查询医院所有科室列表")
@GetMapping("getDeptList/{hoscode}")
public Result getDeptList(@PathVariable String hoscode){
List<DepartmentVo> departmentVoList =departmentService.getDeptTree(hoscode);
return Result.ok(departmentVoList);
}
}
Service
//根据医院编号,查询医院所有科室列表
@Override
public List<DepartmentVo> getDeptTree(String hoscode) {
//创建一个list集合,用于最终数据的封装
List<DepartmentVo> result = new ArrayList<>();
//根据医院编号,查询医院所有科室信息
Department departmentQuery = new Department();
departmentQuery.setHoscode(hoscode);
Example example = Example.of(departmentQuery);
//所有科室列表
List<Department> all = departmentRepository.findAll(example);
//根据大科室编号bigcode分组
Map<String, List<Department>> listMap = all.stream().collect(Collectors.groupingBy(Department::getBigcode));
for (Map.Entry<String,List<Department>> entry:listMap.entrySet()){
//大科室编号
String bigcode = entry.getKey();
//大科室对应的全局数据
List<Department> departmentList = entry.getValue();
//封装大科室
DepartmentVo departmentVo = new DepartmentVo();
departmentVo.setDepcode(bigcode);
departmentVo.setDepname(departmentList.get(0).getBigname());
//封装小科室
List<DepartmentVo> childrenList = new ArrayList<>();
for(Department department:departmentList){
DepartmentVo departmentQueryVo1 = new DepartmentVo();
departmentQueryVo1.setDepname(department.getDepname());
departmentQueryVo1.setDepcode(department.getDepcode());
childrenList.add(departmentQueryVo1);
}
//把小科室的list放到大科室children里面
departmentVo.setChildren(childrenList);
//放到result里面
result.add(departmentVo);
}
return result;
}
前端
src\api\hosp.js
//查看科室详情
getschedule(hoscode) {
return request({
//GET /admin/hosp/department/getDeptList/{hoscode}
url: `/admin/hosp/department/getDeptList/${hoscode}`,
method: 'get'
})
},
src\router\index.js
{
path: 'hospital/schedule/:hoscode',
name: '排班',
component: () => import('@/views/hosp/schedule'),
meta: { title: '排班', noCache: true },
hidden: true
},
src\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 {
data: [],
defaultProps: {
children: 'children',
label: 'depname'
},
hoscode: null
}
},
created(){
this.hoscode = this.$route.params.hoscode
this.fetchData()
},
methods:{
fetchData() {
hospApi.getDeptByHoscode(this.hoscode)
.then(response => {
this.data = response.data
})
}
}
}
</script>
<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>
这样我们的显示就做好了
日期显示
Controller
@RestController
@RequestMapping("/admin/hosp/schedule")
//@CrossOrigin
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
//根据医院编号和科室查询排班规律
@ApiOperation(value = "查询排班规则数据")
@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.getRuleSchedule(page,limit,hoscode,depcode);
return Result.ok(map);
}
}
Service
我们这段代码的逻辑
1.根据医院编号和科室设置成一个条件
2.设置聚合操作,先根据工作日期进行排序,然后进行统计号源,最后进行分页
3.通过上面设置的条件进行查询得到bookingScheduleRuleVoList
4.获取分组查询的总记录数同时把日期对应的星期获取通过getDayOfWeek
5.把上面所有的数据全部进行封装返回
@Override
public Map<String, Object> getRuleSchedule(long page, long limit, String hoscode, String depcode) {
// 1.根据医院编号和科室编号查询
Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode);
// 2.根据工作日workData进行分组
// 构造条件
// 用于做聚合操作
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)
);
//查询
List<BookingScheduleRuleVo> bookingScheduleRuleVoList = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class).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);
}
//设置最终的数据
HashMap<String, Object> Result = new HashMap<>();
Result.put("bookingScheduleRuleVoList",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;
}
前端
创建/api/hosp/schedule.js
getScheduleRule(page, limit, hoscode, depcode) {
return request({
url: `/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`,
method: 'get'
})
}
修改/views/hosp/schedule.vue组件
<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 hospApi from '@/api/hosp'
export default {
data() {
return {
data: [],
defaultProps: {
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.workDate = this.getCurDate()
this.fetchData()
},
methods:{
fetchData() {
hospApi.getDeptByHoscode(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() {
hospApi.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>
<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>
排班详情
controller根据医院编号,科室编号,工作日期,查询排班详细信息
//根据医院编号,科室编号,工作日期,查询排班详细信息
@ApiOperation(value = "查询排班详细信息")
@GetMapping("getScheduleDetail/{hoscode}/{depcode}/{workDate}")
public Result getScheduleDetail(@PathVariable String hoscode,
@PathVariable String depcode,
@PathVariable String workDate){
List<Schedule> scheduleList = scheduleService.getScheduleDetail(hoscode,depcode,workDate);
return Result.ok(scheduleList);
}
Service
//根据医院编号,科室编号,工作日期,查询排班详细信息
@Override
public List<Schedule> getScheduleDetail(String hoscode, String depcode, String workDate) {
List<Schedule> scheduleList = scheduleRepository.findScheduleByHoscodeAndDepcodeAndWorkDate(hoscode,depcode,new DateTime(workDate).toDate());
//遍历list集合,向设置其他值,医院名称,科室名称,日期对应星期
scheduleList.stream().forEach(item -> {
this.packageSchedule(item);
});
return scheduleList;
}
private void packageSchedule(Schedule item) {
//设置医院的名称
item.getParam().put("hosname",hospitalService.getHospName(item.getHoscode()));
//设置科室名称
item.getParam().put("depname",departmentService.getDepName(item.getHoscode(),item.getDepcode()));
//设置日期对应星期
item.getParam().put("dayOfWeek",this.getDayOfWeek(new DateTime(item.getWorkDate())));
}
/**
* 根据日期获取周几数据
* @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;
}
前端
src\api\hosp.js
//查询排班详情
getScheduleDetail(hoscode,depcode,workDate){
return request({
url: `/admin/hosp/schedule/getScheduleDetail/${hoscode}/${depcode}/${workDate}`,
method: 'get'
})
}
src\views\hosp\schedule.vue
<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-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 }}
</template>
</el-table-column>
<el-table-column label="号源时间" width="80">
<template slot-scope="scope">
{{ scope.row.workTime == 0 ? "上午" : "下午" }}
</template>
</el-table-column>
<el-table-column
prop="reservedNumber"
label="可预约数"
width="80"
/>
<el-table-column
prop="availableNumber"
label="剩余预约数"
width="100"
/>
<el-table-column prop="amount" label="挂号费(元)" width="90" />
<el-table-column prop="skill" label="擅长技能" />
</el-table>
</el-row>
</el-main>
</el-container>
</div>
</template>
<script>
import hospApi from "@/api/hosp";
export default {
data() {
return {
data: [],
defaultProps: {
children: "children",
label: "depname",
},
hoscode: null,
activeIndex: 0,
depcode: null,
depname: null,
workDate: null,
bookingScheduleList: [],
baseMap: {},
page: 1, // 当前页
limit: 7, // 每页个数
total: 0, // 总页码
scheduleList:[],
};
},
created() {
this.hoscode = this.$route.params.hoscode;
this.workDate = this.getCurDate();
this.fetchData();
},
methods: {
//查询【排班的详情
egtscheduleList(){
hospApi.getScheduleDetail(this.hoscode,this.depcode,this.workDate)
.then(response => {
this.scheduleList = response.data
})
},
fetchData() {
hospApi.getschedule(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() {
hospApi
.getScheduleRule(this.page, this.limit, this.hoscode, this.depcode)
.then((response) => {
this.bookingScheduleList = response.data.bookingScheduleRuleVoList;
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;
}
//调用
this.egtscheduleList()
});
},
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;
this.egtscheduleList();
},
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>
<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>