package com.ltkj.web.controller.system; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ltkj.common.annotation.Log; import com.ltkj.common.core.controller.BaseController; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.core.domain.entity.*; import com.ltkj.common.core.page.TableDataInfo; import com.ltkj.common.enums.BusinessType; import com.ltkj.common.utils.DateUtils; import com.ltkj.common.utils.poi.ExcelUtil; import com.ltkj.hosp.dto.MallSchedulingTimeDto; import com.ltkj.hosp.service.IDictUserInfoService; import com.ltkj.hosp.vodomain.DoctorUserVo; import com.ltkj.mall.service.IMallSchedulingTimeService; import com.ltkj.system.domain.SysUserRole; import com.ltkj.system.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.*; import java.util.stream.Collectors; /** * 排班时间Controller * * @author ltkj_赵佳豪&李格 * @date 2023-07-18 */ @RestController @RequestMapping("/mall/schedulingTime") @Api(tags = "PC端医生排班接口") public class StjSchedulingTimeController extends BaseController { @Autowired private IMallSchedulingTimeService mallSchedulingTimeService; @Autowired private ISysUserService userService; @Resource private IDictUserInfoService userInfoService; @Autowired private ISysDeptService deptService; @Autowired private SysUserRoleService userRoleService; /** * 查询排班时间是否存在 */ @GetMapping("/isExist") public AjaxResult isExist(@RequestParam String time) { if (time != null) { LambdaQueryWrapper wq=new LambdaQueryWrapper<>(); wq.eq(MallSchedulingTime::getTime,time); List list = mallSchedulingTimeService.list(wq); if (list!=null&&list.size()>0){ return AjaxResult.success(1); }else { return AjaxResult.success(0); } } return AjaxResult.error("出错了,请联系工作人员!"); } /** * 查询排班时间列表 */ @GetMapping("/list") @ApiOperation(value = "查询排班时间列表") public TableDataInfo list(MallSchedulingTime mallTimeConfig) { startPage(); List list = mallSchedulingTimeService.selectMallTimeConfigList(mallTimeConfig); return getDataTable(list); } /** * 导出排班时间列表 */ // @PreAuthorize("@ss.hasPermi('mall:timeConfig:export')") @Log(title = "排班时间", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, MallSchedulingTime mallTimeConfig) { List list = mallSchedulingTimeService.selectMallTimeConfigList(mallTimeConfig); ExcelUtil util = new ExcelUtil(MallSchedulingTime.class); util.exportExcel(response, list, "排班时间数据"); } /** * 获取排班时间详细信息 */ // @PreAuthorize("@ss.hasPermi('mall:timeConfig:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(mallSchedulingTimeService.getById(id)); } /** * 返回当前表中最大时间 */ @GetMapping("/returnLastTime") public AjaxResult returnLastTime() { final MallSchedulingTime one = mallSchedulingTimeService.getOne(new LambdaQueryWrapper().orderByDesc(MallSchedulingTime::getTime).last("limit 1")); if (one!=null&&one.getTime().getTime()>new Date().getTime()){ Calendar calendar = Calendar.getInstance(); calendar.setTime(one.getTime()); calendar.add(Calendar.DATE, 1); Date nextDate = calendar.getTime(); return AjaxResult.success(nextDate); }else if (one!=null&&one.getTime().getTime() schedulingTimeList) { if(null !=schedulingTimeList && schedulingTimeList.size()>0){ for (MallSchedulingTime schedulingTime : schedulingTimeList) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(MallSchedulingTime::getDeptId,schedulingTime.getDeptId()); wq.eq(MallSchedulingTime::getTime,schedulingTime.getTime()); wq.eq(MallSchedulingTime::getTimeSlot,schedulingTime.getTimeSlot()); wq.eq(MallSchedulingTime::getUserId,schedulingTime.getUserId()); wq.eq(MallSchedulingTime::getMOrA,schedulingTime.getMOrA()); MallSchedulingTime mallSchedulingTime = mallSchedulingTimeService.getOne(wq); if(null !=mallSchedulingTime){ continue; } SysDept dept = deptService.getById(schedulingTime.getDeptId()); schedulingTime.setHospId(dept.getHospId()); schedulingTime.setHospName(dept.getHospName()); mallSchedulingTimeService.save(schedulingTime); } return AjaxResult.success("操作成功!"); } return AjaxResult.error("操作失败!"); } /** * 修改排班时间 */ @PutMapping @ApiOperation(value = "修改医生排班信息数据接口") public AjaxResult edit(@RequestBody MallSchedulingTime mallTimeConfig) { return toAjax(mallSchedulingTimeService.updateById(mallTimeConfig)); } /** * 修改医生是否停诊状态接口 */ @PostMapping("/updateIsClose") @ApiOperation(value = "修改医生是否停诊状态接口") public AjaxResult updateIsClose(@RequestBody MallSchedulingTime mallTimeConfig) { MallSchedulingTime schedulingTime = mallSchedulingTimeService.getById(mallTimeConfig.getId()); if(null !=schedulingTime){ schedulingTime.setIsClose(mallTimeConfig.getIsClose()); if (mallSchedulingTimeService.updateById(schedulingTime)) { if(schedulingTime.getIsClose().equals("Y")){ //停诊后取消所有停诊当天的挂号记录 // LambdaQueryWrapper wq=new LambdaQueryWrapper<>(); // wq.eq(GhCusRegisterInfo::getUserId,schedulingTime.getUserId()); // wq.between(GhCusRegisterInfo::getRegisterTime,DateUtil.beginOfDay(schedulingTime.getTime()),DateUtil.endOfDay(schedulingTime.getTime())); // List infoList = cusRegisterInfoService.list(wq); // if(null !=infoList && infoList.size()>0){ // for (GhCusRegisterInfo registerInfo : infoList) { // registerInfo.setIsExpiration("Y"); // registerInfo.setIsVisit("Y"); // cusRegisterInfoService.updateById(registerInfo); // //若收费还将退费 // //短信或邮箱告知客户 // } // } } return AjaxResult.success(); } } return AjaxResult.error(); } /** * 删除排班时间 */ @DeleteMapping("/{ids}") @ApiOperation(value = "删除医生排班时间接口") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(mallSchedulingTimeService.removeByIds(Arrays.asList(ids))); } /** * 获取排班信息临时数据接口 */ @PostMapping("/getSchedulingInformation") @ApiOperation(value = "获取排班信息临时数据接口") public AjaxResult getSchedulingInformation(@RequestBody List dtos) { List list=new ArrayList<>(); if (dtos!=null){ for (MallSchedulingTimeDto dto : dtos) { if(null !=dto){ if(null !=dto.getStartTime() && null !=dto.getEndTime()){ List dateList = mallSchedulingTimeService.getDateListByBetweenTime(dto.getStartTime(), dto.getEndTime()); if(null !=dateList && dateList.size()>0){ if (dto.getMOrA()==1){ for (Date date : dateList) { MallSchedulingTime schedulingTime =new MallSchedulingTime(); schedulingTime.setTime(DateUtil.parse(DateUtil.format(date,"yyyy-MM-dd"))); schedulingTime.setAllNum(Long.valueOf(dto.getAllNum())); schedulingTime.setNowNum(Long.valueOf(dto.getAllNum())); schedulingTime.setWeek(DateUtils.dateToWeek(date)); schedulingTime.setMOrA("上午"); schedulingTime.setUserId(dto.getUserId()); schedulingTime.setUserName(dto.getUserName()); schedulingTime.setIsClose("N"); // schedulingTime.setTimeSlot(s); schedulingTime.setNumType(dto.getNumType()); schedulingTime.setDeptId(dto.getDeptId()); schedulingTime.setDeptName(dto.getDeptName()); list.add(schedulingTime); } }else if (dto.getMOrA()==2){ for (Date date : dateList) { MallSchedulingTime schedulingTime =new MallSchedulingTime(); schedulingTime.setTime(DateUtil.parse(DateUtil.format(date,"yyyy-MM-dd"))); schedulingTime.setAllNum(Long.valueOf(dto.getAllNum())); schedulingTime.setNowNum(Long.valueOf(dto.getAllNum())); schedulingTime.setWeek(DateUtils.dateToWeek(date)); schedulingTime.setMOrA("下午"); schedulingTime.setUserId(dto.getUserId()); schedulingTime.setUserName(dto.getUserName()); schedulingTime.setIsClose("N"); // schedulingTime.setTimeSlot(s); schedulingTime.setNumType(dto.getNumType()); schedulingTime.setDeptId(dto.getDeptId()); schedulingTime.setDeptName(dto.getDeptName()); list.add(schedulingTime); } }else if (dto.getMOrA()==3){ for (Date date : dateList) { MallSchedulingTime schedulingTime =new MallSchedulingTime(); schedulingTime.setTime(DateUtil.parse(DateUtil.format(date,"yyyy-MM-dd"))); schedulingTime.setAllNum(Long.valueOf(dto.getAllNum())); schedulingTime.setNowNum(Long.valueOf(dto.getAllNum())); schedulingTime.setWeek(DateUtils.dateToWeek(date)); schedulingTime.setMOrA("上午"); schedulingTime.setUserId(dto.getUserId()); schedulingTime.setUserName(dto.getUserName()); schedulingTime.setIsClose("N"); // schedulingTime.setTimeSlot(s); schedulingTime.setNumType(dto.getNumType()); schedulingTime.setDeptId(dto.getDeptId()); schedulingTime.setDeptName(dto.getDeptName()); list.add(schedulingTime); MallSchedulingTime schedulingTime1 =new MallSchedulingTime(); schedulingTime1.setTime(DateUtil.parse(DateUtil.format(date,"yyyy-MM-dd"))); schedulingTime1.setAllNum(Long.valueOf(dto.getAllNum())); schedulingTime1.setNowNum(Long.valueOf(dto.getAllNum())); schedulingTime1.setWeek(DateUtils.dateToWeek(date)); schedulingTime1.setMOrA("下午"); schedulingTime1.setUserId(dto.getUserId()); schedulingTime1.setUserName(dto.getUserName()); schedulingTime1.setIsClose("N"); // schedulingTime.setTimeSlot(s); schedulingTime1.setNumType(dto.getNumType()); schedulingTime1.setDeptId(dto.getDeptId()); schedulingTime1.setDeptName(dto.getDeptName()); list.add(schedulingTime1); } } } } } } } return AjaxResult.success(list); } /** * 获取所有医生信息数据列表接口 */ @GetMapping("/getUserListBySchedulingTimt") @ApiOperation(value = "获取所有医生信息数据列表接口") public AjaxResult getUserListBySchedulingTimt(@RequestParam(required = false) @ApiParam(value = "医生姓名") String userName, @RequestParam(required = false) @ApiParam(value = "科室") String deptName, @RequestParam(defaultValue = "1") @ApiParam(value = "分页") Integer pageNum, @RequestParam(defaultValue = "10") @ApiParam(value = "一页展示条数") Integer pageSize, @RequestParam(required = false) @ApiParam(value = "角色id") Long roleId) { Page page=new Page<>(pageNum,pageSize); LambdaQueryWrapper wq=new LambdaQueryWrapper<>(); if (roleId!=null){ LambdaQueryWrapper wq111=new LambdaQueryWrapper<>(); wq111.eq(SysUserRole::getRoleId,roleId); final List list1 = userRoleService.list(wq111); final List collect = list1.stream().map(SysUserRole::getUserId).collect(Collectors.toList()); wq.in(SysUser::getUserId,collect); } if(null !=userName){ wq.like(SysUser::getNickName,userName); } if(null !=deptName && !"".equals(deptName)){ wq.in(SysUser::getDeptId,deptService.getSysDeptId(deptName)); } Page userPage = userService.page(page, wq); List list = userPage.getRecords(); List voList = new ArrayList<>(); if(null !=list && list.size()>0){ for (SysUser user : list) { DoctorUserVo vo=new DoctorUserVo(); vo.setUserId(String.valueOf(user.getUserId())); vo.setUserName(user.getNickName()); vo.setDeptId(String.valueOf(user.getDeptId())); vo.setDeptName(deptService.getById(user.getDeptId()).getDeptName()); DictUserInfo info = userInfoService.getOne(new LambdaQueryWrapper().eq(DictUserInfo::getUserId,user.getUserId())); if(null !=info){ vo.setCftitle(info.getCftitle()); } List timeList = mallSchedulingTimeService.list(new LambdaQueryWrapper() .eq(MallSchedulingTime::getUserId, user.getUserId()).orderByDesc(MallSchedulingTime::getTime)); if(null !=timeList && timeList.size()>0){ if(null !=timeList.get(0)){ vo.setTime(timeList.get(0).getTime()); } } voList.add(vo); } } Map map=new HashMap<>(); map.put("total",page.getTotal()); map.put("voList",voList); return AjaxResult.success(map); } /** * 获取预约时间段字典列表 */ // @GetMapping("/getTimeList") // @ApiOperation(value = "获取预约时间段字典列表") // public AjaxResult getTimeList() { // LambdaQueryWrapper wq22 = new LambdaQueryWrapper<>(); // wq22.eq(SysDictData::getDictType, "yuyue_time_slot"); // final List list = dictDataService.list(wq22); // return success(list); // } }