|
|
@@ -0,0 +1,130 @@
|
|
|
+package com.fs.app.controller;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import com.fs.common.annotation.Log;
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.enums.BusinessType;
|
|
|
+import com.fs.doctor.domain.FsDoctorOnline;
|
|
|
+import com.fs.doctor.service.IFsDoctorOnlineService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 医生在线状态Controller
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2025-12-12
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/doctor/online")
|
|
|
+public class FsDoctorOnlineController extends AppBaseController {
|
|
|
+ @Autowired
|
|
|
+ private IFsDoctorOnlineService fsDoctorOnlineService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询医生在线状态列表
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('doctor:online:list')")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public R list(FsDoctorOnline fsDoctorOnline) {
|
|
|
+ PageHelper.startPage(fsDoctorOnline.getPageNum(), fsDoctorOnline.getPageSize());
|
|
|
+ List<FsDoctorOnline> list = fsDoctorOnlineService.selectFsDoctorOnlineList(fsDoctorOnline);
|
|
|
+ PageInfo<FsDoctorOnline> listPageInfo=new PageInfo<>(list);
|
|
|
+ return R.ok().put("data",listPageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取医生在线状态详细信息
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('doctor:online:query')")
|
|
|
+ @GetMapping(value = "/{doctorId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("doctorId") Long doctorId) {
|
|
|
+ return AjaxResult.success(fsDoctorOnlineService.selectFsDoctorOnlineByDoctorId(doctorId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增医生在线状态
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('doctor:online:add')")
|
|
|
+ @Log(title = "医生在线状态", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ public R add(@RequestBody FsDoctorOnline fsDoctorOnline) {
|
|
|
+ fsDoctorOnlineService.insertFsDoctorOnline(fsDoctorOnline);
|
|
|
+ return R.ok("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改医生在线状态
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('doctor:online:edit')")
|
|
|
+ @Log(title = "医生在线状态", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public R edit(@RequestBody FsDoctorOnline fsDoctorOnline) {
|
|
|
+ fsDoctorOnlineService.updateFsDoctorOnline(fsDoctorOnline);
|
|
|
+ return R.ok("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除医生在线状态
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('doctor:online:remove')")
|
|
|
+ @Log(title = "医生在线状态", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{doctorIds}")
|
|
|
+ public R remove(@PathVariable Long[] doctorIds) {
|
|
|
+ fsDoctorOnlineService.deleteFsDoctorOnlineByDoctorIds(doctorIds);
|
|
|
+ return R.ok("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 心跳接口 - 前端定期调用,更新在线状态
|
|
|
+ */
|
|
|
+ @PostMapping("/heartbeat")
|
|
|
+ public AjaxResult heartbeat() {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isBlank(getDoctorId())) {
|
|
|
+ return AjaxResult.error("未获取到医生ID");
|
|
|
+ }
|
|
|
+ Long doctorId = Long.parseLong(getDoctorId());
|
|
|
+ fsDoctorOnlineService.heartbeat(doctorId);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } catch (CustomException e) {
|
|
|
+ log.error("心跳异常, doctorId: {}", getDoctorId(), e);
|
|
|
+ return AjaxResult.error("心跳机制失败,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主动登出 - 标记为离线(用于正常退出时)
|
|
|
+ */
|
|
|
+ @PostMapping("/updateOnlineStatusOnLogout")
|
|
|
+ public AjaxResult updateOnlineStatusOnLogout() {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isBlank(getDoctorId())) {
|
|
|
+ return AjaxResult.error("未获取到医生ID");
|
|
|
+ }
|
|
|
+ Long doctorId = Long.parseLong(getDoctorId());
|
|
|
+ fsDoctorOnlineService.updateOnlineStatusOnLogout(doctorId);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } catch (CustomException e) {
|
|
|
+ log.error("登出登录更新在线状态异常, doctorId: {}", getDoctorId(), e);
|
|
|
+ return AjaxResult.error("登出登录更新在线状态异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|